Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements skip option or skipLaunch4j property #190

Merged
merged 8 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
version: 2
updates:
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: org.apache.maven:maven-compat
versions:
- 3.8.1
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: org.apache.maven:maven-compat
versions:
- 3.8.1
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
6 changes: 1 addition & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
java: [ 8, 11, 16 ]
experimental: [false]
include:
- java: 17-ea
experimental: true
java: [ 8, 11, 17 ]

steps:
- uses: actions/[email protected]
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Originally hosted at http://9stmaryrd.com/tools/launch4j-maven-plugin/

# Documentation

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.
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.
The full list of all the parameters is available [here](src/main/resources/MOJO.md)

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

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

See [#4](../../issues/4) for more details.

Q: How can I skip execution of the plugin?

A: You can either use `<skip>true</skip>` configuration option or provide `-DskipLaunch4j` property to JVM

See PR [#190](../../pull/190) for more details.
31 changes: 26 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.0</version>
<configuration>
<relativizeDecorationLinks>false</relativizeDecorationLinks>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-module-markdown</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -215,21 +235,22 @@
<reports>
<report>index</report>
<report>summary</report>
<report>license</report>
<report>licenses</report>
<report>dependencies</report>
<report>plugins</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.22.2</version>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
</plugin>
</plugins>
</reporting>
Expand Down
98 changes: 60 additions & 38 deletions src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@
*/
package com.akathist.maven.plugins.launch4j;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import net.sf.launch4j.Builder;
import net.sf.launch4j.BuilderException;
import net.sf.launch4j.config.Config;
import net.sf.launch4j.config.ConfigPersister;
import net.sf.launch4j.config.ConfigPersisterException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
Expand All @@ -50,20 +40,29 @@
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;

import net.sf.launch4j.Builder;
import net.sf.launch4j.BuilderException;
import net.sf.launch4j.config.Config;
import net.sf.launch4j.config.ConfigPersister;
import net.sf.launch4j.config.ConfigPersisterException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
* Wraps a jar in a Windows executable.
*/
@Mojo(
name = "launch4j",
defaultPhase = LifecyclePhase.PACKAGE,
requiresDependencyResolution = ResolutionScope.RUNTIME,
threadSafe = true
name = "launch4j",
defaultPhase = LifecyclePhase.PACKAGE,
requiresDependencyResolution = ResolutionScope.RUNTIME,
threadSafe = true
)
public class Launch4jMojo extends AbstractMojo {

Expand All @@ -74,7 +73,7 @@ public class Launch4jMojo extends AbstractMojo {
/**
* Maven Session.
*/
@Parameter (defaultValue = "${session}", required = true, readonly = true)
@Parameter(defaultValue = "${session}", required = true, readonly = true)
private MavenSession session;

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

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

/**
* If set to true, execution of the plugin will be skipped
*/
@Parameter(defaultValue = "false")
private boolean skip = false;

private File getJar() {
return new File(jar);
}
Expand All @@ -330,20 +335,25 @@ public void execute() throws MojoExecutionException {
}

private void doExecute() throws MojoExecutionException {
if (this.skipExecution()) {
getLog().debug("Skipping execution of the plugin");
return;
}

final File workDir = setupBuildEnvironment();
if (infile != null) {
if (infile.exists()) {
try {
if (getLog().isDebugEnabled()) {
getLog().debug("Trying to load Launch4j native configuration using file=" + infile.getAbsolutePath());
}
// load launch4j configfile from <infile>
// load launch4j config file from <infile>
ConfigPersister.getInstance().load(infile);

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

// retreive the loaded configuration for manipulation
// retrieve the loaded configuration for manipulation
Config c = ConfigPersister.getInstance().getConfig();

String jarDefaultValue = project.getBuild().getDirectory() + "/" + project.getBuild().getFinalName() + ".jar";
Expand Down Expand Up @@ -500,7 +510,7 @@ private void createParentFolder() {
* Writes a marker file to prevent unzipping more than once.
*/
private File unpackWorkDir(Artifact artifact) throws MojoExecutionException {
Artifact localArtifact= localRepository.find(artifact);
Artifact localArtifact = localRepository.find(artifact);
if (localArtifact == null || localArtifact.getFile() == null) {
throw new MojoExecutionException("Cannot obtain file path to " + artifact);
}
Expand All @@ -520,7 +530,7 @@ private File unpackWorkDir(Artifact artifact) throws MojoExecutionException {
getLog().info("Platform-specific work directory already exists: " + workdir.getAbsolutePath());
} else {
// trying to use plexus-archiver here is a miserable waste of time:
try(JarFile jf = new JarFile(platJar)){
try (JarFile jf = new JarFile(platJar)) {
Enumeration<JarEntry> en = jf.entries();
while (en.hasMoreElements()) {
JarEntry je = en.nextElement();
Expand All @@ -533,8 +543,8 @@ private File unpackWorkDir(Artifact artifact) throws MojoExecutionException {
if (je.isDirectory()) {
outFile.mkdirs();
} else {
try(InputStream in = jf.getInputStream(je)){
try (FileOutputStream fout = new FileOutputStream(outFile)){
try (InputStream in = jf.getInputStream(je)) {
try (FileOutputStream fout = new FileOutputStream(outFile)) {
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) >= 0) {
Expand Down Expand Up @@ -658,7 +668,7 @@ private Artifact chooseBinaryBits() throws MojoExecutionException {
}

return factory.createArtifactWithClassifier(LAUNCH4J_GROUP_ID, LAUNCH4J_ARTIFACT_ID,
getLaunch4jVersion(), "jar", "workdir-" + plat);
getLaunch4jVersion(), "jar", "workdir-" + plat);
}

private File getBaseDir() {
Expand Down Expand Up @@ -755,20 +765,20 @@ private void printState() {
}

/**
* The Launch4j version used by the plugin.
* A version of the Launch4j used by the plugin.
* We want to download the platform-specific bundle whose version matches the Launch4j version,
* so we have to figure out what version the plugin is using.
*
* @return
* @throws MojoExecutionException
* @return version of Launch4j
* @throws MojoExecutionException when version is null
*/
private String getLaunch4jVersion() throws MojoExecutionException {
String version = null;

for (Artifact artifact : pluginArtifacts) {
if (LAUNCH4J_GROUP_ID.equals(artifact.getGroupId()) &&
LAUNCH4J_ARTIFACT_ID.equals(artifact.getArtifactId())
&& "core".equals(artifact.getClassifier())) {
LAUNCH4J_ARTIFACT_ID.equals(artifact.getArtifactId())
&& "core".equals(artifact.getClassifier())) {

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

return version;
}

/**
* Checks if execution of the plugin should be skipped
*
* @return true to skip execution
*/
private boolean skipExecution() {
getLog().debug("skip = " + System.getProperty("skipLaunch4j"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo? Should it be "skip = " + skip?

getLog().debug("skipLaunch4j = " + System.getProperty("skipLaunch4j"));
return skip || System.getProperty("skipLaunch4j") != null;
}

}
Loading