public void Load (HaxeProject project)
		{
			mProject = project;
			
			TargetHXMLFileEntry.Text = mProject.TargetHXMLFile;
			AdditionalArgumentsEntry.Text = mProject.AdditionalArguments;
		}
Exemplo n.º 2
0
        private string[] BuildNmeCommand(string[] extraClasspaths, string output, string target, bool noTrace, string extraArgs)
        {
            List <String> pr = new List <String>();

            string builder = HaxeProject.GetBuilder(output);

            if (builder == null)
            {
                builder = "openfl";
            }

            pr.Add("run " + builder + " build");
            pr.Add(Quote(output));
            pr.Add(target);
            if (!noTrace)
            {
                pr.Add("-debug");
                if (target.StartsWith("flash"))
                {
                    pr.Add("-Dfdb");
                }
            }
            if (extraArgs != null)
            {
                pr.Add(extraArgs);
            }

            return(pr.ToArray());
        }
Exemplo n.º 3
0
        static void ParserOutputFile(HaxeProject project, BuildResult result, StringBuilder output, string filename)
        {
            StreamReader reader = File.OpenText(filename);

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                output.AppendLine(line);

                line = line.Trim();
                if (line.Length == 0 || line.StartsWith("\t"))
                {
                    continue;
                }

                BuildError error = CreateErrorFromString(project, line);
                if (error != null)
                {
                    result.Append(error);
                }
            }

            reader.Close();
        }
