Пример #1
0
        protected override string GenerateCommandLineCommands()
        {
            //   Running command: C:\Program Files (x86)\Java\jdk1.6.0_20\bin\javac.exe
            //     "-J-Dfile.encoding=UTF8"
            //     "-d" "bin\classes"
            //     "-classpath" "C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\AndroidMSBuildTest\AndroidMSBuildTest\obj\Debug\android\bin\mono.android.jar"
            //     "-bootclasspath" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar"
            //     "-encoding" "UTF-8"
            //     "@C:\Users\Jonathan\AppData\Local\Temp\tmp79c4ac38.tmp"

            //var android_dir = MonoDroid.MonoDroidSdk.GetAndroidProfileDirectory (TargetFrameworkDirectory);

            var cmd = new CommandLineBuilder();

            cmd.AppendSwitchIfNotNull("-J-Dfile.encoding=", "UTF8");

            cmd.AppendSwitchIfNotNull("-d ", ClassesOutputDirectory);

            cmd.AppendSwitchIfNotNull("-classpath ", Jars == null || !Jars.Any() ? null : string.Join(Path.PathSeparator.ToString(), Jars.Select(i => i.ItemSpec)));
            cmd.AppendSwitchIfNotNull("-bootclasspath ", JavaPlatformJarPath);
            cmd.AppendSwitchIfNotNull("-encoding ", "UTF-8");
            cmd.AppendFileNameIfNotNull(string.Format("@{0}", TemporarySourceListFile));
            cmd.AppendSwitchIfNotNull("-target ", JavacTargetVersion);
            cmd.AppendSwitchIfNotNull("-source ", JavacSourceVersion);

            return(cmd.ToString());
        }
