public void LoadConfigData(ProjectConfigurationPropertyPanel dlg)
        {
            configuration      = (DotNetProjectConfiguration)dlg.CurrentConfiguration;
            project            = (DotNetProject)dlg.ConfiguredProject;
            compilerParameters = (JavaCompilerParameters)configuration.CompilationParameters;

            compileTargetCombo.Active = (int)configuration.CompileTarget;

            if (compilerParameters.Compiler == JavaCompiler.Javac)
            {
                compilerJavacButton.Active = true;
            }
            else
            {
                compilerGcjButton.Active = true;
            }

            enableOptimizationCheckButton.Active       = compilerParameters.Optimize;
            generateDebugInformationCheckButton.Active = configuration.DebugMode;
            deprecationCheckButton.Active      = compilerParameters.Deprecation;
            generateWarningsCheckButton.Active = compilerParameters.GenWarnings;
            warningsAsErrorsCheckButton.Active = !configuration.RunWithWarnings;

            compilerEntry.Text  = compilerParameters.CompilerPath;
            classPathEntry.Text = compilerParameters.ClassPath;
            mainClassEntry.Text = compilerParameters.MainClass;
            symbolsEntry.Text   = compilerParameters.DefineSymbols;
            OnCompilerToggled(null, null);
        }
Exemple #2
0
        public ConfigurationParameters CreateCompilationParameters(XmlElement projectOptions)
        {
            JavaCompilerParameters parameters = new JavaCompilerParameters();

            if (Properties.Classpath.Length > 0)
            {
                parameters.ClassPath = Properties.Classpath;
            }

            parameters.Compiler     = Properties.CompilerType;
            parameters.CompilerPath = Properties.CompilerCommand;

            if (projectOptions != null)
            {
                if (projectOptions.Attributes["MainClass"] != null)
                {
                    parameters.MainClass = projectOptions.GetAttribute("MainClass");
                }
                if (projectOptions.Attributes["ClassPath"] != null)
                {
                    parameters.ClassPath += ":" + projectOptions.GetAttribute("ClassPath");
                }
            }
            return(parameters);
        }
		public void LoadConfigData (ProjectConfigurationPropertyPanel dlg)
		{	
			configuration = (DotNetProjectConfiguration) dlg.CurrentConfiguration;
			project = (DotNetProject) dlg.ConfiguredProject;
			compilerParameters = (JavaCompilerParameters) configuration.CompilationParameters;

			compileTargetCombo.Active = (int) configuration.CompileTarget;

			if (compilerParameters.Compiler == JavaCompiler.Javac)
				compilerJavacButton.Active = true;
			else
				compilerGcjButton.Active = true;

			enableOptimizationCheckButton.Active = compilerParameters.Optimize;
			generateDebugInformationCheckButton.Active = configuration.DebugMode;
			deprecationCheckButton.Active = compilerParameters.Deprecation;
			generateWarningsCheckButton.Active = compilerParameters.GenWarnings;
			warningsAsErrorsCheckButton.Active = !configuration.RunWithWarnings;
			
			compilerEntry.Text = compilerParameters.CompilerPath;
			classPathEntry.Text = compilerParameters.ClassPath;				
			mainClassEntry.Text = compilerParameters.MainClass;				
			symbolsEntry.Text = compilerParameters.DefineSymbols;	
			OnCompilerToggled (null, null);
		}
		public ConfigurationParameters CreateCompilationParameters (XmlElement projectOptions)
		{
			JavaCompilerParameters parameters = new JavaCompilerParameters ();
			if (Properties.Classpath.Length > 0)
				parameters.ClassPath = Properties.Classpath;
				
			parameters.Compiler = Properties.CompilerType;
			parameters.CompilerPath = Properties.CompilerCommand;
			
			if (projectOptions != null) {
				if (projectOptions.Attributes["MainClass"] != null) {
					parameters.MainClass = projectOptions.GetAttribute ("MainClass");
				}
				if (projectOptions.Attributes["ClassPath"] != null) {
					parameters.ClassPath += ":" + projectOptions.GetAttribute ("ClassPath");
				}
			}
			return parameters;
		}
        static string GenerateOptionString(DotNetProjectConfiguration configuration)
        {
            JavaCompilerParameters parameters = (configuration.CompilationParameters as JavaCompilerParameters) ?? new JavaCompilerParameters();
            StringBuilder          result     = new StringBuilder();

            result.Append(configuration.DebugMode ? " -g " : " -g:none ");
            if (parameters.Optimize)
            {
                result.Append(" -O ");
            }
            if (parameters.Deprecation)
            {
                result.Append(" -deprecation ");
            }
            if (parameters.GenWarnings)
            {
                result.Append(" -nowarn ");
            }
            result.Append(" -encoding utf8 ");
            return(result.ToString());
        }
            public CodeGenerationPanelWidget(IProperties CustomizationObject)
                : base("Java.glade", "CodeGenerationPanel")
            {
                configuration = (DotNetProjectConfiguration)((IProperties)CustomizationObject).GetProperty("Config");
                compilerParameters = (JavaCompilerParameters) configuration.CompilationParameters;

                ListStore store = new ListStore (typeof (string));
                store.AppendValues (GettextCatalog.GetString ("Executable"));
                store.AppendValues (GettextCatalog.GetString ("Library"));
                compileTargetCombo.Model = store;
                CellRendererText cr = new CellRendererText ();
                compileTargetCombo.PackStart (cr, true);
                compileTargetCombo.AddAttribute (cr, "text", 0);
                compileTargetCombo.Active = (int) configuration.CompileTarget;

                if (compilerParameters.Compiler == JavaCompiler.Javac)
                    compilerJavacButton.Active = true;
                else
                    compilerGcjButton.Active = true;

                compilerJavacButton.Toggled += new EventHandler (OnCompilerToggled);
                compilerGcjButton.Toggled += new EventHandler (OnCompilerToggled);

                enableOptimizationCheckButton.Active = compilerParameters.Optimize;
                generateDebugInformationCheckButton.Active = configuration.DebugMode;
                deprecationCheckButton.Active = compilerParameters.Deprecation;
                generateWarningsCheckButton.Active = compilerParameters.GenWarnings;
                warningsAsErrorsCheckButton.Active = !configuration.RunWithWarnings;

                compilerEntry.Text = compilerParameters.CompilerPath;
                classPathEntry.Text = compilerParameters.ClassPath;
                mainClassEntry.Text = compilerParameters.MainClass;
                symbolsEntry.Text = compilerParameters.DefineSymbols;
            }
        public ICloneable CreateCompilationParameters(XmlElement projectOptions)
        {
            JavaCompilerParameters parameters = new JavaCompilerParameters ();
            parameters.ClassPath = Path.Combine (Path.Combine (Properties.IkvmPath, "classpath"), "mscorlib.jar");
            if (Properties.Classpath.Length > 0)
                parameters.ClassPath += ": " + Properties.Classpath;

            parameters.Compiler = Properties.CompilerType;
            parameters.CompilerPath = Properties.CompilerCommand;

            if (projectOptions != null) {
                if (projectOptions.Attributes["MainClass"] != null) {
                    parameters.MainClass = projectOptions.GetAttribute ("MainClass");
                }
                if (projectOptions.Attributes["ClassPath"] != null) {
                    parameters.ClassPath += ":" + projectOptions.GetAttribute ("ClassPath");
                }
            }
            return parameters;
        }
        private bool DoCompilation(IProgressMonitor monitor, string compiler, string args, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, TextWriter output, TextWriter error)
        {
            LogTextWriter chainedError = new LogTextWriter ();
            chainedError.ChainWriter (monitor.Log);
            chainedError.ChainWriter (error);

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

            monitor.Log.WriteLine ("Compiling Java source code ...");

            Process p = Runtime.ProcessService.StartProcess (compiler, args, null, chainedOutput, chainedError, null);
            p.WaitForExit ();
            return p.ExitCode == 0;
        }
        public static BuildResult Compile(ProjectItemCollection projectItems, DotNetProjectConfiguration configuration, ConfigurationSelector configurationSelector, IProgressMonitor monitor)
        {
            JavaCompilerParameters parameters = (configuration.CompilationParameters as JavaCompilerParameters) ?? new JavaCompilerParameters();
            string outdir   = configuration.OutputDirectory;
            string options  = GenerateOptionString(configuration);
            string compiler = parameters.CompilerPath;

            if (String.IsNullOrEmpty(compiler))
            {
                compiler = "javac";
            }

            StringBuilder files = new StringBuilder();

            foreach (ProjectFile finfo in projectItems.GetAll <ProjectFile> ())
            {
                if (finfo.Subtype != Subtype.Directory && finfo.BuildAction == BuildAction.Compile)
                {
                    files.Append(" \"");
                    files.Append(finfo.Name);
                    files.Append("\"");
                }
            }

            StringBuilder classpath = new StringBuilder(parameters.ClassPath);

            AppendClasspath(classpath, GenerateReferenceStubs(monitor, configurationSelector, configuration, parameters, projectItems));
            AppendClasspath(classpath, GenerateReferenceStub(monitor, configurationSelector, configuration, new ProjectReference(ReferenceType.Gac, "mscorlib")));

            StringBuilder args = new StringBuilder();

            args.Append(options.ToString());
            if (parameters.Compiler == JavaCompiler.Gcj)
            {
                args.Append("-C ");
            }
            if (classpath.Length != 0)
            {
                args.Append(" -classpath ");
                args.Append(classpath.ToString());
            }
            args.Append(files.ToString());
            args.Append(" -d ");
            args.Append(outdir);

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

            bool success;

            try {
                success = Compile(monitor, compiler, args.ToString(), configuration, parameters, output, error);
                ParseJavaOutput(parameters.Compiler, error.ToString(), results);
            } catch (Exception ex) {
                string errorMsg = AddinManager.CurrentLocalizer.GetString("Execution on '{0}' failed. Make sure the Java compiler is properly installed", compiler);
                monitor.ReportError(errorMsg, ex);
                success = false;
                results.Errors.Add(new CompilerError("", 0, 0, "", errorMsg));
            }

            if (success)
            {
                output = new StringWriter();
                error  = new StringWriter();
                CompileToAssembly(monitor, configuration, parameters, projectItems, output, error);
                ParseIkvmOutput(parameters.Compiler, error.ToString(), results);
            }

            return(new BuildResult(results, ""));
        }
        static void CompileToAssembly(IProgressMonitor monitor, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectItemCollection projectItems, TextWriter output, TextWriter error)
        {
            monitor.Log.WriteLine(GettextCatalog.GetString("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);

            StringBuilder args = new StringBuilder("*.class ");

            args.Append("-assembly:"); args.Append(asm);
            args.Append(" -target:"); args.Append(TargetToString(configuration.CompileTarget));
            if (configuration.DebugMode)
            {
                args.Append(" -debug");
            }
            args.Append(" -srcpath:"); args.Append(configuration.ParentItem.BaseDirectory);

            foreach (ProjectReference lib in projectItems.GetAll <ProjectReference> ())
            {
                foreach (string fileName in lib.GetReferencedFileNames(configuration.Selector))
                {
                    args.Append(" -r:"); args.Append(fileName);
                }
            }

            foreach (string fileName in new ProjectReference(ReferenceType.Gac, "mscorlib").GetReferencedFileNames(configuration.Selector))
            {
                args.Append(" -r:"); args.Append(fileName);
            }

            monitor.Log.WriteLine("ikvmc " + args);
            Process process = Runtime.ProcessService.StartProcess("ikvmc", args.ToString(), configuration.OutputDirectory, chainedOutput, chainedError, null);

            process.WaitForExit();
        }
        static bool Compile(IProgressMonitor monitor, string compiler, string args, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, TextWriter output, TextWriter error)
        {
            LogTextWriter chainedError = new LogTextWriter();

            chainedError.ChainWriter(monitor.Log);
            chainedError.ChainWriter(error);

            LogTextWriter chainedOutput = new LogTextWriter();

            chainedOutput.ChainWriter(monitor.Log);
            chainedOutput.ChainWriter(output);

            monitor.Log.WriteLine(GettextCatalog.GetString("Compiling Java source code ..."));
            monitor.Log.WriteLine(compiler + " " + args);

            Process process = Runtime.ProcessService.StartProcess(compiler, args, null, chainedOutput, chainedError, null);

            process.WaitForExit();
            return(process.ExitCode == 0);
        }
        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 ();
        }
        static string GenerateReferenceStubs(IProgressMonitor monitor, ConfigurationSelector configurationSelector, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectItemCollection projectItems)
        {
            StringBuilder result = new StringBuilder();

            foreach (ProjectReference reference in projectItems.GetAll <ProjectReference> ())
            {
                AppendClasspath(result, GenerateReferenceStub(monitor, configurationSelector, configuration, reference));
            }
            return(result.ToString());
        }
		static bool Compile (IProgressMonitor monitor, string compiler, string args, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, TextWriter output, TextWriter error)
		{
			LogTextWriter chainedError = new LogTextWriter ();
			chainedError.ChainWriter (monitor.Log);
			chainedError.ChainWriter (error);
			
			LogTextWriter chainedOutput = new LogTextWriter ();
			chainedOutput.ChainWriter (monitor.Log);
			chainedOutput.ChainWriter (output);
			
			monitor.Log.WriteLine (GettextCatalog.GetString ("Compiling Java source code ..."));
			monitor.Log.WriteLine (compiler + " " + args);
			
			Process process = Runtime.ProcessService.StartProcess (compiler, args, null, chainedOutput, chainedError, null);
			process.WaitForExit ();
			return process.ExitCode == 0;
        }
		static void CompileToAssembly (IProgressMonitor monitor, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectItemCollection projectItems, TextWriter output, TextWriter error)
		{
			monitor.Log.WriteLine (GettextCatalog.GetString ("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);
			
			StringBuilder args = new StringBuilder ("-recurse:*.class ");
			
			args.Append ("-assembly:"); args.Append (asm);
			args.Append (" -target:"); args.Append (TargetToString (configuration.CompileTarget));
			if (configuration.DebugMode)
				args.Append (" -debug");
			args.Append (" -srcpath:"); args.Append (configuration.ParentItem.BaseDirectory);
			
			foreach (ProjectReference lib in projectItems.GetAll<ProjectReference> ()) {
				foreach (string fileName in lib.GetReferencedFileNames (configuration.Selector)) {
					args.Append (" -r:"); args.Append (fileName);
				}
			}
			
			foreach (string fileName in new ProjectReference(ReferenceType.Gac, "mscorlib").GetReferencedFileNames (configuration.Selector)) {
				args.Append (" -r:"); args.Append (fileName);
			}
			
			monitor.Log.WriteLine ("ikvmc " + args);
			Process process = Runtime.ProcessService.StartProcess ("ikvmc", args.ToString (), configuration.OutputDirectory, chainedOutput, chainedError, null);
			process.WaitForExit ();
		}
		static string GenerateReferenceStubs (IProgressMonitor monitor, ConfigurationSelector configurationSelector, DotNetProjectConfiguration configuration, JavaCompilerParameters compilerparameters, ProjectItemCollection projectItems)
		{
			StringBuilder result = new StringBuilder ();
			foreach (ProjectReference reference in projectItems.GetAll<ProjectReference> ()) {
				AppendClasspath (result, GenerateReferenceStub (monitor, configurationSelector, configuration, reference));
			}
			return result.ToString ();
		}
        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;
        }
        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, "");
        }