示例#1
0
        private void GetReferences(Roles role, Regex r, string[] ignore = null, string[] allow = null, string defaultExt = null)
        {
            var input = !Role.HasFlag(Roles.Description) ? new ScnSyntax.Comment().Replace(Text, "") : Text;

            foreach (Match m in r.Matches(input))
            {
                if (ignore != null && ignore.Contains(m.Value))
                {
                    continue;
                }
                var path = ((role == Roles.Description ? BaseDirectory : SceneryDirectory) + "\\" + m.Value).Replace('/', '\\');
                var ext  = System.IO.Path.GetExtension(m.Value);
                if (defaultExt != null && ext == "")
                {
                    ext = defaultExt; path += ext;
                }
                if (System.IO.File.Exists(path))
                {
                    if (allow != null && !allow.Contains(ext))
                    {
                        continue;
                    }
                    if (!References.Any(p => p.Path == path))
                    {
                        var reference = new ProjectFile(path, role);
                        References.Add(reference);
                        reference.GetReferences();
                    }
                }
            }
        }
        /// <inheritdoc />
        public override bool Execute()
        {
            foreach (var r in Required)
            {
                if (Omitted.Any(x => x.ToString().Equals(r.ToString(), StringComparison.OrdinalIgnoreCase)))
                {
                    Log.LogMessage(MessageImportance.Low, $"Required reference '{r}' is set to omit.");
                    continue;
                }

                Log.LogMessage(MessageImportance.Low, $"Checking required reference: {r}");
                if (References.Any(x => x.ToString().Equals(r.ToString(), StringComparison.OrdinalIgnoreCase)))
                {
                    // found.
                    continue;
                }

                Log.LogWarning(
                    null,
                    "CCG0005",
                    string.Empty, // TODO: Can we get HelpLink like in roslyn analysers?
                    ProjectFile ?? string.Empty,
                    0,
                    0,
                    0,
                    0,
                    $"No reference to '{r}' found. Usage of '{r}' is strongly recommended");
            }

            return(true);
        }
示例#3
0
 private bool Has(TReference reference)
 {
     lock (References)
     {
         return(References.Any(r => r.Value == reference));
     }
 }
示例#4
0
 private void GuardForDuplicateReferenceMap(ReferenceMap <T> result)
 {
     if (References.Any(p => p.Name.Equals(result.Name)))
     {
         throw new ArgumentException($"Duplicate mapping for reference property {result.Name} detected.");
     }
 }
示例#5
0
 public void AddReference(ManyToOneMapping manyToOne)
 {
     if (References.Any(x => x.Name == manyToOne.Name))
     {
         throw new InvalidOperationException("Tried to add many-to-one '" + manyToOne.Name + "' when already added.");
     }
     AddMapping(manyToOne, MappingType.ManyToOne);
 }
        public virtual ProjectRootElement Construct()
        {
            // Workaround for https://github.com/dotnet/msbuild/issues/2554 when using Microsoft.Build.Construction.ProjectRootElement.Create
            var msbuildExePathVarName = "MSBUILD_EXE_PATH";

            if (!Builder.UseDotNet && !TestEnvironment.IsWindows)
            {
                Environment.SetEnvironmentVariable(msbuildExePathVarName, typeof(DotNetXamarinProject).Assembly.Location);
            }
            ProjectRootElement root = null;

            try {
                root = ProjectRootElement.Create();
            } finally {
                if (!Builder.UseDotNet && !TestEnvironment.IsWindows)
                {
                    Environment.SetEnvironmentVariable(msbuildExePathVarName, null);
                }
            }

            if (Packages.Any())
            {
                root.AddItemGroup().AddItem(BuildActions.None, "packages.config");
            }
            foreach (var pkg in Packages.Where(p => p.AutoAddReferences))
            {
                foreach (var reference in pkg.References)
                {
                    if (!References.Any(r => r.Include == reference.Include))
                    {
                        References.Add(reference);
                    }
                }
            }

            foreach (var pg in PropertyGroups)
            {
                pg.AddElement(root);
            }

            foreach (var ig in ItemGroupList)
            {
                var ige = root.AddItemGroup();
                foreach (var i in ig)
                {
                    if (i.Deleted)
                    {
                        continue;
                    }
                    ige.AddItem(i.BuildAction, i.Include(), i.Metadata);
                }
            }

            root.FullPath = ProjectName + Language.DefaultProjectExtension;

            return(root);
        }
