View unanswered posts | View active topics


Reply to topic  [ 3 posts ] 
FB project import patches 
Author Message
Member

Joined: Mon Sep 20, 2010 8:55 am
Posts: 86
Post FB project import patches
Here is the list of changes:

1. Output path
In the original FB project we have these attributes under 'compiler' node:
Code:
outputFolderLocation="X:/project"
outputFolderPath="bin-debug"

FD sets the output path to "bin-debug\project.swf", while it has to set it to "x:\project\project.swf".

Fixed by using 'outputFolderLocation' instead of 'outputFolderPath'. If this breaks your projects, please let me know.

2. Libraries
Libraries are defined in FB like this:
Code:
<libraryPathEntry kind="3" linkType="2" path="${env_dir}/as/loader/loader.swc" sourcepath="${env_dir}/as/loader/shared" useDefaultLinkType="false"/>

In FD libraries are imported in External Libraries or SWC Libraries. Absolute paths are resolved to relative (if possible).

3. Fixed a bug with empty compiler options, that made libraries inaccessible for import.

4. Added "Flex Builder Workspace Paths" parameter to Project Manager options (Tools -> Program Settings... -> Project Manager). This paths will be resolved while importing libraries. Example:
FB project file:
Code:
<libraryPathEntry kind="3" linkType="2" path="${env_dir}/as/loader/loader.swc" sourcepath="${env_dir}/as/loader/shared" useDefaultLinkType="false"/>

FD Project Manager options:
Code:
games=c:\games
projects=c:\dev\projects
env_dir=d:\environment
Library will be imported with path "d:\environment\as\loader\loader.swc", which will then be reduced if the project is on the same disk (if project is in the "d:\environment\as\game\", this will resolve to "..\loader\loader.swc").

Workspace Paths are name-value pairs, separated with '=' (just plain strings, like "name=value").


This patch mostly hacks together the needed functionality and may be unstable. For example, I don't know how it will work with long unicode paths. Anyway, it works for me, so I decided to share it.
Code:
Index: External/Plugins/ProjectManager/Projects/AS3/FlexProjectReader.cs
===================================================================
--- External/Plugins/ProjectManager/Projects/AS3/FlexProjectReader.cs    (revision 1469)
+++ External/Plugins/ProjectManager/Projects/AS3/FlexProjectReader.cs    (working copy)
@@ -37,7 +37,7 @@
 
         private void ReadCompilerOptions()
         {
-            outputPath = GetAttribute("outputFolderPath") ?? "";
+            outputPath = GetAttribute("outputFolderLocation") ?? "";
             mainApp = (GetAttribute("sourceFolderPath") ?? "") + "/" + mainApp;
             if (mainApp.StartsWith("/")) mainApp = mainApp.Substring(1);
             project.CompileTargets.Add(OSPath(mainApp.Replace('/', '\\')));
@@ -75,8 +75,11 @@
 
         private void ReadCompilerSourcePaths()
         {
-            ReadStartElement("compilerSourcePath");
-            ReadPaths("compilerSourcePathEntry", project.Classpaths);
+            if (!IsEmptyElement)
+            {
+                   ReadStartElement("compilerSourcePath");
+                ReadPaths("compilerSourcePathEntry", project.Classpaths);
+            }
         }
 
         private void ReadLibraryPaths()
@@ -96,11 +99,16 @@
 
                     case "libraryPathEntry":
                         string path = GetAttribute("path") ?? "";
+                        if (path.StartsWith("$"))
+                              path = normalizeFBPath(path);
                         if (path.Length > 0 && !path.StartsWith("$"))
                         {
+                              path = getRelativePath(path, project.ProjectPath);
                             asset = new LibraryAsset(project, path.Replace('/', '\\'));
-                            if (exclude) asset.SwfMode = SwfAssetMode.ExternalLibrary;
-                            else asset.SwfMode = SwfAssetMode.Library;
+                            if (exclude || (GetAttribute("linkType").ToString() == "2"))
+                                  asset.SwfMode = SwfAssetMode.ExternalLibrary;
+                            else
+                                  asset.SwfMode = SwfAssetMode.Library;
                             project.SwcLibraries.Add(asset);
                         }
                         break;
@@ -109,6 +117,27 @@
             }
             project.RebuildCompilerOptions();
         }
