Skip to content

Commit 3882b84

Browse files
authored
Merge pull request #30 from klausbrunner/no-commons
use plexus-utils instead of commons-io
2 parents bbb3f97 + 2bbb1da commit 3882b84

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@
6767
<dependency>
6868
<groupId>net.e175.klaus</groupId>
6969
<artifactId>zip-prefixer</artifactId>
70-
<version>0.2.2</version>
70+
<version>0.3.1</version>
7171
</dependency>
72-
<dependency>
73-
<groupId>commons-io</groupId>
74-
<artifactId>commons-io</artifactId>
75-
<version>2.11.0</version>
72+
<dependency> <!-- should become redundant with Java 11 -->
73+
<groupId>org.codehaus.plexus</groupId>
74+
<artifactId>plexus-utils</artifactId>
75+
<version>3.5.1</version>
7676
</dependency>
7777

7878
<dependency>
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.skife.maven</groupId>
9+
<artifactId>test-parent</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>test-011</artifactId>
14+
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>@project.groupId@</groupId>
19+
<artifactId>@project.artifactId@</artifactId>
20+
<version>@project.version@</version>
21+
<configuration>
22+
<programFile>bananas</programFile>
23+
<attachProgramFile>true</attachProgramFile>
24+
</configuration>
25+
<executions>
26+
<execution>
27+
<phase>package</phase>
28+
<goals>
29+
<goal>really-executable-jar</goal>
30+
</goals>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
37+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class App {
2+
public static void main(String[] args) {
3+
System.out.printf("%s %s!%n",
4+
System.getProperty("testapp.greeting", "Hello"),
5+
args.length > 0 ? args[0] : "world");
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.nio.file.Files
2+
3+
File bananaJar = new File(new File(basedir, "target"), 'bananas')
4+
assert bananaJar.exists()
5+
result = bananaJar.toString().execute().text
6+
assert result.contains("Hello world!")
7+
8+
File installedPlainJar = new File(localRepositoryPath, "org/skife/maven/test-011/1.0-SNAPSHOT/test-011-1.0-SNAPSHOT.jar")
9+
assert installedPlainJar.exists()
10+
11+
// seems that Maven will forcibly rename the attached artifact. this monkey gets no banana.
12+
File installedBanana = new File(localRepositoryPath, "org/skife/maven/test-011/1.0-SNAPSHOT/test-011-1.0-SNAPSHOT.sh")
13+
assert installedBanana.exists()
14+
15+
assert Files.size(bananaJar.toPath()) == Files.size(installedBanana.toPath())

src/main/java/org/skife/waffles/ReallyExecutableJarMojo.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package org.skife.waffles;
1515

1616
import net.e175.klaus.zip.ZipPrefixer;
17-
import org.apache.commons.io.IOUtils;
1817
import org.apache.maven.artifact.Artifact;
1918
import org.apache.maven.plugin.AbstractMojo;
2019
import org.apache.maven.plugin.MojoExecutionException;
@@ -24,6 +23,7 @@
2423
import org.apache.maven.plugins.annotations.Parameter;
2524
import org.apache.maven.project.MavenProject;
2625
import org.apache.maven.project.MavenProjectHelper;
26+
import org.codehaus.plexus.util.IOUtil;
2727

2828
import java.io.File;
2929
import java.io.IOException;
@@ -35,6 +35,7 @@
3535
import java.nio.file.Path;
3636
import java.nio.file.Paths;
3737
import java.util.ArrayList;
38+
import java.util.Arrays;
3839
import java.util.List;
3940

4041
import static java.lang.String.format;
@@ -178,7 +179,8 @@ private void makeExecutable(File file)
178179

179180
Path target = file.toPath();
180181
try {
181-
ZipPrefixer.applyPrefixesToZip(target, getPreamble(target.toUri()), "\n\n".getBytes(UTF_8));
182+
ZipPrefixer.applyPrefixBytesToZip(target,
183+
Arrays.asList(getPreamble(target.toUri()), "\n\n".getBytes(UTF_8)));
182184
} catch (IOException e) {
183185
throw new MojoExecutionException(format("Failed to apply prefix to JAR [%s]", file.getAbsolutePath()), e);
184186
}
@@ -204,11 +206,10 @@ private byte[] getPreamble(URI uri) throws MojoExecutionException {
204206
if (scriptIn == null) {
205207
throw new IOException("unable to load " + scriptFile);
206208
}
207-
return IOUtils.toByteArray(scriptIn); // Java 9+: scriptIn.readAllBytes();
209+
return IOUtil.toByteArray(scriptIn); // Java 9+: scriptIn.readAllBytes();
208210
}
209211
} catch (IOException e) {
210212
throw new MojoExecutionException("unable to load preamble data", e);
211213
}
212214
}
213-
214215
}

0 commit comments

Comments
 (0)