Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.

Commit d49f261

Browse files
committed
Preliminary, incomplete, GWT Maven Plugin.
1 parent bc0d785 commit d49f261

File tree

36 files changed

+1988
-305
lines changed

36 files changed

+1988
-305
lines changed

bindery/event-gwt/pom.xml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,14 @@
1212
<artifactId>event-gwt</artifactId>
1313

1414
<build>
15-
<resources>
16-
<resource>
17-
<directory>src/main/resources</directory>
18-
</resource>
19-
<!-- embed sources in the JAR -->
20-
<resource>
21-
<directory>src/main/java</directory>
22-
</resource>
23-
<!-- super-sources -->
24-
<resource>
25-
<directory>src/main/super</directory>
26-
</resource>
27-
<!-- Where java-source dependencies are unpacked -->
28-
<resource>
29-
<directory>${dependencySourcesDirectory}</directory>
30-
</resource>
31-
</resources>
32-
3315
<plugins>
34-
<!-- Unpack java-source dependencies -->
3516
<plugin>
36-
<artifactId>maven-dependency-plugin</artifactId>
17+
<groupId>com.google.gwt.maven</groupId>
18+
<artifactId>gwt-maven-plugin</artifactId>
19+
<configuration>
20+
<moduleName>com.google.web.bindery.event.Event</moduleName>
21+
<skipModule>true</skipModule>
22+
</configuration>
3723
</plugin>
3824
</plugins>
3925
</build>

bindery/pom.xml

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
<artifactId>gwt-bindery-parent</artifactId>
1515
<packaging>pom</packaging>
1616

17-
<properties>
18-
<dependencySourcesDirectory>${project.build.directory}/generated-resources/dependency-sources</dependencySourcesDirectory>
19-
</properties>
20-
2117
<dependencyManagement>
2218
<dependencies>
2319
<dependency>
@@ -44,49 +40,6 @@
4440
</execution>
4541
</executions>
4642
</plugin>
47-
<plugin>
48-
<artifactId>maven-dependency-plugin</artifactId>
49-
<executions>
50-
<execution>
51-
<phase>generate-resources</phase>
52-
<goals>
53-
<goal>unpack-dependencies</goal>
54-
</goals>
55-
<configuration>
56-
<includeTypes>java-source</includeTypes>
57-
<includeScope>compile</includeScope>
58-
<outputDirectory>${dependencySourcesDirectory}</outputDirectory>
59-
</configuration>
60-
</execution>
61-
</executions>
62-
</plugin>
63-
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
64-
<plugin>
65-
<groupId>org.eclipse.m2e</groupId>
66-
<artifactId>lifecycle-mapping</artifactId>
67-
<version>1.0.0</version>
68-
<configuration>
69-
<lifecycleMappingMetadata>
70-
<pluginExecutions>
71-
<pluginExecution>
72-
<pluginExecutionFilter>
73-
<groupId>org.apache.maven.plugins</groupId>
74-
<artifactId>maven-dependency-plugin</artifactId>
75-
<versionRange>[2.1,)</versionRange>
76-
<goals>
77-
<goal>
78-
unpack-dependencies
79-
</goal>
80-
</goals>
81-
</pluginExecutionFilter>
82-
<action>
83-
<ignore/>
84-
</action>
85-
</pluginExecution>
86-
</pluginExecutions>
87-
</lifecycleMappingMetadata>
88-
</configuration>
89-
</plugin>
9043
</plugins>
9144
</pluginManagement>
9245
</build>

