-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add custom headers and libraries to working dir #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ | |
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.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
|
@@ -281,6 +286,8 @@ public void execute() throws MojoExecutionException { | |
printState(); | ||
} | ||
|
||
File workdir = setupBuildEnvironment(); | ||
|
||
Config c = new Config(); | ||
|
||
c.setHeaderType(headerType); | ||
|
@@ -297,8 +304,8 @@ public void execute() throws MojoExecutionException { | |
c.setRestartOnCrash(restartOnCrash); | ||
c.setManifest(manifest); | ||
c.setIcon(icon); | ||
c.setHeaderObjects(objs); | ||
c.setLibs(libs); | ||
c.setHeaderObjects(relativizeAndCopy(workdir, objs)); | ||
c.setLibs(relativizeAndCopy(workdir, libs)); | ||
c.setVariables(vars); | ||
|
||
if (classPath != null) { | ||
|
@@ -321,7 +328,6 @@ public void execute() throws MojoExecutionException { | |
} | ||
|
||
ConfigPersister.getInstance().setAntConfig(c, getBaseDir()); | ||
File workdir = setupBuildEnvironment(); | ||
Builder b = new Builder(new MavenLog(getLog()), workdir); | ||
|
||
try { | ||
|
@@ -455,6 +461,36 @@ private void setPermissions(File workdir) { | |
} | ||
} | ||
|
||
/** | ||
* If custom header objects or libraries shall be linked, they need to sit inside the launch4j working dir. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the objs and libs must be relative to project's base dir? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems to be the way how it is implemented in launch4j. It will try to construct an absolute path using Let me know if there is a better way to acheive this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I assume you have tested this solution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I've tested a configuration like this:
I copied the default header objects from the launch4j sources into my project dir and renamed them. Also, I linked w32api/crt2.0 which is already part of the working directory and not included into my project sources. This will produce a running launcher even if an absolute path is specified by using ${basedir}. Of course, I made sure nothing will break if header objects aren't used at all. |
||
*/ | ||
private List<String> relativizeAndCopy(File workdir, List<String> paths) throws MojoExecutionException { | ||
if(paths == null) return null; | ||
|
||
List<String> result = new ArrayList<>(); | ||
for(String path : paths) { | ||
Path source = basedir.toPath().resolve(path); | ||
Path dest = workdir.toPath().resolve(basedir.toPath().relativize(source)); | ||
|
||
if(!source.startsWith(basedir.toPath())) { | ||
throw new MojoExecutionException("File must reside in the project directory: " + path); | ||
} | ||
|
||
if (Files.exists(source)) { | ||
try { | ||
Path target = Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING); | ||
result.add(workdir.toPath().relativize(target).toString()); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Can't copy file to workdir", e); | ||
} | ||
} else { | ||
result.add(path); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Downloads the platform-specific parts, if necessary. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like unused