示例#7
0
        private void TryResolveWildcardReferences()
        {
            // ensure xipton assemblies to be loaded in the execution context
            AppDomain.CurrentDomain
            .EnsureXiptonAssembliesLoaded();

            if (!References.Any(s => s.Contains("*.")))
            {
                // no need to resolve references
                return;
            }

            if (!_allowWildcardReferences)
            {
                throw new TemplateConfigurationException("AllowWildcardReferences == false -> References cannot be configured using wildcards. All references must be configured explicitely.");
            }

            // ensure all bin assemblies to be loaded in the execution context
            AppDomain.CurrentDomain.EnsureBinAssembliesLoaded();

            var domainAssemblies = AppDomain.CurrentDomain
                                   .GetAssemblies()
                                   .Where(a => !a.IsDynamic)
                                   .ToList();

            var referencedAssemblyFileNames = new List <string>();

            FindAssemblyFileNamesByPattern("*.dll", domainAssemblies, referencedAssemblyFileNames);
            FindAssemblyFileNamesByPattern("*.exe", domainAssemblies, referencedAssemblyFileNames);

            References =
                References
                .Where(referenceName =>
                       !referenceName.Contains("*") &&
                       !referencedAssemblyFileNames.Any(filename => filename
                                                        .TrimEnd()
                                                        .EndsWith(EnsureLeadingBackSlash(referenceName), StringComparison.OrdinalIgnoreCase)
                                                        )
                       )
                .Concat(
                    referencedAssemblyFileNames
                    )
                .ToList()
                .AsReadOnly();
        }
