ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1377682 - in /ant/sandbox/antdsl/branches/import-experiment: ./ org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java test/test-module.bnd
Date Mon, 27 Aug 2012 13:48:38 GMT
Author: hibou
Date: Mon Aug 27 13:48:38 2012
New Revision: 1377682

URL: http://svn.apache.org/viewvc?rev=1377682&view=rev
Log:
Fix the classloader used by the typedef

Modified:
    ant/sandbox/antdsl/branches/import-experiment/   (props changed)
    ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
    ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
    ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd

Propchange: ant/sandbox/antdsl/branches/import-experiment/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Aug 27 13:48:38 2012
@@ -2,3 +2,4 @@ build
 lib
 build-deps
 *.classpath
+.ant

Modified: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java?rev=1377682&r1=1377681&r2=1377682&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
(original)
+++ ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/AbstractAntDslProjectHelper.java
Mon Aug 27 13:48:38 2012
@@ -97,16 +97,6 @@ public abstract class AbstractAntDslProj
             project.addReference(REFID_FUNCTION_REGISTRY, functionRegistry);
         }
 
-        OSGiFrameworkManager osgiFrameworkManager = project.getReference(REFID_OSGI_FRAMEWORK_MANAGER);
-        if (osgiFrameworkManager == null) {
-            try {
-                osgiFrameworkManager = new OSGiFrameworkManager();
-            } catch (BundleException e) {
-                throw new BuildException("Unable to boot the OSGi framwork (" + e.getMessage()
+ ")", e);
-            }
-            project.addReference(REFID_OSGI_FRAMEWORK_MANAGER, osgiFrameworkManager);
-        }
-
         Stack<ClassLoader> classloaderStack = project.getReference(REFID_CLASSLOADER_STACK);
         if (classloaderStack == null) {
             classloaderStack = new Stack<ClassLoader>();
@@ -134,8 +124,6 @@ public abstract class AbstractAntDslProj
             }
         } else {
             // top level file
-            classloaderStack.push(getOSGiFrameworkManager(project).getGodClassLoader());
-
             context.setCurrentTargets(new HashMap<String, Target>());
             parse(project, source, context);
 
@@ -262,6 +250,17 @@ public abstract class AbstractAntDslProj
             }
         }
 
+        OSGiFrameworkManager osgiFrameworkManager = project.getReference(REFID_OSGI_FRAMEWORK_MANAGER);
+        if (osgiFrameworkManager == null) {
+            try {
+                osgiFrameworkManager = new OSGiFrameworkManager(project.getBaseDir());
+            } catch (BundleException e) {
+                throw new BuildException("Unable to boot the OSGi framwork (" + e.getMessage()
+ ")", e);
+            }
+            project.addReference(REFID_OSGI_FRAMEWORK_MANAGER, osgiFrameworkManager);
+        }
+        getClassloaderStack(project).push(osgiFrameworkManager.getGodClassLoader());
+
         String antFileProp = MagicNames.ANT_FILE + "." + context.getCurrentProjectName();
         String dup = project.getProperty(antFileProp);
         String typeProp = MagicNames.ANT_FILE_TYPE + "." + context.getCurrentProjectName();
@@ -415,6 +414,9 @@ public abstract class AbstractAntDslProj
         ProjectHelper subHelper = ProjectHelperRepository.getInstance().getProjectHelperForBuildFile(urlResource);
 
         ClassLoader childCl = getOSGiFrameworkManager(project).getClassLoader(buildModule,
buildUrl);
+        if (childCl == null) {
+            throw new RuntimeException("Unable to find the classloader of the resource "
+ buildUrl);
+        }
         getClassloaderStack(project).push(childCl);
 
         // push current stacks into the sub helper

Modified: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java?rev=1377682&r1=1377681&r2=1377682&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
(original)
+++ ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
Mon Aug 27 13:48:38 2012
@@ -1,6 +1,7 @@
 package org.apache.ant.antdsl;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
@@ -36,9 +37,11 @@ public class OSGiFrameworkManager {
 
     private GodClassLoader godClassLoader = new GodClassLoader();
 
-    public OSGiFrameworkManager() throws BundleException {
+    public OSGiFrameworkManager(File basedir) throws BundleException {
         Map<String, String> configMap = new HashMap<String, String>();
         configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, ANT_PACKAGES);
+        configMap.put(Constants.FRAMEWORK_STORAGE, new File(basedir, ".ant/.felix-cache").getAbsolutePath());
+        configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true");
         framework = getFrameworkFactory().newFramework(configMap);
         framework.init();
     }
@@ -128,20 +131,38 @@ public class OSGiFrameworkManager {
     /**
      * Find which classloader is responsible for resolving holding url
      * 
-     * @param url
      * @return
      */
     public ClassLoader getClassLoader(String resource, URL url) {
         for (Bundle bundle : bundles) {
             BundleWiring wiring = bundle.adapt(BundleWiring.class);
-            List<URL> entries = wiring.findEntries(resource, null, 0);
-            if (!entries.isEmpty()) {
+            int i = resource.lastIndexOf('/');
+            String path = resource.substring(0, i);
+            String name = resource.substring(i + 1);
+            List<URL> entries = wiring.findEntries(path, name, 0);
+            if (!entries.isEmpty() && containsUrls(entries, url)) {
                 return wiring.getClassLoader();
             }
         }
         return null;
     }
 
+    private boolean containsUrls(List<URL> urls, URL url) {
+        for (URL u : urls) {
+            if (urlEquals(u, url)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean urlEquals(URL url1, URL url2) {
+        if (!url1.getProtocol().equals("bundle") || !url2.getProtocol().equals("bundle"))
{
+            return url1.equals(url2);
+        }
+        return url1.getHost().equals(url2.getHost()) && url1.getPath().equals(url2.getPath());
+    }
+
     private class GodClassLoader extends ClassLoader {
 
         private GodClassLoader() {

Modified: ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd?rev=1377682&r1=1377681&r2=1377682&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd (original)
+++ ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd Mon Aug 27 13:48:38
2012
@@ -3,4 +3,5 @@ version=1.0
 Bundle-Version: ${version}
 Bundle-SymbolicName: org.apache.ant.antdsl.test
 Include-Resource: test-module
-Export-Package: org.apache.ant.antdsl.test.*
\ No newline at end of file
+Export-Package: org.apache.ant.antdsl.test.*
+Import-Package: org.apache.ant.antunit
\ No newline at end of file



Mime
View raw message