Skip to content
Permalink
Browse files

[JENKINS-17680] Upgrade is applied also to MatrixProject.

  • Loading branch information...
ikedam committed Aug 3, 2013
1 parent 854deb1 commit b42c2158119f8c8b06d0562bbd1d9bf7b7ee5f49
@@ -145,6 +145,16 @@ private static synchronized void setUpgradeNeeded() {
}
}

// get all CopyArtifacts configured to AbstractProject. This works both for Project and MatrixProject.
private static List<CopyArtifact> getCopiers(AbstractProject<?,?> project) throws IOException {
DescribableList<Builder,Descriptor<Builder>> list =
project instanceof Project ? ((Project<?,?>)project).getBuildersList()
: (project instanceof MatrixProject ?
((MatrixProject)project).getBuildersList() : null);
if (list == null) return Collections.emptyList();
return list.getAll(CopyArtifact.class);
}

@Initializer(after=InitMilestone.JOB_LOADED)
public static void upgradeCopyArtifact() {
if (!upgradeNeeded) {
@@ -153,15 +163,19 @@ public static void upgradeCopyArtifact() {
upgradeNeeded = false;

boolean isUpgraded = false;
for (Project<?,?> project: Jenkins.getInstance().getAllItems(Project.class)) {
for (CopyArtifact target: Util.filter(project.getBuilders(), CopyArtifact.class)) {
try {
if (target.upgradeIfNecessary(project)) {
isUpgraded = true;
for (AbstractProject<?,?> project: Jenkins.getInstance().getAllItems(AbstractProject.class)) {
try {
for (CopyArtifact target: getCopiers(project)) {
try {
if (target.upgradeIfNecessary(project)) {
isUpgraded = true;
}
} catch(IOException e) {
LOGGER.log(Level.SEVERE, String.format("Failed to upgrade CopyArtifact in %s", project.getFullName()), e);
}
} catch(IOException e) {
LOGGER.log(Level.SEVERE, String.format("Failed to upgrade CopyArtifact in %s", project.getFullName()), e);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, String.format("Failed to upgrade CopyArtifact in %s", project.getFullName()), e);
}
}

@@ -391,12 +405,7 @@ else if (ca.getProjectName().startsWith(oldName + '/'))
}

private static List<CopyArtifact> getCopiers(AbstractProject<?,?> project) throws IOException {
DescribableList<Builder,Descriptor<Builder>> list =
project instanceof Project ? ((Project<?,?>)project).getBuildersList()
: (project instanceof MatrixProject ?
((MatrixProject)project).getBuildersList() : null);
if (list == null) return Collections.emptyList();
List<CopyArtifact> copiers = list.getAll(CopyArtifact.class);
List<CopyArtifact> copiers = CopyArtifact.getCopiers(project);
for (CopyArtifact copier : copiers) {
copier.upgradeIfNecessary(project);
}
@@ -920,6 +920,14 @@ public void testProjectNameSplit() throws Exception {
assertTrue(configXml, configXml.contains("<project>parameterized</project>"));
assertTrue(configXml, configXml.contains("<parameters>good=true</parameters>"));
assertTrue(configXml, configXml.contains("<project>matrix/which=two</project>"));

MatrixProject matrixCopier = Jenkins.getInstance().getItemByFullName("matrix-copier", MatrixProject.class);
assertNotNull(matrixCopier);
configXml = matrixCopier.getConfigFile().asString();
assertFalse(configXml, configXml.contains("<projectName>"));
// When a project is specified with a variable, it is split improperly.
assertTrue(configXml, configXml.contains("<project>matrix</project>"));
assertTrue(configXml, configXml.contains("<parameters>which=${which}</parameters>"));
}

@Bug(17447)
Binary file not shown.

0 comments on commit b42c215

Please sign in to comment.
You can’t perform that action at this time.