Skip to content

Commit 5be254e

Browse files
committed
Add effective-config, effective-test-config and crypt goals
1 parent 59c2423 commit 5be254e

File tree

8 files changed

+139
-15
lines changed

8 files changed

+139
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Version 2.4.0 (2017-02-09)
2+
3+
* [new] New goal `effective-config` to dump effective configuration of the project as YAML.
4+
* [new] New goal `effective-test-config` to dump effective test configuration of the project as YAML.
5+
* [new] New goal `crypt` to crypt password using the configured master key store of the application.
6+
17
# Version 2.3.2 (2017-02-06)
28

39
* [new] Detect and use the latest version of Maven archetype plugin when generating a project.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<groupId>org.seedstack</groupId>
2121
<artifactId>seedstack-maven-plugin</artifactId>
22-
<version>2.3.2-SNAPSHOT</version>
22+
<version>2.4.0-SNAPSHOT</version>
2323
<packaging>maven-plugin</packaging>
2424

2525
<properties>

src/license/THIRD-PARTY.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Please fill the missing licenses for dependencies :
1313
#
1414
#
15-
#Mon Feb 06 10:34:27 CET 2017
15+
#Thu Feb 09 18:02:08 CET 2017
1616
classworlds--classworlds--1.1-alpha-2=
1717
commons-collections--commons-collections--3.1=
1818
dom4j--dom4j--1.6.1=

src/main/java/org/seedstack/maven/AbstractExecutableMojo.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.URL;
2222
import java.net.URLClassLoader;
2323
import java.util.ArrayList;
24+
import java.util.Collection;
2425
import java.util.List;
2526

