예제 #1
0
        protected override string GenerateCommandLineCommands()
        {
            var builder = new CommandLineBuilder();

            builder.AppendSwitch("/nologo");
            builder.AppendSwitch("/quiet");

            builder.AppendFileNameIfNotNull(Source);
            if (Resource != null)
            {
                builder.AppendSwitch("/resource=\"" + Resource + "\"");
            }

            if (Output != null)
            {
                builder.AppendSwitch("/output=\"" + Output + "\"");
            }
            if (string.Compare(OutputType, "library", true) == 0 ||
                (string.IsNullOrEmpty(OutputType) && Output != null && !".exe".Equals(Path.GetExtension(Output), StringComparison.InvariantCultureIgnoreCase)))
            {
                builder.AppendSwitch("/dll");
            }

            if (NoAutoInherit)
            {
                builder.AppendSwitch("/noautoinherit");
            }
            if (CreatePdb)
            {
                builder.AppendSwitch("/pdb");
            }
            if (Optimize)
            {
                builder.AppendSwitch("/optimize");
            }
            if (Fold)
            {
                builder.AppendSwitch("/fold");
            }
            if (NoCorStub)
            {
                builder.AppendSwitch("/nocorstub");
            }
            if (StripReloc)
            {
                builder.AppendSwitch("/stripreloc");
            }

            if (!string.IsNullOrEmpty(Debug))
            {
                try
                {
                    var debug = Convert.ToBoolean(Debug);
                    if (debug)
                    {
                        builder.AppendSwitch("/debug");
                    }
                }
                catch
                {
                    builder.AppendSwitch("/debug=" + Debug.ToLower());
                }
            }
            if (Key != null)
            {
                builder.AppendSwitch("/key=" + Key);
            }
            if (Include != null)
            {
                builder.AppendSwitch("/include=" + Include);
            }
            if (MDV != null)
            {
                builder.AppendSwitch("/mdv=" + MDV);
            }
            if (MSV != null)
            {
                builder.AppendSwitch("/msv=" + MSV);
            }
            if (string.Compare(Platform, "x64") == 0)
            {
                builder.AppendSwitch("/x64");
            }
            if (string.Compare(Platform, "itanium") == 0)
            {
                builder.AppendSwitch("/itanium");
            }

            if (Subsystem != 0)
            {
                builder.AppendSwitch("/subsystem=" + Subsystem);
            }
            if (Flags != 0)
            {
                builder.AppendSwitch("/flags=" + Flags);
            }
            if (Alignment != 0)
            {
                builder.AppendSwitch("/alignment=" + Alignment);
            }
            if (Base != 0)
            {
                builder.AppendSwitch("/base=" + Base);
            }
            if (Stack != 0)
            {
                builder.AppendSwitch("/stack=" + Stack);
            }

            Log.LogMessage(MessageImportance.High, "Assembling {0}...", Source);
            return(builder.ToString());
        }
        bool DoExecute()
        {
            var    abis       = SupportedAbis.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
            var    results    = new List <ITaskItem> ();
            string bundlepath = Path.Combine(TempOutputPath, "bundles");

            if (!Directory.Exists(bundlepath))
            {
                Directory.CreateDirectory(bundlepath);
            }
            else
            {
                Directory.Delete(bundlepath, true);
            }
            foreach (var abi in abis)
            {
                AndroidTargetArch arch = AndroidTargetArch.Other;
                switch (abi)
                {
                case "arm64":
                case "arm64-v8a":
                case "aarch64":
                    arch = AndroidTargetArch.Arm64;
                    break;

                case "armeabi-v7a":
                    arch = AndroidTargetArch.Arm;
                    break;

                case "x86":
                    arch = AndroidTargetArch.X86;
                    break;

                case "x86_64":
                    arch = AndroidTargetArch.X86_64;
                    break;

                case "mips":
                    arch = AndroidTargetArch.Mips;
                    break;
                }

                if (!NdkUtil.ValidateNdkPlatform(Log, AndroidNdkDirectory, arch, enableLLVM: false))
                {
                    return(false);
                }

                int level   = NdkUtil.GetMinimumApiLevelFor(arch, AndroidNdkDirectory);
                var outpath = Path.Combine(bundlepath, abi);
                if (!Directory.Exists(outpath))
                {
                    Directory.CreateDirectory(outpath);
                }

                var clb = new CommandLineBuilder();
                clb.AppendSwitch("--dos2unix=false");
                clb.AppendSwitch("--nomain");
                clb.AppendSwitch("--i18n none");
                clb.AppendSwitch("--bundled-header");
                clb.AppendSwitch("--mono-api-struct-path");
                clb.AppendFileNameIfNotNull(BundleApiPath);
                clb.AppendSwitch("--style");
                clb.AppendSwitch("linux");
                clb.AppendSwitch("-c");
                clb.AppendSwitch("-o");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.c"));
                clb.AppendSwitch("-oo");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "assemblies.o"));
                if (AutoDeps)
                {
                    clb.AppendSwitch("--autodeps");
                }
                if (KeepTemp)
                {
                    clb.AppendSwitch("--keeptemp");
                }
                clb.AppendSwitch("-z");                  // Compress
                clb.AppendFileNamesIfNotNull(Assemblies, " ");
                var psi = new ProcessStartInfo()
                {
                    FileName               = MkbundlePath,
                    Arguments              = clb.ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                };
                var gccNoQuotes = NdkUtil.GetNdkTool(AndroidNdkDirectory, arch, "gcc");
                var gcc         = '"' + gccNoQuotes + '"';
                var gas         = '"' + NdkUtil.GetNdkTool(AndroidNdkDirectory, arch, "as") + '"';
                psi.EnvironmentVariables ["CC"] = gcc;
                psi.EnvironmentVariables ["AS"] = gas;
                Log.LogDebugMessage("CC=" + gcc);
                Log.LogDebugMessage("AS=" + gas);
                //psi.EnvironmentVariables ["PKG_CONFIG_PATH"] = Path.Combine (Path.GetDirectoryName (MonoDroidSdk.MandroidTool), "lib", abi);
                Log.LogDebugMessage("[mkbundle] " + psi.FileName + " " + clb);
                var proc = new Process();
                proc.OutputDataReceived += OnMkbundleOutputData;
                proc.ErrorDataReceived  += OnMkbundleErrorData;
                proc.StartInfo           = psi;
                proc.Start();
                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();
                proc.WaitForExit();
                if (proc.ExitCode != 0)
                {
                    Log.LogCodedError("XA5102", "Conversion from assembly to native code failed. Exit code {0}", proc.ExitCode);
                    return(false);
                }

                // then compile temp.c into temp.o and ...

                clb = new CommandLineBuilder();
                clb.AppendSwitch("-c");

                // This is necessary only when unified headers are in use but it won't hurt to have it
                // defined even if we don't use them
                clb.AppendSwitch($"-D__ANDROID_API__={level}");

                // This is necessary because of the injected code, which is reused between libmonodroid
                // and the bundle
                clb.AppendSwitch("-DANDROID");

                clb.AppendSwitch("-o");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.o"));
                if (!string.IsNullOrWhiteSpace(IncludePath))
                {
                    clb.AppendSwitch("-I");
                    clb.AppendFileNameIfNotNull(IncludePath);
                }

                string asmIncludePath = NdkUtil.GetNdkAsmIncludePath(AndroidNdkDirectory, arch, level);
                if (!String.IsNullOrEmpty(asmIncludePath))
                {
                    clb.AppendSwitch("-I");
                    clb.AppendFileNameIfNotNull(asmIncludePath);
                }

                clb.AppendSwitch("-I");
                clb.AppendFileNameIfNotNull(NdkUtil.GetNdkPlatformIncludePath(AndroidNdkDirectory, arch, level));
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.c"));
                Log.LogDebugMessage("[CC] " + gcc + " " + clb);
                if (MonoAndroidHelper.RunProcess(gccNoQuotes, clb.ToString(), OnCcOutputData, OnCcErrorData) != 0)
                {
                    Log.LogCodedError("XA5103", "NDK C compiler resulted in an error. Exit code {0}", proc.ExitCode);
                    return(false);
                }

                // ... link temp.o and assemblies.o into app.so

                clb = new CommandLineBuilder();
                clb.AppendSwitch("--shared");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.o"));
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "assemblies.o"));

                // API23+ requires that the shared library has its soname set or it won't load
                clb.AppendSwitch("-soname");
                clb.AppendSwitch(BundleSharedLibraryName);
                clb.AppendSwitch("-o");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, BundleSharedLibraryName));
                clb.AppendSwitch("-L");
                clb.AppendFileNameIfNotNull(NdkUtil.GetNdkPlatformLibPath(AndroidNdkDirectory, arch, level));
                clb.AppendSwitch("-lc");
                clb.AppendSwitch("-lm");
                clb.AppendSwitch("-ldl");
                clb.AppendSwitch("-llog");
                clb.AppendSwitch("-lz");                  // Compress
                string ld = NdkUtil.GetNdkTool(AndroidNdkDirectory, arch, "ld");
                Log.LogMessage(MessageImportance.Normal, "[LD] " + ld + " " + clb);
                if (MonoAndroidHelper.RunProcess(ld, clb.ToString(), OnLdOutputData, OnLdErrorData) != 0)
                {
                    Log.LogCodedError("XA5201", "NDK Linker resulted in an error. Exit code {0}", proc.ExitCode);
                    return(false);
                }
                results.Add(new TaskItem(Path.Combine(outpath, "libmonodroid_bundle_app.so")));
            }
            OutputNativeLibraries = results.ToArray();
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Returns a string value containing the command line arguments to pass directly to the executable file.
        /// </summary>
        /// <returns>
        /// A string value containing the command line arguments to pass directly to the executable file.
        /// </returns>
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            string c = Environment.OSVersion.Platform == PlatformID.Unix ? "-" : "--";

            if (EnableShadowCopy)
            {
                builder.AppendSwitch(c + "shadowcopy");
            }
            if (_testInNewThread.HasValue && !_testInNewThread.Value)
            {
                builder.AppendSwitch(c + "nothread");
            }
            if (Force32Bit)
            {
                builder.AppendSwitch(c + "x86");
            }
            if (NoHeader)
            {
                builder.AppendSwitch(c + "noheader");
            }
            if (NoColor)
            {
                builder.AppendSwitch(c + "nocolor");
            }
            if (Verbose)
            {
                builder.AppendSwitch(c + "verbose");
            }
            builder.AppendFileNamesIfNotNull(_assemblies, " ");

            builder.AppendSwitchIfNotNull(c + "config=", _projectConfiguration);

            builder.AppendSwitchIfNotNull(c + "err=", _errorOutputFile);

            builder.AppendSwitchIfNotNull(c + "out=", _textOutputFile);

            builder.AppendSwitchIfNotNull(c + "framework=", _framework);

            builder.AppendSwitchIfNotNull(c + "process=", _process);

            builder.AppendSwitchIfNotNull(c + "domain=", _domain);

            builder.AppendSwitchIfNotNull(c + "apartment=", _apartment);

            builder.AppendSwitchIfNotNull(c + "where=", _where);

            builder.AppendSwitchIfNotNull(c + "timeout=", _timeout);

            builder.AppendSwitchIfNotNull(c + "workers=", _workers);

            builder.AppendSwitchIfNotNull(c + "result=", _outputXmlFile);

            builder.AppendSwitchIfNotNull(c + "work=", _workingDirectory);

            builder.AppendSwitchIfNotNull(c + "labels=", _showLabels);

            builder.AppendSwitchIfNotNull(c + "trace=", _trace);

            return(builder.ToString());
        }
