Skip to content

Commit 8241761

Browse files
committed
overwrite several properties analogous to the ANT task
It’s possible to overwrite the properties 'jar', 'outfile', 'fileVersion', 'txtFileVersion', 'productVersion', 'txtProductVersion' Example: <configuration> <infile>${project.build.sourceDir}/launch4j-config.xml</infile> <jar>${project.build.directory}/${my.finalJarName}.jar</jar> <outfile>${project.build.directory}/${my.finalShortName}.exe</outfile> <versionInfo> <fileVersion>${my.versionNumber.withBuildId}</fileVersion> <txtFileVersion>${my.versionNumber}</txtFileVersion> <productVersion>${my.versionNumber.withBuildId}</productVersion> <txtProductVersion>${my.versionNumber}</txtProductVersion> </versionInfo> </configuration> For ANT task analogy see https://sourceforge.net/p/launch4j/git/ci/master/tree/src/net/sf/launch4j/ant/Launch4jTask.java#l84
1 parent 2272907 commit 8241761

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,50 @@ public void execute() throws MojoExecutionException {
300300
if (getLog().isDebugEnabled()) {
301301
getLog().debug("Trying to load Launch4j native configuration using file=" + infile.getAbsolutePath());
302302
}
303+
// load launch4j configfile from <infile>
303304
ConfigPersister.getInstance().load(infile);
305+
306+
// overwrite several properties analogous to the ANT task
307+
// https://sourceforge.net/p/launch4j/git/ci/master/tree/src/net/sf/launch4j/ant/Launch4jTask.java#l84
308+
309+
// retreive the loaded configuration for manipulation
310+
Config c = ConfigPersister.getInstance().getConfig();
311+
312+
String jarDefaultValue = project.getBuild().getDirectory() + "/" + project.getBuild().getFinalName() + ".jar";
313+
if (jar != null && !jar.equals(jarDefaultValue)) {
314+
getLog().debug("Overwriting config file property 'jar' (='"+c.getJar().getAbsolutePath()+"') with local value '"+getJar().getAbsolutePath()+"'");
315+
// only overwrite when != defaultValue (should be != null anytime because of the default value)
316+
c.setJar(getJar());
317+
}
318+
319+
File outFileDefaultValue = new File(project.getBuild().getDirectory() + "/" + project.getArtifactId() + ".exe");
320+
if (outfile != null && !outfile.getAbsolutePath().equals(outFileDefaultValue.getAbsolutePath())) {
321+
// only overwrite when != defaultValue (should be != null anytime because of the default value)
322+
getLog().debug("Overwriting config file property 'outfile' (='"+c.getOutfile().getAbsolutePath()+"') with local value '"+outfile.getAbsolutePath()+"'");
323+
c.setOutfile(outfile);
324+
}
325+
326+
if (versionInfo != null) {
327+
if (versionInfo.fileVersion != null) {
328+
getLog().debug("Overwriting config file property 'versionInfo.fileVersion' (='"+c.getVersionInfo().getFileVersion()+"') with local value '"+versionInfo.fileVersion+"'");
329+
c.getVersionInfo().setFileVersion(versionInfo.fileVersion);
330+
}
331+
if (versionInfo.txtFileVersion != null) {
332+
getLog().debug("Overwriting config file property 'versionInfo.txtFileVersion' (='"+c.getVersionInfo().getTxtFileVersion()+"') with local value '"+versionInfo.txtFileVersion+"'");
333+
c.getVersionInfo().setTxtFileVersion(versionInfo.txtFileVersion);
334+
}
335+
if (versionInfo.productVersion != null) {
336+
getLog().debug("Overwriting config file property 'versionInfo.productVersion' (='"+c.getVersionInfo().getProductVersion()+"') with local value '"+versionInfo.productVersion+"'");
337+
c.getVersionInfo().setProductVersion(versionInfo.productVersion);
338+
}
339+
if (versionInfo.txtProductVersion != null) {
340+
getLog().debug("Overwriting config file property 'versionInfo.txtProductVersion' (='"+c.getVersionInfo().getTxtProductVersion()+"') with local value '"+versionInfo.txtProductVersion+"'");
341+
c.getVersionInfo().setTxtProductVersion(versionInfo.txtProductVersion);
342+
}
343+
}
344+
345+
ConfigPersister.getInstance().setAntConfig(c, infile.getParentFile());
346+
304347
} catch (ConfigPersisterException e) {
305348
getLog().error(e);
306349
throw new MojoExecutionException("Could not load Launch4j native configuration file", e);

0 commit comments

Comments
 (0)