View unanswered posts | View active topics



Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Custom JRE location trouble and fixing 
Author Message
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Today I've got another problem with FD - it do not use a 'java.home' argument defined in Flex SDK 'jvm.config'. But other arguments (from it) using successfuly :)
So, I've just fixed it by steps that listed below.
If it is not a "good code" — please fix it by yourself.

I've used marker /*!*/ to show modifes.

Bug fixing (by compiling order):

AS3ProjectBuilder.cs:
Quote:
CompileWithMxmlc():
Code:
   //
   // Resolving path to "java.exe" using JvmConfigHelper.GetJavaEXE( jvmConfig )
   //
   public void CompileWithMxmlc(string workingdir, string arguments, bool configChanged)
   {
      if (fcsh != null)
      {
         string output;
         string[] errors;
         string jvmarg = VMARGS + " -Dapplication.home=\""+ sdkPath + "\" -jar \"" + fcshPath + "\"";

/*!*/      fcsh.Compile(workingdir, configChanged, arguments, out output, out errors, jvmarg, JvmConfigHelper.GetJavaEXE( jvmConfig ) );

         string[] lines = output.Split('\n');
         foreach (string line in lines)
         {
            if (!line.StartsWith("Recompile:") && !line.StartsWith("Reason:"))
               Console.Write(line);
         }
         foreach (string error in errors)
            Console.Error.WriteLine(error);

         if (errors.Length > 0)
            throw new BuildException("Build halted with errors (fcsh).");
      }
      else
      {
         string jvmarg = VMARGS + " -jar \"" + mxmlcPath + "\" +flexlib=\"" + Path.Combine(sdkPath, "frameworks") + "\" ";
/*!*/      if( !ProcessRunner.Run( JvmConfigHelper.GetJavaEXE( jvmConfig ), jvmarg + arguments, false ) )
            throw new BuildException("Build halted with errors (mxmlc).");
      }
   }


FlexCompilerShell.cs:
Quote:

Compile():
Code:
   public void Compile( string projectPath,
                   bool configChanged,
                   string arguments,
                   out string output,
                   out string[] errors,
                   string jvmarg )
   {
      Compile( projectPath, configChanged, arguments, out output, out errors, jvmarg, "java.exe" /*or JvmConfigHelper.GetJavaEXE( null )*/ );
   }

   //
   //   overloading "Compile()" with additional argument "javaExe", that is resolved path to "java.exe"
   //
   public void Compile( string projectPath,
                   bool configChanged,
                   string arguments,
                   out string output,
                   out string[] errors,
                   string jvmarg,
/*!*/                string javaExe )
   {
      StringBuilder o = new StringBuilder();

      // shut down fcsh if our working path has changed
      if (projectPath != workingDir)
         Cleanup();
      
      // start up fcsh if necessary
      if (process == null || process.HasExited)
/*!*/      o.AppendLine( "INITIALIZING: " + Initialize( jvmarg, projectPath, javaExe ) );
      else
         errorList.Clear();

      // success?
      if( process != null )
      {
/*!*/      o.AppendLine( "Starting java as " + process.StartInfo.FileName + "" );
      }
      else
      {
         output = o.ToString();
         errorList.Add("Could not compile because the fcsh process could not be started.");
         errors = errorList.ToArray();
         return;
      }

      ..........
      
   }


Initialize():
Code:
   //
   //   adding additional argument "javaExe", that is resolved path to "java.exe"
   //
/*!*/ string Initialize( string jvmarg, string projectPath, string javaExe )
   {
      errorList = new List<string>();

      if (jvmarg == null)
      {
         //  || !File.Exists(fcshPath)
         // removed! how can i guess file existence using jvm arguments?
         process = null;
         return "Failed, no compiler configured";
      }

      workingDir = projectPath;
      process = new Process();
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.RedirectStandardInput = true;
      process.StartInfo.RedirectStandardOutput = true;
      process.StartInfo.RedirectStandardError = true;
      process.StartInfo.StandardOutputEncoding = Encoding.Default;
      process.StartInfo.StandardErrorEncoding = Encoding.Default;
      process.StartInfo.CreateNoWindow = true;
/*!*/   process.StartInfo.FileName = javaExe;
      process.StartInfo.Arguments = jvmarg;
      process.StartInfo.WorkingDirectory = workingDir;
      
      ..............
      
   }



