Skip to content

Commit

Permalink
Fix quarkusio#3321 create-extension Maven mojo should allow creating …
Browse files Browse the repository at this point in the history
…from scratch
  • Loading branch information
ppalaga committed Aug 5, 2019
1 parent 5120227 commit c508b44
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 109 deletions.
22 changes: 13 additions & 9 deletions devtools/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/templates</directory>
<filtering>false</filtering>
</resource>
</resources>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
Expand Down Expand Up @@ -254,6 +250,14 @@
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<escapeString>@@</escapeString>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
224 changes: 144 additions & 80 deletions devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

<artifactId>[=artifactId]-deployment</artifactId>
[#if nameBase?? ] <name>[=namePrefix][=nameBase][=nameSegmentDelimiter]Deployment</name>
[/#if]
[#if !multipleExtensions ]

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom-deployment</artifactId>
<version>[=quarkusVersion]</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
[/#if]

<dependencies>
Expand All @@ -24,7 +38,7 @@
<dependency>
<groupId>[=groupId]</groupId>
<artifactId>[=artifactId]</artifactId>
[#if !assumeManaged ] <version>[=r"$"]{project.version}</version>
[#if !assumeManaged ] <version>${project.version}</version>
[/#if]
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<groupId>[=grandParentGroupId]</groupId>
<artifactId>[=grandParentArtifactId]</artifactId>
<version>[=grandParentVersion]</version>
<relativePath>[=grandParentRelativePath]</relativePath>
[#if grandParentRelativePath?? ] <relativePath>[=grandParentRelativePath]</relativePath>
[/#if]
</parent>
[/#if]

Expand All @@ -20,6 +21,23 @@
[/#if]

<packaging>pom</packaging>
[#if !multipleExtensions ]

<dependencyManagement>
<dependencies>
<dependency>
<groupId>[=groupId]</groupId>
<artifactId>[=artifactId]</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>[=groupId]</groupId>
<artifactId>[=artifactId]-deployment</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
[/#if]
<modules>
<module>deployment</module>
<module>runtime</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</goals>
<phase>compile</phase>
<configuration>
<deployment>[=r"$"]{project.groupId}:[=r"$"]{project.artifactId}-deployment:[=r"$"]{project.version}
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
</deployment>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

public class CreateExtensionMojoTest {

static CreateExtensionMojo createMojo(String testProjectName) throws IllegalArgumentException,
static CreateExtensionMojo copyTestTree(String testProjectName, String testName) throws IllegalArgumentException,
IllegalAccessException, IOException, NoSuchFieldException, SecurityException {
final Path srcDir = Paths.get("src/test/resources/projects/" + testProjectName);
/*
* We want to run on the same project multiple times with different args so let's create a copy with a random
* suffix
*/
final Path copyDir = Paths
.get("target/test-classes/projects/" + testProjectName + "-" + ((int) (Math.random() * 1000)));
.get("target/test-classes/projects/" + testProjectName + "-" + testName);
Files.walk(srcDir).forEach(source -> {
try {
final Path dest = copyDir.resolve(srcDir.relativize(source));
Expand All @@ -34,8 +34,12 @@ static CreateExtensionMojo createMojo(String testProjectName) throws IllegalArgu
}
});

return defaultMojo(copyDir);
}

public static CreateExtensionMojo defaultMojo(Path basedir) {
final CreateExtensionMojo mojo = new CreateExtensionMojo();
mojo.basedir = copyDir;
mojo.basedir = basedir;
mojo.encoding = CreateExtensionMojo.DEFAULT_ENCODING;
mojo.templatesUriBase = CreateExtensionMojo.DEFAULT_TEMPLATES_URI_BASE;
mojo.quarkusVersion = CreateExtensionMojo.DEFAULT_QUARKUS_VERSION;
Expand All @@ -44,22 +48,36 @@ static CreateExtensionMojo createMojo(String testProjectName) throws IllegalArgu
return mojo;
}

@Test
void singleExtensionFromScratch() throws IOException, MojoExecutionException, MojoFailureException {
final Path basedir = Paths
.get("target/test-classes/projects/single-from-scratch");
Files.createDirectories(basedir);
final CreateExtensionMojo mojo = defaultMojo(basedir);
mojo.groupId = "io.quarkus.example";
mojo.artifactId = "single-ext";
mojo.execute();

assertTreesMatch(Paths.get("target/test-classes/expected/single-from-scratch"),
mojo.basedir);
}

@Test
void createExtensionUnderExistingPomMinimal() throws MojoExecutionException, MojoFailureException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException {
final CreateExtensionMojo mojo = createMojo("create-extension-pom");
final CreateExtensionMojo mojo = copyTestTree("create-extension-pom", "minimal");
mojo.artifactId = "my-project-(minimal-extension)";
mojo.assumeManaged = false;
mojo.execute();

assertTreesMatch(Paths.get("src/test/resources/expected/create-extension-pom-minimal"),
assertTreesMatch(Paths.get("target/test-classes/expected/create-extension-pom-minimal"),
mojo.basedir);
}

@Test
void createExtensionUnderExistingPomCustomGrandParent() throws MojoExecutionException, MojoFailureException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException {
final CreateExtensionMojo mojo = createMojo("create-extension-pom");
final CreateExtensionMojo mojo = copyTestTree("create-extension-pom", "grand-parent");
mojo.artifactId = "myproject-(with-grand-parent)";
mojo.grandParentArtifactId = "build-bom";
mojo.grandParentRelativePath = "../../build-bom/pom.xml";
Expand All @@ -70,7 +88,7 @@ void createExtensionUnderExistingPomCustomGrandParent() throws MojoExecutionExce
mojo.execute();

assertTreesMatch(
Paths.get("src/test/resources/expected/create-extension-pom-with-grand-parent"),
Paths.get("target/test-classes/expected/create-extension-pom-with-grand-parent"),
mojo.basedir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
<version>${quarkus.version}</version>
<version>@@${quarkus.version}</version>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>my-project-minimal-extension</artifactId>
<version>${project.version}</version>
<version>@@${project.version}</version>
</dependency>
</dependencies>

Expand All @@ -36,7 +36,7 @@
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
<version>@@${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<version>@@${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>extension-descriptor</goal>
</goals>
<phase>compile</phase>
<configuration>
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
<deployment>@@${project.groupId}:@@${project.artifactId}-deployment:@@${project.version}
</deployment>
</configuration>
</execution>
Expand All @@ -40,7 +40,7 @@
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
<version>@@${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>org.acme</groupId>
<artifactId>myproject-with-grand-parent-deployment</artifactId>
<version>${project.version}</version>
<version>@@${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>org.acme</groupId>
<artifactId>myproject-with-grand-parent</artifactId>
<version>${project.version}</version>
<version>@@${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
<version>@@${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
<version>@@${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus.example</groupId>
<artifactId>single-ext-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>single-ext-deployment</artifactId>
<name>Single Ext - Deployment</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom-deployment</artifactId>
<version>@@${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus.example</groupId>
<artifactId>single-ext</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>@@${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.example.single.ext.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

class SingleExtProcessor {

private static final String FEATURE = "single-ext";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-build-parent</artifactId>
<version>${project.version}</version>
</parent>

<groupId>io.quarkus.example</groupId>
<artifactId>single-ext-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Single Ext - Parent</name>

<packaging>pom</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus.example</groupId>
<artifactId>single-ext</artifactId>
<version>@@${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus.example</groupId>
<artifactId>single-ext-deployment</artifactId>
<version>@@${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Loading

0 comments on commit c508b44

Please sign in to comment.