1818 */
1919package 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 ;
3626import org .apache .maven .artifact .Artifact ;
3727import org .apache .maven .artifact .repository .ArtifactRepository ;
3828import org .apache .maven .execution .MavenSession ;
5040import org .apache .maven .shared .transfer .artifact .resolve .ArtifactResolver ;
5141import 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)
6867public 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