David Morgan Spencer Savage | cb9fc3c | 2009-09-18 15:53:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
David Morgan Spencer Savage | 5571dc3 | 2009-09-18 15:47:02 +0000 | [diff] [blame] | 19 | import java.util.jar.JarFile |
| 20 | |
| 21 | def processFeature(file,writer) { |
| 22 | def jar = new JarFile(file) |
| 23 | |
| 24 | if (jar.getEntry( "feature.xml" ) != null) { |
| 25 | def path = 'features/' + file.getName() |
| 26 | def attrs = jar.getManifest().getMainAttributes() |
| 27 | |
| 28 | def id = attrs.getValue('Bundle-SymbolicName') |
| 29 | def version = attrs.getValue('Bundle-Version') |
| 30 | |
| 31 | writer.println( ' <feature url="' + path + '" id="' + id + '" version="' + version + '">' ) |
| 32 | writer.println( ' <category name="Sigil"/>') |
| 33 | writer.println( ' </feature>' ) |
| 34 | } |
| 35 | |
| 36 | jar.close() |
| 37 | } |
| 38 | |
| 39 | def findJars(dir,closure) { |
| 40 | dir.eachFileRecurse() { f -> |
| 41 | if (f ==~ /.*jar$/) closure( f ) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | |
| 46 | def generateUpdateSite(dir,site) { |
| 47 | def writer = new PrintWriter( site ) |
| 48 | writer.println('<site>') |
| 49 | |
| 50 | findJars( dir, { f -> processFeature( f, writer ) } ) |
| 51 | |
| 52 | writer.println(' <category-def name="Sigil" label="Sigil-Core"> ') |
| 53 | writer.println(' <description>') |
| 54 | writer.println(' Sigil is an SDK for developing OSGi applications') |
| 55 | writer.println(' </description>') |
| 56 | writer.println(' </category-def>') |
| 57 | writer.println('</site>') |
| 58 | |
| 59 | writer.close() |
| 60 | } |
| 61 | |
| 62 | args.each{ ant.echo(message:it) } |
| 63 | |
| 64 | def dir = new File( args[0] ) |
| 65 | def site = new File( args[1] ) |
| 66 | |
| 67 | generateUpdateSite(dir, site) |