Skip to content

Commit

Permalink
Teach NarProperties to extract a list of all known AOLs
Browse files Browse the repository at this point in the history
In the upcoming support for using native-lib-loader to unpack and load
our native libraries, we will need to stay platform-independent. Hence
we will need to know what native libraries are bundled for the current
architecture/OS. Unfortunately, this is not enough information because
NAR uses a full AOL identifier (in particular, the linker name) to
identify the location of the native library in the .nar file. To remedy
this, we will simply look in the paths corresponding to all AOLs
matching the current "AO".

Side note: using properties.keySet() does *not* work in NarProperties
because the properties are usually empty. The properties inherit their
defaults from an opaque Properties object passed to the constructor, hence
the keys we are after are only available via the propertyNames() method.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and hkmoon committed Sep 29, 2014
1 parent 2fbb7ed commit b821868
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/java/com/github/maven_nar/NarProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -116,4 +121,20 @@ public static void inject(MavenProject project, InputStream properties) throws M
public String getProperty(String key) {
return properties.getProperty(key);
}

public Collection<String> getKnownAOLs() {
final Collection<String> result = new LinkedHashSet<String>();
final Pattern pattern = Pattern.compile("([^.]+)\\.([^.]+)\\.([^.]+).*");
final Enumeration<?> e = properties.propertyNames();
while (e.hasMoreElements()) {
final Object key = e.nextElement();
if (key instanceof String) {
final Matcher matcher = pattern.matcher((String) key);
if (matcher.matches()) {
result.add(matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3));
}
}
}
return result;
}
}

0 comments on commit b821868

Please sign in to comment.