Example #1
0
        public override bool Execute()
        {
            if (_src == null)
            {
                throw new Exception("license-files: missing 'src'");
            }

            if (_toDir == null)
            {
                throw new Exception("license-files: missing 'toDir'");
            }

            if (_xslFile == null)
            {
                //Look in the same folder as the dll file.
                Uri codeBasePath = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), UriKind.Absolute);
                String path = codeBasePath.AbsolutePath;
                String xslFilePath = path + @"\manifest.xsl";
                FileInfo xslFile = new FileInfo(xslFilePath);
                _xslFile = xslFile.FullName;
            }

            foreach (ITaskItem excludedProduct in ExcludedProducts)
            {
                External ex = new External();
                ex.Src = excludedProduct.GetMetadata("src");
                ex.Name = excludedProduct.GetMetadata("name");
                Boolean include;
                Boolean.TryParse(excludedProduct.GetMetadata("include"), out include);
                ex.Include = include;
                ex.ParentProduct = excludedProduct.GetMetadata("parentproduct");
                ex.License = excludedProduct.GetMetadata("license");
                ex.Version = excludedProduct.GetMetadata("version");
                _externals.AddConfiguredExternal(ex);
            }
            Log.LogMessage(MessageImportance.Normal, "license-files: collecting license files in " + _src, null);

            DirectoryInfo src = new DirectoryInfo(_src);
            DirectoryInfo toDir = new DirectoryInfo(_toDir);
            if (!toDir.Exists)
                toDir.Create();

            LicenseFilesManifest manifest = new LicenseFilesManifest();

            SortedList<String, String> externals = getExternalsVersions(src);
            SortedList<String, List<LicenseFound>> licenses = new SortedList<String, List<LicenseFound>>();
            foreach (String external in externals.Keys)
            {
                if (!isIncluded(external))
                {
                    Log.LogMessage(MessageImportance.Normal, "skipping license file in '" + external + "'", null);
                    continue;
                }
                String version;
                externals.TryGetValue(external, out version);
                List<LicenseFound> licensesCollected = collect(external, external,
                    external, version, new DirectoryInfo(src + @"\" + external), 1);
                if (licensesCollected != null)
                {
                    licenses.Add(external, licensesCollected);
                    foreach (LicenseFound licenseFound in licensesCollected)
                    {
                        manifest.Add(getLicenseInfo(external, licenseFound));
                    }
                }
            }

            foreach (String external in externals.Keys)
            {
                if (!licenses.ContainsKey(external) && isIncluded(external))
                {
                    String version;
                    externals.TryGetValue(external, out version);
                    Log.LogMessage(MessageImportance.Normal, "missing license file in '" + external + " (" + version + ")'", null);
                    manifest.Add(getLicenseInfo(external, new LicenseInfo(external, version)));
                }
            }

            foreach (List<LicenseFound> licensesFound in licenses.Values)
            {
                foreach (LicenseFound licenseFound in licensesFound)
                {
                    String licenseFilename = licenseFound.LicenseFilename;
                    FileInfo destinationFile = new FileInfo(toDir.FullName + @"\" + getLicenseFilename(licenseFilename));
                    File.Copy(licenseFound.File, destinationFile.FullName, true);
                }
            }

            FileInfo manifestFile = new FileInfo(toDir + @"\manifest.xml");
            Log.LogMessage(MessageImportance.Normal, "writing " + manifestFile.FullName, null);
            manifest.WriteTo(manifestFile, _xslFile);
            Log.LogMessage(MessageImportance.Normal, manifest.ToString(), null);

            return true;
        }
Example #2
0
        public override bool Execute()
        {
            try
              {
            if (_toDir == null)
            {
              throw new Exception("license-manifests: missing 'toDir'");
            }

            if (_xslFile == null)
            {
              //Look in the same folder as the dll file.
              Uri codeBasePath = new Uri(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), UriKind.Absolute);
              String path = codeBasePath.AbsolutePath;
              String xslFilePath = path + @"\manifest.xsl";
              FileInfo xslFile = new FileInfo(xslFilePath);
              _xslFile = xslFile.FullName;
            }

            Log.LogMessage(MessageImportance.Normal, "license-manifests: collecting manifests to " + _toDir, null);

            Directory.CreateDirectory(_toDir);

            LicenseFilesManifest combinedManifest = new LicenseFilesManifest();
            foreach (ITaskItem item in _manifests)
            {
              int count = 0;
              LicenseFilesManifest manifest = new LicenseFilesManifest();
              manifest.SetSrcDir(item.GetMetadata("Fullpath"));
              foreach (LicenseInfo licenseInfo in manifest.GetLicenses())
              {
            combinedManifest.Add(licenseInfo);
            count++;
              }
              foreach (FileInfo licenseFile in manifest.SrcDir.GetFiles())
              {
            if (!licenseFile.Name.Equals("manifest.xml"))
            {
              String targetLicenseFile = Path.Combine(_toDir, licenseFile.Name);
              File.Copy(licenseFile.FullName, targetLicenseFile, true);
            }
              }
              Log.LogMessage(MessageImportance.Normal, "merged " + count + " license(s) from " + manifest.SrcDir.FullName);
            }

            String manifestXsl = null;
            if (_xslFile != null)
            {
              manifestXsl = Path.Combine(_toDir, "manifest.xsl");
              Log.LogMessage(MessageImportance.Normal, "copying " + _xslFile + " to " + _toDir);
              File.Copy(_xslFile, manifestXsl, true);
            }

            FileInfo manifestFile = new FileInfo(Path.Combine(_toDir, "manifest.xml"));
            Log.LogMessage(MessageImportance.Normal, "writing " + manifestFile);
            combinedManifest.WriteTo(manifestFile, manifestXsl != null ? manifestXsl : null);

            return true;
              }
              catch (Exception e)
              {
            Log.LogMessage(MessageImportance.High, "error: " + e.Message);
            Console.WriteLine(e.StackTrace);
            throw;
              }
        }