JvmConfigHelper.cs:
Quote:
GetJavaEXE():
Code:
public static string GetJavaEXE(Hashtable jvmConfig)
{
   string p = "java.exe"; // rely on environment path;

   if( jvmConfig == null )
      return p;

   string home = jvmConfig["java.home"] as string;

   if( home.Length > 0 )
      p = Path.Combine( home, "bin\\java.exe" );

   return p;
}



Last edited by i.o. on Tue Jan 25, 2011 2:19 am, edited 5 times in total.



Mon Jan 24, 2011 4:11 pm
Profile
Member

Joined: Thu Feb 09, 2006 10:58 am
Posts: 1095
Location: Israel
Reply with quote
Wait, does that mean I can use portable JAVA?

_________________
MovieClipCommander


Mon Jan 24, 2011 8:04 pm
Profile
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Yes. But .NET framework should be installed anyway I guess.
How I see — FD using Java Runtime Enviroment only for running Flex SDK tools like mxmlc.jar and etc.

UPD: I've missed little modifing of JvmConfigHelper.GetJavaEXE(). Now you can pass null to get default 'java.exe' location.


Tue Jan 25, 2011 1:26 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
While we're at it, I think GetJavaEXE should try to expand the JAVA_HOME environment var if nothing is defined in the SDK config.


Tue Jan 25, 2011 9:09 am
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Nice to hear you, Philippe :)
Quote:
I think GetJavaEXE should try to expand the JAVA_HOME environment var if nothing is defined in the SDK config.

Idea is good but I'm sorry, I don't know C# as good as that needs to resolve JAVA_HOME path by myself.

Actually in FD source code I've seen duplicated code for compiling with mxmlc:
1. ProjectManager.Building.AS3.AS3ProjectBuilder.CompileWithMxmlc()
2. AS3Context.Compiler.FlexShells.RunMxmlc() — by the way, here 'java.home' is using

These parts seems as the very similar to each other and I don't understand why you have separated it and written as different...


Tue Jan 25, 2011 10:21 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
I'll handle the env expansion code.

Code is duplicated because it is actually quite different in practice (and it was done by 2 different people :P).


Tue Jan 25, 2011 11:17 am
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Thanks for explanation :)
And last question: do you have any ideas about startup failure (viewtopic.php?f=6&t=7864) ?
Now I'm using r1537 on that system and don't have any problems (except viewtopic.php?f=6&t=7847).
Can I help you to resolve that startup crashing?


Tue Jan 25, 2011 11:46 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
i.o. wrote:
Thanks for explanation :)
And last question: do you have any ideas about startup failure (viewtopic.php?f=6&t=7864) ?
Now I'm using r1537 on that system and don't have any problems (except viewtopic.php?f=6&t=7847).
Can I help you to resolve that startup crashing?

Well that's a bit OT here ;)
Didn't have any brilliant suggestions so we'll see if a new build helps - we'll release a new build soon now and make sure you're using a compatible version of ExportSWC.


Tue Jan 25, 2011 2:02 pm
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Thanks, I will wait new dev. builds.
Now I've made and using patch (JRE bug) on r1537. Don't have any troubles for a while ;)


Tue Jan 25, 2011 2:41 pm
Profile
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Question: How can I get FD directory path inside AS3ProjectBuilder.DetectFlexSdk()?

It's needing because Flex SDK path can be relative or absolute starting from '/' or '\'. Nothing restrict that. Just in DetectFlexSdk() needing convert any type of path to absolute (with drive letter at start) and store it to flexsdkPath.
I'm talking about resolving Flex SDK absolute path because 'java.home' also can be relative (to Flex SDK) or absolute (starting from '/' or '\'). This works in Flex SDK (for example I can use "java.home=/programs/java/jre" that's mean JRE located with Flex SDK on the same drive that marked as slash. After first slash - just usual absolute path). But this doesn't work in FD.

Thanks.


Tue Jan 25, 2011 5:04 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Look into PluginCore.Helpers.PathHelper to have access to lots of useful path consts & resolution method.


Tue Jan 25, 2011 5:15 pm
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Well, after some modifications it (SDK and JRE locations) wokrs with "/" and "\" and "../" and "..\" and for project customized SDK and for default SDK location! :D

Please see main code parts:
JvmConfigHelper.cs
Quote:
GetJavaEXE() (changed: partial)
Code:
   public static string GetJavaEXE()
   {
      return GetJavaEXE( null, null );
   }
   public static string GetJavaEXE( Hashtable jvmConfig )
   {
      return GetJavaEXE( jvmConfig, null );
   }
/*!*/public static string GetJavaEXE( Hashtable jvmConfig, string flexSdkPath )
   {
/*!*/   // default java location. Needing to get it from ENV JAVA_HOME if it's set. Else - set to "java.exe"
      string p = "java.exe";

      if( jvmConfig == null )
         return p;

/*!*/   string home = ResolvePath( jvmConfig["java.home"] as string, flexSdkPath, true );

      if( home != null && home.Length > 0 )
         p = Path.Combine( home, "bin\\java.exe" );

      return p;
   }


Quote:
ResolvePath() (changed: whole)
Code:
   // This is duplicate of 'PathHelper.ResolvePath()'
   // because I don't have idea how to use PathHelper.ResolvePath here
   // because JvmConfigHelper using in external tool 'FDBuild'
   // and it doesn't see namespace PluginCore.Managers
   // because doesn't have reference to PluginCore.dll
   private static string ResolvePath( String path, String relativeTo, Boolean checkResolvedPathExisting )
   {
      if( path == null || path.Length == 0 )
         return null;

      Boolean isPathNetworked = (Boolean) (path.IndexOf( "\\\\" ) == 0 || path.IndexOf( "//" ) == 0);
      Boolean isPathAbsSlashed = (Boolean) (path.IndexOf( "\\" ) == 0 || path.IndexOf( "/" ) == 0) && !isPathNetworked;

      if( Path.IsPathRooted( path ) && !isPathNetworked && !isPathAbsSlashed )
         return path;

      if( isPathNetworked )
         return path;   // network path resolving

      if( relativeTo == null )
         relativeTo = "C:\\";

      String resolvedPath = null;

      if( isPathAbsSlashed )
         resolvedPath = Path.GetPathRoot( relativeTo ) + path.Substring( 1 );   // absolute slashed path resolving
      else
         resolvedPath = Path.Combine( relativeTo, path );   // relative path resolving

      if( checkResolvedPathExisting && !(Directory.Exists( resolvedPath ) || File.Exists( resolvedPath )) )
         resolvedPath = null;

      return resolvedPath;
   }



PathHelper.cs
Quote:
ResolvePath() (changed: whole)
Code:

        /// <summary>
        /// Resolve a path which may be:
        /// - absolute or
        /// - relative to base path
        /// </summary>
        public static string ResolvePath( String path )
        {
            return ResolvePath( path, null, true );
        }

        /// <summary>
        /// Resolve a path which may be:
        /// - absolute or
        /// - relative to a specified path, or
        /// - relative to base path
        /// </summary>
      public static string ResolvePath( String path, String relativeTo )
      {
         return ResolvePath( path, relativeTo, true );
      }

      /// <summary>
      /// Resolve a path which may be:
      /// - absolute or
      /// - relative to a specified path, or
      /// - relative to base path
      /// </summary>
        public static string ResolvePath( String path, String relativeTo, Boolean checkResolvedPathExisting )
        {
         if( path == null || path.Length == 0 )
            return null;

         Boolean isPathNetworked = (Boolean) (path.IndexOf( "\\\\" ) == 0 || path.IndexOf( "//" ) == 0);
         Boolean isPathAbsSlashed = (Boolean) (path.IndexOf( "\\" ) == 0 || path.IndexOf( "/" ) == 0) && !isPathNetworked;

         if( Path.IsPathRooted( path ) && !isPathNetworked && !isPathAbsSlashed )
            return path;

         if( isPathNetworked )
            return path;   // network path resolving

         if( relativeTo == null )
            relativeTo = PluginBase.MainForm.StandaloneMode ? AppDir : UserAppDir;

         String resolvedPath = null;

         if( isPathAbsSlashed )
            resolvedPath = Path.GetPathRoot( relativeTo ) + path.Substring( 1 );   // absolute slashed path resolving
         else
            resolvedPath = Path.Combine( relativeTo, path );   // relative path resolving

         if( checkResolvedPathExisting && !(Directory.Exists( resolvedPath ) || File.Exists( resolvedPath )) )
            resolvedPath = null;

         return resolvedPath;
        }

      /* OLD VERSION
      public static string ResolvePath( String path, String relativeTo )
      {
         String combine;
         if( Path.IsPathRooted( path ) ) return path;
         if( path == null || path.Length == 0 ) return null;
         if( relativeTo != null )
         {
            combine = Path.Combine( relativeTo, path );
            if( Directory.Exists( combine ) || File.Exists( combine ) ) return combine;
         }
         if( !PluginBase.MainForm.StandaloneMode )
         {
            combine = Path.Combine( UserAppDir, path );
            if( Directory.Exists( combine ) || File.Exists( combine ) ) return combine;
         }
         combine = Path.Combine( AppDir, path );
         if( Directory.Exists( combine ) || File.Exists( combine ) ) return combine;
         return null;
      }
      */



