-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-15405 Add archetype for custom Infinispan module (#11617)
* Also remove outdated release information from building guide
- Loading branch information
1 parent
3f8ce4d
commit 052c2fc
Showing
14 changed files
with
366 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.infinispan.archetypes</groupId> | ||
<artifactId>infinispan-archetypes</artifactId> | ||
<version>15.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>custom-module</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Infinispan ModuleLifecycle Archetype</name> | ||
<description>Maven archetype to create an Infinispan ModuleLifecycle implementation</description> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
archetypes/custom-module/src/main/resources/META-INF/maven/archetype-metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<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" | ||
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" | ||
name="Infinispan Project Archetype" partial="false"> | ||
<fileSets> | ||
<fileSet filtered="true" packaged="true" encoding="UTF-8"> | ||
<directory>src/main/java</directory> | ||
</fileSet> | ||
|
||
<fileSet filtered="false" packaged="false" encoding="UTF-8"> | ||
<directory>src/main/resources</directory> | ||
</fileSet> | ||
</fileSets> | ||
</archetype-descriptor> |
101 changes: 101 additions & 0 deletions
101
archetypes/custom-module/src/main/resources/archetype-resources/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>\${groupId}</groupId> | ||
<artifactId>\${artifactId}</artifactId> | ||
<packaging>jar</packaging> | ||
<version>\${version}</version> | ||
<name>Server Task</name> | ||
<description>Archetype project for building Server Task for use within Infinispan</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-bom</artifactId> | ||
<!-- Which Infinispan version do you want to use? Released versions are always more reliable than snapshots! --> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-component-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-component-processor</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kohsuke.metainf-services</groupId> | ||
<artifactId>metainf-services</artifactId> | ||
<version>${versionx.org.kohsuke.metainf-services.metainf-services}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- enforce java 11 and maven 3.2 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<version>3.0.0-M1</version> | ||
<executions> | ||
<execution> | ||
<id>enforce-java</id> | ||
<goals> | ||
<goal>enforce</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<requireJavaVersion> | ||
<version>[${maven.compiler.source},)</version> | ||
</requireJavaVersion> | ||
<requireMavenVersion> | ||
<version>[3.2.1,)</version> | ||
</requireMavenVersion> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- by default, compile to JDK 11 compatibility --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${version.maven-compiler-plugin}</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>JBoss.org Public Repository</id> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<url>https://repository.jboss.org/nexus/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
archetypes/custom-module/src/main/resources/archetype-resources/src/main/java/Attribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ${package}; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public enum Attribute { | ||
// must be first | ||
UNKNOWN(null), | ||
|
||
MESSAGE("message"); | ||
private static final Map<String, Attribute> ATTRIBUTES; | ||
|
||
static { | ||
final Map<String, Attribute> map = new HashMap<>(); | ||
for (Attribute attribute : values()) { | ||
final String name = attribute.name; | ||
if (name != null) { | ||
map.put(name, attribute); | ||
} | ||
} | ||
ATTRIBUTES = Map.copyOf(map); | ||
} | ||
|
||
private final String name; | ||
|
||
Attribute(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public static Attribute forName(String localName) { | ||
final Attribute attribute = ATTRIBUTES.get(localName); | ||
return attribute == null ? UNKNOWN : attribute; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ypes/custom-module/src/main/resources/archetype-resources/src/main/java/CustomModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ${package}; | ||
|
||
import org.infinispan.configuration.global.GlobalConfiguration; | ||
import org.infinispan.factories.GlobalComponentRegistry; | ||
import org.infinispan.factories.annotations.InfinispanModule; | ||
import org.infinispan.lifecycle.ModuleLifecycle; | ||
|
||
@InfinispanModule(name = "custom-module", requiredModules = "core") | ||
public class CustomModule implements ModuleLifecycle { | ||
@Override | ||
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) { | ||
CustomModuleConfiguration config = globalConfiguration.module(CustomModuleConfiguration.class); | ||
// The config object will be null if the custom module hasn't been configured declaratively via JSON/XML/Yaml | ||
// or programmatically when creating the EmbeddedCacheManager GlobalConfiguration | ||
if (config != null) { | ||
// Print out welcome message from CustomModuleConfiguration. If the message attribute hasn't been overridden in | ||
// the config, then the default message is printed | ||
System.out.println("Custom Module Message: " + config.message()); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...odule/src/main/resources/archetype-resources/src/main/java/CustomModuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ${package}; | ||
|
||
import org.infinispan.commons.configuration.BuiltBy; | ||
import org.infinispan.commons.configuration.attributes.AttributeDefinition; | ||
import org.infinispan.commons.configuration.attributes.AttributeSet; | ||
import org.infinispan.commons.configuration.attributes.ConfigurationElement; | ||
import org.infinispan.configuration.serializing.SerializedWith; | ||
|
||
@BuiltBy(CustomModuleConfigurationBuilder.class) | ||
@SerializedWith(CustomModuleSerializer.class) | ||
public class CustomModuleConfiguration extends ConfigurationElement<CustomModuleConfiguration> { | ||
|
||
static final AttributeDefinition<String> MESSAGE = AttributeDefinition.builder(Attribute.MESSAGE, "Module Loaded") | ||
.immutable().build(); | ||
static AttributeSet attributeDefinitionSet() { | ||
return new AttributeSet(CustomModuleConfiguration.class, MESSAGE); | ||
} | ||
|
||
CustomModuleConfiguration(AttributeSet attributes) { | ||
super(Element.ROOT, attributes); | ||
} | ||
|
||
public String message() { | ||
return attributes.attribute(MESSAGE).get(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rc/main/resources/archetype-resources/src/main/java/CustomModuleConfigurationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ${package}; | ||
|
||
import org.infinispan.commons.configuration.Builder; | ||
import org.infinispan.commons.configuration.Combine; | ||
import org.infinispan.commons.configuration.attributes.AttributeSet; | ||
import org.infinispan.configuration.global.GlobalConfigurationBuilder; | ||
|
||
public class CustomModuleConfigurationBuilder implements Builder<CustomModuleConfiguration> { | ||
|
||
private final AttributeSet attributes = CustomModuleConfiguration.attributeDefinitionSet(); | ||
|
||
private final GlobalConfigurationBuilder builder; | ||
|
||
public CustomModuleConfigurationBuilder(GlobalConfigurationBuilder builder) { | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public CustomModuleConfiguration create() { | ||
return new CustomModuleConfiguration(attributes.protect()); | ||
} | ||
|
||
@Override | ||
public Builder<?> read(CustomModuleConfiguration template, Combine combine) { | ||
this.attributes.read(template.attributes(), combine); | ||
return this; | ||
} | ||
|
||
@Override | ||
public AttributeSet attributes() { | ||
return attributes; | ||
} | ||
|
||
public Builder<?> message(String message) { | ||
attributes.attribute(CustomModuleConfiguration.MESSAGE).set(message); | ||
return this; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ustom-module/src/main/resources/archetype-resources/src/main/java/CustomModuleParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ${package}; | ||
|
||
import org.infinispan.commons.CacheConfigurationException; | ||
import org.infinispan.commons.configuration.io.ConfigurationReader; | ||
import org.infinispan.configuration.global.GlobalConfigurationBuilder; | ||
import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; | ||
import org.infinispan.configuration.parsing.ConfigurationParser; | ||
import org.infinispan.configuration.parsing.Namespace; | ||
import org.infinispan.configuration.parsing.ParseUtils; | ||
import org.infinispan.configuration.parsing.Parser; | ||
import org.infinispan.configuration.parsing.ParserScope; | ||
import org.kohsuke.MetaInfServices; | ||
|
||
@MetaInfServices | ||
@Namespace(root = "custom-module") | ||
@Namespace(uri = Parser.NAMESPACE + "*", root = "custom-module") | ||
public class CustomModuleParser implements ConfigurationParser { | ||
|
||
@Override | ||
public void readElement(ConfigurationReader reader, ConfigurationBuilderHolder holder) { | ||
if (!holder.inScope(ParserScope.CACHE_CONTAINER)) | ||
throw new CacheConfigurationException(String.format("Unexpected scope. Expected CACHE_CONTAINER but was %s", holder.getScope())); | ||
|
||
|
||
Element element = Element.forName(reader.getLocalName()); | ||
if (element != Element.ROOT) | ||
throw ParseUtils.unexpectedElement(reader); | ||
|
||
GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder(); | ||
CustomModuleConfigurationBuilder builder = globalBuilder.addModule(CustomModuleConfigurationBuilder.class); | ||
|
||
for (int i = 0; i < reader.getAttributeCount(); i++) { | ||
ParseUtils.requireNoNamespaceAttribute(reader, i); | ||
String value = reader.getAttributeValue(i); | ||
Attribute attribute = Attribute.forName(reader.getAttributeName(i)); | ||
switch (attribute) { | ||
case MESSAGE: | ||
builder.message(value); | ||
break; | ||
default: | ||
throw ParseUtils.unexpectedAttribute(reader, i); | ||
} | ||
} | ||
ParseUtils.requireNoContent(reader); | ||
} | ||
|
||
@Override | ||
public Namespace[] getNamespaces() { | ||
return ParseUtils.getNamespaceAnnotations(getClass()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...m-module/src/main/resources/archetype-resources/src/main/java/CustomModuleSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ${package}; | ||
|
||
import org.infinispan.commons.configuration.io.ConfigurationWriter; | ||
import org.infinispan.configuration.serializing.ConfigurationSerializer; | ||
|
||
public class CustomModuleSerializer implements ConfigurationSerializer<CustomModuleConfiguration> { | ||
@Override | ||
public void serialize(ConfigurationWriter writer, CustomModuleConfiguration configuration) { | ||
writer.writeStartElement(Element.ROOT); | ||
configuration.attributes().write(writer); | ||
writer.writeEndElement(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
archetypes/custom-module/src/main/resources/archetype-resources/src/main/java/Element.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ${package}; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public enum Element { | ||
//must be first | ||
UNKNOWN(null), | ||
|
||
ROOT("custom-module"), | ||
; | ||
|
||
private static final Map<String, Element> ELEMENTS; | ||
|
||
static { | ||
final Map<String, Element> map = new HashMap<>(); | ||
for (Element element : values()) { | ||
final String name = element.name; | ||
if (name != null) { | ||
map.put(name, element); | ||
} | ||
} | ||
ELEMENTS = Map.copyOf(map); | ||
} | ||
|
||
private final String name; | ||
|
||
Element(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public static Element forName(final String localName) { | ||
final Element element = ELEMENTS.get(localName); | ||
return element == null ? UNKNOWN : element; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
archetypes/custom-module/src/test/resources/projects/test/archetype.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sourceEncoding=UTF-8 | ||
groupId=org.infinispan.archetypes.test | ||
artifactId=test | ||
version=1.0.0-SNAPSHOT | ||
package=org.infinispan.archetypes.test | ||
packageInPathFormat=org/infinispan/archetypes/test |
1 change: 1 addition & 0 deletions
1
archetypes/custom-module/src/test/resources/projects/test/goal.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.