maven/pom.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>gwt</artifactId>
7+
<groupId>com.google.gwt</groupId>
8+
<version>2.6.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<groupId>com.google.gwt.maven</groupId>
13+
<artifactId>gwt-maven-plugin</artifactId>
14+
<packaging>maven-plugin</packaging>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.maven</groupId>
19+
<artifactId>maven-plugin-api</artifactId>
20+
<version>3.0.5</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.maven.plugin-tools</groupId>
24+
<artifactId>maven-plugin-annotations</artifactId>
25+
<version>3.2</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.codehaus.plexus</groupId>
30+
<artifactId>plexus-archiver</artifactId>
31+
<version>2.3</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.codehaus.plexus</groupId>
35+
<artifactId>plexus-utils</artifactId>
36+
<version>3.0.10</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.apache.maven</groupId>
40+
<artifactId>maven-core</artifactId>
41+
<version>3.0.5</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.apache.maven.surefire</groupId>
45+
<artifactId>maven-surefire-common</artifactId>
46+
<version>2.14.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.sonatype.plexus</groupId>
50+
<artifactId>plexus-build-api</artifactId>
51+
<version>0.0.7</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.google.gwt.dev</groupId>
55+
<artifactId>gwt-compiler</artifactId>
56+
<version>${project.version}</version>
57+
</dependency>
58+
</dependencies>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-plugin-plugin</artifactId>
65+
<version>3.2</version>
66+
<extensions>true</extensions>
67+
<configuration>
68+
<goalPrefix>gwt</goalPrefix>
69+
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
70+
</configuration>
71+
<executions>
72+
<execution>
73+
<goals>
74+
<goal>helpmojo</goal>
75+
<goal>descriptor</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.google.gwt.maven;
2+
3+
import org.apache.maven.model.Resource;
4+
import org.apache.maven.plugin.MojoExecutionException;
5+
import org.apache.maven.plugins.annotations.Parameter;
6+
import org.codehaus.plexus.util.StringUtils;
7+
8+
public abstract class AbstractAddSuperSourcesMojo extends AbstractSourcesAsResourcesMojo {
9+
10+
/**
11+
* Name of the module into which to optionally relocate super-sources.
12+
* <p>
13+
* Super-sources will be relocated into a {@code super} subfolder.
14+
*/
15+
@Parameter
16+
protected String moduleName;
17+
18+
public AbstractAddSuperSourcesMojo() {
19+
super();
20+
}
21+
22+
@Override
23+
public void execute() throws MojoExecutionException {
24+
String superSourceRoot = getSuperSourceRoot();
25+
if (checkResource(superSourceRoot)) {
26+
Resource resource = createResource(superSourceRoot);
27+
if (isSuperSourceRelocated()) {
28+
if (StringUtils.isBlank(moduleName)) {
29+
throw new MojoExecutionException("Cannot relocate super-sources if moduleName is not specified");
30+
}
31+
String targetPath = moduleName.replace('.', '/');
32+
// Keep only package name
33+
targetPath = targetPath.substring(0, targetPath.lastIndexOf('/'));
34+
// Relocate into 'super' subfolder
35+
targetPath = ensureTrailingSlash(targetPath) + "super/";
36+
resource.setTargetPath(targetPath);
37+
}
38+
addResource(resource);
39+
}
40+
}
41+
42+
protected abstract String getSuperSourceRoot();
43+
44+
protected abstract boolean isSuperSourceRelocated();
45+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.google.gwt.maven;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.List;
6+
import org.apache.maven.artifact.Artifact;
7+
import org.apache.maven.artifact.ArtifactUtils;
8+
import org.apache.maven.model.Resource;
9+
import org.apache.maven.plugin.MojoExecutionException;
10+
import org.apache.maven.plugins.annotations.Component;
11+
import org.apache.maven.project.MavenProject;
12+
import org.codehaus.plexus.archiver.UnArchiver;
13+
import org.codehaus.plexus.util.FileUtils;
14+
15+
public abstract class AbstractImportSourcesMojo extends AbstractSourcesAsResourcesMojo {
16+
17+
@Component(hint = "jar")
18+
private UnArchiver unArchiver;
19+
20+
@Override
21+
public void execute() throws MojoExecutionException {
22+
// Add the compile source roots as resources to the build
23+
for (String sourceRoot : getSourceRoots()) {
24+
addResource(sourceRoot);
25+
}
26+
27+
// Now unpack the type=java-source dependencies and add them as resources
28+
if (!getOutputDirectory().exists() && !getOutputDirectory().mkdirs()) {
29+
throw new MojoExecutionException("Cannot create output directory: " + getOutputDirectory().getAbsolutePath());
30+
}
31+
unArchiver.setDestDirectory(getOutputDirectory());
32+
addResource(getOutputDirectory().getPath());
33+
34+
for (Artifact artifact : project.getDependencyArtifacts()) {
35+
if (!includeArtifact(artifact)) {
36+
continue;
37+
}
38+
if (!"java-source".equals(artifact.getArtifactHandler().getPackaging())) {
39+
if (getLog().isDebugEnabled()) {
40+
getLog().debug("Skipping non-java-source dependency: " + artifact.getId());
41+
}
42+
continue;
43+
}
44+
if (getLog().isInfoEnabled()) {
45+
getLog().info("Importing " + artifact.getId());
46+
}
47+
// copy directory recursively, while dealing with http://jira.codehaus.org/browse/MNG-5214
48+
if (artifact.getFile().isDirectory()) {
49+
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
50+
getLog().warn(artifact.getId() + " has not been packaged yet, trying to infer sources from reactor.");
51+
importFromProjectReferences(ArtifactUtils.key(artifact));
52+
} else {
53+
unArchiver.setSourceFile(artifact.getFile());
54+
unArchiver.extract();
55+
}
56+
}
57+
}
58+
59+
private void importFromProjectReferences(String id) throws MojoExecutionException {
60+
try {
61+
MavenProject reference = project.getProjectReferences().get(id);
62+
for (String sourceRoot : reference.getCompileSourceRoots()) {
63+
File sourceDirectory = new File(sourceRoot);
64+
if (!sourceDirectory.isAbsolute()) {
65+
sourceDirectory = new File(reference.getBasedir(), sourceRoot);
66+
}
67+
if (sourceDirectory.exists()) {
68+
getLog().info("copying " + sourceDirectory);
69+
FileUtils.copyDirectoryStructureIfModified(sourceDirectory, getOutputDirectory());
70+
} else {
71+
getLog().info("skip non existing imported source directory " + sourceDirectory);
72+
}
73+
}
74+
} catch (IOException e) {
75+
throw new MojoExecutionException(e.getMessage(), e);
76+
}
77+
}
78+
79+
private void addResource(String resourceDirectory) {
80+
if (checkResource(resourceDirectory)) {
81+
Resource resource = createResource(resourceDirectory);
82+
addResource(resource);
83+
}
84+
}
85+
86+
protected abstract List<Resource> getProjectResources();
87+
88+
protected abstract void addResource(Resource resource);
89+
90+
protected abstract Iterable<String> getSourceRoots();
91+
92+
protected abstract File getOutputDirectory();
93+
94+
protected abstract boolean includeArtifact(Artifact artifact);
95+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.google.gwt.maven;
2+
3+
import org.apache.maven.model.Resource;
4+
import org.apache.maven.plugin.AbstractMojo;
5+
import org.apache.maven.plugins.annotations.Parameter;
6+
import org.apache.maven.project.MavenProject;
7+
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
public abstract class AbstractSourcesAsResourcesMojo extends AbstractMojo {
12+
private static final List<String> JAVA_SOURCES = Collections.singletonList("**/*.java");
13+
14+
@Parameter(defaultValue = "${project}", required = true, readonly = true)
15+
protected MavenProject project;
16+
17+
protected boolean checkResource(String sourceRoot) {
18+
// TODO: cache a processed list of Resources in a ThreadLocal as an optimization?
19+
sourceRoot = ensureTrailingSlash(sourceRoot);
20+
for (Resource resource : getProjectResources()) {
21+
String dir = ensureTrailingSlash(resource.getDirectory());
22+
if (dir.equals(sourceRoot)) {
23+
getLog().info(sourceRoot + " already added as a resource folder; skipping.");
24+
continue;
25+
}
26+
if (dir.startsWith(sourceRoot) || sourceRoot.startsWith(dir)) {
27+
getLog().warn(String.format(
28+
"Conflicting path between source folder (%s, to be added as resource) and resource (%s); skipping.",
29+
sourceRoot, dir));
30+
return false;
31+
}
32+
}
33+
return true;
34+
}
35+
36+
protected Resource createResource(String resourceDirectory) {
37+
Resource resource = new Resource();
38+
resource.setDirectory(resourceDirectory);
39+
resource.setIncludes(JAVA_SOURCES);
40+
return resource;
41+
}
42+
43+
protected abstract List<Resource> getProjectResources();
44+
45+
protected abstract void addResource(Resource resource);
46+
47+
protected String ensureTrailingSlash(String directory) {
48+
if (directory.endsWith("/")) {
49+
return directory;
50+
}
51+
return directory + "/";
52+
}
53+
}

0 commit comments

Comments
 (0)