use groovy script to generate update site.xml (FELIX-1597)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@816682 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/bldcommon/updatesite.groovy b/sigil/bldcommon/updatesite.groovy
new file mode 100644
index 0000000..de8ac77
--- /dev/null
+++ b/sigil/bldcommon/updatesite.groovy
@@ -0,0 +1,49 @@
+import java.util.jar.JarFile
+
+def processFeature(file,writer) {
+  def jar = new JarFile(file)
+
+  if (jar.getEntry( "feature.xml" ) != null) {
+    def path = 'features/' + file.getName()
+    def attrs = jar.getManifest().getMainAttributes()
+
+    def id = attrs.getValue('Bundle-SymbolicName')
+    def version = attrs.getValue('Bundle-Version')
+
+    writer.println( '  <feature url="' + path + '" id="' + id + '" version="' + version + '">' )
+    writer.println( '    <category name="Sigil"/>')
+    writer.println( '  </feature>' )
+  }
+
+  jar.close()
+}
+
+def findJars(dir,closure) {
+  dir.eachFileRecurse() { f ->
+    if (f ==~ /.*jar$/) closure( f )
+  }
+}
+
+
+def generateUpdateSite(dir,site) {
+  def writer = new PrintWriter( site )
+  writer.println('<site>')
+
+  findJars( dir, { f -> processFeature( f, writer ) } )
+
+  writer.println('  <category-def name="Sigil" label="Sigil-Core"> ')
+  writer.println('    <description>')
+  writer.println('      Sigil is an SDK for developing OSGi applications')
+  writer.println('    </description>')
+  writer.println('  </category-def>')
+  writer.println('</site>')
+
+  writer.close()
+}
+
+args.each{ ant.echo(message:it) }
+
+def dir = new File( args[0] )
+def site = new File( args[1] )
+
+generateUpdateSite(dir, site)
diff --git a/sigil/build.xml b/sigil/build.xml
index 619ad05..3e17dbc 100644
--- a/sigil/build.xml
+++ b/sigil/build.xml
@@ -18,8 +18,11 @@
   under the License.
 -->
 <project name="sigil" default="dist" 
-  xmlns:ivy="antlib:org.apache.ivy.ant">
+  xmlns:ivy="antlib:org.apache.ivy.ant"
+  xmlns:groovy="antlib:org.codehaus.groovy">
+
   <import file="bldcommon/common.xml"/>
+
   <fileset id="my.projects" dir="${basedir}">
     <exclude name="ivy/resolver/test/**/${build_xml}"/>
     <exclude name="ivy/resolver/example/**/${build_xml}"/>
@@ -35,12 +38,11 @@
 
   <target name="clean" depends="clean-list, clean-site" />
 
-  <target name="build" depends="build-list" />
+  <target name="build" depends="init, build-list" />
 
   <target name="report" depends="report-list" />
 
-  <target name="site" depends="common-init">
-    <copy file="eclipse/updatesite/site.xml" todir="${site.dir}" />
+  <target name="site" depends="bldcommon.init">
     <!-- eclipse features -->
     <ivy:retrieve organisation="org.apache" module="felix.sigil.eclipse.core.feature" revision="latest.integration" inline="true" pattern="${site.dir}/features/[artifact]_${buildVersion}.[ext]" transitive="false"/>
     <ivy:retrieve organisation="org.apache" module="felix.sigil.eclipse.obr.feature" revision="latest.integration" inline="true" pattern="${site.dir}/features/[artifact]_${buildVersion}.[ext]" transitive="false"/>
@@ -66,6 +68,11 @@
     
     <!-- ivy -->
     <ivy:retrieve organisation="org.apache" module="felix.sigil.ivy.resolver" revision="latest.integration" inline="true" pattern="${site.dir}/ivy/[artifact].[ext]" transitive="false"/>
+
+    <groovy:groovy src="bldcommon/updatesite.groovy">
+      <arg value="${site.dir}/features"/>
+      <arg value="${site.dir}/site.xml" />
+    </groovy:groovy>
   </target>
 
   <target name="clean-site">