Adding new maven-shade-plugin ResourceTransformer
+ IncludeDirectoryTransformer allows for arbitrarily
including a directory into the jar file.
diff --git a/jetty-build-support/pom.xml b/jetty-build-support/pom.xml
index 65da17a..6c35d06 100644
--- a/jetty-build-support/pom.xml
+++ b/jetty-build-support/pom.xml
@@ -13,7 +13,8 @@
<name>Jetty Toolchain :: Build Support</name>
<description>Build Support for Jetty (Contains Enforcer Rules, PMD Rulesets, etc ...)</description>
<properties>
- <api.version>1.0-beta-1</api.version>
+ <enforcer.version>1.0-beta-1</enforcer.version>
+ <shade.version>2.3</shade.version>
<maven.version>2.0.9</maven.version>
</properties>
<build>
@@ -54,7 +55,12 @@
<dependency>
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer-api</artifactId>
- <version>${api.version}</version>
+ <version>${enforcer.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>${shade.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
diff --git a/jetty-build-support/src/main/java/org/eclipse/jetty/toolchain/shade/IncludeDirectoryTransformer.java b/jetty-build-support/src/main/java/org/eclipse/jetty/toolchain/shade/IncludeDirectoryTransformer.java
new file mode 100644
index 0000000..2b2830b
--- /dev/null
+++ b/jetty-build-support/src/main/java/org/eclipse/jetty/toolchain/shade/IncludeDirectoryTransformer.java
@@ -0,0 +1,103 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.toolchain.shade;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardOpenOption;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.plugins.shade.relocation.Relocator;
+import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Include arbitrary directory in shaded jar
+ */
+public class IncludeDirectoryTransformer implements ResourceTransformer
+{
+ public static boolean DEBUG = false;
+
+ private static class DirectoryCopier extends SimpleFileVisitor<Path>
+ {
+ private final Path basePath;
+ private final JarOutputStream jos;
+
+ public DirectoryCopier(Path basePath, JarOutputStream jos)
+ {
+ this.basePath = basePath;
+ this.jos = jos;
+ }
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
+ {
+ String entryName = basePath.relativize(file).toString();
+ debug("entryName = %s",entryName);
+
+ jos.putNextEntry(new JarEntry(entryName));
+
+ InputStream in = Files.newInputStream(file, StandardOpenOption.READ);
+ IOUtil.copy(in,jos);
+ IOUtil.close(in);
+
+ return super.visitFile(file,attrs);
+ }
+
+ public void debug(String format, Object... args)
+ {
+ if (DEBUG)
+ {
+ System.err.printf("## " + this.getClass().getSimpleName() + " " + format + "%n",args);
+ }
+ }
+ }
+
+ File directory;
+
+ public boolean canTransformResource(String resource)
+ {
+ return false;
+ }
+
+ public boolean hasTransformedResource()
+ {
+ return directory != null ? directory.exists() : false;
+ }
+
+ public void modifyOutputStream(JarOutputStream jos) throws IOException
+ {
+ // Copy all of the resources in directory to JAR
+ Path basePath = directory.toPath();
+ Files.walkFileTree(basePath,new DirectoryCopier(basePath,jos));
+ }
+
+ public void processResource(String resource, InputStream is, List<Relocator> relocators) throws IOException
+ {
+ // do nothing
+ }
+}