2627
/**
@@ -32,11 +33,14 @@ public class AbstractExecutableMojo extends AbstractMojo {
3233
private MavenProject project;
3334
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
3435
private File classesDirectory;
36+
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
37+
private File testClassesDirectory;
3538
@Parameter(property = "args")
3639
private String args;
3740

3841
private final IsolatedThreadGroup isolatedThreadGroup = new IsolatedThreadGroup("seed-app");
3942
private final Object monitor = new Object();
43+
private boolean testMode = false;
4044
protected Runnable runnable;
4145

4246
@Override
@@ -68,6 +72,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6872
joinNonDaemonThreads(isolatedThreadGroup);
6973
}
7074

75+
protected void enableTestMode() {
76+
this.testMode = true;
77+
}
78+
7179
protected Object getMonitor() {
7280
return monitor;
7381
}
@@ -118,30 +126,46 @@ private URL[] getClassPathUrls() throws MojoExecutionException {
118126
List<URL> urls = new ArrayList<URL>();
119127

120128
try {
121-
// Project resources
122-
for (Resource resource : this.project.getResources()) {
123-
File directory = new File(resource.getDirectory());
124-
urls.add(directory.toURI().toURL());
125-
removeDuplicatesFromOutputDirectory(this.classesDirectory, directory);
129+
if (testMode) {
130+
// Project test resources
131+
addResources(this.testClassesDirectory, this.project.getTestResources(), urls);
132+
133+
// Project test classes
134+
urls.add(this.testClassesDirectory.toURI().toURL());
126135
}
127136

137+
// Project resources
138+
addResources(this.classesDirectory, this.project.getResources(), urls);
139+
128140
// Project classes
129141
urls.add(this.classesDirectory.toURI().toURL());
130142

131-
// Project dependencies
132-
for (Artifact artifact : this.project.getArtifacts()) {
133-
File file = artifact.getFile();
134-
if (file.getName().endsWith(".jar")) {
135-
urls.add(file.toURI().toURL());
136-
}
137-
}
143+
// Project dependencies (scope is dependent upon the @Mojo annotation and the already executed phase)
144+
addArtifacts(this.project.getArtifacts(), urls);
138145
} catch (MalformedURLException e) {
139146
throw new MojoExecutionException("Unable to build classpath", e);
140147
}
141148

142149
return urls.toArray(new URL[urls.size()]);
143150
}
144151

152+
private void addArtifacts(Collection<Artifact> artifacts, List<URL> urls) throws MalformedURLException {
153+
for (Artifact artifact : artifacts) {
154+
File file = artifact.getFile();
155+
if (file.getName().endsWith(".jar")) {
156+
urls.add(file.toURI().toURL());
157+
}
158+
}
159+
}
160+
161+
private void addResources(File classesDirectory, List<Resource> resources, List<URL> urls) throws MalformedURLException {
162+
for (Resource resource : resources) {
163+
File directory = new File(resource.getDirectory());
164+
urls.add(directory.toURI().toURL());
165+
removeDuplicatesFromOutputDirectory(classesDirectory, directory);
166+
}
167+
}
168+
145169
private void removeDuplicatesFromOutputDirectory(File outputDirectory, File originDirectory) {
146170
if (originDirectory.isDirectory()) {
147171
String[] list = originDirectory.list();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.maven;
9+
10+
import org.apache.maven.plugin.MojoExecutionException;
11+
import org.apache.maven.plugin.MojoFailureException;
12+
import org.apache.maven.plugins.annotations.Execute;
13+
import org.apache.maven.plugins.annotations.LifecyclePhase;
14+
import org.apache.maven.plugins.annotations.Mojo;
15+
import org.apache.maven.plugins.annotations.ResolutionScope;
16+
import org.seedstack.maven.runnables.ToolLauncherRunnable;
17+
18+
/**
19+
* Defines the crypt goal. This goal runs the crypt Seed tool which crypts the given argument using a key/pair in
20+
* the master keystore of the application.
21+
*/
22+
@Mojo(name = "crypt", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
23+
@Execute(phase = LifecyclePhase.PROCESS_CLASSES)
24+
public class CryptMojo extends AbstractExecutableMojo {
25+
@Override
26+
public void execute() throws MojoExecutionException, MojoFailureException {
27+
runnable = new ToolLauncherRunnable("crypt", getArgs(), getMonitor(), getLog());
28+
super.execute();
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.maven;
9+
10+
import org.apache.maven.plugin.MojoExecutionException;
11+
import org.apache.maven.plugin.MojoFailureException;
12+
import org.apache.maven.plugins.annotations.Execute;
13+
import org.apache.maven.plugins.annotations.LifecyclePhase;
14+
import org.apache.maven.plugins.annotations.Mojo;
15+
import org.apache.maven.plugins.annotations.ResolutionScope;
16+
import org.seedstack.maven.runnables.ToolLauncherRunnable;
17+
18+
/**
19+
* Defines the effective-config goal. This goal runs the effective-config Seed tool which dumps the effective configuration of
20+
* the application.
21+
*/
22+
@Mojo(name = "effective-config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
23+
@Execute(phase = LifecyclePhase.PROCESS_CLASSES)
24+
public class EffectiveConfigMojo extends AbstractExecutableMojo {
25+
@Override
26+
public void execute() throws MojoExecutionException, MojoFailureException {
27+
runnable = new ToolLauncherRunnable("effective-config", getArgs(), getMonitor(), getLog());
28+
super.execute();
29+
}
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (c) 2013-2016, The SeedStack authors <http://seedstack.org>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
package org.seedstack.maven;
9+
10+
import org.apache.maven.plugin.MojoExecutionException;
11+
import org.apache.maven.plugin.MojoFailureException;
12+
import org.apache.maven.plugins.annotations.Execute;
13+
import org.apache.maven.plugins.annotations.LifecyclePhase;
14+
import org.apache.maven.plugins.annotations.Mojo;
15+
import org.apache.maven.plugins.annotations.ResolutionScope;
16+
import org.seedstack.maven.runnables.ToolLauncherRunnable;
17+
18+
/**
19+
* Defines the effective-test-config goal. This goal runs the effective-config Seed tool with the test classpath,
20+
* which dumps the effective test configuration.
21+
*/
22+
@Mojo(name = "effective-test-config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST)
23+
@Execute(phase = LifecyclePhase.PROCESS_TEST_CLASSES)
24+
public class EffectiveTestConfigMojo extends AbstractExecutableMojo {
25+
public EffectiveTestConfigMojo() {
26+
enableTestMode();
27+
}
28+
29+
@Override
30+
public void execute() throws MojoExecutionException, MojoFailureException {
31+
runnable = new ToolLauncherRunnable("effective-config", getArgs(), getMonitor(), getLog());
32+
super.execute();
33+
}
34+
}

src/main/java/org/seedstack/maven/GenerateMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
package org.seedstack.maven;
99

10-
import edu.emory.mathcs.backport.java.util.Collections;
1110
import org.apache.commons.lang.StringUtils;
1211
import org.apache.maven.archetype.ArchetypeManager;
1312
import org.apache.maven.archetype.catalog.Archetype;
@@ -26,6 +25,7 @@
2625
import org.seedstack.maven.components.ArtifactResolver;
2726

2827
import java.util.ArrayList;
28+
import java.util.Collections;
2929
import java.util.HashSet;
3030
import java.util.Set;
3131

0 commit comments

Comments
 (0)