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 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);
 }
        void GetFolderContent(Project project, string folder, out ProjectFileCollection files, out ArrayList folders)
        {
            files = new ProjectFileCollection ();
            folders = new ArrayList ();
            string folderPrefix = folder + Path.DirectorySeparatorChar;

            foreach (ProjectFile file in project.ProjectFiles)
            {
                string dir;

                // Resource files are shown in a special resource folder (?!?!).
                if (file.BuildAction == BuildAction.EmbedAsResource)
                    continue;

                if (file.Subtype != Subtype.Directory) {
                    dir = Path.GetDirectoryName (file.Name);
                    if (dir == folder) {
                        files.Add (file);
                        continue;
                    }
                } else
                    dir = file.Name;

                if (dir.StartsWith (folderPrefix)) {
                    int i = dir.IndexOf (Path.DirectorySeparatorChar, folderPrefix.Length);
                    if (i != -1) dir = dir.Substring (0,i);
                    if (!folders.Contains (dir))
                        folders.Add (dir);
                }
            }
        }
 public ICompilerResult Compile(ProjectFileCollection projectFiles, ProjectReferenceCollection references, DotNetProjectConfiguration configuration, IProgressMonitor monitor)
 {
     return compilerServices.Compile (projectFiles, references, configuration, monitor);
 }
 public ProjectFileEnumerator(ProjectFileCollection mappings)
 {
     this.temp = ((IEnumerable)(mappings));
     this.baseEnumerator = temp.GetEnumerator();
 }
 /// <summary>
 ///     <para>
 ///       Adds the contents of another <see cref='.ProjectFileCollection'/> to the end of the collection.
 ///    </para>
 /// </summary>
 /// <param name='value'>
 ///    A <see cref='.ProjectFileCollection'/> containing the objects to add to the collection.
 /// </param>
 /// <returns>
 ///   <para>None.</para>
 /// </returns>
 /// <seealso cref='.ProjectFileCollection.Add'/>
 public void AddRange(ProjectFileCollection 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)
        {
            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 void TransferFiles(IProgressMonitor monitor, Project sourceProject, string sourcePath, Project targetProject, string targetPath, bool removeFromSource, bool copyOnlyProjectFiles)
        {
            if (targetProject == null)
                throw new ArgumentNullException ("targetProject");

            if (!targetPath.StartsWith (targetProject.BaseDirectory))
                throw new ArgumentException ("Invalid project folder: " + targetPath);

            if (sourceProject != null && !sourcePath.StartsWith (sourceProject.BaseDirectory))
                throw new ArgumentException ("Invalid project folder: " + sourcePath);

            if (copyOnlyProjectFiles && sourceProject == null)
                throw new ArgumentException ("A source project must be specified if copyOnlyProjectFiles is True");

            // Get the list of files to copy

            ICollection filesToMove;
            try {
                if (copyOnlyProjectFiles) {
                    filesToMove = sourceProject.ProjectFiles.GetFilesInPath (sourcePath);
                } else {
                    ProjectFileCollection col = new ProjectFileCollection ();
                    GetAllFilesRecursive (sourcePath, col);
                    filesToMove = col;
                }
            } catch (Exception ex) {
                monitor.ReportError (string.Format (GettextCatalog.GetString ("Could not get any file from '{0}'."), sourcePath), ex);
                return;
            }

            // Ensure that the destination folder is created, even if no files
            // are copied

            try {
                string newFolder = Path.Combine (targetPath, Path.GetFileName (sourcePath));
                if (Directory.Exists (sourcePath) && !Directory.Exists (newFolder))
                    Runtime.FileService.CreateDirectory (newFolder);
            } catch (Exception ex) {
                monitor.ReportError (string.Format (GettextCatalog.GetString ("Could not create directory '{0}'."), targetPath), ex);
                return;
            }

            // Transfer files

            string basePath = Path.GetDirectoryName (sourcePath);
            monitor.BeginTask (GettextCatalog.GetString ("Copying files..."), filesToMove.Count);

            foreach (ProjectFile file in filesToMove) {
                string sourceFile = file.Name;
                string newFile = targetPath + sourceFile.Substring (basePath.Length);

                try {
                    string fileDir = Path.GetDirectoryName (newFile);
                    if (!Directory.Exists (fileDir))
                        Runtime.FileService.CreateDirectory (fileDir);
                    Runtime.FileService.CopyFile (sourceFile, newFile);
                } catch (Exception ex) {
                    monitor.ReportError (string.Format (GettextCatalog.GetString ("File '{0}' could not be created."), newFile), ex);
                    monitor.Step (1);
                    continue;
                }

                if (sourceProject != null) {
                    ProjectFile projectFile = sourceProject.ProjectFiles.GetFile (sourceFile);
                    if (projectFile != null) {
                        if (removeFromSource)
                            sourceProject.ProjectFiles.Remove (projectFile);
                        if (targetProject.ProjectFiles.GetFile (newFile) == null) {
                            projectFile = (ProjectFile) projectFile.Clone ();
                            projectFile.SetProject (null);
                            projectFile.Name = newFile;
                            targetProject.ProjectFiles.Add (projectFile);
                        }
                    }
                }

                if (removeFromSource) {
                    try {
                        Runtime.FileService.RemoveFile (sourceFile);
                    } catch (Exception ex) {
                        monitor.ReportError (string.Format (GettextCatalog.GetString ("File '{0}' could not be deleted."), sourceFile), ex);
                    }
                }
                monitor.Step (1);
            }

            // If moving a folder, remove to source folder

            if (removeFromSource && Directory.Exists (sourcePath) && (
                    !copyOnlyProjectFiles ||
                    IsDirectoryHierarchyEmpty (sourcePath)))
            {
                try {
                    Runtime.FileService.RemoveFile (sourcePath);
                } catch (Exception ex) {
                    monitor.ReportError (string.Format (GettextCatalog.GetString ("Directory '{0}' could not be deleted."), sourcePath), ex);
                }
            }

            monitor.EndTask ();
        }
        void GetAllFilesRecursive(string path, ProjectFileCollection files)
        {
            if (File.Exists (path)) {
                files.Add (new ProjectFile (path));
                return;
            }

            foreach (string file in Directory.GetFiles (path))
                files.Add (new ProjectFile (file));

            foreach (string dir in Directory.GetDirectories (path))
                GetAllFilesRecursive (dir, files);
        }
        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, "");
        }