Skip to content

Commit

Permalink
feat(java17): generate groovy api extension compliant with Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
rbioteau committed Nov 23, 2023
1 parent 1619270 commit 93b1569
Show file tree
Hide file tree
Showing 33 changed files with 900 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
outputs:
app_version: ${{steps.get-app-version.outputs.APP_VERSION}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: get-app-version
name: Get archetype version
run: |
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install Java and Maven
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'temurin'
- name: Download latest archetype snapshot
uses: actions/download-artifact@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workflow-create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Java and Maven
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'temurin'

- name: Extract version
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "bonita-rest-api-extension-archetype",
"version": "1.6.2"
"version": "1.7.0"
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.bonitasoft.archetypes</groupId>
<artifactId>bonita-rest-api-extension-archetype</artifactId>
<version>1.6.2-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>Bonita Rest API extension Archetype</name>
<description>Maven archetype to bootstrap a Bonita Rest API extension project</description>
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/META-INF/archetype-post-generate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def logger = Logger.getLogger("Archetype post generate")
Path projectPath = Paths.get(request.outputDirectory, request.artifactId)
def language = request.properties.get("language")
def installWrapper = Boolean.valueOf(request.properties.get("wrapper"))
def bonitaVersion = request.properties.get('bonitaVersion')

if (isGroovy(language)) {
prepareGroovyProject(logger, projectPath)
Expand Down Expand Up @@ -160,6 +161,21 @@ project.build.plugins.find { it.artifactId == 'maven-assembly-plugin' }?.version
// Remove version for manage compiler plugin
project.build.plugins.find { it.artifactId == 'maven-compiler-plugin' }?.version = null

if(bonitaVersion
&& !bonitaVersion.startsWith('7.')
&& !bonitaVersion.startsWith('8.')
&& !bonitaVersion.startsWith('9.')) {
// Remove property define in parent
removeProperty(project, 'groovy-eclipse-compiler.version')
removeProperty(project, 'groovy-eclipse-batch.version')
// Remove compiler plugin
project.build.plugins.removeIf { it.artifactId == 'maven-compiler-plugin' }
// Remove groovy plugin repository already define in parent pom
project.pluginRepositories.removeIf { it.id == 'groovy' }

}


// Remove dependency management for bonita bom (should be in parent)
def bonitaBom = project.dependencyManagement.dependencies.find { it.artifactId == 'bonita-runtime-bom' }
if (bonitaBom != null) project.dependencyManagement.dependencies.remove(bonitaBom)
Expand Down
19 changes: 14 additions & 5 deletions src/main/resources/archetype-resources/README.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
#set( $bonitaVersionParts = $bonitaVersion.split('\.') )
#set( $shortBonitaVersion = $bonitaVersionParts.get(0) +'.'+ $bonitaVersionParts.get(1) )
#set( $after713 = $bonitaVersion.matches('7.(1[3-9]|[2-9][0-9]).*') || !$bonitaVersion.startsWith('7.') )
#if ( $bonitaVersion.lastIndexOf('.') != $bonitaVersion.indexOf('.'))
#set( $shortBonitaVersion = $bonitaVersion.substring(0, $bonitaVersion.lastIndexOf('.')) )
#if ( $shortBonitaVersion.lastIndexOf('.') != $shortBonitaVersion.indexOf('.'))
#set( $shortBonitaVersion = $shortBonitaVersion.substring(0, $shortBonitaVersion.lastIndexOf('.')) )
#end
#elseif ( $bonitaVersion.endsWith('-SNAPSHOT') )
#set( $shortBonitaVersion = $bonitaVersion.substring(0, $bonitaVersion.indexOf('-SNAPSHOT')) )
#else
#set( $shortBonitaVersion = $bonitaVersion )
#end
#set( $after713 = $bonitaVersion.matches('7.(1[3-5]).*') || !$bonitaVersion.startsWith('7.') )
#set( $after10 = !$bonitaVersion.startsWith('7.') && !$bonitaVersion.startsWith('8.') && !$bonitaVersion.startsWith('9.') )
:doctype: book
:toc: left
:toclevels: 3
Expand All @@ -18,8 +27,8 @@
:imagesdir: ./doc/images

:short-bonita-version: ${shortBonitaVersion}
:doc-url: https://documentation.bonitasoft.com/bonita/${shortBonitaVersion}
:java-version:#if( $after713 ) 11#else 1.8#end
:doc-url: https://documentation.bonitasoft.com/bonita/{short-bonita-version}
:java-version:#if( $after10 ) 17#elseif ( $after713 ) 11#else 1.8#end


image::yourlogo.png[your logo here]
Expand Down
35 changes: 26 additions & 9 deletions src/main/resources/archetype-resources/groovy-pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#set( $after713 = $bonitaVersion.matches('7.(1[3-9]|[2-9][0-9]).*') || !$bonitaVersion.startsWith('7.') )
#set( $after713 = $bonitaVersion.matches('7.(1[3-5]).*') || !$bonitaVersion.startsWith('7.') )
#set( $after10 = !$bonitaVersion.startsWith('7.') && !$bonitaVersion.startsWith('8.') && !$bonitaVersion.startsWith('9.'))
<?xml version="1.0" encoding="UTF-8"?>
<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">
Expand All @@ -12,7 +13,8 @@

<properties>
<!-- Maven -->
<java.version>#if( $after713 )
<java.version>#if( $after10 )
17#elseif ( $after713 )
11#else
8#end</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -33,15 +35,19 @@
2.3-groovy-3.0#else
1.3-groovy-2.4#end</spock-core.version>
<byte-buddy.version>1.14.5</byte-buddy.version>
<logback-classic.version>1.2.11</logback-classic.version>
<logback-classic.version>1.2.12</logback-classic.version>

<!-- Maven plugins -->
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
<maven.compiler.compilerId>groovy-eclipse-compiler</maven.compiler.compilerId>
<maven-assembly-plugin.version>3.6.0</maven-assembly-plugin.version>
<maven-surefire.version>3.1.0</maven-surefire.version>
<groovy-eclipse-compiler.version>3.7.0</groovy-eclipse-compiler.version>
<groovy-eclipse-batch.version>#if( $after713 )
<maven-surefire.version>3.2.2</maven-surefire.version>
<groovy-eclipse-compiler.version>#if( $after10 )
3.9.0#else
3.7.0#end</groovy-eclipse-compiler.version>
<groovy-eclipse-batch.version>#if( $after10 )
3.0.9-03#elseif ( $after713)
3.0.8-01#else
2.4.21-01#end</groovy-eclipse-batch.version>

Expand Down Expand Up @@ -163,9 +169,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
Expand Down Expand Up @@ -197,4 +200,18 @@
</plugin>
</plugins>
</build>
#if( $after10 )
<pluginRepositories>
<pluginRepository>
<id>groovy</id>
<url>https://groovy.jfrog.io/artifactory/plugins-release/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
#end
</project>
2 changes: 1 addition & 1 deletion src/main/resources/archetype-resources/kotlin-pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#set( $after713 = $bonitaVersion.matches('7.(1[3-9]|[2-9][0-9]).*') || !$bonitaVersion.startsWith('7.') )
#set( $after713 = $bonitaVersion.matches('7.(1[3-5]).*') || !$bonitaVersion.startsWith('7.') )
<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">
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#set( $after713 = $bonitaVersion.matches('7.(1[3-9]|[2-9][0-9]).*') || !$bonitaVersion.startsWith('7.') )
#set( $after713 = $bonitaVersion.matches('7.(1[3-5]).*') || !$bonitaVersion.startsWith('7.') )
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption

// Run 'mvn install' fisrt and then 'mvn groovy:execute -Dsource=target/test-classes/testGroovySubModuleProject/IT.groovy -Dscope=test' from project root

// Given
def sourcePath = '${project.basedir}/src/test/resources/testGroovySubModuleProjectPost10/'
def testPath = '${project.build.testOutputDirectory}/testGroovySubModuleProjectPost10/'
def sourceParentFolder = "${sourcePath}/module-parent"
def parentFolder = "${testPath}/module-parent"
def moduleArtifactId = "my-rest-api"


println "[Integration Test] Test generation of sub module ${moduleArtifactId} in folder ${parentFolder}"

// Delete previous run if any
def moduleFolder = new File("${parentFolder}/${moduleArtifactId}")
if (moduleFolder.exists()) {
Files.deleteIfExists(Paths.get("${parentFolder}/${moduleArtifactId}/pom.xml"))
moduleFolder.deleteDir()
// Reset the parent pom (whitout sub-module declaration)
Files.copy(Paths.get("${sourceParentFolder}/pom.xml"), Paths.get("${parentFolder}/pom.xml"), StandardCopyOption.REPLACE_EXISTING);
}

// When
println "Generate sub module ..."
def sout = new StringBuilder(), serr = new StringBuilder()
def proc = """mvn archetype:generate -B \
-DarchetypeGroupId=org.bonitasoft.archetypes \
-DarchetypeArtifactId=bonita-rest-api-extension-archetype \
-DarchetypeVersion=${project.version} \
-DgroupId=org.company.api \
-DartifactId=${moduleArtifactId} \
-Dversion=0.0.1-SNAPSHOT \
-Dlanguage=groovy \
-DbonitaVersion=10.0-SNAPSHOT \
-DapiName=myRestApi \
-DapiDisplayName=My-REST-API \
-DpathTemplate=my-rest-api \
-DurlParameters=p,c \
-DhttpVerb=GET
""".execute(null, new File(parentFolder))
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(10 * 60 * 1000)
println "out> $sout\nerr> $serr"

// Then
println "Verifying generation result ..."

assert proc.exitValue() == 0: "Maven archetype execution exit code should be 0"

def parentPomFile = new File("${parentFolder}/pom.xml")
assert parentPomFile.text.contains("<module>${moduleArtifactId}</module>"): 'Parent pom should declare project as sub module'

def modulePomFile = new File("${parentFolder}/${moduleArtifactId}/pom.xml")
def referencePomFile = new File("${testPath}/reference/pom.xml")
assert referencePomFile.text == modulePomFile.text: 'Reference pom and project pom should have the same content'

println "SUCCESS"


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:imagesdir: ./doc/images

:short-bonita-version: 7.10
:doc-url: https://documentation.bonitasoft.com/bonita/7.10
:doc-url: https://documentation.bonitasoft.com/bonita/{short-bonita-version}
:java-version: 1.8

image::yourlogo.png[your logo here]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
<!-- Test -->
<spock-core.version>1.3-groovy-2.4</spock-core.version>
<byte-buddy.version>1.14.5</byte-buddy.version>
<logback-classic.version>1.2.11</logback-classic.version>
<logback-classic.version>1.2.12</logback-classic.version>

<!-- Maven plugins -->
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
<maven.compiler.compilerId>groovy-eclipse-compiler</maven.compiler.compilerId>
<maven-assembly-plugin.version>3.6.0</maven-assembly-plugin.version>
<maven-surefire.version>3.1.0</maven-surefire.version>
<maven-surefire.version>3.2.2</maven-surefire.version>
<groovy-eclipse-compiler.version>3.7.0</groovy-eclipse-compiler.version>
<groovy-eclipse-batch.version>2.4.21-01</groovy-eclipse-batch.version>

Expand Down Expand Up @@ -118,9 +119,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
groupId=com.company.bonitasoft
artifactId=ds-rest-api
version=1.0.0-SNAPSHOT
package=com.company.bonitasoft
language=groovy
wrapper=false
sp=false
bonitaVersion=10.0.0
apiName=datasource
apiDisplayName=Datasource Rest API extension
apiDesc=A Rest API extension reading a datasource
httpVerb=GET
pathTemplate=datasource
permissionNames=customPermission1,customPermission2
urlParameters=userId,startDate
Empty file.
Loading

0 comments on commit 93b1569

Please sign in to comment.