Exemple #1
0
        public CollectTargets(TaskLoggingHelper log)
        {
            Log = log;
            // Get the parent directory of the running program.  We assume that
            // this is the root of the FieldWorks repository tree.
            var fwrt = BuildUtils.GetAssemblyFolder();

            while (!Directory.Exists(Path.Combine(fwrt, "Build")) || !Directory.Exists(Path.Combine(fwrt, "Src")))
            {
                fwrt = Path.GetDirectoryName(fwrt);
                if (fwrt == null)
                {
                    Log.LogError("Error pulling the working folder from the running assembly.");
                    break;
                }
            }
            m_fwroot = fwrt;
        }
Exemple #2
0
        protected TeamCityQueryResult QueryTeamCity()
        {
            // Didn't find a matching dependency in FLExBridge; check for the most-specific version-tagged build, if any (e.g. fw-8.2.8~beta2~nightly)
            var availableTags = GetTagsFromBuildType();

            if (availableTags == null)
            {
                Log.LogError("Unable to retrieve dependencies for BuildType {0}. Check your connection and whether the BuildType exists", BuildType);
                return(TeamCityQueryResult.Failed);
            }
            if (availableTags.Any())
            {
                Dictionary <string, string> versionParts;
                if (!string.IsNullOrEmpty(VersionInfo) && BuildUtils.ParseSymbolFile(VersionInfo, Log, out versionParts))
                {
                    var tempTag = string.Format("fw-{0}.{1}.{2}~{3}",
                                                versionParts["FWMAJOR"], versionParts["FWMINOR"], versionParts["FWREVISION"], versionParts["FWBETAVERSION"]);
                    tempTag = tempTag.Replace(" ", "").ToLowerInvariant();                     // TC tags are spaceless and lowercase
                    var versionDelims = new[] { '.', '~' };
                    var idxDelim      = tempTag.LastIndexOfAny(versionDelims);
                    while (idxDelim > 0 && !availableTags.Contains(tempTag))
                    {
                        tempTag  = tempTag.Remove(idxDelim);
                        idxDelim = tempTag.LastIndexOfAny(versionDelims);
                    }
                    if (availableTags.Contains(tempTag))
                    {
                        Tag = tempTag + TagSuffix;
                        Log.LogMessage("Found matching tag for BuildType {0}: {1}", BuildType, Tag);
                        if (!string.IsNullOrEmpty(Query))
                        {
                            Log.LogWarning("Guessing Tags doesn't check queries. Guessed tag '{0}' for BuildType {1}, but it may not match {2}",
                                           Tag, BuildType, Query);
                        }
                        return(TeamCityQueryResult.Found);
                    }
                }
            }

            // REVIEW (Hasso) 2016.10: using .lastSuccessful should be a WARNING on package builds (may lead to bit rot)
            // If all else fails, use the default "tag" .lastSuccessful
            Tag = DefaultTag;
            return(TeamCityQueryResult.FellThrough);
        }
        private string LocalizeResx(string resxPath, string rootNamespace, string projectFolder)
        {
            string partialDir        = Path.GetDirectoryName(resxPath.Substring(ParentTask.SrcFolder.Length));
            string projectPartialDir = projectFolder.Substring(ParentTask.SrcFolder.Length);
            string outputFolder      = Path.Combine(ParentTask.OutputFolder, Locale) + partialDir;
            var    resxFileName      = Path.GetFileNameWithoutExtension(resxPath);
            // This is the relative path from the project folder to the resx file folder.
            // It needs to go into the file name if not empty, but with a dot instead of folder separator.
            string subFolder = "";

            if (partialDir.Length > projectPartialDir.Length)
            {
                subFolder = Path.GetFileName(partialDir) + ".";
            }
            string fileName = rootNamespace + "." + subFolder + resxFileName + "." + Locale + ".resx";

            Directory.CreateDirectory(outputFolder);
            var      stylesheet        = Path.Combine(ParentTask.RealBldFolder, "LocalizeResx.xsl");
            var      localizedResxPath = Path.Combine(outputFolder, fileName);
            DateTime dtStart           = DateTime.Now;
            var      parameters        = new List <BuildUtils.XsltParam>();

            parameters.Add(new BuildUtils.XsltParam()
            {
                Name = "lang", Value = Locale
            });
            // The output directory that the transform wants is not the one where it will write the file, but the base
            // Output directory, where it expects to find that we have written the XML version of the PO file, [locale].xml.
            parameters.Add(new BuildUtils.XsltParam()
            {
                Name = "outputdir", Value = ParentTask.OutputFolder
            });
            //parameters.Add(new XsltParam() { Name = "verbose", Value = "true" });
            BuildUtils.ApplyXslt(stylesheet, resxPath, localizedResxPath, parameters);
            m_xsltTime += DateTime.Now - dtStart;
            return(localizedResxPath);
        }
