Skip to content

Commit 19d7876

Browse files
authored
Merge pull request #21 from wendigo/master
Add support for executable ZIP64 jars
2 parents 4d6cc05 + 834915c commit 19d7876

File tree

4 files changed

+63
-65
lines changed

4 files changed

+63
-65
lines changed

Diff for: .travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: java
22
jdk:
3-
- oraclejdk7
43
- oraclejdk8
54
install: mvn -DskipTests=true -Dbasepom.check.skip-all=true -Dbasepom.it.skip=true -B install
65
script: mvn -B verify

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ To use it, add a plugin to your pom like
7878

7979
Changes:
8080

81+
2.0.0 - support ZIP64 format
82+
- require Java 8, drop support for JDK7
83+
8184
1.4.0 - require Java 7, change code to use JDK7 APIs
8285
- Support Windows
8386
- Don't suppress errors

Diff for: pom.xml

+11-39
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
<parent>
1616
<groupId>org.basepom</groupId>
1717
<artifactId>basepom-standard-oss</artifactId>
18-
<version>9</version>
18+
<version>15</version>
1919
</parent>
2020

2121
<modelVersion>4.0.0</modelVersion>
2222

2323
<groupId>org.skife.maven</groupId>
2424
<artifactId>really-executable-jar-maven-plugin</artifactId>
25-
<version>1.4.2-SNAPSHOT</version>
25+
<version>2.0.0-SNAPSHOT</version>
2626
<packaging>maven-plugin</packaging>
2727

2828
<name>Really Executable Jar Maven Plugin</name>
@@ -53,10 +53,9 @@
5353
</scm>
5454

5555
<properties>
56-
<project.jdk7.home>${env.JAVA7_HOME}</project.jdk7.home>
57-
<project.build.targetJdk>1.7</project.build.targetJdk>
56+
<project.build.targetJdk>1.8</project.build.targetJdk>
5857
<dep.maven-api.version>3.0</dep.maven-api.version>
59-
<dep.plexus.version>1.5.5</dep.plexus.version>
58+
<dep.plexus.version>2.1.1</dep.plexus.version>
6059
<dep.plexus-utils.version>2.0.4</dep.plexus-utils.version>
6160
<dep.plugin.plugin.version>3.4</dep.plugin.plugin.version>
6261
</properties>
@@ -87,6 +86,12 @@
8786
<version>${dep.plexus-utils.version}</version>
8887
</dependency>
8988

89+
<dependency>
90+
<groupId>org.apache.commons</groupId>
91+
<artifactId>commons-compress</artifactId>
92+
<version>1.22</version>
93+
</dependency>
94+
9095
<dependency>
9196
<groupId>org.apache.maven</groupId>
9297
<artifactId>maven-artifact</artifactId>
@@ -195,6 +200,7 @@
195200
<plugin>
196201
<groupId>org.codehaus.mojo</groupId>
197202
<artifactId>findbugs-maven-plugin</artifactId>
203+
<version>3.0.4</version>
198204
<configuration>
199205
<excludeFilterFile>${project.basedir}/src/build/findbugsExcludeFilter.xml</excludeFilterFile>
200206
</configuration>
@@ -211,38 +217,4 @@
211217
</plugin>
212218
</plugins>
213219
</build>
214-
215-
<profiles>
216-
<profile>
217-
<id>travis</id>
218-
<activation>
219-
<property>
220-
<name>env.TRAVIS</name>
221-
</property>
222-
</activation>
223-
<properties>
224-
<project.jdk7.home>${env.JAVA_HOME}</project.jdk7.home>
225-
</properties>
226-
</profile>
227-
<profile>
228-
<id>cross-compile</id>
229-
<activation>
230-
<jdk>(1.7,]</jdk>
231-
</activation>
232-
<build>
233-
<pluginManagement>
234-
<plugins>
235-
<plugin>
236-
<artifactId>maven-compiler-plugin</artifactId>
237-
<configuration>
238-
<compilerArguments children.combine="append">
239-
<bootclasspath>${project.jdk7.home}/jre/lib/rt.jar:${project.jdk7.home}/jre/lib/jce.jar:${project.jdk7.home}/../classes/classes.jar</bootclasspath>
240-
</compilerArguments>
241-
</configuration>
242-
</plugin>
243-
</plugins>
244-
</pluginManagement>
245-
</build>
246-
</profile>
247-
</profiles>
248220
</project>

Diff for: src/main/java/org/skife/waffles/ReallyExecutableJarMojo.java

+49-25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
*/
1414
package org.skife.waffles;
1515

16+
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
17+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
18+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntryPredicate;
19+
import org.apache.commons.compress.archivers.zip.ZipFile;
1620
import org.apache.maven.artifact.Artifact;
1721
import org.apache.maven.plugin.AbstractMojo;
1822
import org.apache.maven.plugin.MojoExecutionException;
@@ -25,10 +29,11 @@
2529
import org.codehaus.plexus.util.FileUtils;
2630
import org.codehaus.plexus.util.IOUtil;
2731

