Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quarkusio#3321 create-extension Maven mojo should allow creating from scratch #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion core/builder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-build-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion core/creator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/devmode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../build-parent/pom.xml</relativePath>
<relativePath>../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion devtools/aesh/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion devtools/extension-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion devtools/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-build-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
24 changes: 14 additions & 10 deletions devtools/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../../build-parent/pom.xml</relativePath>
<relativePath>../../parents/build-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down 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
Loading