-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
247 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,5 @@ | ||
.metadata | ||
.settings | ||
target | ||
.project | ||
.classpath |
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,13 @@ | ||
# farsight-wm-parent | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-silver.svg)](https://opensource.org/licenses/MIT) | ||
|
||
A small maven-plugin assisting in building IS-packages that depend on jar files. | ||
|
||
## Features | ||
- copy jar files from compile or runtime dependencies into the code/jars (/static) directory of the is package. | ||
|
||
## Nice-to-Have Features | ||
- compile java services | ||
- create java service nodes from annotations in the source code | ||
- create importable zip archive | ||
- create/update entries in mainfest.v3 |
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,85 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>farsight-wm</groupId> | ||
<artifactId>is-package-maven-plugin</artifactId> | ||
|
||
<packaging>maven-plugin</packaging> | ||
|
||
<version>1.0.0</version> | ||
<name>farsight-wm:is-package-maven-plugin</name> | ||
<url>https://github.com/farsight-wm/is-package-maven-plugin</url> | ||
|
||
<issueManagement> | ||
<url>https://github.com/farsight-wm/parent/is-package-maven-plugin</url> | ||
<system>GitHub.com</system> | ||
</issueManagement> | ||
|
||
<scm> | ||
<url>https://github.com/farsight-wm/is-package-maven-plugin</url> | ||
<connection>scm:git:https://github.com/farsight-wm/is-package-maven-plugin.git</connection> | ||
<developerConnection>scm:git:https://github.com/farsight-wm/is-package-maven-plugin.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<licenses> | ||
<license> | ||
<name>The MIT License (MIT)</name> | ||
<url>https://opensource.org/licenses/MIT</url> | ||
<distribution>manual</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<name>Cornelius Wicke</name> | ||
<url>https://www.xing.com/profile/Cornelius_Wicke</url> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<version>2.0</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>org.apache.maven</groupId> | ||
<artifactId>maven-project</artifactId> | ||
<version>2.2.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.7</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>3.3.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
41 changes: 41 additions & 0 deletions
41
src/main/java/farsight/ispackage/mojo/IsPackageDefinition.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,41 @@ | ||
package farsight.ispackage.mojo; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
public class IsPackageDefinition { | ||
|
||
public static class IsJarDependency { | ||
@Parameter | ||
public boolean staticJar = false; | ||
|
||
@Parameter(required = true) | ||
public String id; | ||
|
||
@Parameter(required = false) | ||
public String filename; | ||
|
||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.append("id", id) | ||
.build(); | ||
} | ||
} | ||
|
||
|
||
@Parameter(required = true) | ||
public String name; | ||
|
||
@Parameter(required = false) | ||
public List<IsJarDependency> jars; | ||
|
||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.append("name", name) | ||
.append("jars", jars) | ||
.build(); | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/farsight/ispackage/mojo/IsPackageMojo.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,103 @@ | ||
package farsight.ispackage.mojo; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.util.FileUtils; | ||
|
||
import farsight.ispackage.mojo.IsPackageDefinition.IsJarDependency; | ||
|
||
/** | ||
* Mojo that copies required jar file into an is package | ||
*/ | ||
@Mojo(name = "is-package", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) | ||
public class IsPackageMojo extends AbstractMojo { | ||
|
||
@Parameter(defaultValue = "src/is") | ||
public String source; | ||
|
||
@Parameter(defaultValue = "target/is") | ||
public String target; | ||
|
||
@Parameter(required = true) | ||
public List<IsPackageDefinition> packages; | ||
|
||
@Parameter(defaultValue = "${project}", readonly = true, required = true) | ||
private MavenProject project; | ||
|
||
private File sourceBase; | ||
private File targetBase; | ||
|
||
public void execute() throws MojoExecutionException { | ||
sourceBase = new File(project.getBasedir(), source); | ||
targetBase = new File(project.getBasedir(), target); | ||
|
||
for (IsPackageDefinition isPackage : packages) { | ||
buildIsPackage(isPackage); | ||
} | ||
} | ||
|
||
private void buildIsPackage(IsPackageDefinition isPackage) throws MojoExecutionException { | ||
getLog().info("Building IS-Package: " + isPackage.name); | ||
|
||
File pkgSource = new File(sourceBase, isPackage.name); | ||
File pkgTarget = new File(targetBase, isPackage.name); | ||
|
||
if (!pkgSource.isDirectory()) { | ||
throw new MojoExecutionException("IS-Package source not found at: " + pkgSource); | ||
} | ||
|
||
pkgTarget.mkdirs(); | ||
|
||
try { | ||
FileUtils.copyDirectoryStructureIfModified(pkgSource, pkgTarget); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Error copying source files", e); | ||
} | ||
|
||
if (isPackage.jars != null) { | ||
// append jars | ||
|
||
File jars = new File(pkgTarget, "code/jars"); | ||
File staticJars = new File(jars, "static"); | ||
|
||
for (IsJarDependency jar : isPackage.jars) { | ||
Artifact artifact = getArtifact(jar); | ||
if (artifact == null) | ||
throw new MojoExecutionException("Artifact is not a dependency: " + jar.id); | ||
|
||
getLog().info("Adding jar: " + artifact); | ||
File outDirectory = jar.staticJar ? staticJars : jars; | ||
outDirectory.mkdirs(); | ||
|
||
File jarFile = artifact.getFile(); | ||
if (jarFile == null || !jarFile.canRead()) | ||
throw new MojoExecutionException("Cannot read artifact file: " + jarFile); | ||
|
||
File output = new File(outDirectory, jar.filename == null ? jarFile.getName() : jar.filename); | ||
|
||
try { | ||
FileUtils.copyFile(jarFile, output); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Cannot copy artifact file: " + jarFile, e); | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
private Artifact getArtifact(IsJarDependency jar) { | ||
return jar.id.equals(project.getGroupId() + ":" + project.getArtifactId()) ? project.getArtifact() | ||
: (Artifact) project.getArtifactMap().get(jar.id); | ||
} | ||
} |