Skip to content

Commit f08c7f9

Browse files
committed
build plugin fixes and improvements
1 parent 5ad99f0 commit f08c7f9

11 files changed

Lines changed: 285 additions & 111 deletions

File tree

flapi-build-plugin/src/main/java/unquietcode/tools/flapi/plugin/FlapiBuildPlugin.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.maven.plugins.annotations.ResolutionScope;
2929
import org.apache.maven.project.MavenProject;
3030
import unquietcode.tools.flapi.Descriptor;
31+
import unquietcode.tools.flapi.DescriptorMaker;
3132
import unquietcode.tools.flapi.ExtractRuntime;
3233
import unquietcode.tools.flapi.plugin.compile.CharSequenceJavaFileObject;
3334
import unquietcode.tools.flapi.plugin.compile.ClassFileManager;
@@ -53,8 +54,8 @@
5354
*/
5455
@Mojo(
5556
name="generate",
56-
defaultPhase=LifecyclePhase.PROCESS_CLASSES,
57-
requiresDependencyResolution=ResolutionScope.COMPILE
57+
defaultPhase=LifecyclePhase.PROCESS_TEST_CLASSES,
58+
requiresDependencyResolution=ResolutionScope.TEST
5859
)
5960
public class FlapiBuildPlugin extends AbstractMojo {
6061

@@ -67,13 +68,6 @@ public class FlapiBuildPlugin extends AbstractMojo {
6768
@Parameter(required=true)
6869
private String descriptorClass;
6970

70-
/**
71-
* The name of the method, which should be
72-
* return type 'Descriptor' with no parameters.
73-
*/
74-
@Parameter(required=true)
75-
private String descriptorMethod;
76-
7771
/**
7872
* The directory to which the generated classes
7973
* will be written.
@@ -92,7 +86,7 @@ public class FlapiBuildPlugin extends AbstractMojo {
9286
* If true, the runtime classes will be written
9387
* out alongside the generated classes.
9488
*/
95-
@Parameter(defaultValue="false")
89+
@Parameter(defaultValue="true")
9690
private boolean includeRuntime;
9791

9892
/**
@@ -104,13 +98,14 @@ public class FlapiBuildPlugin extends AbstractMojo {
10498
/**
10599
* If true, the sources will be compiled and written.
106100
*/
107-
@Parameter(defaultValue="false")
101+
@Parameter(defaultValue="true")
108102
private boolean writeClasses;
109103

110104

111105
@Override
112106
public void execute() throws MojoExecutionException, MojoFailureException {
113107
Method method;
108+
DescriptorMaker descriptorMaker;
114109

115110
// instantiate the class
116111
URLClassLoader classLoader;
@@ -123,22 +118,29 @@ public void execute() throws MojoExecutionException, MojoFailureException {
123118
throw new MojoExecutionException("could not load class", ex);
124119
}
125120

121+
// ensure that it implements the interface
122+
if (!DescriptorMaker.class.isAssignableFrom(_descriptorClass)) {
123+
throw new MojoExecutionException("object must implement the DescriptorMaker interface");
124+
}
125+
126126
// lookup the method
127127
try {
128-
method = _descriptorClass.getMethod(descriptorMethod);
128+
method = _descriptorClass.getMethod("descriptor");
129129
} catch (NoSuchMethodException ex) {
130130
throw new MojoExecutionException("method cannot be found", ex);
131131
}
132132

133-
// ensure that it returns a Descriptor
134-
if (!Descriptor.class.isAssignableFrom(method.getReturnType())) {
135-
throw new MojoExecutionException("method must return a Descriptor object");
133+
// instantiate the object
134+
try {
135+
descriptorMaker = (DescriptorMaker) _descriptorClass.newInstance();
136+
} catch (Exception ex) {
137+
throw new MojoExecutionException("could not instantiate DescriptorMaker object", ex);
136138
}
137139

138140
// execute and get the descriptor
139141
Descriptor descriptor;
140142
try {
141-
descriptor = (Descriptor) method.invoke(null);
143+
descriptor = (Descriptor) method.invoke(descriptorMaker);
142144
} catch (IllegalAccessException ex) {
143145
throw new MojoExecutionException("method not accessible", ex);
144146
} catch (InvocationTargetException ex) {
@@ -174,7 +176,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
174176
private URLClassLoader getCompiledClassloader() throws Exception {
175177
List<URL> urls = new ArrayList<URL>();
176178

177-
for (Object object : project.getCompileClasspathElements()) {
179+
for (Object object : project.getTestClasspathElements()) {
178180
String path = (String) object;
179181
System.out.println(path);
180182
urls.add(new File(path).toURI().toURL());
@@ -213,6 +215,10 @@ private ClassLoader compileAndWriteClasses(Descriptor descriptor, URLClassLoader
213215
List<String> options = new ArrayList<String>();
214216
options.add("-classpath");
215217
options.add(makeClasspath(classLoader));
218+
options.add("-source");
219+
options.add("1.6");
220+
options.add("-target");
221+
options.add("1.6");
216222

217223
Iterable<? extends JavaFileObject> compilationUnits = getSourceFiles(descriptor);
218224
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);

flapi-build-project/pom.xml

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Copyright 2013 Benjamin Fagin
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
18+
Read the included LICENSE.TXT for more information.
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
20+
221
<project xmlns="http://maven.apache.org/POM/4.0.0"
322
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
423
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -12,7 +31,6 @@
1231
<properties>
1332
<flapi.generated.sources>${project.build.directory}/generated-sources/flapi</flapi.generated.sources>
1433
<flapi.descriptor.class>change.me</flapi.descriptor.class>
15-
<flapi.descriptor.method>changeMe</flapi.descriptor.method>
1634
</properties>
1735

1836
<profiles>
@@ -38,7 +56,6 @@
3856
</goals>
3957
<configuration>
4058
<descriptorClass>${flapi.descriptor.class}</descriptorClass>
41-
<descriptorMethod>${flapi.descriptor.method}</descriptorMethod>
4259
<sourcesDirectory>${flapi.generated.sources}</sourcesDirectory>
4360
</configuration>
4461
</execution>
@@ -95,50 +112,8 @@
95112
</execution>
96113
</executions>
97114
</plugin>
98-
99-
<!-- compile normally, then again for generated sources -->
100-
<plugin>
101-
<groupId>org.apache.maven.plugins</groupId>
102-
<artifactId>maven-compiler-plugin</artifactId>
103-
<version>2.5.1</version>
104-
<configuration>
105-
<source>1.6</source>
106-
<target>1.6</target>
107-
</configuration>
108-
<executions>
109-
<execution>
110-
<id>normal</id>
111-
<goals>
112-
<goal>compile</goal>
113-
</goals>
114-
<phase>compile</phase>
115-
</execution>
116-
<execution>
117-
<id>generated</id>
118-
<goals>
119-
<goal>compile</goal>
120-
</goals>
121-
<phase>process-test-sources</phase>
122-
</execution>
123-
<execution>
124-
<id>test</id>
125-
<goals>
126-
<goal>testCompile</goal>
127-
</goals>
128-
<phase>test-compile</phase>
129-
</execution>
130-
</executions>
131-
</plugin>
132115
</plugins>
133116
</build>
134117
</profile>
135118
</profiles>
136-
137-
<dependencies>
138-
<dependency>
139-
<groupId>unquietcode.tools.flapi</groupId>
140-
<artifactId>flapi</artifactId>
141-
<version>${project.version}</version>
142-
</dependency>
143-
</dependencies>
144119
</project>

flapi-build-test-consumer/pom.xml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Copyright 2013 Benjamin Fagin
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
18+
Read the included LICENSE.TXT for more information.
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
20+
221
<project xmlns="http://maven.apache.org/POM/4.0.0"
322
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
423
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -24,18 +43,13 @@
2443
</build>
2544

2645
<dependencies>
27-
<dependency>
28-
<groupId>unquietcode.tools.flapi</groupId>
29-
<artifactId>flapi-runtime</artifactId>
30-
<version>${project.version}</version>
31-
<scope>test</scope>
32-
</dependency>
46+
<!-- runtime is included -->
3347
<dependency>
3448
<groupId>unquietcode.tools.flapi.test</groupId>
3549
<artifactId>build-test-producer</artifactId>
3650
<version>${project.version}</version>
37-
<scope>test</scope>
3851
</dependency>
52+
3953
<dependency>
4054
<groupId>junit</groupId>
4155
<artifactId>junit</artifactId>

flapi-build-test-consumer/src/test/java/unquietcode/tools/flapi/plugin/DescriptorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
*/
3535
public class DescriptorTest {
3636

37-
3837
@Test
3938
public void usage() {
4039
EmailMessage message = EmailGenerator.compose(helper)

flapi-build-test-producer/pom.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Copyright 2013 Benjamin Fagin
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
18+
Read the included LICENSE.TXT for more information.
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
20+
221
<project xmlns="http://maven.apache.org/POM/4.0.0"
322
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
423
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -17,6 +36,14 @@
1736

1837
<properties>
1938
<flapi.descriptor.class>unquietcode.tools.flapi.plugin.TestDescriptor</flapi.descriptor.class>
20-
<flapi.descriptor.method>descriptor</flapi.descriptor.method>
2139
</properties>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>unquietcode.tools.flapi</groupId>
44+
<artifactId>flapi</artifactId>
45+
<version>${project.version}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
2249
</project>

flapi-build-test-producer/src/main/java/unquietcode/tools/flapi/plugin/TestDescriptor.java renamed to flapi-build-test-producer/src/test/java/unquietcode/tools/flapi/plugin/TestDescriptor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package unquietcode.tools.flapi.plugin;
2121

2222
import unquietcode.tools.flapi.Descriptor;
23+
import unquietcode.tools.flapi.DescriptorMaker;
2324
import unquietcode.tools.flapi.Flapi;
2425

2526
/**
@@ -28,9 +29,9 @@
2829
*
2930
* A test which builds an 'email builder' descriptor.
3031
*/
31-
public class TestDescriptor {
32+
public class TestDescriptor implements DescriptorMaker {
3233

33-
public static Descriptor descriptor() {
34+
public Descriptor descriptor() {
3435
Descriptor builder = Flapi.builder()
3536
.setPackage("unquietcode.tools.flapi.plugin.test.builder")
3637
.setStartingMethodName("compose")
@@ -51,6 +52,4 @@ public static Descriptor descriptor() {
5152

5253
return builder;
5354
}
54-
55-
5655
}

0 commit comments

Comments
 (0)