예제 #4
0
        string GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile)
        {
            var cmd = new CommandLineBuilder();

            cmd.AppendSwitch("link");
            if (MonoAndroidHelper.LogInternalExceptions)
            {
                cmd.AppendSwitch("-v");
            }

            string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest");

            Directory.CreateDirectory(manifestDir);
            string           manifestFile = Path.Combine(manifestDir, Path.GetFileName(ManifestFile));
            ManifestDocument manifest     = new ManifestDocument(ManifestFile, this.Log);

            manifest.SdkVersion = AndroidSdkPlatform;
            if (currentAbi != null)
            {
                if (!string.IsNullOrEmpty(VersionCodePattern))
                {
                    manifest.CalculateVersionCode(currentAbi, VersionCodePattern, VersionCodeProperties);
                }
                else
                {
                    manifest.SetAbi(currentAbi);
                }
            }
            else if (!string.IsNullOrEmpty(VersionCodePattern))
            {
                manifest.CalculateVersionCode(null, VersionCodePattern, VersionCodeProperties);
            }
            manifest.ApplicationName = ApplicationName;
            manifest.Save(manifestFile);

            cmd.AppendSwitchIfNotNull("--manifest ", manifestFile);
            if (!string.IsNullOrEmpty(JavaDesignerOutputDirectory))
            {
                var designerDirectory = Path.IsPathRooted(JavaDesignerOutputDirectory) ? JavaDesignerOutputDirectory : Path.Combine(WorkingDirectory, JavaDesignerOutputDirectory);
                Directory.CreateDirectory(designerDirectory);
                cmd.AppendSwitchIfNotNull("--java ", JavaDesignerOutputDirectory);
            }
            if (PackageName != null)
            {
                cmd.AppendSwitchIfNotNull("--custom-package ", PackageName.ToLowerInvariant());
            }

            if (AdditionalResourceArchives != null)
            {
                foreach (var item in AdditionalResourceArchives)
                {
                    var flata = Path.Combine(WorkingDirectory, item.ItemSpec);
                    if (File.Exists(flata))
                    {
                        cmd.AppendSwitchIfNotNull("-R ", flata);
                    }
                    else
                    {
                        Log.LogDebugMessage("Archive does not exist: " + flata);
                    }
                }
            }

            if (CompiledResourceFlatArchive != null)
            {
                var flata = Path.Combine(WorkingDirectory, CompiledResourceFlatArchive.ItemSpec);
                if (File.Exists(flata))
                {
                    cmd.AppendSwitchIfNotNull("-R ", flata);
                }
                else
                {
                    Log.LogDebugMessage("Archive does not exist: " + flata);
                }
            }

            cmd.AppendSwitch("--auto-add-overlay");

            if (!string.IsNullOrWhiteSpace(UncompressedFileExtensions))
            {
                foreach (var ext in UncompressedFileExtensions.Split(new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    cmd.AppendSwitchIfNotNull("-0 ", ext);
                }
            }

            if (!string.IsNullOrEmpty(ExtraPackages))
            {
                cmd.AppendSwitchIfNotNull("--extra-packages ", ExtraPackages);
            }

            cmd.AppendSwitchIfNotNull("-I ", JavaPlatformJarPath);

            if (!string.IsNullOrEmpty(ResourceSymbolsTextFile))
            {
                cmd.AppendSwitchIfNotNull("--output-text-symbols ", ResourceSymbolsTextFile);
            }

            if (ProtobufFormat)
            {
                cmd.AppendSwitch("--proto-format");
            }

            var extraArgsExpanded = ExpandString(ExtraArgs);

            if (extraArgsExpanded != ExtraArgs)
            {
                Log.LogDebugMessage("  ExtraArgs expanded: {0}", extraArgsExpanded);
            }

            if (!string.IsNullOrWhiteSpace(extraArgsExpanded))
            {
                cmd.AppendSwitch(extraArgsExpanded);
            }

            if (!string.IsNullOrWhiteSpace(AssetsDirectory))
            {
                var assetDir = AssetsDirectory.TrimEnd('\\');
                if (!Path.IsPathRooted(assetDir))
                {
                    assetDir = Path.Combine(WorkingDirectory, assetDir);
                }
                if (!string.IsNullOrWhiteSpace(assetDir) && Directory.Exists(assetDir))
                {
                    cmd.AppendSwitchIfNotNull("-A ", assetDir);
                }
            }
            cmd.AppendSwitchIfNotNull("-o ", currentResourceOutputFile);
            return(cmd.ToString());
        }
예제 #5
0
 private static void EmitAlwaysAppendSwitch(CommandLineBuilder builder, ToolSwitch toolSwitch)
 {
     builder.AppendSwitch(toolSwitch.Name);
 }
        bool DoExecute()
        {
            var    abis       = SupportedAbis.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
            var    results    = new List <ITaskItem> ();
            string bundlepath = Path.Combine(TempOutputPath, "bundles");

            if (!Directory.Exists(bundlepath))
            {
                Directory.CreateDirectory(bundlepath);
            }
            else
            {
                Directory.Delete(bundlepath, true);
            }
            foreach (var abi in abis)
            {
                AndroidTargetArch arch = AndroidTargetArch.Other;
                switch (abi)
                {
                case "arm64":
                case "arm64-v8a":
                case "aarch64":
                    arch = AndroidTargetArch.Arm64;
                    break;

                case "armeabi":
                case "armeabi-v7a":
                    arch = AndroidTargetArch.Arm;
                    break;

                case "x86":
                    arch = AndroidTargetArch.X86;
                    break;

                case "x86_64":
                    arch = AndroidTargetArch.X86_64;
                    break;

                case "mips":
                    arch = AndroidTargetArch.Mips;
                    break;
                }

                if (!NdkUtil.ValidateNdkPlatform(Log, AndroidNdkDirectory, arch, enableLLVM: false))
                {
                    return(false);
                }

                // FIXME: it is kind of hacky, we should have something like NdkUtil.GetMinimumApiLevelFor(arch).
                int level   = NdkUtil.IsNdk64BitArch(arch) ? 21 : arch == AndroidTargetArch.Arm ? 4 : 9;
                var outpath = Path.Combine(bundlepath, abi);
                if (!Directory.Exists(outpath))
                {
                    Directory.CreateDirectory(outpath);
                }

                var clb = new CommandLineBuilder();
                clb.AppendSwitch("--dos2unix=false");
                clb.AppendSwitch("--nomain");
                clb.AppendSwitch("--i18n none");
                clb.AppendSwitch("--style");
                clb.AppendSwitch("linux");
                clb.AppendSwitch("-c");
                clb.AppendSwitch("-o");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.c"));
                clb.AppendSwitch("-oo");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "assemblies.o"));
                if (AutoDeps)
                {
                    clb.AppendSwitch("--autodeps");
                }
                if (KeepTemp)
                {
                    clb.AppendSwitch("--keeptemp");
                }
                clb.AppendSwitch("-z");                  // Compress
                clb.AppendFileNamesIfNotNull(Assemblies, " ");
                var psi = new ProcessStartInfo()
                {
                    FileName               = MkbundlePath,
                    Arguments              = clb.ToString(),
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                };
                var gccNoQuotes = NdkUtil.GetNdkTool(AndroidNdkDirectory, arch, "gcc");
                var gcc         = '"' + gccNoQuotes + '"';
                var gas         = '"' + NdkUtil.GetNdkTool(AndroidNdkDirectory, arch, "as") + '"';
                psi.EnvironmentVariables ["CC"] = gcc;
                psi.EnvironmentVariables ["AS"] = gas;
                Log.LogDebugMessage("CC=" + gcc);
                Log.LogDebugMessage("AS=" + gas);
                //psi.EnvironmentVariables ["PKG_CONFIG_PATH"] = Path.Combine (Path.GetDirectoryName (MonoDroidSdk.MandroidTool), "lib", abi);
                Log.LogDebugMessage("[mkbundle] " + psi.FileName + " " + clb);
                var proc = new Process();
                proc.OutputDataReceived += OnMkbundleOutputData;
                proc.ErrorDataReceived  += OnMkbundleErrorData;
                proc.StartInfo           = psi;
                proc.Start();
                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();
                proc.WaitForExit();
                if (proc.ExitCode != 0)
                {
                    Log.LogCodedError("XA5102", "Conversion from assembly to native code failed. Exit code {0}", proc.ExitCode);
                    return(false);
                }

                // make some changes in the mkbundle output so that it does not require libmonodroid.so
                var mkbundleOutput = File.ReadAllText(Path.Combine(outpath, "temp.c"));
                mkbundleOutput = mkbundleOutput.Replace("void mono_mkbundle_init ()", "void mono_mkbundle_init (void (register_bundled_assemblies_func)(const MonoBundledAssembly **), void (register_config_for_assembly_func)(const char *, const char *))")
                                 .Replace("mono_register_config_for_assembly (\"", "register_config_for_assembly_func (\"")
                                 .Replace("install_dll_config_files (void)", "install_dll_config_files (void (register_config_for_assembly_func)(const char *, const char *))")
                                 .Replace("install_dll_config_files ()", "install_dll_config_files (register_config_for_assembly_func)")
                                 .Replace("mono_register_bundled_assemblies(", "register_bundled_assemblies_func(");
                File.WriteAllText(Path.Combine(outpath, "temp.c"), mkbundleOutput);

                // then compile temp.c into temp.o and ...

                clb = new CommandLineBuilder();
                clb.AppendSwitch("-c");
                clb.AppendSwitch("-o");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.o"));
                if (!string.IsNullOrWhiteSpace(IncludePath))
                {
                    clb.AppendSwitch("-I");
                    clb.AppendFileNameIfNotNull(IncludePath);
                }
                clb.AppendSwitch("-I");
                clb.AppendFileNameIfNotNull(NdkUtil.GetNdkPlatformIncludePath(AndroidNdkDirectory, arch, level));
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.c"));
                Log.LogDebugMessage("[CC] " + gcc + " " + clb);
                if (MonoAndroidHelper.RunProcess(gccNoQuotes, clb.ToString(), OnCcOutputData, OnCcErrorData) != 0)
                {
                    Log.LogCodedError("XA5103", "NDK C compiler resulted in an error. Exit code {0}", proc.ExitCode);
                    return(false);
                }

                // ... link temp.o and assemblies.o into app.so

                clb = new CommandLineBuilder();
                clb.AppendSwitch("--shared");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "temp.o"));
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "assemblies.o"));
                clb.AppendSwitch("-o");
                clb.AppendFileNameIfNotNull(Path.Combine(outpath, "libmonodroid_bundle_app.so"));
                clb.AppendSwitch("-L");
                clb.AppendFileNameIfNotNull(NdkUtil.GetNdkPlatformLibPath(AndroidNdkDirectory, arch, level));
                clb.AppendSwitch("-lc");
                clb.AppendSwitch("-lm");
                clb.AppendSwitch("-ldl");
                clb.AppendSwitch("-llog");
                clb.AppendSwitch("-lz");                  // Compress
                string ld = NdkUtil.GetNdkTool(AndroidNdkDirectory, arch, "ld");
                Log.LogMessage(MessageImportance.Normal, "[LD] " + ld + " " + clb);
                if (MonoAndroidHelper.RunProcess(ld, clb.ToString(), OnLdOutputData, OnLdErrorData) != 0)
                {
                    Log.LogCodedError("XA5201", "NDK Linker resulted in an error. Exit code {0}", proc.ExitCode);
                    return(false);
                }
                results.Add(new TaskItem(Path.Combine(outpath, "libmonodroid_bundle_app.so")));
            }
            OutputNativeLibraries = results.ToArray();
            return(true);
        }
