Skip to content

Commit

Permalink
Merge pull request #22 from chringwer/copy-obj-and-libs
Browse files Browse the repository at this point in the history
Add custom headers and libraries to working dir
  • Loading branch information
lukaszlenart committed Mar 31, 2015
2 parents f793e0c + a072857 commit 7ea5c23
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -281,6 +286,8 @@ public void execute() throws MojoExecutionException {
printState();
}

File workdir = setupBuildEnvironment();

Config c = new Config();

c.setHeaderType(headerType);
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
*/
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.
*/
Expand Down

0 comments on commit 7ea5c23

Please sign in to comment.