Skip to content

Commit ed24be1

Browse files
author
Vincent Potucek
committed
chore: singularize AbstractMojo#createFile(File)
1 parent 77ebd14 commit ed24be1

28 files changed

Lines changed: 127 additions & 247 deletions

File tree

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

Lines changed: 2 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;

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
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.coreit.component;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
24+
public interface MojoCompanion {
25+
26+
static void createFile(File file) {
27+
if (file.getParentFile().mkdirs()) {
28+
try {
29+
file.createNewFile();
30+
} catch (IOException e) {
31+
throw new RuntimeException(e);
32+
}
33+
}
34+
}
35+
}

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: 3 additions & 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;
@@ -29,6 +28,8 @@
2928
import org.apache.maven.plugins.annotations.Parameter;
3029
import org.apache.maven.project.MavenProject;
3130

31+
import static org.apache.maven.coreit.component.MojoCompanion.createFile;
32+
3233
/**
3334
* Creates a text file in the project base directory.
3435
*
@@ -69,16 +70,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6970
if (!outputFile.isAbsolute()) {
7071
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7172
}
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);
73+
createFile(outputFile);
8374
}
8475
}

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: 3 additions & 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;
@@ -29,6 +28,8 @@
2928
import org.apache.maven.plugins.annotations.Parameter;
3029
import org.apache.maven.project.MavenProject;
3130

31+
import static org.apache.maven.coreit.component.MojoCompanion.createFile;
32+
3233
/**
3334
* Creates a text file in the project base directory.
3435
*
@@ -69,16 +70,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6970
if (!outputFile.isAbsolute()) {
7071
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7172
}
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);
73+
createFile(outputFile);
8374
}
8475
}

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: 3 additions & 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;
@@ -29,6 +28,8 @@
2928
import org.apache.maven.plugins.annotations.Parameter;
3029
import org.apache.maven.project.MavenProject;
3130

31+
import static org.apache.maven.coreit.component.MojoCompanion.createFile;
32+
3233
/**
3334
* Creates a text file in the project base directory.
3435
*
@@ -69,16 +70,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6970
if (!outputFile.isAbsolute()) {
7071
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7172
}
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);
73+
createFile(outputFile);
8374
}
8475
}

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: 3 additions & 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;
@@ -29,6 +28,8 @@
2928
import org.apache.maven.plugins.annotations.Parameter;
3029
import org.apache.maven.project.MavenProject;
3130

31+
import static org.apache.maven.coreit.component.MojoCompanion.createFile;
32+
3233
/**
3334
* Creates a text file in the project base directory.
3435
*
@@ -69,16 +70,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6970
if (!outputFile.isAbsolute()) {
7071
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7172
}
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);
73+
createFile(outputFile);
8374
}
8475
}

its/core-it-support/core-it-plugins/maven-it-plugin-core-stubs/maven-ear-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ under the License.
5656
<artifactId>maven-compat</artifactId>
5757
<scope>provided</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>ch.qos.logback</groupId>
61+
<artifactId>logback-core</artifactId>
62+
<version>1.5.18</version>
63+
<scope>compile</scope>
64+
</dependency>
5965
</dependencies>
6066
</project>

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: 3 additions & 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;
@@ -29,6 +28,8 @@
2928
import org.apache.maven.plugins.annotations.Parameter;
3029
import org.apache.maven.project.MavenProject;
3130

31+
import static org.apache.maven.coreit.component.MojoCompanion.createFile;
32+
3233
/**
3334
* Creates a text file in the project base directory.
3435
*
@@ -69,16 +70,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6970
if (!outputFile.isAbsolute()) {
7071
outputFile = new File(project.getBasedir(), pathname).getAbsoluteFile();
7172
}
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);
73+
createFile(outputFile);
8374
}
8475
}

0 commit comments

Comments
 (0)