Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added Maven Plugin as a module
- Loading branch information
Showing
5 changed files
with
427 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Forge Maven Extensions | ||
|
||
This project contains a MOJO to create .FAR (Forge Archive) files. | ||
|
||
## Usage | ||
<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> | ||
<groupId>com.example.app</groupId> | ||
<artifactId>example-far</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>far</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>maven-far-plugin</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
|
||
</build> | ||
</project> |
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,148 @@ | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.jboss</groupId> | ||
<artifactId>jboss-parent</artifactId> | ||
<version>6</version> | ||
</parent> | ||
|
||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>maven-far-plugin</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>maven-plugin</packaging> | ||
<name>Forge - Maven Plugin</name> | ||
<url>http://forge.jboss.org</url> | ||
|
||
<prerequisites> | ||
<maven>3.0</maven> | ||
</prerequisites> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<forge.scm.connection>scm:git:git://github.com/forge/maven-extensions.git</forge.scm.connection> | ||
<forge.developer.connection>scm:git:git@github.com:forge/maven-extensions.git</forge.developer.connection> | ||
<forge.scm.url>http://github.com/forge/maven-extensions</forge.scm.url> | ||
|
||
<maven.version>3.0.4</maven.version> | ||
</properties> | ||
|
||
<licenses> | ||
<license> | ||
<name>Eclipse Public License version 1.0</name> | ||
<url>http://www.eclipse.org/legal/epl-v10.html</url> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>lincoln</id> | ||
<name>Lincoln Baxter, III</name> | ||
<email>lincolnbaxter@gmail.com</email> | ||
</developer> | ||
<developer> | ||
<id>koen</id> | ||
<name>Koen Aers</name> | ||
<email>koen.aers@gmail.com</email> | ||
</developer> | ||
<developer> | ||
<id>gastaldi</id> | ||
<name>George Gastaldi</name> | ||
<email>gegastaldi@gmail.com</email> | ||
</developer> | ||
</developers> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-core</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</groupId> | ||
<artifactId>maven-artifact</artifactId> | ||
<version>${maven.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-archiver</artifactId> | ||
<version>2.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>3.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<scm> | ||
<connection>${forge.scm.connection}</connection> | ||
<developerConnection>${forge.developer.connection}</developerConnection> | ||
<url>${forge.scm.url}</url> | ||
</scm> | ||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<version>3.1</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<configuration> | ||
<goalPrefix>forge</goalPrefix> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>generated-helpmojo</id> | ||
<goals> | ||
<goal>helpmojo</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<inherited>true</inherited> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> | ||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
199 changes: 199 additions & 0 deletions
199
maven-far-plugin/src/main/java/org/jboss/forge/maven/packaging/ForgeArchiveMojo.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,199 @@ | ||
/* | ||
* Copyright 2012 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.maven.packaging; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.apache.maven.archiver.MavenArchiveConfiguration; | ||
import org.apache.maven.archiver.MavenArchiver; | ||
import org.apache.maven.artifact.DependencyResolutionRequiredException; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.project.MavenProject; | ||
import org.apache.maven.project.MavenProjectHelper; | ||
import org.codehaus.plexus.archiver.ArchiverException; | ||
import org.codehaus.plexus.archiver.jar.JarArchiver; | ||
import org.codehaus.plexus.archiver.jar.ManifestException; | ||
import org.codehaus.plexus.util.FileUtils; | ||
|
||
/** | ||
* Builds a FAR file. | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* @goal far | ||
* @phase package | ||
* @threadSafe | ||
* @requiresDependencyResolution runtime | ||
*/ | ||
public class ForgeArchiveMojo extends AbstractMojo | ||
{ | ||
private static final String FORGE_XML = "META-INF/forge.xml"; | ||
private static final String[] DEFAULT_EXCLUDES = new String[] { "**/package.html" }; | ||
private static final String[] DEFAULT_INCLUDES = new String[] { "**/**" }; | ||
|
||
/** | ||
* Directory containing the generated JAR. | ||
* | ||
* @parameter default-value="${project.build.directory}" | ||
* @required | ||
*/ | ||
private File outputDirectory; | ||
|
||
/** | ||
* Directory containing the classes and resource files that should be packaged into the JAR. | ||
* | ||
* @parameter default-value="${project.build.outputDirectory}" | ||
* @required | ||
*/ | ||
private File classesDirectory; | ||
|
||
/** | ||
* Name of the generated FAR. | ||
* | ||
* @parameter alias="farName" property="finalName" default-value="${project.build.finalName}" | ||
* @required | ||
*/ | ||
private String finalName; | ||
|
||
/** | ||
* Classifier to add to the generated FAR. If given, the artifact will be an attachment instead. The classifier will | ||
* not be applied to the JAR file of the project - only to the FAR file. | ||
* | ||
* @parameter | ||
*/ | ||
private String classifier; | ||
|
||
/** | ||
* The Maven project. | ||
* | ||
* @parameter default-value="${project}" | ||
* @required | ||
* @readonly | ||
*/ | ||
private MavenProject project; | ||
|
||
/** | ||
* The JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib. | ||
* | ||
* @component role="org.codehaus.plexus.archiver.Archiver" role-hint="jar" | ||
* @required | ||
*/ | ||
private JarArchiver jarArchiver; | ||
|
||
/** | ||
* The Maven project's helper. | ||
* | ||
* @component | ||
*/ | ||
private MavenProjectHelper projectHelper; | ||
|
||
/** | ||
* The archive configuration to use. See <a href="http://maven.apache.org/shared/maven-archiver/index.html">Maven | ||
* Archiver Reference</a>. | ||
* | ||
* @parameter | ||
*/ | ||
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); | ||
|
||
/** | ||
* @parameter default-value="${session}" | ||
* @readonly | ||
* @required | ||
*/ | ||
private MavenSession session; | ||
|
||
/** | ||
* Generates an FAR jar and optionally an FAR-client jar. | ||
*/ | ||
public void execute() | ||
throws MojoExecutionException | ||
{ | ||
if (getLog().isInfoEnabled()) | ||
{ | ||
getLog().info("Building FAR " + finalName); | ||
} | ||
|
||
File farFile = getFarFile(outputDirectory, finalName, classifier); | ||
|
||
MavenArchiver archiver = new MavenArchiver(); | ||
|
||
archiver.setArchiver(jarArchiver); | ||
|
||
archiver.setOutputFile(farFile); | ||
|
||
File deploymentDescriptor = new File(outputDirectory, FORGE_XML); | ||
|
||
try | ||
{ | ||
archiver.getArchiver().addDirectory(classesDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES); | ||
|
||
if (!deploymentDescriptor.exists()) | ||
{ | ||
// File does not exists, create and add some content | ||
deploymentDescriptor.getParentFile().mkdir(); | ||
deploymentDescriptor.createNewFile(); | ||
FileUtils.fileWrite(deploymentDescriptor, "<forge/>"); | ||
} | ||
// Adding descriptor to file | ||
archiver.getArchiver().addFile(deploymentDescriptor, FORGE_XML); | ||
|
||
// create archive | ||
archiver.createArchive(session, project, archive); | ||
} | ||
catch (ArchiverException e) | ||
{ | ||
throw new MojoExecutionException("There was a problem creating the FAR archive: " + e.getMessage(), e); | ||
} | ||
catch (ManifestException e) | ||
{ | ||
throw new MojoExecutionException("There was a problem creating the FAR archive: " + e.getMessage(), e); | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new MojoExecutionException("There was a problem creating the FAR archive: " + e.getMessage(), e); | ||
} | ||
catch (DependencyResolutionRequiredException e) | ||
{ | ||
throw new MojoExecutionException("There was a problem creating the FAR archive: " + e.getMessage(), e); | ||
} | ||
|
||
// Handle the classifier if necessary | ||
if (classifier != null) | ||
{ | ||
projectHelper.attachArtifact(project, "far", classifier, farFile); | ||
} | ||
else | ||
{ | ||
project.getArtifact().setFile(farFile); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the FAR Jar file to generate, based on an optional classifier. | ||
* | ||
* @param basedir the output directory | ||
* @param finalName the name of the ear file | ||
* @param classifier an optional classifier | ||
* @return the FAR file to generate | ||
*/ | ||
private static File getFarFile(File basedir, String finalName, String classifier) | ||
{ | ||
if (classifier == null) | ||
{ | ||
classifier = ""; | ||
} | ||
else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) | ||
{ | ||
classifier = "-" + classifier; | ||
} | ||
|
||
return new File(basedir, finalName + classifier + ".far"); | ||
} | ||
} |
Oops, something went wrong.