+        private string normalizeFBPath(string path)
+        {
+              string env_path_name = path.Substring(2, path.IndexOf('}') - 2);
+              string[] paths = PluginMain.Settings.FBWorkspacePaths;
+              for (int i = 0; i < paths.Length; i++)
+              {
+                    if (paths[i].StartsWith(env_path_name + "="))
+                    {
+                          string env_path = paths[i].Substring(env_path_name.Length + 1);
+                          return (path.Replace("${" + env_path_name + "}", env_path));
+                    }
+              }
+              return path;
+        }
+        private string getRelativePath(string path1, string path2)
+        {
+            System.Uri uri1 = new Uri(path1);
+            System.Uri uri2 = new Uri(path2);
+            Uri relativeUri = uri2.MakeRelativeUri(uri1);
+            return relativeUri.ToString();
+        }
 
         public void ReadApplications()
         {
Index: External/Plugins/ProjectManager/Settings.cs
===================================================================
--- External/Plugins/ProjectManager/Settings.cs    (revision 1469)
+++ External/Plugins/ProjectManager/Settings.cs    (working copy)
@@ -49,6 +49,7 @@
         string[] excludedDirectories = new string[] { "obj", ".svn", "_svn", ".cvs", "_cvs", "cvs", "_sgbak", ".git" };
         string[] executableFileTypes = new string[] { ".exe", ".lnk", ".fla", ".doc", ".pps", ".psd", ".png", ".jpg", ".gif", ".xls", ".docproj", ".ttf", ".otf", ".wav", ".mp3", ".ppt", ".pptx", ".docx", ".xlsx", ".ai", ".pdf", ".zip", ".rar" };
         string[] filteredDirectoryNames = new string[] { "src", "source", "sources", "as", "as2", "as3", "actionscript", "flash", "classes", "trunk", "svn" };
+        string[] fbWorkspacePaths = new string[] { };
 
         #region Properties
         [Browsable(false)]
@@ -169,6 +170,15 @@
             get { return filteredDirectoryNames; }
             set { filteredDirectoryNames = value; FireChanged("FilteredDirectoryNames"); }
         }
+       
+        [DisplayName("Flex Builder Workspace Paths")]
+        [LocalizedDescription("ProjectManager.Description.FBWorkspacePaths")]
+        [LocalizedCategory("ProjectManager.Category.Exclusions")]
+        public string[] FBWorkspacePaths
+        {
+            get { return fbWorkspacePaths; }
+            set { fbWorkspacePaths = value; FireChanged("FBWorkspacePaths"); }
+        }
 
         [DisplayName("Show Project Classpaths")]
         [LocalizedDescription("ProjectManager.Description.ShowProjectClasspaths")]


Tue Oct 12, 2010 2:20 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 10749
Location: Paris, France
Post Re: FB project import patches
Do you think this additional configuration could be detected automatically?
Maybe Flex/Flash Builder store this information somewhere.


Wed Oct 13, 2010 1:05 pm
Profile WWW
Member

Joined: Mon Sep 20, 2010 8:55 am
Posts: 86
Post Re: FB project import patches
This additional information (path variables) is stored in the workspace (as mentioned here: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/resInt_linked.htm), so it is only possible to retrieve it if we have FB installed on the computer with proper paths set in the workspace.
The best way to handle this would be to use some kind of eclipse plugin that will subtitute path variables with their values, but it won't work if the user does not have FB or if the demo license has expired.

I guess we should ask the user about every path in the project file, but it was more complex to implement than just add one more configuration parameter. I have lots of projects with identical path variables, which I have to import often, and this solution was good enough to use.


And there's one more problem with path variables: if they are used somewhere in compiler options, FB evaluates them to full paths, while in the project file it looks like an ordinary directory and imports incorrectly.


Wed Oct 13, 2010 3:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.