Example #1
0
        /// <summary>
        /// Checks whether all origins for this file are available
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        internal bool CanPackage(TBLogFile file)
        {
            foreach (TBLogItem item in file.AllPublishItems)
            {
                if (!item.IsShared)
                {
                    continue;
                }

                FileData fd;

                if (!Files.TryGetValue(item.FullSrc, out fd))
                {
                    return(false);
                }

                if (fd.Origin == null)
                {
                    return(false);
                }

                BuildOrigin bo = fd.Origin as BuildOrigin;

                if (bo != null && bo.Pack == null)
                {
                    return(false); // Package this one first!
                }
            }

            return(true);
        }
Example #2
0
        public void BuildExternal()
        {
            ProcessStartInfo psi = new ProcessStartInfo(MSBuild, string.Format("/nologo \"{0}\" /v:q /p:Configuration={1} \"/logger:MSBuildLogger,{2};OutputDir={3};Indent=true\"", Solution, OtherConfiguration, Logger, LoggerPath));

            psi.UseShellExecute        = false;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;
            psi.CreateNoWindow         = true;

            using (Process p = Process.Start(psi))
            {
                p.WaitForExit();
                string output = p.StandardOutput.ReadToEnd();
                string err    = p.StandardError.ReadToEnd();

                Assert.That(err, Is.EqualTo(""), "MSBuild gave no error");
                //Assert.That(output, Is.EqualTo(""), "MSBuild gave no output");
                Assert.That(p.ExitCode, Is.EqualTo(0), "MSBuild ran successfully");
            }

            Assert.That(File.Exists(QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog")), Is.True, "Logfile created");

            XPathDocument doc = new XPathDocument(QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog"));

            XPathNavigator      nav   = doc.CreateNavigator();
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable);

            nsMgr.AddNamespace("tb", "http://schemas.qqn.nl/2007/TurtleBuild/BuildResult");
            Assert.That(nav.SelectSingleNode("/tb:TurtleBuildData/tb:Configuration", nsMgr).GetAttribute("outputPath", ""), Is.Not.EqualTo(""), "outputPath is set");
            //doc.CreateNavigator().SelectSingleNode("

            TBLogFile file = TBLogFile.Load(QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog"));

            Assert.That(file, Is.Not.Null);
            Assert.That(file.Configurations.Count, Is.GreaterThanOrEqualTo(1), "Configurations available");

            Assert.That(file.Configurations[0].ProjectOutput.Items.Count, Is.GreaterThan(1));

            Assert.That(file.Configurations[0].ProjectOutput.Items[0].Container, Is.SameAs(file.Configurations[0].ProjectOutput), "Container is set");

            Assert.That(file.Configurations[0].Target.DebugSrc, Is.Not.Null);


            using (StringWriter sw = new StringWriter())
            {
                using (XmlWriter xw = new XmlTextWriter(sw))
                {
                    xw.WriteStartDocument();
                    xw.WriteStartElement("TurtleBuild", "q:q");
                    QQn.TurtleUtils.Tokens.Tokenizer.TryWriteXml(new XmlTextWriter(sw), file);

                    xw.WriteEndDocument();
                }

                string text = sw.ToString();
                Assert.That(text.Length, Is.GreaterThan(100));
            }
        }
Example #3
0
        public BuildOrigin(TBLogFile logFile)
        {
            if (logFile == null)
            {
                throw new ArgumentNullException("logFile");
            }

            _log         = logFile;
            _projectFile = QQnPath.Combine(logFile.ProjectPath, logFile.Project.File);
        }
Example #4
0
        /// <summary>
        /// Tries to create packages from the specified logfiles; walking dependencies if needed.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <param name="newPackages">The new packages.</param>
        /// <returns></returns>
        public static bool TryCreatePackages(PackageArgs args, out PackageList newPackages)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            PackageState state = new PackageState(args);

            state.LoadExternalOrigins();
            state.CreateBuildOrigins();
            state.AddRequirements();

            state.CalculateDependencies();

            newPackages = new PackageList();

            List <TBLogFile> filesToRun = new List <TBLogFile>(state.Logs);

            while (filesToRun.Count > 0)
            {
                int n = 0;
                for (int i = 0; i < filesToRun.Count; i++)
                {
                    TBLogFile file = filesToRun[i];
                    if (state.CanPackage(file))
                    {
                        filesToRun.RemoveAt(i--);

                        string   target     = QQnPath.Combine(args.OutputDir, file.Project.Name + ".tpZip");
                        FileInfo targetInfo = new FileInfo(target);

                        TPack pack;
                        if (targetInfo.Exists && targetInfo.LastWriteTime > file.GetLastWriteTime())
                        {
                            pack = TPack.OpenFrom(target, VerificationMode.None);
                            state.SetOriginPack(file, pack.Pack);
                        }
                        else
                        {
                            pack = TPack.Create(target, state.CreateDefinition(file));
                        }
                        newPackages.Add(target, pack);
                        n++;
                    }
                }

                if (n == 0)
                {
                    break; // Can't package anything
                }
            }

            return(true);
        }
Example #5
0
 internal void SetOriginPack(TBLogFile file, Pack pack)
 {
     foreach (BuildOrigin origin in BuildOrigins)
     {
         if (origin.LogFile == file)
         {
             origin.Pack = pack;
             return;
         }
     }
 }
Example #6
0
        public void MakePackage()
        {
            string logFile = QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog");

            if (!File.Exists(logFile))
            {
                BuildInternal();
            }

            TBLogFile log = TBLogFile.Load(logFile);

            Assert.That(!string.IsNullOrEmpty(log.Project.Name));

            DebugReference reference = null;

            foreach (TBLogItem item in log.Configurations[0].ProjectOutput.Items)
            {
                if (!item.IsShared && !item.IsCopy)
                {
                    switch (Path.GetExtension(item.Src).ToUpperInvariant())
                    {
                    case ".PDB":
                    case ".DLL":
                        if (reference == null)
                        {
                            reference = AssemblyUtils.GetDebugReference(item.FullSrc);

                            Assert.That(reference, Is.Not.Null);
                            Assert.That(reference.PdbFile, Is.Not.Null);
                        }
                        else
                        {
                            DebugReference dr = AssemblyUtils.GetDebugReference(item.FullSrc);

                            Assert.That(dr, Is.Not.Null);
                            // Path does not have to equal; the pdb information contains the sourcepath (obj directory for c# code)
                            Assert.That(Path.GetFileName(dr.PdbFile), Is.EqualTo(Path.GetFileName(reference.PdbFile)));
                            Assert.That(dr.DebugId, Is.EqualTo(reference.DebugId));
                        }
                        break;
                    }
                }
            }

            Pack pack = null;

            Assert.That(PackUtils.TryCreatePack(log, out pack));

            string path = QQnPath.Combine(PackagePath, "QQn.TurtleMSBuild.tpZip");
            TPack  tp   = TPack.Create(path, pack);

            using (TPack pkg = TPack.OpenFrom(path, VerificationMode.Full))
                using (DirectoryMap dm = DirectoryMap.Get(ExtractPath))
                {
                    Assert.That(pkg, Is.Not.Null);

                    pkg.ExtractTo(dm);
                }

            using (TPack pkg = TPack.OpenFrom(path, VerificationMode.Full))
            {
                Assert.That(pkg, Is.Not.Null);

                pkg.ExtractTo(ExtractPath);
            }
        }
Example #7
0
        public Pack CreateDefinition(TBLogFile file)
        {
            BuildOrigin myOrigin = null;

            foreach (BuildOrigin bo in BuildOrigins)
            {
                if (bo.LogFile == file)
                {
                    myOrigin = bo;
                    break;
                }
            }

            Pack p = new Pack();

            TBLogConfiguration config = file.Configurations[0];
            TBLogTarget        target = config.Target;
            TBLogAssembly      asm    = config.Assembly;

            if (!string.IsNullOrEmpty(target.KeySrc))
            {
                p.StrongNameKey = StrongNameKey.LoadFrom(QQnPath.Combine(file.ProjectPath, target.KeySrc));
            }
            else if (!string.IsNullOrEmpty(target.KeyContainer))
            {
                p.StrongNameKey = StrongNameKey.LoadFromContainer(target.KeyContainer, false);
            }

            if (asm != null && !string.IsNullOrEmpty(asm.AssemblyName))
            {
                AssemblyName name = new AssemblyName(asm.AssemblyName);
                p.Version = name.Version;
            }

            PackContainer po = p.Containers.AddItem("#ProjectOutput");

            po.ContainerDir = config.OutputPath;
            po.BaseDir      = QQnPath.Combine(file.ProjectPath);
            foreach (TBLogItem item in file.AllProjectOutput)
            {
                if (item.IsShared)
                {
                    continue;
                }

                PackFile pf = po.Files.AddItem(QQnPath.EnsureRelativePath(po.BaseDir, item.FullSrc));
                pf.StreamName = item.Src;
            }

            PackContainer ct = p.Containers.AddItem("#Content");

            ct.ContainerDir = "";
            po.BaseDir      = file.ProjectPath;

            foreach (TBLogItem item in file.AllContents)
            {
                if (item.IsShared)
                {
                    continue;
                }

                PackFile pf = po.Files.AddItem(QQnPath.EnsureRelativePath(po.BaseDir, item.FullSrc));
            }

            myOrigin.Pack = p;

            return(p);
        }
Example #8
0
        /// <summary>
        /// Tries to create a pack.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="pack">The pack.</param>
        /// <returns></returns>
        public static bool TryCreatePack(TBLogFile project, out Pack pack)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            TBLogFile log = project;

            string projectDir = project.Project.Path;

            Pack p = new Pack();

            p.BaseDir = projectDir;

            PackContainer projectOutput = p.Containers.AddItem("#ProjectOutput");

            TBLogConfiguration config = log.Configurations[0];


            if (!string.IsNullOrEmpty(config.OutputPath))
            {
                projectOutput.ContainerDir = config.OutputPath;
                projectOutput.BaseDir      = config.OutputPath;
            }

            foreach (TBLogItem item in config.ProjectOutput.Items)
            {
                if (item.IsShared)
                {
                    continue;
                }

                PackFile pf = projectOutput.Files.AddItem(QQnPath.MakeRelativePath(projectOutput.BaseDir, QQnPath.Combine(projectDir, item.Src)));

                pf.StreamName = item.Src;
            }

            PackContainer projectContent = p.Containers.AddItem("#ProjectContent");

            if (!string.IsNullOrEmpty(config.OutputPath))
            {
                projectContent.ContainerDir = "content/" + log.Project.Name;
                projectContent.BaseDir      = log.ProjectPath;
            }

            foreach (TBLogItem item in config.Content.Items)
            {
                PackFile pf = projectContent.Files.AddItem(QQnPath.MakeRelativePath(projectContent.BaseDir, QQnPath.Combine(projectDir, item.Src)));

                pf.StreamName = item.Src;
            }

            PackContainer projectScripts = p.Containers.AddItem("#ProjectScripts");

            if (!string.IsNullOrEmpty(config.OutputPath))
            {
                projectScripts.ContainerDir = "scripts/" + log.Project.Name;
                projectScripts.BaseDir      = log.Project.Path;
            }

            foreach (TBLogItem item in config.Content.Items)
            {
                PackFile pf = projectContent.Files.AddItem(QQnPath.MakeRelativePath(projectContent.BaseDir, QQnPath.Combine(projectDir, item.Src)));

                pf.StreamName = item.Src;
            }

            if (config.Target.KeySrc != null)
            {
                p.StrongNameKey = StrongNameKey.LoadFrom(QQnPath.Combine(log.Project.Path, config.Target.KeySrc));
            }
            else if (config.Target.KeyContainer != null)
            {
                p.StrongNameKey = StrongNameKey.LoadFromContainer(config.Target.KeyContainer, false);
            }


            foreach (PackContainer pc in p.Containers)
            {
                foreach (PackFile pf in pc.Files)
                {
                    VerifyUtils.UpdateFile(pf.BaseDir, pf);
                }
            }

            pack = p;

            return(true);
        }