mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-01-06 00:52:05 +01:00
380 lines
10 KiB
Plaintext
380 lines
10 KiB
Plaintext
import random
|
|
|
|
DEBUG_ARG='JAVA_TOOL_OPTIONS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=y"'
|
|
FORCE_INSTALL=True
|
|
NONE='NONE'
|
|
|
|
SRC = 'src/main/java/**/'
|
|
TEST = 'src/test/java/**/'
|
|
RESOURCES_ROOT = 'src/main/resources/'
|
|
TEST_RESOURCES_ROOT = 'src/test/resources/'
|
|
|
|
include_defs('//onos.defs')
|
|
|
|
def _get_name():
|
|
base_path = get_base_path()
|
|
return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator
|
|
|
|
def checkstyle(
|
|
name,
|
|
srcs = None,
|
|
jar_target = None,
|
|
):
|
|
|
|
if srcs:
|
|
base = get_base_path()
|
|
files = '%s\n%s\n' % (name, base) + '\n'.join(['%s/%s' % (base, s) for s in srcs])
|
|
|
|
genrule(
|
|
name = name + '-checkstyle-files',
|
|
bash = "echo '%s' > $OUT" % files,
|
|
srcs = srcs,
|
|
out = 'checkstyle-files.txt',
|
|
)
|
|
|
|
sh_test(
|
|
name = name + '-checkstyle',
|
|
test = '//tools/build/conf:start-buck-daemon',
|
|
deps = [ ':' + name + '-checkstyle-files',
|
|
'//tools/build/conf:onos-java-header',
|
|
'//tools/build/conf:onos-build-conf', ],
|
|
args = [
|
|
'$(location //tools/build/conf:buck-daemon-jar)',
|
|
'checkstyle',
|
|
'$(location :' + name + '-checkstyle-files)',
|
|
'$(location //tools/build/conf:checkstyle-xml)',
|
|
'$(location //tools/build/conf:suppressions-xml)',
|
|
],
|
|
test_rule_timeout_ms = 20000,
|
|
labels = [ 'checkstyle' ],
|
|
)
|
|
|
|
def java_doc(
|
|
name,
|
|
title,
|
|
pkgs,
|
|
paths,
|
|
srcs = [],
|
|
deps = [],
|
|
visibility = [],
|
|
do_it_wrong = False,
|
|
):
|
|
if do_it_wrong:
|
|
sourcepath = paths
|
|
else:
|
|
sourcepath = ['$SRCDIR/' + n for n in paths]
|
|
|
|
if len(srcs) != 0:
|
|
cmd = ' '.join([
|
|
'while ! test -f .buckconfig; do cd ..; done;',
|
|
'javadoc',
|
|
'-tag onos.rsModel:a:"onos model"',
|
|
'-quiet',
|
|
'-protected',
|
|
'-encoding UTF-8',
|
|
'-charset UTF-8',
|
|
'-notimestamp',
|
|
'-windowtitle "' + title + '"',
|
|
'-link http://docs.oracle.com/javase/8/docs/api',
|
|
'-subpackages ',
|
|
':'.join(pkgs),
|
|
'-sourcepath ',
|
|
':'.join(sourcepath),
|
|
' -classpath ',
|
|
':'.join(['$(classpath %s)' % n for n in deps]),
|
|
'-d $TMP',
|
|
]) + ';jar cf $OUT -C $TMP .'
|
|
|
|
genrule(
|
|
name = name,
|
|
cmd = cmd,
|
|
srcs = srcs,
|
|
out = name + '.jar',
|
|
visibility = visibility,
|
|
)
|
|
|
|
def sonar(
|
|
name,
|
|
test = False
|
|
):
|
|
|
|
cmd = '; '.join([ 'rm -f $OUT',
|
|
'printf "%(src_base)s = " >> $OUT',
|
|
'%(srcs)s >> $OUT',
|
|
'echo "%(binary_base)s = %(classes)s" >> $OUT',
|
|
'printf "%(lib_base)s = " >> $OUT',
|
|
'%(libraries)s >> $OUT'
|
|
]) % {
|
|
'srcs' : "echo $(srcs :%s) | sed 's/ /,/g'" % name,
|
|
'classes' : ("$(bin_dir :%s#non-osgi)" if not test else "$(bin_dir :%s)") % name,
|
|
'libraries' : "echo $(classpath :%s) | sed 's/:/,/g'" % name,
|
|
'src_base' : 'sonar.sources' if not test else 'sonar.tests',
|
|
'binary_base' : 'sonar.java.binaries' if not test else 'sonar.java.test.binaries',
|
|
'lib_base' : 'sonar.java.libraries' if not test else 'sonar.java.test.libraries'
|
|
}
|
|
# FIXME do we need to specify dep here or with the expander cover it?
|
|
genrule(
|
|
name = name + "-sonar",
|
|
cmd = cmd,
|
|
out = 'sonar-project.properties'
|
|
)
|
|
|
|
def osgi_jar(
|
|
name = None,
|
|
srcs = None,
|
|
group_id = ONOS_GROUP_ID,
|
|
version = ONOS_VERSION,
|
|
deps = [],
|
|
visibility = ['PUBLIC'],
|
|
license = 'NONE',
|
|
description = '',
|
|
debug = False,
|
|
import_packages = '*',
|
|
dynamicimport_packages = '',
|
|
embedded_dependencies = '',
|
|
export_packages = '!.,!*.impl.*,!*.internal.*,*',
|
|
package_name_root = 'org.onosproject',
|
|
include_resources = {},
|
|
web_context = NONE,
|
|
api_title = None,
|
|
api_version = NONE,
|
|
api_package = NONE,
|
|
api_description = NONE,
|
|
resources = NONE,
|
|
resources_root = None,
|
|
tests = None,
|
|
do_javadocs = True,
|
|
do_checkstyle = True,
|
|
**kwargs
|
|
):
|
|
|
|
# if name and _get_name() != name:
|
|
# print _get_name(), '!=', name
|
|
if name is None:
|
|
name = _get_name()
|
|
|
|
if srcs is None:
|
|
srcs = glob([SRC + '/*.java'])
|
|
|
|
if resources == NONE and resources_root is not None:
|
|
resources = glob([resources_root + '**'])
|
|
elif resources == NONE:
|
|
resources = glob([RESOURCES_ROOT + '**'])
|
|
|
|
if resources and not resources_root:
|
|
resources_root = RESOURCES_ROOT
|
|
|
|
mvn_coords = group_id + ':' + name + ':' + version
|
|
|
|
onos_jar(
|
|
name = name,
|
|
srcs = srcs + glob(['src/main/webapp/**']),
|
|
deps = deps,
|
|
visibility = visibility,
|
|
resources = resources,
|
|
resources_root = resources_root,
|
|
bundle_name = name,
|
|
group_id = group_id,
|
|
bundle_version = version,
|
|
bundle_license = license,
|
|
bundle_description = description,
|
|
import_packages = import_packages,
|
|
export_packages = export_packages,
|
|
include_resources = include_resources,
|
|
dynamicimport_packages = dynamicimport_packages,
|
|
embedded_dependencies = embedded_dependencies,
|
|
web_context = web_context,
|
|
api_title = api_title,
|
|
api_version = api_version,
|
|
api_package = api_package,
|
|
api_description = api_description,
|
|
tests = tests,
|
|
maven_coords = mvn_coords,
|
|
**kwargs
|
|
)
|
|
|
|
### Checkstyle
|
|
if do_checkstyle:
|
|
checkstyle(
|
|
name = name,
|
|
srcs = srcs,
|
|
)
|
|
|
|
if do_javadocs:
|
|
java_doc(
|
|
name = name + '-javadoc',
|
|
title = 'Java Docs',
|
|
pkgs = [ package_name_root ],
|
|
paths = [ 'src/main/java' ],
|
|
srcs = srcs,
|
|
deps = deps,
|
|
visibility = visibility,
|
|
do_it_wrong = False,
|
|
)
|
|
|
|
# TODO add project config for intellij
|
|
# project_config(
|
|
# src_target = ':' + name,
|
|
# src_roots = [ 'src/main/java' ],
|
|
# test_target = ':' + name + '-tests',
|
|
# test_roots = [ 'src/test/java' ],
|
|
# )
|
|
|
|
### .m2 Install
|
|
mvn_cmd = ' '.join(( 'mvn install:install-file',
|
|
'-Dfile=$(location :%s)' % name,
|
|
'-DgroupId=%s' % group_id,
|
|
'-DartifactId=%s' % name,
|
|
'-Dversion=%s' % version,
|
|
'-Dpackaging=jar' ))
|
|
cmd = mvn_cmd + ' > $OUT'
|
|
if FORCE_INSTALL:
|
|
# Add a random number to the command to force this rule to run.
|
|
# TODO We should make this configurable from CLI, perhaps with a flag.
|
|
cmd = 'FOO=%s ' % random.random() + cmd
|
|
genrule(
|
|
name = name + '-install',
|
|
bash = cmd,
|
|
out = 'install.log',
|
|
visibility = visibility,
|
|
)
|
|
sonar(
|
|
name = name,
|
|
)
|
|
|
|
def osgi_jar_with_tests(
|
|
name = None,
|
|
deps = [],
|
|
group_id = ONOS_GROUP_ID,
|
|
version = ONOS_VERSION,
|
|
test_srcs = None,
|
|
test_deps = [ '//lib:TEST' ],
|
|
test_resources = None,
|
|
test_resources_root = None,
|
|
visibility = [ 'PUBLIC' ],
|
|
**kwargs
|
|
):
|
|
|
|
if name is None:
|
|
name = _get_name()
|
|
|
|
if test_resources and not test_resources_root:
|
|
test_resources_root = TEST_RESOURCES_ROOT
|
|
if test_resources_root and not test_resources:
|
|
test_resources = glob([test_resources_root + '**'])
|
|
if not test_resources and not test_resources_root:
|
|
test_resources = glob([TEST_RESOURCES_ROOT + '**'])
|
|
if test_resources:
|
|
test_resources_root = TEST_RESOURCES_ROOT
|
|
|
|
if test_srcs is None:
|
|
test_srcs = glob([TEST + '/*.java'])
|
|
|
|
mvn_coords = group_id + ':' + name + ':jar:tests:' + version
|
|
|
|
if test_srcs:
|
|
java_test(
|
|
name = name + '-tests',
|
|
srcs = test_srcs,
|
|
deps = deps +
|
|
test_deps +
|
|
[':' + name + '#non-osgi'],
|
|
resources = test_resources,
|
|
resources_root = test_resources_root,
|
|
maven_coords = mvn_coords,
|
|
visibility = visibility,
|
|
)
|
|
|
|
checkstyle(
|
|
name = name + '-tests',
|
|
srcs = test_srcs,
|
|
)
|
|
|
|
sonar(
|
|
name = name + '-tests',
|
|
test = True
|
|
)
|
|
|
|
osgi_jar(name = name,
|
|
deps = deps,
|
|
group_id = group_id,
|
|
version = version,
|
|
visibility = visibility,
|
|
tests = [':' + name + '-tests'],
|
|
**kwargs)
|
|
else:
|
|
osgi_jar(name = name,
|
|
deps = deps,
|
|
group_id = group_id,
|
|
version = version,
|
|
visibility = visibility,
|
|
**kwargs)
|
|
|
|
def tar_file(
|
|
name,
|
|
srcs,
|
|
other_tars = [],
|
|
root = None,
|
|
out = None,
|
|
visibility = [ 'PUBLIC' ],
|
|
):
|
|
|
|
cmds = [ 'mkdir -p $TMP/%(root_dir)s',
|
|
'cp -R -L $SRCDIR/* $TMP/%(root_dir)s' ]
|
|
for t in other_tars:
|
|
cmds += [ 'tar -zxf $(location %s)' % t + ' -C $TMP/%(root_dir)s' ]
|
|
cmds += [ 'tar -C $TMP -zcf $OUT %(root_dir)s' ]
|
|
|
|
cmd = ' && '.join(cmds) % {
|
|
'root_dir': root if root is not None else name
|
|
}
|
|
|
|
genrule(
|
|
name = name,
|
|
srcs = srcs,
|
|
bash = cmd,
|
|
out = out if out is not None else ( root if root is not None else name ) + '.tar.gz',
|
|
visibility = visibility,
|
|
)
|
|
|
|
def only_lib_dep_pom(
|
|
name,
|
|
src,
|
|
out,
|
|
version = ONOS_VERSION,
|
|
onosGroupId = ONOS_GROUP_ID,
|
|
visibility = [ 'PUBLIC' ],
|
|
):
|
|
|
|
cmd = 'grep -v \<module\> ' + src + ' | sed "s#<modules>#<modules><module>lib</module>#" >$OUT'
|
|
|
|
genrule(
|
|
name = name,
|
|
srcs = [ src ],
|
|
bash = cmd,
|
|
out = out,
|
|
visibility = visibility,
|
|
maven_coords = onosGroupId + ':onos:pom:' + version,
|
|
)
|
|
|
|
def pass_thru_pom(
|
|
name,
|
|
src,
|
|
out,
|
|
artifactId,
|
|
version = ONOS_VERSION,
|
|
onosGroupId = ONOS_GROUP_ID,
|
|
visibility = [ 'PUBLIC' ],
|
|
):
|
|
|
|
cmd = 'cp ' + src + ' $OUT'
|
|
|
|
genrule(
|
|
name = name,
|
|
srcs = [ src ],
|
|
bash = cmd,
|
|
out = out,
|
|
visibility = visibility,
|
|
maven_coords = onosGroupId + ':' + artifactId + ':pom:' + version,
|
|
)
|