BuildActions.cs
Quote:
GetCompilerPath() (changed: partial)
Code:
   static public string GetCompilerPath(Project project)
   {
      if (project.Language == "as3" && (project as AS3Project).CompilerOptions.CustomSDK.Length > 0)
      {
         usingProjectDefinedCompiler = true;
         return PathHelper.ResolvePath((project as AS3Project).CompilerOptions.CustomSDK, project.Directory);
      }
      usingProjectDefinedCompiler = false;

      Hashtable info = new Hashtable();
      info["language"] = project.Language;
      DataEvent de = new DataEvent(EventType.Command, "ASCompletion.GetCompilerPath", info);
      EventManager.DispatchEvent(project, de);
      if( de.Handled && info.ContainsKey( "compiler" ) )
      {
      //   return PathHelper.ResolvePath(info["compiler"] as string, project.Directory);
/*!*/      return PathHelper.ResolvePath( info["compiler"] as string, PathHelper.AppDir ); // AppDir because it's not a custom SDK for project
      }
      else
      {
         return null;
      }
   }



Wed Jan 26, 2011 6:17 am
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
i.o., could you create a SVN patch? It's very easy from TortoiseSVN.


Wed Jan 26, 2011 9:09 am
Profile WWW
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
If you will explain me how to do it - sure, no problem, I'm using Tortoise SVN ;)
And actually I've modifed r1537.

Wait a second...


Wed Jan 26, 2011 11:45 am
Profile
Member

Joined: Fri Jul 30, 2010 2:28 am
Posts: 118
Reply with quote
Here we are:
Code:
Index: External/Plugins/ProjectManager/Actions/BuildActions.cs
===================================================================
--- External/Plugins/ProjectManager/Actions/BuildActions.cs   (revision 1537)
+++ External/Plugins/ProjectManager/Actions/BuildActions.cs   (working copy)
@@ -204,11 +204,15 @@
             info["language"] = project.Language;
             DataEvent de = new DataEvent(EventType.Command, "ASCompletion.GetCompilerPath", info);
             EventManager.DispatchEvent(project, de);
-            if (de.Handled && info.ContainsKey("compiler"))
-            {
-                return PathHelper.ResolvePath(info["compiler"] as string, project.Directory);
-            }
-            else return null;
+         if( de.Handled && info.ContainsKey( "compiler" ) )
+         {
+         //   return PathHelper.ResolvePath(info["compiler"] as string, project.Directory);
+            return PathHelper.ResolvePath( info["compiler"] as string, PathHelper.AppDir );   // AppDir because it's not a custom SDK for project
+         }
+         else
+         {
+            return null;
+         }
         }
 
         void OnBuildComplete(bool runOutput)
Index: External/Plugins/ProjectManager/Helpers/FlexCompilerShell.cs
===================================================================
--- External/Plugins/ProjectManager/Helpers/FlexCompilerShell.cs   (revision 1537)
+++ External/Plugins/ProjectManager/Helpers/FlexCompilerShell.cs   (working copy)
@@ -34,7 +34,11 @@
         static string lastArguments;
         static int lastCompileID;
 
