Skip to content

Commit

Permalink
wired build commands in
Browse files Browse the repository at this point in the history
  • Loading branch information
makc committed Jun 13, 2013
1 parent 4f2cdb2 commit f25d076
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 33 deletions.
101 changes: 76 additions & 25 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class PluginMain : IPlugin
private String pathToLog;
private System.Timers.Timer timer;
private Keys MakeItLiveKeys = Keys.Control | Keys.Shift | Keys.L;
private Boolean allowBuildInterception = true;

#region Required Properties

Expand Down Expand Up @@ -148,6 +149,16 @@ public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
toolbarButton = CreateToolbarButton(toolStrip as ToolStrip, "colt_save.png", "Menu.ExportToCOLT", new EventHandler(OnClick));
toolbarButton2 = CreateToolbarButton(toolStrip as ToolStrip, "colt_run.png", "Menu.OpenInCOLT", new EventHandler(OnClick2));
}
else if ((cmd == "ProjectManager.BuildingProject") || (cmd == "ProjectManager.TestingProject"))
{
// todo: FD might send this for projects other than PluginBase.CurrentProject - figure out how to catch that
if (settingObject.InterceptBuilds && allowBuildInterception)
{
new AppStarter(ProductionBuild, cmd == "ProjectManager.TestingProject");

e.Handled = true;
}
}
break;

case EventType.FileSave:
Expand Down Expand Up @@ -258,12 +269,12 @@ private static Image GetImage(String imageName)

private void OnClick(Object sender, System.EventArgs e)
{
new AppStarter(ExportAndOpen);
new AppStarter(ExportAndOpen, settingObject.AutoRun);
}

private void OnClick2(Object sender, System.EventArgs e)
{
new AppStarter(FindAndOpen);
new AppStarter(FindAndOpen, settingObject.AutoRun);
}

#endregion
Expand Down Expand Up @@ -440,7 +451,7 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)
#endregion

/// <summary>
/// Connects to COLT
/// Connects to COLT (todo: rename)
/// </summary>
private void ConnectToCOLT(Boolean create = false)
{
Expand All @@ -466,10 +477,38 @@ private void ConnectToCOLT(Boolean create = false)
}
}

/// <summary>
/// Makes production build and optionally runs it
/// </summary>
private void ProductionBuild(Boolean run)
{
// make sure the COLT project is open
// todo: currently no way to know if this fails, check the state before running the build in the future
if (toolbarButton2.Enabled) FindAndOpen(false); else ExportAndOpen(false);

try
{
JsonRpcClient client = new JsonRpcClient();
client.Invoke("runProductionCompilation", new Object[] { "TEST", /*run*/false });

// leverage FD launch mechanism
// todo: does runProductionCompilation block? no idea atm
if (run)
{
EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.PlayOutput", null));
}
}
catch (Exception details)
{
TraceManager.Add(details.ToString(), -1);
}
}


/// <summary>
/// Opens the project in COLT
/// </summary>
private void FindAndOpen()
private void FindAndOpen(Boolean run)
{
// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
Expand All @@ -485,10 +524,11 @@ private void FindAndOpen()
{
JsonRpcClient client = new JsonRpcClient();
client.Invoke("loadProject", new Object[] { "TEST", coltFileName });
if (run) client.Invoke("runBaseCompilation", new Object[] { "TEST" });
}
catch (Exception details)
{
TraceManager.Add("FindAndOpen failed\n" + details, -1);
TraceManager.Add(details.ToString(), -1);
}
}

Expand All @@ -499,37 +539,39 @@ private void FindAndOpen()

}

