Skip to content

Commit 507af6e

Browse files
committed
added IT test for action and preprocessor user function in maven plugin
1 parent cde50c2 commit 507af6e

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.igormaznitsa</groupId>
7+
<artifactId>jcp-test-maven-action</artifactId>
8+
<version>0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>jcp-test-maven-action-action</artifactId>
12+
<packaging>jar</packaging>
13+
14+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.igormaznitsa.jcp.it;
2+
3+
import com.igormaznitsa.jcp.context.PreprocessorContext;
4+
import com.igormaznitsa.jcp.expression.Value;
5+
import com.igormaznitsa.jcp.extension.PreprocessorExtension;
6+
import java.util.Arrays;
7+
8+
public class CustomPreprocessorExtension implements PreprocessorExtension {
9+
@Override
10+
public boolean processAction(PreprocessorContext context, Value[] parameters) {
11+
System.out.println("Called action for parameters: " + Arrays.toString(parameters));
12+
return true;
13+
}
14+
15+
@Override
16+
public int getUserFunctionArity(String functionName) {
17+
if (functionName.equals("hellofunc")) {
18+
return 1;
19+
} else {
20+
throw new IllegalArgumentException("Unexpected user function: " + functionName);
21+
}
22+
}
23+
24+
@Override
25+
public Value processUserFunction(
26+
PreprocessorContext context,
27+
String functionName,
28+
Value[] arguments) {
29+
if (functionName.equals("hellofunc")) {
30+
return Value.valueOf("Hello " + arguments[0].toString() + "!");
31+
} else {
32+
throw new IllegalArgumentException("Unexpected user function call: " + functionName);
33+
}
34+
}
35+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.igormaznitsa</groupId>
7+
<artifactId>jcp-test-maven-action</artifactId>
8+
<version>0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>jcp-test-maven-action-plugin-call</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>com.igormaznitsa</groupId>
18+
<artifactId>jcp</artifactId>
19+
<version>${jcp.test.version}</version>
20+
<configuration>
21+
<eol>\r\n</eol>
22+
</configuration>
23+
<executions>
24+
<execution>
25+
<id>preprocess-sources</id>
26+
<phase>generate-sources</phase>
27+
<goals>
28+
<goal>preprocess</goal>
29+
</goals>
30+
<configuration>
31+
<allowWhitespaces>true</allowWhitespaces>
32+
<eol>\r\n</eol>
33+
<extensions>
34+
<extension>java</extension>
35+
</extensions>
36+
<keepAttributes>true</keepAttributes>
37+
<keepComments>true</keepComments>
38+
<keepLines>true</keepLines>
39+
<actionPreprocessorExtension>com.igormaznitsa.jcp.it.CustomPreprocessorExtension
40+
</actionPreprocessorExtension>
41+
<sourceEncoding>UTF-8</sourceEncoding>
42+
<targetEncoding>UTF-8</targetEncoding>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
<dependencies>
47+
<dependency>
48+
<groupId>com.igormaznitsa</groupId>
49+
<artifactId>jcp-test-maven-action-action</artifactId>
50+
<version>${project.version}</version>
51+
</dependency>
52+
</dependencies>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.igormaznitsa.jcp.it;
2+
3+
public class Main {
4+
5+
public static void main(String ... args) {
6+
//#action "Huzzaa"
7+
System.out.println("Started");
8+
}
9+
10+
public static String makeHello() {
11+
return /*$"\""+$hellofunc("jcp")+"\";"$*/ /*-*/ "";
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.igormaznitsa.jcp.it;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
class MainTest {
7+
@Test
8+
void testMain() {
9+
Assertions.assertEquals("Hello jcp!", Main.makeHello());
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.igormaznitsa</groupId>
7+
<artifactId>jcp-tests</artifactId>
8+
<version>0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>jcp-test-maven-action</artifactId>
12+
<packaging>pom</packaging>
13+
14+
<modules>
15+
<module>jcp-test-maven-action-action</module>
16+
<module>jcp-test-maven-action-plugin-call</module>
17+
</modules>
18+
19+
</project>

jcp-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<modules>
2323
<module>jcp-test-ant</module>
2424
<module>jcp-test-maven</module>
25+
<module>jcp-test-maven-action</module>
2526
<module>jcp-test-static-site</module>
2627
<module>jcp-test-javassist</module>
2728
<module>jcp-test-gradle-5</module>

0 commit comments

Comments
 (0)