Skip to content

Commit

Permalink
[FIXED JENKINS-24825] define hudson.model.AbstractItem#movedTo
Browse files Browse the repository at this point in the history
(cherry picked from commit 9b3f488)

Conflicts:
	changelog.html
  • Loading branch information
ndeloof authored and olivergondza committed Nov 7, 2014
1 parent 034919e commit a4a28fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/AbstractItem.java
Expand Up @@ -41,6 +41,7 @@
import hudson.util.AlternativeUiTextProvider.Message;
import hudson.util.AtomicFileWriter;
import hudson.util.IOUtils;
import jenkins.model.DirectlyModifiableTopLevelItemGroup;
import jenkins.model.Jenkins;
import jenkins.security.NotReallyRoleSensitiveCallable;
import org.acegisecurity.Authentication;
Expand Down Expand Up @@ -324,6 +325,10 @@ public Void call() throws IOException {
}
}

public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir) throws IOException {
newItem.onLoad(destination, name);
}

/**
* A pointless function to work around what appears to be a HotSpot problem. See JENKINS-5756 and bug 6933067
* on BugParade for more details.
Expand Down Expand Up @@ -733,4 +738,5 @@ public static AbstractItem resolveForCLI(
* Replaceable pronoun of that points to a job. Defaults to "Job"/"Project" depending on the context.
*/
public static final Message<AbstractItem> PRONOUN = new Message<AbstractItem>();

}
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Items.java
Expand Up @@ -381,7 +381,7 @@ public static <I extends AbstractItem & TopLevelItem> I move(I item, DirectlyMod
FileUtils.moveDirectory(item.getRootDir(), destDir);
oldParent.remove(item);
I newItem = destination.add(item, name);
newItem.onLoad(destination, name);
item.movedTo(destination, newItem, destDir);
ItemListener.fireLocationChange(newItem, oldFullName);
return newItem;
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/hudson/model/Job.java
Expand Up @@ -63,13 +63,15 @@
import hudson.widgets.HistoryWidget.Adapter;
import hudson.widgets.Widget;
import jenkins.model.BuildDiscarder;
import jenkins.model.DirectlyModifiableTopLevelItemGroup;
import jenkins.model.Jenkins;
import jenkins.model.ProjectNamingStrategy;
import jenkins.security.HexStringConfidentialKey;
import jenkins.util.io.OnMaster;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
Expand Down Expand Up @@ -628,6 +630,18 @@ public void renameTo(String newName) throws IOException {
}
}

@Override
public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir) throws IOException {
Job newJob = (Job) newItem; // Missing covariant parameters type here.
File oldBuildDir = getBuildDir();
super.movedTo(destination, newItem, destDir);
File newBuildDir = getBuildDir();
if (oldBuildDir.isDirectory() && !newBuildDir.isDirectory()) {
FileUtils.forceMkdir(destDir.getParentFile());
FileUtils.moveDirectory(oldBuildDir, newBuildDir);
}
}

@Override public void delete() throws IOException, InterruptedException {
super.delete();
Util.deleteRecursive(getBuildDir());
Expand Down

0 comments on commit a4a28fb

Please sign in to comment.