Skip to content

Commit

Permalink
1.2 support wip (so far only exports FD project and opens it in COLT,…
Browse files Browse the repository at this point in the history
… rpc stuff is broken)
  • Loading branch information
makc committed Oct 17, 2013
1 parent 8daaa8e commit 531bfcb
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 17 deletions.
122 changes: 121 additions & 1 deletion ColtPlugin/COLTRemoteProject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace ColtPlugin
using System.Xml;
namespace ColtPlugin
{
public class COLTRemoteProject
{
Expand All @@ -23,5 +24,124 @@ public class COLTRemoteProject
public string outputPath;
public string targetPlayerVersion;
public string compilerOptions;

public void Save()
{
// <xml projectName="untitled" projectType="AS">
XmlDocument doc = new XmlDocument();
XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("", "xml", ""));
root.Attributes.Append(doc.CreateAttribute("projectType")).Value = "AS";
root.Attributes.Append(doc.CreateAttribute("projectName")).Value = name;

// <paths> <sources-set>src</sources-set> <libraries-set/> <assets-set/> <html-template/> </paths>
XmlElement paths = (XmlElement)root.AppendChild(doc.CreateElement("", "paths", ""));
((XmlElement)paths.AppendChild(doc.CreateElement("", "sources-set", ""))).InnerText = string.Join(", ", sources);
((XmlElement)paths.AppendChild(doc.CreateElement("", "libraries-set", ""))).InnerText = string.Join(", ", libraries);
((XmlElement)paths.AppendChild(doc.CreateElement("", "assets-set", ""))).InnerText = string.Join(", ", assets);
((XmlElement)paths.AppendChild(doc.CreateElement("", "html-template", ""))).InnerText = htmlTemplateDir;

// <build>
// <sdk>
// <sdk-path>/Applications/COLT/COLT.app/flex_sdk</sdk-path>
// <use-flex>true</use-flex>
// <use-custom>false</use-custom>
// <custom-config/>
// </sdk>
XmlElement build = (XmlElement)root.AppendChild(doc.CreateElement("", "build", ""));
XmlElement sdk = (XmlElement)build.AppendChild(doc.CreateElement("", "sdk", ""));
XmlElement sdkPath = (XmlElement)sdk.AppendChild(doc.CreateElement("", "sdk-path", ""));
if ((flexSDKPath != null) && (flexSDKPath.Length > 0))
{
sdkPath.InnerText = flexSDKPath;
}
else
{
sdkPath.InnerText = "${colt_home}/flex_sdk";
}
((XmlElement)sdk.AppendChild(doc.CreateElement("", "use-flex", ""))).InnerText = "true";
XmlElement useCustom = (XmlElement)sdk.AppendChild(doc.CreateElement("", "use-custom", ""));
XmlElement customConfig = (XmlElement)sdk.AppendChild(doc.CreateElement("", "custom-config", ""));
if ((customConfigPath != null) && (customConfigPath.Length > 0))
{
useCustom.InnerText = "true";
customConfig.InnerText = customConfigPath;
}
else
{
useCustom.InnerText = "false";
}

//<build>
// <main-class>/Users/eliseyev/IdeaProjects/untitled/src/com/codeorchestra/Tree.as</main-class>
// <output-name>untitled.swf</output-name>
// <output-path>/Users/eliseyev/IdeaProjects/untitled/output</output-path>
// <use-max-version>true</use-max-version>
// <player-version>11.8</player-version>
// <is-rsl>false</is-rsl>
// <locale/>
// <is-exclude>false</is-exclude>
// <is-interrupt>false</is-interrupt>
// <interrupt-value>30</interrupt-value>
// <compiler-options/>
//</build>
XmlElement build2 = (XmlElement)build.AppendChild(doc.CreateElement("", "build", ""));
((XmlElement)build2.AppendChild(doc.CreateElement("", "main-class", ""))).InnerText = mainClass;
((XmlElement)build2.AppendChild(doc.CreateElement("", "output-name", ""))).InnerText = outputFileName;
((XmlElement)build2.AppendChild(doc.CreateElement("", "output-path", ""))).InnerText = outputPath; // FIXME: same path in <production> below - leave it blank here??
((XmlElement)build2.AppendChild(doc.CreateElement("", "use-max-version", ""))).InnerText = "true";
((XmlElement)build2.AppendChild(doc.CreateElement("", "player-version", ""))).InnerText = targetPlayerVersion;
((XmlElement)build2.AppendChild(doc.CreateElement("", "is-rsl", ""))).InnerText = "false";
build2.AppendChild(doc.CreateElement("", "locale", ""));
((XmlElement)build2.AppendChild(doc.CreateElement("", "is-exclude", ""))).InnerText = "false";
((XmlElement)build2.AppendChild(doc.CreateElement("", "is-interrupt", ""))).InnerText = "true"; // "false";
((XmlElement)build2.AppendChild(doc.CreateElement("", "interrupt-value", ""))).InnerText = "30";
((XmlElement)build2.AppendChild(doc.CreateElement("", "compiler-options", ""))).InnerText = compilerOptions;

//<production>
// <output-path>/Users/eliseyev/IdeaProjects/untitled/output</output-path>
// <compress>false</compress>
// <optimize>false</optimize>
//</production>
//<run-target>
// <run-target>SWF</run-target>
//</run-target>
XmlElement production = (XmlElement)build.AppendChild(doc.CreateElement("", "production", ""));
((XmlElement)production.AppendChild(doc.CreateElement("", "output-path", ""))).InnerText = outputPath;
((XmlElement)production.AppendChild(doc.CreateElement("", "compress", ""))).InnerText = "false";
((XmlElement)production.AppendChild(doc.CreateElement("", "optimize", ""))).InnerText = "false";
XmlElement runTarget = (XmlElement)build.AppendChild(doc.CreateElement("", "run-target", ""));
((XmlElement)runTarget.AppendChild(doc.CreateElement("", "run-target", ""))).InnerText = "SWF";

//<live>
// <settings>
// <clear-log>false</clear-log>
// <disconnect>false</disconnect>
// </settings>
// <launch>
// <launcher>DEFAULT</launcher>
// <player-path/>
// </launch>
// <live>
// <live-type>annotated</live-type>
// <paused>false</paused>
// <make-gs-live>false</make-gs-live>
// <max-loop>10000</max-loop>
// </live>
//</live>
XmlElement live = (XmlElement)root.AppendChild(doc.CreateElement("", "live", ""));
XmlElement settings = (XmlElement)live.AppendChild(doc.CreateElement("", "settings", ""));
((XmlElement)settings.AppendChild(doc.CreateElement("", "clear-log", ""))).InnerText = "true"; // "false";
((XmlElement)settings.AppendChild(doc.CreateElement("", "disconnect", ""))).InnerText = "true"; // "false";
XmlElement launch = (XmlElement)live.AppendChild(doc.CreateElement("", "launch", ""));
((XmlElement)launch.AppendChild(doc.CreateElement("", "launcher", ""))).InnerText = "DEFAULT";
launch.AppendChild(doc.CreateElement("", "player-path", ""));
XmlElement live2 = (XmlElement)live.AppendChild(doc.CreateElement("", "live", ""));
((XmlElement)live2.AppendChild(doc.CreateElement("", "live-type", ""))).InnerText = "annotated";
((XmlElement)live2.AppendChild(doc.CreateElement("", "paused", ""))).InnerText = "false";
((XmlElement)live2.AppendChild(doc.CreateElement("", "make-gs-live", ""))).InnerText = "false";
((XmlElement)live2.AppendChild(doc.CreateElement("", "max-loop", ""))).InnerText = "10000";

doc.Save(path);
}
}
}
73 changes: 59 additions & 14 deletions ColtPlugin/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using ASCompletion.Context;
using System.Text.RegularExpressions;
using ASCompletion.Model;
using System.Xml;

namespace ColtPlugin
{
Expand Down Expand Up @@ -358,28 +359,30 @@ private ToolStripButton CreateToolbarButton(ToolStrip toolStrip, String image, S

private void OnClick(Object sender, EventArgs e)
{
if (settingObject.SecurityToken != null)
ExportAndOpen(settingObject.AutoRun);//FIXME
/* if (settingObject.SecurityToken != null)
{
new AppStarter(ExportAndOpen, settingObject.AutoRun);
}
else
{
new AppStarter(GetSecurityToken, true);
}
}*/
}

private void OnClick2(Object sender, EventArgs e)
{
if (settingObject.SecurityToken != null)
FindAndOpen(settingObject.AutoRun);//FIXME
/* if (settingObject.SecurityToken != null)
{
new AppStarter(FindAndOpen, settingObject.AutoRun);
}
else
{
new AppStarter(GetSecurityToken, true);
}
}*/
}

#endregion
Expand All @@ -391,14 +394,27 @@ private void OnClick2(Object sender, EventArgs e)
/// </summary>
public void LoadSettings()
{
string defaultExe = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\COLT\colt.exe";

settingObject = new Settings();
if (!File.Exists(settingFilename)) SaveSettings();

if (!File.Exists(settingFilename))
{
settingObject.Executable = defaultExe;
SaveSettings();
}
else
{
Object obj = ObjectSerializer.Deserialize(settingFilename, settingObject);
settingObject = (Settings)obj;
// debug
//settingObject.SecurityToken = null;
string exe = settingObject.Executable;
if ((exe == null) || (exe.Length == 0))
{
settingObject.Executable = defaultExe;
SaveSettings();
}
}
}

Expand Down Expand Up @@ -618,7 +634,7 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)

private void GetSecurityToken(Boolean param)
{
JsonRpcClient client = new JsonRpcClient();
JsonRpcClient client = new JsonRpcClient("FIXME");

try
{
Expand Down Expand Up @@ -657,7 +673,7 @@ private void ProductionBuild(Boolean run)

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

// leverage FD launch mechanism
Expand All @@ -672,6 +688,22 @@ private void ProductionBuild(Boolean run)
}
}

private void OpenInCOLT(string pathToProject)
{
// put it on recent files list
string coltFolder = System.Environment.GetEnvironmentVariable("USERPROFILE") + @"\.colt\";

XmlDocument workingSet = new XmlDocument();
workingSet.Load(coltFolder + "workingset.xml");
XmlElement root = (XmlElement)workingSet.SelectSingleNode("/workingset");
XmlElement project = (XmlElement)root.PrependChild(workingSet.CreateElement("", "project", ""));
project.Attributes.Append(workingSet.CreateAttribute("path")).Value = pathToProject;
workingSet.Save(coltFolder + "workingset.xml");

// open COLT exe
Process.Start(settingObject.Executable);
}


/// <summary>
/// Opens the project in COLT and optionally runs live session
Expand All @@ -685,14 +717,17 @@ private void FindAndOpen(Boolean run)
// Find COLT project to open
String coltFileName = GetCOLTFile();

// Open it with default app (COLT)
// Open it
if (coltFileName != null)
{
try
{
JsonRpcClient client = new JsonRpcClient();
OpenInCOLT(coltFileName);

// TODO: if (run) client.Invoke...
/* JsonRpcClient client = new JsonRpcClient("FIXME");
client.Invoke("loadProject", new Object[] { settingObject.SecurityToken, coltFileName });
if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });
if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });*/
}
catch (Exception details)
{
Expand Down Expand Up @@ -722,8 +757,15 @@ private void ExportAndOpen(Boolean run)
{
try
{
JsonRpcClient client = new JsonRpcClient();
// Export the project as xml file
project.Save();

// Open it
OpenInCOLT(project.path);

/* JsonRpcClient client = new JsonRpcClient("FIXME");
client.Invoke("createProject", new Object[] { settingObject.SecurityToken, project });
*/

// Enable "open" button
toolbarButton2.Enabled = true;
Expand All @@ -737,7 +779,8 @@ private void ExportAndOpen(Boolean run)
}
}

if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });
//TODO this must return...
/* if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });*/
}
catch (Exception details)
{
Expand Down Expand Up @@ -843,7 +886,7 @@ private COLTRemoteProject ExportCOLTProject()
{
if (libraryPathsList[i].ToLower().EndsWith(".swc"))
{
libraryPathsList[i] = project.GetAbsolutePath(libraryPathsList[i]);
libraryPathsList[i] = @"..\" + libraryPathsList[i];
}

else
Expand Down Expand Up @@ -875,14 +918,16 @@ private COLTRemoteProject ExportCOLTProject()

else
{
result.outputPath = project.GetAbsolutePath("");
result.outputFileName = outputPath;
}

String[] sourcePaths = project.SourcePaths.Clone() as String[];
for (int i=0; i<sourcePaths.Length; i++) sourcePaths[i] = project.GetAbsolutePath(sourcePaths[i]);
for (int i=0; i<sourcePaths.Length; i++) sourcePaths[i] = @"..\" + sourcePaths[i];
result.sources = sourcePaths;

result.assets = AssetFolders;
for (int i=0; i<result.assets.Length; i++) result.assets[i] = @"..\" + project.GetRelativePath(result.assets[i]);

// size, frame rate and background color
String[] coltAdditionalOptionsKeys = {
Expand Down
2 changes: 1 addition & 1 deletion ColtPlugin/Rpc/AppStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private Boolean COLTIsRunning ()
{
try
{
JsonRpcClient client = new JsonRpcClient();
JsonRpcClient client = new JsonRpcClient("FIXME");
client.Invoke("ping", new Object[] { });
return true;
}
Expand Down
19 changes: 18 additions & 1 deletion ColtPlugin/Rpc/JsonRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Web.Services.Protocols;
using Jayrock.Json;
using System.Xml;

public class JsonRpcException : Exception
{
Expand All @@ -26,9 +27,25 @@ public class JsonRpcClient : HttpWebClientProtocol
{
private int _id;

public JsonRpcClient()
public JsonRpcClient(string projectPath)
: base()
{
string coltFolder = System.Environment.GetEnvironmentVariable("USERPROFILE") + @"\.colt\";

XmlDocument storageDescriptor = new XmlDocument();
storageDescriptor.Load(coltFolder + "storage.xml");

// <xml>
// <storage path='/Users/makc/Desktop/Site/site.colt' subDir='8572a4d3' />
XmlNodeList storageList = storageDescriptor.SelectNodes("/xml/storage[@path='" + projectPath + "']");
if (storageList.Count == 1)
{
string storage = storageList[0].Attributes["subDir"].Value;
int port = int.Parse ( File.ReadAllText(coltFolder + @"storage\" + storage + @"\rpc.info").Split(':')[1] );

Url = "http://127.0.0.1:" + port + "/rpc/coltService"; return;
}

Url = "http://127.0.0.1:8092/rpc/coltService";
}

Expand Down
12 changes: 12 additions & 0 deletions ColtPlugin/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ public class Settings
{
public String SecurityToken;

private String coltExe = null;
private String workingFolder = "colt";
private Boolean autorun = true;
private Boolean fullConfig = false;
private Boolean interceptBuilds = false;

/// <summary>
/// Get and sets colt.exe path
/// </summary>
[DisplayName("Path to COLT")]
[Description("Path to COLT executable.")]
public String Executable
{
get { return this.coltExe; }
set { this.coltExe = value; }
}

/// <summary>
/// Get and sets colt folder
Expand Down

0 comments on commit 531bfcb

Please # to comment.