Skip to content

Commit 9ae5c5e

Browse files
author
Vincent Potucek
committed
chore: apply SOC to have single AbstractMojo#createFile(File)
1 parent 77ebd14 commit 9ae5c5e

22 files changed

Lines changed: 34 additions & 247 deletions

File tree

compat/maven-plugin-api/src/main/java/org/apache/maven/plugin/AbstractMojo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.maven.plugin;
2020

21+
import java.io.File;
22+
import java.io.IOException;
2123
import java.util.Map;
2224

2325
import org.apache.maven.plugin.logging.Log;
@@ -176,6 +178,17 @@ public Log getLog() {
176178
return log;
177179
}
178180

181+
protected void createFile(File file) throws MojoExecutionException {
182+
getLog().info("Create file: " + file);
183+
if (file.getParentFile().mkdirs()) {
184+
try {
185+
file.createNewFile();
186+
} catch (IOException e) {
187+
throw new MojoExecutionException(e);
188+
}
189+
}
190+
}
191+
179192
@Override
180193
public Map getPluginContext() {
181194
return pluginContext;

its/core-it-suite/src/test/resources/mng-0870/plugin/src/main/java/org/apache/maven/plugin/coreit/LoadMojo.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
*/
3939

4040
import java.io.File;
41-
import java.io.IOException;
4241
import java.net.URL;
4342

4443
import org.apache.maven.plugin.AbstractMojo;
@@ -81,14 +80,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
8180
if (url == null) {
8281
throw new MojoExecutionException("Resource was not found, incomplete plugin class realm");
8382
}
84-
85-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + file);
86-
87-
try {
88-
file.getParentFile().mkdirs();
89-
file.createNewFile();
90-
} catch (IOException e) {
91-
throw new MojoExecutionException("Output file could not be created: " + file, e);
92-
}
83+
createFile(file);
9384
}
9485
}

its/core-it-suite/src/test/resources/mng-1088/plugin/src/main/java/org/apache/maven/plugin/coreit/TouchMojo.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
*/
3939

4040
import java.io.File;
41-
import java.io.IOException;
4241

4342
import org.apache.maven.plugin.AbstractMojo;
4443
import org.apache.maven.plugin.MojoExecutionException;
@@ -66,13 +65,6 @@ public class TouchMojo extends AbstractMojo {
6665
* @throws MojoExecutionException If the output file could not be created.
6766
*/
6867
public void execute() throws MojoExecutionException {
69-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + file);
70-
71-
try {
72-
file.getParentFile().mkdirs();
73-
file.createNewFile();
74-
} catch (IOException e) {
75-
throw new MojoExecutionException("Output file could not be created: " + file, e);
76-
}
68+
createFile(file);
7769
}
7870
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-clean-plugin/src/main/java/org/apache/maven/plugin/coreit/CleanMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/coreit/CompileMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/coreit/TestCompileMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/coreit/DeployMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-ear-plugin/src/main/java/org/apache/maven/plugin/coreit/EarMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-ear-plugin/src/main/java/org/apache/maven/plugin/coreit/GenerateApplicationXmlMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/coreit/EjbMojo.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugin.coreit;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322

2423
import org.apache.maven.plugin.AbstractMojo;
2524
import org.apache.maven.plugin.MojoExecutionException;
@@ -69,16 +68,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6968
if (!outputFile.isAbsolute()) {
7069
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7170
}
72-
73-
getLog().info("[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile);
74-
75-
try {
76-
outputFile.getParentFile().mkdirs();
77-
outputFile.createNewFile();
78-
} catch (IOException e) {
79-
throw new MojoExecutionException("Output file could not be created: " + pathname, e);
80-
}
81-
82-
getLog().info("[MAVEN-CORE-IT-LOG] Created output file: " + outputFile);
71+
createFile(outputFile);
8372
}
8473
}

0 commit comments

Comments
 (0)