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

Add useCurrentDirectory parameter in CreateExtensionMoJo #13045

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ 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
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since 1.10.0.Final might be handy for future readers.

*/
@Parameter(property = "quarkus.useCurrentDirectory", defaultValue = "false")
boolean useCurrentDirectory;

boolean currentProjectIsBaseDir;

Charset charset;
Expand Down Expand Up @@ -624,6 +632,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(
Expand Down Expand Up @@ -801,10 +813,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 ? basedir.toPath()
: new File(basedir, artifactIdBase).toPath();
}

private Path getExtensionRuntimeBaseDir() {
Expand Down Expand Up @@ -931,7 +948,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);
Expand All @@ -940,7 +957,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);
Expand Down Expand Up @@ -1146,6 +1163,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>my-ext-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>my-ext-deployment</artifactId>
<name>My Ext - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>my-ext</artifactId>
<version>\${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</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 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);
}

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
@@ -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());
}

}
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.acme</groupId>
<artifactId>my-ext-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<name>My Ext - Parent</name>

<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>
<quarkus.version>${project.version}</quarkus.version>
<compiler-plugin.version>${compiler-plugin.version}</compiler-plugin.version>
</properties>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>\${compiler-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>my-ext-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>my-ext</artifactId>
<name>My Ext - Runtime</name>

<dependencies>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<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>
</configuration>
</execution>
</executions>
</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>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>