You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2012/08/27 12:14:31 UTC
svn commit: r1377632 - in /ant/sandbox/antdsl/branches/import-experiment: ./
org.apache.ant.antdsl/src/org/apache/ant/antdsl/
org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/ test/
test/test-module/ test/test-module/org/ test/test-module/org/apac...
Author: hibou
Date: Mon Aug 27 10:14:30 2012
New Revision: 1377632
URL: http://svn.apache.org/viewvc?rev=1377632&view=rev
Log:
- remove classloader hack by using BundleWiring
- implement a function to try to find the classloader of the bundle holding a resource (an ant script)
- stack the classloader properly when importing a script
- make the import module work on a basic exemple
Added:
ant/sandbox/antdsl/branches/import-experiment/test/build.xml (with props)
ant/sandbox/antdsl/branches/import-experiment/test/test-module/
ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd
ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/
ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/
ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/
ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/
ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/
ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant (with props)
Removed:
ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh
Modified:
ant/sandbox/antdsl/branches/import-experiment/build.xml
ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml
ant/sandbox/antdsl/branches/import-experiment/ivy.xml
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/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java
ant/sandbox/antdsl/branches/import-experiment/test/ (props changed)
ant/sandbox/antdsl/branches/import-experiment/test/build.ant
Modified: ant/sandbox/antdsl/branches/import-experiment/build.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/build.xml?rev=1377632&r1=1377631&r2=1377632&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/build.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/build.xml Mon Aug 27 10:14:30 2012
@@ -44,8 +44,8 @@
<target name="get-deps" depends="init,ivy:configure" description="Download dependencies" >
<ivy:resolve file="ivy-fixed.xml" conf="*" uncompress="true" />
<!--ivy:retrieve conf="*" pattern="${basedir}/lib/[type]s/[artifact]_[revision](.[ext])" sync="true" uncompress="true" /-->
- <ivy:cachepath pathid="antruntime.classpath.ivy" conf="antruntime" type="jar" uncompress="true" osgi="true" />
- <ivy:cachepath pathid="generate.classpath.ivy" conf="generate" type="jar" uncompress="true" osgi="true" />
+ <ivy:cachepath pathid="antruntime.classpath.ivy" conf="antruntime" type="jar,bundle" uncompress="true" osgi="true" />
+ <ivy:cachepath pathid="generate.classpath.ivy" conf="generate" type="jar,bundle" uncompress="true" osgi="true" />
<!-- Now we need to hack since we the ant trunk to build -->
<path id="antruntime.classpath">
<fileset dir="build-deps/apache-ant-1.9.0alpha/lib" includes="*.jar" />
Modified: ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml?rev=1377632&r1=1377631&r2=1377632&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml Mon Aug 27 10:14:30 2012
@@ -4,7 +4,7 @@
module="ant-dsl"
revision="1.0.0"
status="integration"
- publication="20120822212844"
+ publication="20120826210539"
/>
<configurations>
<conf name="default" visibility="public"/>
@@ -157,7 +157,7 @@
<dependency org="bundle" name="org.eclipse.ui.navigator" rev="3.5.200.v20120523-1955" force="true" transitive="false" conf="transitive-optional->default"/>
<dependency org="bundle" name="org.eclipse.ui.navigator.resources" rev="3.4.400.v20120523-1955" force="true" transitive="false" conf="transitive-optional->default"/>
<dependency org="bundle" name="org.eclipse.ui.views.properties.tabbed" rev="3.5.300.v20120523-1955" force="true" transitive="false" conf="transitive-optional->default"/>
+ <dependency org="org.apache.felix" name="org.apache.felix.framework" rev="4.0.3" force="true" transitive="false" conf="osgi->default,compile,runtime,sources,master;antruntime->default,compile,runtime,master,sources"/>
<dependency org="bundle" name="org.eclipse.emf.mwe2.lib" rev="2.2.0.v201112070431" force="true" transitive="false" conf="generate->default"/>
- <dependency org="org.apache.felix" name="org.apache.felix.framework" rev="4.0.3" force="true" transitive="false" conf="osgi->default,compile,runtime,master,sources"/>
</dependencies>
</ivy-module>
Modified: ant/sandbox/antdsl/branches/import-experiment/ivy.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/ivy.xml?rev=1377632&r1=1377631&r2=1377632&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/ivy.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/ivy.xml Mon Aug 27 10:14:30 2012
@@ -17,7 +17,7 @@
<!-- some optional dependency we do need -->
<dependency org="bundle" name="org.eclipse.emf.mwe2.lib" rev="2.2.0+" conf="generate->default" />
- <dependency org="org.apache.felix" name="org.apache.felix.framework" rev="4.0.3" conf="osgi->default,sources" />
+ <dependency org="org.apache.felix" name="org.apache.felix.framework" rev="4.0.3" conf="osgi,antruntime->default,sources" />
<!-- provided -->
<exclude org="package" module="javax.xml.parsers" />
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=1377632&r1=1377631&r2=1377632&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 10:14:30 2012
@@ -373,6 +373,12 @@ public abstract class AbstractAntDslProj
throw new BuildException("Unable to install the bundle " + resource.getName() + " (" + e.getMessage() + ")", e);
}
}
+
+ try {
+ osgiFrameworkManager.start();
+ } catch (BundleException e) {
+ throw new BuildException("Unable to start the OSGi framework (" + e.getMessage() + ")", e);
+ }
}
protected void importAntlib(Project project, AntDslContext context, String name, String resource) {
@@ -408,9 +414,9 @@ public abstract class AbstractAntDslProj
ProjectHelper subHelper = ProjectHelperRepository.getInstance().getProjectHelperForBuildFile(urlResource);
- // TODO
- // add to the classloader stack the classloader of the imported build
-
+ ClassLoader childCl = getOSGiFrameworkManager(project).getClassLoader(buildModule, buildUrl);
+ getClassloaderStack(project).push(childCl);
+
// push current stacks into the sub helper
subHelper.getImportStack().addAll(this.getImportStack());
subHelper.getExtensionStack().addAll(this.getExtensionStack());
@@ -419,6 +425,7 @@ public abstract class AbstractAntDslProj
subHelper.parse(project, urlResource);
// push back the stack from the sub helper to the main one
+ getClassloaderStack(project).pop();
project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, this);
getImportStack().clear();
getImportStack().addAll(subHelper.getImportStack());
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=1377632&r1=1377631&r2=1377632&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 10:14:30 2012
@@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -18,33 +17,52 @@ import org.osgi.framework.BundleExceptio
import org.osgi.framework.Constants;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
+import org.osgi.framework.wiring.BundleWiring;
public class OSGiFrameworkManager {
- private static final String ANT_PACKAGES = "org.apache.tools.ant," + "org.apache.tools.ant.types," + "org.apache.tools.ant.taskdefs.condition,"
- + "org.apache.tools.ant.taskdefs," + "org.apache.tools.ant.util";
+ //@formatter:off
+ private static final String ANT_PACKAGES =
+ "org.apache.tools.ant,"
+ + "org.apache.tools.ant.types,"
+ + "org.apache.tools.ant.taskdefs.condition,"
+ + "org.apache.tools.ant.taskdefs,"
+ + "org.apache.tools.ant.util";
+ //@formatter:on
private Framework framework;
- private List<Bundle> bundleToStart = new ArrayList<Bundle>();
+ private List<Bundle> bundles = new ArrayList<Bundle>();
- private Map<String, ClassLoader> classloaders = new LinkedHashMap<String, ClassLoader>();
-
- private GodClassLoader godClassLoader;
+ private GodClassLoader godClassLoader = new GodClassLoader();
public OSGiFrameworkManager() throws BundleException {
Map<String, String> configMap = new HashMap<String, String>();
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, ANT_PACKAGES);
framework = getFrameworkFactory().newFramework(configMap);
framework.init();
- godClassLoader = new GodClassLoader();
}
private FrameworkFactory getFrameworkFactory() {
- URL url = OSGiFrameworkManager.class.getClassLoader().getResource("META-INF/services/org.osgi.framework.launch.FrameworkFactory");
- if (url == null) {
+ Enumeration<URL> urls;
+ try {
+ urls = OSGiFrameworkManager.class.getClassLoader().getResources("META-INF/services/org.osgi.framework.launch.FrameworkFactory");
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
+ if (urls == null || !urls.hasMoreElements()) {
throw new BuildException("No OSGi framework could be found in Ant's classpath");
}
+ URL url = null;
+ ArrayList<URL> urlList = Collections.list(urls);
+ for (URL candidate : urlList) {
+ if (candidate.toExternalForm().contains("felix")) {
+ url = candidate;
+ }
+ }
+ if (url == null) {
+ url = urlList.iterator().next();
+ }
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(url.openStream()));
@@ -71,9 +89,8 @@ public class OSGiFrameworkManager {
public void install(String bundleURI) throws BundleException {
Bundle bundle = framework.getBundleContext().installBundle(bundleURI);
- classloaders.put(bundleURI, new BundleClassLoader(bundle));
if (!isFragment(bundle)) {
- bundleToStart.add(bundle);
+ bundles.add(bundle);
}
}
@@ -95,42 +112,34 @@ public class OSGiFrameworkManager {
}
}
});
- for (Bundle bundle : bundleToStart) {
+ for (Bundle bundle : bundles) {
bundle.start();
}
}
- public ClassLoader getClassloader(String bundleURI) {
- return classloaders.get(bundleURI);
- }
-
public GodClassLoader getGodClassLoader() {
return godClassLoader;
}
- private static class BundleClassLoader extends ClassLoader {
-
- private Bundle bundle;
-
- private BundleClassLoader(Bundle bundle) {
- super(null);
- this.bundle = bundle;
- }
-
- @Override
- public URL getResource(String name) {
- return bundle.getResource(name);
- }
-
- @Override
- public Enumeration<URL> getResources(String name) throws IOException {
- return bundle.getResources(name);
- }
+ public List<Bundle> getBundles() {
+ return bundles;
+ }
- @Override
- public Class< ? > loadClass(String name) throws ClassNotFoundException {
- return bundle.loadClass(name);
+ /**
+ * 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()) {
+ return wiring.getClassLoader();
+ }
}
+ return null;
}
private class GodClassLoader extends ClassLoader {
@@ -141,7 +150,9 @@ public class OSGiFrameworkManager {
@Override
public URL getResource(String name) {
- for (ClassLoader cl : classloaders.values()) {
+ for (Bundle bundle : bundles) {
+ BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ ClassLoader cl = wiring.getClassLoader();
URL url = cl.getResource(name);
if (url != null) {
return url;
@@ -153,7 +164,9 @@ public class OSGiFrameworkManager {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
List<URL> urls = new ArrayList<URL>();
- for (ClassLoader cl : classloaders.values()) {
+ for (Bundle bundle : bundles) {
+ BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ ClassLoader cl = wiring.getClassLoader();
Enumeration<URL> resources = cl.getResources(name);
if (resources != null) {
urls.addAll(Collections.list(resources));
@@ -164,7 +177,9 @@ public class OSGiFrameworkManager {
@Override
public Class< ? > loadClass(String name) throws ClassNotFoundException {
- for (ClassLoader cl : classloaders.values()) {
+ for (Bundle bundle : bundles) {
+ BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ ClassLoader cl = wiring.getClassLoader();
try {
return cl.loadClass(name);
} catch (ClassNotFoundException e) {
Modified: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext?rev=1377632&r1=1377631&r2=1377632&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext (original)
+++ ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDSL.xtext Mon Aug 27 10:14:30 2012
@@ -43,7 +43,7 @@ EAntlibImport:
;
EBuildImport:
- 'module' name=QualifiedName
+ 'module' file=StringLiteral
;
EExtensionPoint:
Modified: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java?rev=1377632&r1=1377631&r2=1377632&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java (original)
+++ ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/AntDslXTextProjectHelper.java Mon Aug 27 10:14:30 2012
@@ -181,7 +181,7 @@ public class AntDslXTextProjectHelper ex
importAntlib(project, context, readIdentifier(eAntlibImport.getName()), readString(eAntlibImport.getResource()));
} else if (eImport instanceof EBuildImport) {
EBuildImport eBuildImport = (EBuildImport) eImport;
- // TODO
+ importBuildModule(project, context, readString(eBuildImport.getFile()));
} else {
throw new IllegalArgumentException("Unsupported import " + eImport.getClass().getName());
}
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Aug 27 10:14:30 2012
@@ -1,2 +1,4 @@
org.apache.ant.antunit-1.2.jar
ant-antunit-1.2.jar
+biz.aQute.bnd-1.50.0.jar
+org.apache.ant.antdsl.test-1.0.jar
Modified: ant/sandbox/antdsl/branches/import-experiment/test/build.ant
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/test/build.ant?rev=1377632&r1=1377631&r2=1377632&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/build.ant (original)
+++ ant/sandbox/antdsl/branches/import-experiment/test/build.ant Mon Aug 27 10:14:30 2012
@@ -3,10 +3,13 @@ default : build
antpath {
file(file = "test/org.apache.ant.antunit-1.2.jar")
+ file(file = "test/org.apache.ant.antdsl.test-1.0.jar")
}
import antlib "org/apache/ant/antunit/antlib.xml" as antunit
+import module "org/apache/ant/antdsl/test/build.ant"
target build
+ depends imported
{
antunit:assertEquals(expected = "test", actual = "test")
antunit:assertEquals(expected = "test", actual = "nok")
Added: ant/sandbox/antdsl/branches/import-experiment/test/build.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/test/build.xml?rev=1377632&view=auto
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/build.xml (added)
+++ ant/sandbox/antdsl/branches/import-experiment/test/build.xml Mon Aug 27 10:14:30 2012
@@ -0,0 +1,18 @@
+<project>
+
+ <target name="get-bnd">
+ <get src="http://dl.dropbox.com/u/2590603/bnd/biz.aQute.bnd.jar" dest="biz.aQute.bnd-1.50.0.jar" />
+ </target>
+
+ <target name="build-antunit">
+ <taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="biz.aQute.bnd-1.50.0.jar" />
+ <get src="http://repo1.maven.org/maven2/org/apache/ant/ant-antunit/1.2/ant-antunit-1.2.jar" dest="ant-antunit-1.2.jar" />
+ <bndwrap jars="ant-antunit-1.2.jar" output="org.apache.ant.antunit-1.2.jar" />
+ </target>
+
+ <target name="build-module">
+ <taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="biz.aQute.bnd-1.50.0.jar" />
+ <bnd files="test-module.bnd" output="org.apache.ant.antdsl.test-1.0.jar" />
+ </target>
+
+</project>
\ No newline at end of file
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/build.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/build.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: 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=1377632&view=auto
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd (added)
+++ ant/sandbox/antdsl/branches/import-experiment/test/test-module.bnd Mon Aug 27 10:14:30 2012
@@ -0,0 +1,6 @@
+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
Added: ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant?rev=1377632&view=auto
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant (added)
+++ ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant Mon Aug 27 10:14:30 2012
@@ -0,0 +1,8 @@
+
+import antlib "org/apache/ant/antunit/antlib.xml" as antunit
+
+target imported
+{
+ antunit:assertEquals(expected = "test", actual = "test")
+ echo(message = "imported!")
+}
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: ant/sandbox/antdsl/branches/import-experiment/test/test-module/org/apache/ant/antdsl/test/build.ant
------------------------------------------------------------------------------
svn:mime-type = text/xml