Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Split demo into extension and mojo projects
From 3d07ee9d65f2b1f4f6a4c6f540cc3dc025be782b Mon Sep 17 00:00:00 2001
From: Stuart McCulloch <mcculls@gmail.com>
Date: Thu, 4 Feb 2021 22:54:20 +0000
Subject: [PATCH] Fix demo
---
demo/pom.xml | 4 +-
extension-mojo/pom.xml | 87 --------------------
.../fr/brouillard/oss/maven/InfoExtension.java | 32 --------
.../java/fr/brouillard/oss/maven/InfoHolder.java | 18 -----
.../java/fr/brouillard/oss/maven/InfoMojo.java | 29 -------
extension/pom.xml | 51 ++++++++++++
.../fr/brouillard/oss/maven/InfoExtension.java | 32 ++++++++
.../java/fr/brouillard/oss/maven/InfoHolder.java | 18 +++++
.../main/resources/META-INF/maven/extension.xml | 5 ++
mojo/pom.xml | 93 ++++++++++++++++++++++
.../fr/brouillard/oss/maven/mojo/InfoMojo.java | 30 +++++++
11 files changed, 231 insertions(+), 168 deletions(-)
delete mode 100644 extension-mojo/pom.xml
delete mode 100644 extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoExtension.java
delete mode 100644 extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoHolder.java
delete mode 100644 extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoMojo.java
create mode 100644 extension/pom.xml
create mode 100644 extension/src/main/java/fr/brouillard/oss/maven/InfoExtension.java
create mode 100644 extension/src/main/java/fr/brouillard/oss/maven/InfoHolder.java
create mode 100644 extension/src/main/resources/META-INF/maven/extension.xml
create mode 100644 mojo/pom.xml
create mode 100644 mojo/src/main/java/fr/brouillard/oss/maven/mojo/InfoMojo.java
diff --git a/demo/pom.xml b/demo/pom.xml
index 34f8ba7..fad20ef 100644
--- a/demo/pom.xml
+++ b/demo/pom.xml
@@ -16,7 +16,7 @@
<plugins>
<plugin>
<groupId>fr.brouillard.oss</groupId>
- <artifactId>maven-demo-extension</artifactId>
+ <artifactId>maven-demo-mojo</artifactId>
<version>0</version>
<executions>
<execution>
@@ -29,4 +29,4 @@
</plugin>
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git a/extension-mojo/pom.xml b/extension-mojo/pom.xml
deleted file mode 100644
index fa98c61..0000000
--- a/extension-mojo/pom.xml
+++ /dev/null
@@ -1,87 +0,0 @@
-<?xml version="1.0"?>
-<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>fr.brouillard.oss</groupId>
- <artifactId>maven-demo-extension</artifactId>
- <version>0</version>
- <name>maven demo extension JSR330 and plugin</name>
- <packaging>maven-plugin</packaging>
-
- <properties>
- <maven.compiler.source>1.8</maven.compiler.source>
- <maven.compiler.target>1.8</maven.compiler.target>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.version>3.6.3</maven.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <version>1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>${maven.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model-builder</artifactId>
- <version>${maven.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>${maven.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-annotations</artifactId>
- <version>3.6.0</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.eclipse.sisu</groupId>
- <artifactId>sisu-maven-plugin</artifactId>
- <version>0.3.4</version>
- <executions>
- <execution>
- <id>generate-index</id>
- <goals>
- <goal>main-index</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-plugin-plugin</artifactId>
- <version>3.6.0</version>
- <configuration>
- <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
- </configuration>
- <executions>
- <execution>
- <id>mojo-descriptor</id>
- <goals>
- <goal>descriptor</goal>
- </goals>
- <phase>process-classes</phase>
- </execution>
- <execution>
- <id>help-goal</id>
- <goals>
- <goal>helpmojo</goal>
- </goals>
- <phase>process-classes</phase>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
\ No newline at end of file
diff --git a/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoExtension.java b/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoExtension.java
deleted file mode 100644
index fdeaffe..0000000
--- a/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoExtension.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package fr.brouillard.oss.maven;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.apache.maven.AbstractMavenLifecycleParticipant;
-import org.apache.maven.MavenExecutionException;
-import org.apache.maven.execution.MavenSession;
-import org.codehaus.plexus.logging.Logger;
-
-@Named
-@Singleton
-public class InfoExtension extends AbstractMavenLifecycleParticipant {
- private final InfoHolder infoHolder;
- private Logger logger;
-
- @Inject
- public InfoExtension(Logger logger, InfoHolder infoHolder) {
- this.logger = logger;
- this.infoHolder = infoHolder;
- }
-
- @Override
- public void afterSessionStart(MavenSession session) throws MavenExecutionException {
- super.afterSessionStart(session);
-
- String information = "Build started at " + System.currentTimeMillis();
- logger.info("extension generated information: " + information);
- infoHolder.setInformation(information);
- }
-}
diff --git a/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoHolder.java b/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoHolder.java
deleted file mode 100644
index 5a95f2e..0000000
--- a/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoHolder.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package fr.brouillard.oss.maven;
-
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-@Named
-@Singleton
-public class InfoHolder {
- private String information;
-
- public String getInformation() {
- return information;
- }
-
- public void setInformation(String information) {
- this.information = information;
- }
-}
diff --git a/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoMojo.java b/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoMojo.java
deleted file mode 100644
index 2019676..0000000
--- a/extension-mojo/src/main/java/fr/brouillard/oss/maven/InfoMojo.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package fr.brouillard.oss.maven;
-
-import javax.inject.Inject;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-
-@Mojo(name = "info", defaultPhase = LifecyclePhase.VALIDATE, requiresProject = false)
-public class InfoMojo extends AbstractMojo {
- private InfoHolder infoHolder;
-
- @Inject
- public InfoMojo(InfoHolder infoHolder) {
- this.infoHolder = infoHolder;
- }
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- String information = infoHolder.getInformation();
- if (information != null) {
- getLog().info("Information: " + information);
- } else {
- getLog().error("No information provided, Singleton injection might have failed");
- }
- }
-}
diff --git a/extension/pom.xml b/extension/pom.xml
new file mode 100644
index 0000000..7b9b1bb
--- /dev/null
+++ b/extension/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<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>fr.brouillard.oss</groupId>
+ <artifactId>maven-demo-extension</artifactId>
+ <version>0</version>
+ <name>maven demo extension</name>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.version>3.6.3</maven.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model-builder</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.sisu</groupId>
+ <artifactId>sisu-maven-plugin</artifactId>
+ <version>0.3.4</version>
+ <executions>
+ <execution>
+ <id>generate-index</id>
+ <goals>
+ <goal>main-index</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/extension/src/main/java/fr/brouillard/oss/maven/InfoExtension.java b/extension/src/main/java/fr/brouillard/oss/maven/InfoExtension.java
new file mode 100644
index 0000000..98c5af0
--- /dev/null
+++ b/extension/src/main/java/fr/brouillard/oss/maven/InfoExtension.java
@@ -0,0 +1,32 @@
+package fr.brouillard.oss.maven;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.AbstractMavenLifecycleParticipant;
+import org.apache.maven.MavenExecutionException;
+import org.apache.maven.execution.MavenSession;
+import org.codehaus.plexus.logging.Logger;
+
+@Named
+@Singleton
+public class InfoExtension extends AbstractMavenLifecycleParticipant {
+ private final InfoHolder infoHolder;
+ private Logger logger;
+
+ @Inject
+ public InfoExtension(Logger logger, InfoHolder infoHolder) {
+ this.logger = logger;
+ this.infoHolder = infoHolder;
+ }
+
+ @Override
+ public void afterSessionStart(MavenSession session) throws MavenExecutionException {
+ super.afterSessionStart(session);
+
+ String information = "Build started at " + System.currentTimeMillis();
+ logger.info("extension generated information: " + information);
+ infoHolder.setInformation(information);
+ }
+}
diff --git a/extension/src/main/java/fr/brouillard/oss/maven/InfoHolder.java b/extension/src/main/java/fr/brouillard/oss/maven/InfoHolder.java
new file mode 100644
index 0000000..5a95f2e
--- /dev/null
+++ b/extension/src/main/java/fr/brouillard/oss/maven/InfoHolder.java
@@ -0,0 +1,18 @@
+package fr.brouillard.oss.maven;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+@Named
+@Singleton
+public class InfoHolder {
+ private String information;
+
+ public String getInformation() {
+ return information;
+ }
+
+ public void setInformation(String information) {
+ this.information = information;
+ }
+}
diff --git a/extension/src/main/resources/META-INF/maven/extension.xml b/extension/src/main/resources/META-INF/maven/extension.xml
new file mode 100644
index 0000000..98af7d6
--- /dev/null
+++ b/extension/src/main/resources/META-INF/maven/extension.xml
@@ -0,0 +1,5 @@
+<extension>
+ <exportedPackages>
+ <exportedPackage>fr.brouillard.oss.maven.*</exportedPackage>
+ </exportedPackages>
+</extension>
diff --git a/mojo/pom.xml b/mojo/pom.xml
new file mode 100644
index 0000000..30ed57f
--- /dev/null
+++ b/mojo/pom.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0"?>
+<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>fr.brouillard.oss</groupId>
+ <artifactId>maven-demo-mojo</artifactId>
+ <version>0</version>
+ <name>maven demo plugin</name>
+ <packaging>maven-plugin</packaging>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.version>3.6.3</maven.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model-builder</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${maven.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.6.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>fr.brouillard.oss</groupId>
+ <artifactId>maven-demo-extension</artifactId>
+ <version>0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.sisu</groupId>
+ <artifactId>sisu-maven-plugin</artifactId>
+ <version>0.3.4</version>
+ <executions>
+ <execution>
+ <id>generate-index</id>
+ <goals>
+ <goal>main-index</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.6.0</version>
+ <configuration>
+ <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+ </configuration>
+ <executions>
+ <execution>
+ <id>mojo-descriptor</id>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ <phase>process-classes</phase>
+ </execution>
+ <execution>
+ <id>help-goal</id>
+ <goals>
+ <goal>helpmojo</goal>
+ </goals>
+ <phase>process-classes</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/mojo/src/main/java/fr/brouillard/oss/maven/mojo/InfoMojo.java b/mojo/src/main/java/fr/brouillard/oss/maven/mojo/InfoMojo.java
new file mode 100644
index 0000000..11f5a04
--- /dev/null
+++ b/mojo/src/main/java/fr/brouillard/oss/maven/mojo/InfoMojo.java
@@ -0,0 +1,30 @@
+package fr.brouillard.oss.maven.mojo;
+
+import javax.inject.Inject;
+
+import fr.brouillard.oss.maven.InfoHolder;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+
+@Mojo(name = "info", defaultPhase = LifecyclePhase.VALIDATE, requiresProject = false)
+public class InfoMojo extends AbstractMojo {
+ private InfoHolder infoHolder;
+
+ @Inject
+ public InfoMojo(InfoHolder infoHolder) {
+ this.infoHolder = infoHolder;
+ }
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ String information = infoHolder.getInformation();
+ if (information != null) {
+ getLog().info("Information: " + information);
+ } else {
+ getLog().error("No information provided, Singleton injection might have failed");
+ }
+ }
+}
--
2.3.2 (Apple Git-55)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment