From f5a02385f6f194bda908cc42965fd616d8dfa18c Mon Sep 17 00:00:00 2001 From: George Andrinopoulos Date: Sun, 1 Nov 2020 07:35:03 +0200 Subject: [PATCH 1/3] Add useCurrentDirectory parameter in CreateExtensionMoJo --- .../io/quarkus/maven/CreateExtensionMojo.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java index fdf58c0f27094..c6674c7805507 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java @@ -529,6 +529,15 @@ public class CreateExtensionMojo extends AbstractMojo { @Parameter(property = "quarkus.generateDevModeTest", defaultValue = "true") boolean generateDevModeTest; + /** + * Indicates whether to generate the extension under the current directory or under a directory based on the + * artifactId + * + * @since TBD + */ + @Parameter(property = "quarkus.useCurrentDirectory", defaultValue = "false") + boolean useCurrentDirectory; + boolean currentProjectIsBaseDir; Charset charset; @@ -624,6 +633,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { boolean setQuarkusVersionProp = true; if (isCurrentProjectExists()) { rootPom = getCurrentProjectPom(); + if (rootPom != null && useCurrentDirectory) { + throw new MojoFailureException( + "Cannot add extension under this directory. Pom file was found."); + } rootModel = MojoUtils.readPom(rootPom); if (!"pom".equals(rootModel.getPackaging())) { throw new MojoFailureException( @@ -801,10 +814,15 @@ private File getCurrentProjectPom() { private Path getExtensionProjectBaseDir() { if (currentProjectIsBaseDir) { + if (useCurrentDirectory) { + return project.getBasedir() == null ? basedir.toPath() + : project.getBasedir().toPath(); + } return project.getBasedir() == null ? basedir.toPath().resolve(artifactIdBase) : project.getBasedir().toPath().resolve(artifactIdBase); } - return new File(basedir, artifactIdBase).toPath(); + return useCurrentDirectory ? new File(basedir, artifactIdBase).toPath() + : basedir.toPath(); } private Path getExtensionRuntimeBaseDir() { @@ -931,7 +949,7 @@ private Configuration getTemplateConfig() throws IOException { private void generateUnitTestClass(Configuration cfg, TemplateParams model) throws IOException, TemplateException { final Path unitTest = basedir.toPath() - .resolve(model.artifactIdBase + "/deployment/src/test/java/" + model.javaPackageBase.replace('.', '/') + .resolve(getExtensionTestPath(model.artifactIdBase) + model.javaPackageBase.replace('.', '/') + "/test/" + model.artifactIdBaseCamelCase + "Test.java"); evalTemplate(cfg, "UnitTest.java", unitTest, model); @@ -940,7 +958,7 @@ private void generateUnitTestClass(Configuration cfg, TemplateParams model) thro private void generateDevModeTestClass(Configuration cfg, TemplateParams model) throws IOException, TemplateException { final Path devModeTest = basedir .toPath() - .resolve(model.artifactIdBase + "/deployment/src/test/java/" + model.javaPackageBase.replace('.', '/') + .resolve(getExtensionTestPath(model.artifactIdBase) + model.javaPackageBase.replace('.', '/') + "/test/" + model.artifactIdBaseCamelCase + "DevModeTest.java"); evalTemplate(cfg, "DevModeTest.java", devModeTest, model); @@ -1146,6 +1164,10 @@ static String artifactIdBase(String artifactId) { } } + private String getExtensionTestPath(String artifactIdBase) { + return useCurrentDirectory ? "deployment/src/test/java/" : artifactIdBase + "/deployment/src/test/java/"; + } + public void setItestParentPath(String itestParentPath) { this.itestParentPath = Paths.get(itestParentPath); } From 4915a8228cf5336d074a13b8e8b02d423314a225 Mon Sep 17 00:00:00 2001 From: George Andrinopoulos Date: Mon, 2 Nov 2020 10:26:52 +0200 Subject: [PATCH 2/3] Fix extension project path --- .../src/main/java/io/quarkus/maven/CreateExtensionMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java index c6674c7805507..07e45ad3ce89b 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java @@ -821,8 +821,8 @@ private Path getExtensionProjectBaseDir() { return project.getBasedir() == null ? basedir.toPath().resolve(artifactIdBase) : project.getBasedir().toPath().resolve(artifactIdBase); } - return useCurrentDirectory ? new File(basedir, artifactIdBase).toPath() - : basedir.toPath(); + return useCurrentDirectory ? basedir.toPath() + : new File(basedir, artifactIdBase).toPath(); } private Path getExtensionRuntimeBaseDir() { From 58c0e109a1a77a128aff863a4b5c8d65f26459e0 Mon Sep 17 00:00:00 2001 From: George Andrinopoulos Date: Mon, 2 Nov 2020 22:35:46 +0200 Subject: [PATCH 3/3] Add test for createe extension under current directory --- .../io/quarkus/maven/CreateExtensionMojo.java | 1 - .../maven/CreateExtensionMojoTest.java | 14 +++++ .../deployment/pom.xml | 51 ++++++++++++++++++ .../my/ext/deployment/MyExtProcessor.java | 15 ++++++ .../acme/my/ext/test/MyExtDevModeTest.java | 22 ++++++++ .../java/org/acme/my/ext/test/MyExtTest.java | 23 ++++++++ .../pom.xml | 50 +++++++++++++++++ .../runtime/pom.xml | 53 +++++++++++++++++++ 8 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/pom.xml create mode 100644 integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java create mode 100644 integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtDevModeTest.java create mode 100644 integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtTest.java create mode 100644 integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/pom.xml create mode 100644 integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/runtime/pom.xml diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java index 07e45ad3ce89b..178310a356b4b 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateExtensionMojo.java @@ -533,7 +533,6 @@ public class CreateExtensionMojo extends AbstractMojo { * Indicates whether to generate the extension under the current directory or under a directory based on the * artifactId * - * @since TBD */ @Parameter(property = "quarkus.useCurrentDirectory", defaultValue = "false") boolean useCurrentDirectory; diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/CreateExtensionMojoTest.java b/integration-tests/maven/src/test/java/io/quarkus/maven/CreateExtensionMojoTest.java index e3705e9a74429..40faf1d41c7ed 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/CreateExtensionMojoTest.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/CreateExtensionMojoTest.java @@ -194,6 +194,20 @@ void createNewExtensionProject() throws Exception { mojo.basedir.toPath()); } + @Test + void createNewExtensionOnCurrentDirectory() throws Exception { + final CreateExtensionMojo mojo = initMojo(newProjectDir("new-extension-current-directory-project")); + mojo.groupId = "org.acme"; + mojo.artifactId = "my-ext"; + mojo.version = "1.0-SNAPSHOT"; + mojo.useCurrentDirectory = true; + mojo.assumeManaged = null; + mojo.execute(); + assertTreesMatch( + Paths.get("target/test-classes/expected/new-extension-current-directory-project"), + mojo.basedir.toPath()); + } + @Test void createNewExtensionProjectWithJBossParent() throws Exception { final CreateExtensionMojo mojo = initMojo(newProjectDir("new-ext-project-with-jboss-parent")); diff --git a/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/pom.xml b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/pom.xml new file mode 100644 index 0000000000000..9650c557d75f0 --- /dev/null +++ b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + org.acme + my-ext-parent + 1.0-SNAPSHOT + ../pom.xml + + + my-ext-deployment + My Ext - Deployment + + + + io.quarkus + quarkus-core-deployment + + + org.acme + my-ext + \${project.version} + + + io.quarkus + quarkus-junit5-internal + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + diff --git a/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java new file mode 100644 index 0000000000000..0b9fa976adcc4 --- /dev/null +++ b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/main/java/org/acme/my/ext/deployment/MyExtProcessor.java @@ -0,0 +1,15 @@ +package org.acme.my.ext.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +class MyExtProcessor { + + private static final String FEATURE = "my-ext"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + +} diff --git a/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtDevModeTest.java b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtDevModeTest.java new file mode 100644 index 0000000000000..6132fc535f323 --- /dev/null +++ b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtDevModeTest.java @@ -0,0 +1,22 @@ +package org.acme.my.ext.test; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusDevModeTest; + +class MyExtDevModeTest { + @RegisterExtension + static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() // Start hot reload (DevMode) test with your extension loaded + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Test + public void test() { + // Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information + Assertions.fail("Add dev mode assertions to " + getClass().getName()); + } + +} diff --git a/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtTest.java b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtTest.java new file mode 100644 index 0000000000000..71ed95323e1d2 --- /dev/null +++ b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/deployment/src/test/java/org/acme/my/ext/test/MyExtTest.java @@ -0,0 +1,23 @@ +package org.acme.my.ext.test; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +class MyExtTest { + + @RegisterExtension + static final QuarkusUnitTest unitTest = new QuarkusUnitTest() // Start unit test with your extension loaded + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Test + public void test() { + // Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information + Assertions.fail("Add some assertions to " + getClass().getName()); + } + +} diff --git a/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/pom.xml b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/pom.xml new file mode 100644 index 0000000000000..30b3da1b2e542 --- /dev/null +++ b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + org.acme + my-ext-parent + 1.0-SNAPSHOT + My Ext - Parent + + pom + + + UTF-8 + UTF-8 + 1.8 + 1.8 + true + ${project.version} + ${compiler-plugin.version} + + + + deployment + runtime + + + + + io.quarkus + quarkus-bom + ${quarkus.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + \${compiler-plugin.version} + + + + + diff --git a/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/runtime/pom.xml b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/runtime/pom.xml new file mode 100644 index 0000000000000..a38543d99a911 --- /dev/null +++ b/integration-tests/maven/src/test/resources/expected/new-extension-current-directory-project/runtime/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + org.acme + my-ext-parent + 1.0-SNAPSHOT + ../pom.xml + + + my-ext + My Ext - Runtime + + + + + + + + io.quarkus + quarkus-bootstrap-maven-plugin + ${quarkus.version} + + + + extension-descriptor + + compile + + \${project.groupId}:\${project.artifactId}-deployment:\${project.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + +