Skip to content

Commit 00f2dc6

Browse files
committed
Improved reloading again
1 parent 820ad3e commit 00f2dc6

File tree

11 files changed

+141
-130
lines changed

11 files changed

+141
-130
lines changed

pom.xml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<packaging>maven-plugin</packaging>
2424

2525
<properties>
26-
<maven.version>3.1</maven.version>
26+
<maven.version>3.3</maven.version>
2727
<plexus-component.version>1.6</plexus-component.version>
2828
<maven.compiler.source>1.7</maven.compiler.source>
2929
<maven.compiler.target>1.7</maven.compiler.target>
@@ -80,7 +80,8 @@
8080
<licenseMerge>BSD|BSD 3-Clause License</licenseMerge>
8181
<licenseMerge>BSD|BSD style modified by Coverity</licenseMerge>
8282
<licenseMerge>BSD|The BSD License</licenseMerge>
83-
<licenseMerge>CDDL 1.0|COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0</licenseMerge>
83+
<licenseMerge>CDDL 1.0|COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
84+
</licenseMerge>
8485
<licenseMerge>CPL 1.0|Common Public License Version 1.0</licenseMerge>
8586
<licenseMerge>EPL 1.0|Eclipse Public License, Version 1.0</licenseMerge>
8687
<licenseMerge>EPL 1.0|Eclipse Public License - Version 1.0</licenseMerge>
@@ -93,7 +94,7 @@
9394
<plugin>
9495
<groupId>org.apache.maven.plugins</groupId>
9596
<artifactId>maven-plugin-plugin</artifactId>
96-
<version>${maven.version}</version>
97+
<version>3.5</version>
9798
<configuration>
9899
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
99100
</configuration>
@@ -146,6 +147,16 @@
146147
<artifactId>jline</artifactId>
147148
<version>2.14.5</version>
148149
</dependency>
150+
<dependency>
151+
<groupId>commons-collections</groupId>
152+
<artifactId>commons-collections</artifactId>
153+
<version>3.2.2</version>
154+
</dependency>
155+
<dependency>
156+
<groupId>com.google.guava</groupId>
157+
<artifactId>guava</artifactId>
158+
<version>18.0</version>
159+
</dependency>
149160
</dependencies>
150161
</dependencyManagement>
151162

@@ -184,7 +195,7 @@
184195
<dependency>
185196
<groupId>org.eclipse.aether</groupId>
186197
<artifactId>aether-util</artifactId>
187-
<version>0.9.0.M2</version>
198+
<version>1.0.2.v20150114</version>
188199
</dependency>
189200
<dependency>
190201
<groupId>org.twdata.maven</groupId>
@@ -205,25 +216,25 @@
205216
<dependency>
206217
<groupId>org.apache.maven</groupId>
207218
<artifactId>maven-core</artifactId>
208-
<version>${maven.version}.0</version>
219+
<version>${maven.version}.9</version>
209220
<scope>provided</scope>
210221
</dependency>
211222
<dependency>
212223
<groupId>org.apache.maven</groupId>
213224
<artifactId>maven-model</artifactId>
214-
<version>${maven.version}.0</version>
225+
<version>${maven.version}.9</version>
215226
<scope>provided</scope>
216227
</dependency>
217228
<dependency>
218229
<groupId>org.apache.maven</groupId>
219230
<artifactId>maven-plugin-api</artifactId>
220-
<version>${maven.version}.0</version>
231+
<version>${maven.version}.9</version>
221232
<scope>provided</scope>
222233
</dependency>
223234
<dependency>
224235
<groupId>org.apache.maven</groupId>
225236
<artifactId>maven-artifact</artifactId>
226-
<version>${maven.version}.0</version>
237+
<version>${maven.version}.9</version>
227238
<scope>provided</scope>
228239
</dependency>
229240
<dependency>
@@ -252,9 +263,9 @@
252263
<version>${jackson.version}</version>
253264
</dependency>
254265
<dependency>
255-
<groupId>asm</groupId>
266+
<groupId>org.ow2.asm</groupId>
256267
<artifactId>asm</artifactId>
257-
<version>3.3.1</version>
268+
<version>6.0</version>
258269
</dependency>
259270
<dependency>
260271
<groupId>org.eclipse.jetty</groupId>