32+
import java.io.ByteArrayOutputStream;
2833
import java.io.File;
29-
import java.io.FileOutputStream;
3034
import java.io.IOException;
3135
import java.io.InputStream;
36+
import java.net.URI;
3237
import java.net.URL;
3338
import java.net.URLClassLoader;
3439
import java.nio.file.Files;
@@ -37,6 +42,12 @@
3742
import java.util.ArrayList;
3843
import java.util.List;
3944

45+
import static java.lang.String.format;
46+
import static java.nio.charset.StandardCharsets.US_ASCII;
47+
import static java.nio.charset.StandardCharsets.UTF_8;
48+
import static java.nio.file.Files.readAllBytes;
49+
import static org.apache.commons.compress.archivers.zip.Zip64Mode.AlwaysWithCompatibility;
50+
4051
/**
4152
* Make an artifact generated by the build really executable. The resulting artifact
4253
* can be run directly from the command line (Java must be installed and in the
@@ -162,39 +173,52 @@ private void makeExecutable(File file)
162173
{
163174
getLog().debug("Making " + file.getAbsolutePath() + " executable");
164175

165-
Path original = Paths.get(file.getAbsolutePath() + ".rx-orig");
176+
Path original = Paths.get(file.getAbsolutePath() + ".original");
166177
Files.move(file.toPath(), original);
167-
try (final FileOutputStream out = new FileOutputStream(file);
168-
final InputStream in = Files.newInputStream(original)) {
178+
try (JarArchiveOutputStream jar = new JarArchiveOutputStream(Files.newOutputStream(file.toPath()))) {
179+
jar.writePreamble(getPreamble(original.toUri()));
180+
jar.setUseZip64(AlwaysWithCompatibility);
181+
jar.setEncoding(UTF_8.name());
182+
183+
try (ZipFile zip = new ZipFile(original.toFile())) {
184+
zip.copyRawEntries(jar, zipArchiveEntry -> true);
185+
}
186+
jar.flush();
187+
jar.finish();
188+
}
189+
finally {
190+
Files.deleteIfExists(original);
191+
}
192+
193+
if (!file.setExecutable(true, false)) {
194+
throw new MojoExecutionException(format("Could not make JAR [%s] executable", file.getAbsolutePath()));
195+
}
196+
getLog().info(format("Successfully made JAR [%s] executable", file.getAbsolutePath()));
197+
}
169198

199+
private byte[] getPreamble(URI uri) throws MojoExecutionException
200+
{
201+
try
202+
{
170203
if (scriptFile == null) {
171-
out.write(("#!/bin/sh\n\nexec java " + flags + " -jar \"$0\" \"$@\"\n\n").getBytes("ASCII"));
204+
return ("#!/bin/sh\n\nexec java " + flags + " -jar \"$0\" \"$@\"\n\n").getBytes(UTF_8);
172205
}
173206
else if (Files.exists(Paths.get(scriptFile))) {
174-
getLog().debug(String.format("Loading file[%s] from filesystem", scriptFile));
175-
176-
byte[] script = Files.readAllBytes(Paths.get(scriptFile));
177-
out.write(script);
178-
out.write(new byte[]{'\n', '\n'});
207+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
208+
outputStream.write(readAllBytes(Paths.get(scriptFile)));
209+
outputStream.write("\n\n".getBytes(US_ASCII));
210+
return outputStream.toByteArray();
179211
}
180-
else {
181-
getLog().debug(String.format("Loading file[%s] from jar[%s]", scriptFile, original));
182-
183-
try (final URLClassLoader loader = new URLClassLoader(new URL[]{original.toUri().toURL()}, null);
184-
final InputStream scriptIn = loader.getResourceAsStream(scriptFile)) {
185212

186-
out.write(IOUtil.toString(scriptIn).getBytes("ASCII"));
187-
out.write("\n\n".getBytes("ASCII"));
188-
}
213+
try (final URLClassLoader loader = new URLClassLoader(new URL[]{uri.toURL()}, null); final InputStream scriptIn = loader.getResourceAsStream(scriptFile)) {
214+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
215+
outputStream.write(IOUtil.toString(scriptIn).getBytes(UTF_8));
216+
outputStream.write("\n\n".getBytes(UTF_8));
217+
return outputStream.toByteArray();
189218
}
190-
IOUtil.copy(in, out);
191219
}
192-
finally {
193-
Files.deleteIfExists(original);
220+
catch (IOException e) {
221+
throw new MojoExecutionException(e.getMessage());
194222
}
195-
196-
file.setExecutable(true, false);
197-
198-
getLog().info(String.format("Successfully made JAR [%s] executable", file.getAbsolutePath()));
199223
}
200224
}

0 commit comments

Comments
 (0)