Skip to content

Commit 7a66c3e

Browse files
anurag.agslawekjaranowski
authored andcommitted
Add support for JEP 512 for for package-private static main methods with and without arguments
1 parent a6d01ef commit 7a66c3e

5 files changed

Lines changed: 120 additions & 0 deletions

File tree

src/test/java/org/codehaus/mojo/exec/ExecJavaMojoTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ public void testJSR512StaticMainNoArgs() throws Exception {
115115
assertEquals("Correct choice" + System.getProperty("line.separator"), output);
116116
}
117117

118+
public void testJSR512PackagePrivateStaticMainNoArgs() throws Exception {
119+
File pom = new File(getBasedir(), "src/test/projects/project27/pom.xml");
120+
121+
String output = execute(pom, "java");
122+
123+
assertEquals("Correct choice" + System.getProperty("line.separator"), output);
124+
}
125+
126+
public void testJSR512PackagePrivateStaticMainWithArgs() throws Exception {
127+
File pom = new File(getBasedir(), "src/test/projects/project28/pom.xml");
128+
129+
String output = execute(pom, "java");
130+
131+
assertEquals("Correct choice arg1 arg2" + System.getProperty("line.separator"), output);
132+
}
133+
118134
public void testJSR512FailureInstanceMainPrivateNoArgsConstructor() throws Exception {
119135
File pom = new File(getBasedir(), "src/test/projects/project25/pom.xml");
120136
try {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.codehaus.mojo.exec;
2+
3+
/**
4+
* Tests a main method that's not public, static, and has no parameters.
5+
*/
6+
public class JSR512DummyMain6 {
7+
static void main() {
8+
System.out.println("Correct choice");
9+
}
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.codehaus.mojo.exec;
2+
3+
/**
4+
* Tests a main method that's not public, static, and has parameters.
5+
*/
6+
public class JSR512DummyMain7 {
7+
static void main(String[] args) {
8+
StringBuilder buffer = new StringBuilder("Correct choice");
9+
10+
for (String arg : args) {
11+
buffer.append(" ").append(arg);
12+
}
13+
14+
System.out.println(buffer.toString());
15+
}
16+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.cb.maven.plugins.exec</groupId>
4+
<artifactId>project4</artifactId>
5+
<version>0.1</version>
6+
<packaging>jar</packaging>
7+
<name>Maven Exec Plugin</name>
8+
<inceptionYear>2005</inceptionYear>
9+
<licenses>
10+
<license>
11+
<name>Apache License 2</name>
12+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
13+
<distribution>repo</distribution>
14+
</license>
15+
</licenses>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.codehaus.mojo</groupId>
21+
<artifactId>exec-maven-plugin</artifactId>
22+
<executions>
23+
<execution>
24+
<phase>test</phase>
25+
<goals>
26+
<goal>java</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
<configuration>
31+
<mainClass>org.codehaus.mojo.exec.JSR512DummyMain6</mainClass>
32+
</configuration>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
37+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.cb.maven.plugins.exec</groupId>
4+
<artifactId>project4</artifactId>
5+
<version>0.1</version>
6+
<packaging>jar</packaging>
7+
<name>Maven Exec Plugin</name>
8+
<inceptionYear>2005</inceptionYear>
9+
<licenses>
10+
<license>
11+
<name>Apache License 2</name>
12+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
13+
<distribution>repo</distribution>
14+
</license>
15+
</licenses>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.codehaus.mojo</groupId>
21+
<artifactId>exec-maven-plugin</artifactId>
22+
<executions>
23+
<execution>
24+
<phase>test</phase>
25+
<goals>
26+
<goal>java</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
<configuration>
31+
<mainClass>org.codehaus.mojo.exec.JSR512DummyMain7</mainClass>
32+
<arguments>
33+
<argument>arg1</argument>
34+
<argument>arg2</argument>
35+
</arguments>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
41+
</project>

0 commit comments

Comments
 (0)