Skip to content

Commit

Permalink
[FIXED JENKINS-17913] Expand manifest file and URL
Browse files Browse the repository at this point in the history
  • Loading branch information
scottanderson committed Oct 24, 2014
1 parent 8481d85 commit 4a759bf
Showing 1 changed file with 32 additions and 36 deletions.
68 changes: 32 additions & 36 deletions src/main/java/hudson/plugins/repo/RepoScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,14 @@ public class RepoScm extends SCM implements Serializable {
private final boolean resetFirst;
private final boolean quiet;

/**
* Returns the manifest repository URL.
*/
@Exported
public String getManifestRepositoryUrl() {
return manifestRepositoryUrl;
}

/**
* Returns the manifest branch name. By default, this is null and repo
* defaults to "master".
*/
@Exported
public String getManifestBranch() {
return manifestBranch;
}

private String getManifestBranch(final EnvVars env) {
return manifestBranch == null ? null : env.expand(manifestBranch);
}

/**
* Same as {@link #getManifestBranch()} but with <em>default</em>
* values of parameters expanded.
* @param environment an existing environment, which contains already
* properties from the current build
* @param project the project that is being built
*/
private String getManifestBranchExpanded(final EnvVars environment,
private EnvVars getEnvVars(final EnvVars environment,
final AbstractProject<?, ?> project) {
// create an empty vars map
final EnvVars finalEnv = new EnvVars();
Expand All @@ -144,8 +123,24 @@ private String getManifestBranchExpanded(final EnvVars environment,
}

EnvVars.resolve(finalEnv);
return finalEnv;
}

/**
* Returns the manifest repository URL.
*/
@Exported
public String getManifestRepositoryUrl() {
return manifestRepositoryUrl;
}

return getManifestBranch(finalEnv);
/**
* Returns the manifest branch name. By default, this is null and repo
* defaults to "master".
*/
@Exported
public String getManifestBranch() {
return manifestBranch;
}

/**
Expand Down Expand Up @@ -174,6 +169,7 @@ public String getManifestGroup() {
public String getRepoUrl() {
return repoUrl;
}

/**
* Returns the name of the mirror directory. By default, this is null and
* repo does not use a mirror.
Expand Down Expand Up @@ -329,8 +325,8 @@ protected PollingResult compareRemoteRevisionWith(
final SCMRevisionState baseline) throws IOException,
InterruptedException {
SCMRevisionState myBaseline = baseline;
final String expandedManifestBranch =
getManifestBranchExpanded(null, project);
final EnvVars env = getEnvVars(null, project);
final String expandedManifestBranch = env.expand(manifestBranch);
final AbstractBuild<?, ?> lastBuild = project.getLastBuild();

if (myBaseline == null) {
Expand All @@ -351,8 +347,7 @@ protected PollingResult compareRemoteRevisionWith(
repoDir = workspace;
}

if (!checkoutCode(launcher, repoDir, expandedManifestBranch,
listener.getLogger())) {
if (!checkoutCode(launcher, repoDir, env, listener.getLogger())) {
// Some error occurred, try a build now so it gets logged.
return new PollingResult(myBaseline, myBaseline,
Change.INCOMPARABLE);
Expand Down Expand Up @@ -388,17 +383,17 @@ public boolean checkout(
repoDir = workspace;
}

AbstractProject<?, ?> proj = build.getProject();
EnvVars env = build.getEnvironment(listener);
final String expandedBranch = getManifestBranchExpanded(
env, build.getProject());
if (!checkoutCode(launcher, repoDir, expandedBranch,
listener.getLogger())) {
env = getEnvVars(env, proj);
if (!checkoutCode(launcher, repoDir, env, listener.getLogger())) {
return false;
}
final String manifest =
getStaticManifest(launcher, repoDir, listener.getLogger());
final String manifestRevision =
getManifestRevision(launcher, repoDir, listener.getLogger());
final String expandedBranch = env.expand(manifestBranch);
final RevisionState currentState =
new RevisionState(manifest, manifestRevision, expandedBranch,
listener.getLogger());
Expand Down Expand Up @@ -452,7 +447,8 @@ private int doSync(final Launcher launcher, final FilePath workspace,
}

private boolean checkoutCode(final Launcher launcher,
final FilePath workspace, final String expandedManifestBranch,
final FilePath workspace,
final EnvVars env,
final OutputStream logger)
throws IOException, InterruptedException {
final List<String> commands = new ArrayList<String>(4);
Expand All @@ -462,14 +458,14 @@ private boolean checkoutCode(final Launcher launcher,
commands.add(getDescriptor().getExecutable());
commands.add("init");
commands.add("-u");
commands.add(manifestRepositoryUrl);
if (expandedManifestBranch != null) {
commands.add(env.expand(manifestRepositoryUrl));
if (manifestBranch != null) {
commands.add("-b");
commands.add(expandedManifestBranch);
commands.add(env.expand(manifestBranch));
}
if (manifestFile != null) {
commands.add("-m");
commands.add(manifestFile);
commands.add(env.expand(manifestFile));
}
if (mirrorDir != null) {
commands.add("--reference=" + mirrorDir);
Expand Down

0 comments on commit 4a759bf

Please sign in to comment.