private void ExportAndOpen()
private void ExportAndOpen(Boolean run)
{
// Create COLT subfolder if does not exist yet
// While at that, start listening for colt/compile_errors.log changes
ConnectToCOLT(true);

// Create COLT project in it
COLTRemoteProject project = ExportCOLTProject();
try
if (project != null)
{
JsonRpcClient client = new JsonRpcClient();
client.Invoke("createProject", new Object[] { "TEST", project });
//Object state = client.Invoke("getState", new Object[] { "TEST" });
//TraceManager.Add("State: " + state);
}
catch (Exception details)
{
TraceManager.Add("ExportAndOpen failed\n" + details, -1);
}
try
{
JsonRpcClient client = new JsonRpcClient();
client.Invoke("createProject", new Object[] { "TEST", project });
if (run) client.Invoke("runBaseCompilation", new Object[] { "TEST" });
}
catch (Exception details)
{
TraceManager.Add(details.ToString(), -1);
}

// Remove older *.colt files
foreach (String oldFile in Directory.GetFiles(Path.GetDirectoryName(project.path), "*.colt"))
{
if (!project.path.Contains(Path.GetFileName(oldFile)))
// Remove older *.colt files
foreach (String oldFile in Directory.GetFiles(Path.GetDirectoryName(project.path), "*.colt"))
{
File.Delete(oldFile);
if (!project.path.Contains(Path.GetFileName(oldFile)))
{
File.Delete(oldFile);
}
}
}

// Enable "open" button
toolbarButton2.Enabled = true;
// Enable "open" button
toolbarButton2.Enabled = true;
}
}

/// <summary>
Expand Down Expand Up @@ -568,7 +610,16 @@ private COLTRemoteProject ExportCOLTProject()
{
TraceManager.Add("Required file (" + projectName + "Config.xml) does not exist, project must be built first...", -1);

EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null));
try
{
allowBuildInterception = false;
EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null));
}

finally
{
allowBuildInterception = true;
}

return null;
}
Expand Down
27 changes: 19 additions & 8 deletions ColtPlugin/Rpc/AppStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
using System.Net;
using System.Timers;

public delegate void AppStarterDelegate ();
public delegate void AppStarterDelegate(Boolean param);

class AppStarter
public class AppStarter
{
private AppStarterDelegate callback;
private Boolean callbackParam;
private String tempColtFile;
private Timer timer;
private int count;

public AppStarter(AppStarterDelegate onConnected)
public AppStarter(AppStarterDelegate onConnected, Boolean onConnectedParam)
{
if (COLTIsRunning())
{
onConnected();
onConnected(onConnectedParam);
}

else
{
callback = onConnected;
callbackParam = onConnectedParam;
tempColtFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".colt");

File.CreateText(tempColtFile).Close();
Expand Down Expand Up @@ -57,7 +59,7 @@ private void OnTimer(Object sender = null, EventArgs e = null)
if (COLTIsRunning())
{
// we are good to go
callback();
callback(callbackParam);

CleanUp();
return;
Expand Down Expand Up @@ -88,12 +90,21 @@ private Boolean COLTIsRunning ()
WebClient client = new WebClient();
try
{
client.DownloadString("http://127.0.0.1:8091/crossdomain.xml");
return true;
// this must always throw
client.DownloadString("http://127.0.0.1:8091/rpc/coltService");
}

catch (Exception)
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.InternalServerError)
{
// until rpc is ready, this should be 404, not 500
// todo: still does not work - colt crashes :S
return true;
}
}
}

return false;
Expand Down
23 changes: 23 additions & 0 deletions ColtPlugin/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace ColtPlugin
public class Settings
{
private String workingFolder = "colt";
private Boolean autorun = true;
private Boolean fullConfig = false;
private Boolean interceptBuilds = false;

/// <summary>
/// Get and sets colt folder
Expand All @@ -23,6 +25,17 @@ public String WorkingFolder
set { this.workingFolder = value; }
}

/// <summary>
/// Get and sets full autorun flag
/// </summary>
[DisplayName("Automatically run COLT project")]
[Description("Automatically compile and run COLT project after opening it in COLT."), DefaultValue(true)]
public Boolean AutoRun
{
get { return this.autorun; }
set { this.autorun = value; }
}

/// <summary>
/// Get and sets full config flag
/// </summary>
Expand All @@ -34,6 +47,16 @@ public Boolean FullConfig
set { this.fullConfig = value; }
}

/// <summary>
/// Get and sets production builds flag
/// </summary>
[DisplayName("Use COLT for FD builds")]
[Description("Use COLT fast compiler to build your FD projects."), DefaultValue(false)]
public Boolean InterceptBuilds
{
get { return this.interceptBuilds; }
set { this.interceptBuilds = value; }
}
}

}

0 comments on commit f25d076

Please # to comment.