summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java8
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/NarUtil.java92
2 files changed, 99 insertions, 1 deletions
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java b/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
index 3f2cf17..d04c01e 100644
--- a/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
@@ -139,6 +139,14 @@ public abstract class AbstractNarLayout
log );
}
}
+ if ( NarUtil.getOS( os ).equals( OS.MACOSX ) )
+ {
+ File[] dylibDirs = new File[2];
+ dylibDirs[0] = new File( narLocation, "lib/" + defaultAOL + "/" + Library.SHARED );
+ dylibDirs[1] = new File( narLocation, "lib/" + defaultAOL + "/" + Library.JNI );
+
+ NarUtil.runInstallNameTool( dylibDirs, log );
+ }
}
/**
diff --git a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java
index fd0f6a1..2d4f221 100644
--- a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java
+++ b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java
@@ -26,10 +26,12 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import java.util.regex.Pattern;
import org.apache.bcel.classfile.ClassParser;
@@ -46,7 +48,6 @@ import org.codehaus.plexus.util.cli.Commandline;
*/
public final class NarUtil
{
-
private NarUtil()
{
// never instantiate
@@ -210,6 +211,95 @@ public final class NarUtil
}
}
+ static void runInstallNameTool( File[] files, final Log log )
+ throws MojoExecutionException, MojoFailureException
+ {
+ Set libs = findInstallNameToolCandidates( files, log );
+
+ for ( Iterator i = libs.iterator(); i.hasNext(); )
+ {
+ File subjectFile = ( File )i.next();
+ String subjectName = subjectFile.getName();
+ String subjectPath = subjectFile.getPath();
+
+ int idResult = runCommand(
+ "install_name_tool",
+ new String[] { "-id", subjectPath, subjectPath },
+ null, null, log );
+
+ if ( idResult != 0 )
+ {
+ throw new MojoExecutionException(
+ "Failed to execute 'install_name_tool -id "
+ + subjectPath
+ + " "
+ + subjectPath
+ + "'"
+ + " return code: \'"
+ + idResult
+ + "\'." );
+ }
+
+ for ( Iterator j = libs.iterator(); j.hasNext(); )
+ {
+ File dependentFile = ( File )j.next();
+ String dependentPath = dependentFile.getPath();
+
+ if (dependentPath == subjectPath) continue;
+
+ int changeResult = runCommand(
+ "install_name_tool",
+ new String[] { "-change", subjectName, subjectPath, dependentPath },
+ null, null, log );
+
+ if ( changeResult != 0 )
+ {
+ throw new MojoExecutionException(
+ "Failed to execute 'install_name_tool -change "
+ + subjectName
+ + " "
+ + subjectPath
+ + " "
+ + dependentPath
+ + "'"
+ + " return code: \'"
+ + changeResult
+ + "\'." );
+ }
+ }
+ }
+ }
+
+ static Set findInstallNameToolCandidates( File[] files, final Log log )
+ throws MojoExecutionException, MojoFailureException
+ {
+ HashSet candidates = new HashSet();
+
+ for (int i = 0; i < files.length; i++)
+ {
+ File file = files[i];
+
+ if ( !file.exists() )
+ {
+ continue;
+ }
+
+ if ( file.isDirectory() )
+ {
+ candidates.addAll(findInstallNameToolCandidates( file.listFiles(), log ));
+ }
+
+ String fileName = file.getName();
+ if ( file.isFile() && file.canWrite()
+ && ( fileName.endsWith( ".dylib" ) || (fileName.endsWith( ".jnilib" ))))
+ {
+ candidates.add(file);
+ }
+ }
+
+ return candidates;
+ }
+
public static void makeLink( File file, final Log log )
throws MojoExecutionException, MojoFailureException
{