Skip to content

Commit

Permalink
Modified to produce a jar file instead of WEB-INF/classes
Browse files Browse the repository at this point in the history
Because of the prefetching change in remoting  (see JENKINS-15120), it
is desirable now to produce class files in a jar file, not in a classes
directory, so that slaves can prefetch them and cache them efficiently.
  • Loading branch information
kohsuke committed Jun 9, 2013
1 parent 603d259 commit 6035351
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
Expand Up @@ -340,7 +340,7 @@ protected String[] getDependentWarIncludes() {
return StringUtils.split(StringUtils.defaultString(dependentWarIncludes), ",");
}

public void buildExplodedWebapp(File webappDirectory)
public void buildExplodedWebapp(File webappDirectory, File jarFile)
throws MojoExecutionException {
getLog().info("Exploding webapp...");

Expand Down Expand Up @@ -370,6 +370,8 @@ public void buildExplodedWebapp(File webappDirectory)
}

buildWebapp(project, webappDirectory);

copyFileIfModified(jarFile, new File(getWebappDirectory(),"WEB-INF/lib/"+jarFile.getName()));
}
catch (IOException e) {
throw new MojoExecutionException("Could not explode webapp...", e);
Expand Down Expand Up @@ -500,12 +502,6 @@ public void buildWebapp(MavenProject project, File webappDirectory)

File tldDirectory = new File(webappDirectory, WEB_INF + "/tld");

File webappClassesDirectory = new File(webappDirectory, WEB_INF + "/classes");

if (classesDirectory.exists() && !classesDirectory.equals(webappClassesDirectory)) {
copyDirectoryStructureIfModified(classesDirectory, webappClassesDirectory);
}

Set<MavenArtifact> artifacts = getProjectArtfacts();

List<String> duplicates = findDuplicates(artifacts);
Expand Down
36 changes: 19 additions & 17 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/HpiMojo.java
Expand Up @@ -122,37 +122,39 @@ public void execute() throws MojoExecutionException {
private void performPackaging()
throws IOException, ArchiverException, ManifestException, DependencyResolutionRequiredException, MojoExecutionException {

File hpiFile = getOutputFile(".hpi");
buildExplodedWebapp(getWebappDirectory());
// generate a manifest
File manifestFile = new File(getWebappDirectory(), "META-INF/MANIFEST.MF");
generateManifest(manifestFile);
Manifest manifest = loadManifest(manifestFile);

//generate war file
// create a jar file to be used when other plugins depend on this plugin.
File jarFile = getOutputFile(".jar");
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
jarArchiver.addConfiguredManifest(manifest);
jarArchiver.addDirectory(getClassesDirectory());
archiver.createArchive(project,archive);
projectHelper.attachArtifact(project, "jar", null, jarFile);

// generate war file
buildExplodedWebapp(getWebappDirectory(),jarFile);

File hpiFile = getOutputFile(".hpi");
getLog().info("Generating hpi " + hpiFile.getAbsolutePath());

MavenArchiver archiver = new MavenArchiver();
archiver = new MavenArchiver();

archiver.setArchiver(hpiArchiver);
archiver.setOutputFile(hpiFile);

File manifestFile = new File(getWebappDirectory(), "META-INF/MANIFEST.MF");
generateManifest(manifestFile);
Manifest manifest = loadManifest(manifestFile);

hpiArchiver.addConfiguredManifest(manifest);
hpiArchiver.addDirectory(getWebappDirectory(), getIncludes(), getExcludes());

// create archive
archiver.createArchive(project, archive);
project.getArtifact().setFile(hpiFile);

// also creates a jar file to be used when other plugins depend on this plugin.
File jarFile = getOutputFile(".jar");
archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
jarArchiver.addConfiguredManifest(manifest);
jarArchiver.addDirectory(getClassesDirectory());
archiver.createArchive(project,archive);
projectHelper.attachArtifact(project, "jar", null, jarFile);
}

private Manifest loadManifest(File f) throws IOException, ManifestException {
Expand Down

3 comments on commit 6035351

@slide
Copy link
Member

@slide slide commented on 6035351 Feb 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this change breaks tools like CLIRR because it expects the classes directory to be available.

@kohsuke
Copy link
Member Author

@kohsuke kohsuke commented on 6035351 Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it break the CLIRR plugin for Jenkins (although I couldn't find it)? I'm not sure if I understand.

@slide
Copy link
Member

@slide slide commented on 6035351 Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the maven-clirr-plugin to my plugin to test for backward compatibility in my API. I was using maven-hpi-plugin 1.99 in my pom for some reason (I don't remember why), the maven-clirr-plugin didn't find any differences even though I had made significant changes. I then removed the override to 1.99 for the maven-hpi-plugin and it was able to find differences. After some minimal debugging of the maven-clirr-plugin, I determined that it was because the classes directory was not in the hpi.

Please sign in to comment.