Skip to content

Commit d6cc655

Browse files
authored
Merge pull request #190 from orphan-oss/implement-skip
Implements skip option or skipLaunch4j property
2 parents d68c843 + a95e996 commit d6cc655

File tree

7 files changed

+441
-77
lines changed

7 files changed

+441
-77
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
version: 2
22
updates:
3-
- package-ecosystem: maven
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "04:00"
8-
open-pull-requests-limit: 10
9-
ignore:
10-
- dependency-name: org.apache.maven:maven-compat
11-
versions:
12-
- 3.8.1
3+
- package-ecosystem: "maven"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
ignore:
8+
- dependency-name: org.apache.maven:maven-compat
9+
versions:
10+
- 3.8.1
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"

.github/workflows/maven.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,32 @@
1515

1616
name: Java CI
1717

18-
on: [push, pull_request]
18+
on:
19+
pull_request:
20+
push:
21+
branches:
22+
- master
1923

2024
jobs:
2125
build:
22-
2326
runs-on: ubuntu-latest
24-
continue-on-error: ${{ matrix.experimental }}
2527
strategy:
2628
matrix:
27-
java: [ 8, 11, 16 ]
28-
experimental: [false]
29-
include:
30-
- java: 17-ea
31-
experimental: true
32-
29+
java: [ 8, 11, 17 ]
3330
steps:
34-
- uses: actions/[email protected]
35-
- uses: actions/[email protected]
36-
with:
37-
path: ~/.m2/repository
38-
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
39-
restore-keys: |
40-
${{ runner.os }}-maven-
41-
- name: Set up JDK ${{ matrix.java }}
42-
uses: actions/setup-java@v2
43-
with:
44-
distribution: adopt
45-
java-version: ${{ matrix.java }}
46-
- name: Build with Maven
47-
run: mvn -V test -Ddoclint=all --file pom.xml --no-transfer-progress
31+
- name: Checkout code
32+
uses: actions/[email protected]
33+
- name: Set up cache
34+
uses: actions/[email protected]
35+
with:
36+
path: ~/.m2/repository
37+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
38+
restore-keys: |
39+
${{ runner.os }}-maven-
40+
- name: Set up JDK ${{ matrix.java }}
41+
uses: actions/setup-java@v3
42+
with:
43+
distribution: adopt
44+
java-version: ${{ matrix.java }}
45+
- name: Build with Maven on Java ${{ matrix.java }}
46+
run: mvn -V test -Ddoclint=all --file pom.xml --no-transfer-progress

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ Originally hosted at http://9stmaryrd.com/tools/launch4j-maven-plugin/
1212

1313
# Documentation
1414

