Skip to content

Commit 1d01d3d

Browse files
committed
Autodetect cygwin, uninstall ansi
1 parent 3af43e8 commit 1d01d3d

File tree

5 files changed

+82
-27
lines changed

5 files changed

+82
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Version 2.6.4 (2017-10-19)
2+
3+
* [fix] Uninstall ansi console before exiting.
4+
* [new] Automatically switch to basic prompt under CYGWIN.
5+
16
# Version 2.6.3 (2017-10-19)
27

38
* [new] Add basic prompt mode (-DbasicPrompt) on generate goal, for the case where ConsoleUI doesn't work properly.

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.6.3-SNAPSHOT</version>
22+
<version>2.6.4-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
@@ -13,7 +13,7 @@
1313
# Please fill the missing licenses for dependencies :
1414
#
1515
#
16-
#Thu Oct 19 15:02:05 CEST 2017
16+
#Thu Oct 19 17:15:54 CEST 2017
1717
classworlds--classworlds--1.1-alpha-2=
1818
commons-collections--commons-collections--3.1=
1919
dom4j--dom4j--1.6.1=

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
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

1011
import org.apache.maven.plugin.AbstractMojo;
1112
import org.fusesource.jansi.AnsiConsole;
1213

13-
public abstract class AbstractSeedStackMojo extends AbstractMojo {
14+
abstract class AbstractSeedStackMojo extends AbstractMojo {
1415
static {
16+
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
17+
@Override
18+
public void run() {
19+
AnsiConsole.systemUninstall();
20+
}
21+
}, "uninstall-ansi"));
1522
AnsiConsole.systemInstall();
1623
}
1724
}

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

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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