src/license/THIRD-PARTY.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
# Please fill the missing licenses for dependencies :
1414
#
1515
#
16-
#Wed Nov 29 22:13:09 CET 2017
16+
#Thu Nov 30 15:58:46 CET 2017
1717
classworlds--classworlds--1.1-alpha-2=
18-
commons-collections--commons-collections--3.1=
1918
dom4j--dom4j--1.6.1=
2019
jdom--jdom--1.0=
2120
org.codehaus.plexus--plexus-component-api--1.0-alpha-16=
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
9+
package org.seedstack.maven;
10+
11+
class RefreshException extends Exception {
12+
public RefreshException() {
13+
}
14+
15+
public RefreshException(String message) {
16+
super(message);
17+
}
18+
19+
public RefreshException(String message, Throwable cause) {
20+
super(message, cause);
21+
}
22+
}

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

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,40 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.maven;
910

11+
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
12+
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
13+
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
14+
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
15+
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
16+
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
17+
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
18+
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
19+
20+
import java.io.File;
21+
import java.util.ArrayList;
22+
import java.util.HashMap;
23+
import java.util.LinkedHashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Set;
27+
import java.util.TreeSet;
1028
import org.apache.maven.execution.MavenSession;
1129
import org.apache.maven.model.Dependency;
1230
import org.apache.maven.model.Profile;
13-
import org.apache.maven.plugin.AbstractMojo;
1431
import org.apache.maven.plugin.BuildPluginManager;
1532
import org.apache.maven.plugin.MojoExecutionException;
1633
import org.apache.maven.plugin.MojoFailureException;
1734
import org.apache.maven.plugins.annotations.Component;
1835
import org.apache.maven.plugins.annotations.Mojo;
36+
import org.apache.maven.plugins.annotations.Parameter;
1937
import org.apache.maven.project.DefaultProjectBuildingRequest;
2038
import org.apache.maven.project.MavenProject;
2139
import org.apache.maven.project.ProjectBuilder;
2240
import org.apache.maven.project.ProjectBuildingException;
2341

24-
import java.io.File;
25-
import java.util.ArrayList;
26-
import java.util.HashMap;
27-
import java.util.LinkedHashMap;
28-
import java.util.List;
29-
import java.util.Map;
30-
import java.util.Set;
31-
import java.util.TreeSet;
32-
33-
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
34-
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
35-
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
36-
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
37-
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
38-
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
39-
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
40-
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
41-
4242
/**
4343
* Release the project simply by stripping the -SNAPSHOT part of the version.
4444
* Useful in continuous delivery pipelines.
@@ -47,49 +47,50 @@
4747
*/
4848
@Mojo(name = "release", requiresProject = true, threadSafe = false, aggregator = true)
4949
public class ReleaseMojo extends AbstractSeedStackMojo {
50-
public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
51-
52-
@Component
53-
private MavenProject executionMavenProject;
54-
55-
@Component
50+
private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
51+
@Parameter(defaultValue = "${project}", readonly = true)
52+
private MavenProject mavenProject;
53+
@Parameter(defaultValue = "${session}", readonly = true)
5654
private MavenSession mavenSession;
57-
5855
@Component
5956
private BuildPluginManager buildPluginManager;
60-
6157
@Component
6258
private ProjectBuilder projectBuilder;
6359

6460
@Override
6561
public void execute() throws MojoExecutionException, MojoFailureException {
66-
String currentVersion = executionMavenProject.getVersion();
62+
String currentVersion = mavenProject.getVersion();
6763

68-
if (isProjectDirty(getReactorModules("", executionMavenProject))) {
69-
throw new MojoFailureException("Cannot continue, a POM transformation is already in progress, commit and revert it before executing the release goal");
64+
if (isProjectDirty(getReactorModules("", mavenProject))) {
65+
throw new MojoFailureException(
66+
"Cannot continue, a POM transformation is already in progress, commit and revert it before " +
67+
"executing the release goal");
7068
}
7169

72-
if (!executionMavenProject.equals(getLocalRoot(executionMavenProject))) {
73-
throw new MojoFailureException("Cannot continue, release goal must be executed from the local project root");
70+
if (!mavenProject.equals(getLocalRoot(mavenProject))) {
71+
throw new MojoFailureException("Cannot continue, release goal must be executed from the local project " +
72+
"root");
7473
}
7574

7675
if (!currentVersion.endsWith(SNAPSHOT_SUFFIX)) {
7776
throw new MojoFailureException("Cannot continue, project version is not a SNAPSHOT");
7877
}
7978

80-
if (executionMavenProject.hasParent() && executionMavenProject.getParent().getVersion().endsWith(SNAPSHOT_SUFFIX)) {
79+
if (mavenProject.hasParent() && mavenProject.getParent()
80+
.getVersion()
81+
.endsWith(SNAPSHOT_SUFFIX)) {
8182
throw new MojoFailureException("Cannot continue, parent project is still a SNAPSHOT");
8283
}
8384

8485
String newVersion = currentVersion.substring(0, currentVersion.length() - SNAPSHOT_SUFFIX.length());
8586
getLog().info("SNAPSHOT version found, setting release version to " + newVersion);
86-
executionMavenProject.getProperties().setProperty("newVersion", newVersion);
87-
executeVersionsPlugin("set", executionMavenProject);
87+
mavenProject.getProperties().setProperty("newVersion", newVersion);
88+
executeVersionsPlugin("set", mavenProject);
8889

8990
boolean shouldRevert = false;
9091
List<MavenProject> transformedModules = new ArrayList<>();
91-
transformedModules.add(executionMavenProject);
92-
transformedModules.addAll(getReactorModules("", executionMavenProject).values());
92+
transformedModules.add(mavenProject);
93+
transformedModules.addAll(getReactorModules("", mavenProject).values());
9394
getLog().info("Checking transformed modules");
9495
for (MavenProject transformedModule : transformedModules) {
9596
try {
@@ -127,17 +128,22 @@ private void commitModule(MavenProject mavenProject) throws MojoExecutionExcepti
127128
}
128129

129130
private void checkModule(MavenProject mavenProject) throws MojoFailureException {
130-
Map<String, Dependency> snapshotDependencies = new HashMap<String, Dependency>();
131+
Map<String, Dependency> snapshotDependencies = new HashMap<>();
131132
for (Dependency dependency : mavenProject.getDependencies()) {
132133
if (dependency.getVersion().endsWith(SNAPSHOT_SUFFIX)) {
133134
snapshotDependencies.put(mavenProject.getArtifactId(), dependency);
134135
}
135136
}
136137

137138
if (!snapshotDependencies.isEmpty()) {
138-
StringBuilder sb = new StringBuilder("Cannot continue, there are still SNAPSHOT dependencies in the project:\n");
139+
StringBuilder sb = new StringBuilder(
140+
"Cannot continue, there are still SNAPSHOT dependencies in the project:\n");
139141
for (Map.Entry<String, Dependency> dependencyEntry : snapshotDependencies.entrySet()) {
140-
sb.append("\t* ").append(dependencyEntry.getKey()).append(": ").append(dependencyEntry.getValue().getManagementKey()).append("\n");
142+
sb.append("\t* ")
143+
.append(dependencyEntry.getKey())
144+
.append(": ")
145+
.append(dependencyEntry.getValue().getManagementKey())
146+
.append("\n");
141147
}
142148

143149
throw new MojoFailureException(sb.toString());
@@ -180,8 +186,8 @@ private Map<String, MavenProject> getReactorModules(String path, MavenProject pr
180186
path += '/';
181187
}
182188

183-
Map<String, MavenProject> result = new LinkedHashMap<String, MavenProject>();
184-
Map<String, MavenProject> childResults = new LinkedHashMap<String, MavenProject>();
189+
Map<String, MavenProject> result = new LinkedHashMap<>();
190+
Map<String, MavenProject> childResults = new LinkedHashMap<>();
185191

186192
Set<String> childModules = getChildModules(project);
187193
for (String moduleName : childModules) {
@@ -211,9 +217,8 @@ private Map<String, MavenProject> getReactorModules(String path, MavenProject pr
211217
return result;
212218
}
213219

214-
215220
private Set<String> getChildModules(MavenProject mavenProject) {
216-
Set<String> childModules = new TreeSet<String>();
221+
Set<String> childModules = new TreeSet<>();
217222
childModules.addAll(mavenProject.getModules());
218223
for (Profile profile : mavenProject.getModel().getProfiles()) {
219224
childModules.addAll(profile.getModules());
@@ -246,7 +251,7 @@ private MavenProject getLocalRoot(MavenProject project) {
246251
private MavenProject buildProject(File moduleProjectFile) throws ProjectBuildingException {
247252
DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest();
248253
request.setSystemProperties(System.getProperties());
249-
request.setRepositorySession(executionMavenProject.getProjectBuildingRequest().getRepositorySession());
254+
request.setRepositorySession(mavenProject.getProjectBuildingRequest().getRepositorySession());
250255
return projectBuilder.build(moduleProjectFile, request).getProject();
251256
}
252257
}

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import java.lang.reflect.InvocationTargetException;
1212
import java.lang.reflect.Method;
13-
import org.apache.maven.plugin.MojoExecutionException;
1413

1514
/**
1615
* SeedStack utils.
@@ -35,11 +34,11 @@ public static Object getSeedLauncher() throws Exception {
3534
}
3635
return getLauncherMethod.invoke(null);
3736
} catch (Exception e) {
38-
throw new MojoExecutionException("Cannot launch SeedStack application", unwrapException(e));
37+
throw unwrapException(e);
3938
}
4039
}
4140

42-
public static Object getToolLauncher(String tool) throws MojoExecutionException {
41+
public static Object getToolLauncher(String tool) throws Exception {
4342
try {
4443
Method getLauncherMethod;
4544
try {
@@ -51,7 +50,7 @@ public static Object getToolLauncher(String tool) throws MojoExecutionException
5150
}
5251
return getLauncherMethod.invoke(null, tool);
5352
} catch (Exception e) {
54-
throw new MojoExecutionException("Cannot launch SeedStack tool", unwrapException(e));
53+
throw unwrapException(e);
5554
}
5655
}
5756

@@ -60,8 +59,7 @@ public static void launch(Object seedLauncher, String[] args) throws Exception {
6059
Method launchMethod = seedLauncher.getClass().getMethod("launch", String[].class);
6160
launchMethod.invoke(seedLauncher, new Object[]{args});
6261
} catch (Exception e) {
63-
throw new MojoExecutionException("Cannot launch SeedStack application", unwrapException(e));
64-
62+
throw unwrapException(e);
6563
}
6664
}
6765

@@ -70,7 +68,7 @@ public static void shutdown(Object seedLauncher) throws Exception {
7068
Method shutdownMethod = seedLauncher.getClass().getMethod("shutdown");
7169
shutdownMethod.invoke(seedLauncher);
7270
} catch (Exception e) {
73-
throw new MojoExecutionException("Cannot shutdown SeedStack application", unwrapException(e));
71+
throw unwrapException(e);
7472
}
7573
}
7674

@@ -79,22 +77,23 @@ public static void refresh(Object seedLauncher) throws Exception {
7977
try {
8078
refreshMethod = seedLauncher.getClass().getMethod("refresh");
8179
} catch (NoSuchMethodException e) {
82-
throw new MojoExecutionException("Application refresh is not supported before Seed 3.4.0", e);
80+
throw new RuntimeException("Application refresh is not supported before Seed 3.4.0", e);
8381
}
8482
try {
8583
refreshMethod.invoke(seedLauncher);
8684
} catch (Exception e) {
87-
throw new MojoExecutionException("Unable to refresh SeedStack application", unwrapException(e));
85+
throw unwrapException(e);
8886
}
8987
}
9088

91-
private static Throwable unwrapException(Exception e) {
92-
Throwable t;
93-
if (e instanceof InvocationTargetException) {
94-
t = ((InvocationTargetException) e).getTargetException();
89+
private static Exception unwrapException(Exception e) {
90+
Exception unwrapped;
91+
if (e instanceof InvocationTargetException
92+
&& ((InvocationTargetException) e).getTargetException() instanceof Exception) {
93+
unwrapped = (Exception) ((InvocationTargetException) e).getTargetException();
9594
} else {
96-
t = e;
95+
unwrapped = e;
9796
}
98-
return t;
97+
return unwrapped;
9998
}
10099
}

0 commit comments

Comments
 (0)