Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<archetype-descriptor xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" name="oss-quickstart-template-simple"
xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<requiredProperties>
<requiredProperty key="moduleName">
<defaultValue>NONE</defaultValue>
</requiredProperty>
</requiredProperties>

<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class AppTest {

@Test
void helloShouldReturnName() {
public void helloShouldReturnName() {
App app = new App();
assertThat(app.hello("Bob")).isEqualTo("Hello, Bob");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package=it.pkg
groupId=archetype.it
artifactId=basic
version=0.1-SNAPSHOT
moduleName=NONE
18 changes: 18 additions & 0 deletions oss-quickstart-template-simple/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class AppTest {

@Test
void helloShouldReturnName() {
public void helloShouldReturnName() {
App app = new App();
assertThat(app.hello("Bob")).isEqualTo("Hello, Bob");
}
Expand Down
9 changes: 9 additions & 0 deletions update-from-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ 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
gsed -i 's/--><project/-->\n<project/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml
gsed -i 's/<name>OSS.*<\/name>/<name>My OSS Project<\/name>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml
gsed -i 's/<description>.*<\/description>/<description>My Latest OSS Project<\/description>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml
gsed -i 's/<url>https.*<\/url>/<url>tbd.<\/url>/g' oss-quickstart-archetype-simple/src/main/resources/archetype-resources/pom.xml

gsed -i 's/<url>https.*<\/url>/<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