Skip to content

Commit ab113b0

Browse files
committed
Generate Maven Archetype
1 parent ea61d67 commit ab113b0

File tree

42 files changed

+653
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+653
-295
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ install:
2525
script:
2626
# Test with the defaults
2727
- sbt new file://$(pwd) --name=hello && pushd hello && sbt test && popd
28-
# Test with custom name/organization to ensure templating is done correctly
29-
- sbt new file://$(pwd) --name=smello --organization=org.eggsample && cd smello && sbt test
28+
# Test with custom name/organization to ensure templating is done correctly
29+
- sbt new file://$(pwd) --name=smello --organization=org.eggsample && pushd smello && sbt test && popd
30+
# Test Maven Archetype
31+
- ./test-archetype.sh
3032

3133
cache:
3234
directories:
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
3+
name="lagom-maven-java">
4+
5+
<requiredProperties>
6+
<requiredProperty key="serviceName">
7+
<defaultValue>hello</defaultValue>
8+
</requiredProperty>
9+
<requiredProperty key="serviceClassName">
10+
<defaultValue>Hello</defaultValue>
11+
</requiredProperty>
12+
<!-- These properties must be valid Velocity identifiers, so cannot contain dots. -->
13+
<requiredProperty key="scala-binary-version">
14+
<defaultValue>2.12</defaultValue>
15+
<validationRegex>\d+\.\d+</validationRegex>
16+
</requiredProperty>
17+
</requiredProperties>
18+
19+
<!-- If you read up on the documentation and various blog posts and question/answers out on the internet, you'll
20+
see that the archetype descriptor actually has a nifty feature where it can be aware of different modules, and
21+
name packages for you, and all sorts of wonderful things. The problem is, we want the names of the modules to be
22+
dynamically selected using the above properties (eg, service1Name), but the Maven archetype plugin treats module
23+
directories different to all other directories, where other directories can substitute any property they want
24+
using __myPropertyName__ syntax, the module directory is hard coded to only substitute __rootArtifactId__. This
25+
issue has been raised here: https://issues.apache.org/jira/browse/ARCHETYPE-455, a patch has existed for 3 years,
26+
but no response or review from the maintainers. So, consequently, we can't use modules in the archetype
27+
descriptor. -->
28+
29+
<fileSets>
30+
<fileSet filtered="true" encoding="UTF-8">
31+
<directory></directory>
32+
<includes>
33+
<include>**/*</include>
34+
</includes>
35+
<excludes>
36+
<exclude>pom.xml</exclude>
37+
<exclude>LICENSE</exclude>
38+
</excludes>
39+
</fileSet>
40+
</fileSets>
41+
42+
</archetype-descriptor>

src/main/g8/$name__norm$-api/src/main/java/$package$/api/$name__Camel$Event.java renamed to src/main/g8/$if(mavenArchetype.truthy)$archetype-resources$endif$/$if(mavenArchetype.truthy)$__serviceName__$else$$name__norm$$endif$-api/src/main/java/$if(mavenArchetype.truthy)$__packageInPathFormat__$else$$package$$endif$/$if(mavenArchetype.truthy)$__serviceName__$endif$/api/$if(mavenArchetype.truthy)$__serviceClassName__$else$$name__Camel$$endif$Event.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package $package$.api;
1+
package $if(mavenArchetype.truthy)$\${package}.\${serviceName}$else$$package$$endif$.api;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonSubTypes;
@@ -8,13 +8,13 @@
88

99
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
1010
@JsonSubTypes({
11-
@JsonSubTypes.Type(value = $name;format="Camel"$Event.GreetingMessageChanged.class, name = "greeting-message-changed")
11+
@JsonSubTypes.Type(value = $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Event.GreetingMessageChanged.class, name = "greeting-message-changed")
1212
})
13-
public interface $name;format="Camel"$Event {
13+
public interface $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Event {
1414
String getName();
1515

1616
@Value
17-
final class GreetingMessageChanged implements $name;format="Camel"$Event {
17+
final class GreetingMessageChanged implements $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Event {
1818
public final String name;
1919
public final String message;
2020

src/main/g8/$name__norm$-api/src/main/java/$package$/api/$name__Camel$Service.java renamed to src/main/g8/$if(mavenArchetype.truthy)$archetype-resources$endif$/$if(mavenArchetype.truthy)$__serviceName__$else$$name__norm$$endif$-api/src/main/java/$if(mavenArchetype.truthy)$__packageInPathFormat__$else$$package$$endif$/$if(mavenArchetype.truthy)$__serviceName__$endif$/api/$if(mavenArchetype.truthy)$__serviceClassName__$else$$name__Camel$$endif$Service.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package $package$.api;
1+
package $if(mavenArchetype.truthy)$\${package}.\${serviceName}$else$$package$$endif$.api;
22

33
import akka.Done;
44
import akka.NotUsed;
@@ -11,12 +11,12 @@
1111
import static com.lightbend.lagom.javadsl.api.Service.*;
1212

1313
/**
14-
* The $name;format="camel"$ service interface.
14+
* The $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$ service interface.
1515
* <p>
1616
* This describes everything that Lagom needs to know about how to serve and
17-
* consume the $name;format="Camel"$Service.
17+
* consume the $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Service.
1818
*/
19-
public interface $name;format="Camel"$Service extends Service {
19+
public interface $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Service extends Service {
2020
/**
2121
* Example:
2222
* curl http://localhost:9000/api/hello/Alice
@@ -32,11 +32,11 @@ public interface $name;format="Camel"$Service extends Service {
3232
/**
3333
* This gets published to Kafka.
3434
*/
35-
Topic<$name;format="Camel"$Event> helloEvents();
35+
Topic<$if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Event> helloEvents();
3636

3737
@Override
3838
default Descriptor descriptor() {
39-
return named("$name;format="camel"$")
39+
return named("$if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$")
4040
.withCalls(
4141
pathCall("/api/hello/:id", this::hello),
4242
pathCall("/api/hello/:id", this::useGreeting)
@@ -48,7 +48,7 @@ default Descriptor descriptor() {
4848
// go to the same partition (and hence are delivered in order with respect
4949
// to that user), we configure a partition key strategy that extracts the
5050
// name as the partition key.
51-
.withProperty(KafkaProperties.partitionKeyStrategy(), $name;format="Camel"$Event::getName)
51+
.withProperty(KafkaProperties.partitionKeyStrategy(), $if(mavenArchetype.truthy)$\${serviceClassName}$else$$name;format="Camel"$$endif$Event::getName)
5252
)
5353
.withAutoAcl(true);
5454
}

src/main/g8/$name__norm$-api/src/main/java/$package$/api/GreetingMessage.java renamed to src/main/g8/$if(mavenArchetype.truthy)$archetype-resources$endif$/$if(mavenArchetype.truthy)$__serviceName__$else$$name__norm$$endif$-api/src/main/java/$if(mavenArchetype.truthy)$__packageInPathFormat__$else$$package$$endif$/$if(mavenArchetype.truthy)$__serviceName__$endif$/api/GreetingMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package $package$.api;
1+
package $if(mavenArchetype.truthy)$\${package}.\${serviceName}$else$$package$$endif$.api;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

0 commit comments

Comments
 (0)