Skip to content

Commit

Permalink
Use the external command factory for the script generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Apple committed Jul 18, 2013
1 parent 5e50fd4 commit 2091748
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
12 changes: 5 additions & 7 deletions Kudu.Core/Deployment/Generator/ExternalCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ namespace Kudu.Core.Deployment.Generator
{
public abstract class ExternalCommandBuilder : ISiteBuilder
{
// TODO: Once CustomBuilder is removed, change all internals back to privates

private readonly ExternalCommandFactory _externalCommandFactory;

protected ExternalCommandBuilder(IEnvironment environment, IDeploymentSettingsManager settings, IBuildPropertyProvider propertyProvider, string repositoryPath)
{
Environment = environment;
Expand All @@ -22,7 +18,7 @@ protected ExternalCommandBuilder(IEnvironment environment, IDeploymentSettingsMa
PropertyProvider = propertyProvider;
HomePath = environment.SiteRootPath;

_externalCommandFactory = new ExternalCommandFactory(environment, settings, repositoryPath);
ExternalCommandFactory = new ExternalCommandFactory(environment, settings, repositoryPath);
}

protected IEnvironment Environment { get; private set; }
Expand All @@ -35,6 +31,8 @@ protected ExternalCommandBuilder(IEnvironment environment, IDeploymentSettingsMa

protected string HomePath { get; private set; }

internal ExternalCommandFactory ExternalCommandFactory { get; private set; }

public abstract Task Build(DeploymentContext context);

protected void RunCommand(DeploymentContext context, string command)
Expand All @@ -44,8 +42,8 @@ protected void RunCommand(DeploymentContext context, string command)

// Creates an executable pointing to cmd and the working directory being
// the repository root
var exe = _externalCommandFactory.BuildExternalCommandExecutable(RepositoryPath, context.OutputPath, customLogger);
var exe = ExternalCommandFactory.BuildExternalCommandExecutable(RepositoryPath, context.OutputPath, customLogger);

exe.EnvironmentVariables[WellKnownEnvironmentVariables.PreviousManifestPath] = context.PreviousManifestFilePath ?? String.Empty;
exe.EnvironmentVariables[WellKnownEnvironmentVariables.NextManifestPath] = context.NextManifestFilePath;

Expand Down
16 changes: 8 additions & 8 deletions Kudu.Core/Deployment/Generator/GeneratorSiteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
using System.Threading.Tasks;
using Kudu.Contracts.Settings;
using Kudu.Contracts.Tracing;
using Kudu.Core.Infrastructure;

namespace Kudu.Core.Deployment.Generator
{
public abstract class GeneratorSiteBuilder : ExternalCommandBuilder
{
private const string ScriptGeneratorCommandFormat = "-y --no-dot-deployment -r \"{0}\" -o \"{1}\" {2}";
private const string ScriptGeneratorCommandArgumentsFormat = "-y --no-dot-deployment -r \"{0}\" -o \"{1}\" {2}";
private const string DeploymentScriptFileName = "deploy.cmd";
private const string DeploymentCommandCacheKeyFileName = "deploymentCacheKey";

Expand Down Expand Up @@ -66,25 +65,26 @@ private void GenerateScript(DeploymentContext context, ILogger buildLogger)
{
using (context.Tracer.Step("Generating deployment script"))
{
var scriptGenerator = new Executable(DeploymentScriptGeneratorToolPath, RepositoryPath, DeploymentSettings.GetCommandIdleTimeout());
var scriptGenerator = ExternalCommandFactory.BuildExternalCommandExecutable(RepositoryPath, context.OutputPath, buildLogger);

// Set home path to the user profile so cache directories created by azure-cli are created there
scriptGenerator.SetHomePath(System.Environment.GetEnvironmentVariable("APPDATA"));

var scriptGeneratorCommand = String.Format(ScriptGeneratorCommandFormat, RepositoryPath, Environment.DeploymentToolsPath, ScriptGeneratorCommandArguments);
var scriptGeneratorCommandArguments = String.Format(ScriptGeneratorCommandArgumentsFormat, RepositoryPath, Environment.DeploymentToolsPath, ScriptGeneratorCommandArguments);
var scriptGeneratorCommand = "\"{0}\" {1}".FormatInvariant(DeploymentScriptGeneratorToolPath, scriptGeneratorCommandArguments);

bool cacheUsed = UseCachedDeploymentScript(scriptGeneratorCommand, context);
bool cacheUsed = UseCachedDeploymentScript(scriptGeneratorCommandArguments, context);
if (!cacheUsed)
{
buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommand);
buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommandArguments);

scriptGenerator.ExecuteWithProgressWriter(buildLogger, context.Tracer, scriptGeneratorCommand);

CacheDeploymentScript(scriptGeneratorCommand, context);
CacheDeploymentScript(scriptGeneratorCommandArguments, context);
}
else
{
buildLogger.Log(Resources.Log_DeploymentScriptGeneratorUsingCache, scriptGeneratorCommand);
buildLogger.Log(Resources.Log_DeploymentScriptGeneratorUsingCache, scriptGeneratorCommandArguments);
}
}
}
Expand Down

0 comments on commit 2091748

Please sign in to comment.