Пример #2
0
 protected override void WriteOptionsToResponseFile(StreamWriter sw)
 {
     sw.WriteLine($"-d \"{ClassesOutputDirectory.Replace (@"\", @"\\")}\"");
     sw.WriteLine("-classpath \"{0}\"", Jars == null || !Jars.Any() ? null : string.Join(Path.PathSeparator.ToString(), Jars.Select(i => i.ItemSpec.Replace(@"\", @"\\"))));
     sw.WriteLine("-bootclasspath \"{0}\"", JavaPlatformJarPath.Replace(@"\", @"\\"));
     sw.WriteLine($"-encoding UTF8");
 }
Пример #3
0
        public override bool Execute()
        {
            Log.LogDebugMessage("GetImportedLibraries Task");
            Log.LogDebugMessage("  TargetDirectory: {0}", TargetDirectory);
            if (!Directory.Exists(TargetDirectory))
            {
                Log.LogDebugMessage("Target directory was not found");
                return(true);
            }
            // there could be ./AndroidManifest.xml and bin/AndroidManifest.xml, which will be the same. So, ignore "bin" ones.
            ManifestDocuments = Directory.GetFiles(TargetDirectory, "AndroidManifest.xml", SearchOption.AllDirectories).Where(f => !Path.GetDirectoryName(f).EndsWith("bin")).Select(p => new TaskItem(p)).ToArray();
            NativeLibraries   = Directory.GetFiles(TargetDirectory, "*.so", SearchOption.AllDirectories)
                                .Where(p => MonoAndroidHelper.GetNativeLibraryAbi(p) != null)
                                .Select(p => new TaskItem(p)).ToArray();
            Jars = Directory.GetFiles(TargetDirectory, "*.jar", SearchOption.AllDirectories).Select(p => new TaskItem(p)).ToArray();
            Log.LogDebugTaskItems("  NativeLibraries: ", NativeLibraries);
            Log.LogDebugTaskItems("  Jars: ", Jars);
            Log.LogDebugTaskItems("  ManifestDocuments: ", ManifestDocuments);

            if (!string.IsNullOrEmpty(CacheFile))
            {
                var document = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("Paths",
                                 new XElement("ManifestDocuments", ManifestDocuments.Select(e => new XElement("ManifestDocument", e.ItemSpec))),
                                 new XElement("NativeLibraries", NativeLibraries.Select(e => new XElement("NativeLibrary", e.ItemSpec))),
                                 new XElement("Jars", Jars.Select(e => new XElement("Jar", e.ItemSpec)))
                                 ));
                document.SaveIfChanged(CacheFile);
            }

            return(true);
        }
Пример #4
0
        // Extracts library project contents under e.g. obj/Debug/[__library_projects__/*.jar | res/*/*]
        public override bool Execute()
        {
            Log.LogDebugMessage("ResolveLibraryProjectImports Task");
            Log.LogDebugMessage("  ImportsDirectory: {0}", ImportsDirectory);
            Log.LogDebugMessage("  OutputDirectory: {0}", OutputDirectory);
            Log.LogDebugMessage("  OutputImportDirectory: {0}", OutputImportDirectory);
            Log.LogDebugMessage("  UseShortFileNames: {0}", UseShortFileNames);
            Log.LogDebugTaskItems("  Assemblies: ", Assemblies);

            var jars = new List <string> ();
            var resolvedResourceDirectories = new List <string> ();
            var resolvedAssetDirectories    = new List <string> ();
            var resolvedEnvironmentFiles    = new List <string> ();

            using (var resolver = new DirectoryAssemblyResolver(Log.LogWarning, loadDebugSymbols: false)) {
                Extract(resolver, jars, resolvedResourceDirectories, resolvedAssetDirectories, resolvedEnvironmentFiles);
            }

            Jars = jars.ToArray();
            ResolvedResourceDirectories = resolvedResourceDirectories
                                          .Select(s => new TaskItem(Path.GetFullPath(s)))
                                          .ToArray();
            ResolvedAssetDirectories = resolvedAssetDirectories.ToArray();
            ResolvedEnvironmentFiles = resolvedEnvironmentFiles.ToArray();

            ResolvedResourceDirectoryStamps = ResolvedResourceDirectories
                                              .Select(s => new TaskItem(Path.GetFullPath(Path.Combine(s.ItemSpec, "../..")) + ".stamp"))
                                              .ToArray();

            foreach (var directory in ResolvedResourceDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory.ItemSpec);
            }

            foreach (var directory in ResolvedAssetDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory);
            }

            if (!string.IsNullOrEmpty(CacheFile))
            {
                var document = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("Paths",
                                 new XElement("Jars", string.Join(";", Jars)),
                                 new XElement("ResolvedResourceDirectories",
                                              ResolvedResourceDirectories.Select(e => new XElement("ResolvedResourceDirectory", e))),
                                 new XElement("ResolvedAssetDirectories",
                                              ResolvedAssetDirectories.Select(e => new XElement("ResolvedAssetDirectory", e))),
                                 new XElement("ResolvedEnvironmentFiles",
                                              ResolvedEnvironmentFiles.Select(e => new XElement("ResolvedEnvironmentFile", e))),
                                 new XElement("ResolvedResourceDirectoryStamps",
                                              ResolvedResourceDirectoryStamps.Select(e => new XElement("ResolvedResourceDirectoryStamp", e)))
                                 ));
                document.Save(CacheFile);
            }

            Log.LogDebugTaskItems("  Jars: ", Jars.Select(s => new TaskItem(s)).ToArray());
            Log.LogDebugTaskItems("  ResolvedResourceDirectories: ", ResolvedResourceDirectories.Select(s => new TaskItem(s)).ToArray());
            Log.LogDebugTaskItems("  ResolvedAssetDirectories: ", ResolvedAssetDirectories.Select(s => new TaskItem(s)).ToArray());
            Log.LogDebugTaskItems("  ResolvedEnvironmentFiles: ", ResolvedEnvironmentFiles.Select(s => new TaskItem(s)).ToArray());
            Log.LogDebugTaskItems("  ResolvedResourceDirectoryStamps: ", ResolvedResourceDirectoryStamps);

            return(!Log.HasLoggedErrors);
        }
Пример #5
0
        public override bool RunTask()
        {
            if (!Directory.Exists(TargetDirectory))
            {
                Log.LogDebugMessage("Target directory was not found");
                return(true);
            }

            var manifestDocuments = new List <ITaskItem> ();
            var nativeLibraries   = new List <ITaskItem> ();
            var jarFiles          = new List <ITaskItem> ();

            foreach (var file in Directory.EnumerateFiles(TargetDirectory, "*", SearchOption.AllDirectories))
            {
                if (file.EndsWith(".so", StringComparison.OrdinalIgnoreCase))
                {
                    if (MonoAndroidHelper.GetNativeLibraryAbi(file) != null)
                    {
                        nativeLibraries.Add(new TaskItem(file));
                    }
                }
                else if (file.EndsWith(".jar", StringComparison.OrdinalIgnoreCase))
                {
                    jarFiles.Add(new TaskItem(file));
                }
                else if (file.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                {
                    if (Path.GetFileName(file) == "AndroidManifest.xml")
                    {
                        // there could be ./AndroidManifest.xml and bin/AndroidManifest.xml, which will be the same. So, ignore "bin" ones.
                        var directory = Path.GetFileName(Path.GetDirectoryName(file));
                        if (IgnoredManifestDirectories.Contains(directory))
                        {
                            continue;
                        }
                        manifestDocuments.Add(new TaskItem(file));
                    }
                }
            }

            ManifestDocuments = manifestDocuments.ToArray();
            NativeLibraries   = nativeLibraries.ToArray();
            Jars = jarFiles.ToArray();

            if (!string.IsNullOrEmpty(CacheFile))
            {
                var document = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("Paths",
                                 new XElement("ManifestDocuments", ManifestDocuments.Select(e => new XElement("ManifestDocument", e.ItemSpec))),
                                 new XElement("NativeLibraries", NativeLibraries.Select(e => new XElement("NativeLibrary", e.ItemSpec))),
                                 new XElement("Jars", Jars.Select(e => new XElement("Jar", e.ItemSpec)))
                                 ));
                document.SaveIfChanged(CacheFile);
            }

            Log.LogDebugTaskItems("  NativeLibraries: ", NativeLibraries);
            Log.LogDebugTaskItems("  Jars: ", Jars);
            Log.LogDebugTaskItems("  ManifestDocuments: ", ManifestDocuments);

            return(true);
        }
Пример #6
0
        // Extracts library project contents under e.g. obj/Debug/[__library_projects__/*.jar | res/*/*]
        // Extracts library project contents under e.g. obj/Debug/[lp/*.jar | res/*/*]
        public override bool RunTask()
        {
            var jars = new Dictionary <string, ITaskItem> ();
            var resolvedResourceDirectories = new List <ITaskItem> ();
            var resolvedAssetDirectories    = new List <ITaskItem> ();
            var resolvedEnvironmentFiles    = new List <ITaskItem> ();

            assemblyMap.Load(AssemblyIdentityMapFile);
            try {
                Extract(jars, resolvedResourceDirectories, resolvedAssetDirectories, resolvedEnvironmentFiles);
            } catch (ZipIOException ex) {
                Log.LogCodedError("XA1004", ex.Message);
                Log.LogDebugMessage(ex.ToString());
            }

            Jars = jars.Values.ToArray();
            ResolvedResourceDirectories = resolvedResourceDirectories.ToArray();
            ResolvedAssetDirectories    = resolvedAssetDirectories.ToArray();
            ResolvedEnvironmentFiles    = resolvedEnvironmentFiles.ToArray();

            ResolvedResourceDirectoryStamps = ResolvedResourceDirectories
                                              .Select(s => new TaskItem(Path.GetFullPath(Path.Combine(s.ItemSpec, "../..")) + ".stamp"))
                                              .ToArray();

            foreach (var directory in ResolvedResourceDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory.ItemSpec);
            }

            foreach (var directory in ResolvedAssetDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory.ItemSpec);
            }

            if (!string.IsNullOrEmpty(CacheFile))
            {
                var document = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("Paths",
                                 new XElement("Jars",
                                              Jars.Select(e => new XElement("Jar", e))),
                                 new XElement("ResolvedResourceDirectories",
                                              XDocumentExtensions.ToXElements(ResolvedResourceDirectories, "ResolvedResourceDirectory", knownMetadata)
                                              ),
                                 new XElement("ResolvedAssetDirectories",
                                              XDocumentExtensions.ToXElements(ResolvedAssetDirectories, "ResolvedAssetDirectory", knownMetadata)),
                                 new XElement("ResolvedEnvironmentFiles",
                                              XDocumentExtensions.ToXElements(ResolvedEnvironmentFiles, "ResolvedEnvironmentFile", knownMetadata)),
                                 new XElement("ResolvedResourceDirectoryStamps",
                                              XDocumentExtensions.ToXElements(ResolvedResourceDirectoryStamps, "ResolvedResourceDirectoryStamp", knownMetadata))
                                 ));
                document.SaveIfChanged(CacheFile);
            }

            assemblyMap.Save(AssemblyIdentityMapFile);

            Log.LogDebugTaskItems("  Jars: ", Jars);
            Log.LogDebugTaskItems("  ResolvedResourceDirectories: ", ResolvedResourceDirectories);
            Log.LogDebugTaskItems("  ResolvedAssetDirectories: ", ResolvedAssetDirectories);
            Log.LogDebugTaskItems("  ResolvedEnvironmentFiles: ", ResolvedEnvironmentFiles);
            Log.LogDebugTaskItems("  ResolvedResourceDirectoryStamps: ", ResolvedResourceDirectoryStamps);

            return(!Log.HasLoggedErrors);
        }
        // Extracts library project contents under e.g. obj/Debug/[__library_projects__/*.jar | res/*/*]
        // Extracts library project contents under e.g. obj/Debug/[lp/*.jar | res/*/*]
        public override bool Execute()
        {
            var jars = new Dictionary <string, ITaskItem> ();
            var resolvedResourceDirectories = new List <ITaskItem> ();
            var resolvedAssetDirectories    = new List <ITaskItem> ();
            var resolvedEnvironmentFiles    = new List <ITaskItem> ();

            assemblyMap.Load(AssemblyIdentityMapFile);
            assembliesToSkipCaseFixup  = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
            assembliestoSkipExtraction = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
            bool metaDataValue;

            foreach (var asm in Assemblies)
            {
                if (bool.TryParse(asm.GetMetadata(AndroidSkipResourceProcessing), out metaDataValue) && metaDataValue)
                {
                    assembliesToSkipCaseFixup.Add(asm.ItemSpec);
                }
                if (bool.TryParse(asm.GetMetadata(GetAdditionalResourcesFromAssemblies.AndroidSkipResourceExtraction), out metaDataValue) && metaDataValue)
                {
                    assembliestoSkipExtraction.Add(asm.ItemSpec);
                }
            }

            using (var resolver = new DirectoryAssemblyResolver(this.CreateTaskLogger(), loadDebugSymbols: false)) {
                try {
                    Extract(resolver, jars, resolvedResourceDirectories, resolvedAssetDirectories, resolvedEnvironmentFiles);
                } catch (ZipIOException ex) {
                    Log.LogCodedError("XA1004", ex.Message);
                    Log.LogDebugMessage(ex.ToString());
                }
            }

            Jars = jars.Values.ToArray();
            ResolvedResourceDirectories = resolvedResourceDirectories.ToArray();
            ResolvedAssetDirectories    = resolvedAssetDirectories.ToArray();
            ResolvedEnvironmentFiles    = resolvedEnvironmentFiles.ToArray();

            ResolvedResourceDirectoryStamps = ResolvedResourceDirectories
                                              .Select(s => new TaskItem(Path.GetFullPath(Path.Combine(s.ItemSpec, "../..")) + ".stamp"))
                                              .ToArray();

            foreach (var directory in ResolvedResourceDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory.ItemSpec);
            }

            foreach (var directory in ResolvedAssetDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory.ItemSpec);
            }

            if (!string.IsNullOrEmpty(CacheFile))
            {
                var document = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("Paths",
                                 new XElement("Jars",
                                              Jars.Select(e => new XElement("Jar", e))),
                                 new XElement("ResolvedResourceDirectories",
                                              XDocumentExtensions.ToXElements(ResolvedResourceDirectories, "ResolvedResourceDirectory", knownMetadata)
                                              ),
                                 new XElement("ResolvedAssetDirectories",
                                              XDocumentExtensions.ToXElements(ResolvedAssetDirectories, "ResolvedAssetDirectory", knownMetadata)),
                                 new XElement("ResolvedEnvironmentFiles",
                                              XDocumentExtensions.ToXElements(ResolvedEnvironmentFiles, "ResolvedEnvironmentFile", knownMetadata)),
                                 new XElement("ResolvedResourceDirectoryStamps",
                                              XDocumentExtensions.ToXElements(ResolvedResourceDirectoryStamps, "ResolvedResourceDirectoryStamp", knownMetadata))
                                 ));
                document.SaveIfChanged(CacheFile);
            }

            assemblyMap.Save(AssemblyIdentityMapFile);

            Log.LogDebugTaskItems("  Jars: ", Jars);
            Log.LogDebugTaskItems("  ResolvedResourceDirectories: ", ResolvedResourceDirectories);
            Log.LogDebugTaskItems("  ResolvedAssetDirectories: ", ResolvedAssetDirectories);
            Log.LogDebugTaskItems("  ResolvedEnvironmentFiles: ", ResolvedEnvironmentFiles);
            Log.LogDebugTaskItems("  ResolvedResourceDirectoryStamps: ", ResolvedResourceDirectoryStamps);

            return(!Log.HasLoggedErrors);
        }
        // Extracts library project contents under e.g. obj/Debug/[__library_projects__/*.jar | res/*/*]
        // Extracts library project contents under e.g. obj/Debug/[lp/*.jar | res/*/*]
        public override bool Execute()
        {
            var jars = new List <string> ();
            var resolvedResourceDirectories = new List <ITaskItem> ();
            var resolvedAssetDirectories    = new List <string> ();
            var resolvedEnvironmentFiles    = new List <string> ();

            assemblyMap.Load(AssemblyIdentityMapFile);
            assembliesToSkip = new HashSet <string> (AssembliesToSkipCases ?? new string [0], StringComparer.OrdinalIgnoreCase);

            using (var resolver = new DirectoryAssemblyResolver(this.CreateTaskLogger(), loadDebugSymbols: false)) {
                try {
                    Extract(resolver, jars, resolvedResourceDirectories, resolvedAssetDirectories, resolvedEnvironmentFiles);
                } catch (ZipIOException ex) {
                    Log.LogCodedError("XA1004", ex.Message);
                    Log.LogDebugMessage(ex.ToString());
                }
            }

            Jars = jars.ToArray();
            ResolvedResourceDirectories = resolvedResourceDirectories.ToArray();
            ResolvedAssetDirectories    = resolvedAssetDirectories.ToArray();
            ResolvedEnvironmentFiles    = resolvedEnvironmentFiles.ToArray();

            ResolvedResourceDirectoryStamps = ResolvedResourceDirectories
                                              .Select(s => new TaskItem(Path.GetFullPath(Path.Combine(s.ItemSpec, "../..")) + ".stamp"))
                                              .ToArray();

            foreach (var directory in ResolvedResourceDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory.ItemSpec);
            }

            foreach (var directory in ResolvedAssetDirectories)
            {
                MonoAndroidHelper.SetDirectoryWriteable(directory);
            }

            if (!string.IsNullOrEmpty(CacheFile))
            {
                var document = new XDocument(
                    new XDeclaration("1.0", "UTF-8", null),
                    new XElement("Paths",
                                 new XElement("Jars",
                                              Jars.Select(e => new XElement("Jar", e))),
                                 new XElement("ResolvedResourceDirectories",
                                              ResolvedResourceDirectories.Select(dir => {
                    var e = new XElement("ResolvedResourceDirectory", dir.ItemSpec);
                    foreach (var name in knownMetadata)
                    {
                        var value = dir.GetMetadata(name);
                        if (!string.IsNullOrEmpty(value))
                        {
                            e.SetAttributeValue(name, value);
                        }
                    }
                    return(e);
                })),
                                 new XElement("ResolvedAssetDirectories",
                                              ResolvedAssetDirectories.Select(e => new XElement("ResolvedAssetDirectory", e))),
                                 new XElement("ResolvedEnvironmentFiles",
                                              ResolvedEnvironmentFiles.Select(e => new XElement("ResolvedEnvironmentFile", e))),
                                 new XElement("ResolvedResourceDirectoryStamps",
                                              ResolvedResourceDirectoryStamps.Select(e => new XElement("ResolvedResourceDirectoryStamp", e)))
                                 ));
                document.SaveIfChanged(CacheFile);
            }

            assemblyMap.Save(AssemblyIdentityMapFile);

            Log.LogDebugTaskItems("  Jars: ", Jars);
            Log.LogDebugTaskItems("  ResolvedResourceDirectories: ", ResolvedResourceDirectories);
            Log.LogDebugTaskItems("  ResolvedAssetDirectories: ", ResolvedAssetDirectories);
            Log.LogDebugTaskItems("  ResolvedEnvironmentFiles: ", ResolvedEnvironmentFiles);
            Log.LogDebugTaskItems("  ResolvedResourceDirectoryStamps: ", ResolvedResourceDirectoryStamps);

            return(!Log.HasLoggedErrors);
        }