15-
Please check [this](src/main/resources/README.adoc) document for more detailed info on how to use the plugin. Please also check [Launch4j's Configuration file](http://launch4j.sourceforge.net/docs.html#Configuration_file) page.
15+
Please check [this](src/main/resources/README.adoc) document for more detailed info on how to use the plugin.
16+
Please also check [Launch4j's Configuration file](http://launch4j.sourceforge.net/docs.html#Configuration_file) page.
17+
The full list of all the parameters is available [here](src/main/resources/MOJO.md)
1618

1719
**NOTE**: Since version 2.0.x this plugin requires to be used with Maven 3.6.x at least.
1820

@@ -179,3 +181,9 @@ A: Yes but you will have to install these libs to avoid problems:
179181
- bzip2-libs.i686
180182

181183
See [#4](../../issues/4) for more details.
184+
185+
Q: How can I skip execution of the plugin?
186+
187+
A: You can either use `<skip>true</skip>` configuration option or provide `-DskipLaunch4j` property to JVM
188+
189+
See PR [#190](../../pull/190) for more details.

pom.xml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@
158158
</execution>
159159
</executions>
160160
</plugin>
161+
<plugin>
162+
<groupId>org.apache.maven.plugins</groupId>
163+
<artifactId>maven-site-plugin</artifactId>
164+
<version>3.9.0</version>
165+
<configuration>
166+
<relativizeDecorationLinks>false</relativizeDecorationLinks>
167+
</configuration>
168+
<dependencies>
169+
<dependency>
170+
<groupId>org.apache.maven.doxia</groupId>
171+
<artifactId>doxia-core</artifactId>
172+
<version>1.9.1</version>
173+
</dependency>
174+
<dependency>
175+
<groupId>org.apache.maven.doxia</groupId>
176+
<artifactId>doxia-module-markdown</artifactId>
177+
<version>1.9.1</version>
178+
</dependency>
179+
</dependencies>
180+
</plugin>
161181
</plugins>
162182
</build>
163183

@@ -215,21 +235,22 @@
215235
<reports>
216236
<report>index</report>
217237
<report>summary</report>
218-
<report>license</report>
238+
<report>licenses</report>
219239
<report>dependencies</report>
240+
<report>plugins</report>
220241
</reports>
221242
</reportSet>
222243
</reportSets>
223244
</plugin>
224245
<plugin>
225246
<groupId>org.apache.maven.plugins</groupId>
226-
<artifactId>maven-javadoc-plugin</artifactId>
227-
<version>3.4.1</version>
247+
<artifactId>maven-plugin-plugin</artifactId>
248+
<version>3.6.4</version>
228249
</plugin>
229250
<plugin>
230251
<groupId>org.apache.maven.plugins</groupId>
231-
<artifactId>maven-surefire-report-plugin</artifactId>
232-
<version>2.22.2</version>
252+
<artifactId>maven-javadoc-plugin</artifactId>
253+
<version>3.4.1</version>
233254
</plugin>
234255
</plugins>
235256
</reporting>

src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,11 @@
1818
*/
1919
package com.akathist.maven.plugins.launch4j;
2020

21-
import java.io.File;
22-
import java.io.FileOutputStream;
23-
import java.io.IOException;
24-
import java.io.InputStream;
25-
import java.nio.file.Files;
26-
import java.nio.file.Path;
27-
import java.nio.file.StandardCopyOption;
28-
import java.util.ArrayList;
29-
import java.util.Date;
30-
import java.util.Enumeration;
31-
import java.util.List;
32-
import java.util.Set;
33-
import java.util.jar.JarEntry;
34-
import java.util.jar.JarFile;
35-
21+
import net.sf.launch4j.Builder;
22+
import net.sf.launch4j.BuilderException;
23+
import net.sf.launch4j.config.Config;
24+
import net.sf.launch4j.config.ConfigPersister;
25+
import net.sf.launch4j.config.ConfigPersisterException;
3626
import org.apache.maven.artifact.Artifact;
3727
import org.apache.maven.artifact.repository.ArtifactRepository;
3828
import org.apache.maven.execution.MavenSession;
@@ -50,20 +40,29 @@
5040
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
5141
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
5242

53-
import net.sf.launch4j.Builder;
54-
import net.sf.launch4j.BuilderException;
55-
import net.sf.launch4j.config.Config;
56-
import net.sf.launch4j.config.ConfigPersister;
57-
import net.sf.launch4j.config.ConfigPersisterException;
43+
import java.io.File;
44+
import java.io.FileOutputStream;
45+
import java.io.IOException;
46+
import java.io.InputStream;
47+
import java.nio.file.Files;
48+
import java.nio.file.Path;
49+
import java.nio.file.StandardCopyOption;
50+
import java.util.ArrayList;
51+
import java.util.Date;
52+
import java.util.Enumeration;
53+
import java.util.List;
54+
import java.util.Set;
55+
import java.util.jar.JarEntry;
56+
import java.util.jar.JarFile;
5857

5958
/**
6059
* Wraps a jar in a Windows executable.
6160
*/
6261
@Mojo(
63-
name = "launch4j",
64-
defaultPhase = LifecyclePhase.PACKAGE,
65-
requiresDependencyResolution = ResolutionScope.RUNTIME,
66-
threadSafe = true
62+
name = "launch4j",
63+
defaultPhase = LifecyclePhase.PACKAGE,
64+
requiresDependencyResolution = ResolutionScope.RUNTIME,
65+
threadSafe = true
6766
)
6867
public class Launch4jMojo extends AbstractMojo {
6968

@@ -74,7 +73,7 @@ public class Launch4jMojo extends AbstractMojo {
7473
/**
7574
* Maven Session.
7675
*/
77-
@Parameter (defaultValue = "${session}", required = true, readonly = true)
76+
@Parameter(defaultValue = "${session}", required = true, readonly = true)
7877
private MavenSession session;
7978

8079
/**
@@ -118,7 +117,7 @@ public class Launch4jMojo extends AbstractMojo {
118117
* Used to get the Launch4j artifact version.
119118
*/
120119
@Parameter(defaultValue = "${plugin.artifacts}")
121-
private java.util.List<Artifact> pluginArtifacts;
120+
private List<Artifact> pluginArtifacts;
122121

123122
/**
124123
* The base of the current project.
@@ -314,6 +313,12 @@ public class Launch4jMojo extends AbstractMojo {
314313
@Parameter(defaultValue = "false")
315314
private boolean parallelExecution = false;
316315

316+
/**
317+
* If set to true, execution of the plugin will be skipped
318+
*/
319+
@Parameter(defaultValue = "false")
320+
private boolean skip = false;
321+
317322
private File getJar() {
318323
return new File(jar);
319324
}
@@ -330,20 +335,25 @@ public void execute() throws MojoExecutionException {
330335
}
331336

332337
private void doExecute() throws MojoExecutionException {
338+
if (this.skipExecution()) {
339+
getLog().debug("Skipping execution of the plugin");
340+
return;
341+
}
342+
333343
final File workDir = setupBuildEnvironment();
334344
if (infile != null) {
335345
if (infile.exists()) {
336346
try {
337347
if (getLog().isDebugEnabled()) {
338348
getLog().debug("Trying to load Launch4j native configuration using file=" + infile.getAbsolutePath());
339349
}
340-
// load launch4j configfile from <infile>
350+
// load launch4j config file from <infile>
341351
ConfigPersister.getInstance().load(infile);
342352

343353
// overwrite several properties analogous to the ANT task
344354
// https://sourceforge.net/p/launch4j/git/ci/master/tree/src/net/sf/launch4j/ant/Launch4jTask.java#l84
345355

346-
// retreive the loaded configuration for manipulation
356+
// retrieve the loaded configuration for manipulation
347357
Config c = ConfigPersister.getInstance().getConfig();
348358

349359
String jarDefaultValue = project.getBuild().getDirectory() + "/" + project.getBuild().getFinalName() + ".jar";
@@ -500,7 +510,7 @@ private void createParentFolder() {
500510
* Writes a marker file to prevent unzipping more than once.
501511
*/
502512
private File unpackWorkDir(Artifact artifact) throws MojoExecutionException {
503-
Artifact localArtifact= localRepository.find(artifact);
513+
Artifact localArtifact = localRepository.find(artifact);
504514
if (localArtifact == null || localArtifact.getFile() == null) {
505515
throw new MojoExecutionException("Cannot obtain file path to " + artifact);
506516
}
@@ -520,7 +530,7 @@ private File unpackWorkDir(Artifact artifact) throws MojoExecutionException {
520530
getLog().info("Platform-specific work directory already exists: " + workdir.getAbsolutePath());
521531
} else {
522532
// trying to use plexus-archiver here is a miserable waste of time:
523-
try(JarFile jf = new JarFile(platJar)){
533+
try (JarFile jf = new JarFile(platJar)) {
524534
Enumeration<JarEntry> en = jf.entries();
525535
while (en.hasMoreElements()) {
526536
JarEntry je = en.nextElement();
@@ -533,8 +543,8 @@ private File unpackWorkDir(Artifact artifact) throws MojoExecutionException {
533543
if (je.isDirectory()) {
534544
outFile.mkdirs();
535545
} else {
536-
try(InputStream in = jf.getInputStream(je)){
537-
try (FileOutputStream fout = new FileOutputStream(outFile)){
546+
try (InputStream in = jf.getInputStream(je)) {
547+
try (FileOutputStream fout = new FileOutputStream(outFile)) {
538548
byte[] buf = new byte[1024];
539549
int len;
540550
while ((len = in.read(buf)) >= 0) {
@@ -658,7 +668,7 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
658668
}
659669

660670
return factory.createArtifactWithClassifier(LAUNCH4J_GROUP_ID, LAUNCH4J_ARTIFACT_ID,
661-
getLaunch4jVersion(), "jar", "workdir-" + plat);
671+
getLaunch4jVersion(), "jar", "workdir-" + plat);
662672
}
663673

664674
private File getBaseDir() {
@@ -755,20 +765,20 @@ private void printState() {
755765
}
756766

757767
/**
758-
* The Launch4j version used by the plugin.
768+
* A version of the Launch4j used by the plugin.
759769
* We want to download the platform-specific bundle whose version matches the Launch4j version,
760770
* so we have to figure out what version the plugin is using.
761771
*
762-
* @return
763-
* @throws MojoExecutionException
772+
* @return version of Launch4j
773+
* @throws MojoExecutionException when version is null
764774
*/
765775
private String getLaunch4jVersion() throws MojoExecutionException {
766776
String version = null;
767777

768778
for (Artifact artifact : pluginArtifacts) {
769779
if (LAUNCH4J_GROUP_ID.equals(artifact.getGroupId()) &&
770-
LAUNCH4J_ARTIFACT_ID.equals(artifact.getArtifactId())
771-
&& "core".equals(artifact.getClassifier())) {
780+
LAUNCH4J_ARTIFACT_ID.equals(artifact.getArtifactId())
781+
&& "core".equals(artifact.getClassifier())) {
772782

773783
version = artifact.getVersion();
774784
getLog().debug("Found launch4j version " + version);
@@ -782,4 +792,16 @@ private String getLaunch4jVersion() throws MojoExecutionException {
782792

783793
return version;
784794
}
795+
796+
/**
797+
* Checks if execution of the plugin should be skipped
798+
*
799+
* @return true to skip execution
800+
*/
801+
private boolean skipExecution() {
802+
getLog().debug("skip = " + this.skip);
803+
getLog().debug("skipLaunch4j = " + System.getProperty("skipLaunch4j"));
804+
return skip || System.getProperty("skipLaunch4j") != null;
805+
}
806+
785807
}

0 commit comments

Comments
 (0)