Exemple #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Do the generation
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override bool Execute()
        {
            Dictionary <string, string> substitutions;

            if (!BuildUtils.ParseSymbolFile(Symbols, Log, out substitutions))
            {
                return(false);
            }

            string template     = Template;
            bool   addedComment = false;

            try
            {
                StreamReader stream       = new StreamReader(template);
                string       fileContents = stream.ReadToEnd();
                stream.Close();

                Regex regex = new Regex("\\$YEAR");
                fileContents = regex.Replace(fileContents, DateTime.Now.Year.ToString());

                regex        = new Regex("\\$MONTH");
                fileContents = regex.Replace(fileContents, string.Format("{0:MM}", DateTime.Now));

                regex        = new Regex("\\$DAY");
                fileContents = regex.Replace(fileContents, string.Format("{0:dd}", DateTime.Now));

                regex = new Regex("\\$NUMBEROFDAYS");
                var numberOfDays = Convert.ToInt32(Math.Truncate(DateTime.Now.ToOADate())).ToString();
                fileContents = regex.Replace(fileContents, numberOfDays);

                // Jenkins builds should set the BUILD_NUMBER in the environment
                var buildNumber = Environment.GetEnvironmentVariable("BUILD_NUMBER");
                if (string.IsNullOrEmpty(buildNumber))
                {
                    // fall back to number of days if no BUILD_NUMBER is in the environment
                    buildNumber = numberOfDays;
                }
                regex        = new Regex("\\$BUILDNUMBER");
                fileContents = regex.Replace(fileContents, buildNumber);

                regex = new Regex("\\$GENERATEDFILECOMMENT");
                if (regex.IsMatch(fileContents))
                {
                    fileContents = regex.Replace(fileContents,
                                                 string.Format("This file is generated from {0}. Do NOT modify!",
                                                               Path.GetFileName(template)));
                    addedComment = true;
                }

                regex = new Regex("\\$!((?<env>\\w+)|\\{(?<env>\\w+):(?<default>\\w+)\\})");
                Match match = regex.Match(fileContents);
                while (match.Success)
                {
                    string strEnv     = match.Result("${env}");
                    string strDefault = match.Result("${default}");
                    string strEnvValue;
                    substitutions.TryGetValue(strEnv, out strEnvValue);
                    fileContents = regex.Replace(fileContents, string.IsNullOrEmpty(strEnvValue) ? strDefault : strEnvValue, 1, match.Index);

                    match = regex.Match(fileContents);
                }

                if (!addedComment)
                {
                    fileContents = string.Format("// This file is generated from {0}. Do NOT modify!\n{1}",
                                                 Path.GetFileName(template), fileContents);
                }

                // Don't write the output file if it hasn't changed from a previous run.
                if (File.Exists(Output))
                {
                    string oldFileContents = File.ReadAllText(Output);
                    if (fileContents == oldFileContents)
                    {
                        Log.LogMessage(MessageImportance.Low, "Skipping generating {0} from {1} because it hasn't changed.", Output, Path.GetFileName(template));
                        return(true);
                    }
                }
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    StreamWriter outStream = new StreamWriter(memoryStream);
                    outStream.Write(fileContents);

                    outStream.Close();

                    Log.LogMessage(MessageImportance.Low, "Generating {0} from {1}", Output,
                                   Path.GetFileName(template));

                    StreamWriter outFileStream = new StreamWriter(Output);
                    outFileStream.Write(fileContents);
                    outFileStream.Close();
                }
            }
            catch (Exception e)
            {
                Log.LogMessage(MessageImportance.High, "Generating {0} from {1} threw an exception {2}", Output,
                               template, e.Message);
                return(false);
            }
            return(true);
        }