forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix quarkusio#2113 create-extension Maven mojo
- Loading branch information
Showing
18 changed files
with
1,088 additions
and
0 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
437 changes: 437 additions & 0 deletions
437
devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java
Large diffs are not rendered by default.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
devtools/maven/src/main/resources/create-extension-templates/Processor.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,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
package [=javaPackage]; | ||
|
||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
|
||
class [=properExtensionNameCamelCase]Processor { | ||
|
||
private static final String FEATURE = "[=properExtensionName]"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
devtools/maven/src/main/resources/create-extension-templates/deployment-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,50 @@ | ||
<?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> | ||
[#if parent.groupId?? ] <parent> | ||
<groupId>[=parent.groupId]</groupId> | ||
<artifactId>[=parent.artifactId]</artifactId> | ||
<version>[=parent.version]</version> | ||
<relativePath>[=parent.relativePath]</relativePath> | ||
</parent> | ||
[/#if] | ||
|
||
[#if project.groupId?? && project.groupId != parent.groupId ] <groupId>[=project.groupId]</groupId> | ||
[/#if] | ||
[#if project.artifactId?? ] <artifactId>[=project.artifactId]</artifactId> | ||
[/#if] | ||
[#if project.version?? && project.version != parent.version ] <version>[=project.version]</version> | ||
[/#if] | ||
[#if project.name?? ] <name>[=project.name]</name> | ||
[/#if] | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core-deployment</artifactId> | ||
[#if !assumeManaged ] <version>[=quarkusVersion]</version> | ||
[/#if] | ||
</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>[=quarkusVersion]</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
28 changes: 28 additions & 0 deletions
28
devtools/maven/src/main/resources/create-extension-templates/parent-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,28 @@ | ||
<?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> | ||
[#if parent.groupId?? ] <parent> | ||
<groupId>[=parent.groupId]</groupId> | ||
<artifactId>[=parent.artifactId]</artifactId> | ||
<version>[=parent.version]</version> | ||
<relativePath>[=parent.relativePath]</relativePath> | ||
</parent> | ||
[/#if] | ||
|
||
[#if project.groupId?? && project.groupId != parent.groupId ] <groupId>[=project.groupId]</groupId> | ||
[/#if] | ||
[#if project.artifactId?? ] <artifactId>[=project.artifactId]</artifactId> | ||
[/#if] | ||
[#if project.version?? && project.version != parent.version ] <version>[=project.version]</version> | ||
[/#if] | ||
[#if project.name?? ] <name>[=project.name]</name> | ||
[/#if] | ||
|
||
<packaging>pom</packaging> | ||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
devtools/maven/src/main/resources/create-extension-templates/runtime-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,44 @@ | ||
<?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> | ||
[#if parent.groupId?? ] <parent> | ||
<groupId>[=parent.groupId]</groupId> | ||
<artifactId>[=parent.artifactId]</artifactId> | ||
<version>[=parent.version]</version> | ||
<relativePath>[=parent.relativePath]</relativePath> | ||
</parent> | ||
[/#if] | ||
|
||
[#if project.groupId?? && project.groupId != parent.groupId ] <groupId>[=project.groupId]</groupId> | ||
[/#if] | ||
[#if project.artifactId?? ] <artifactId>[=project.artifactId]</artifactId> | ||
[/#if] | ||
[#if project.version?? && project.version != parent.version ] <version>[=project.version]</version> | ||
[/#if] | ||
[#if project.name?? ] <name>[=project.name]</name> | ||
[/#if] | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-maven-plugin</artifactId> | ||
</plugin> | ||
<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>[=quarkusVersion]</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
195 changes: 195 additions & 0 deletions
195
devtools/maven/src/test/java/io/quarkus/maven/CreateExtensionMojoTest.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,195 @@ | ||
package io.quarkus.maven; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.codehaus.plexus.util.FileUtils; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CreateExtensionMojoTest { | ||
|
||
static CreateExtensionMojo createMojo(String testProjectName) throws IllegalArgumentException, | ||
IllegalAccessException, IOException, NoSuchFieldException, SecurityException { | ||
final File srcDir = new File("target/test-classes/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 File copyDir = new File( | ||
"target/test-classes/projects/" + testProjectName + "-" + ((int) (Math.random() * 1000))); | ||
FileUtils.copyDirectory(srcDir, copyDir); | ||
|
||
final CreateExtensionMojo mojo = new CreateExtensionMojo(); | ||
mojo.basedir = copyDir; | ||
mojo.encoding = CreateExtensionMojo.DEFAULT_ENCODING; | ||
mojo.templatesUriBase = CreateExtensionMojo.DEFAULT_TEMPLATES_URI_BASE; | ||
mojo.quarkusVersion = CreateExtensionMojo.DEFAULT_QUARKUS_VERSION; | ||
mojo.assumeManaged = true; | ||
return mojo; | ||
} | ||
|
||
@Test | ||
void createExtensionUnderExistingPomMinimal() throws MojoExecutionException, MojoFailureException, | ||
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException { | ||
final CreateExtensionMojo mojo = createMojo("create-extension-under-existing-pom"); | ||
mojo.artifactId = "my-project-(minimal-extension)"; | ||
mojo.assumeManaged = false; | ||
mojo.execute(); | ||
|
||
assertTreesMatch(Paths.get("target/test-classes/expected/create-extension-under-existing-pom-minimal"), | ||
mojo.basedir.toPath()); | ||
} | ||
|
||
@Test | ||
void createExtensionUnderExistingPomCustomGrandParent() throws MojoExecutionException, MojoFailureException, | ||
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException { | ||
final CreateExtensionMojo mojo = createMojo("create-extension-under-existing-pom"); | ||
mojo.artifactId = "my-project-(custom-grand-parent-extension)"; | ||
mojo.grandParentArtifactId = "build-bom"; | ||
mojo.grandParentRelativePath = "../../build-bom/pom.xml"; | ||
mojo.execute(); | ||
|
||
assertTreesMatch( | ||
Paths.get("target/test-classes/expected/create-extension-under-existing-pom-custom-grand-parent"), | ||
mojo.basedir.toPath()); | ||
} | ||
|
||
static void assertTreesMatch(Path expected, Path actual) throws IOException { | ||
final Set<Path> expectedFiles = new LinkedHashSet<>(); | ||
Files.walk(expected).filter(Files::isRegularFile).forEach(p -> { | ||
final Path relative = expected.relativize(p); | ||
expectedFiles.add(relative); | ||
final Path actualPath = actual.resolve(relative); | ||
try { | ||
Assert.assertEquals(new String(Files.readAllBytes(p), StandardCharsets.UTF_8), | ||
new String(Files.readAllBytes(actualPath), StandardCharsets.UTF_8)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
final Set<Path> unexpectedFiles = new LinkedHashSet<>(); | ||
Files.walk(actual).filter(Files::isRegularFile).forEach(p -> { | ||
final Path relative = actual.relativize(p); | ||
if (!expectedFiles.contains(relative)) { | ||
unexpectedFiles.add(relative); | ||
} | ||
}); | ||
if (!unexpectedFiles.isEmpty()) { | ||
Assert.fail(String.format("Files found under [%s] but not defined as expected under [%s]:%s", actual, | ||
expected, unexpectedFiles.stream().map(Path::toString).collect(Collectors.joining("\n ")))); | ||
} | ||
} | ||
|
||
@Test | ||
void getPackage() throws IOException { | ||
Assert.assertEquals("org.apache.camel.quarkus.aws.sns.deployment", | ||
CreateExtensionMojo.getJavaPackage("org.apache.camel.quarkus", "camel-quarkus-aws-sns-deployment")); | ||
} | ||
|
||
@Test | ||
void toCapCamelCase() throws IOException { | ||
Assert.assertEquals("FooBarBaz", CreateExtensionMojo.toCapCamelCase("foo-bar-baz")); | ||
} | ||
|
||
@Test | ||
void addModule() throws IOException { | ||
final Path path = Paths.get("pom.xml"); | ||
{ | ||
final String source = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" // | ||
+ "<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" // | ||
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" // | ||
+ " <modelVersion>4.0.0</modelVersion>\n" // | ||
+ " <groupId>org.acme</groupId>\n" // | ||
+ " <artifactId>grand-parent</artifactId>\n" // | ||
+ " <version>0.1-SNAPSHOT</version>\n" // | ||
+ " <packaging>pom</packaging>\n" // | ||
+ "</project>\n"; | ||
final String actual = CreateExtensionMojo.addModule(path, source, "new-module"); | ||
final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" // | ||
+ "<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" // | ||
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" // | ||
+ " <modelVersion>4.0.0</modelVersion>\n" // | ||
+ " <groupId>org.acme</groupId>\n" // | ||
+ " <artifactId>grand-parent</artifactId>\n" // | ||
+ " <version>0.1-SNAPSHOT</version>\n" // | ||
+ " <packaging>pom</packaging>\n" // | ||
+ " <modules>\n" // | ||
+ " <module>new-module</module>\n" // | ||
+ " </modules>\n" + "</project>\n"; | ||
Assert.assertEquals(expected, actual); | ||
} | ||
{ | ||
final String source = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" // | ||
+ "<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" // | ||
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" // | ||
+ " <modelVersion>4.0.0</modelVersion>\n" // | ||
+ " <groupId>org.acme</groupId>\n" // | ||
+ " <artifactId>grand-parent</artifactId>\n" // | ||
+ " <version>0.1-SNAPSHOT</version>\n" // | ||
+ "\n" // | ||
+ " <packaging>pom</packaging>\n" // | ||
+ "\n" // | ||
+ " <modules>\n" // | ||
+ " <module>old-module</module>\n" // | ||
+ " </modules>\n" + "</project>\n"; | ||
final String actual = CreateExtensionMojo.addModule(path, source, "new-module"); | ||
final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" // | ||
+ "<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" // | ||
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" // | ||
+ " <modelVersion>4.0.0</modelVersion>\n" // | ||
+ " <groupId>org.acme</groupId>\n" // | ||
+ " <artifactId>grand-parent</artifactId>\n" // | ||
+ " <version>0.1-SNAPSHOT</version>\n" // | ||
+ "\n" // | ||
+ " <packaging>pom</packaging>\n" // | ||
+ "\n" // | ||
+ " <modules>\n" // | ||
+ " <module>old-module</module>\n" // | ||
+ " <module>new-module</module>\n" // | ||
+ " </modules>\n" // | ||
+ "</project>\n"; | ||
Assert.assertEquals(expected, actual); | ||
} | ||
{ | ||
final String source = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" // | ||
+ "<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" // | ||
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" // | ||
+ " <modelVersion>4.0.0</modelVersion>\n" // | ||
+ " <groupId>org.acme</groupId>\n" // | ||
+ " <artifactId>grand-parent</artifactId>\n" // | ||
+ " <version>0.1-SNAPSHOT</version>\n" // | ||
+ " <packaging>pom</packaging>\n" // | ||
+ "\n" // | ||
+ " <build>\n" // | ||
+ " </build>\n" // | ||
+ "</project>\n"; | ||
final String actual = CreateExtensionMojo.addModule(path, source, "new-module"); | ||
final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" // | ||
+ "<project xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" // | ||
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" // | ||
+ " <modelVersion>4.0.0</modelVersion>\n" // | ||
+ " <groupId>org.acme</groupId>\n" // | ||
+ " <artifactId>grand-parent</artifactId>\n" // | ||
+ " <version>0.1-SNAPSHOT</version>\n" // | ||
+ " <packaging>pom</packaging>\n" // | ||
+ "\n" // | ||
+ " <modules>\n" // | ||
+ " <module>new-module</module>\n" // | ||
+ " </modules>\n" // | ||
+ " <build>\n" // | ||
+ " </build>\n" // | ||
+ "</project>\n"; | ||
Assert.assertEquals(expected, actual); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.