Skip to content

Commit

Permalink
Creates parent folder of outfile if configured
Browse files Browse the repository at this point in the history
Closes #141
  • Loading branch information
lukaszlenart committed May 4, 2021
1 parent cca4a51 commit b559715
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Binary file added src/test/resources/test-project/example.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@
<plugins>
<plugin>
<artifactId>launch4j-maven-plugin</artifactId>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>console</headerType>
<outfile>target/test.exe</outfile>
<outfile>binary/test.exe</outfile>
<dontWrapJar>true</dontWrapJar>
<jar>test-project/example.jar</jar>
<jre>
<minVersion>1.5.0</minVersion>
</jre>
</configuration>
</plugin>
</plugins>
Expand Down

0 comments on commit b559715

Please sign in to comment.