예제 #7
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

            if (!UseProguard)
            {
                // Add the JavaOptions if they are not null
                // These could be any of the additional options
                if (!string.IsNullOrEmpty(JavaOptions))
                {
                    cmd.AppendSwitch(JavaOptions);
                }

                // Add the specific -XmxN to override the default heap size for the JVM
                // N can be in the form of Nm or NGB (e.g 100m or 1GB )
                cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

                cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(ProguardJarPath));
            }

            if (!ClassesOutputDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                ClassesOutputDirectory += Path.DirectorySeparatorChar;
            }

            var classesZip = Path.Combine(ClassesOutputDirectory, "..", "classes.zip");
            var acwLines   = File.ReadAllLines(AcwMapFile);

            using (var appcfg = File.CreateText(ProguardGeneratedApplicationConfiguration))
                for (int i = 0; i + 2 < acwLines.Length; i += 3)
                {
                    try {
                        var line = acwLines [i + 2];
                        var java = line.Substring(line.IndexOf(';') + 1);
                        appcfg.WriteLine("-keep class " + java + " { *; }");
                    } catch {
                        // skip invalid lines
                    }
                }

            if (!string.IsNullOrWhiteSpace(ProguardCommonXamarinConfiguration))
            {
                using (var xamcfg = File.CreateText(ProguardCommonXamarinConfiguration)) {
                    GetType().Assembly.GetManifestResourceStream("proguard_xamarin.cfg").CopyTo(xamcfg.BaseStream);
                    if (!string.IsNullOrEmpty(ProguardMappingFileOutput))
                    {
                        xamcfg.WriteLine("-keepattributes SourceFile");
                        xamcfg.WriteLine("-keepattributes LineNumberTable");
                        xamcfg.WriteLine($"-printmapping {Path.GetFullPath (ProguardMappingFileOutput)}");
                    }
                }
            }

            var enclosingChar = OS.IsWindows ? "\"" : string.Empty;

            foreach (var file in ProguardConfigurationFiles)
            {
                if (File.Exists(file))
                {
                    cmd.AppendSwitchUnquotedIfNotNull("-include ", $"{enclosingChar}'{file}'{enclosingChar}");
                }
                else
                {
                    Log.LogCodedWarning("XA4304", file, 0, Properties.Resources.XA4304, file);
                }
            }

            var injars  = new List <string> ();
            var libjars = new List <string> ();

            injars.Add(classesZip);
            if (JavaLibrariesToEmbed != null)
            {
                foreach (var jarfile in JavaLibrariesToEmbed)
                {
                    injars.Add(jarfile.ItemSpec);
                }
            }
            libjars.Add(JavaPlatformJarPath);
            if (JavaLibrariesToReference != null)
            {
                foreach (var jarfile in JavaLibrariesToReference.Select(p => p.ItemSpec))
                {
                    libjars.Add(jarfile);
                }
            }

            cmd.AppendSwitchUnquotedIfNotNull("-injars ", "\"'" + string.Join($"'{ProguardInputJarFilter}{Path.PathSeparator}'", injars.Distinct()) + $"'{ProguardInputJarFilter}\"");
            cmd.AppendSwitchUnquotedIfNotNull("-libraryjars ", $"{enclosingChar}'" + string.Join($"'{Path.PathSeparator}'", libjars.Distinct()) + $"'{enclosingChar}");
            cmd.AppendSwitchIfNotNull("-outjars ", ProguardJarOutput);

            if (EnableLogging)
            {
                cmd.AppendSwitchIfNotNull("-dump ", DumpOutput);
                cmd.AppendSwitchIfNotNull("-printseeds ", PrintSeedsOutput);
                cmd.AppendSwitchIfNotNull("-printusage ", PrintUsageOutput);
                cmd.AppendSwitchIfNotNull("-printmapping ", PrintMappingOutput);
            }

            // http://stackoverflow.com/questions/5701126/compile-with-proguard-gives-exception-local-variable-type-mismatch#7587680
            cmd.AppendSwitch("-optimizations !code/allocation/variable");

            return(cmd.ToString());
        }
예제 #8
0
        /// <summary>
        /// Construct the command line from the task properties by using the CommandLineBuilder
        /// </summary>
        /// <returns></returns>
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            builder.AppendSwitch("/nologo");
            builder.AppendSwitchIfNotNull("/ERRORREPORT:", "PROMPT");

            if (mTargetType == eTargetType.DLL || mTargetType == eTargetType.EXE)
            {
                builder.AppendSwitchIfNotNull("/DEBUGTYPE:", "CV,FIXUP");
                builder.AppendSwitch("/NXCOMPAT");
                builder.AppendSwitch("/DYNAMICBASE");
            }

            if (debug)
            {
                builder.AppendSwitch("/DEBUG");
                builder.AppendSwitch("/ASSEMBLYDEBUG");
            }

            if (null != DEFLIBS)
            {
                //  Specify the libs we Do want to add
                foreach (ITaskItem toAdd in DEFLIBS)
                {
                    builder.AppendSwitchIfNotNull("/DEFAULTLIB:", toAdd);
                }
            }

            //  /DELAYLOAD files
            if (delayload != null)
            {
                //  Find the last index of the import libs...
                //  Insert also "Delayimp.lib" into this set as well
                //  This is required to make the /DELAYLOAD work properly
                //

                foreach (ITaskItem toAdd in delayload)
                {
                    builder.AppendSwitchIfNotNull("/DELAYLOAD:", toAdd);
                }
            }

            if (libpath != null)
            {
                foreach (ITaskItem toAdd in libpath)
                {
                    builder.AppendSwitchIfNotNull("/LIBPATH:", toAdd);
                }
            }

            //  /DLL
            if (mTargetType == eTargetType.DLL)
            {
                builder.AppendSwitch("/DLL");
            }


            //  /IMPLIB:filenames...
            if (implib != null)
            {
                foreach (ITaskItem toAdd in implib)
                {
                    builder.AppendSwitchIfNotNull("/IMPLIB:", toAdd);
                }
            }

            //  /MANIFEST and /MANIFESTFILE
            if (manifest)
            {
                builder.AppendSwitch("/MANIFEST");
                builder.AppendSwitchIfNotNull("/MANIFESTFILE:", manifestfile);
            }

            //  /KEYFILE
            builder.AppendSwitchIfNotNull("/KEYFILE:", keyFile);

            // /DELAYSIGN
            if (delaySign)
            {
                builder.AppendSwitch("/DELAYSIGN");
            }

            // MACHINE
            builder.AppendSwitchIfNotNull("/MACHINE:", machine);

            //  Specify the libs we DONT want
            if (nodefaultlib != null)
            {
                foreach (ITaskItem toAdd in nodefaultlib)
                {
                    builder.AppendSwitchIfNotNull("/NODEFAULTLIB:", toAdd.ItemSpec + ".lib");
                }
            }

            //  Specify the subsystem
            builder.AppendSwitchIfNotNull("/SUBSYSTEM:", subsystem);

            //  Add the OBJ files
            if (objfiles != null)
            {
                foreach (ITaskItem toAdd in objfiles)
                {
                    builder.AppendSwitch(toAdd.ItemSpec);
                }
            }

            //  Specify the PDB file if set...
            builder.AppendSwitchIfNotNull("/PDB:", pdb);

            // Specify the DEF file if set...
            builder.AppendSwitchIfNotNull("/DEF:", moduleDefinitionFile);

            //  Specify the output file name. We put this last to make it visually easier to find the
            //  name of the output when reviewing build log files.
            builder.AppendSwitchIfNotNull("/OUT:", outfilename);

            Log.LogMessage(MessageImportance.High, "Linking {0}", outfilename);

            return(builder.ToString());
        }
예제 #9
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

            if (!UseProguard)
            {
                // Add the JavaOptions if they are not null
                // These could be any of the additional options
                if (!string.IsNullOrEmpty(JavaOptions))
                {
                    cmd.AppendSwitch(JavaOptions);
                }

                // Add the specific -XmxN to override the default heap size for the JVM
                // N can be in the form of Nm or NGB (e.g 100m or 1GB )
                cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

                cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(ProguardJarPath));
            }

            if (!ClassesOutputDirectory.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                ClassesOutputDirectory += Path.DirectorySeparatorChar;
            }
            var classesFullPath = Path.GetFullPath(ClassesOutputDirectory);

            if (File.Exists(ProguardJarInput))
            {
                File.Delete(ProguardJarInput);
            }
            using (var zip = ZipArchive.Open(ProguardJarInput, FileMode.Create)) {
                foreach (var file in Directory.GetFiles(classesFullPath, "*", SearchOption.AllDirectories))
                {
                    zip.AddFile(file, Path.Combine(Path.GetDirectoryName(file.Substring(classesFullPath.Length)), Path.GetFileName(file)));
                }
            }

            var acwLines = File.ReadAllLines(AcwMapFile);

            using (var appcfg = File.CreateText(ProguardGeneratedApplicationConfiguration))
                for (int i = 0; i + 3 < acwLines.Length; i += 4)
                {
                    try {
                        var java = acwLines [i + 3].Substring(acwLines [i + 3].IndexOf(';') + 1);
                        appcfg.WriteLine("-keep class " + java + " { *; }");
                    } catch {
                        // skip invalid lines
                    }
                }

            var injars  = new List <string> ();
            var libjars = new List <string> ();

            injars.Add(ProguardJarInput);
            if (JavaLibrariesToEmbed != null)
            {
                foreach (var jarfile in JavaLibrariesToEmbed)
                {
                    injars.Add(jarfile.ItemSpec);
                }
            }

            using (var xamcfg = File.Create(ProguardCommonXamarinConfiguration))
                GetType().Assembly.GetManifestResourceStream("proguard_xamarin.cfg").CopyTo(xamcfg);

            var configs = ProguardConfigurationFiles
                          .Replace("{sdk.dir}", Path.GetDirectoryName(Path.GetDirectoryName(ProguardHome)) + Path.DirectorySeparatorChar)
                          .Replace("{intermediate.common.xamarin}", ProguardCommonXamarinConfiguration)
                          .Replace("{intermediate.references}", ProguardGeneratedReferenceConfiguration)
                          .Replace("{intermediate.application}", ProguardGeneratedApplicationConfiguration)
                          .Replace("{project}", string.Empty)        // current directory anyways.
                          .Split(';')
                          .Select(s => s.Trim())
                          .Where(s => !string.IsNullOrWhiteSpace(s));

            foreach (var file in configs)
            {
                if (File.Exists(file))
                {
                    cmd.AppendSwitchIfNotNull("-include ", file);
                }
                else
                {
                    Log.LogWarning("Proguard configuration file '{0}' was not found.", file);
                }
            }

            libjars.Add(JavaPlatformJarPath);
            if (ExternalJavaLibraries != null)
            {
                foreach (var jarfile in ExternalJavaLibraries.Select(p => p.ItemSpec))
                {
                    libjars.Add(jarfile);
                }
            }

            cmd.AppendSwitch("\"-injars");
            cmd.AppendSwitch(string.Join(Path.PathSeparator.ToString(), injars.Distinct().Select(s => '\'' + s + '\'')) + "\"");

            cmd.AppendSwitch("\"-libraryjars");
            cmd.AppendSwitch(string.Join(Path.PathSeparator.ToString(), libjars.Distinct().Select(s => '\'' + s + '\'')) + "\"");

            cmd.AppendSwitch("-outjars");
            cmd.AppendSwitch('"' + ProguardJarOutput + '"');

            if (EnableLogging)
            {
                cmd.AppendSwitchIfNotNull("-dump ", DumpOutput);
                cmd.AppendSwitchIfNotNull("-printseeds ", PrintSeedsOutput);
                cmd.AppendSwitchIfNotNull("-printusage ", PrintUsageOutput);
                cmd.AppendSwitchIfNotNull("-printmapping ", PrintMappingOutput);
            }

            return(cmd.ToString());
        }
