Skip to content

Commit b821868

Browse files
dschohkmoon
authored andcommitted
Teach NarProperties to extract a list of all known AOLs
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 <[email protected]>
1 parent 2fbb7ed commit b821868

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main/java/com/github/maven_nar/NarProperties.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121

2222
import java.io.File;
2323
import java.io.FileInputStream;
24-
import java.io.InputStream;
2524
import java.io.FileNotFoundException;
2625
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.util.Collection;
28+
import java.util.Enumeration;
29+
import java.util.LinkedHashSet;
2730
import java.util.Properties;
31+
import java.util.regex.Matcher;
32+
import java.util.regex.Pattern;
2833

2934
import org.apache.maven.plugin.MojoFailureException;
3035
import org.apache.maven.project.MavenProject;
@@ -116,4 +121,20 @@ public static void inject(MavenProject project, InputStream properties) throws M
116121
public String getProperty(String key) {
117122
return properties.getProperty(key);
118123
}
124+
125+
public Collection<String> getKnownAOLs() {
126+
final Collection<String> result = new LinkedHashSet<String>();
127+
final Pattern pattern = Pattern.compile("([^.]+)\\.([^.]+)\\.([^.]+).*");
128+
final Enumeration<?> e = properties.propertyNames();
129+
while (e.hasMoreElements()) {
130+
final Object key = e.nextElement();
131+
if (key instanceof String) {
132+
final Matcher matcher = pattern.matcher((String) key);
133+
if (matcher.matches()) {
134+
result.add(matcher.group(1) + "-" + matcher.group(2) + "-" + matcher.group(3));
135+
}
136+
}
137+
}
138+
return result;
139+
}
119140
}

0 commit comments

Comments
 (0)