geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1483563 - in /geronimo/xbean/trunk/xbean-finder/src: main/java/org/apache/xbean/finder/UrlSet.java test/java/org/apache/xbean/finder/UrlSetTest.java
Date Thu, 16 May 2013 20:53:04 GMT
Author: dblevins
Date: Thu May 16 20:53:04 2013
New Revision: 1483563

URL: http://svn.apache.org/r1483563
Log:
XBEAN-247 - Better JVM Filtering for OSX

Modified:
    geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/UrlSet.java
    geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/UrlSetTest.java

Modified: geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/UrlSet.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/UrlSet.java?rev=1483563&r1=1483562&r2=1483563&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/UrlSet.java (original)
+++ geronimo/xbean/trunk/xbean-finder/src/main/java/org/apache/xbean/finder/UrlSet.java Thu
May 16 20:53:04 2013
@@ -145,13 +145,21 @@ public class UrlSet implements Iterable<
 
         File java = new File(path);
 
-        if (path.matches("/System/Library/Frameworks/JavaVM.framework/Versions/[^/]+/Home")){
-            java = java.getParentFile();
+        if (isOsx() && path.endsWith("/Contents/Home")) {
+            java = java.getParentFile().getParentFile();
         }
 
         return exclude(java);
     }
 
+    public UrlSet excludeJvm() throws MalformedURLException  {
+        UrlSet urls = excludeJavaHome().excludeJavaExtDirs().excludeJavaEndorsedDirs();
+        if (isOsx()) {
+            urls = urls.exclude(new File("/System/Library/Java/Support"));
+        }
+        return urls;
+    }
+
     public UrlSet excludePaths(String pathString) throws MalformedURLException {
         String[] paths = pathString.split(File.pathSeparator);
         UrlSet urlSet = this;
@@ -205,4 +213,8 @@ public class UrlSet implements Iterable<
     public String toString() {
         return super.toString() + "[" + urls.size() + "]";
     }
+
+    public boolean isOsx() {
+        return "Mac OS X".equals(System.getProperty("os.name"));
+    }
 }

Modified: geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/UrlSetTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/UrlSetTest.java?rev=1483563&r1=1483562&r2=1483563&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/UrlSetTest.java
(original)
+++ geronimo/xbean/trunk/xbean-finder/src/test/java/org/apache/xbean/finder/UrlSetTest.java
Thu May 16 20:53:04 2013
@@ -19,18 +19,15 @@ package org.apache.xbean.finder;
 import junit.framework.TestCase;
 
 import java.net.URL;
-import java.util.List;
-import java.io.File;
+import java.util.Properties;
 
 /**
  * @version $Rev$ $Date$
  */
 public class UrlSetTest extends TestCase {
-    private UrlSet urlSet;
-    private URL[] originalUrls;
 
-    protected void setUp() throws Exception {
-        originalUrls = new URL[]{
+    public void testAll() throws Exception {
+        final URL[] originalUrls = new URL[]{
                 new URL("file:/Users/dblevins/work/xbean/trunk/xbean-finder/target/classes/"),
                 new URL("file:/Users/dblevins/work/xbean/trunk/xbean-finder/target/test-classes/"),
                 new URL("jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/.compatibility/14compatibility.jar!/"),
@@ -64,10 +61,7 @@ public class UrlSetTest extends TestCase
                 new URL("jar:file:/System/Library/Java/Extensions/vecmath.jar!/"),
                 new URL("jar:file:/Users/dblevins/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar!/"),
         };
-        urlSet = new UrlSet(originalUrls);
-    }
-
-    public void testAll() throws Exception {
+        UrlSet urlSet = new UrlSet(originalUrls);
 
         assertEquals("Urls.size()", 32, urlSet.getUrls().size());
 
@@ -104,4 +98,64 @@ public class UrlSetTest extends TestCase
         UrlSet filteredSet2 = filteredSet.exclude(junitSet);
         assertEquals("FilteredSet2.getUrls().size()", 2, filteredSet2.getUrls().size());
     }
+
+
+    public void testOsxJdk16Filtering() throws Exception {
+        final URL[] urls = {
+                new URL("file:/Applications/IntelliJ%20IDEA%2011.app/lib/idea_rt.jar"),
+                new URL("file:/Applications/IntelliJ%20IDEA%2011.app/plugins/junit/lib/junit-rt.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/dt.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jce.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jconsole.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/management-agent.jar"),
+                new URL("file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/sa-jdi.jar"),
+                new URL("file:/System/Library/Java/Support/CoreDeploy.bundle/Contents/Resources/Java/deploy.jar"),
+                new URL("file:/System/Library/Java/Support/Deploy.bundle/Contents/Resources/Java/javaws.jar"),
+                new URL("file:/Users/dblevins/.m2/repository/asm/asm-commons/3.2/asm-commons-3.2.jar"),
+                new URL("file:/Users/dblevins/.m2/repository/asm/asm-tree/3.2/asm-tree-3.2.jar"),
+                new URL("file:/Users/dblevins/.m2/repository/asm/asm/3.2/asm-3.2.jar"),
+                new URL("file:/Users/dblevins/.m2/repository/junit/junit/4.8.2/junit-4.8.2.jar"),
+                new URL("file:/Users/dblevins/.m2/repository/org/osgi/org.osgi.core/4.3.1/org.osgi.core-4.3.1.jar"),
+                new URL("file:/Users/dblevins/.m2/repository/org/slf4j/slf4j-api/1.5.11/slf4j-api-1.5.11.jar"),
+                new URL("file:/Users/dblevins/work/xbean/trunk/xbean-bundleutils/target/classes/"),
+                new URL("file:/Users/dblevins/work/xbean/trunk/xbean-finder/target/classes/"),
+                new URL("file:/Users/dblevins/work/xbean/trunk/xbean-finder/target/test-classes/"),
+        };
+
+        System.setProperty("java.endorsed.dirs", "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed");
+        System.setProperty("java.ext.dirs", "/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext");
+        System.setProperty("java.home", "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home");
+        System.setProperty("os.name", "Mac OS X");
+
+        final UrlSet urlSet = new UrlSet(urls);
+        assertEquals(urls.length, urlSet.size());
+        assertEquals(27, urlSet.excludeJavaEndorsedDirs().size());
+        assertEquals(22, urlSet.excludeJavaExtDirs().size());
+        assertEquals(13, urlSet.excludeJavaHome().size());
+        assertEquals(11, urlSet.excludeJvm().size());
+    }
+
+    private final Properties properties = new Properties();
+
+    protected void setUp() throws java.lang.Exception {
+        swap(System.getProperties(), properties);
+    }
+
+    protected void tearDown() throws java.lang.Exception {
+        swap(properties, System.getProperties());
+    }
+
+    private static void swap(Properties from, Properties to) {
+        to.clear();
+        to.putAll(from);
+    }
 }



Mime
View raw message