예제 #10
0
파일: ILMerge.cs 프로젝트: mazj/JobSystem
        /// <summary>
        /// Returns a string value containing the command line arguments
        /// to pass directly to the executable file.
        /// </summary>
        /// <returns>
        /// Returns a string value containing the command line arguments
        /// to pass directly to the executable file.
        /// </returns>
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            if (allowDuplicateTypes != null)
            {
                foreach (ITaskItem allowDuplicateType in allowDuplicateTypes)
                {
                    builder.AppendSwitch(@"/allowDup:" + allowDuplicateType.ItemSpec);
                }
            }

            if (allowZeroPeKind)
            {
                builder.AppendSwitch(@"/zeroPeKind");
            }

            if (attributeFile != null)
            {
                builder.AppendSwitch(@"/attr:" + attributeFile.ItemSpec);
            }

            if (closed)
            {
                builder.AppendSwitch(@"/closed");
            }

            if (copyAttributes)
            {
                builder.AppendSwitch(@"/copyattrs");
            }

            if (!debugInfo)
            {
                builder.AppendSwitch(@"/ndebug");
            }

            if (delaySign)
            {
                builder.AppendSwitch(@"/delaysign");
            }

            if (excludeFile != null)
            {
                builder.AppendSwitch(@"/internalize" +
                                     ((excludeFile.ItemSpec.Length == 0) ? string.Empty : @":" + excludeFile.ItemSpec));
            }

            if (keyFile != null)
            {
                builder.AppendSwitch(@"/keyfile:" + keyFile.ItemSpec);
            }

            if (logFile != null)
            {
                builder.AppendSwitch(@"/log" +
                                     ((logFile.ItemSpec.Length == 0) ? string.Empty : @":" + logFile.ItemSpec));
            }

            if (outputFile != null)
            {
                builder.AppendSwitch(@"/out:" + outputFile.ItemSpec);
            }

            if (publicKeyTokens)
            {
                builder.AppendSwitch(@"/publickeytokens");
            }

            if (targetPlatformVersion != null)
            {
                builder.AppendSwitch(@"/targetplatform:" +
                                     targetPlatformVersion +
                                     ((targetPlatformDirectory == null) ? string.Empty : @"," + targetPlatformDirectory.ItemSpec));
            }

            if (targetKind != null)
            {
                builder.AppendSwitch(@"/target:" + targetKind);
            }

            if (version != null)
            {
                builder.AppendSwitch(@"/ver:" + version);
            }

            if (xmlDocumentation)
            {
                builder.AppendSwitch(@"/xmldocs");
            }

            builder.AppendFileNamesIfNotNull(inputAssemblies, @" ");

            return(builder.ToString());
        }
예제 #11
0
        public void TestAppendSwitch3()
        {
            clb = new CommandLineBuilder();

            clb.AppendSwitch(String.Empty);
        }
예제 #12
0
        public void TestAppendSwitch2()
        {
            clb = new CommandLineBuilder();

            clb.AppendSwitch(null);
        }
예제 #13
0
 /// <summary>
 /// Generates the SvnAdmin command.
 /// </summary>
 /// <returns></returns>
 protected virtual void AppendCommand(CommandLineBuilder commandLine)
 {
     commandLine.AppendSwitch(Command);
     commandLine.AppendFileNameIfNotNull(RepositoryPath);
 }
예제 #14
0
        /// <summary>
        /// Generates a string value containing the command line arguments
        /// to pass directly to the executable file.
        /// </summary>
        /// <returns>
        /// Returns a string value containing the command line arguments
        /// to pass directly to the executable file.
        /// </returns>
        protected override string GenerateCommandLineCommands()
        {
            var builder = new CommandLineBuilder();


            builder.AppendSwitchIfNotNull("/allowDup:", AllowDuplicateTypes, " /allowDup:");

            if (AllowZeroPeKind)
            {
                builder.AppendSwitch("/zeroPeKind");
            }

            builder.AppendSwitchIfNotNull("/attr:", AttributeFile);

            if (Closed)
            {
                builder.AppendSwitch("/closed");
            }

            if (CopyAttributes)
            {
                builder.AppendSwitch("/copyattrs");
            }

            if (!DebugInfo)
            {
                builder.AppendSwitch("/ndebug");
            }

            if (DelaySign)
            {
                builder.AppendSwitch("/delaysign");
            }

            if (ExcludeFile != null)
            {
                if (ExcludeFile.ItemSpec.Length == 0)
                {
                    builder.AppendSwitch("/internalize");
                }
                else
                {
                    builder.AppendSwitchIfNotNull("/internalize:", ExcludeFile);
                }
            }
            else if (Internalize)
            {
                builder.AppendSwitch("/internalize");
            }

            builder.AppendSwitchIfNotNull("/keyfile:", KeyFile);

            if (LogFile != null)
            {
                if (LogFile.ItemSpec.Length == 0)
                {
                    builder.AppendSwitchIfNotNull("/log:", LogFile);
                }
                else
                {
                    builder.AppendSwitch("/log");
                }
            }

            builder.AppendSwitchIfNotNull("/out:", OutputFile);

            if (PublicKeyTokens)
            {
                builder.AppendSwitch("/publickeytokens");
            }

            if (TargetPlatformVersion != null)
            {
                if (TargetPlatformDirectory == null)
                {
                    builder.AppendSwitch("/targetplatform:" + TargetPlatformVersion);
                }
                else
                {
                    builder.AppendSwitchIfNotNull("/targetplatform:" + TargetPlatformVersion + ",", TargetPlatformDirectory);
                }
            }

            builder.AppendSwitchIfNotNull("/target:", TargetKind);

            builder.AppendSwitchIfNotNull("/ver:", Version);

            if (XmlDocumentation)
            {
                builder.AppendSwitch("/xmldocs");
            }

            builder.AppendSwitchIfNotNull("/lib:", SearchDirectories, " /lib:");

            builder.AppendFileNamesIfNotNull(InputAssemblies, " ");

            return(builder.ToString());
        }
예제 #15
0
        /// <summary>
        /// Launches Visual Studio.
        /// </summary>
        /// <param name="arguments">The current <see cref="ProgramArguments" />.</param>
        /// <param name="visualStudioInstance">A <see cref="VisualStudioInstance" /> object representing which instance of Visual Studio to launch.</param>
        /// <param name="solutionFileFullPath">The full path to the solution file.</param>
        /// <param name="logger">A <see cref="ISlnGenLogger" /> to use for logging.</param>
        /// <returns>true if Visual Studio was launched, otherwise false.</returns>
        public static bool TryLaunch(ProgramArguments arguments, VisualStudioInstance visualStudioInstance, string solutionFileFullPath, ISlnGenLogger logger)
        {
            if (!arguments.ShouldLaunchVisualStudio())
            {
                return(true);
            }

            if (!Utility.RunningOnWindows)
            {
                logger.LogWarning("Launching Visual Studio is not currently supported on your operating system.");

                return(true);
            }

            bool loadProjectsInVisualStudio = arguments.ShouldLoadProjectsInVisualStudio();
            bool enableShellExecute         = arguments.EnableShellExecute();

            string devEnvFullPath = arguments.DevEnvFullPath?.LastOrDefault();

            if (!enableShellExecute || !loadProjectsInVisualStudio || Program.CurrentDevelopmentEnvironment.IsCorext)
            {
                if (devEnvFullPath.IsNullOrWhiteSpace())
                {
                    if (visualStudioInstance == null)
                    {
                        logger.LogError(
                            Program.CurrentDevelopmentEnvironment.IsCorext
                                ? $"Could not find a Visual Studio {Environment.GetEnvironmentVariable("VisualStudioVersion")} installation.  Please do one of the following:\n a) Specify a full path to devenv.exe via the -vs command-line argument\n b) Update your corext.config to specify a version of MSBuild.Corext that matches a Visual Studio version you have installed\n c) Install a version of Visual Studio that matches the version of MSBuild.Corext in your corext.config"
                                : "Could not find a Visual Studio installation.  Please specify the full path to devenv.exe via the -vs command-line argument");

                        return(false);
                    }

                    if (visualStudioInstance.IsBuildTools)
                    {
                        logger.LogError("Cannot use a BuildTools instance of Visual Studio.");

                        return(false);
                    }

                    devEnvFullPath = Path.Combine(visualStudioInstance.InstallationPath, "Common7", "IDE", "devenv.exe");
                }
            }

            if (solutionFileFullPath.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(solutionFileFullPath));
            }

            CommandLineBuilder commandLineBuilder = new CommandLineBuilder();

            ProcessStartInfo processStartInfo;

            if (!devEnvFullPath.IsNullOrWhiteSpace())
            {
                if (!File.Exists(devEnvFullPath))
                {
                    logger.LogError($"The specified path to Visual Studio ({devEnvFullPath}) does not exist or is inaccessible.");

                    return(false);
                }

                processStartInfo = new ProcessStartInfo
                {
                    FileName        = devEnvFullPath !,
                    UseShellExecute = false,
                };

                commandLineBuilder.AppendFileNameIfNotNull(solutionFileFullPath);

                if (!arguments.ShouldLoadProjectsInVisualStudio())
                {
                    commandLineBuilder.AppendSwitch(DoNotLoadProjectsCommandLineArgument);
                }
            }
            else
            {
                processStartInfo = new ProcessStartInfo
                {
                    FileName        = solutionFileFullPath,
                    UseShellExecute = true,
                };
            }

            try
            {
                processStartInfo.Arguments = commandLineBuilder.ToString();

                Process process = new Process
                {
                    StartInfo = processStartInfo,
                };

                logger.LogMessageHigh("Launching Visual Studio...");
                logger.LogMessageLow("  FileName = {0}", processStartInfo.FileName);
                logger.LogMessageLow("  Arguments = {0}", processStartInfo.Arguments);
                logger.LogMessageLow("  UseShellExecute = {0}", processStartInfo.UseShellExecute);
                logger.LogMessageLow("  WindowStyle = {0}", processStartInfo.WindowStyle);

                if (!process.Start())
                {
                    logger.LogError("Failed to launch Visual Studio.");
                }
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to launch Visual Studio. {e.Message}");
            }

            return(true);
        }
예제 #16
0
        /// <summary>
        /// Generates the svn arguments.
        /// </summary>
        /// <returns></returns>
        protected virtual void AppendArguments(CommandLineBuilder commandLine)
        {
            commandLine.AppendSwitchIfNotNull("--username ", Username);
            commandLine.AppendSwitchIfNotNull("--password ", Password);
            commandLine.AppendSwitchIfNotNull("--message ", Message);

            commandLine.AppendSwitchIfTrue("--force", Force);
            commandLine.AppendSwitchIfTrue("--verbose", Verbose);

            commandLine.AppendSwitchIfTrue("--xml", Xml);
            commandLine.AppendSwitchIfTrue("--non-interactive", NonInteractive);
            commandLine.AppendSwitchIfTrue("--no-auth-cache", NoAuthCache);

            // raw arguments
            if (!string.IsNullOrEmpty(Arguments))
                commandLine.AppendSwitch(Arguments);
        }