示例#8
0
        private IAmmyPlatform GetCompatiblePlatform()
        {
            if (References.Any(r => r.Path.EndsWith("Xamarin.Forms.Core.dll", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(new XamarinFormsPlatform());
            }

            if (References.Any(r => r.Path.EndsWith("Avalonia.Controls.dll", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(new AvaloniaPlatform());
            }

            if (References.Any(r => r.Path.EndsWith("System.Runtime.WindowsRuntime.dll", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(new UwpPlatform());
            }

            return(new WpfPlatform());
        }
示例#9
0
        public virtual ProjectRootElement Construct()
        {
            var root = ProjectRootElement.Create();

            if (Packages.Any())
            {
                root.AddItemGroup().AddItem(BuildActions.None, "packages.config");
            }
            foreach (var pkg in Packages.Where(p => p.AutoAddReferences))
            {
                foreach (var reference in pkg.References)
                {
                    if (!References.Any(r => r.Include == reference.Include))
                    {
                        References.Add(reference);
                    }
                }
            }

            foreach (var pg in PropertyGroups)
            {
                pg.AddElement(root);
            }

            foreach (var ig in ItemGroupList)
            {
                var ige = root.AddItemGroup();
                foreach (var i in ig)
                {
                    if (i.Deleted)
                    {
                        continue;
                    }
                    ige.AddItem(i.BuildAction, i.Include(), i.Metadata);
                }
            }

            root.FullPath = ProjectName + Language.DefaultProjectExtension;

            return(root);
        }
示例#10
0
        private void TryResolveWildcardReferences()
        {
            if (!References.Any(s => s.Contains("*.")))
            {
                // no need to resolve references
                return;
            }

            // ensure xipton assemblies as well as all bin assemblies to be loaded in the execution context
            AppDomain.CurrentDomain
            .EnsureXiptonAssembliesLoaded()
            .EnsureBinAssembliesLoaded();

            var domainAssemblies = AppDomain.CurrentDomain
                                   .GetAssemblies()
                                   .Where(a => !a.IsDynamic)
                                   .ToList();

            var referencedAssemblyFileNames = new List <string>();

            FindAssemblyFileNamesByPattern("*.dll", domainAssemblies, referencedAssemblyFileNames);
            FindAssemblyFileNamesByPattern("*.exe", domainAssemblies, referencedAssemblyFileNames);

            References =
                References
                .Where(referenceName =>
                       !referenceName.Contains("*") &&
                       !referencedAssemblyFileNames.Any(filename => filename
                                                        .TrimEnd()
                                                        .EndsWith(EnsureLeadingBackSlash(referenceName), StringComparison.OrdinalIgnoreCase)
                                                        )
                       )
                .Concat(
                    referencedAssemblyFileNames
                    )
                .ToList()
                .AsReadOnly();
        }
示例#11
0
        public Application AddFieldsFromTemplate(ApplicationTemplate template)
        {
            if (Degrees?.Any() != true)
            {
                Degrees = template.Degrees.Select(d => new ApplicationDegree
                {
                    Application = this,
                    Index       = d.Index,
                    Degree      = d.Name
                }).ToList();
            }

            if (Documents?.Any() != true)
            {
                Documents = template.Documents.Select(d => new ApplicationDocument
                {
                    Application = this,
                    Index       = d.Index,
                    Name        = d.Name,
                    Description = d.Description
                }).ToList();
            }

            if (References?.Any() != true)
            {
                References = new List <ApplicationReference>();
                for (int i = 0; i < template.NumberOfReferences; ++i)
                {
                    References.Add(new ApplicationReference
                    {
                        Application = this,
                        Index       = i
                    });
                }
            }

            return(this);
        }
        public override bool Execute()
        {
            // In Xamarin Studio, if the project name isn't a valid C# identifier
            // then $(RootNamespace) is not set, and the generated Activity is
            // placed into the "Application" namespace. VS just munges the project
            // name to be a valid C# identifier.
            // Use "Application" as the default namespace name to work with XS.
            Namespace = Namespace ?? "Application";

            Log.LogDebugMessage("GenerateResourceDesigner Task");
            Log.LogDebugMessage("  NetResgenOutputFile: {0}", NetResgenOutputFile);
            Log.LogDebugMessage("  JavaResgenInputFile: {0}", JavaResgenInputFile);
            Log.LogDebugMessage("  Namespace: {0}", Namespace);
            Log.LogDebugMessage("  ResourceDirectory: {0}", ResourceDirectory);
            Log.LogDebugTaskItemsAndLogical("  AdditionalResourceDirectories:", AdditionalResourceDirectories);
            Log.LogDebugMessage("  IsApplication: {0}", IsApplication);
            Log.LogDebugMessage("  UseManagedResourceGenerator: {0}", UseManagedResourceGenerator);
            Log.LogDebugTaskItemsAndLogical("  Resources:", Resources);
            Log.LogDebugTaskItemsAndLogical("  References:", References);

            if (!File.Exists(JavaResgenInputFile) && !UseManagedResourceGenerator)
            {
                return(true);
            }

            // ResourceDirectory may be a relative path, and
            // we need to compare it to absolute paths
            ResourceDirectory = Path.GetFullPath(ResourceDirectory);

            // Create our capitalization maps so we can support mixed case resources
            foreach (var item in Resources)
            {
                if (!item.ItemSpec.StartsWith(ResourceDirectory))
                {
                    continue;
                }

                var name         = item.ItemSpec.Substring(ResourceDirectory.Length);
                var logical_name = item.GetMetadata("LogicalName").Replace('\\', '/');

                AddRename(name.Replace('/', Path.DirectorySeparatorChar), logical_name.Replace('/', Path.DirectorySeparatorChar));
            }
            if (AdditionalResourceDirectories != null)
            {
                foreach (var additionalDir in AdditionalResourceDirectories)
                {
                    var file = Path.Combine(ProjectDir, Path.GetDirectoryName(additionalDir.ItemSpec), "__res_name_case_map.txt");
                    if (File.Exists(file))
                    {
                        foreach (var line in File.ReadAllLines(file).Where(l => !string.IsNullOrEmpty(l)))
                        {
                            string [] tok = line.Split(';');
                            AddRename(tok [1].Replace('/', Path.DirectorySeparatorChar), tok [0].Replace('/', Path.DirectorySeparatorChar));
                        }
                    }
                }
            }

            // Parse out the resources from the R.java file
            CodeTypeDeclaration resources;

            if (UseManagedResourceGenerator)
            {
                var parser = new ManagedResourceParser()
                {
                    Log = Log
                };
                resources = parser.Parse(ResourceDirectory, AdditionalResourceDirectories?.Select(x => x.ItemSpec), IsApplication, resource_fixup);
            }
            else
            {
                var parser = new JavaResourceParser()
                {
                    Log = Log
                };
                resources = parser.Parse(JavaResgenInputFile, IsApplication, resource_fixup);
            }

            var  extension = Path.GetExtension(NetResgenOutputFile);
            var  language  = string.Compare(extension, ".fs", StringComparison.OrdinalIgnoreCase) == 0 ? "F#" : CodeDomProvider.GetLanguageFromExtension(extension);
            bool isVB      = string.Equals(extension, ".vb", StringComparison.OrdinalIgnoreCase);
            bool isFSharp  = string.Equals(language, "F#", StringComparison.OrdinalIgnoreCase);
            bool isCSharp  = string.Equals(language, "C#", StringComparison.OrdinalIgnoreCase);

            // Let VB put this in the default namespace
            if (isVB)
            {
                Namespace = string.Empty;
            }

            // Create static resource overwrite methods for each Resource class in libraries.
            var assemblyNames = new List <string> ();

            if (IsApplication && References != null && References.Any())
            {
                // FIXME: should this be unified to some better code with ResolveLibraryProjectImports?
                using (var resolver = new DirectoryAssemblyResolver(this.CreateTaskLogger(), loadDebugSymbols: false)) {
                    foreach (var assemblyName in References)
                    {
                        var    suffix   = assemblyName.ItemSpec.EndsWith(".dll") ? String.Empty : ".dll";
                        string hintPath = assemblyName.GetMetadata("HintPath").Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
                        string fileName = assemblyName.ItemSpec + suffix;
                        string fullPath = Path.GetFullPath(assemblyName.ItemSpec);
                        // Skip non existing files in DesignTimeBuild
                        if (!File.Exists(fullPath) && DesignTimeBuild)
                        {
                            Log.LogDebugMessage("Skipping non existant dependancy '{0}' due to design time build.", fullPath);
                            continue;
                        }
                        resolver.Load(fullPath);
                        if (!String.IsNullOrEmpty(hintPath) && !File.Exists(hintPath))                           // ignore invalid HintPath
                        {
                            hintPath = null;
                        }
                        string assemblyPath = String.IsNullOrEmpty(hintPath) ? fileName : hintPath;
                        if (MonoAndroidHelper.IsFrameworkAssembly(fileName) && !MonoAndroidHelper.FrameworkEmbeddedJarLookupTargets.Contains(Path.GetFileName(fileName)))
                        {
                            continue;
                        }
                        Log.LogDebugMessage("Scan assembly {0} for resource generator", fileName);
                        assemblyNames.Add(assemblyPath);
                    }
                    var assemblies = assemblyNames.Select(assembly => resolver.GetAssembly(assembly));
                    new ResourceDesignerImportGenerator(Namespace, resources, Log)
                    .CreateImportMethods(assemblies);
                }
            }

            AdjustConstructor(isFSharp, resources);
            foreach (var member in resources.Members)
            {
                if (member is CodeTypeDeclaration)
                {
                    AdjustConstructor(isFSharp, (CodeTypeDeclaration)member);
                }
            }

            // Write out our Resources.Designer.cs file

            WriteFile(NetResgenOutputFile, resources, language, isFSharp, isCSharp);

            return(!Log.HasLoggedErrors);
        }
示例#13
0
 /// <summary>
 /// Constructs and return a <see cref="string" /> containing details of the current instance
 /// </summary>
 /// <returns>A <see cref="string" /> containing details of the current instance</returns>
 protected override string PrintF()
 {
     return(References == null || !References.Any()
         ? "no references"
         : References.Aggregate(string.Empty, (current, item) => current = $"{current}, {item.Key}={item.Value}").Substring(2));
 }
示例#14
0
        string CreateResponseFile()
        {
            var responseFile = Path.GetTempFileName();

            using var response = new StreamWriter(responseFile, append: false, encoding: Files.UTF8withoutBOM);
            Log.LogDebugMessage("[java-source-utils] response file contents: {0}", responseFile);

            if (BootClassPath != null && BootClassPath.Any())
            {
                var classpath = string.Join(Path.PathSeparator.ToString(), BootClassPath.Select(p => Path.GetFullPath(p.ItemSpec)));
                AppendArg(response, "--bootclasspath");
                AppendArg(response, classpath);
            }

            if (References != null && References.Any())
            {
                foreach (var r in References)
                {
                    if (Directory.Exists(r.ItemSpec))
                    {
                        AppendArg(response, "--source");
                        AppendArg(response, Path.GetFullPath(r.ItemSpec));
                        continue;
                    }
                    if (!File.Exists(r.ItemSpec))
                    {
                        Log.LogCodedError("XA1022", Properties.Resources.XA1022, r.ItemSpec);
                        continue;
                    }
                    if (r.ItemSpec.EndsWith(".jar", StringComparison.OrdinalIgnoreCase))
                    {
                        AppendArg(response, "--jar");
                        AppendArg(response, Path.GetFullPath(r.ItemSpec));
                        continue;
                    }
                    if (r.ItemSpec.EndsWith(".aar", StringComparison.OrdinalIgnoreCase))
                    {
                        AppendArg(response, "--aar");
                        AppendArg(response, Path.GetFullPath(r.ItemSpec));
                        continue;
                    }
                    Log.LogError($"Unsupported @(Reference) item: {r.ItemSpec}");
                }
            }
            AppendArg(response, "--output-javadoc");
            AppendArg(response, OutputJavadocXml.ItemSpec);

            if (!string.IsNullOrEmpty(JavadocCopyrightFile?.ItemSpec))
            {
                AppendArg(response, "--doc-copyright");
                AppendArg(response, Path.GetFullPath(JavadocCopyrightFile.ItemSpec));
            }
            if (!string.IsNullOrEmpty(JavadocUrlPrefix))
            {
                AppendArg(response, "--doc-url-prefix");
                AppendArg(response, Path.GetFullPath(JavadocUrlPrefix));
            }
            if (!string.IsNullOrEmpty(JavadocUrlStyle))
            {
                AppendArg(response, "--doc-link-style");
                AppendArg(response, Path.GetFullPath(JavadocUrlStyle));
            }

            foreach (var path in InputFiles)
            {
                AppendArg(response, Path.GetFullPath(path.ItemSpec));
            }

            return(responseFile);

            void AppendArg(TextWriter writer, string line)
            {
                writer.WriteLine(line);
                Log.LogDebugMessage(line);
            }
        }