From b559715e0e59498f472d4d64b91979b76e962ebe Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 4 May 2021 08:36:08 +0200 Subject: [PATCH] Creates parent folder of outfile if configured Closes #141 --- pom.xml | 5 +++++ .../maven/plugins/launch4j/Launch4jMojo.java | 16 ++++++++++++++++ .../plugins/launch4j/Launch4jMojoTest.java | 7 ++++--- src/test/resources/test-project/example.jar | Bin 0 -> 462 bytes .../pom.xml} | 10 +++++++++- 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/test-project/example.jar rename src/test/resources/{test-plugin-pom.xml => test-project/pom.xml} (70%) diff --git a/pom.xml b/pom.xml index 1db7b67..5489d9e 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,11 @@ maven-artifact-transfer 0.13.1 + + junit + junit + 4.13.2 + org.apache.maven.plugin-testing maven-plugin-testing-harness diff --git a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java index eb4491d..ff95f76 100644 --- a/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java +++ b/src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java @@ -474,11 +474,27 @@ private void doExecute() throws MojoExecutionException { * @return the work directory. */ private File setupBuildEnvironment() throws MojoExecutionException { + createParentFolder(); Artifact binaryBits = chooseBinaryBits(); retrieveBinaryBits(binaryBits); return unpackWorkDir(binaryBits); } + private void createParentFolder() { + if (outfile != null) { + File parent = outfile.getParentFile(); + if (!parent.exists()) { + getLog().debug("Parent " + parent.getPath() + " does not exist, creating it!"); + boolean created = parent.mkdirs(); + if (created) { + getLog().debug("Parent " + parent.getPath() + " has been created!"); + } else { + getLog().warn("Cannot create parent " + parent.getPath() + "!"); + } + } + } + } + /** * Unzips the given artifact in-place and returns the newly-unzipped top-level directory. * Writes a marker file to prevent unzipping more than once. diff --git a/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java b/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java index 2cdbd77..eb67938 100644 --- a/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java +++ b/src/test/java/com/akathist/maven/plugins/launch4j/Launch4jMojoTest.java @@ -17,11 +17,12 @@ protected void tearDown() throws Exception { } public void testWorkingDir() throws Exception { - File pom = getTestFile( "src/test/resources/test-plugin-pom.xml" ); - + File pom = getTestFile("src/test/resources/test-project/pom.xml"); Launch4jMojo mojo = (Launch4jMojo) lookupMojo("launch4j", pom); - assertNotNull(mojo); + + File outfilePath = (File) getVariableValueFromObject(mojo, "outfile"); + assertEquals("binary/test.exe", outfilePath.getPath()); } } diff --git a/src/test/resources/test-project/example.jar b/src/test/resources/test-project/example.jar new file mode 100644 index 0000000000000000000000000000000000000000..26cd436056b4366ec6d7bd284d7af04689c6a901 GIT binary patch literal 462 zcmWIWW@Zs#;Nak3SY5d|hye+3GO#fCx`sIFdiuHP|2xINz|0Wf&CUT*!30$nfK#&w zPz7AGucM!*n`>~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>gu43Vg zcp-U2dge^642xw?#HaiaU-GPSXGQj>qK`$4U^x8?Ab>593D=4gCdej$yn*a6kT(!uACL+4RDd@t8%Tl~2sZ&~HbxK+0KEQP APyhe` literal 0 HcmV?d00001 diff --git a/src/test/resources/test-plugin-pom.xml b/src/test/resources/test-project/pom.xml similarity index 70% rename from src/test/resources/test-plugin-pom.xml rename to src/test/resources/test-project/pom.xml index 331f6d9..8d778c6 100644 --- a/src/test/resources/test-plugin-pom.xml +++ b/src/test/resources/test-project/pom.xml @@ -15,9 +15,17 @@ launch4j-maven-plugin + + launch4j + console - target/test.exe + binary/test.exe + true + test-project/example.jar + + 1.5.0 +