예제 #17
0
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            if (this.AllowDuplicateResources)
            {
                builder.AppendSwitch(@"/allowDuplicateResources");
            }

            if (this.AllowDuplicateTypes != null)
            {
                foreach (ITaskItem allowDuplicateType in this.AllowDuplicateTypes)
                {
                    builder.AppendSwitch(@"/allowDup:" + allowDuplicateType.ItemSpec);
                }
            }

            if (this.AllowZeroPeKind)
            {
                builder.AppendSwitch(@"/zeroPeKind");
            }

            if (this.AttributeFile != null)
            {
                builder.AppendSwitch(string.Format(CultureInfo.CurrentCulture, "/attr:\"{0}\"", this.AttributeFile.ItemSpec));
            }

            if (this.Closed)
            {
                builder.AppendSwitch(@"/closed");
            }

            if (this.CopyAttributes)
            {
                builder.AppendSwitch(@"/copyattrs");
            }

            if (!this.DebugInfo)
            {
                builder.AppendSwitch(@"/ndebug");
            }

            if (this.DelaySign)
            {
                builder.AppendSwitch(@"/delaysign");
            }

            if (this.ExcludeFile != null)
            {
                builder.AppendSwitch(string.Format(CultureInfo.CurrentCulture, "/internalize:\"{0}\"", this.ExcludeFile.ItemSpec));
            }
            else if (this.Internalize)
            {
                builder.AppendSwitch(@"/internalize");
            }

            if (this.KeyFile != null)
            {
                builder.AppendSwitch(string.Format(CultureInfo.CurrentCulture, "/keyfile:\"{0}\"", this.KeyFile.ItemSpec));
            }

            if (this.LogFile != null)
            {
                builder.AppendSwitch(string.Format(CultureInfo.CurrentCulture, "/log:\"{0}\"", this.LogFile.ItemSpec));
            }

            if (this.PublicKeyTokens)
            {
                builder.AppendSwitch(@"/useFullPublicKeyForReferences");
            }

            if (this.SearchDirectories != null)
            {
                foreach (ITaskItem searchDirectory in this.SearchDirectories)
                {
                    builder.AppendSwitch(@"/lib:" + searchDirectory.ItemSpec);
                }
            }

            if (this.TargetPlatformVersion != null)
            {
                builder.AppendSwitch(@"/targetplatform:" + this.TargetPlatformVersion + @"," + this.TargetPlatformDirectory.ItemSpec);
            }

            if (this.TargetKind != null)
            {
                builder.AppendSwitch(@"/target:" + this.TargetKind);
            }

            if (this.UnionMerge)
            {
                builder.AppendSwitch(@"/union");
            }

            if (this.Version != null)
            {
                builder.AppendSwitch(@"/ver:" + this.Version);
            }

            if (this.XmlDocs)
            {
                builder.AppendSwitch(@"/xmldocs");
            }

            builder.AppendSwitch(@"/align:" + this.FileAlignment);
            builder.AppendSwitch(string.Format(CultureInfo.CurrentCulture, "/out:\"{0}\"", this.OutputFile.ItemSpec));
            builder.AppendFileNamesIfNotNull(this.InputAssemblies, @" ");

            return(builder.ToString());
        }
예제 #18
0
        /// <summary>
        /// Returns a string value containing the command line arguments to pass directly to the executable file.
        /// </summary>
        /// <returns>
        /// A string value containing the command line arguments to pass directly to the executable file.
        /// </returns>
        protected override string GenerateCommandLineCommands()
        {
            var builder = new CommandLineBuilder();

            builder.AppendSwitch("pack");
            builder.AppendFileNameIfNotNull(File);
            builder.AppendSwitchIfNotNull("-OutputDirectory ", OutputDirectory);
            builder.AppendSwitchIfNotNull("-BasePath ", BasePath);
            builder.AppendSwitchIfNotNull("-Version ", Version);
            builder.AppendSwitchIfNotNull("-Suffix ", Suffix);
            builder.AppendSwitchIfNotNull("-Verbosity ", Verbosity);
            builder.AppendSwitchIfNotNull("-MinClientVersion", MinClientVersion);

            if (ExcludeEmptyDirectories)
            {
                builder.AppendSwitch("-ExcludeEmptyDirectories");
            }

            if (Build)
            {
                builder.AppendSwitch("-Build");
            }

            if (Tool)
            {
                builder.AppendSwitch("-Tool");
            }

            // backward compatible with old Verbose property
            if (Verbosity == null && Verbose)
            {
                builder.AppendSwitch("-Verbosity detailed");
            }

            if (Symbols)
            {
                builder.AppendSwitch("-Symbols");
            }

            if (NoDefaultExcludes)
            {
                builder.AppendSwitch("-NoDefaultExcludes");
            }

            if (NoPackageAnalysis)
            {
                builder.AppendSwitch("-NoPackageAnalysis");
            }

            if (IncludeReferencedProjects)
            {
                builder.AppendSwitch("-IncludeReferencedProjects");
            }

            if (ForceEnglishOutput)
            {
                builder.AppendSwitch("-ForceEnglishOutput");
            }

            builder.AppendSwitchIfNotNull("-Exclude ", Exclude);
            builder.AppendSwitchIfNotNull("-Properties ", Properties);

            return(builder.ToString());
        }
예제 #19
0
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            builder.AppendSwitch("--noheader");
            builder.AppendFileNamesIfNotNull(this.Assemblies, " ");
            if (this.Use32Bit)
            {
                builder.AppendSwitch("--x86");
            }

            if (this.TeamCity)
            {
                builder.AppendSwitch("--teamcity");
            }

            if (!this.NoShadow)
            {
                builder.AppendSwitch("--shadowcopy");
            }

            if (this.DisposeRunners)
            {
                builder.AppendSwitch("--dispose-runners");
            }

            if (this.WorkerThreads > 0)
            {
                builder.AppendSwitch("--workers=" + this.WorkerThreads);
            }

            if (this.TestTimeout > 0)
            {
                builder.AppendSwitch("--timeout=" + this.TestTimeout);
            }

            if (this.Agents > 0)
            {
                builder.AppendSwitch("--agents=" + this.Agents);
            }

            builder.AppendSwitchIfNotNull("--labels=", this.Labels);
            builder.AppendSwitchIfNotNull("--test=", this.Test);
            builder.AppendSwitchIfNotNull("--config=", this.Configuration);
            builder.AppendSwitchIfNotNull("--where=", this.Where);
            builder.AppendSwitchIfNotNull("--process=", this.Process);
            builder.AppendSwitchIfNotNull("--domain=", this.Domain);
            builder.AppendSwitchIfNotNull("--framework=", this.Framework);

            if (this.OutputXmlFile != null)
            {
                builder.AppendSwitch("--result=" + this.OutputXmlFile + ";format=nunit2");
            }
            else
            {
                builder.AppendSwitch("--result=TestResult.xml;format=nunit2");
            }

            builder.AppendSwitchIfNotNull("--err=", this.ErrorOutputFile);
            builder.AppendSwitchIfNotNull("--out=", this.OutputFile);
            return(builder.ToString());
        }
예제 #20
0
 /// <summary>
 /// Generates the arguments.
 /// </summary>
 /// <param name="builder">The builder.</param>
 protected override void GenerateArguments(CommandLineBuilder builder)
 {
     builder.AppendSwitch("--porcelain");
     base.GenerateArguments(builder);
 }
예제 #21
0
        protected virtual CommandLineBuilder GetCommandLineBuilder()
        {
            var cmd = new CommandLineBuilder();

            if (!string.IsNullOrEmpty(JavaOptions))
            {
                cmd.AppendSwitch(JavaOptions);
            }
            cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);
            cmd.AppendSwitchIfNotNull("-classpath ", JarPath);
            cmd.AppendSwitch(MainClass);

            if (!string.IsNullOrEmpty(ExtraArguments))
            {
                cmd.AppendSwitch(ExtraArguments);                  // it should contain "--dex".
            }
            if (Debug)
            {
                cmd.AppendSwitch("--debug");
            }
            else
            {
                cmd.AppendSwitch("--release");
            }

            //NOTE: if this is blank, we can omit --min-api in this call
            if (!string.IsNullOrEmpty(AndroidManifestFile))
            {
                var doc           = AndroidAppManifest.Load(AndroidManifestFile, MonoAndroidHelper.SupportedVersions);
                int minApiVersion = doc.MinSdkVersion == null ? 4 : (int)doc.MinSdkVersion;
                cmd.AppendSwitchIfNotNull("--min-api ", minApiVersion.ToString());
            }

            if (!EnableDesugar)
            {
                cmd.AppendSwitch("--no-desugaring");
            }

            var injars  = new List <string> ();
            var libjars = new List <string> ();

            if (AlternativeJarLibrariesToEmbed?.Length > 0)
            {
                Log.LogDebugMessage("  processing AlternativeJarLibrariesToEmbed...");
                foreach (var jar in AlternativeJarLibrariesToEmbed)
                {
                    injars.Add(jar.ItemSpec);
                }
            }
            else if (JavaLibrariesToEmbed != null)
            {
                Log.LogDebugMessage("  processing ClassesZip, JavaLibrariesToEmbed...");
                if (!string.IsNullOrEmpty(ClassesZip) && File.Exists(ClassesZip))
                {
                    injars.Add(ClassesZip);
                }
                foreach (var jar in JavaLibrariesToEmbed)
                {
                    injars.Add(jar.ItemSpec);
                }
            }
            libjars.Add(JavaPlatformJarPath);
            if (JavaLibrariesToReference != null)
            {
                foreach (var jar in JavaLibrariesToReference)
                {
                    libjars.Add(jar.ItemSpec);
                }
            }

            cmd.AppendSwitchIfNotNull("--output ", OutputDirectory);
            foreach (var jar in libjars)
            {
                cmd.AppendSwitchIfNotNull("--lib ", jar);
            }
            foreach (var jar in injars)
            {
                cmd.AppendFileNameIfNotNull(jar);
            }

            return(cmd);
        }