-        string Initialize(string jvmarg, string projectPath)
+
+      //
+      //   adding additional argument "javaExe", that is resolved path to "java.exe"
+      //
+      string Initialize( string jvmarg, string projectPath, string javaExe )
         {
             errorList = new List<string>();
          warningList = new List<string>();
@@ -56,9 +60,10 @@
             process.StartInfo.StandardOutputEncoding = Encoding.Default;
             process.StartInfo.StandardErrorEncoding = Encoding.Default;
             process.StartInfo.CreateNoWindow = true;
-            process.StartInfo.FileName = "java.exe";
+         process.StartInfo.FileName = javaExe;
             process.StartInfo.Arguments = jvmarg;
             process.StartInfo.WorkingDirectory = workingDir;
+
             try
             {
                 process.Start();
@@ -81,32 +86,59 @@
             throw new Exception("Process Exited");
         }
 
-        public void Compile(string projectPath, bool configChanged, string arguments,
-            out string output, out string[] errors, out string[] warnings, string jvmarg)
-        {
-            StringBuilder o = new StringBuilder();
-           
-            // shut down fcsh if our working path has changed
-            if (projectPath != workingDir) Cleanup();
-           
-            // start up fcsh if necessary
-         if (process == null || process.HasExited)
-            o.AppendLine("INITIALIZING: " + Initialize(jvmarg, projectPath));
+
+
+
+      public void Compile( string projectPath,
+                      bool configChanged,
+                      string arguments,
+                      out string output,
+                      out string[] errors,
+                      out string[] warnings,
+                      string jvmarg )
+      {
+         Compile( projectPath, configChanged, arguments, out output, out errors, out warnings, jvmarg, "java.exe" /*or JvmConfigHelper.GetJavaEXE( null )*/ );
+      }
+
+      //
+      //   overloading "Compile()" with additional argument "javaExe", that is resolved path to "java.exe"
+      //
+      public void Compile( string projectPath,
+                      bool configChanged,
+                      string arguments,
+                      out string output,
+                      out string[] errors,
+                      out string[] warnings,
+                      string jvmarg,
+      /*!*/                string javaExe )
+      {
+         StringBuilder o = new StringBuilder();
+
+         // shut down fcsh if our working path has changed
+         if( projectPath != workingDir )
+            Cleanup();
+
+         // start up fcsh if necessary
+         if( process == null || process.HasExited )
+            /*!*/
+            o.AppendLine( "INITIALIZING: " + Initialize( jvmarg, projectPath, javaExe ) );
          else
+            errorList.Clear();
+
+         // success?
+         if( process != null )
          {
-            errorList.Clear();
-            warningList.Clear();
+            /*!*/
+            o.AppendLine( "Starting java as " + process.StartInfo.FileName + "" );
          }
-
-            // success?
-            if (process == null)
-            {
-                output = o.ToString();
-                errorList.Add("Could not compile because the fcsh process could not be started.");
-                errors = errorList.ToArray();
+         else
+         {
+            output = o.ToString();
+            errorList.Add( "Could not compile because the fcsh process could not be started." );
+            errors = errorList.ToArray();
             warnings = warningList.ToArray();
-                return;
-            }
+            return;
+         }
 
             if (arguments != lastArguments)
             {
@@ -139,7 +171,7 @@
                 // force a fresh compile
                 lastCompileID = 0;
                 lastArguments = null;
-                Compile(projectPath, true, arguments, out output, out errors, out warnings, jvmarg);
+            Compile( projectPath, true, arguments, out output, out errors, out warnings, jvmarg, javaExe );
                 return;
             }
             
Index: External/Tools/FDBuild/Building/AS3/AS3ProjectBuilder.cs
===================================================================
--- External/Tools/FDBuild/Building/AS3/AS3ProjectBuilder.cs   (revision 1537)
+++ External/Tools/FDBuild/Building/AS3/AS3ProjectBuilder.cs   (working copy)
@@ -7,7 +7,9 @@
 using System.IO;
 using FDBuild.Building.AS3;
 using System.Collections;
+using PluginCore.PluginCore.Helpers;
 
+
 namespace ProjectManager.Building.AS3
 {
     public class AS3ProjectBuilder : ProjectBuilder
@@ -24,7 +26,7 @@
             : base(project, compilerPath)
         {
             this.project = project;
-
+         
             DetectFlexSdk(compilerPath);
 
             bool hostedInFD = (ipcName != null && ipcName != "");
@@ -68,11 +70,15 @@
                     flexsdkPath = reader.ReadLine();
                 }
             }
-            if (Path.GetFileName(flexsdkPath) == "bin") flexsdkPath = Path.GetDirectoryName(flexsdkPath);
+
+            if (Path.GetFileName(flexsdkPath) == "bin")
+            flexsdkPath = Path.GetDirectoryName(flexsdkPath);
+
             sdkPath = flexsdkPath;
             mxmlcPath = Path.Combine(Path.Combine(flexsdkPath, "lib"), "mxmlc.jar");
             fcshPath = Path.Combine(Path.Combine(flexsdkPath, "lib"), "fcsh.jar");
             jvmConfig = PluginCore.PluginCore.Helpers.JvmConfigHelper.ReadConfig(Path.Combine(flexsdkPath, "bin\\jvm.config"));
+
             if (jvmConfig.ContainsKey("java.args") && jvmConfig["java.args"].ToString().Trim().Length > 0)
                 VMARGS = jvmConfig["java.args"].ToString();
         }
@@ -147,7 +153,7 @@
                 string[] errors;
             string[] warnings;
                 string jvmarg = VMARGS + " -Dapplication.home=\""+ sdkPath + "\" -jar \"" + fcshPath + "\"";
-                fcsh.Compile(workingdir, configChanged, arguments, out output, out errors, out warnings, jvmarg);
+            fcsh.Compile( workingdir, configChanged, arguments, out output, out errors, out warnings, jvmarg, JvmConfigHelper.GetJavaEXE( jvmConfig, sdkPath ) );
 
                 string[] lines = output.Split('\n');
                 foreach (string line in lines)
@@ -166,7 +172,7 @@
             else
             {
                 string jvmarg = VMARGS + " -jar \"" + mxmlcPath + "\" +flexlib=\"" + Path.Combine(sdkPath, "frameworks") + "\" ";
-                if (!ProcessRunner.Run("java.exe", jvmarg + arguments, false))
+            if( !ProcessRunner.Run( JvmConfigHelper.GetJavaEXE( jvmConfig, sdkPath ), jvmarg + arguments, false ) )
                     throw new BuildException("Build halted with errors (mxmlc).");
             }
         }
Index: PluginCore/PluginCore/Helpers/JvmConfigHelper.cs
===================================================================
--- PluginCore/PluginCore/Helpers/JvmConfigHelper.cs   (revision 1537)
+++ PluginCore/PluginCore/Helpers/JvmConfigHelper.cs   (working copy)
@@ -44,11 +44,67 @@
             return config;
         }
 
