Skip to content

Commit

Permalink
* Make the arbitrary resources available to process executed with `B…
Browse files Browse the repository at this point in the history
…uilder.buildCommand` via the `BUILD_PATH` environment variable
  • Loading branch information
saudet committed May 7, 2017
1 parent afa7b7c commit ee96dc6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Make the arbitrary resources available to process executed with `Builder.buildCommand` via the `BUILD_PATH` environment variable
* Prevent `Parser` from outputting setters for `const` member pointers
* Add support for arrays of function pointers
* Let users bundle arbitrary resources, have them extracted in cache, and used as `include` or `link` paths ([pull #43](https://github.com/bytedeco/javacpp/pull/43))
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/bytedeco/javacpp/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ public static File extractResource(URL resourceURL, File directoryOrFile,
* @throws IOException
*/
public static URL[] findResources(Class cls, String name) throws IOException {
while (name.contains("//")) {
name = name.replace("//", "/");
}
if (!name.startsWith("/")) {
String s = cls.getName().replace('.', '/');
int n = s.lastIndexOf('/');
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/bytedeco/javacpp/tools/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public class BuildMojo extends AbstractMojo {
@Parameter(property = "javacpp.includeResources")
String[] includeResources = null;

/** Add the path to the "platform.buildpath" property. */
@Parameter(property = "javacpp.buildPath")
String buildPath = null;

/** Add the paths to the "platform.buildpath" property. */
@Parameter(property = "javacpp.buildPaths")
String[] buildPaths = null;

/** Add the path to the "platform.buildresource" property. */
@Parameter(property = "javacpp.buildResource")
String buildResource = null;

/** Add the paths to the "platform.buildresource" property. */
@Parameter(property = "javacpp.buildResources")
String[] buildResources = null;

/** Add the path to the "platform.linkpath" property. */
@Parameter(property = "javacpp.linkPath")
String linkPath = null;
Expand Down Expand Up @@ -193,6 +209,10 @@ String[] merge(String[] ss, String s) {
if (log.isDebugEnabled()) {
log.debug("classPath: " + classPath);
log.debug("classPaths: " + Arrays.deepToString(classPaths));
log.debug("buildPath: " + buildPath);
log.debug("buildPaths: " + Arrays.deepToString(buildPaths));
log.debug("buildResource: " + buildResource);
log.debug("buildResources: " + Arrays.deepToString(buildResources));
log.debug("includePath: " + includePath);
log.debug("includePaths: " + Arrays.deepToString(includePaths));
log.debug("includeResource: " + includeResource);
Expand Down Expand Up @@ -261,6 +281,16 @@ String[] merge(String[] ss, String s) {
log.info("Detected platform \"" + Loader.getPlatform() + "\"");
log.info("Building for platform \"" + properties.get("platform") + "\"");
String separator = properties.getProperty("platform.path.separator");
for (String s : merge(buildPaths, buildPath)) {
String v = properties.getProperty("platform.buildpath", "");
properties.setProperty("platform.buildpath",
v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s);
}
for (String s : merge(buildResources, buildResource)) {
String v = properties.getProperty("platform.buildresource", "");
properties.setProperty("platform.buildresource",
v.length() == 0 || v.endsWith(separator) ? v + s : v + separator + s);
}
for (String s : merge(includePaths, includePath)) {
String v = properties.getProperty("platform.includepath", "");
properties.setProperty("platform.includepath",
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/bytedeco/javacpp/tools/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,23 @@ public File[] build() throws IOException, InterruptedException, ParserException
if (environmentVariables != null) {
pb.environment().putAll(environmentVariables);
}
String paths = properties.getProperty("platform.buildpath", "");
String resources = properties.getProperty("platform.buildresource", "");
String separator = properties.getProperty("platform.path.separator");
if (paths.length() > 0 || resources.length() > 0) {
for (String s : resources.split(separator)) {
for (File f : Loader.cacheResources(s)) {
if (paths.length() > 0 && !paths.endsWith(separator)) {
paths += separator;
}
paths += f.getCanonicalPath();
}
}
if (paths.length() > 0) {
pb.environment().put("BUILD_PATH", paths);
pb.environment().put("PATH_SEPARATOR", separator);
}
}
int exitValue = pb.inheritIO().start().waitFor();
if (exitValue != 0) {
throw new RuntimeException("Process exited with an error: " + exitValue);
Expand Down Expand Up @@ -828,7 +845,6 @@ public File[] build() throws IOException, InterruptedException, ParserException
return FileVisitResult.CONTINUE;
}
});
break;
}
}
}
Expand Down

0 comments on commit ee96dc6

Please sign in to comment.