Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(144)

Unified Diff: Tools/Google.Build.Utils/Build/Project.cs

Issue 12767046: Issue 377: New build for releasing a new version (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: david comments Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Tools/Google.Build.Tester/app.config ('k') | Tools/Google.Build.Utils/DirUtils.cs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/Google.Build.Utils/Build/Project.cs
===================================================================
deleted file mode 100644
--- a/Tools/Google.Build.Utils/Build/Project.cs
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
-Copyright 2011 Google Inc
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using Google.Apis.Samples.Helper;
-using Microsoft.Build.Evaluation;
-using Microsoft.Build.Framework;
-using ConsoleLogger = Microsoft.Build.BuildEngine.ConsoleLogger;
-
-namespace Google.Build.Utils.Build
-{
- /// <summary>
- /// Represents a buildable project.
- /// </summary>
- public class Project
- {
- /// <summary>
- /// The working directory in which the project file resides.
- /// </summary>
- public string WorkingDirectory { get; private set; }
-
- /// <summary>
- /// The .csproj project file.
- /// </summary>
- public string ProjectFile { get; private set; }
-
- /// <summary>
- /// The Configuration to build. Default: "Release"
- /// </summary>
- public string Configuration
- {
- get { return internalProject.GetProperty("Configuration").EvaluatedValue; }
- set { internalProject.SetProperty("Configuration", value); }
- }
-
- /// <summary>
- /// Path to the generated binary file.
- /// </summary>
- public string BinaryFile
- {
- get { return internalProject.GetPropertyValue("TargetPath"); }
- }
-
- /// <summary>
- /// The simple name of this project.
- /// </summary>
- public string Name
- {
- get { return internalProject.GetPropertyValue("ProjectName"); }
- }
-
- /// <summary>
- /// Returns the paths to all generated output files.
- /// </summary>
- public string[] OutputFiles
- {
- get
- {
- string[] extensions = new[] { ".pdb", ".xml" };
- string binary = BinaryFile;
-
- // Generate the list of output files.
- var result = new List<string>();
- result.Add(BinaryFile);
- result.AddRange(extensions.Select(ext => Path.ChangeExtension(binary, ext)).Where(File.Exists));
- return result.ToArray();
- }
- }
-
- private readonly Microsoft.Build.Evaluation.Project internalProject;
-
- public Project(string projectFile)
- {
- if (!File.Exists(projectFile))
- {
- throw new FileNotFoundException("The specified project file cannot be found.", projectFile);
- }
- ProjectFile = projectFile;
- WorkingDirectory = Path.GetDirectoryName(projectFile);
- internalProject = (from p in ProjectCollection.GlobalProjectCollection.LoadedProjects
- where p.FullPath == Path.GetFullPath(projectFile)
- select p).SingleOrDefault() ?? new Microsoft.Build.Evaluation.Project(ProjectFile);
- Configuration = "Release";
- }
-
- private void Build(string target)
- {
- if (!internalProject.Build(target))
- {
- // If the build fails, re-run this build with a logger attached.
- internalProject.Build(target, new[] { new ConsoleLogger(LoggerVerbosity.Quiet) });
- Process.Start(WorkingDirectory);
- throw new ApplicationException("Build of project [" + this + ":" + target + "] failed!");
- }
- }
-
- /// <summary>
- /// Cleans the project.
- /// </summary>
- public void Clean()
- {
- Log("Cleaning ...");
- Build("Clean");
- }
-
- /// <summary>
- /// Compiles the project.
- /// </summary>
- public void Compile()
- {
- Log("Compiling ...");
- Build("Build");
-
- if (!File.Exists(BinaryFile))
- {
- throw new ApplicationException(
- "Build was successful, but target binary file does not exist: " + BinaryFile);
- }
- }
-
- /// <summary>
- /// Copies the resulting binaries to the specified directory.
- /// </summary>
- public void CopyTo(string dir)
- {
- Log("Copying output to " + Path.GetFileName(dir) + " ...");
-
- if (!Directory.Exists(dir))
- {
- Directory.CreateDirectory(dir);
- }
-
- // Copy all output files into the target directory
- foreach (string file in OutputFiles)
- {
- string fileName = Path.GetFileName(file);
- Log(" * " + fileName);
- File.Copy(file, Path.Combine(dir, fileName), true);
- }
- }
-
- /// <summary>
- /// Copies the resulting binaries and dependencies to the specified directory.
- /// </summary>
- public void CopyAllFilesTo(string dir)
- {
- Log("Copying output to " + Path.GetFileName(dir) + " ...");
-
- if (!Directory.Exists(dir))
- {
- Directory.CreateDirectory(dir);
- }
-
- // Copy all output files into the target directory
- string buildDir = Path.GetDirectoryName(BinaryFile);
- foreach (string file in Directory.GetFiles(buildDir, "*.*", SearchOption.TopDirectoryOnly))
- {
- switch (Path.GetExtension(file).ToLower())
- {
- case ".dll":
- case ".exe":
- case ".pdb":
- case ".xml":
- break; // Copy all assemblies and relevant information into the target directory.
-
- default:
- continue; // Unsupported.
- }
-
- string fileName = Path.GetFileName(file);
- Log(" * " + fileName);
- File.Copy(file, Path.Combine(dir, fileName), true);
- }
- }
-
- /// <summary> Cleans and Compiles the project. </summary>
- public void RunBuildTask()
- {
- CommandLine.WriteAction("Running [" + Name + "] build task..");
- Clean();
- Compile();
- }
-
- public override string ToString()
- {
- return Path.GetFileNameWithoutExtension(ProjectFile);
- }
-
- private void Log(string msg)
- {
- CommandLine.WriteLine("{{green}} " + msg, this);
- }
-
- /// <summary> Replaces Assembly version numner with the given one. </summary>
- public void ReplaceVersion(string newVersion)
- {
- // no need to increase version
- if (newVersion == null)
- return;
-
- var ASSEMBLY_INFO_PREFIX = "[assembly: AssemblyVersion(\"";
- var assemblyInfoFile = System.IO.Path.Combine(WorkingDirectory, "Properties", "AssemblyInfo.cs");
-
- try
- {
- // read all lines and replace the current version with the given newVersion
- var allLines = File.ReadAllLines(assemblyInfoFile).Select(
- l =>
- {
- // if the line contains assembly information, replace old version with new version
- if (l.StartsWith(ASSEMBLY_INFO_PREFIX))
- return ReplaceVersionInLine(l, ASSEMBLY_INFO_PREFIX, newVersion);
- else
- return l;
- });
- File.WriteAllLines(assemblyInfoFile, allLines);
- }
- catch (Exception ex)
- {
- // TODO(peleyal): remove before commiting
- CommandLine.WriteLine(ex.Message);
- }
- }
-
- /// <summary> Returns the assembly infromation line with the new version. </summary>
- private string ReplaceVersionInLine(string line, string assemblyVersionPrefix, string newVersion)
- {
- var startVersion = assemblyVersionPrefix.Length;
- // '.*' ends the old version number (e.g 1.2.* \ 1.3.0.*)
- var endVersion = line.IndexOf(".*", startVersion);
- var oldVersion = line.Substring(startVersion, endVersion - startVersion);
- return line.Replace(assemblyVersionPrefix + oldVersion, assemblyVersionPrefix + newVersion);
- }
- }
-}
« no previous file with comments | « Tools/Google.Build.Tester/app.config ('k') | Tools/Google.Build.Utils/DirUtils.cs » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b