Exemplo n.º 4
0
        public TestClassRunner( )
        {
            if (this.checkRunFromValidClass())
            {
                this.notifyTestStart();

                HaxeProject project = (HaxeProject)PluginBase.CurrentProject;

                this.generateDocumentClassFromTemplate();

                this.storeOrigDocumentClass(project);

                this.setDocumentClass(project, Path.Combine(Path.GetDirectoryName(project.ProjectPath), this.tempDocumentClass));


                this.build();

                //TODO: figure out the build finished event
                Thread.Sleep(1500);

                this.setDocumentClass(project, this.origDocumentPath);

                this.cleanup();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        private bool CheckCurrent()
        {
            try
            {
                IProject project = PluginBase.CurrentProject;
                if (project == null || !project.EnableInteractiveDebugger)
                {
                    return(false);
                }
                currentProject = project as Project;

                // ignore non-flash haxe targets
                if (project is HaxeProject)
                {
                    HaxeProject hproj = project as HaxeProject;
                    if (hproj.MovieOptions.Platform == HaxeMovieOptions.NME_PLATFORM &&
                        (hproj.TargetBuild != null && !hproj.TargetBuild.StartsWith("flash")))
                    {
                        return(false);
                    }
                }
                // Give a console warning for non external player...
                if (currentProject.TestMovieBehavior == TestMovieBehavior.NewTab || currentProject.TestMovieBehavior == TestMovieBehavior.NewWindow)
                {
                    TraceManager.Add(TextHelper.GetString("Info.CannotDebugActiveXPlayer"));
                    return(false);
                }
            }
            catch (Exception e)
            {
                ErrorManager.ShowError(e);
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        public void Load(HaxeProject project)
        {
            mProject = project;

            TargetHXMLFileEntry.Text      = mProject.TargetHXMLFile;
            AdditionalArgumentsEntry.Text = mProject.AdditionalArguments;
        }
Exemplo n.º 7
0
        private static void UpdateProject()
        {
            string haxelib = GetHaxelib(hxproj);

            if (haxelib == "haxelib")
            {
                TraceManager.AddAsync("Haxelib not found", -3);
                return;
            }

            string builder = HaxeProject.GetBuilder(hxproj);

            if (builder == null)
            {
                TraceManager.AddAsync("Project config not found:\n" + hxproj.OutputPathAbsolute, -3);
                return;
            }

            string config = hxproj.TargetBuild;

            if (String.IsNullOrEmpty(config))
            {
                config = "flash";
            }

            ProcessStartInfo pi = new ProcessStartInfo();

            pi.FileName               = haxelib;
            pi.Arguments              = "run " + builder + " display \"" + hxproj.GetRelativePath(nmmlPath) + "\" " + config;
            pi.RedirectStandardError  = true;
            pi.RedirectStandardOutput = true;
            pi.UseShellExecute        = false;
            pi.CreateNoWindow         = true;
            pi.WorkingDirectory       = Path.GetDirectoryName(hxproj.ProjectPath);
            pi.WindowStyle            = ProcessWindowStyle.Hidden;
            Process p = Process.Start(pi);

            p.WaitForExit(5000);

            string hxml = p.StandardOutput.ReadToEnd();
            string err  = p.StandardError.ReadToEnd();

            p.Close();

            if (string.IsNullOrEmpty(hxml) || (!string.IsNullOrEmpty(err) && err.Trim().Length > 0))
            {
                if (string.IsNullOrEmpty(err))
                {
                    err = "Haxelib error: no response";
                }
                TraceManager.AddAsync(err, -3);
                hxproj.RawHXML = null;
            }
            else
            {
                hxproj.RawHXML = Regex.Split(hxml, "[\r\n]+");
            }
        }
Exemplo n.º 8
0
        internal string ImportProject(string importFrom)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Title  = TextHelper.GetString("Title.ImportProject");
                dialog.Filter = TextHelper.GetString("Info.ImportProjectFilter");
                if (importFrom == "hxml")
                {
                    dialog.FilterIndex = 3;
                }
                if (dialog.ShowDialog() == DialogResult.OK && File.Exists(dialog.FileName))
                {
                    string fileName         = dialog.FileName;
                    string currentDirectory = Directory.GetCurrentDirectory();
                    try
                    {
                        if (FileInspector.IsHxml(Path.GetExtension(fileName).ToLower()))
                        {
                            var project = HaxeProject.Load(fileName);
                            var path    = Path.GetDirectoryName(project.ProjectPath);
                            var name    = Path.GetFileNameWithoutExtension(project.OutputPath);
                            var newPath = Path.Combine(path, $"{name}.hxproj");
                            PatchProject(project);
                            PatchHxmlProject(project);
                            project.SaveAs(newPath);
                            return(newPath);
                        }
                        if (FileInspector.IsFlexBuilderPackagedProject(fileName))
                        {
                            fileName = ExtractPackagedProject(fileName);
                        }
                        if (FileInspector.IsFlexBuilderProject(fileName))
                        {
                            AS3Project imported = AS3Project.Load(fileName);
                            string     path     = Path.GetDirectoryName(imported.ProjectPath);
                            string     name     = Path.GetFileNameWithoutExtension(imported.OutputPath);
                            string     newPath  = Path.Combine(path, name + ".as3proj");
                            PatchProject(imported);
                            PatchFbProject(imported);
                            imported.SaveAs(newPath);

                            return(newPath);
                        }
                        ErrorManager.ShowInfo(TextHelper.GetString("Info.NotValidFlashBuilderProject"));
                    }
                    catch (Exception exception)
                    {
                        Directory.SetCurrentDirectory(currentDirectory);
                        string msg = TextHelper.GetString("Info.CouldNotOpenProject");
                        ErrorManager.ShowInfo(msg + " " + exception.Message);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 9
0
        static BuildResult ParseOutput(HaxeProject project, string stderr)
        {
            BuildResult result = new BuildResult();

            StringBuilder output = new StringBuilder();

            ParserOutputFile(project, result, output, stderr);

            result.CompilerOutput = output.ToString();

            return(result);
        }
Exemplo n.º 10
0
        public HaxeProjectBuilder(HaxeProject project, string compilerPath)
            : base(project, compilerPath)
        {
            this.project = project;

            string basePath = compilerPath ?? @"C:\Motion-Twin\haxe"; // default installation

            haxePath = Path.Combine(basePath, "haxe.exe");
            if (!File.Exists(haxePath))
            {
                haxePath = "haxe.exe"; // hope you have it in your environment path!
            }
        }
Exemplo n.º 11
0
        private void storeOrigDocumentClass(HaxeProject project)
        {
            string origMain    = project.CompilerOptions.MainClass.Replace(".", "\\");
            string projectPath = Path.GetDirectoryName(project.ProjectPath);

            foreach (string cp in project.AbsoluteClasspaths)
            {
                if (File.Exists(Path.Combine(cp, origMain + ".hx")))
                {
                    this.origDocumentPath = Path.Combine(cp, origMain + ".hx");
                    break;
                }
            }
        }
Exemplo n.º 12
0
        static internal bool HandleProject(IProject project)
        {
            HaxeProject hxproj = project as HaxeProject;

            if (hxproj == null)
            {
                return(false);
            }
            if (!hxproj.MovieOptions.HasPlatformSupport)
            {
                return(false);
            }
            return(hxproj.MovieOptions.PlatformSupport.ExternalToolchain != null);
        }
Exemplo n.º 13
0
        public static void Run(HaxeProject project, HaxeProjectConfiguration configuration, IProgressMonitor monitor, ExecutionContext context)
        {
            ExecutionCommand cmd = CreateExecutionCommand(project, configuration);

            if (cmd is HaxeExecutionCommand)
            {
                IConsole console;
                if (configuration.ExternalConsole)
                {
                    console = context.ExternalConsoleFactory.CreateConsole(false);
                }
                else
                {
                    console = context.ConsoleFactory.CreateConsole(false);
                }

                AggregatedOperationMonitor operationMonitor = new AggregatedOperationMonitor(monitor);

                try
                {
                    if (!context.ExecutionHandler.CanExecute(cmd))
                    {
                        monitor.ReportError(String.Format("Cannot execute '{0}'.", cmd.Target), null);
                        return;
                    }

                    IProcessAsyncOperation operation = context.ExecutionHandler.Execute(cmd, console);

                    operationMonitor.AddOperation(operation);
                    operation.WaitForCompleted();

                    monitor.Log.WriteLine("Player exited with code {0}.", operation.ExitCode);
                }
                catch (Exception)
                {
                    monitor.ReportError(String.Format("Error while executing '{0}'.", cmd.Target), null);
                }
                finally
                {
                    operationMonitor.Dispose();
                    console.Dispose();
                }
            }
            //else
            //{
            //	Process.Start (cmd);
            //}
        }
Exemplo n.º 14
0
        public static bool CanRun(HaxeProject project, HaxeProjectConfiguration configuration, ExecutionContext context)
        {
            // need to optimize so this caches the result

            ExecutionCommand cmd = CreateExecutionCommand(project, configuration);

            if (cmd == null)
            {
                return(false);
            }
            else if (cmd is HaxeExecutionCommand)
            {
                return(context.ExecutionHandler.CanExecute(cmd));
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 15
0
        static public void Clean(IProject project)
        {
            if (!(project is HaxeProject))
            {
                return;
            }
            HaxeProject hxproj = project as HaxeProject;

            if (hxproj.MovieOptions.Platform != HaxeMovieOptions.NME_PLATFORM)
            {
                return;
            }

            string builder = HaxeProject.GetBuilder(hxproj);

            if (builder == null)
            {
                return;
            }

            string haxelib = GetHaxelib(hxproj);
            string config  = hxproj.TargetBuild;

            if (String.IsNullOrEmpty(config))
            {
                config = "flash";
            }

            ProcessStartInfo pi = new ProcessStartInfo();

            pi.FileName         = haxelib;
            pi.Arguments        = " run " + builder + " clean \"" + hxproj.OutputPathAbsolute + "\" " + config;
            pi.UseShellExecute  = false;
            pi.CreateNoWindow   = true;
            pi.WorkingDirectory = Path.GetDirectoryName(hxproj.ProjectPath);
            pi.WindowStyle      = ProcessWindowStyle.Hidden;
            Process p = Process.Start(pi);

            p.WaitForExit(5000);
            p.Close();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Watch NME projects to update the configuration & HXML command using 'nme display'
        /// </summary>
        /// <param name="project"></param>
        static public void Monitor(IProject project)
        {
            if (updater == null)
            {
                updater                     = new System.Timers.Timer();
                updater.Interval            = 200;
                updater.SynchronizingObject = PluginCore.PluginBase.MainForm as System.Windows.Forms.Form;
                updater.Elapsed            += updater_Elapsed;
                updater.AutoReset           = false;
            }

            hxproj = null;
            StopWatcher();

            if (project is HaxeProject)
            {
                hxproj = project as HaxeProject;
                hxproj.ProjectUpdating += new ProjectUpdatingHandler(hxproj_ProjectUpdating);
                hxproj_ProjectUpdating(hxproj);
            }
        }
Exemplo n.º 17
0
        static internal bool Clean(IProject project)
        {
            if (!HandleProject(project))
            {
                return(false);
            }
            HaxeProject hxproj = project as HaxeProject;

            var toolchain = hxproj.MovieOptions.PlatformSupport.ExternalToolchain;
            var exe       = GetExecutable(toolchain);

            if (exe == null)
            {
                return(false);
            }

            string args = GetCommand(hxproj, "clean");

            if (args == null)
            {
                return(false);
            }

            TraceManager.Add(toolchain + " " + args);

            ProcessStartInfo pi = new ProcessStartInfo();

            pi.FileName         = Environment.ExpandEnvironmentVariables(exe);
            pi.Arguments        = args;
            pi.UseShellExecute  = false;
            pi.CreateNoWindow   = true;
            pi.WorkingDirectory = Path.GetDirectoryName(hxproj.ProjectPath);
            pi.WindowStyle      = ProcessWindowStyle.Hidden;
            Process p = Process.Start(pi);

            p.WaitForExit(5000);
            p.Close();
            return(true);
        }
Exemplo n.º 18
0
        static string GetCommand(HaxeProject project, string name, bool processArguments)
        {
            var platform = project.MovieOptions.PlatformSupport;
            var version  = platform.GetVersion(project.MovieOptions.Version);

            if (version.Commands == null)
            {
                throw new Exception(String.Format("No external commands found for target {0} and version {1}",
                                                  project.MovieOptions.Platform, project.MovieOptions.Version));
            }
            if (version.Commands.ContainsKey(name))
            {
                var cmd = version.Commands[name].Value;
                if (platform.ExternalToolchain == "haxelib")
                {
                    cmd = "run " + cmd;
                }
                else if (platform.ExternalToolchain == "cmd")
                {
                    cmd = "/c " + cmd;
                }

                if (!processArguments)
                {
                    return(cmd);
                }
                else
                {
                    return(PluginBase.MainForm.ProcessArgString(cmd));
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 19
0
        private void initProcess(bool completionMode)
        {
            // check haxe project & context
            if (PluginBase.CurrentProject == null || !(PluginBase.CurrentProject is HaxeProject) ||
                !(Context.Context is HaXeContext.Context))
            {
                return;
            }

            PluginBase.MainForm.CallCommand("SaveAllModified", null);

            HaxeProject hp = (PluginBase.CurrentProject as HaxeProject);

            // Current file
            string file = PluginBase.MainForm.CurrentDocument.FileName;

            // Locate carret position
            Int32 pos = position + 1; // sci.CurrentPos;

            // locate a . or (
            while (pos > 1 && sci.CharAt(pos - 1) != '.' && sci.CharAt(pos - 1) != '(')
            {
                pos--;
            }

            try
            {
                Byte[]     bom = new Byte[4];
                FileStream fs  = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
                if (fs.CanSeek)
                {
                    fs.Read(bom, 0, 4);
                    fs.Close();
                    if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf)
                    {
                        pos += 3; // Skip BOM
                    }
                }
            }
            catch {}

            // Build haXe command
            string[] paths = ProjectManager.PluginMain.Settings.GlobalClasspaths.ToArray();
            string   hxml  = String.Join(" ", hp.BuildHXML(paths, "__nothing__", true));

            // Get the current class edited (ensure completion even if class not reference in the project)
            int    start   = file.LastIndexOf("\\") + 1;
            int    end     = file.LastIndexOf(".");
            string package = Context.Context.CurrentModel.Package;

            if (package != "")
            {
                string cl       = Context.Context.CurrentModel.Package + "." + file.Substring(start, end - start);
                string libToAdd = file.Split(new string[] { "\\" + String.Join("\\", cl.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)) }, StringSplitOptions.RemoveEmptyEntries).GetValue(0).ToString();
                hxml = hxml + " " + "-cp \"" + libToAdd + "\" " + cl;
            }
            else
            {
                hxml = hxml + " " + file.Substring(start, end - start);
            }

            // Build haXe built-in completion/check syntax command
            string args = completionMode
                ? "--display \"" + file + "\"@" + pos.ToString() + " " + hxml
                : "--no-output " + hxml;

            // compiler path
            string haxePath       = Environment.GetEnvironmentVariable("HAXEPATH");
            string customHaxePath = (Context.Context.Settings as HaXeSettings).HaXePath;

            if (customHaxePath != null && customHaxePath.Length > 0)
            {
                haxePath = PathHelper.ResolvePath(customHaxePath);
            }

            string process = Path.Combine(haxePath, "haxe.exe");

            if (!File.Exists(process))
            {
                ErrorManager.ShowInfo(String.Format(TextHelper.GetString("Info.HaXeExeError"), "\n"));
                p = null;
                return;
            }

            // Run haXe compiler
            p = new Process();
            p.StartInfo.FileName              = process;
            p.StartInfo.Arguments             = args;
            p.StartInfo.UseShellExecute       = false;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow        = true;
            p.StartInfo.WindowStyle           = ProcessWindowStyle.Hidden;
            p.StartInfo.WorkingDirectory      = hp.Directory;
            p.EnableRaisingEvents             = true;
        }
Exemplo n.º 20
0
        private static BuildError CreateErrorFromString(HaxeProject project, string text)
        {
            Match match = mErrorIgnore.Match(text);

            if (match.Success)
            {
                return(null);
            }

            match = mErrorFull.Match(text);
            if (!match.Success)
            {
                match = mErrorCmdLine.Match(text);
            }
            if (!match.Success)
            {
                match = mErrorFileChar.Match(text);
            }
            if (!match.Success)
            {
                match = mErrorFileChars.Match(text);
            }
            if (!match.Success)
            {
                match = mErrorFile.Match(text);
            }

            if (!match.Success)
            {
                match = mErrorSimple.Match(text);
            }
            if (!match.Success)
            {
                return(null);
            }

            int n;

            BuildError error = new BuildError();

            error.FileName  = match.Result("${file}") ?? "";
            error.IsWarning = match.Result("${level}").ToLower() == "warning";
            error.ErrorText = match.Result("${message}");

            if (error.FileName == "${file}")
            {
                error.FileName = "";
            }
            else
            {
                if (!File.Exists(error.FileName))
                {
                    if (File.Exists(Path.GetFullPath(error.FileName)))
                    {
                        error.FileName = Path.GetFullPath(error.FileName);
                    }
                    else
                    {
                        error.FileName = Path.Combine(project.BaseDirectory, error.FileName);
                    }
                }
            }

            if (Int32.TryParse(match.Result("${line}"), out n))
            {
                error.Line = n;
            }
            else
            {
                error.Line = 0;
            }

            if (Int32.TryParse(match.Result("${column}"), out n))
            {
                error.Column = n + 1;               //haxe counts zero based
            }
            else
            {
                error.Column = -1;
            }

            return(error);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Get build/run/clean commands
 /// </summary>
 static string GetCommand(HaxeProject project, string name)
 {
     return(GetCommand(project, name, true));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Classpathes & classes cache initialisation
        /// </summary>
        public override void BuildClassPath()
        {
            ReleaseClasspath();
            started = true;
            if (hxsettings == null)
            {
                throw new Exception("BuildClassPath() must be overridden");
            }

            // external version definition
            // expected from project manager: "9;path;path..."
            flashVersion = hxsettings.DefaultFlashVersion;
            string exPath = externalClassPath ?? "";

            if (exPath.Length > 0)
            {
                try
                {
                    int p = exPath.IndexOf(';');
                    flashVersion = Convert.ToInt16(exPath.Substring(0, p));
                    exPath       = exPath.Substring(p + 1).Trim();
                }
                catch { }
            }

            // NOTE: version > 10 for non-Flash platforms
            string lang = null;

            features.Directives = new List <string>();
            if (IsJavaScriptTarget)
            {
                lang = "js";
                features.Directives.Add(lang);
            }
            else if (IsNekoTarget)
            {
                lang = "neko";
                features.Directives.Add(lang);
            }
            else if (IsPhpTarget)
            {
                lang = "php";
                features.Directives.Add(lang);
            }
            else if (IsCppTarget)
            {
                lang = "cpp";
                features.Directives.Add(lang);
            }
            else
            {
                features.Directives.Add("flash");
                features.Directives.Add("flash" + flashVersion);
                lang = (flashVersion >= 9) ? "flash9" : "flash";
            }
            features.Directives.Add("true");

            //
            // Class pathes
            //
            classPath = new List <PathModel>();
            // haXe std
            if (hxsettings.HaXePath != null)
            {
                string haxeCP = Path.Combine(hxsettings.HaXePath, "std");
                if (Directory.Exists(haxeCP))
                {
                    PathModel std = PathModel.GetModel(haxeCP, this);
                    if (!std.WasExplored && !Settings.LazyClasspathExploration)
                    {
                        PathExplorer stdExplorer = new PathExplorer(this, std);
                        stdExplorer.HideDirectories(new string[] { "flash", "flash9", "js", "neko", "php", "cpp" });
                        stdExplorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(RefreshContextCache);
                        stdExplorer.Run();
                    }
                    AddPath(std);

                    PathModel specific = PathModel.GetModel(Path.Combine(haxeCP, lang), this);
                    if (!specific.WasExplored && !Settings.LazyClasspathExploration)
                    {
                        PathExplorer speExplorer = new PathExplorer(this, specific);
                        speExplorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(RefreshContextCache);
                        speExplorer.Run();
                    }
                    AddPath(specific);
                }
            }
            HaxeProject proj = PluginBase.CurrentProject as HaxeProject;

            // swf-libs
            if (IsFlashTarget && flashVersion >= 9 && proj != null)
            {
                foreach (LibraryAsset asset in proj.LibraryAssets)
                {
                    if (asset.IsSwf)
                    {
                        string path = proj.GetAbsolutePath(asset.Path);
                        if (File.Exists(path))
                        {
                            AddPath(path);
                        }
                    }
                }
                foreach (string p in proj.CompilerOptions.Additional)
                {
                    if (p.IndexOf("-swf-lib ") == 0)
                    {
                        string path = proj.GetAbsolutePath(p.Substring(9));
                        if (File.Exists(path))
                        {
                            AddPath(path);
                        }
                    }
                }
            }

            // add haxe libraries
            if (proj != null)
            {
                foreach (string param in proj.BuildHXML(new string[0], "", false))
                {
                    if (param.IndexOf("-lib ") == 0)
                    {
                        AddPath(LookupLibrary(param.Substring(5)));
                    }
                }
            }


            // add external pathes
            List <PathModel> initCP = classPath;

            classPath = new List <PathModel>();
            string[] cpathes;
            if (exPath.Length > 0)
            {
                cpathes = exPath.Split(';');
                foreach (string cpath in cpathes)
                {
                    AddPath(cpath.Trim());
                }
            }
            // add user pathes from settings
            if (settings.UserClasspath != null && settings.UserClasspath.Length > 0)
            {
                foreach (string cpath in settings.UserClasspath)
                {
                    AddPath(cpath.Trim());
                }
            }
            // add initial pathes
            foreach (PathModel mpath in initCP)
            {
                AddPath(mpath);
            }

            // parse top-level elements
            InitTopLevelElements();
            if (cFile != null)
            {
                UpdateTopLevelElements();
            }

            // add current temporaty path
            if (temporaryPath != null)
            {
                string tempPath = temporaryPath;
                temporaryPath = null;
                SetTemporaryPath(tempPath);
            }
            FinalizeClasspath();
        }
Exemplo n.º 23
0
        private static ExecutionCommand CreateExecutionCommand(HaxeProject project, HaxeProjectConfiguration configuration)
        {
            string hxmlPath = Path.GetFullPath(project.TargetHXMLFile);

            if (!File.Exists(hxmlPath))
            {
                hxmlPath = Path.Combine(project.BaseDirectory, project.TargetHXMLFile);
            }

            string hxml = File.ReadAllText(hxmlPath);

            hxml = hxml.Replace(Environment.NewLine, " ");
            string[] hxmlArgs = hxml.Split(' ');

            List <string> platforms       = new List <string> ();
            List <string> platformOutputs = new List <string> ();

            bool   addNext    = false;
            bool   nextIsMain = false;
            string main       = "";

            foreach (string hxmlArg in hxmlArgs)
            {
                if (addNext)
                {
                    if (!hxmlArg.StartsWith("-"))
                    {
                        if (nextIsMain)
                        {
                            main       = hxmlArg;
                            nextIsMain = false;
                        }
                        else
                        {
                            platformOutputs.Add(hxmlArg);
                        }
                    }
                    else
                    {
                        if (!nextIsMain)
                        {
                            platforms.RemoveAt(platforms.Count - 1);
                        }
                    }
                }

                addNext = true;

                switch (hxmlArg)
                {
                case "-cpp":
                    platforms.Add("cpp");
                    break;

                case "-swf":
                case "-swf9":
                    platforms.Add("flash");
                    break;

                case "-js":
                    platforms.Add("js");
                    break;

                case "-neko":
                    platforms.Add("neko");
                    break;

                case "-php":
                    platforms.Add("php");
                    break;

                case "-main":
                    nextIsMain = true;
                    break;

                default:
                    addNext = false;
                    break;
                }
            }


            int i = 0;

            //for (int i = 0; i < platforms.Count; i++)
            //{
            string platform = platforms[i];
            string output   = platformOutputs[i];

            if (platform == "cpp" || platform == "neko")
            {
                if (platform == "cpp")
                {
                    output = Path.Combine(output, main);
                    if (configuration.DebugMode)
                    {
                        output += "-debug";
                    }
                }

                if (!File.Exists(Path.GetFullPath(output)))
                {
                    output = Path.Combine(project.BaseDirectory, output);
                }

                string exe  = "";
                string args = "";

                if (platform == "cpp")
                {
                    exe = output;
                }
                else
                {
                    exe  = "neko";
                    args = "\"" + output + "\"";
                }

                //NativeExecutionCommand cmd = new NativeExecutionCommand (exe);
                HaxeExecutionCommand cmd = new HaxeExecutionCommand(exe);
                cmd.Arguments        = args;
                cmd.WorkingDirectory = Path.GetDirectoryName(output);

                if (configuration.DebugMode)
                {
                    //	cmd.EnvironmentVariables.Add ("HXCPP_DEBUG_HOST", "gdb");
                    cmd.EnvironmentVariables.Add("HXCPP_DEBUG", "1");
                }
                //cmd.WorkingDirectory = project.BaseDirectory.FullPath;

                //MonoDevelop.Ide.MessageService.ShowMessage (cmd.Command);
                //MonoDevelop.Ide.MessageService.ShowMessage (cmd.Arguments);
                //MonoDevelop.Ide.MessageService.ShowMessage (cmd.WorkingDirectory);

                return(cmd);
            }
            else if (platform == "flash" || platform == "js")
            {
                if (!File.Exists(Path.GetFullPath(output)))
                {
                    output = Path.Combine(project.BaseDirectory, output);
                }

                if (platform == "js")
                {
                    output = Path.Combine(Path.GetDirectoryName(output), "index.html");
                }

                //string target = output;

                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.MacOSX:
                    //target = "open \"" + output + "\"";
                    break;

                case PlatformID.Unix:
                    //target = "xdg-open \"" + output + "\"";
                    break;
                }

                ProcessExecutionCommand cmd = new ProcessExecutionCommand();
                cmd.Command = output;
                return(cmd);
            }
            //}

            return(null);
        }
 public HaxeProjectWriter(HaxeProject project, string filename)
     : base(project, filename)
 {
     this.project = base.Project as HaxeProject;
 }
Exemplo n.º 25
0
        public static BuildResult Compile(HaxeProject project, HaxeProjectConfiguration configuration, IProgressMonitor monitor)
        {
            string exe = "haxe";
            //string args = project.TargetHXMLFile;

            string hxmlPath = Path.GetFullPath(project.TargetHXMLFile);

            if (!File.Exists(hxmlPath))
            {
                hxmlPath = Path.Combine(project.BaseDirectory, project.TargetHXMLFile);
            }

            string hxml = File.ReadAllText(hxmlPath);

            hxml = hxml.Replace(Environment.NewLine, " ");
            string[] hxmlArgs = hxml.Split(' ');

            bool createNext = false;

            foreach (string hxmlArg in hxmlArgs)
            {
                if (createNext)
                {
                    if (!hxmlArg.StartsWith("-"))
                    {
                        string path = Path.GetFullPath(Path.GetDirectoryName(hxmlArg));
                        if (!Directory.Exists(path))
                        {
                            path = Path.Combine(project.BaseDirectory, hxmlArg);
                            if (!Directory.Exists(Path.GetDirectoryName(path)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(path));
                            }
                        }
                    }
                    createNext = false;
                }

                if (hxmlArg == "-js" || hxmlArg == "-swf" || hxmlArg == "-swf9" || hxmlArg == "-neko")
                {
                    createNext = true;
                }
            }

            string args = String.Join(" ", hxmlArgs);

            if (configuration.DebugMode)
            {
                args += " -debug";
            }

            if (project.AdditionalArguments != "")
            {
                args += " " + project.AdditionalArguments;
            }

            if (configuration.AdditionalArguments != "")
            {
                args += " " + configuration.AdditionalArguments;
            }

            string error    = "";
            int    exitCode = DoCompilation(exe, args, project.BaseDirectory, monitor, ref error);

            BuildResult result = ParseOutput(project, error);

            if (result.CompilerOutput.Trim().Length != 0)
            {
                monitor.Log.WriteLine(result.CompilerOutput);
            }

            if (result.ErrorCount == 0 && exitCode != 0)
            {
                string errorMessage = File.ReadAllText(error);
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    result.AddError(errorMessage);
                }
                else
                {
                    result.AddError("Build failed. Go to \"Build Output\" for more information");
                }
            }

            FileService.DeleteFile(error);
            return(result);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Run NME project (after build)
        /// </summary>
        /// <param name="command">Project's custom run command</param>
        /// <returns>Execution handled</returns>
        static public bool Run(string command)
        {
            if (!string.IsNullOrEmpty(command)) // project has custom run command
            {
                return(false);
            }

            HaxeProject project = PluginBase.CurrentProject as HaxeProject;

            if (project == null || project.OutputType != OutputType.Application)
            {
                return(false);
            }

            string builder = HaxeProject.GetBuilder(project);

            if (builder == null)
            {
                return(true);
            }

            string config = project.TargetBuild;

            if (String.IsNullOrEmpty(config))
            {
                config = "flash";
            }
            else if (config.IndexOf("android") >= 0)
            {
                CheckADB();
            }

            if (project.TraceEnabled)
            {
                config += " -debug -Dfdb";
            }
            //if (config.StartsWith("flash") && config.IndexOf("-DSWF_PLAYER") < 0)
            //    config += GetSwfPlayer();

            string args    = "run " + builder + " run \"" + project.OutputPathAbsolute + "\" " + config;
            string haxelib = GetHaxelib(project);

            if (config.StartsWith("html5") && ProjectManager.Actions.Webserver.Enabled && project.RawHXML != null) // webserver
            {
                foreach (string line in project.RawHXML)
                {
                    if (line.StartsWith("-js "))
                    {
                        string path = line.Substring(4);
                        path = path.Substring(0, path.LastIndexOf("/"));
                        ProjectManager.Actions.Webserver.StartServer(project.GetAbsolutePath(path));
                        return(true);
                    }
                }
            }

            TraceManager.Add("haxelib " + args);

            if (config.StartsWith("flash") || config.StartsWith("html5")) // no capture
            {
                if (config.StartsWith("flash") && project.TraceEnabled)   // debugger
                {
                    DataEvent de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null);
                    EventManager.DispatchEvent(project, de);
                    de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", null);
                    EventManager.DispatchEvent(project, de);
                }

                var infos = new ProcessStartInfo(haxelib, args);
                infos.WorkingDirectory = project.Directory;
                infos.WindowStyle      = ProcessWindowStyle.Hidden;
                Process.Start(infos);
            }
            else
            {
                string oldWD = PluginBase.MainForm.WorkingDirectory;
                PluginBase.MainForm.WorkingDirectory = project.Directory;
                PluginBase.MainForm.CallCommand("RunProcessCaptured", haxelib + ";" + args);
                PluginBase.MainForm.WorkingDirectory = oldWD;
            }
            return(true);
        }
Exemplo n.º 27
0
 public HaxeProjectWriter(HaxeProject project, string filename)
     : base(project, filename)
 {
     this.project = base.Project as HaxeProject;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Run project (after build)
        /// </summary>
        /// <param name="command">Project's custom run command</param>
        /// <returns>Execution handled</returns>
        static internal bool Run(string command)
        {
            if (!string.IsNullOrEmpty(command)) // project has custom run command
            {
                return(false);
            }

            HaxeProject hxproj = PluginBase.CurrentProject as HaxeProject;

            if (!HandleProject(hxproj))
            {
                return(false);
            }

            var platform  = hxproj.MovieOptions.PlatformSupport;
            var toolchain = platform.ExternalToolchain;
            var exe       = GetExecutable(toolchain);

            if (exe == null)
            {
                return(false);
            }

            string args = GetCommand(hxproj, "run");

            if (args == null)
            {
                return(false);
            }

            string config = hxproj.TargetBuild;

            if (String.IsNullOrEmpty(config))
            {
                config = "flash";
            }
            else if (config.IndexOfOrdinal("android") >= 0)
            {
                CheckADB();
            }

            if (config.StartsWithOrdinal("html5") && ProjectManager.Actions.Webserver.Enabled && hxproj.RawHXML != null) // webserver
            {
                foreach (string line in hxproj.RawHXML)
                {
                    if (line.StartsWithOrdinal("-js "))
                    {
                        string path = line.Substring(4);
                        path = path.Substring(0, path.LastIndexOf('/'));
                        ProjectManager.Actions.Webserver.StartServer(hxproj.GetAbsolutePath(path));
                        return(true);
                    }
                }
            }

            TraceManager.Add(toolchain + " " + args);

            if (hxproj.TraceEnabled && hxproj.EnableInteractiveDebugger) // debugger
            {
                DataEvent de;
                if (config.StartsWithOrdinal("flash"))
                {
                    de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null);
                    EventManager.DispatchEvent(hxproj, de);
                }
                de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", null);
                EventManager.DispatchEvent(hxproj, de);
            }

            exe = Environment.ExpandEnvironmentVariables(exe);
            if (ShouldCapture(platform.ExternalToolchainCapture, config))
            {
                string oldWD = PluginBase.MainForm.WorkingDirectory;
                PluginBase.MainForm.WorkingDirectory = hxproj.Directory;
                PluginBase.MainForm.CallCommand("RunProcessCaptured", exe + ";" + args);
                PluginBase.MainForm.WorkingDirectory = oldWD;
            }
            else
            {
                var infos = new ProcessStartInfo(exe, args);
                infos.WorkingDirectory = hxproj.Directory;
                infos.WindowStyle      = ProcessWindowStyle.Hidden;
                Process.Start(infos);
            }
            return(true);
        }