Пример #1
0
        public override bool Execute()
        {
            if (!InitializeAddinRegistry())
            {
                return(false);
            }

            string[] result;
            try {
                var service = new SetupService(Registry);
                result = service.BuildPackage(
                    new LogProgressStatus(Log, 0),
                    OutputDir,
                    AddinFile
                    );
            } catch (Exception ex) {
                Log.LogError("Internal error: {0}", ex);
                return(false);
            }

            if (Log.HasLoggedErrors)
            {
                return(false);
            }

            if (result.Length != 1)
            {
                Log.LogError("Unexpected number of packaging results: {0}", result.Length);
                return(false);
            }

            PackageFile = result [0];

            Log.LogMessage(MessageImportance.Normal, "Created package: {0}", PackageFile);

            return(true);
        }
Пример #2
0
        public void AddinPackageCreation()
        {
            repoBuilt = false;
            if (Directory.Exists(repoDir))
            {
                Directory.Delete(repoDir, true);
            }
            Directory.CreateDirectory(repoDir);
            Directory.CreateDirectory(repoExtrasDir);

            string asm = Path.Combine(baseDir, "SimpleApp.addin.xml");

            string[] p = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));

            asm = Path.Combine(addinsDir, "HelloWorldExtension.dll");
            p   = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));

            asm = Path.Combine(addinsDir, "CommandExtension.addin.xml");
            p   = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));

            asm = Path.Combine(addinsDir, "SystemInfoExtension.addin.xml");
            p   = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));

            asm = Path.Combine(addinsDir, "MultiAssemblyAddin.dll");
            p   = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));

            string extras = Path.Combine(addinsDir, "extras");

            asm = Path.Combine(extras, "ExtraExtender.addin.xml");
            p   = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));

            asm = Path.Combine(extras, "FileContentExtension.addin.xml");
            p   = setup.BuildPackage(monitor, repoDir, asm);
            Assert.IsTrue(File.Exists(p[0]));
        }
Пример #3
0
        AddinData BuildProjectAddin(BuildContext ctx, SourceTagInfo stag, string logFile, string sourcePath, AppReleaseInfo rel, AddinProjectAddin addin)
        {
            SetupService     ss = new SetupService();
            bool             generatedXplatPackage = false;
            HashSet <string> foundPlatforms        = new HashSet <string> ();
            AddinData        ainfo = new AddinData();

            foreach (AddinProjectSource psource in addin.Sources)
            {
                if (string.IsNullOrEmpty(psource.AddinFile))
                {
                    throw new Exception("AddinFile element not found in addin-project.xml");
                }

                string platforms = psource.Platforms;
                if (string.IsNullOrEmpty(platforms))
                {
                    platforms = ctx.Application.Platforms;
                }

                string[] platformList = platforms.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string plat in platformList)
                {
                    if (!foundPlatforms.Add(plat))
                    {
                        throw new Exception("Platform " + plat + " specificed in more than open Project element");
                    }
                }

                string outFile = NormalizePath(psource.AddinFile);

                if (!string.IsNullOrEmpty(psource.BuildFile))
                {
                    // Build the project

                    // Move the sources to the work area (which is sandboxed)

                    if (!Directory.Exists(ctx.LocalSettings.WorkAreaPath))
                    {
                        Directory.CreateDirectory(ctx.LocalSettings.WorkAreaPath);
                    }

                    string workArea = Path.Combine(ctx.LocalSettings.WorkAreaPath, "builder");
                    if (Directory.Exists(workArea))
                    {
                        Directory.Delete(workArea, true);
                    }

                    Directory.Move(sourcePath, workArea);

                    StringBuilder output = new StringBuilder();

                    try {
                        string solFile = Path.Combine(workArea, NormalizePath(psource.BuildFile));

                        // Restore packages
                        RunCommand(true, "nuget", "restore \"" + solFile + "\"", output, output, Timeout.Infinite);

                        string refPath = rel.GetAssembliesPath(ctx);

                        if (ContaintsMdTargetsFile(workArea) && !string.IsNullOrEmpty(ctx.LocalSettings.LocalAppInstallPath))
                        {
                            foreach (var p in ctx.LocalSettings.LocalAppInstallPath.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                var ip = Path.Combine(refPath, "__install", p);
                                if (Directory.Exists(ip))
                                {
                                    refPath = ip;
                                    break;
                                }
                            }
                        }

                        string ops = " \"/p:ReferencePath=" + refPath + "\"";

                        if (!string.IsNullOrEmpty(psource.BuildConfiguration))
                        {
                            ops += " \"/property:Configuration=" + psource.BuildConfiguration + "\"";
                        }

                        ops = ops + " \"" + solFile + "\"";

                        // Clean the project
                        RunCommand(true, ctx.LocalSettings.MSBuildCommand, "/t:Clean " + ops, output, output, Timeout.Infinite);

                        // Build
                        RunCommand(true, ctx.LocalSettings.MSBuildCommand, ops, output, output, Timeout.Infinite);
                    }
                    finally {
                        output = output.Replace(workArea, "/build");
                        File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(output.ToString()) + "</pre>");
                        Directory.Move(workArea, sourcePath);
                    }
                }

                // Generate the package

                string tmpPath = Path.Combine(sourcePath, "tmp");

                File.AppendAllText(logFile, "<p><b>Building Package</b></p>");
                LocalStatusMonitor monitor = new LocalStatusMonitor();
                try {
                    if (Directory.Exists(tmpPath))
                    {
                        Directory.Delete(tmpPath, true);
                    }
                    Directory.CreateDirectory(tmpPath);
                    ss.BuildPackage(monitor, tmpPath, Path.Combine(sourcePath, outFile));
                    string file = Directory.GetFiles(tmpPath, "*.mpack").FirstOrDefault();
                    if (file == null)
                    {
                        throw new Exception("Add-in generation failed");
                    }

                    AddinInfo ai = ReadAddinInfo(file);
                    ainfo.AddinVersion = ai.Version;
                    ainfo.AddinId      = Mono.Addins.Addin.GetIdName(ai.Id);

                    if (!generatedXplatPackage && platformList.Length > 0)
                    {
                        File.Copy(file, Path.Combine(stag.GetPackagePath(ctx), "All.mpack"), true);
                        generatedXplatPackage = true;
                    }
                    else
                    {
                        foreach (string plat in platformList)
                        {
                            File.Copy(file, Path.Combine(stag.GetPackagePath(ctx), plat + ".mpack"), true);
                        }
                    }
                }
                finally {
                    try {
                        Directory.Delete(tmpPath, true);
                    }
                    catch { }
                    File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(monitor.ToString()) + "</pre>");
                }
            }
            ainfo.Platforms  = string.Join(" ", foundPlatforms.ToArray());
            ainfo.AppVersion = rel.AppVersion;
            return(ainfo);
        }