예제 #22
0
        protected override string GenerateCommandLineCommands()
        {
            //   Running command: C:\Program Files\Java\jdk1.6.0_25\bin\java.exe -jar
            //     C:\Program Files (x86)\Android\android-sdk\platform-tools\lib\dx.jar --dex
            //     --output=C:\Users\jeff\Documents\Visual Studio 2010\Projects\<project>\...\android\bin\classes.dex
            //     C:\Users\jeff\Documents\Visual Studio 2010\Projects\<project>\...\android\bin\classes
            //     C:\Users\jeff\Documents\Visual Studio 2010\Projects\<project>\...\android\bin\mono.android.jar

            var cmd = new CommandLineBuilder();

            if (!UseDx)
            {
                // Add the JavaOptions if they are not null
                // These could be any of the additional options
                if (!string.IsNullOrEmpty(JavaOptions))
                {
                    cmd.AppendSwitch(JavaOptions);
                }

                cmd.AppendSwitchIfNotNull("-Dfile.encoding=", "UTF8");
                // Add the specific -XmxN to override the default heap size for the JVM
                // N can be in the form of Nm or NGB (e.g 100m or 1GB )
                cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

                cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(DxJarPath));
            }
            else
            {
                // To pass additional java parameters to `dx` you must
                // provide the parameter without the leading `-`
                // the dx tool will add that in after stripping off
                // the `-J`
                cmd.AppendSwitchIfNotNull("-JDfile.encoding=", "UTF8");
            }

            cmd.AppendSwitch(DxExtraArguments);

            cmd.AppendSwitchIfNotNull("--input-list=", inputListFile);

            if (MultiDexEnabled)
            {
                if (string.IsNullOrEmpty(MultiDexMainDexListFile))
                {
                    Log.LogCodedWarning("XA4305", Properties.Resources.XA4305, nameof(MultiDexMainDexListFile));
                }
                else if (!File.Exists(MultiDexMainDexListFile))
                {
                    Log.LogCodedWarning("XA4305", MultiDexMainDexListFile, 0, Properties.Resources.XA4305_File_Missing, MultiDexMainDexListFile);
                }
                else
                {
                    cmd.AppendSwitch("--multi-dex");
                    cmd.AppendSwitchIfNotNull("--main-dex-list=", MultiDexMainDexListFile);
                }
            }
            cmd.AppendSwitchIfNotNull("--output ", Path.GetDirectoryName(ClassesOutputDirectory));

            using (var sw = new StreamWriter(path: inputListFile, append: false,
                                             encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false))) {
                // .jar files
                if (AlternativeJarFiles != null && AlternativeJarFiles.Any())
                {
                    Log.LogDebugMessage("  processing AlternativeJarFiles...");
                    foreach (var l in AlternativeJarFiles)
                    {
                        var fullPath = Path.GetFullPath(l.ItemSpec);
                        Log.LogDebugMessage($"    {fullPath}");
                        sw.WriteLine(fullPath);
                    }
                }
                else
                {
                    Log.LogDebugMessage("  processing ClassesOutputDirectory...");
                    if (!string.IsNullOrEmpty(ClassesZip) && File.Exists(ClassesZip))
                    {
                        Log.LogDebugMessage($"    {ClassesZip}");
                        sw.WriteLine(Path.GetFullPath(ClassesZip));
                    }
                    foreach (var jar in JavaLibrariesToCompile)
                    {
                        var fullPath = Path.GetFullPath(jar.ItemSpec);
                        Log.LogDebugMessage($"    {fullPath}");
                        sw.WriteLine(fullPath);
                    }
                }
            }

            return(cmd.ToString());
        }
예제 #23
0
 /// <summary>
 /// Generates the command.
 /// </summary>
 /// <param name="builder">The <see cref="CommandLineBuilder"/>.</param>
 protected virtual void GenerateCommand(CommandLineBuilder builder)
 {
     builder.AppendSwitch(Command);
     builder.AppendFileNamesIfNotNull(Files, " ");
 }
예제 #24
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

                        #if DEBUG
            cmd.AppendSwitch("/v");
                        #endif

            cmd.AppendSwitch("/nostdlib");
            cmd.AppendSwitchIfNotNull("/baselib:", BaseLibDll);
            cmd.AppendSwitchIfNotNull("/out:", OutputAssembly);

            string dir;
            if (!string.IsNullOrEmpty(BaseLibDll))
            {
                dir = Path.GetDirectoryName(BaseLibDll);
                cmd.AppendSwitchIfNotNull("/lib:", dir);
                cmd.AppendSwitchIfNotNull("/r:", Path.Combine(dir, "mscorlib.dll"));
            }

            if (ProcessEnums)
            {
                cmd.AppendSwitch("/process-enums");
            }

            if (EmitDebugInformation)
            {
                cmd.AppendSwitch("/debug");
            }

            if (AllowUnsafeBlocks)
            {
                cmd.AppendSwitch("/unsafe");
            }

            cmd.AppendSwitchIfNotNull("/ns:", Namespace);

            if (!string.IsNullOrEmpty(DefineConstants))
            {
                var strv      = DefineConstants.Split(new [] { ';' });
                var sanitized = new List <string> ();

                foreach (var str in strv)
                {
                    if (str != string.Empty)
                    {
                        sanitized.Add(str);
                    }
                }

                if (sanitized.Count > 0)
                {
                    cmd.AppendSwitchIfNotNull("/d:", string.Join(";", sanitized.ToArray()));
                }
            }

            //cmd.AppendSwitch ("/e");

            foreach (var item in ApiDefinitions)
            {
                cmd.AppendFileNameIfNotNull(Path.GetFullPath(item.ItemSpec));
            }

            if (CoreSources != null)
            {
                foreach (var item in CoreSources)
                {
                    cmd.AppendSwitchIfNotNull("/s:", Path.GetFullPath(item.ItemSpec));
                }
            }

            if (Sources != null)
            {
                foreach (var item in Sources)
                {
                    cmd.AppendSwitchIfNotNull("/x:", Path.GetFullPath(item.ItemSpec));
                }
            }

            if (AdditionalLibPaths != null)
            {
                foreach (var item in AdditionalLibPaths)
                {
                    cmd.AppendSwitchIfNotNull("/lib:", Path.GetFullPath(item.ItemSpec));
                }
            }

            HandleReferences(cmd);

            if (Resources != null)
            {
                foreach (var item in Resources)
                {
                    var    args = new List <string> ();
                    string id;

                    args.Add(item.ToString());
                    id = item.GetMetadata("LogicalName");
                    if (!string.IsNullOrEmpty(id))
                    {
                        args.Add(id);
                    }

                    cmd.AppendSwitchIfNotNull("/res:", args.ToArray(), ",");
                }
            }

            if (NativeLibraries != null)
            {
                foreach (var item in NativeLibraries)
                {
                    var    args = new List <string> ();
                    string id;

                    args.Add(item.ToString());
                    id = item.GetMetadata("LogicalName");
                    if (string.IsNullOrEmpty(id))
                    {
                        id = Path.GetFileName(args[0]);
                    }
                    args.Add(id);

                    cmd.AppendSwitchIfNotNull("/link-with:", args.ToArray(), ",");
                }
            }

            if (GeneratedSourcesDir != null)
            {
                cmd.AppendSwitchIfNotNull("/tmpdir:", Path.GetFullPath(GeneratedSourcesDir));
            }

            if (GeneratedSourcesFileList != null)
            {
                cmd.AppendSwitchIfNotNull("/sourceonly:", Path.GetFullPath(GeneratedSourcesFileList));
            }

            cmd.AppendSwitch($"/target-framework={TargetFrameworkMoniker}");

            if (!string.IsNullOrEmpty(ExtraArgs))
            {
                var    extraArgs = CommandLineArgumentBuilder.Parse(ExtraArgs);
                var    target    = OutputAssembly;
                string projectDir;

                if (ProjectDir.StartsWith("~/", StringComparison.Ordinal))
                {
                    // Note: Since the Visual Studio plugin doesn't know the user's home directory on the Mac build host,
                    // it simply uses paths relative to "~/". Expand these paths to their full path equivalents.
                    var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                    projectDir = Path.Combine(home, ProjectDir.Substring(2));
                }
                else
                {
                    projectDir = ProjectDir;
                }

                var customTags = new Dictionary <string, string> (StringComparer.OrdinalIgnoreCase)
                {
                    { "projectdir", projectDir },
                    // Apparently msbuild doesn't propagate the solution path, so we can't get it.
                    // { "solutiondir",  proj.ParentSolution != null ? proj.ParentSolution.BaseDirectory : proj.BaseDirectory },
                };
                // OutputAssembly is optional so it can be null
                if (target != null)
                {
                    var d = Path.GetDirectoryName(target);
                    var n = Path.GetFileName(target);
                    customTags.Add("targetpath", Path.Combine(d, n));
                    customTags.Add("targetdir", d);
                    customTags.Add("targetname", n);
                    customTags.Add("targetext", Path.GetExtension(target));
                }

                for (int i = 0; i < extraArgs.Length; i++)
                {
                    var argument = extraArgs[i];
                    cmd.AppendTextUnquoted(" ");
                    cmd.AppendTextUnquoted(StringParserService.Parse(argument, customTags));
                }
            }

            var v = VerbosityUtils.Merge(ExtraArgs, (LoggerVerbosity)Verbosity);
            if (v.Length > 0)
            {
                foreach (var arg in v)
                {
                    cmd.AppendTextUnquoted(" ");
                    cmd.AppendTextUnquoted(arg);
                }
            }

            return(cmd.ToString());
        }
예제 #25
0
        /// <summary>
        /// Generates the arguments.
        /// </summary>
        /// <param name="builder">The <see cref="CommandLineBuilder"/>.</param>
        protected virtual void GenerateArguments(CommandLineBuilder builder)
        {
            builder.AppendSwitch("/noprompt");

            builder.AppendSwitchIfNotNull("/comment:", Comment);
            builder.AppendSwitchIfNotNull("/version:", Version);
            builder.AppendSwitchIfNotNull("/lock:", Lock);
            builder.AppendSwitchIfNotNull("/type:", Type);
            builder.AppendSwitchIfNotNull("/author:", Author);
            builder.AppendSwitchIfNotNull("/notes:", Notes);
            builder.AppendSwitchIfNotNull("/format:", Format);
            builder.AppendSwitchIfNotNull("/collection:", Collection);
            builder.AppendSwitchIfNotNull("/v:C", ChangesetVersion);
            builder.AppendSwitchIfNotNull("/override:", Override);

            if (Recursive)
            {
                builder.AppendSwitch("/recursive");
            }
            if (All)
            {
                builder.AppendSwitch("/all");
            }
            if (Overwrite)
            {
                builder.AppendSwitch("/overwrite");
            }
            if (Force)
            {
                builder.AppendSwitch("/force");
            }
            if (Preview)
            {
                builder.AppendSwitch("/preview");
            }
            if (Remap)
            {
                builder.AppendSwitch("/remap");
            }
            if (Silent)
            {
                builder.AppendSwitch("/silent");
            }
            if (Saved)
            {
                builder.AppendSwitch("/saved");
            }
            if (Validate)
            {
                builder.AppendSwitch("/validate");
            }
            if (Bypass)
            {
                builder.AppendSwitch("/bypass");
            }

            if (!string.IsNullOrEmpty(UserName))
            {
                string login = "******" + UserName;
                if (!string.IsNullOrEmpty(Password))
                {
                    login += "," + Password;
                }

                builder.AppendSwitch(login);
            }

            if (!string.IsNullOrEmpty(WorkspaceName))
            {
                string workspace = "/workspace:" + WorkspaceName;
                if (!string.IsNullOrEmpty(WorkspaceOwner))
                {
                    workspace += "," + WorkspaceOwner;
                }

                builder.AppendSwitch(workspace);
            }

            if (!string.IsNullOrEmpty(ShelveSetName))
            {
                string shelveset = "/shelveset:" + ShelveSetName;
                if (!string.IsNullOrEmpty(ShelveSetOwner))
                {
                    shelveset += "," + ShelveSetOwner;
                }

                builder.AppendSwitch(shelveset);
            }
        }
