alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (build.xml)

This example Groovy source code file (build.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

built-by, bundle-activator, bundle-classpath, bundle-name, bundle-symbolicname, bundle-vendor, bundle-vendor, bundle-version, bundle-version, groovy, groovy, import-package, osgi, osgi

The Groovy build.xml source code

<?xml version="1.0"?>
<project name="groovy-osgi-sample" default="print-results">

  <property name="build.dir" value="build"/>
  <property file="build.properties"/>
  <property name="groovy.jar" value="groovy-all-${groovy.version}.jar" />
  <property name="hello.bundle" value="hello-bundle-imports-groovy.jar" />
  <property name="hello.bundle.contains" value="hello-bundle-contains-groovy.jar" />
  <property name="harness.bundle" value="hello-groovy-test-harness.jar" />
    
  <taskdef name="groovyc"
	   classname="org.codehaus.groovy.ant.Groovyc"
	   classpathref="project.classpath"/>
  
  <target name="init" description="cleanup and reinitialize">
	  <path id="project.classpath">
		  <pathelement location="${osgi.jar}"/>
		  <pathelement location="${groovy.bin.dir}${file.separator}${groovy.jar}"/>
		  <pathelement location="${build.dir}${file.separator}${hello.bundle}"/>
	  </path>
	  
	  <delete dir="${build.dir}" />
	  <mkdir dir="${build.dir}${file.separator}hello-groovy-bundle" />
	  <mkdir dir="${build.dir}${file.separator}hello-groovy-test-harness" />
  </target>
  
  <target name="make-hello-groovy-bundle" description="compile and build the Hello Groovy bundles">
  
    <groovyc destdir="${build.dir}${file.separator}hello-groovy-bundle"
	     srcdir=".${file.separator}hello-groovy-bundle"
              listfiles="true">
              <classpath refid="project.classpath"/>
    </groovyc>
    
    <!-- This jar file imports Groovy from the container -->
    <jar destfile="${build.dir}${file.separator}${hello.bundle}">
	    <fileset dir="${build.dir}${file.separator}hello-groovy-bundle"/>
	    <manifest>
		    <attribute name="Built-By" value="${user.name}"/>
		    <attribute name="provider" value="org.codehaus.groovy.osgi"/>
		    <attribute name="Bundle-ManifestVersion" value="2"/>
		    <attribute name="Bundle-Name" value="Groovy OSGi Example Bundle"/>
		    <attribute name="Bundle-SymbolicName" value="org.codehaus.groovy.osgi.hello-groovy-bundle"/>
		    <attribute name="Bundle-Version" value="1.0.0"/>
		    <attribute name="Bundle-Activator" value="org.codehaus.groovy.osgi.Activator"/>
		    <attribute name="Bundle-Vendor" value="Groovy"/>
		    <attribute name="Bundle-Localization" value="plugin"/>
		    <attribute name="Import-Package" value="groovy.lang;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.reflection;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime.callsite;version="1.7.0.beta-1-SNAPSHOT",org.w3c.dom,org.osgi.framework;version="1.3.0""/> 
		    <attribute name="Export-Package" value="org.codehaus.groovy.osgi;version="1.0.0""/> 
		    <attribute name="Bundle-ClassPath" value="."/>
	    </manifest>
    </jar>
    
    <!-- This jar includes the Groovy jar within itself-->
    <jar destfile="${build.dir}${file.separator}${hello.bundle.contains}">
	    <fileset dir="${build.dir}${file.separator}hello-groovy-bundle"/>
	    <fileset file="${groovy.bin.dir}${file.separator}${groovy.jar}" casesensitive="no" />
	    <manifest>
		    <attribute name="Built-By" value="${user.name}"/>
		    <attribute name="provider" value="org.codehaus.groovy.osgi"/>
		    <attribute name="Bundle-ManifestVersion" value="2"/>
		    <attribute name="Bundle-Name" value="Groovy OSGi Example Bundle"/>
		    <attribute name="Bundle-SymbolicName" value="org.codehaus.groovy.osgi.hello-groovy-bundle"/>
		    <attribute name="Bundle-Version" value="1.0.0"/>
		    <attribute name="Bundle-Activator" value="org.codehaus.groovy.osgi.Activator"/>
		    <attribute name="Bundle-Vendor" value="Groovy"/>
		    <attribute name="Bundle-Localization" value="plugin"/>
		    <attribute name="Import-Package" value="org.w3c.dom,org.osgi.framework;version="1.3.0""/> 
		    <attribute name="Export-Package" value="org.codehaus.groovy.osgi;version="1.0.0""/> 
		    <attribute name="Bundle-ClassPath" value=".,${groovy.jar}"/>
	    </manifest>
    </jar> 
  </target>

  <target name="make-harness-bundle" description="Makes the test harness bundle">
	  
	  <groovyc destdir="${build.dir}${file.separator}hello-groovy-test-harness"
		   srcdir=".${file.separator}hello-groovy-test-harness"
		   listfiles="true">
		  <classpath refid="project.classpath"/>
	  </groovyc>
	  
	  <jar destfile="${build.dir}${file.separator}${harness.bundle}">
		  <fileset dir="${build.dir}${file.separator}hello-groovy-test-harness"/>
		  <manifest>
			  <attribute name="Built-By" value="${user.name}"/>
			  <attribute name="provider" value="org.codehaus.groovy.osgi.harness"/>
			  <attribute name="Bundle-ManifestVersion" value="2"/>
			  <attribute name="Bundle-Name" value="Groovy OSGi Test Harness"/>
			  <attribute name="Bundle-SymbolicName" value="org.codehaus.groovy.osgi.harness.hello-groovy-test-harness"/>
			  <attribute name="Bundle-Version" value="1.0.0"/>
			  <attribute name="Bundle-Activator" value="org.codehaus.groovy.osgi.harness.HarnessActivator"/>
			  <attribute name="Bundle-Vendor" value="Groovy"/>
			  <attribute name="Bundle-Localization" value="plugin"/>
			  <attribute name="Import-Package" value="org.codehaus.groovy.runtime.typehandling;version="1.0.0",org.codehaus.groovy.osgi;version="1.0.0",groovy.lang;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.reflection;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime.callsite;version="1.7.0.beta-1-SNAPSHOT",org.w3c.dom,org.osgi.framework;version="1.3.0""/> 
			  <attribute name="Bundle-ClassPath" value="."/>
		  </manifest>
	  </jar>
	  
  </target>

  <target name="print-results" depends="init,make-hello-groovy-bundle,make-harness-bundle" description="compile and build everything">
	<makeurl file="${basedir}/${groovy.bin.dir}/${groovy.jar}" property="groovy.jar.url"/>
	<makeurl file="${basedir}/${build.dir}/${hello.bundle}" property="hello.jar1.url"/>
	<makeurl file="${basedir}/${build.dir}/${hello.bundle.contains}" property="hello.jar2.url"/>
	<makeurl file="${basedir}/${build.dir}/${harness.bundle}" property="harness.jar.url"/>
	
	<echo>To run the OSGi console, run the following command: 
 java -jar ${osgi.jar} -console 
To install these applications in the container, run the following commands in the OSGi container: 
 install ${groovy.jar.url}
 install ${hello.jar1.url}
 install ${hello.jar2.url}
 install ${harness.jar.url}
To start the applications in the container, run the following commands in the OSGi container: 
 start [bundle1] [bundle2]
Where [bundle1] and [bundle] are the bundle IDs printed by the console in the previous step.</echo>  
  </target>
</project>

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy build.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.