Brian O'Connor

Replacing karaf-assembly bash script with python script

Also, removing self-referencing repo from:
apps/openstackswitching/app/features.xml

Change-Id: I041325a1a114ee4d5ef01afd24f73db4f92b30b3
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 ~ limitations under the License. 15 ~ limitations under the License.
16 --> 16 -->
17 <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> 17 <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 - <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
19 <feature name="${project.artifactId}" version="${project.version}" 18 <feature name="${project.artifactId}" version="${project.version}"
20 description="${project.description}"> 19 description="${project.description}">
21 <feature>onos-api</feature> 20 <feature>onos-api</feature>
......
1 -#!/bin/bash
2 -# -----------------------------------------------------------------------------
3 -# Assembles together all bundles required to run ONOS off-line.
4 -# -----------------------------------------------------------------------------
5 -
6 -mkdir -p target
7 -
8 -features=target/features-list.xml
9 -repos=target/staged-repos.xml
10 -
11 -echo "<features>" > $repos
12 -echo " <repository>mvn:org.onosproject/onos-features/1.4.0-SNAPSHOT/xml/features</repository>" >> $repos
13 -
14 -# Find all app feature files
15 -find $ONOS_ROOT -name '*-features.xml' | grep -v features-repo > $features
16 -
17 -# Produce repository entry for each file
18 -cat $features | while read feature; do
19 - echo " <repository>file:$feature</repository>" >> $repos
20 -done
21 -
22 -# Create a synthetic feature that depends on all other ONOS features
23 -echo " <feature name=\"foo\">" >> $repos
24 -grep "feature name=" $ONOS_ROOT/features/features.xml | cut -d\" -f2 | while read f; do
25 - echo " <feature>$f</feature>" >> $repos
26 -done
27 -
28 -cat $features | while read feature; do
29 - grep "feature name=" $feature | cut -d\" -f2 | while read f; do
30 - echo " <feature>$f</feature>" >> $repos
31 - done
32 -done
33 -echo " </feature>" >> $repos
34 -
35 -echo "</features>" >> $repos
...\ No newline at end of file ...\ No newline at end of file
1 +#!/usr/bin/env python
2 +'''
3 + Builds synthetic feature file that includes all core, provider, and application
4 + features, so that we can pre-stage all bundles required to run ONOS off-line.
5 +'''
6 +
7 +import os
8 +import xml.etree.ElementTree as ET
9 +
10 +FEATURE_TAG = '{http://karaf.apache.org/xmlns/features/v1.2.0}feature'
11 +STAGED_REPOS = 'target/staged-repos.xml'
12 +
13 +if 'ONOS_ROOT' in os.environ:
14 + ONOS_ROOT = os.environ['ONOS_ROOT']
15 +else:
16 + # fallback to working directory if ONOS_ROOT is not set
17 + ONOS_ROOT = os.getcwd()
18 +
19 +def findFeatureFiles(path=ONOS_ROOT):
20 + #only descend into target directories that have pom
21 + for root, dirs, files in os.walk(path):
22 + if 'pom.xml' not in files:
23 + if 'target' in dirs:
24 + #pruning target dir with no pom.xml
25 + dirs.remove('target')
26 + if '/target' in root:
27 + if '/classes/' in root:
28 + #filter out features.xml for maven-plugin
29 + continue
30 + for f in files:
31 + if f.endswith('features.xml'):
32 + yield os.path.join(root, f)
33 +
34 +def featuresFromFile(file):
35 + features = []
36 + tree = ET.parse(file)
37 + root = tree.getroot()
38 + for feature in root.findall(FEATURE_TAG):
39 + features.append(feature.attrib['name'])
40 + return features
41 +
42 +if __name__ == '__main__':
43 + outputTree = ET.Element('features')
44 + uberFeature = ET.Element('feature', attrib={'name' : 'onos-uber-synthetic'})
45 + for file in findFeatureFiles():
46 + features = featuresFromFile(file)
47 + if len(features) > 0:
48 + ET.SubElement(outputTree, 'repository').text = 'file:%s' % file
49 + for feature in features:
50 + ET.SubElement(uberFeature, 'feature').text = feature
51 + outputTree.append(uberFeature)
52 +
53 + outputFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), STAGED_REPOS)
54 + outputDir = os.path.dirname(outputFile)
55 + if not os.path.exists(outputDir):
56 + os.mkdir(outputDir)
57 + ET.ElementTree(outputTree).write(outputFile)
58 +
59 + import sys
60 + if '-d' in sys.argv:
61 + # -------- TODO for debug only --------
62 + def indent(elem, level=0):
63 + #function borrowed from: http://effbot.org/zone/element-lib.htm#prettyprint
64 + i = "\n" + level*" "
65 + if len(elem):
66 + if not elem.text or not elem.text.strip():
67 + elem.text = i + " "
68 + if not elem.tail or not elem.tail.strip():
69 + elem.tail = i
70 + for elem in elem:
71 + indent(elem, level+1)
72 + if not elem.tail or not elem.tail.strip():
73 + elem.tail = i
74 + else:
75 + if level and (not elem.tail or not elem.tail.strip()):
76 + elem.tail = i
77 +
78 + print 'Writing to file:', outputFile
79 + indent(outputTree)
80 + ET.dump(outputTree)
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
42 <phase>generate-sources</phase> 42 <phase>generate-sources</phase>
43 <configuration> 43 <configuration>
44 <target> 44 <target>
45 - <exec executable="bash"> 45 + <exec executable="python">
46 - <arg value="${basedir}/onos-assembly"/> 46 + <arg value="${basedir}/onos-assembly.py"/>
47 </exec> 47 </exec>
48 </target> 48 </target>
49 </configuration> 49 </configuration>
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
70 <descriptor>file:${basedir}/target/staged-repos.xml</descriptor> 70 <descriptor>file:${basedir}/target/staged-repos.xml</descriptor>
71 </descriptors> 71 </descriptors>
72 <features> 72 <features>
73 - <feature>foo</feature> 73 + <feature>onos-uber-synthetic</feature>
74 </features> 74 </features>
75 <repository>target/repo</repository> 75 <repository>target/repo</repository>
76 </configuration> 76 </configuration>
......