Committed by
Thomas Vachuska
Generate onos_app rule
There are three genrules: 1. Build features.xml 2. Build app.xml 3. Generate app.oar Change-Id: I6adfd47fadf40ad2440998071a01894458629ac6
Showing
8 changed files
with
297 additions
and
15 deletions
... | @@ -14,7 +14,7 @@ TEST_DEPS = [ | ... | @@ -14,7 +14,7 @@ TEST_DEPS = [ |
14 | '//lib:TEST', | 14 | '//lib:TEST', |
15 | ] | 15 | ] |
16 | 16 | ||
17 | -java_library( | 17 | +osgi_jar( |
18 | name = CURRENT_NAME, | 18 | name = CURRENT_NAME, |
19 | srcs = glob([SRC + '/*.java']), | 19 | srcs = glob([SRC + '/*.java']), |
20 | deps = COMPILE_DEPS, | 20 | deps = COMPILE_DEPS, |
... | @@ -29,3 +29,16 @@ java_test( | ... | @@ -29,3 +29,16 @@ java_test( |
29 | [CURRENT_TARGET], | 29 | [CURRENT_TARGET], |
30 | source_under_test = [CURRENT_TARGET], | 30 | source_under_test = [CURRENT_TARGET], |
31 | ) | 31 | ) |
32 | + | ||
33 | +BUNDLES = [ | ||
34 | + (CURRENT_TARGET, ONOS_GROUP_ID + ':' + CURRENT_NAME + ':' + ONOS_VERSION), | ||
35 | +] | ||
36 | + | ||
37 | +onos_app( | ||
38 | + app_name = 'org.onosproject.fwd', | ||
39 | + title = 'Reactive Forwarding App', | ||
40 | + category = 'Traffic Steering', | ||
41 | + url = 'http://onosproject.org', | ||
42 | + description = 'Reactive forwarding application using flow subsystem.', | ||
43 | + included_bundles = BUNDLES, | ||
44 | +) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -6,6 +6,21 @@ python_binary( | ... | @@ -6,6 +6,21 @@ python_binary( |
6 | ) | 6 | ) |
7 | 7 | ||
8 | python_binary( | 8 | python_binary( |
9 | + name = 'onos-app-writer', | ||
10 | + main = 'onos_app.py', | ||
11 | + deps = [], | ||
12 | + visibility = ['PUBLIC'], | ||
13 | +) | ||
14 | + | ||
15 | +python_binary( | ||
16 | + name = 'onos-app-oar', | ||
17 | + main = 'onos_oar.py', | ||
18 | + deps = [], | ||
19 | + visibility = ['PUBLIC'], | ||
20 | +) | ||
21 | + | ||
22 | + | ||
23 | +python_binary( | ||
9 | name = 'pack_war', | 24 | name = 'pack_war', |
10 | main = 'pack_war.py', | 25 | main = 'pack_war.py', |
11 | deps = [':util'], | 26 | deps = [':util'], | ... | ... |
1 | include_defs('//bucklets/maven_jar.bucklet') | 1 | include_defs('//bucklets/maven_jar.bucklet') |
2 | include_defs('//bucklets/onos.bucklet') | 2 | include_defs('//bucklets/onos.bucklet') |
3 | +include_defs('//bucklets/onos_app.bucklet') | ||
3 | 4 | ||
4 | BASE_DEPS = [ | 5 | BASE_DEPS = [ |
5 | '//lib:junit', | 6 | '//lib:junit', |
6 | '//lib:hamcrest-all', | 7 | '//lib:hamcrest-all', |
7 | '//lib:slf4j-api', | 8 | '//lib:slf4j-api', |
8 | '//lib:guava-testlib', | 9 | '//lib:guava-testlib', |
9 | -] | 10 | +] |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
buck-tools/onos_app.py
0 → 100755
1 | +#!/usr/bin/env python | ||
2 | +#FIXME Add license | ||
3 | + | ||
4 | +##### Templates for features.xml | ||
5 | +FEATURES_HEADER = '''\ | ||
6 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
7 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" | ||
8 | + name="%(feature_repo_name)s"> | ||
9 | +''' | ||
10 | +FEATURE_HEADER= '''\ | ||
11 | + <feature name="%(feature_name)s" version="%(version)s" | ||
12 | + description="%(title)s"> | ||
13 | +''' | ||
14 | +EXISTING_FEATURE = ' <feature>%s</feature>\n' | ||
15 | +BUNDLE = ' <bundle>%s</bundle>\n' | ||
16 | +FEATURE_FOOTER = ' </feature>\n' | ||
17 | +FEATURES_FOOTER = '</features>' | ||
18 | + | ||
19 | +##### Templates for app.xml | ||
20 | +APP_HEADER = '''\ | ||
21 | +<?xml version="1.0" encoding="UTF-8"?> | ||
22 | +<app name="%(app_name)s" origin="%(origin)s" version="%(version)s" | ||
23 | + title="%(title)s" category="%(category)s" url="%(url)s" | ||
24 | + featuresRepo="%(feature_repo_name)s" | ||
25 | + features="%(feature_name)s" apps="%(apps)s"> | ||
26 | + <description>%(description)s</description> | ||
27 | +''' | ||
28 | +ARTIFACT = ' <artifact>%s</artifact>\n' | ||
29 | +APP_FOOTER = '</app>' | ||
30 | + | ||
31 | + | ||
32 | +def mvnUrl(bundle): | ||
33 | + return 'mvn:' + bundle.replace(':', '/') | ||
34 | + | ||
35 | +def generateFeatureFile(feature_name, | ||
36 | + version, | ||
37 | + title, | ||
38 | + feature_repo_name, | ||
39 | + features = [], | ||
40 | + bundles = [], | ||
41 | + **kwargs): | ||
42 | + values = { | ||
43 | + 'feature_name' : feature_name, | ||
44 | + 'version' : version, | ||
45 | + 'title' : title, | ||
46 | + 'feature_repo_name' : '-'.join(feature_repo_name.split(':')[1:3]), | ||
47 | + } | ||
48 | + | ||
49 | + output = FEATURES_HEADER % values + FEATURE_HEADER % values | ||
50 | + | ||
51 | + for feature in features: | ||
52 | + output += EXISTING_FEATURE % feature | ||
53 | + | ||
54 | + for bundle in bundles: | ||
55 | + output += BUNDLE % mvnUrl(bundle) | ||
56 | + | ||
57 | + output += FEATURE_FOOTER + FEATURES_FOOTER | ||
58 | + return output | ||
59 | + | ||
60 | +def generateAppFile(app_name, | ||
61 | + origin, | ||
62 | + version, | ||
63 | + title, | ||
64 | + category, | ||
65 | + url, | ||
66 | + feature_repo_name, | ||
67 | + feature_name, | ||
68 | + description = None, | ||
69 | + apps = [], | ||
70 | + artifacts = [], | ||
71 | + **kwargs): | ||
72 | + values = { | ||
73 | + 'app_name' : app_name, | ||
74 | + 'origin' : origin, | ||
75 | + 'version' : version, | ||
76 | + 'title' : title, | ||
77 | + 'category' : category, | ||
78 | + 'url' : url, | ||
79 | + 'feature_repo_name' : mvnUrl(feature_repo_name) + '/xml/features', | ||
80 | + 'feature_name' : feature_name, | ||
81 | + } | ||
82 | + | ||
83 | + values['description'] = description if description else title | ||
84 | + values['apps'] = ','.join(apps) if apps else '' | ||
85 | + | ||
86 | + output = APP_HEADER % values | ||
87 | + | ||
88 | + for artifact in artifacts: | ||
89 | + output += ARTIFACT % mvnUrl(artifact) | ||
90 | + | ||
91 | + output += APP_FOOTER | ||
92 | + return output | ||
93 | + | ||
94 | + | ||
95 | +if __name__ == '__main__': | ||
96 | + import sys, optparse | ||
97 | + | ||
98 | + parser = optparse.OptionParser() | ||
99 | + parser.add_option("-n", "--name", dest="feature_name", help="Feature Name") | ||
100 | + parser.add_option("-a", "--app", dest="app_name", help="App Name") | ||
101 | + parser.add_option("-o", "--origin", dest="origin", help="Origin") | ||
102 | + parser.add_option("-c", "--category", dest="category", help="Category") | ||
103 | + parser.add_option("-u", "--url", dest="url", help="URL") | ||
104 | + parser.add_option("-v", "--version", dest="version", help="Version") | ||
105 | + parser.add_option("-t", "--title", dest="title", help="Title") | ||
106 | + parser.add_option("-r", "--repo", dest="repo_name", help="Repo Name") | ||
107 | + | ||
108 | + parser.add_option('-b', '--bundle', | ||
109 | + action="append", dest='included_bundles', | ||
110 | + metavar="BUNDLE", help='Included Bundle (multiple allowed)') | ||
111 | + parser.add_option('-e', '--excluded-bundle', | ||
112 | + action="append", dest='excluded_bundles', | ||
113 | + metavar="BUNDLE", help='Excluded Bundle (multiple allowed)') | ||
114 | + parser.add_option('-f', '--feature', | ||
115 | + action="append", dest='features', | ||
116 | + metavar="FEATURE", help='Existing Feature (multiple allowed)') | ||
117 | + parser.add_option('-d', '--apps', | ||
118 | + action="append", dest='apps', | ||
119 | + metavar="FEATURE", help='Required App (multiple allowed)') | ||
120 | + | ||
121 | + parser.add_option("-A", "--write-app", dest="write_app", action="store_true") | ||
122 | + parser.add_option("-F", "--write-features", dest="write_features", action="store_true") | ||
123 | + | ||
124 | + (options, args) = parser.parse_args() | ||
125 | + | ||
126 | + values = {} | ||
127 | + if options.feature_name and options.version and options.title: | ||
128 | + values['feature_name'] = options.feature_name.split(':')[1] | ||
129 | + values['version'] = options.version | ||
130 | + values['title'] = options.title | ||
131 | + else: | ||
132 | + sys.stderr.write('ERROR: Feature Name, Version, and Title are required\n') | ||
133 | + sys.stderr.flush() | ||
134 | + sys.exit(1) | ||
135 | + | ||
136 | + if options.app_name and options.origin and options.category and options.url: | ||
137 | + values['app_name'] = options.app_name | ||
138 | + values['origin'] = options.origin | ||
139 | + values['category'] = options.category | ||
140 | + values['url'] = options.url | ||
141 | + elif options.write_app: | ||
142 | + sys.stderr.write('ERROR: Feature Name, Version, and Title are required\n') | ||
143 | + sys.stderr.flush() | ||
144 | + sys.exit(1) | ||
145 | + | ||
146 | + values['feature_repo_name'] = options.repo_name if options.repo_name \ | ||
147 | + else options.feature_name | ||
148 | + | ||
149 | + if options.write_features: | ||
150 | + bundles = [] | ||
151 | + if options.included_bundles: | ||
152 | + bundles += options.included_bundles | ||
153 | + if options.excluded_bundles: | ||
154 | + bundles += options.excluded_bundles | ||
155 | + print generateFeatureFile(bundles=bundles, | ||
156 | + features=options.features, | ||
157 | + **values) | ||
158 | + if options.write_app: | ||
159 | + print generateAppFile(artifacts=options.included_bundles, | ||
160 | + apps=options.apps, | ||
161 | + **values) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
buck-tools/onos_oar.py
0 → 100755
1 | +#!/usr/bin/env python | ||
2 | +#FIXME Add license | ||
3 | + | ||
4 | +from zipfile import ZipFile | ||
5 | + | ||
6 | +def generateOar(output, files=[]): | ||
7 | + # Note this is not a compressed zip | ||
8 | + with ZipFile(output, 'w') as zip: | ||
9 | + for file, mvnCoords in files: | ||
10 | + filename = file.split('/')[-1] | ||
11 | + if mvnCoords == 'NONE': | ||
12 | + dest = filename | ||
13 | + else: | ||
14 | + groupId, artifactId, version = mvnCoords.split(':') | ||
15 | + groupId = groupId.replace('.', '/') | ||
16 | + extension = filename.split('.')[-1] | ||
17 | + if extension == 'jar': | ||
18 | + filename = '%s-%s.jar' % ( artifactId, version ) | ||
19 | + dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) | ||
20 | + print file, '->', dest | ||
21 | + zip.write(file, dest) | ||
22 | + | ||
23 | +if __name__ == '__main__': | ||
24 | + import sys | ||
25 | + | ||
26 | + if len(sys.argv) < 2: | ||
27 | + print 'USAGE' | ||
28 | + sys.exit(1) | ||
29 | + | ||
30 | + output = sys.argv[1] | ||
31 | + args = sys.argv[2:] | ||
32 | + | ||
33 | + if len(args) % 2 != 0: | ||
34 | + print 'There must be an even number of args: file mvn_coords' | ||
35 | + sys.exit(2) | ||
36 | + | ||
37 | + files = zip(*[iter(args)]*2) | ||
38 | + generateOar(output, files) |
... | @@ -4,11 +4,14 @@ DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,add | ... | @@ -4,11 +4,14 @@ DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,add |
4 | FORCE_INSTALL=True | 4 | FORCE_INSTALL=True |
5 | NONE='NONE' | 5 | NONE='NONE' |
6 | 6 | ||
7 | +ONOS_GROUP_ID = 'org.onosproject' | ||
8 | +ONOS_VERSION = '1.6.0-SNAPSHOT' | ||
9 | + | ||
7 | def osgi_jar( | 10 | def osgi_jar( |
8 | name, | 11 | name, |
9 | srcs, | 12 | srcs, |
10 | - group_id = 'org.onosproject', | 13 | + group_id = ONOS_GROUP_ID, |
11 | - version = '1.6.0-SNAPSHOT', | 14 | + version = ONOS_VERSION, |
12 | deps = [], | 15 | deps = [], |
13 | visibility = ['PUBLIC'], | 16 | visibility = ['PUBLIC'], |
14 | license = 'NONE', | 17 | license = 'NONE', |
... | @@ -62,7 +65,7 @@ def osgi_jar( | ... | @@ -62,7 +65,7 @@ def osgi_jar( |
62 | genrule( | 65 | genrule( |
63 | name = osgi_jar_name, | 66 | name = osgi_jar_name, |
64 | bash = bash, | 67 | bash = bash, |
65 | - out = name + '.jar', | 68 | + out = '%s-%s.jar' % (name, version), #FIXME add version to jar file |
66 | srcs = glob(['src/main/webapp/**']), | 69 | srcs = glob(['src/main/webapp/**']), |
67 | visibility = [], #intentially, not visible | 70 | visibility = [], #intentially, not visible |
68 | ) | 71 | ) |
... | @@ -110,12 +113,3 @@ def osgi_jar( | ... | @@ -110,12 +113,3 @@ def osgi_jar( |
110 | visibility = visibility, | 113 | visibility = visibility, |
111 | ) | 114 | ) |
112 | 115 | ||
113 | -def onos_app( | ||
114 | - name, | ||
115 | - **kwargs): | ||
116 | - | ||
117 | - osgi_jar( | ||
118 | - name = name, | ||
119 | - **kwargs | ||
120 | - ) | ||
121 | - | ... | ... |
bucklets/onos_app.bucklet
0 → 100644
1 | +ONOS_ORIGIN = 'ON.Lab' | ||
2 | +ONOS_VERSION = '1.6.0-SNAPSHOT' | ||
3 | +DEFAULT_APP_CATEGORY = 'Utility' | ||
4 | + | ||
5 | +def onos_app( | ||
6 | + app_name, | ||
7 | + title, | ||
8 | + version = ONOS_VERSION, | ||
9 | + origin = ONOS_ORIGIN, | ||
10 | + category = DEFAULT_APP_CATEGORY, | ||
11 | + url = None, | ||
12 | + description = None, #TODO make this a file | ||
13 | + #TODO icon, | ||
14 | + feature_name = None, | ||
15 | + required_features = [ 'onos-api' ], | ||
16 | + required_apps = [], | ||
17 | + included_bundles = [], | ||
18 | + excluded_bundles = [], | ||
19 | + **kwargs): | ||
20 | + | ||
21 | + if not feature_name and len(included_bundles) == 1: | ||
22 | + feature_name = included_bundles[0][1] | ||
23 | + | ||
24 | + args = [ '-n %s' % feature_name, | ||
25 | + '-v %s' % version, | ||
26 | + '-t "%s"' % title, | ||
27 | + '-o "%s"' % origin, | ||
28 | + '-c "%s"' % category, | ||
29 | + '-a "%s"' % app_name, | ||
30 | + '-u %s' % url, | ||
31 | + ] | ||
32 | + args += [ '-f %s' % f for f in required_features ] | ||
33 | + args += [ '-b %s' % b for (t, b) in included_bundles ] | ||
34 | + args += [ '-e %s' % b for (t, b) in excluded_bundles ] | ||
35 | + args += [ '-d %s' % a for a in required_apps ] | ||
36 | + | ||
37 | + cmd = '$(exe //buck-tools:onos-app-writer) -F ' + ' '.join(args) + ' > $OUT' | ||
38 | + genrule( | ||
39 | + name = 'app-features', | ||
40 | + bash = cmd, | ||
41 | + out = '%s-%s-features.xml' % (feature_name.split(':')[1], version), | ||
42 | + visibility = [], | ||
43 | + ) | ||
44 | + cmd = '$(exe //buck-tools:onos-app-writer) -A ' + ' '.join(args) + ' > $OUT' | ||
45 | + genrule( | ||
46 | + name = 'app-xml', | ||
47 | + bash = cmd, | ||
48 | + out = 'app.xml', | ||
49 | + visibility = [], | ||
50 | + ) | ||
51 | + | ||
52 | + sources = [ | ||
53 | + '$(location :app-features) %s' % feature_name, | ||
54 | + '$(location :app-xml) NONE', | ||
55 | + ] | ||
56 | + sources += ['$(location %s) %s' % i for i in included_bundles] | ||
57 | + genrule( | ||
58 | + name = 'app-oar', | ||
59 | + out = 'app.oar', | ||
60 | + bash = '$(exe //buck-tools:onos-app-oar) $OUT ' + ' '.join(sources) | ||
61 | + ) |
... | @@ -21,7 +21,6 @@ | ... | @@ -21,7 +21,6 @@ |
21 | <description>${project.description}</description> | 21 | <description>${project.description}</description> |
22 | <artifact>mvn:${project.groupId}/onos-of-api/${project.version}</artifact> | 22 | <artifact>mvn:${project.groupId}/onos-of-api/${project.version}</artifact> |
23 | <artifact>mvn:${project.groupId}/onos-of-ctl/${project.version}</artifact> | 23 | <artifact>mvn:${project.groupId}/onos-of-ctl/${project.version}</artifact> |
24 | - <artifact>mvn:${project.groupId}/onos-drivers/${project.version}</artifact> | ||
25 | 24 | ||
26 | <artifact>mvn:${project.groupId}/onos-of-provider-device/${project.version}</artifact> | 25 | <artifact>mvn:${project.groupId}/onos-of-provider-device/${project.version}</artifact> |
27 | <artifact>mvn:${project.groupId}/onos-of-provider-packet/${project.version}</artifact> | 26 | <artifact>mvn:${project.groupId}/onos-of-provider-packet/${project.version}</artifact> | ... | ... |
-
Please register or login to post a comment