예제 #26
0
        protected override string GenerateCommandLineCommands()
        {
            //   Running command: C:\Program Files\Java\jdk1.6.0_25\bin\java.exe -jar
            //     C:\Program Files (x86)\Android\android-sdk\platform-tools\lib\dx.jar --dex
            //     --output=C:\Users\jeff\Documents\Visual Studio 2010\Projects\<project>\...\android\bin\classes.dex
            //     C:\Users\jeff\Documents\Visual Studio 2010\Projects\<project>\...\android\bin\classes
            //     C:\Users\jeff\Documents\Visual Studio 2010\Projects\<project>\...\android\bin\mono.android.jar

            var cmd = new CommandLineBuilder();

            if (!UseDx)
            {
                // Add the JavaOptions if they are not null
                // These could be any of the additional options
                if (!string.IsNullOrEmpty(JavaOptions))
                {
                    cmd.AppendSwitch(JavaOptions);
                }

                // Add the specific -XmxN to override the default heap size for the JVM
                // N can be in the form of Nm or NGB (e.g 100m or 1GB )
                cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

                cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(DxJarPath));
            }

            cmd.AppendSwitch(DxExtraArguments);

            cmd.AppendSwitchIfNotNull("--input-list=", inputListFile);

            if (MultiDexEnabled)
            {
                cmd.AppendSwitch("--multi-dex");
                cmd.AppendSwitchIfNotNull("--main-dex-list=", MultiDexMainDexListFile);
            }
            cmd.AppendSwitchIfNotNull("--output ", Path.GetDirectoryName(ClassesOutputDirectory));

            using (var sw = new StreamWriter(path: inputListFile, append: false,
                                             encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false))) {
                // .jar files
                if (AlternativeJarFiles != null && AlternativeJarFiles.Any())
                {
                    Log.LogDebugMessage("  processing AlternativeJarFiles...");
                    foreach (var l in AlternativeJarFiles)
                    {
                        var fullPath = Path.GetFullPath(l.ItemSpec);
                        Log.LogDebugMessage($"    {fullPath}");
                        sw.WriteLine(fullPath);
                    }
                }
                else
                {
                    Log.LogDebugMessage("  processing ClassesOutputDirectory...");
                    var zip = Path.GetFullPath(Path.Combine(ClassesOutputDirectory, "..", "classes.zip"));
                    if (!File.Exists(zip))
                    {
                        throw new FileNotFoundException($"'{zip}' does not exist. Please rebuild the project.");
                    }
                    Log.LogDebugMessage($"    {zip}");
                    sw.WriteLine(Path.GetFullPath(zip));
                    foreach (var jar in JavaLibrariesToCompile)
                    {
                        var fullPath = Path.GetFullPath(jar.ItemSpec);
                        Log.LogDebugMessage($"    {fullPath}");
                        sw.WriteLine(fullPath);
                    }
                }
            }

            return(cmd.ToString());
        }
예제 #27
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

            // Add the JavaOptions if they are not null
            // These could be any of the additional options
            if (!string.IsNullOrEmpty(JavaOptions))
            {
                cmd.AppendSwitch(JavaOptions);
            }

            // Add the specific -XmxN to override the default heap size for the JVM
            // N can be in the form of Nm or NGB (e.g 100m or 1GB )
            cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

            // See https://bugzilla.xamarin.com/show_bug.cgi?id=21096
            cmd.AppendSwitch("-XX:-UseSplitVerifier");

            // Arguments sent to java.exe
            cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(MonoAndroidToolsDirectory, "jar2xml.jar"));

            foreach (var jar in SourceJars)
            {
                cmd.AppendSwitchIfNotNull("--jar=", Path.GetFullPath(jar.ItemSpec));
            }

            var libraryProjectJars = MonoAndroidHelper.ExpandFiles(LibraryProjectJars);

            foreach (var jar in libraryProjectJars)
            {
                if (MonoAndroidHelper.IsEmbeddedReferenceJar(jar))
                {
                    cmd.AppendSwitchIfNotNull("--ref=", Path.GetFullPath(jar));
                }
                else
                {
                    cmd.AppendSwitchIfNotNull("--jar=", Path.GetFullPath(jar));
                }
            }

            // Arguments sent to jar2xml
            var jarpath = Path.Combine(AndroidSdkDirectory, "platforms", "android-" + MonoAndroidHelper.GetPlatformApiLevelName(AndroidApiLevel), "android.jar");

            cmd.AppendSwitchIfNotNull("--ref=", Path.GetFullPath(jarpath));

            cmd.AppendSwitchIfNotNull("--out=", Path.GetFullPath(OutputFile));

            if (ReferenceJars != null)
            {
                foreach (var jar in ReferenceJars)
                {
                    cmd.AppendSwitchIfNotNull("--ref=", Path.GetFullPath(jar.ItemSpec));
                }
            }

            if (DroidDocPaths != null)
            {
                foreach (var path in DroidDocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--droiddocpath=", Path.GetFullPath(path));
                }
            }

            if (JavaDocPaths != null)
            {
                foreach (var path in JavaDocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--javadocpath=", Path.GetFullPath(path));
                }
            }

            if (Java7DocPaths != null)
            {
                foreach (var path in Java7DocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--java7docpath=", Path.GetFullPath(path));
                }
            }

            if (Java8DocPaths != null)
            {
                foreach (var path in Java8DocPaths.Split(';'))
                {
                    cmd.AppendSwitchIfNotNull("--java8docpath=", Path.GetFullPath(path));
                }
            }

            if (JavaDocs != null)
            {
                foreach (var doc in JavaDocs)
                {
                    var opt = GetJavadocOption(doc.ItemSpec);
                    if (opt != null)
                    {
                        cmd.AppendSwitchIfNotNull(opt, Path.GetFullPath(Path.GetDirectoryName(doc.ItemSpec)));
                    }
                }
            }
            return(cmd.ToString());
        }
