Skip to content

Commit

Permalink
Merge pull request #165 from protean-project/add-setup-mojo
Browse files Browse the repository at this point in the history
Add create, list-extensions and add-extension mojos
  • Loading branch information
stuartwdouglas authored Dec 3, 2018
2 parents 8348221 + 83a48e9 commit 6e54722
Show file tree
Hide file tree
Showing 30 changed files with 2,204 additions and 3 deletions.
143 changes: 140 additions & 3 deletions maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

<artifactId>shamrock-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>

<properties>
<shamrock.version>${project.version}</shamrock.version>

</properties>
<dependencies>

<dependency>
Expand All @@ -37,9 +42,7 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>


<!-- dependencies to annotations -->

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand All @@ -65,7 +68,141 @@
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-development-mode</artifactId>
</dependency>

<!-- user prompt -->
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>2.14.6</version>
</dependency>

<!-- template engine to generate the classes -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.28</version>
</dependency>

<!-- extensions reader -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.7</version>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>*.ftl</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.7.1</version>
<configuration>
<staticMetadataDirectory>${basedir}/target/filtered-resources/META-INF/plexus</staticMetadataDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<goalPrefix>shamrock</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<cloneClean>true</cloneClean>
<settingsFile>src/it/settings.xml</settingsFile>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<postBuildHookScript>verify</postBuildHookScript>
<addTestClassPath>true</addTestClassPath>
<skipInvocation>${skipTests}</skipInvocation>
<streamLogs>true</streamLogs>
<invokerPropertiesFile>invoker.properties</invokerPropertiesFile>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>install</goal>
<goal>run</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<!--suppress MavenModelInspection -->
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>


</project>
35 changes: 35 additions & 0 deletions maven/src/it/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
1 change: 1 addition & 0 deletions maven/src/it/setup-on-existing-pom-it/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:create
31 changes: 31 additions & 0 deletions maven/src/it/setup-on-existing-pom-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<groupId>org.acme</groupId>
<artifactId>shamrock-setup-demo</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
6 changes: 6 additions & 0 deletions maven/src/it/setup-on-existing-pom-it/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.jboss.shamrock.maven.it.SetupVerifier

String base = basedir
File pomFile = new File(base, "pom.xml")

SetupVerifier.verifySetup(pomFile)
1 change: 1 addition & 0 deletions maven/src/it/setup-on-min-pom-it/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:create
25 changes: 25 additions & 0 deletions maven/src/it/setup-on-min-pom-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2016-2018 Red Hat, Inc.
~
~ Red Hat 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.
-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<groupId>org.acme</groupId>
<artifactId>shamrock-setup-demo</artifactId>
<version>0.1-SNAPSHOT</version>
</project>
6 changes: 6 additions & 0 deletions maven/src/it/setup-on-min-pom-it/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.jboss.shamrock.maven.it.SetupVerifier

String base = basedir
File pomFile = new File(base, "pom.xml")

SetupVerifier.verifySetup(pomFile)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:create -DshamrockVersion=0.0.0
30 changes: 30 additions & 0 deletions maven/src/it/setup-with-custom-shamrock-version-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<groupId>org.acme</groupId>
<artifactId>shamrock-setup-demo</artifactId>
<version>0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.jboss.shamrock.maven.it.SetupVerifier

String base = basedir
File pomFile = new File(base, "pom.xml")

SetupVerifier.verifySetupWithVersion(pomFile)
50 changes: 50 additions & 0 deletions maven/src/main/java/org/jboss/shamrock/maven/AddExtensionMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.jboss.shamrock.maven;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import static org.jboss.shamrock.maven.components.dependencies.Extensions.addExtensions;

@Mojo(name = "add-extension", requiresProject = true)
public class AddExtensionMojo extends AbstractMojo {

/**
* The Maven project which will define and configure the shamrock-maven-plugin
*/
@Parameter(defaultValue = "${project}")
protected MavenProject project;

@Parameter(property = "extensions")
private List<String> extensions;


@Override
public void execute() throws MojoExecutionException {
Model model = project.getOriginalModel().clone();
if (addExtensions(model, extensions, getLog())) {
File pomFile = project.getFile();
save(pomFile, model);
}
}

private void save(File pomFile, Model model) throws MojoExecutionException {
MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
try (FileWriter pomFileWriter = new FileWriter(pomFile)) {
xpp3Writer.write(pomFileWriter, model);
pomFileWriter.flush();
} catch (IOException e) {
throw new MojoExecutionException("Unable to write the pom.xml file", e);
}
}

}
Loading

0 comments on commit 6e54722

Please sign in to comment.