ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1377330 - in /ant/sandbox/antdsl/branches/import-experiment: ./ org.apache.ant.antdsl/ org.apache.ant.antdsl/src/org/apache/ant/antdsl/ org.apache.ant.antdsl/src/org/apache/ant/antdsl/xtext/ test/
Date Sat, 25 Aug 2012 17:21:06 GMT
Author: hibou
Date: Sat Aug 25 17:21:05 2012
New Revision: 1377330

URL: http://svn.apache.org/viewvc?rev=1377330&view=rev
Log:
Start experimenting an import model based on OSGi:
- Ant + AntDSLProjectHelper + Felix is the framework
- Ant task jars are bundles: test/build.ant is working
- imported build files should be "within" a bundle: not working at all, need to access some
OSGi classloader...

Added:
    ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
  (with props)
    ant/sandbox/antdsl/branches/import-experiment/test/ant-antunit-1.2.bnd
    ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh   (with props)
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/ivysettings.xml
    ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.classpath
    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/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=1377330&r1=1377329&r2=1377330&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/build.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/build.xml Sat Aug 25 17:21:05 2012
@@ -57,6 +57,7 @@
         </path>
         <echo message="${toString:antruntime.classpath}" file=".antruntime.classpath"
/>
         <echo message="${toString:generate.classpath}" file=".generate.classpath" />
+        <ivy:retrieve conf="osgi" pattern="${basedir}/org.apache.ant.antdsl/lib/[type]s/[artifact]-[revision](.[ext])"
sync="true" />
         <copy file="${basedir}/build-deps/apache-ant-1.9.0alpha/lib/ant.jar" tofile="${basedir}/org.apache.ant.antdsl/lib/jars/ant-1.9.0alpha.jar"
/>
         <jar destfile="${basedir}/org.apache.ant.antdsl/lib/sources/ant-1.9.0alpha.jar"
basedir="${basedir}/build-deps/apache-ant-1.9.0alpha/src/main" />
     </target>

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=1377330&r1=1377329&r2=1377330&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/ivy-fixed.xml Sat Aug 25 17:21:05 2012
@@ -4,7 +4,7 @@
 		module="ant-dsl"
 		revision="1.0.0"
 		status="integration"
-		publication="20120825184447"
+		publication="20120822212844"
 	/>
 	<configurations>
 		<conf name="default" visibility="public"/>
@@ -28,6 +28,7 @@
 		<conf name="use_org.eclipse.xtend2.lib" visibility="public" description="Exported package
org.eclipse.xtend2.lib" extends="default"/>
 		<conf name="antruntime" visibility="public" extends="default"/>
 		<conf name="generate" visibility="public" extends="optional"/>
+		<conf name="osgi" visibility="public"/>
 	</configurations>
 	<publications>
 	</publications>
@@ -157,5 +158,6 @@
 		<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="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=1377330&r1=1377329&r2=1377330&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/ivy.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/ivy.xml Sat Aug 25 17:21:05 2012
@@ -5,6 +5,7 @@
     <configurations>
         <conf name="antruntime" extends="default" />
         <conf name="generate" extends="optional" />
+        <conf name="osgi" />
     </configurations>
     <dependencies>
         <!-- ambiguity fix -->
@@ -16,6 +17,8 @@
         <!-- 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" />
+
         <!-- provided -->
         <exclude org="package" module="javax.xml.parsers" />
         <exclude org="package" module="javax.xml.transform" />

Modified: ant/sandbox/antdsl/branches/import-experiment/ivysettings.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/ivysettings.xml?rev=1377330&r1=1377329&r2=1377330&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/ivysettings.xml (original)
+++ ant/sandbox/antdsl/branches/import-experiment/ivysettings.xml Sat Aug 25 17:21:05 2012
@@ -10,6 +10,7 @@
     </caches>
 
     <resolvers>
+        <ibiblio name="maven" m2compatible="true" />
 
         <updatesite name="eclipse-juno" url="http://download.eclipse.org/releases/juno"
cache="eclipse-juno" requirementStrategy="first" />
         <updatesite name="xtext" url="http://download.itemis.com/updates/releases" cache="xtext"
requirementStrategy="first" />
@@ -17,6 +18,7 @@
         <chain name="all" returnFirst="true">
             <resolver ref="eclipse-juno" />
             <resolver ref="xtext" />
+            <resolver ref="maven" />
         </chain>
 
     </resolvers>

Modified: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.classpath
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/.classpath?rev=1377330&r1=1377329&r2=1377330&view=diff
==============================================================================
Binary files - no diff available.

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=1377330&r1=1377329&r2=1377330&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
Sat Aug 25 17:21:05 2012
@@ -68,6 +68,10 @@ public abstract class AbstractAntDslProj
 
     public static final String REFID_FUNCTION_REGISTRY = "antdsl.function.registry";
 
+    public static final String REFID_OSGI_FRAMEWORK_MANAGER = "antdsl.osgi.framework.manager";
+
+    public static final String REFID_CLASSLOADER_STACK = "antdsl.classloader.stack";
+
     public String getDefaultBuildFile() {
         return "build.ant";
     }
@@ -93,6 +97,22 @@ 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>();
+            project.addReference(REFID_CLASSLOADER_STACK, classloaderStack);
+        }
+
         if (getImportStack().size() > 1) {
             context.setIgnoreProjectTag(true);
             Target currentTarget = context.getCurrentTarget();
@@ -114,6 +134,8 @@ public abstract class AbstractAntDslProj
             }
         } else {
             // top level file
+            classloaderStack.push(getOSGiFrameworkManager(project).getGodClassLoader());
+
             context.setCurrentTargets(new HashMap<String, Target>());
             parse(project, source, context);
 
@@ -145,6 +167,14 @@ public abstract class AbstractAntDslProj
         }
     }
 
+    private OSGiFrameworkManager getOSGiFrameworkManager(Project p) {
+        return p.getReference(REFID_OSGI_FRAMEWORK_MANAGER);
+    }
+
+    private Stack<ClassLoader> getClassloaderStack(Project p) {
+        return p.getReference(REFID_CLASSLOADER_STACK);
+    }
+
     private void parse(Project project, Object source, AntDslContext context) {
         File buildFile = null;
         URL url = null;
@@ -306,6 +336,96 @@ public abstract class AbstractAntDslProj
         return projectName;
     }
 
+    protected void setupAntpath(Project project, AntDslContext context, List<InnerElement>
antpathElements) {
+        UnknownElement element = new UnknownElement("path");
+        element.setProject(project);
+        RuntimeConfigurable wrapper = new RuntimeConfigurable(element, element.getTaskName());
+        context.pushWrapper(wrapper);
+        for (InnerElement antpathElement : antpathElements) {
+            UnknownElement child = mapUnknown(project, context, antpathElement, false);
+            element.addChild(child);
+        }
+        context.popWrapper();
+
+        Path path = new Path(project);
+        element.configure(path);
+
+        OSGiFrameworkManager osgiFrameworkManager = getOSGiFrameworkManager(project);
+        Iterator<Resource> itResources = path.iterator();
+        while (itResources.hasNext()) {
+            Resource resource = itResources.next();
+            String url;
+            if (resource instanceof URLProvider) {
+                url = ((URLProvider) resource).getURL().toExternalForm();
+            } else if (resource instanceof FileProvider) {
+                try {
+                    url = ((FileProvider) resource).getFile().toURI().toURL().toExternalForm();
+                } catch (MalformedURLException e) {
+                    throw new BuildException("Unable to get url of " + resource, e);
+                }
+            } else {
+                // very speculative, but let's try
+                url = resource.getName();
+            }
+            try {
+                osgiFrameworkManager.install(url);
+            } catch (BundleException e) {
+                throw new BuildException("Unable to install the bundle " + resource.getName()
+ " (" + e.getMessage() + ")", e);
+            }
+        }
+    }
+
+    protected void importAntlib(Project project, AntDslContext context, String name, String
resource) {
+        // FIXME seems ugly
+        String uri = UUID.randomUUID().toString();
+
+        ClassLoader cl = getClassloaderStack(project).peek();
+
+        Taskdef taskdef = new Taskdef();
+        taskdef.setProject(project);
+        taskdef.setResource(resource);
+        taskdef.setURI(uri);
+        taskdef.setAntlibClassLoader(cl);
+        taskdef.execute();
+        context.addNamespace(name, uri);
+    }
+
+    protected void importBuildModule(Project project, AntDslContext context, String buildModule)
{
+        ClassLoader cl = getClassloaderStack(project).peek();
+
+        URL buildUrl = cl.getResource(buildModule);
+        if (buildUrl == null) {
+            throw new BuildException("Unable to find the build module " + buildModule);
+        }
+        URLResource urlResource = new URLResource(buildUrl);
+
+        Vector<Object> importStack = getImportStack();
+
+        if (importStack.contains(urlResource)) {
+            project.log("Skipped already imported file:\n" + urlResource + "\n", Project.MSG_VERBOSE);
+            return;
+        }
+
+        ProjectHelper subHelper = ProjectHelperRepository.getInstance().getProjectHelperForBuildFile(urlResource);
+
+        // TODO
+        // add to the classloader stack the classloader of the imported build
+        
+        // push current stacks into the sub helper
+        subHelper.getImportStack().addAll(this.getImportStack());
+        subHelper.getExtensionStack().addAll(this.getExtensionStack());
+        project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, subHelper);
+
+        subHelper.parse(project, urlResource);
+
+        // push back the stack from the sub helper to the main one
+        project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, this);
+        getImportStack().clear();
+        getImportStack().addAll(subHelper.getImportStack());
+        getExtensionStack().clear();
+        getExtensionStack().addAll(subHelper.getExtensionStack());
+    }
+
     public void mapCommonTarget(
             Target target, Project project, AntDslContext context, String name, String description,
List<String> depends, List<String> extensionsOf,
             String onMiss) {

Added: 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=1377330&view=auto
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
(added)
+++ ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
Sat Aug 25 17:21:05 2012
@@ -0,0 +1,179 @@
+package org.apache.ant.antdsl;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+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;
+
+import org.apache.tools.ant.BuildException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+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";
+
+    private Framework framework;
+
+    private List<Bundle> bundleToStart = new ArrayList<Bundle>();
+
+    private Map<String, ClassLoader> classloaders = new LinkedHashMap<String, ClassLoader>();
+
+    private GodClassLoader 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) {
+            throw new BuildException("No OSGi framework could be found in Ant's classpath");
+        }
+        BufferedReader br = null;
+        try {
+            br = new BufferedReader(new InputStreamReader(url.openStream()));
+            for (String s = br.readLine(); s != null; s = br.readLine()) {
+                s = s.trim();
+                // Try to load first non-empty, non-commented line.
+                if ((s.length() > 0) && (s.charAt(0) != '#')) {
+                    return (FrameworkFactory) Class.forName(s).newInstance();
+                }
+            }
+        } catch (Exception e) {
+            throw new BuildException("The OSGi framework factory could not be instanciated
(" + e.getMessage() + ")", e);
+        } finally {
+            if (br != null) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    // don't care
+                }
+            }
+        }
+        throw new BuildException("No OSGi framework factory found");
+    }
+
+    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);
+        }
+    }
+
+    private static boolean isFragment(Bundle bundle) {
+        return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
+    }
+
+    public void start() throws BundleException {
+        framework.start();
+        Runtime.getRuntime().addShutdownHook(new Thread("OSGi Framwork Shutdown Hook") {
+            public void run() {
+                try {
+                    if (framework != null) {
+                        framework.stop();
+                        framework.waitForStop(0);
+                    }
+                } catch (Exception ex) {
+                    System.err.println("Error stopping framework: " + ex);
+                }
+            }
+        });
+        for (Bundle bundle : bundleToStart) {
+            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);
+        }
+
+        @Override
+        public Class< ? > loadClass(String name) throws ClassNotFoundException {
+            return bundle.loadClass(name);
+        }
+    }
+
+    private class GodClassLoader extends ClassLoader {
+
+        private GodClassLoader() {
+            super(null);
+        }
+
+        @Override
+        public URL getResource(String name) {
+            for (ClassLoader cl : classloaders.values()) {
+                URL url = cl.getResource(name);
+                if (url != null) {
+                    return url;
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public Enumeration<URL> getResources(String name) throws IOException {
+            List<URL> urls = new ArrayList<URL>();
+            for (ClassLoader cl : classloaders.values()) {
+                Enumeration<URL> resources = cl.getResources(name);
+                if (resources != null) {
+                    urls.addAll(Collections.list(resources));
+                }
+            }
+            return Collections.enumeration(urls);
+        }
+
+        @Override
+        public Class< ? > loadClass(String name) throws ClassNotFoundException {
+            for (ClassLoader cl : classloaders.values()) {
+                try {
+                    return cl.loadClass(name);
+                } catch (ClassNotFoundException e) {
+                    // next...
+                }
+            }
+            throw new ClassNotFoundException();
+        }
+
+    }
+
+}

Propchange: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/sandbox/antdsl/branches/import-experiment/org.apache.ant.antdsl/src/org/apache/ant/antdsl/OSGiFrameworkManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1377330&r1=1377329&r2=1377330&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
Sat Aug 25 17:21:05 2012
@@ -28,13 +28,22 @@ EProject:
       & ('default' ':' default=Identifier)?
       & ('basedir' ':' basedir=StringLiteral)?
     )
-    ('namespaces' '{' namespaces+=ENamespace* '}')?
+    ('antpath' '{' antpath+=EInnerElement* '}')?
+    ('import' imports+=EImport)*
     tasks=ETaskLists?
     (targets+=ETarget | extensionPoints+=EExtensionPoint | functionDefs+=EFunctionDef)*
 ;
 
-ENamespace:
-    name=Identifier ':' uri=StringLiteral
+EImport:
+    EAntlibImport | EBuildImport
+;
+
+EAntlibImport:
+    'antlib' resource=StringLiteral 'as' name=Identifier
+;
+
+EBuildImport:
+    'module' name=QualifiedName
 ;
 
 EExtensionPoint:
@@ -353,6 +362,11 @@ terminal Identifier:
     | '`' !('`')+ '`'
 ;
 
+terminal QualifiedName:
+      Identifier*
+      ('.' Identifier)*
+;
+
 terminal fragment Letter:
       '\u0024'
     | '\u0041'..'\u005a'

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=1377330&r1=1377329&r2=1377330&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
Sat Aug 25 17:21:05 2012
@@ -64,10 +64,12 @@ import org.apache.ant.antdsl.expr.Ternar
 import org.apache.ant.antdsl.expr.VariableAntExpression;
 import org.apache.ant.antdsl.xtext.antdsl.EAdditiveExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EAndExpr;
+import org.apache.ant.antdsl.xtext.antdsl.EAntlibImport;
 import org.apache.ant.antdsl.xtext.antdsl.EArgument;
 import org.apache.ant.antdsl.xtext.antdsl.EArguments;
 import org.apache.ant.antdsl.xtext.antdsl.EBooleanLiteralExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EBranch;
+import org.apache.ant.antdsl.xtext.antdsl.EBuildImport;
 import org.apache.ant.antdsl.xtext.antdsl.ECharacterLiteralExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EConditionedTasks;
 import org.apache.ant.antdsl.xtext.antdsl.EConditionnalAndExpr;
@@ -85,6 +87,7 @@ import org.apache.ant.antdsl.xtext.antds
 import org.apache.ant.antdsl.xtext.antdsl.EFuncExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EFunctionDef;
 import org.apache.ant.antdsl.xtext.antdsl.EHexLiteralExpr;
+import org.apache.ant.antdsl.xtext.antdsl.EImport;
 import org.apache.ant.antdsl.xtext.antdsl.EInclusiveOrExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EInnerElement;
 import org.apache.ant.antdsl.xtext.antdsl.EInnerElements;
@@ -92,7 +95,6 @@ import org.apache.ant.antdsl.xtext.antds
 import org.apache.ant.antdsl.xtext.antdsl.ELocalAssignment;
 import org.apache.ant.antdsl.xtext.antdsl.ELocalPropertyFuncArgument;
 import org.apache.ant.antdsl.xtext.antdsl.EMultiplicativeExpr;
-import org.apache.ant.antdsl.xtext.antdsl.ENamespace;
 import org.apache.ant.antdsl.xtext.antdsl.ENullExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EOctalLiteralExpr;
 import org.apache.ant.antdsl.xtext.antdsl.EProject;
@@ -162,10 +164,27 @@ public class AntDslXTextProjectHelper ex
 
         setupProject(project, context, name, basedir, def);
 
-        EList<ENamespace> namespaces = eProject.getNamespaces();
-        if (namespaces != null) {
-            for (ENamespace namespace : namespaces) {
-                context.addNamespace(readIdentifier(namespace.getName()), readString(namespace.getUri()));
+        EList<EInnerElement> eAntpathElements = eProject.getAntpath();
+        if (eAntpathElements != null) {
+            List<InnerElement> antpathElements = new ArrayList<InnerElement>();
+            for (EInnerElement eAntpathElement : eAntpathElements) {
+                antpathElements.add(mapInnerElement(project, context, eAntpathElement));
+            }
+            setupAntpath(project, context, antpathElements);
+        }
+
+        EList<EImport> eImports = eProject.getImports();
+        if (eImports != null) {
+            for (EImport eImport : eImports) {
+                if (eImport instanceof EAntlibImport) {
+                    EAntlibImport eAntlibImport = (EAntlibImport) eImport;
+                    importAntlib(project, context, readIdentifier(eAntlibImport.getName()),
readString(eAntlibImport.getResource()));
+                } else if (eImport instanceof EBuildImport) {
+                    EBuildImport eBuildImport = (EBuildImport) eImport;
+                    // TODO
+                } else {
+                    throw new IllegalArgumentException("Unsupported import " + eImport.getClass().getName());
+                }
             }
         }
 

Propchange: ant/sandbox/antdsl/branches/import-experiment/test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Aug 25 17:21:05 2012
@@ -0,0 +1,2 @@
+org.apache.ant.antunit-1.2.jar
+ant-antunit-1.2.jar

Added: ant/sandbox/antdsl/branches/import-experiment/test/ant-antunit-1.2.bnd
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/test/ant-antunit-1.2.bnd?rev=1377330&view=auto
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/ant-antunit-1.2.bnd (added)
+++ ant/sandbox/antdsl/branches/import-experiment/test/ant-antunit-1.2.bnd Sat Aug 25 17:21:05
2012
@@ -0,0 +1,4 @@
+version=1.2
+
+Bundle-Version: ${version}
+Bundle-SymbolicName: org.apache.ant.antunit

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=1377330&r1=1377329&r2=1377330&view=diff
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/build.ant (original)
+++ ant/sandbox/antdsl/branches/import-experiment/test/build.ant Sat Aug 25 17:21:05 2012
@@ -1,72 +1,13 @@
 name : myproject
 default : build
 
-namespaces {
-    antunit : "antlib:org.apache.ant.antunit"
+antpath {
+    file(file = "test/org.apache.ant.antunit-1.2.jar")
 }
+import antlib "org/apache/ant/antunit/antlib.xml" as antunit
 
-{
-    prop foo = "hello world!"
-    echo(message = ${foo})
-}
-
-# Some documentation of the function
-function myfunction(local t = "myfunction")
-{
-    echo(message = ${t})
-}
-
-function myfunction2(local dest, implicit element source)
-{
-    copy(todir = ${dest}, {
-        source()
-    })
-}
-
-target dep {
-    echo(message = "target dependency")
-}
-
-target notexecuted
-    unless isset(property = "foo")
-{
-    echo(message = "must not be printed")
-}
-
-# description of the target
-# which is on a multiline
 target build
-    depends dep, notexecuted
 {
-    copy(file = ${basedir} + "/test/build.ant", tofile = ${basedir} + "/build/test/build.ant.copy")
-    // some comment
-    jar(file = ${basedir} + "/build/test/my.jar" {
-        fileset(dir = ${basedir} + "/test", includes = "*.ant")
-    })
-    myfunction()
-    myfunction(t = "simple function")
-    /*
-     * Some multiline comment 
-     */
-    if (available(file = ${basedir} + "/test/build.ant")) {
-        myfunction2(dest = ${basedir} + "/build/test/dest", {
-            fileset(dir = ${basedir}, includes = "build.*")
-        })
-    } else {
-        fail(message = "fail !")
-    }
-    if (isset(property = "foo") && !isset(property = "notsetproperty")) {
-        echo(message = "test ok")
-    } else {
-        fail(message = "fail !")
-    }
-    echo(message = "test encoding\\backslash")
-    echo(message = "test encoding\ttab")
-    echo(message = "test encoding\nline")
-
-    local test = "hello" + ' ' + "world !"
-    echo(message = ${test})
-    local test2 = ((12345 + 6789) % 98765 == 12.4f)
-    echo(message = ${test2})
-    echo(message = eval("${test2}"))
+    antunit:assertEquals(expected = "test", actual = "test")
+    antunit:assertEquals(expected = "test", actual = "nok")
 }

Added: ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh
URL: http://svn.apache.org/viewvc/ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh?rev=1377330&view=auto
==============================================================================
--- ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh (added)
+++ ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh Sat Aug 25 17:21:05
2012
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+wget "http://repo1.maven.org/maven2/org/apache/ant/ant-antunit/1.2/ant-antunit-1.2.jar"
+bnd wrap -output org.apache.ant.antunit-1.2.jar -properties ant-antunit-1.2.bnd  ant-antunit-1.2.jar

Propchange: ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh
------------------------------------------------------------------------------
    svn:executable = *

Propchange: ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/sandbox/antdsl/branches/import-experiment/test/getAntUnitOSGi.sh
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message