Skip to content

Commit

Permalink
sources-as-resources overhaul
Browse files Browse the repository at this point in the history
Delete import{,-test}-sources goals, and instead include
source roots in classpaths for gwt:compile and gwt:test,
and the new gwt:package-lib.
  • Loading branch information
tbroyer committed Apr 24, 2017
1 parent 242d92b commit 7c4e86a
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 215 deletions.
23 changes: 15 additions & 8 deletions src/main/java/net/ltgt/gwt/maven/AbstractAddSuperSourcesMojo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package net.ltgt.gwt.maven;

import java.util.Collections;
import java.util.List;

import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;

public abstract class AbstractAddSuperSourcesMojo extends AbstractSourcesAsResourcesMojo {
public abstract class AbstractAddSuperSourcesMojo extends AbstractMojo {

/**
* Name of the module into which to optionally relocate super-sources.
Expand All @@ -15,15 +20,15 @@ public abstract class AbstractAddSuperSourcesMojo extends AbstractSourcesAsResou
@Parameter
protected String moduleName;

public AbstractAddSuperSourcesMojo() {
super();
}
@Parameter(defaultValue = "${project}", required = true, readonly = true)
protected MavenProject project;

@Override
public void execute() throws MojoExecutionException {
String superSourceRoot = getSuperSourceRoot();
if (checkResource(superSourceRoot)) {
Resource resource = createResource(superSourceRoot);
for (String superSourceRoot : SourcesAsResourcesHelper.filterSourceRoots(
getLog(), getProjectResources(), Collections.singleton(getSuperSourceRoot()))) {
Resource resource = new Resource();
resource.setDirectory(superSourceRoot);
if (isSuperSourceRelocated()) {
if (StringUtils.isBlank(moduleName)) {
throw new MojoExecutionException("Cannot relocate super-sources if moduleName is not specified");
Expand All @@ -32,7 +37,7 @@ public void execute() throws MojoExecutionException {
// Keep only package name
targetPath = targetPath.substring(0, targetPath.lastIndexOf('/'));
// Relocate into 'super' subfolder
targetPath = ensureTrailingSlash(targetPath) + "super/";
targetPath = SourcesAsResourcesHelper.ensureTrailingSlash(targetPath) + "super/";
resource.setTargetPath(targetPath);
}
addResource(resource);
Expand All @@ -44,4 +49,6 @@ public void execute() throws MojoExecutionException {
protected abstract boolean isSuperSourceRelocated();

protected abstract void addResource(Resource resource);

protected abstract List<Resource> getProjectResources();
}
62 changes: 0 additions & 62 deletions src/main/java/net/ltgt/gwt/maven/AbstractImportSourcesMojo.java

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/net/ltgt/gwt/maven/CompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public void execute() throws MojoExecutionException {
args.add(moduleName);

Set<String> cp = new LinkedHashSet<>();
List<String> sourceRoots = SourcesAsResourcesHelper.filterSourceRoots(
getLog(), project.getResources(), project.getCompileSourceRoots());
cp.addAll(sourceRoots);
try {
cp.addAll(project.getCompileClasspathElements());
} catch (DependencyResolutionRequiredException e) {
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/net/ltgt/gwt/maven/ImportSourcesMojo.java

This file was deleted.

40 changes: 0 additions & 40 deletions src/main/java/net/ltgt/gwt/maven/ImportTestSourcesMojo.java

This file was deleted.

116 changes: 116 additions & 0 deletions src/main/java/net/ltgt/gwt/maven/JarMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package net.ltgt.gwt.maven;

import java.io.File;
import java.util.List;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.jar.JarArchiver;

/**
* Package the compiled GWT library into a JAR archive.
*/
@Mojo(name = "package-lib", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
public class JarMojo extends AbstractMojo {
/**
* Directory containing the classes and resource files that should be packaged into the JAR.
*/
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
private File classesDirectory;

/**
* Directory containing the generated JAR.
*/
@Parameter(defaultValue = "${project.build.directory}", required = true)
private File outputDirectory;

/**
* Name of the generated JAR.
*/
@Parameter(defaultValue = "${project.build.finalName}", readonly = true)
private String finalName;

/**
* The Jar archiver.
*/
@Component(role = Archiver.class, hint = "jar" )
private JarArchiver jarArchiver;

/**
* The {@link {MavenProject}.
*/
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

/**
* The {@link MavenSession}.
*/
@Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;

/**
* The archive configuration to use. See <a href="http://maven.apache.org/shared/maven-archiver/index.html">Maven
* Archiver Reference</a>.
*/
@Parameter
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();

@Component
private MavenProjectHelper projectHelper;

/**
* Require the GWT plugin to build a new JAR even if none of the contents appear to have changed. By default, this
* plugin looks to see if the output jar exists and inputs have not changed. If these conditions are true, the
* plugin skips creation of the jar. This does not work when other plugins, like the maven-shade-plugin, are
* configured to post-process the jar. This plugin can not detect the post-processing, and so leaves the
* post-processed jar in place. This can lead to failures when those plugins do not expect to find their own output
* as an input. Set this parameter to <tt>true</tt> to avoid these problems by forcing this plugin to recreate the
* jar every time.<br/>
*/
@Parameter(property = "maven.jar.forceCreation", defaultValue = "false")
private boolean forceCreation;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File jarFile = new File(outputDirectory, finalName + ".jar");

MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);

archive.setForced(forceCreation);

List<String> sourceRoots = SourcesAsResourcesHelper.filterSourceRoots(
getLog(), project.getResources(), project.getCompileSourceRoots());

try {
for (String sourceRoot : sourceRoots) {
File f = new File(sourceRoot);
if (f.exists()) {
jarArchiver.addDirectory(f);
}
}

if (classesDirectory.exists()) {
jarArchiver.addDirectory(classesDirectory);
}

archiver.createArchive(session, project, archive);
} catch (Exception e) {
throw new MojoExecutionException("Error packaging GWT library", e);
}

project.getArtifact().setFile(jarFile);
}
}
Loading

0 comments on commit 7c4e86a

Please sign in to comment.