diff --git a/README.md b/README.md index 79f2d05..6e99a55 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,23 @@ mvn archetype:generate \ -DarchetypeVersion=1.0.0-SNAPSHOT ``` +Then provide values for the parameters prompted for, such as group and artifact id of the project to be generated. + +Alternatively, use the non-interactive ("batch") mode and provide all the values like so: + +```shell +mvn archetype:generate -B \ + -DarchetypeGroupId=org.moditect.ossquickstart \ + -DarchetypeArtifactId=oss-quickstart-archetype-simple \ + -DarchetypeVersion=1.0.0-SNAPSHOT \ + -DgroupId=com.example.demos \ + -DartifactId=fancy-project \ + -Dversion=1.0.0-SNAPSHOT \ + -DmoduleName=com.example.fancy +``` + +Use the special value `NONE` for `moduleName` if you don't want generate a _module-info.java_ file. + ## Components * _oss-quickstart-archetype-simple_: A Maven archetype for creating a single module project following best practices diff --git a/oss-quickstart-archetype-simple/src/main/resources/META-INF/archetype-post-generate.groovy b/oss-quickstart-archetype-simple/src/main/resources/META-INF/archetype-post-generate.groovy index e21ddde..0057263 100644 --- a/oss-quickstart-archetype-simple/src/main/resources/META-INF/archetype-post-generate.groovy +++ b/oss-quickstart-archetype-simple/src/main/resources/META-INF/archetype-post-generate.groovy @@ -1,3 +1,16 @@ file = new File( request.getOutputDirectory(), request.getArtifactId()+"/.gitignore.tmpl" ); def gitIgnorefile = new File( request.getOutputDirectory(), request.getArtifactId()+"/.gitignore" ); -file.renameTo(gitIgnorefile) \ No newline at end of file +file.renameTo(gitIgnorefile) + +moduleName = request.getProperties().get("moduleName"); + +// module-info.java gets moved into the package of the application; move it back to src/main/java +if (moduleName == null || moduleName.equals("NONE")) { + moduleInfoFile = new File( request.getOutputDirectory(), request.getArtifactId() + "/src/main/java/" + request.getPackage().replaceAll("\\.", "/") + "/module-info.java" ); + moduleInfoFile.delete(); +} +else { + moduleInfoFile = new File( request.getOutputDirectory(), request.getArtifactId() + "/src/main/java/" + request.getPackage().replaceAll("\\.", "/") + "/module-info.java" ); + def moduleInfoFileNew = new File( request.getOutputDirectory(), request.getArtifactId()+"/src/main/java/module-info.java" ); + moduleInfoFile.renameTo(moduleInfoFileNew) +} diff --git a/oss-quickstart-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml b/oss-quickstart-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml index 6049dba..df25c77 100644 --- a/oss-quickstart-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/oss-quickstart-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -2,6 +2,13 @@ + + + + NONE + + + src/main/java diff --git a/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/main/java/module-info.java b/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/main/java/module-info.java new file mode 100644 index 0000000..f325cc6 --- /dev/null +++ b/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/main/java/module-info.java @@ -0,0 +1,21 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * Copyright 2021 The original authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +module ${moduleName} { + exports ${package}; +} diff --git a/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java b/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java index 9f454fa..4d09a40 100644 --- a/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java +++ b/oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -25,7 +25,7 @@ public class AppTest { @Test - void helloShouldReturnName() { + public void helloShouldReturnName() { App app = new App(); assertThat(app.hello("Bob")).isEqualTo("Hello, Bob"); } diff --git a/oss-quickstart-archetype-simple/src/test/resources/projects/basic/archetype.properties b/oss-quickstart-archetype-simple/src/test/resources/projects/basic/archetype.properties index 0c91926..0cef2ea 100644 --- a/oss-quickstart-archetype-simple/src/test/resources/projects/basic/archetype.properties +++ b/oss-quickstart-archetype-simple/src/test/resources/projects/basic/archetype.properties @@ -3,3 +3,4 @@ package=it.pkg groupId=archetype.it artifactId=basic version=0.1-SNAPSHOT +moduleName=NONE diff --git a/oss-quickstart-template-simple/src/main/java/module-info.java b/oss-quickstart-template-simple/src/main/java/module-info.java new file mode 100644 index 0000000..cd15040 --- /dev/null +++ b/oss-quickstart-template-simple/src/main/java/module-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2021 The original authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +module com.example.acme { + exports com.example.acme; +} diff --git a/oss-quickstart-template-simple/src/test/java/com/example/acme/AppTest.java b/oss-quickstart-template-simple/src/test/java/com/example/acme/AppTest.java index f5c510a..7d75835 100644 --- a/oss-quickstart-template-simple/src/test/java/com/example/acme/AppTest.java +++ b/oss-quickstart-template-simple/src/test/java/com/example/acme/AppTest.java @@ -22,7 +22,7 @@ public class AppTest { @Test - void helloShouldReturnName() { + public void helloShouldReturnName() { App app = new App(); assertThat(app.hello("Bob")).isEqualTo("Hello, Bob"); } diff --git a/update-from-templates.sh b/update-from-templates.sh index f7f6019..5b7379f 100755 --- a/update-from-templates.sh +++ b/update-from-templates.sh @@ -24,6 +24,9 @@ mvn archetype:create-from-project -f oss-quickstart-template-simple/pom.xml cp -r oss-quickstart-template-simple/target/generated-sources/archetype/src/main/resources/archetype-resources oss-quickstart-archetype-simple/src/main/resources rm -rf oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/main/java/com rm -rf oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/test/java/com +rm -rf oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/main/java/__packageInPathFormat__/ + +# Adjusting pom.xml # The archetype creation process drops the line-wrap after the license header in the pom.xml; adding this back # using gsed on macOS to have flag compatibility with gnu sed on Linux @@ -31,3 +34,9 @@ gsed -i 's/-->\nOSS.*<\/name>/My OSS Project<\/name>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml gsed -i 's/.*<\/description>/My Latest OSS Project<\/description>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml gsed -i 's/https.*<\/url>/tbd.<\/url>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml + +gsed -i 's/https.*<\/url>/tbd.<\/url>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml + +# Adjusting module-info.java + +gsed -i 's/module \${package}/module \${moduleName}/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/src/main/java/module-info.java