Skip to content
Permalink
Browse files

Merge pull request #22 from marcelst/master

[JENKINS-22673]  Sites for nested Maven multi-module projects deeper than one level are archived flat
  • Loading branch information...
olamy committed Apr 22, 2014
2 parents a0ab963 + 1c42b19 commit 574406cfc25c8c668b8dcf638718c238757ede98
@@ -79,9 +79,7 @@ public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo moj

if(destDir != null && destDir.exists()) {
// try to get the storage location if this is a multi-module project.
final String moduleName = getModuleName(build, pom);
// store at MavenModuleSet level and moduleName
final FilePath target = build.getModuleSetRootDir().child("site").child(moduleName);
final FilePath target = getModulePath(build, pom);
try {
listener.getLogger().printf("[JENKINS] Archiving site from %s to %s%n", destDir, target);
new FilePath(destDir).copyRecursiveTo(target);
@@ -98,35 +96,39 @@ public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo moj
}

/**
* In multi module builds pomBaseDir of the parent project is the same as parent build module root.
*
* In multi module builds, ascend to the parents until hitting the project
* root.
*
* @param build
* @param pom
*
*
* @return the relative path component to copy sites of multi module builds.
* @throws IOException
* @throws InterruptedException
* @throws InterruptedException
*/
private String getModuleName(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException {
String moduleRoot = build.execute(new BuildCallable<String, IOException>() {
private FilePath getModulePath(MavenBuildProxy build, MavenProject pom) throws IOException, InterruptedException {
String rootArtifactId = build.execute(new BuildCallable<String, IOException>() {
private static final long serialVersionUID = 1L;

//@Override
public String call(MavenBuild mavenBuild) throws IOException, InterruptedException {
MavenModuleSetBuild moduleSetBuild = mavenBuild.getModuleSetBuild();
if (moduleSetBuild == null) {
throw new IOException("Parent build not found!");
}
return moduleSetBuild.getModuleRoot().getRemote();
MavenModuleSet moduleSet = mavenBuild.getModuleSetBuild().getParent();
if (moduleSet == null) {
throw new IOException("Parent build not found!");
}
return moduleSet.getRootModule().getArtifactId();
}
});
final File pomBaseDir = pom.getBasedir();
final File remoteWorkspaceDir = new File(moduleRoot);
if (pomBaseDir.equals(remoteWorkspaceDir)) {
return "";
} else {
return pom.getArtifactId();

String path = "";
MavenProject currentLevel = pom;
// build the path to the module by ascending to the parent pom until the root project
while (!rootArtifactId.equals(currentLevel.getArtifactId())) {
path = currentLevel.getArtifactId() + File.separator + path;
currentLevel = currentLevel.getParent();
}

return build.getModuleSetRootDir().child("site").child(path);
}


@@ -6,9 +6,9 @@
import static org.powermock.api.support.membermodification.MemberMatcher.constructor;
import static org.powermock.api.support.membermodification.MemberModifier.suppress;
import hudson.maven.MavenModuleSet.DescriptorImpl;
import hudson.model.AbstractProject;
import hudson.model.DependencyGraph;
import hudson.model.MockHelper;
import hudson.model.AbstractProject;

import java.io.IOException;
import java.util.Collection;
@@ -140,6 +140,26 @@ public void testMultiModuleSiteBuild() throws Exception {
wc.getPage(project, "site/core");
}

public void testNestedMultiModuleSiteBuild() throws Exception {
MavenModuleSet project = createProject("maven-nested-multimodule-site.zip");
project.setGoals("site");

try {
buildAndAssertSuccess(project);
} catch (InterruptedException x) {
return; // TODO as above
}

// this should succeed
HudsonTestCase.WebClient wc = new WebClient();
wc.getPage(project, "site");
wc.getPage(project, "site/core");
wc.getPage(project, "site/client");
wc.getPage(project, "site/client/nested1");
wc.getPage(project, "site/client/nested1/nested2");

}

/**
* Check if the the site goal will work when run from a slave.
*/
Binary file not shown.

0 comments on commit 574406c

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