-        public static string GetJavaEXE(Hashtable jvmConfig)
-        {
-            string home = jvmConfig["java.home"] as string;
-            if (home.Length > 0) return Path.Combine(home, "bin\\java.exe");
-            else return "java.exe"; // rely on environment path
-        }
+
+      
+      public static string GetJavaEXE()
+      {
+         return GetJavaEXE( null, null );
+      }
+      public static string GetJavaEXE( Hashtable jvmConfig )
+      {
+         return GetJavaEXE( jvmConfig, null );
+      }
+      public static string GetJavaEXE( Hashtable jvmConfig, string flexSdkPath )
+      {
+         // default java location. Needing to get it from ENV JAVA_HOME if it's set. Else - set to "java.exe"
+         string p = "java.exe";
+
+         if( jvmConfig == null )
+            return p;
+
+         string home = ResolvePath( jvmConfig["java.home"] as string, flexSdkPath, true );
+
+         if( home != null && home.Length > 0 )
+            p = Path.Combine( home, "bin\\java.exe" );
+
+         return p;
+      }
+
+
+      // This is duplicate of 'PathHelper.ResolvePath()'
+      // because I don't have idea how to use PathHelper.ResolvePath here
+      // because JvmConfigHelper using in external tool 'FDBuild'
+      // and it doesn't see namespace PluginCore.Managers
+      // because doesn't have reference to PluginCore.dll
+      private static string ResolvePath( String path, String relativeTo, Boolean checkResolvedPathExisting )
+      {
+         if( path == null || path.Length == 0 )
+            return null;
+
+         Boolean isPathNetworked = (Boolean) (path.IndexOf( "\\\\" ) == 0 || path.IndexOf( "//" ) == 0);
+         Boolean isPathAbsSlashed = (Boolean) (path.IndexOf( "\\" ) == 0 || path.IndexOf( "/" ) == 0) && !isPathNetworked;
+
+         if( Path.IsPathRooted( path ) && !isPathNetworked && !isPathAbsSlashed )
+            return path;
+
+         if( isPathNetworked )
+            return path;   // network path resolving
+
+         if( relativeTo == null )
+            relativeTo = "C:\\";
+
+         String resolvedPath = null;
+
+         if( isPathAbsSlashed )
+            resolvedPath = Path.GetPathRoot( relativeTo ) + path.Substring( 1 );   // absolute slashed path resolving
+         else
+            resolvedPath = Path.Combine( relativeTo, path );   // relative path resolving
+
+         if( checkResolvedPathExisting && !(Directory.Exists( resolvedPath ) || File.Exists( resolvedPath )) )
+            resolvedPath = null;
+
+         return resolvedPath;
+      }
+
     }
 }