1011
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
@@ -94,21 +95,29 @@ public class GenerateMojo extends AbstractSeedStackMojo {
9495

9596
@Override
9697
public void execute() throws MojoExecutionException, MojoFailureException {
97-
this.basicMode = !mavenSession.getUserProperties().getProperty("basicPrompt", "false").equals("false");
98+
if (mavenSession.getUserProperties().getProperty("basicPrompt") == null) {
99+
this.basicMode = autodetectBasicMode();
100+
} else {
101+
this.basicMode = !mavenSession.getUserProperties().getProperty("basicPrompt", "false").equals("false");
102+
}
98103
if (!basicMode) {
99-
getLog().info("Hint: if enhanced prompt has issues on your system, try basic prompt by adding \"-DbasicPrompt\" to your command line");
104+
getLog().info(
105+
"Hint: if enhanced prompt has issues on your system, try basic prompt by adding \"-DbasicPrompt\""
106+
+ " to your command line");
100107
}
101108

102109
String type = mavenSession.getUserProperties().getProperty("type"),
103-
distributionGroupId = mavenSession.getUserProperties().getProperty("distributionGroupId", "org.seedstack"),
104-
distributionArtifactId = mavenSession.getUserProperties().getProperty("distributionArtifactId", "distribution"),
110+
distributionGroupId = mavenSession.getUserProperties()
111+
.getProperty("distributionGroupId", "org.seedstack"),
112+
distributionArtifactId = mavenSession.getUserProperties()
113+
.getProperty("distributionArtifactId", "distribution"),
105114
version = mavenSession.getUserProperties().getProperty("version"),
106115
archetypeGroupId = mavenSession.getUserProperties().getProperty("archetypeGroupId"),
107116
archetypeArtifactId = mavenSession.getUserProperties().getProperty("archetypeArtifactId"),
108117
archetypeVersion = mavenSession.getUserProperties().getProperty("archetypeVersion"),
109118
remoteCatalog = mavenSession.getUserProperties().getProperty("remoteCatalog", SEEDSTACK_ORG);
110-
boolean allowSnapshots = !mavenSession.getUserProperties().getProperty("allowSnapshots", "false").equals("false");
111-
119+
boolean allowSnapshots = !mavenSession.getUserProperties().getProperty("allowSnapshots", "false")
120+
.equals("false");
112121

113122
if (StringUtils.isBlank(archetypeGroupId)) {
114123
archetypeGroupId = distributionGroupId;
@@ -118,13 +127,19 @@ public void execute() throws MojoExecutionException, MojoFailureException {
118127
if (StringUtils.isBlank(type)) {
119128
// Resolve archetype version using SeedStack highest version
120129
if (StringUtils.isBlank(archetypeVersion)) {
121-
getLog().info("Resolving latest " + (allowSnapshots ? "snapshot" : "release") + " of SeedStack (" + distributionGroupId + ")");
122-
archetypeVersion = artifactResolver.getHighestVersion(mavenProject, distributionGroupId, distributionArtifactId, allowSnapshots);
130+
getLog().info(
131+
"Resolving latest " + (allowSnapshots ? "snapshot" : "release") + " of SeedStack (" +
132+
distributionGroupId + ")");
133+
archetypeVersion = artifactResolver
134+
.getHighestVersion(mavenProject, distributionGroupId, distributionArtifactId,
135+
allowSnapshots);
123136
getLog().info("Resolved version " + archetypeVersion);
124137
}
125138
try {
126-
// We have a list of possible types, let the user choose (if a "web" choice exists, set it as default)
127-
List<Value> list = new ArrayList<>(findProjectTypes(archetypeGroupId, archetypeVersion, remoteCatalog));
139+
// We have a list of possible types, let the user choose (if a "web" choice exists, set it as
140+
// default)
141+
List<Value> list = new ArrayList<>(
142+
findProjectTypes(archetypeGroupId, archetypeVersion, remoteCatalog));
128143
Collections.sort(list);
129144
list.add(new Value("custom archetype", "custom"));
130145
type = getPrompter().promptList("Choose the project type", list, "web");
@@ -139,7 +154,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
139154
}
140155
// Ask for archetype version (defaults to latest)
141156
try {
142-
archetypeVersion = artifactResolver.getHighestVersion(mavenProject, archetypeGroupId, archetypeArtifactId, allowSnapshots);
157+
archetypeVersion = artifactResolver
158+
.getHighestVersion(mavenProject, archetypeGroupId, archetypeArtifactId,
159+
allowSnapshots);
143160
} catch (Exception e) {
144161
archetypeVersion = null;
145162
}
@@ -157,8 +174,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
157174

158175
// If needed, find the latest version of the archetype
159176
if (StringUtils.isBlank(archetypeVersion)) {
160-
getLog().info("Resolving latest " + (allowSnapshots ? "snapshot" : "release") + " of archetype " + archetypeGroupId + ":" + archetypeArtifactId);
161-
archetypeVersion = artifactResolver.getHighestVersion(mavenProject, archetypeGroupId, archetypeArtifactId, allowSnapshots);
177+
getLog().info(
178+
"Resolving latest " + (allowSnapshots ? "snapshot" : "release") + " of archetype " +
179+
archetypeGroupId + ":" + archetypeArtifactId);
180+
archetypeVersion = artifactResolver
181+
.getHighestVersion(mavenProject, archetypeGroupId, archetypeArtifactId, allowSnapshots);
162182
getLog().info("Resolved version " + archetypeVersion);
163183
}
164184

@@ -178,7 +198,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
178198
throw new MojoExecutionException("Generated project group id cannot be blank");
179199
}
180200
if (StringUtils.isBlank(artifactId)) {
181-
artifactId = getPrompter().promptInput("Generated project artifact id", "my-" + (StringUtils.isBlank(type) ? "" : type + "-") + "project");
201+
artifactId = getPrompter().promptInput("Generated project artifact id",
202+
"my-" + (StringUtils.isBlank(type) ? "" : type + "-") + "project");
182203
}
183204
if (StringUtils.isBlank(artifactId)) {
184205
throw new MojoExecutionException("Generated project artifact id cannot be blank");
@@ -192,14 +213,16 @@ public void execute() throws MojoExecutionException, MojoFailureException {
192213

193214
String pluginVersion;
194215
try {
195-
pluginVersion = artifactResolver.getHighestVersion(mavenProject, ARCHETYPE_PLUGIN_GROUP_ID, ARCHETYPE_PLUGIN_ARTIFACT_ID, false);
216+
pluginVersion = artifactResolver
217+
.getHighestVersion(mavenProject, ARCHETYPE_PLUGIN_GROUP_ID, ARCHETYPE_PLUGIN_ARTIFACT_ID, false);
196218
getLog().info("Using the latest version of archetype plugin: " + pluginVersion);
197219
} catch (Exception e) {
198220
getLog().warn("Unable to determine latest version of archetype plugin, falling back to 3.0.0");
199221
pluginVersion = "3.0.0";
200222
}
201223

202-
executeMojo(plugin(groupId(ARCHETYPE_PLUGIN_GROUP_ID), artifactId(ARCHETYPE_PLUGIN_ARTIFACT_ID), version(pluginVersion)),
224+
executeMojo(plugin(groupId(ARCHETYPE_PLUGIN_GROUP_ID), artifactId(ARCHETYPE_PLUGIN_ARTIFACT_ID),
225+
version(pluginVersion)),
203226

204227
goal("generate"),
205228

@@ -257,7 +280,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
257280
if (questionFile.exists() && questionFile.canRead()) {
258281
varsWithAnswers.putAll(getInquirer().inquire(questionFile.toURI().toURL()));
259282
if (!questionFile.delete()) {
260-
getLog().warn("Unable to delete question file, useless files may be still be present in project");
283+
getLog().warn(
284+
"Unable to delete question file, useless files may be still be present in project");
261285
}
262286
}
263287
} catch (MalformedURLException | InquirerException e) {
@@ -271,7 +295,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
271295
}
272296
}
273297

274-
private Thread setupInquiryCancelHook(final File projectDir, final File questionFile, final HashMap<String, Object> vars) {
298+
private Thread setupInquiryCancelHook(final File projectDir, final File questionFile,
299+
final HashMap<String, Object> vars) {
275300
Thread shutdownRender = new Thread(new Runnable() {
276301
@Override
277302
public void run() {
@@ -312,7 +337,8 @@ private void renderTemplates(File file, Map<String, Object> vars) {
312337
template.evaluate(stringWriter, vars);
313338
String renderedContent = stringWriter.toString();
314339
if (renderedContent.trim().length() > 0) {
315-
try (Writer writer = new OutputStreamWriter(new FileOutputStream(outputPath), StandardCharsets.UTF_8)) {
340+
try (Writer writer = new OutputStreamWriter(new FileOutputStream(outputPath),
341+
StandardCharsets.UTF_8)) {
316342
writer.write(renderedContent);
317343
}
318344
} else {
@@ -323,7 +349,8 @@ private void renderTemplates(File file, Map<String, Object> vars) {
323349
}
324350
if (!originalPath.equals(outputPath)) {
325351
if (!new File(originalPath).delete()) {
326-
getLog().warn("Unable to delete original file, useless files may be still be present in project");
352+
getLog().warn(
353+
"Unable to delete original file, useless files may be still be present in project");
327354
}
328355
}
329356
} catch (PebbleException | IOException e) {
@@ -347,18 +374,23 @@ private String processPath(String absolutePath, Map<String, Object> vars) {
347374
private Set<Value> findProjectTypes(String archetypeGroupId, String archetypeVersion, String remoteCatalog) {
348375
Set<Value> possibleTypes = new HashSet<>();
349376
getLog().info("Searching for " + archetypeVersion + " archetypes in remote catalog " + remoteCatalog);
350-
possibleTypes.addAll(findArchetypes(archetypeGroupId, archetypeVersion, archetypeManager.getRemoteCatalog(remoteCatalog)));
377+
possibleTypes.addAll(findArchetypes(archetypeGroupId, archetypeVersion,
378+
archetypeManager.getRemoteCatalog(remoteCatalog)));
351379

352380
if (possibleTypes.isEmpty()) {
353381
getLog().info("No remote " + archetypeVersion + " archetype found, trying the central catalog");
354-
possibleTypes.addAll(findArchetypes(archetypeGroupId, archetypeVersion, archetypeManager.getRemoteCatalog()));
382+
possibleTypes
383+
.addAll(findArchetypes(archetypeGroupId, archetypeVersion, archetypeManager.getRemoteCatalog()));
355384
}
356385
if (possibleTypes.isEmpty()) {
357386
getLog().info("No remote or central " + archetypeVersion + " archetype found, trying the local catalog");
358-
possibleTypes.addAll(findArchetypes(archetypeGroupId, archetypeVersion, archetypeManager.getDefaultLocalCatalog()));
387+
possibleTypes.addAll(findArchetypes(archetypeGroupId, archetypeVersion,
388+
archetypeManager.getDefaultLocalCatalog()));
359389
}
360390
if (possibleTypes.isEmpty()) {
361-
getLog().warn("No " + archetypeVersion + " archetype found anywhere (check your Maven proxy settings), falling back to hard-coded list");
391+
getLog().warn(
392+
"No " + archetypeVersion + " archetype found anywhere (check your Maven proxy settings), falling "
393+
+ "back to hard-coded list");
362394
possibleTypes.add(new Value("addon"));
363395
possibleTypes.add(new Value("batch"));
364396
possibleTypes.add(new Value("cli"));
@@ -397,4 +429,15 @@ private Inquirer getInquirer() {
397429
return fancyInquirer;
398430
}
399431
}
432+
433+
private boolean autodetectBasicMode() {
434+
String ostype = System.getenv("OSTYPE");
435+
if (ostype != null && !ostype.isEmpty()) {
436+
// Fancy mode never works under cygwin
437+
if (ostype.startsWith("cygwin")) {
438+
return true;
439+
}
440+
}
441+
return false;
442+
}
400443
}

0 commit comments

Comments
 (0)