public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection projectReferences, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
        {
            NemerleParameters cp = (NemerleParameters) configuration.CompilationParameters;
            if (cp == null) cp = new NemerleParameters ();

            string references = "";
            string files   = "";

            foreach (ProjectReference lib in projectReferences)
                references += " -r \"" + lib.GetReferencedFileName() + "\"";

            foreach (ProjectFile f in projectFiles)
                if (f.Subtype != Subtype.Directory)
                    switch (f.BuildAction)
                    {
                        case BuildAction.Compile:
                            files += " \"" + f.Name + "\"";
                        break;
                    }

            if (!Directory.Exists (configuration.OutputDirectory))
                Directory.CreateDirectory (configuration.OutputDirectory);

            string args = "-q -no-color " + GetOptionsString (configuration, cp) + references + files  + " -o " + configuration.CompiledOutputName;
            return DoCompilation (args);
        }
        public Project()
        {
            Name = "New Project";
            projectReferences = new ProjectReferenceCollection ();
            projectReferences.SetProject (this);

            projectFileWatcher = new FileSystemWatcher();
            projectFileWatcher.Changed += new FileSystemEventHandler (OnFileChanged);
        }
        public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
        {
            // FIXME: response file?
            StringBuilder parameters = new StringBuilder();
            foreach (ProjectFile finfo in projectFiles) {
                if (finfo.Subtype != Subtype.Directory) {
                    switch (finfo.BuildAction) {
                        case BuildAction.Compile:
                            if (CanCompile (finfo.Name)) {
                                parameters.Append (finfo.Name);
                                parameters.Append (" ");
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

            parameters.Append("/out:");
            parameters.Append(configuration.CompiledOutputName);
            parameters.Append(" ");

            switch (configuration.CompileTarget) {
                case CompileTarget.Library:
                    parameters.Append("/dll ");
                    break;
                case CompileTarget.Exe:
                    parameters.Append("/exe ");
                    break;
                default:
                    throw new System.NotSupportedException("Unsupported compilation target : " + configuration.CompileTarget);
            }

            if (configuration.DebugMode)
                parameters.Append("/debug ");

            string output = String.Empty;
            string error = String.Empty;
            TempFileCollection tf = new TempFileCollection();
            DoCompilation (parameters.ToString (), tf, ref output, ref error);
            ICompilerResult result = ParseOutput(tf, output, error);
            if (result.CompilerOutput.Trim () != "")
                monitor.Log.WriteLine (result.CompilerOutput);

            File.Delete(output);
            File.Delete(error);
            return result;
        }
 public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
 {
     Debug.Assert(compilerManager != null);
     return compilerManager.Compile (projectFiles, references, configuration, monitor);
 }
 public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
 {
     return compilerServices.Compile (projectFiles, references, configuration, monitor);
 }
        public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
        {
            CSharpCompilerParameters compilerparameters = (CSharpCompilerParameters) configuration.CompilationParameters;
            if (compilerparameters == null) compilerparameters = new CSharpCompilerParameters ();

            string exe = configuration.CompiledOutputName;
            string responseFileName = Path.GetTempFileName();
            StreamWriter writer = new StreamWriter(responseFileName);

            if (compilerparameters.CsharpCompiler == CsharpCompiler.Csc) {
                writer.WriteLine("\"/out:" + exe + '"');

                ArrayList pkg_references = new ArrayList ();

                if (references != null) {
                    foreach (ProjectReference lib in references) {
                        string fileName = lib.GetReferencedFileName ();
                        switch (lib.ReferenceType) {
                        case ReferenceType.Gac:
                            string pkg = Runtime.SystemAssemblyService.GetPackageFromFullName (lib.Reference);
                            if (pkg.Trim () == String.Empty) {
                                string msg = String.Format (GettextCatalog.GetString ("{0} could not be found or is invalid."), lib.Reference);
                                Runtime.MessageService.ShowWarning (msg);
                                continue;
                            }
                            if (pkg == "MONO-SYSTEM") {
                                writer.WriteLine ("\"/r:" + Path.GetFileName (fileName) + "\"");
                            } else if (!pkg_references.Contains (pkg)) {
                                pkg_references.Add (pkg);
                                writer.WriteLine ("\"-pkg:" + pkg + "\"");
                            }
                            break;
                        case ReferenceType.Assembly:
                        case ReferenceType.Project:
                            writer.WriteLine ("\"/r:" + fileName + "\"");
                            break;
                        }
                    }
                }

                writer.WriteLine("/noconfig");
                writer.WriteLine("/nologo");
                writer.WriteLine("/codepage:utf8");
            //				writer.WriteLine("/utf8output");
            //				writer.WriteLine("/w:" + compilerparameters.WarningLevel);;

                if (configuration.DebugMode) {
                    writer.WriteLine("/debug:+");
                    writer.WriteLine("/debug:full");
                    writer.WriteLine("/d:DEBUG");
                }

                // mcs default is + but others might not be
                if (compilerparameters.Optimize)
                    writer.WriteLine("/optimize+");
                else
                    writer.WriteLine("/optimize-");

                if (compilerparameters.Win32Icon != null && compilerparameters.Win32Icon.Length > 0 && File.Exists (compilerparameters.Win32Icon)) {
                    writer.WriteLine("\"/win32icon:" + compilerparameters.Win32Icon + "\"");
                }

                if (compilerparameters.UnsafeCode) {
                    writer.WriteLine("/unsafe");
                }

                if (compilerparameters.DefineSymbols.Length > 0) {
                    writer.WriteLine("/define:" + '"' + compilerparameters.DefineSymbols + '"');
                }

                if (compilerparameters.MainClass != null && compilerparameters.MainClass.Length > 0) {
                    writer.WriteLine("/main:" + compilerparameters.MainClass);
                }

                switch (configuration.CompileTarget) {
                    case CompileTarget.Exe:
                        writer.WriteLine("/t:exe");
                        break;
                    case CompileTarget.WinExe:
                        writer.WriteLine("/t:winexe");
                        break;
                    case CompileTarget.Library:
                        writer.WriteLine("/t:library");
                        break;
                }

                foreach (ProjectFile finfo in projectFiles) {
                    if (finfo.Subtype != Subtype.Directory) {
                        switch (finfo.BuildAction) {
                            case BuildAction.Compile:
                                if (CanCompile (finfo.Name))
                                    writer.WriteLine('"' + finfo.Name + '"');
                                break;
                            case BuildAction.EmbedAsResource:
                                // FIXME: workaround 60990
                                writer.WriteLine(@"""/res:{0},{1}""", finfo.Name, Path.GetFileName (finfo.Name));
                                break;
                        }
                    }
                }
                if (compilerparameters.GenerateXmlDocumentation) {
                    writer.WriteLine("\"/doc:" + Path.ChangeExtension(exe, ".xml") + '"');
                }
            }
            else {
                writer.WriteLine("-o " + exe);

                if (compilerparameters.UnsafeCode) {
                    writer.WriteLine("--unsafe");
                }

                writer.WriteLine("--wlevel " + compilerparameters.WarningLevel);

                if (references != null) {
                    foreach (ProjectReference lib in references) {
                        string fileName = lib.GetReferencedFileName ();
                        writer.WriteLine("-r:" + fileName );
                    }
                }

                switch (configuration.CompileTarget) {
                    case CompileTarget.Exe:
                        writer.WriteLine("--target exe");
                        break;
                    case CompileTarget.WinExe:
                        writer.WriteLine("--target winexe");
                        break;
                    case CompileTarget.Library:
                        writer.WriteLine("--target library");
                        break;
                }
                foreach (ProjectFile finfo in projectFiles) {
                    if (finfo.Subtype != Subtype.Directory) {
                        switch (finfo.BuildAction) {
                            case BuildAction.Compile:
                                writer.WriteLine('"' + finfo.Name + '"');
                                break;

                            case BuildAction.EmbedAsResource:
                                writer.WriteLine("--linkres " + finfo.Name);
                                break;
                        }
                    }
                }
            }
            writer.Close();

            string output = String.Empty;
            string error  = String.Empty;

            string compilerName = compilerparameters.CsharpCompiler == CsharpCompiler.Csc ? GetCompilerName() : System.Environment.GetEnvironmentVariable("ComSpec") + " /c mcs";
            string outstr = compilerName + " @" + responseFileName;
            TempFileCollection tf = new TempFileCollection();

            //StreamReader t = File.OpenText(responseFileName);

            //Executor.ExecWaitWithCapture(outstr,  tf, ref output, ref error);
            DoCompilation(outstr, tf, ref output, ref error);

            ICompilerResult result = ParseOutput(tf, output, error);
            if (result.CompilerOutput.Trim () != "")
                monitor.Log.WriteLine (result.CompilerOutput);

            File.Delete(responseFileName);
            File.Delete(output);
            File.Delete(error);
            return result;
        }
 public ProjectReferenceEnumerator(ProjectReferenceCollection mappings)
 {
     this.temp = ((IEnumerable)(mappings));
     this.baseEnumerator = temp.GetEnumerator();
 }
 /// <summary>
 ///     <para>
 ///       Adds the contents of another <see cref='.ProjectReferenceCollection'/> to the end of the collection.
 ///    </para>
 /// </summary>
 /// <param name='value'>
 ///    A <see cref='.ProjectReferenceCollection'/> containing the objects to add to the collection.
 /// </param>
 /// <returns>
 ///   <para>None.</para>
 /// </returns>
 /// <seealso cref='.ProjectReferenceCollection.Add'/>
 public void AddRange(ProjectReferenceCollection value)
 {
     for (int i = 0; (i < value.Count); i = (i + 1)) {
         this.Add(value[i]);
     }
 }
        public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
        {
            VBCompilerParameters compilerparameters = (VBCompilerParameters) configuration.CompilationParameters;
            if (compilerparameters == null) compilerparameters = new VBCompilerParameters ();

            string exe = configuration.CompiledOutputName;
            string responseFileName = Path.GetTempFileName();
            //string stdResponseFileName = String.Concat(propertyService.DataDirectory, Path.DirectorySeparatorChar, "vb.rsp");
            StreamWriter writer = new StreamWriter(responseFileName);

            //Console.WriteLine(GenerateOptions(compilerparameters,exe));
            writer.WriteLine(GenerateOptions (configuration, compilerparameters, exe));

            foreach (ProjectReference lib in references) {
                string fileName = lib.GetReferencedFileName();
                //Console.WriteLine(String.Concat("-r:",fileName));
                writer.WriteLine(String.Concat("-r:", fileName));
            }

            // write source files and embedded resources
            foreach (ProjectFile finfo in projectFiles) {
                if (finfo.Subtype != Subtype.Directory) {
                    switch (finfo.BuildAction) {
                        case BuildAction.Compile:
                            //Console.WriteLine(finfo.Name);
                            writer.WriteLine(finfo.Name);
                        break;

                        case BuildAction.EmbedAsResource:
                            //Console.WriteLine(String.Concat("-resource:", finfo.Name));
                            writer.WriteLine(String.Concat("-resource:", finfo.Name));
                        break;
                    }
                }
            }

            TempFileCollection tf = new TempFileCollection ();
            writer.Close();

            string output = "";
            string error  = "";
            string compilerName = GetCompilerName(compilerparameters.VBCompilerVersion);
            string outstr = String.Concat(compilerName, " @", responseFileName); //, " @", stdResponseFileName);

            //Console.WriteLine("Attempting to run: "+outstr);

            //Executor.ExecWaitWithCapture(outstr, tf, ref output, ref error);
            DoCompilation(outstr,tf,ref output,ref error);

            //Console.WriteLine("Output: "+output);
            //Console.WriteLine("Error: "+error);

            ICompilerResult result = ParseOutput(tf, output);
            ParseOutput(tf,error);

            File.Delete(responseFileName);
            File.Delete(output);
            File.Delete(error);
            if (configuration.CompileTarget != CompileTarget.Library) {
                WriteManifestFile(exe);
            }
            return result;
        }
        public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
        {
            if (JavaLanguageBinding.Properties.IkvmPath == "") {
                monitor.Log.WriteLine ("The Java addin has not been properly configured.");
                monitor.Log.WriteLine ("Please set the location of IKVM in the Java configuration section of MonoDevelop preferences.");
                CompilerResults cre = new CompilerResults (new TempFileCollection ());
                CompilerError err = new CompilerError ();
                err.ErrorText = "The Java addin has not been properly configured.";
                cre.Errors.Add (err);
                return new DefaultCompilerResult (cre, "");
            }

            JavaCompilerParameters compilerparameters = (JavaCompilerParameters) configuration.CompilationParameters;
            if (compilerparameters == null)
                compilerparameters = new JavaCompilerParameters ();

            string outdir = configuration.OutputDirectory;
            string options = "";

            string compiler = compilerparameters.CompilerPath;

            if (configuration.DebugMode)
                options += " -g ";
            else
                options += " -g:none ";

            if (compilerparameters.Optimize)
                options += " -O ";

            if (compilerparameters.Deprecation)
                options += " -deprecation ";

            if (compilerparameters.GenWarnings)
                options += " -nowarn ";

            options += " -encoding utf8 ";

            string files  = "";

            foreach (ProjectFile finfo in projectFiles) {
                if (finfo.Subtype != Subtype.Directory) {
                    switch (finfo.BuildAction) {
                        case BuildAction.Compile:
                            files = files + " \"" + finfo.Name + "\"";
                        break;
                    }
                }
            }

            string classpath = compilerparameters.ClassPath;
            string refClasspath = GenerateReferenceStubs (monitor, configuration, compilerparameters, references);
            if (refClasspath.Length > 0) {
                if (classpath.Length > 0) classpath += ":";
                classpath += refClasspath;
            }

            string args = "";

            if (compilerparameters.Compiler == JavaCompiler.Gcj)
                args = "-C ";

            //FIXME re-enable options
            //FIXME re-enable compilerPath
            if (classpath == "") {
                args += files + " -d " + outdir;
            } else {
                args += " -classpath " + classpath + files + " -d " + outdir;
            }
            args = options + " " + args;
            //Console.WriteLine (args);

            CompilerResults cr = new CompilerResults (new TempFileCollection ());
            StringWriter output = new StringWriter ();
            StringWriter error = new StringWriter ();

            bool res = DoCompilation (monitor, compiler, args, configuration, compilerparameters, output, error);
            ParseJavaOutput (compilerparameters.Compiler, error.ToString(), cr);

            if (res) {
                output = new StringWriter ();
                error = new StringWriter ();
                CompileToAssembly (monitor, configuration, compilerparameters, references, output, error);
                ParseIkvmOutput (compilerparameters.Compiler, error.ToString(), cr);
            }

            return new DefaultCompilerResult (cr, "");
        }
        private string GenerateReferenceStubs(IProgressMonitor monitor, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectReferenceCollection references)
        {
            monitor.Log.WriteLine ("Generating reference stubs ...");

            // Create stubs for referenced assemblies
            string ikvmstub = Path.Combine (Path.Combine (JavaLanguageBinding.Properties.IkvmPath, "bin"), "ikvmstub.exe");

            string classpath = "";

            if (references != null) {
                foreach (ProjectReference lib in references) {
                    string asm = lib.GetReferencedFileName ();
                    ProcessWrapper p = Runtime.ProcessService.StartProcess ("/bin/sh", "-c \"mono " + ikvmstub + " " + asm + "\"", configuration.OutputDirectory, null);
                    p.WaitForExit ();

                    if (classpath.Length > 0) classpath += ":";
                    string name = Path.GetFileNameWithoutExtension (Path.GetFileName (asm));
                    classpath += Path.Combine (configuration.OutputDirectory, name + ".jar");
                }
            }
            return classpath;
        }
        void CompileToAssembly(IProgressMonitor monitor, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectReferenceCollection references, TextWriter output, TextWriter error)
        {
            monitor.Log.WriteLine ("Generating assembly ...");

            LogTextWriter chainedError = new LogTextWriter ();
            chainedError.ChainWriter (monitor.Log);
            chainedError.ChainWriter (error);

            LogTextWriter chainedOutput = new LogTextWriter ();
            chainedOutput.ChainWriter (monitor.Log);
            chainedOutput.ChainWriter (output);

            string outdir = configuration.OutputDirectory;
            string outclass = Path.Combine (outdir, configuration.OutputAssembly + ".class");
            string asm = Path.GetFileNameWithoutExtension (outclass);

            string opts = "-assembly:" + asm;

            switch (configuration.CompileTarget) {
                case CompileTarget.Exe:
                    opts += " -target:exe";
                    break;
                case CompileTarget.WinExe:
                    opts += " -target:winexe";
                    break;
                case CompileTarget.Library:
                    opts += " -target:library";
                    break;
            }

            if (configuration.DebugMode)
                opts += " -debug";

            opts += " -srcpath:" + configuration.SourceDirectory;

            if (references != null) {
                foreach (ProjectReference lib in references)
                    opts += " -r:" + lib.GetReferencedFileName ();
            }

            string ikvmc = Path.Combine (Path.Combine (JavaLanguageBinding.Properties.IkvmPath, "bin"), "ikvmc.exe");

            string args = String.Format ("-c \"mono {0} {1} {2}\"", ikvmc, "*.class", opts);
            Process p = Runtime.ProcessService.StartProcess ("/bin/sh", args, configuration.OutputDirectory, chainedOutput, chainedError, null);
            p.WaitForExit ();
        }