Skip to content

Commit

Permalink
added IT test for action and preprocessor user function in maven plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
raydac committed Jun 6, 2024
1 parent cde50c2 commit 507af6e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jcp-test-maven-action</artifactId>
<version>0-SNAPSHOT</version>
</parent>

<artifactId>jcp-test-maven-action-action</artifactId>
<packaging>jar</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.igormaznitsa.jcp.it;

import com.igormaznitsa.jcp.context.PreprocessorContext;
import com.igormaznitsa.jcp.expression.Value;
import com.igormaznitsa.jcp.extension.PreprocessorExtension;
import java.util.Arrays;

public class CustomPreprocessorExtension implements PreprocessorExtension {
@Override
public boolean processAction(PreprocessorContext context, Value[] parameters) {
System.out.println("Called action for parameters: " + Arrays.toString(parameters));
return true;
}

@Override
public int getUserFunctionArity(String functionName) {
if (functionName.equals("hellofunc")) {
return 1;
} else {
throw new IllegalArgumentException("Unexpected user function: " + functionName);
}
}

@Override
public Value processUserFunction(
PreprocessorContext context,
String functionName,
Value[] arguments) {
if (functionName.equals("hellofunc")) {
return Value.valueOf("Hello " + arguments[0].toString() + "!");
} else {
throw new IllegalArgumentException("Unexpected user function call: " + functionName);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jcp-test-maven-action</artifactId>
<version>0-SNAPSHOT</version>
</parent>

<artifactId>jcp-test-maven-action-plugin-call</artifactId>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>jcp</artifactId>
<version>${jcp.test.version}</version>
<configuration>
<eol>\r\n</eol>
</configuration>
<executions>
<execution>
<id>preprocess-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>preprocess</goal>
</goals>
<configuration>
<allowWhitespaces>true</allowWhitespaces>
<eol>\r\n</eol>
<extensions>
<extension>java</extension>
</extensions>
<keepAttributes>true</keepAttributes>
<keepComments>true</keepComments>
<keepLines>true</keepLines>
<actionPreprocessorExtension>com.igormaznitsa.jcp.it.CustomPreprocessorExtension
</actionPreprocessorExtension>
<sourceEncoding>UTF-8</sourceEncoding>
<targetEncoding>UTF-8</targetEncoding>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.igormaznitsa</groupId>
<artifactId>jcp-test-maven-action-action</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.igormaznitsa.jcp.it;

public class Main {

public static void main(String ... args) {
//#action "Huzzaa"
System.out.println("Started");
}

public static String makeHello() {
return /*$"\""+$hellofunc("jcp")+"\";"$*/ /*-*/ "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.igormaznitsa.jcp.it;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class MainTest {
@Test
void testMain() {
Assertions.assertEquals("Hello jcp!", Main.makeHello());
}
}
19 changes: 19 additions & 0 deletions jcp-tests/jcp-test-maven-action/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.igormaznitsa</groupId>
<artifactId>jcp-tests</artifactId>
<version>0-SNAPSHOT</version>
</parent>

<artifactId>jcp-test-maven-action</artifactId>
<packaging>pom</packaging>

<modules>
<module>jcp-test-maven-action-action</module>
<module>jcp-test-maven-action-plugin-call</module>
</modules>

</project>
1 change: 1 addition & 0 deletions jcp-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<modules>
<module>jcp-test-ant</module>
<module>jcp-test-maven</module>
<module>jcp-test-maven-action</module>
<module>jcp-test-static-site</module>
<module>jcp-test-javassist</module>
<module>jcp-test-gradle-5</module>
Expand Down

0 comments on commit 507af6e

Please sign in to comment.