Skip to content

Commit 0dec76d

Browse files
author
Vincent Potucek
committed
Add method AbstractMojo#mkDirForParentFile(File) central fix try can use automatic resource management
1 parent 9405b2b commit 0dec76d

12 files changed

Lines changed: 52 additions & 27 deletions

File tree

compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,13 @@ void initialize(CliRequest cliRequest) throws ExitException {
332332
} else if (Files.isRegularFile(path)) {
333333
topDirectory = path.getParent();
334334
if (!Files.isDirectory(topDirectory)) {
335-
slf4jLogger.error("Directory {} extracted from the -f/--file command-line argument {} does not exist", topDirectory, arg);
335+
System.err.println("Directory " + topDirectory
336+
+ " extracted from the -f/--file command-line argument " + arg + " does not exist");
336337
throw new ExitException(1);
337338
}
338339
} else {
339-
slf4jLogger.error("POM file {} specified with the -f/--file command line argument does not exist", arg);
340+
System.err.println(
341+
"POM file " + arg + " specified with the -f/--file command line argument does not exist");
340342
throw new ExitException(1);
341343
}
342344
break;
@@ -394,7 +396,7 @@ void cli(CliRequest cliRequest) throws Exception {
394396
}
395397
}
396398
} catch (ParseException e) {
397-
slf4jLogger.error("Unable to parse maven.config file options: {}", e.getMessage());
399+
System.err.println("Unable to parse maven.config file options: " + e.getMessage());
398400
cliManager.displayHelp(System.out);
399401
throw e;
400402
}
@@ -407,7 +409,7 @@ void cli(CliRequest cliRequest) throws Exception {
407409
cliRequest.commandLine = cliMerge(mavenConfig, mavenCli);
408410
}
409411
} catch (ParseException e) {
410-
slf4jLogger.error("Unable to parse command line options: {}", e.getMessage());
412+
System.err.println("Unable to parse command line options: " + e.getMessage());
411413
cliManager.displayHelp(System.out);
412414
throw e;
413415
}
@@ -421,9 +423,9 @@ private void informativeCommands(CliRequest cliRequest) throws ExitException {
421423

422424
if (cliRequest.commandLine.hasOption(CLIManager.VERSION)) {
423425
if (cliRequest.commandLine.hasOption(CLIManager.QUIET)) {
424-
slf4jLogger.info(CLIReportingUtils.showVersionMinimal());
426+
System.out.println(CLIReportingUtils.showVersionMinimal());
425427
} else {
426-
slf4jLogger.info(CLIReportingUtils.showVersion());
428+
System.out.println(CLIReportingUtils.showVersion());
427429
}
428430
throw new ExitException(0);
429431
}
@@ -593,7 +595,7 @@ void logging(CliRequest cliRequest) throws ExitException {
593595

594596
private void version(CliRequest cliRequest) {
595597
if (cliRequest.verbose || cliRequest.commandLine.hasOption(CLIManager.SHOW_VERSION)) {
596-
slf4jLogger.info(CLIReportingUtils.showVersion());
598+
System.out.println(CLIReportingUtils.showVersion());
597599
}
598600
}
599601

@@ -740,7 +742,7 @@ protected void configure() {
740742
container.lookup(Injector.class).discover(extension.getClassRealm());
741743
} catch (Throwable e) {
742744
// ignore
743-
slf4jLogger.error("Exception", e);
745+
e.printStackTrace();
744746
}
745747
}
746748
},
@@ -939,7 +941,7 @@ private List<File> parseExtClasspath(CliRequest cliRequest) {
939941
//
940942
private void encryption(CliRequest cliRequest) throws Exception {
941943
if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) {
942-
slf4jLogger.info("Master password encyption is not supported anymore");
944+
System.out.println("Master password encyption is not supported anymore");
943945
throw new ExitException(1);
944946
} else if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)) {
945947
String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_PASSWORD);
@@ -955,7 +957,7 @@ private void encryption(CliRequest cliRequest) throws Exception {
955957
java.util.Arrays.fill(password, ' ');
956958
}
957959
}
958-
slf4jLogger.info(dispatcher.encrypt(passwd, null));
960+
System.out.println(dispatcher.encrypt(passwd, null));
959961
throw new ExitException(0);
960962
}
961963
}

compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelData.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,15 @@ public void setVersion(String version) {
189189
* @return The effective identifier of the model, never {@code null}.
190190
*/
191191
public String getId() {
192-
return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
192+
StringBuilder buffer = new StringBuilder(128);
193+
194+
buffer.append(getGroupId())
195+
.append(':')
196+
.append(getArtifactId())
197+
.append(':')
198+
.append(getVersion());
199+
200+
return buffer.toString();
193201
}
194202

195203
@Override

compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ static String toId(Model model) {
9898
* @return The user-friendly artifact id, never {@code null}.
9999
*/
100100
static String toId(String groupId, String artifactId, String version) {
101-
return (groupId != null && !groupId.isEmpty() ? groupId : "[unknown-group-id]")
102-
+ ':'
103-
+ (artifactId != null && !artifactId.isEmpty() ? artifactId : "[unknown-artifact-id]")
104-
+ ':'
105-
+ (version != null && !version.isEmpty() ? version : "[unknown-version]");
101+
StringBuilder buffer = new StringBuilder(128);
102+
103+
buffer.append((groupId != null && groupId.length() > 0) ? groupId : "[unknown-group-id]");
104+
buffer.append(':');
105+
buffer.append((artifactId != null && artifactId.length() > 0) ? artifactId : "[unknown-artifact-id]");
106+
buffer.append(':');
107+
buffer.append((version != null && version.length() > 0) ? version : "[unknown-version]");
108+
109+
return buffer.toString();
106110
}
107111

108112
/**

its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/DumpRepoLayoutsMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
112112
if (out != null) {
113113
try {
114114
out.close();
115-
} catch (IOException ignore) {
115+
} catch (IOException e) {
116+
// just ignore
116117
}
117118
}
118119
}

its/core-it-support/core-it-plugins/maven-it-plugin-dependency-collection/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ protected void writeArtifacts(String pathname, Collection artifacts) throws Mojo
8787
if (writer != null) {
8888
try {
8989
writer.close();
90-
} catch (IOException ignore) {
90+
} catch (IOException e) {
91+
// just ignore
9192
}
9293
}
9394
}

its/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ protected void writeArtifacts(String pathname, Collection artifacts) throws Mojo
103103
if (writer != null) {
104104
try {
105105
writer.close();
106-
} catch (IOException ignore) {
106+
} catch (IOException e) {
107+
// just ignore
107108
}
108109
}
109110
}
@@ -151,7 +152,8 @@ protected void writeClassPath(String pathname, Collection classPath) throws Mojo
151152
if (writer != null) {
152153
try {
153154
writer.close();
154-
} catch (IOException ignore) {
155+
} catch (IOException e) {
156+
// just ignore
155157
}
156158
}
157159
}
@@ -209,7 +211,8 @@ protected void writeClassPathChecksums(String pathname, Collection classPath) th
209211
if (os != null) {
210212
try {
211213
os.close();
212-
} catch (IOException ignore) {
214+
} catch (IOException e) {
215+
// just ignore
213216
}
214217
}
215218
}

its/core-it-support/core-it-plugins/maven-it-plugin-expression/src/main/java/org/apache/maven/plugin/coreit/PropertyUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ public static void write(Properties props, File file) throws IOException {
191191
if (out != null) {
192192
try {
193193
out.close();
194-
} catch (IOException ignore) {
194+
} catch (IOException e) {
195+
// just ignore
195196
}
196197
}
197198
}

its/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
107107
if (out != null) {
108108
try {
109109
out.close();
110-
} catch (IOException ignore) {
110+
} catch (IOException e) {
111+
// just ignore
111112
}
112113
}
113114
}

its/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/ListMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
8484
if (out != null) {
8585
try {
8686
out.close();
87-
} catch (IOException ignore) {
87+
} catch (IOException e) {
88+
// just ignore
8889
}
8990
}
9091
}

its/core-it-support/core-it-plugins/maven-it-plugin-uses-wagon/src/main/java/org/apache/maven/plugin/coreit/DumpAuthMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
118118
if (out != null) {
119119
try {
120120
out.close();
121-
} catch (IOException ignore) {
121+
} catch (IOException e) {
122+
// just ignore
122123
}
123124
}
124125
}

0 commit comments

Comments
 (0)