Index: PluginCore/PluginCore/Helpers/PathHelper.cs
===================================================================
--- PluginCore/PluginCore/Helpers/PathHelper.cs   (revision 1537)
+++ PluginCore/PluginCore/Helpers/PathHelper.cs   (working copy)
@@ -177,14 +177,16 @@
             }
         }
 
+
+
         /// <summary>
         /// Resolve a path which may be:
         /// - absolute or
         /// - relative to base path
         /// </summary>
-        public static string ResolvePath(String path)
+        public static string ResolvePath( String path )
         {
-            return ResolvePath(path, null);
+            return ResolvePath( path, null, true );
         }
 
         /// <summary>
@@ -193,26 +195,71 @@
         /// - relative to a specified path, or
         /// - relative to base path
         /// </summary>
-        public static string ResolvePath(String path, String relativeTo)
+      public static string ResolvePath( String path, String relativeTo )
+      {
+         return ResolvePath( path, relativeTo, true );
+      }
+
+      /// <summary>
+      /// Resolve a path which may be:
+      /// - absolute or
+      /// - relative to a specified path, or
+      /// - relative to base path
+      /// </summary>
+        public static string ResolvePath( String path, String relativeTo, Boolean checkResolvedPathExisting )
         {
-            String combine;
-            if (path == null || path.Length == 0) return null;
-            if (Path.IsPathRooted(path)) return path;
-            if (relativeTo != null)
-            {
-                combine = Path.Combine(relativeTo, path);
-                if (Directory.Exists(combine) || File.Exists(combine)) return combine;
-            }
-            if (!PluginBase.MainForm.StandaloneMode)
-            {
-                combine = Path.Combine(UserAppDir, path);
-                if (Directory.Exists(combine) || File.Exists(combine)) return combine;
-            }
-            combine = Path.Combine(AppDir, path);
-            if (Directory.Exists(combine) || File.Exists(combine)) return combine;
-            return null;
+         if( path == null || path.Length == 0 )
+            return null;
+
+         Boolean isPathNetworked = (Boolean) (path.IndexOf( "\\\\" ) == 0 || path.IndexOf( "//" ) == 0);
+         Boolean isPathAbsSlashed = (Boolean) (path.IndexOf( "\\" ) == 0 || path.IndexOf( "/" ) == 0) && !isPathNetworked;
+
+         if( Path.IsPathRooted( path ) && !isPathNetworked && !isPathAbsSlashed )
+            return path;
+
+         if( isPathNetworked )
+            return path;   // network path resolving
+
+         if( relativeTo == null )
+            relativeTo = PluginBase.MainForm.StandaloneMode ? AppDir : UserAppDir;
+
+         String resolvedPath = null;
+
+         if( isPathAbsSlashed )
+            resolvedPath = Path.GetPathRoot( relativeTo ) + path.Substring( 1 );   // absolute slashed path resolving
+         else
+            resolvedPath = Path.Combine( relativeTo, path );   // relative path resolving
+
+         if( checkResolvedPathExisting && !(Directory.Exists( resolvedPath ) || File.Exists( resolvedPath )) )
+            resolvedPath = null;
+
+         return resolvedPath;
         }
 
+      /* OLD VERSION
+      public static string ResolvePath( String path, String relativeTo )
+      {
+         String combine;
+         if( Path.IsPathRooted( path ) ) return path;
+         if( path == null || path.Length == 0 ) return null;
+         if( relativeTo != null )
+         {
+            combine = Path.Combine( relativeTo, path );
+            if( Directory.Exists( combine ) || File.Exists( combine ) ) return combine;
+         }
+         if( !PluginBase.MainForm.StandaloneMode )
+         {
+            combine = Path.Combine( UserAppDir, path );
+            if( Directory.Exists( combine ) || File.Exists( combine ) ) return combine;
+         }
+         combine = Path.Combine( AppDir, path );
+         if( Directory.Exists( combine ) || File.Exists( combine ) ) return combine;
+         return null;
+      }
+      */
+
+
+
         /// <summary>
         /// Converts a long path to a short representative one using ellipsis if necessary
         /// </summary>



Wed Jan 26, 2011 12:03 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 26 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


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

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