예제 #28
0
        /// <summary>
        /// Generates the command line arguments for the OpenCover tool.
        /// </summary>
        /// <returns>The command line arguments for the OpenCover tool.</returns>
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            if (Service)
            {
                builder.AppendSwitch("-service");
            }
            if (Register)
            {
                builder.AppendSwitch("-register:user");
            }
            if (!DefaultFilters)
            {
                builder.AppendSwitch("-nodefaultfilters");
            }
            if (MergeByHash)
            {
                builder.AppendSwitch("-mergebyhash");
            }
            if (ShowUnvisited)
            {
                builder.AppendSwitch("-showunvisited");
            }
            if (OldStyle)
            {
                builder.AppendSwitch("-oldstyle");
            }
            if (ReturnTargetCode)
            {
                builder.AppendSwitch("-returntargetcode" + (TargetCodeOffset != 0 ? $":{TargetCodeOffset}" : ""));
            }

            builder.AppendSwitchIfNotNull("-target:", Target);
            builder.AppendSwitchIfNotNull("-targetdir:", TargetWorkingDir);
            builder.AppendSwitchIfNotNull("-targetargs:", TargetArgs);

            if ((Filter != null) && (Filter.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-filter:", string.Join <ITaskItem>(" ", Filter));
            }

            if ((ExcludeByAttribute != null) && (ExcludeByAttribute.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-excludebyattribute:", string.Join <ITaskItem>(";", ExcludeByAttribute));
            }

            if ((ExcludeByFile != null) && (ExcludeByFile.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-excludebyfile:", string.Join <ITaskItem>(";", ExcludeByFile));
            }

            if ((CoverByTest != null) && (CoverByTest.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-coverbytest:", string.Join <ITaskItem>(";", CoverByTest));
            }

            builder.AppendSwitchIfNotNull("-output:", Output);

            return(builder.ToString());
        }
예제 #29
0
        private static unsafe CommandLineBuilder Init_MakeConEmuCommandLine([NotNull] ConEmuStartInfo startinfo, [NotNull] HostContext hostcontext, [CanBeNull] AnsiLog ansilog, [NotNull] DirectoryInfo dirLocalTempRoot)
        {
            if (startinfo == null)
            {
                throw new ArgumentNullException(nameof(startinfo));
            }
            if (hostcontext == null)
            {
                throw new ArgumentNullException(nameof(hostcontext));
            }

            var cmdl = new CommandLineBuilder();

            // This sets up hosting of ConEmu in our control
            cmdl.AppendSwitch("-InsideWnd");
            cmdl.AppendFileNameIfNotNull("0x" + ((ulong)hostcontext.HWndParent).ToString("X"));

            // Don't use keyboard hooks in ConEmu when embedded
            cmdl.AppendSwitch("-NoKeyHooks");

            // Basic settings, like fonts and hidden tab bar
            // Plus some of the properties on this class
            cmdl.AppendSwitch("-LoadCfgFile");
            cmdl.AppendFileNameIfNotNull(Init_MakeConEmuCommandLine_EmitConfigFile(dirLocalTempRoot, startinfo, hostcontext));

            if (!string.IsNullOrEmpty(startinfo.StartupDirectory))
            {
                cmdl.AppendSwitch("-Dir");
                cmdl.AppendFileNameIfNotNull(startinfo.StartupDirectory);
            }

            // ANSI Log file
            if (ansilog != null)
            {
                cmdl.AppendSwitch("-AnsiLog");
                cmdl.AppendFileNameIfNotNull(ansilog.Directory.FullName);
            }
            if (dirLocalTempRoot == null)
            {
                throw new ArgumentNullException(nameof(dirLocalTempRoot));
            }

            // This one MUST be the last switch
            cmdl.AppendSwitch("-cmd");

            // Console mode command
            // NOTE: if placed AFTER the payload command line, otherwise somehow conemu hooks won't fetch the switch out of the cmdline, e.g. with some complicated git fetch/push cmdline syntax which has a lot of colons inside on itself
            string sConsoleExitMode;

            switch (startinfo.WhenConsoleProcessExits)
            {
            case WhenConsoleProcessExits.CloseConsoleEmulator:
                sConsoleExitMode = "n";
                break;

            case WhenConsoleProcessExits.KeepConsoleEmulator:
                sConsoleExitMode = "c0";
                break;

            case WhenConsoleProcessExits.KeepConsoleEmulatorAndShowMessage:
                sConsoleExitMode = "c";
                break;

            default:
                throw new ArgumentOutOfRangeException("ConEmuStartInfo" + "::" + "WhenConsoleProcessExits", startinfo.WhenConsoleProcessExits, "This is not a valid enum value.");
            }
            cmdl.AppendSwitchIfNotNull("-cur_console:", $"{(startinfo.IsElevated ? "a" : "")}{sConsoleExitMode}");

            // And the shell command line itself
            cmdl.AppendSwitch(startinfo.ConsoleProcessCommandLine);

            return(cmdl);
        }
예제 #30
0
        protected override string GenerateCommandLineCommands()
        {
            var cmd = new CommandLineBuilder();

            if (!UseProguard)
            {
                // Add the JavaOptions if they are not null
                // These could be any of the additional options
                if (!string.IsNullOrEmpty(JavaOptions))
                {
                    cmd.AppendSwitch(JavaOptions);
                }

                // Add the specific -XmxN to override the default heap size for the JVM
                // N can be in the form of Nm or NGB (e.g 100m or 1GB )
                cmd.AppendSwitchIfNotNull("-Xmx", JavaMaximumHeapSize);

                cmd.AppendSwitchIfNotNull("-jar ", Path.Combine(ProguardJarPath));
            }

            if (!ClassesOutputDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                ClassesOutputDirectory += Path.DirectorySeparatorChar;
            }

            var classesZip = Path.Combine(ClassesOutputDirectory, "classes.zip");
            var acwLines   = File.ReadAllLines(AcwMapFile);

            using (var appcfg = File.CreateText(ProguardGeneratedApplicationConfiguration))
                for (int i = 0; i + 3 < acwLines.Length; i += 4)
                {
                    try {
                        var java = acwLines [i + 3].Substring(acwLines [i + 3].IndexOf(';') + 1);
                        appcfg.WriteLine("-keep class " + java + " { *; }");
                    } catch {
                        // skip invalid lines
                    }
                }

            var injars  = new List <string> ();
            var libjars = new List <string> ();

            injars.Add(classesZip + ProguardInputJarFilter);
            if (JavaLibrariesToEmbed != null)
            {
                foreach (var jarfile in JavaLibrariesToEmbed)
                {
                    injars.Add(jarfile.ItemSpec + ProguardInputJarFilter);
                }
            }

            using (var xamcfg = File.Create(ProguardCommonXamarinConfiguration))
                GetType().Assembly.GetManifestResourceStream("proguard_xamarin.cfg").CopyTo(xamcfg);

            var configs = ProguardConfigurationFiles
                          .Replace("{sdk.dir}", AndroidSdkDirectory + Path.DirectorySeparatorChar)
                          .Replace("{intermediate.common.xamarin}", ProguardCommonXamarinConfiguration)
                          .Replace("{intermediate.references}", ProguardGeneratedReferenceConfiguration)
                          .Replace("{intermediate.application}", ProguardGeneratedApplicationConfiguration)
                          .Replace("{project}", string.Empty)        // current directory anyways.
                          .Split(';')
                          .Select(s => s.Trim())
                          .Where(s => !string.IsNullOrWhiteSpace(s));

            var enclosingChar = OS.IsWindows ? "\"" : "'";

            foreach (var file in configs)
            {
                if (File.Exists(file))
                {
                    cmd.AppendSwitchUnquotedIfNotNull("-include ", $"{enclosingChar}{file}{enclosingChar}");
                }
                else
                {
                    Log.LogWarning("Proguard configuration file '{0}' was not found.", file);
                }
            }

            libjars.Add(JavaPlatformJarPath);
            if (ExternalJavaLibraries != null)
            {
                foreach (var jarfile in ExternalJavaLibraries.Select(p => p.ItemSpec))
                {
                    libjars.Add(jarfile);
                }
            }

            string delimiter = $"{enclosingChar}{Path.PathSeparator}{enclosingChar}";

            cmd.AppendSwitchUnquotedIfNotNull("-injars ", enclosingChar + string.Join(delimiter, injars.Distinct()) + enclosingChar);
            cmd.AppendSwitchUnquotedIfNotNull("-libraryjars ", enclosingChar + string.Join(delimiter, libjars.Distinct()) + enclosingChar);
            cmd.AppendSwitchIfNotNull("-outjars ", ProguardJarOutput);

            if (EnableLogging)
            {
                cmd.AppendSwitchIfNotNull("-dump ", DumpOutput);
                cmd.AppendSwitchIfNotNull("-printseeds ", PrintSeedsOutput);
                cmd.AppendSwitchIfNotNull("-printusage ", PrintUsageOutput);
                cmd.AppendSwitchIfNotNull("-printmapping ", PrintMappingOutput);
            }

            // http://stackoverflow.com/questions/5701126/compile-with-proguard-gives-exception-local-variable-type-mismatch#7587680
            cmd.AppendSwitch("-optimizations !code/allocation/variable");

            return(cmd.ToString());
        }
예제 #31
0
        /// <summary>
        /// Generates the command line arguments for the OpenCover tool.
        /// </summary>
        /// <returns>The command line arguments for the OpenCover tool.</returns>
        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            if (Service)
            {
                builder.AppendSwitch("-service");
            }
            if (Register)
            {
                builder.AppendSwitch("-register:user");
            }
            if (!DefaultFilters)
            {
                builder.AppendSwitch("-nodefaultfilters");
            }
            if (MergeByHash)
            {
                builder.AppendSwitch("-mergebyhash");
            }
            if (SkipAutoProps)
            {
                builder.AppendSwitch("-skipautoprops");
            }
            if (ShowUnvisited)
            {
                builder.AppendSwitch("-showunvisited");
            }
            if (ReturnTargetCode)
            {
                builder.AppendSwitch("-returntargetcode" + (TargetCodeOffset != 0 ? string.Format(CultureInfo.InvariantCulture, ":{0}", TargetCodeOffset) : null));
            }

            builder.AppendSwitchIfNotNull("-target:", Target);
            builder.AppendSwitchIfNotNull("-targetdir:", TargetWorkingDir);
            builder.AppendSwitchIfNotNull("-targetargs:", TargetArgs);

            if ((Filter != null) && (Filter.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-filter:", string.Join <ITaskItem>(" ", Filter));
            }

            if ((ExcludeByAttribute != null) && (ExcludeByAttribute.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-excludebyattribute:", string.Join <ITaskItem>(";", ExcludeByAttribute));
            }

            if ((ExcludeByFile != null) && (ExcludeByFile.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-excludebyfile:", string.Join <ITaskItem>(";", ExcludeByFile));
            }

            if ((CoverByTest != null) && (CoverByTest.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-coverbytest:", string.Join <ITaskItem>(";", CoverByTest));
            }

            if ((HideSkipped != null) && (HideSkipped.Length > 0))
            {
                builder.AppendSwitchIfNotNull("-hideskipped:", string.Join <ITaskItem>(";", HideSkipped));
            }

            builder.AppendSwitchIfNotNull("-output:", Output);

            return(builder.ToString());
        }
예제 #32
0
        protected string GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile)
        {
            // For creating Resource.designer.cs:
            //   Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt
            //     "package"
            //     "-M" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\AndroidManifest.xml"
            //     "-J" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way"
            //     "-F" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\resources.apk"
            //     "-S" "c:\users\jonathan\documents\visual studio 2010\Projects\MonoAndroidApplication4\MonoAndroidApplication4\obj\Debug\res"
            //     "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "--max-res-version" "10"

            // For packaging:
            //   Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt
            //     "package"
            //     "-f"
            //     "-m"
            //     "-M" "AndroidManifest.xml"
            //     "-J" "src"
            //     "--custom-package" "androidmsbuildtest.androidmsbuildtest"
            //     "-F" "bin\packaged_resources"
            //     "-S" "C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\AndroidMSBuildTest\AndroidMSBuildTest\obj\Debug\res"
            //     "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "--extra-packages" "com.facebook.android:my.another.library"

            var cmd = new CommandLineBuilder();

            cmd.AppendSwitch("package");

            if (MonoAndroidHelper.LogInternalExceptions)
            {
                cmd.AppendSwitch("-v");
            }
            if (NonConstantId)
            {
                cmd.AppendSwitch("--non-constant-id");
            }
            cmd.AppendSwitch("-f");
            cmd.AppendSwitch("-m");
            string manifestFile;
            string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest");

            Directory.CreateDirectory(manifestDir);
            manifestFile = Path.Combine(manifestDir, Path.GetFileName(ManifestFile));
            ManifestDocument manifest = new ManifestDocument(ManifestFile, this.Log);

            manifest.SdkVersion = AndroidSdkPlatform;
            if (currentAbi != null)
            {
                if (!string.IsNullOrEmpty(VersionCodePattern))
                {
                    manifest.CalculateVersionCode(currentAbi, VersionCodePattern, VersionCodeProperties);
                }
                else
                {
                    manifest.SetAbi(currentAbi);
                }
            }
            else if (!string.IsNullOrEmpty(VersionCodePattern))
            {
                manifest.CalculateVersionCode(null, VersionCodePattern, VersionCodeProperties);
            }
            manifest.ApplicationName = ApplicationName;
            manifest.Save(manifestFile);

            cmd.AppendSwitchIfNotNull("-M ", manifestFile);
            var designerDirectory = Path.IsPathRooted(JavaDesignerOutputDirectory) ? JavaDesignerOutputDirectory : Path.Combine(WorkingDirectory, JavaDesignerOutputDirectory);

            Directory.CreateDirectory(designerDirectory);
            cmd.AppendSwitchIfNotNull("-J ", JavaDesignerOutputDirectory);

            if (PackageName != null)
            {
                cmd.AppendSwitchIfNotNull("--custom-package ", PackageName.ToLowerInvariant());
            }

            if (!string.IsNullOrEmpty(currentResourceOutputFile))
            {
                cmd.AppendSwitchIfNotNull("-F ", currentResourceOutputFile + ".bk");
            }
            // The order of -S arguments is *important*, always make sure this one comes FIRST
            cmd.AppendSwitchIfNotNull("-S ", resourceDirectory.TrimEnd('\\'));
            if (AdditionalResourceDirectories != null)
            {
                foreach (var dir in AdditionalResourceDirectories)
                {
                    var resdir = dir.ItemSpec.TrimEnd('\\');
                    if (Directory.Exists(resdir))
                    {
                        cmd.AppendSwitchIfNotNull("-S ", resdir);
                    }
                }
            }
            if (AdditionalAndroidResourcePaths != null)
            {
                foreach (var dir in AdditionalAndroidResourcePaths)
                {
                    var resdir = Path.Combine(dir.ItemSpec, "res");
                    if (Directory.Exists(resdir))
                    {
                        cmd.AppendSwitchIfNotNull("-S ", resdir);
                    }
                }
            }

            if (LibraryProjectJars != null)
            {
                foreach (var jar in LibraryProjectJars)
                {
                    cmd.AppendSwitchIfNotNull("-j ", jar);
                }
            }

            cmd.AppendSwitchIfNotNull("-I ", JavaPlatformJarPath);

            // Add asset directory if it exists
            if (!string.IsNullOrWhiteSpace(AssetDirectory))
            {
                var assetDir = AssetDirectory.TrimEnd('\\');
                if (!Path.IsPathRooted(assetDir))
                {
                    assetDir = Path.Combine(WorkingDirectory, assetDir);
                }
                if (!string.IsNullOrWhiteSpace(assetDir) && Directory.Exists(assetDir))
                {
                    cmd.AppendSwitchIfNotNull("-A ", assetDir);
                }
            }
            if (!string.IsNullOrWhiteSpace(UncompressedFileExtensions))
            {
                foreach (var ext in UncompressedFileExtensions.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    cmd.AppendSwitchIfNotNull("-0 ", ext);
                }
            }

            if (!string.IsNullOrEmpty(ExtraPackages))
            {
                cmd.AppendSwitchIfNotNull("--extra-packages ", ExtraPackages);
            }

            // TODO: handle resource names
            if (ExplicitCrunch)
            {
                cmd.AppendSwitch("--no-crunch");
            }

            cmd.AppendSwitch("--auto-add-overlay");

            if (!string.IsNullOrEmpty(ResourceSymbolsTextFileDirectory))
            {
                cmd.AppendSwitchIfNotNull("--output-text-symbols ", ResourceSymbolsTextFileDirectory);
            }

            var extraArgsExpanded = ExpandString(ExtraArgs);

            if (extraArgsExpanded != ExtraArgs)
            {
                Log.LogDebugMessage("  ExtraArgs expanded: {0}", extraArgsExpanded);
            }

            if (!string.IsNullOrWhiteSpace(extraArgsExpanded))
            {
                cmd.AppendSwitch(extraArgsExpanded);
            }

            if (!AndroidUseLatestPlatformSdk)
            {
                cmd.AppendSwitchIfNotNull("--max-res-version ", ApiLevel);
            }

            return(cmd.ToString());
        }
예제 #33
0
 /// <summary>
 /// Generates the svn command.
 /// </summary>
 /// <returns></returns>
 protected virtual void AppendCommand(CommandLineBuilder commandLine)
 {
     commandLine.AppendSwitch(Command);
     
     // import has paths in diff order
     if (Command == Commands.Import)
     {
         commandLine.AppendFileNameIfNotNull(LocalPath); 
         commandLine.AppendFileNameIfNotNull(RepositoryPath);
     }
     else
     {
         commandLine.AppendFileNameIfNotNull(RepositoryPath);
         commandLine.AppendFileNameIfNotNull(LocalPath);                
     }
     
 }