Skip to content
Permalink
Browse files

[FIXED JENKINS-18846] Update symlinks for Maven module builds.

(cherry picked from commit a92e9da)

Conflicts:
	changelog.html
	test/src/test/java/hudson/maven/MavenMultiModuleTest.java
  • Loading branch information
jglick authored and olivergondza committed Sep 13, 2013
1 parent cd42847 commit 92e85f74258526def5b9fd8e10efc5575b4d80bb
@@ -37,7 +37,6 @@
import hudson.matrix.MatrixConfiguration;
import hudson.model.Fingerprint.BuildPtr;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.PermalinkProjectAction.Permalink;
import hudson.model.listeners.RunListener;
import hudson.model.listeners.SCMListener;
import hudson.scm.ChangeLogParser;
@@ -59,7 +58,6 @@
import hudson.tasks.test.AggregatedTestResultAction;
import hudson.util.*;
import jenkins.model.Jenkins;
import jenkins.model.PeepholePermalink;
import jenkins.model.lazy.AbstractLazyLoadRunMap.Direction;
import jenkins.model.lazy.BuildReference;
import org.kohsuke.stapler.HttpResponse;
@@ -475,23 +473,6 @@ public String getHudsonVersion() {
return hudsonVersion;
}

/**
* Backward compatibility.
*
* We used to have $JENKINS_HOME/jobs/JOBNAME/lastStable and lastSuccessful symlinked to the appropriate
* builds, but now those are done in {@link PeepholePermalink}. So here, we simply create symlinks that
* resolves to the symlink created by {@link PeepholePermalink}.
*/
private void createSymlink(TaskListener listener, String name, Permalink target) throws InterruptedException {
String targetDir;
if (getProject().getBuildDir().equals(new File(getProject().getRootDir(), "builds"))) {
targetDir = "builds" + File.separator + target.getId();
} else {
targetDir = getProject().getBuildDir() + File.separator + target.getId();
}
Util.createSymlink(getProject().getRootDir(), targetDir, name, listener);
}

/**
* @deprecated as of 1.467
* Please use {@link RunExecution}
@@ -722,9 +703,6 @@ public void defaultCheckout() throws IOException, InterruptedException {
public final void post(BuildListener listener) throws Exception {
try {
post2(listener);

createSymlink(listener, "lastSuccessful", Permalink.LAST_SUCCESSFUL_BUILD);
createSymlink(listener, "lastStable", Permalink.LAST_STABLE_BUILD);
} finally {
// update the culprit list
HashSet<String> r = new HashSet<String>();
@@ -120,6 +120,7 @@
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.PeepholePermalink;
import jenkins.model.RunAction2;

/**
@@ -1586,8 +1587,7 @@ protected final void execute(RunExecution job) {

RunListener.fireStarted(this,listener);

// create a symlink from build number to ID.
Util.createSymlink(getParent().getBuildDir(),getId(),String.valueOf(getNumber()),listener);
updateSymlinks(listener);

setResult(job.run(listener));

@@ -1663,6 +1663,40 @@ protected final void execute(RunExecution job) {
}
}

/**
* Creates a symlink from build number to ID.
* Also makes sure that {@code lastSuccessful} and {@code lastStable} legacy links in the project’s root directory exist.
* Normally you do not need to call this explicitly, since {@link #execute} does so,
* but this may be needed if you are creating synthetic {@link Run}s as part of a container project (such as Maven builds in a module set).
* You should also ensure that {@link RunListener#fireStarted} and {@link RunListener#fireCompleted} are called.
* @param listener probably unused
* @throws InterruptedException probably not thrown
* @since 1.530
*/
public final void updateSymlinks(TaskListener listener) throws InterruptedException {
Util.createSymlink(getParent().getBuildDir(), getId(), String.valueOf(getNumber()), listener);
createSymlink(listener, "lastSuccessful", PermalinkProjectAction.Permalink.LAST_SUCCESSFUL_BUILD);
createSymlink(listener, "lastStable", PermalinkProjectAction.Permalink.LAST_STABLE_BUILD);
}
/**
* Backward compatibility.
*
* We used to have $JENKINS_HOME/jobs/JOBNAME/lastStable and lastSuccessful symlinked to the appropriate
* builds, but now those are done in {@link PeepholePermalink}. So here, we simply create symlinks that
* resolves to the symlink created by {@link PeepholePermalink}.
*/
private void createSymlink(TaskListener listener, String name, PermalinkProjectAction.Permalink target) throws InterruptedException {
File buildDir = getParent().getBuildDir();
File rootDir = getParent().getRootDir();
String targetDir;
if (buildDir.equals(new File(rootDir, "builds"))) {
targetDir = "builds" + File.separator + target.getId();
} else {
targetDir = buildDir + File.separator + target.getId();
}
Util.createSymlink(rootDir, targetDir, name, listener);
}

/**
* Handles a fatal build problem (exception) that occurred during the build.
*/
@@ -41,6 +41,7 @@
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
import hudson.remoting.Channel;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
@@ -73,6 +74,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;

@@ -497,6 +499,7 @@ public void start() {
} catch (IOException e) {
e.printStackTrace();
}
RunListener.fireStarted(MavenBuild.this, listener);
}

public void end() {
@@ -512,6 +515,12 @@ public void end() {
} catch (IOException e) {
e.printStackTrace();
}
try {
updateSymlinks(listener);
} catch (InterruptedException x) {
Logger.getLogger(MavenBuild.class.getName()).log(Level.WARNING, null, x);
}
RunListener.fireCompleted(MavenBuild.this, listener);
}

/**

0 comments on commit 92e85f7

Please sign in to comment.