Initial builds using bazel

Change-Id: I38123b396a2ffda5f36cdca43f3ad1fa67a7ab52
This commit is contained in:
Ray Milkey 2017-08-01 16:56:05 -07:00 committed by Thomas Vachuska
parent 6e4da2f37b
commit 7dac7dadf5
37 changed files with 2988 additions and 53 deletions

1
.bazelrc Normal file
View File

@ -0,0 +1 @@
build --nouse_ijars

21
BUILD Normal file
View File

@ -0,0 +1,21 @@
filegroup(
name = "onos",
srcs = [
"//utils/junit:onlab-junit-osgi",
"//utils/misc:onlab-misc-osgi",
"//utils/osgi:onlab-osgi-osgi",
"//utils/rest:onlab-rest-osgi",
"//utils/osgiwrap:osgi-jar",
"//core/api:onos-api-osgi",
"//core/common:onos-core-common-osgi",
"//incubator/api:onos-incubator-api-osgi",
"//core/store/serializers:onos-core-serializers-osgi",
"//core/store/dist:onos-core-dist-osgi",
"//incubator/store:onos-incubator-store",
"//incubator/net:onos-incubator-net",
"//protocols/openflow/api:onos-protocols-openflow-api-osgi",
"//drivers/default:onos-drivers-default-osgi",
#"//core/net:onos-core-net-osgi",
],
)

4
WORKSPACE Normal file
View File

@ -0,0 +1,4 @@
load("//tools/build/bazel:generate_workspace.bzl", "generated_maven_jars")
generated_maven_jars()
ONOS_VERSION = '1.14.0-SNAPSHOT'

27
core/api/BUILD Normal file
View File

@ -0,0 +1,27 @@
COMPILE_DEPS = COMPILE + NETTY + JACKSON + METRICS + KRYO + [
'//utils/misc:onlab-misc',
'//utils/osgi:onlab-osgi',
'//utils/rest:onlab-rest',
'@joda_time//jar',
'@netty//jar',
]
osgi_jar_with_tests (
name = 'onos-api',
deps = COMPILE_DEPS,
exclude_tests = [
'org.onosproject.net.config.basics.AbstractConfigTest',
'org.onosproject.net.driver.AbstractDriverLoaderTest',
'org.onosproject.net.intent.AbstractIntentTest',
'org.onosproject.net.intent.ConnectivityIntentTest',
'org.onosproject.net.intent.IntentTest',
'org.onosproject.net.pi.runtime.PiConstantsTest',
'org.onosproject.security.SecurityUtilTest',
'org.onosproject.ui.AbstractUiTest',
'org.onosproject.ui.model.AbstractUiModelTest',
'org.onosproject.net.behaviour.QosIdTest',
],
visibility = ["//visibility:public"],
#javadoc_files = glob(['src/main/javadoc/**/*']),
#javadoc_files_root = 'src/main/javadoc',
)

View File

@ -457,6 +457,7 @@ public class IntentData { //FIXME need to make this "immutable"
} else if (currentState == INSTALLED) {
return true;
}
// FALLTHROUGH
case INSTALLED:
if (currentState == INSTALLED) {
return false;

View File

@ -142,11 +142,10 @@ public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> {
type = Type.PURGED;
break;
// fallthrough to default from here
case COMPILING:
case INSTALLING:
case RECOMPILING:
case WITHDRAWING:
case COMPILING: // FALLTHROUGH
case INSTALLING: // FALLTHROUGH
case RECOMPILING: // FALLTHROUGH
case WITHDRAWING: // FALLTHROUGH
default:
return Optional.empty();
}

11
core/common/BUILD Normal file
View File

@ -0,0 +1,11 @@
COMPILE_DEPS = CORE_DEPS + JACKSON + METRICS + [
'//incubator/api:onos-incubator-api',
]
TEST_DEPS = TEST + ['//core/api:onos-api-tests']
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
visibility = ["//visibility:public"],
)

28
core/store/dist/BUILD vendored Normal file
View File

@ -0,0 +1,28 @@
COMPILE_DEPS = CORE_DEPS + NETTY + JACKSON + KRYO + [
'//core/common:onos-core-common',
'//utils/rest:onlab-rest',
'//core/store/serializers:onos-core-serializers',
'@netty_transport//jar',
'@netty_codec//jar',
'@netty_handler//jar',
'@netty_transport_native_epoll//jar',
'@netty_resolver//jar',
'@commons_math3//jar',
'//incubator/api:onos-incubator-api',
]
TEST_DEPS = TEST + [
'//core/api:onos-api-tests',
'//core/common:onos-core-common-tests',
]
osgi_jar_with_tests (
name = 'onos-core-dist',
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
exclude_tests = [
'org.onosproject.store.link.impl.ECLinkStoreTest',
'org.onosproject.store.flow.impl.DistributedFlowRuleStoreTest',
],
visibility = ["//visibility:public"],
)

View File

@ -69,32 +69,41 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> {
case READ_SENDER_IP_VERSION:
ipVersion = buffer.readByte() == 0x0 ? Version.INET : Version.INET6;
checkpoint(DecoderState.READ_SENDER_IP);
// FALLTHROUGH
case READ_SENDER_IP:
byte[] octets = new byte[IpAddress.byteLength(ipVersion)];
buffer.readBytes(octets);
senderIp = IpAddress.valueOf(ipVersion, octets);
checkpoint(DecoderState.READ_SENDER_PORT);
// FALLTHROUGH
case READ_SENDER_PORT:
senderPort = buffer.readInt();
checkpoint(DecoderState.READ_TYPE);
// FALLTHROUGH
case READ_TYPE:
type = InternalMessage.Type.forId(buffer.readByte());
checkpoint(DecoderState.READ_PREAMBLE);
// FALLTHROUGH
case READ_PREAMBLE:
preamble = buffer.readInt();
checkpoint(DecoderState.READ_LOGICAL_TIME);
// FALLTHROUGH
case READ_LOGICAL_TIME:
logicalTime = buffer.readLong();
checkpoint(DecoderState.READ_LOGICAL_COUNTER);
// FALLTHROUGH
case READ_LOGICAL_COUNTER:
logicalCounter = buffer.readLong();
checkpoint(DecoderState.READ_MESSAGE_ID);
// FALLTHROUGH
case READ_MESSAGE_ID:
messageId = buffer.readLong();
checkpoint(DecoderState.READ_CONTENT_LENGTH);
// FALLTHROUGH
case READ_CONTENT_LENGTH:
contentLength = buffer.readInt();
checkpoint(DecoderState.READ_CONTENT);
// FALLTHROUGH
case READ_CONTENT:
if (contentLength > 0) {
//TODO Perform a sanity check on the size before allocating
@ -125,6 +134,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> {
case READ_SUBJECT_LENGTH:
subjectLength = buffer.readShort();
checkpoint(DecoderState.READ_SUBJECT);
// FALLTHROUGH
case READ_SUBJECT:
byte[] messageTypeBytes = new byte[subjectLength];
buffer.readBytes(messageTypeBytes);

View File

@ -0,0 +1,12 @@
COMPILE_DEPS = CORE_DEPS + KRYO + [
'//incubator/api:onos-incubator-api',
]
TEST_DEPS = TEST
osgi_jar_with_tests (
name = 'onos-core-serializers',
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
visibility = ["//visibility:public"],
)

17
drivers/default/BUILD Normal file
View File

@ -0,0 +1,17 @@
COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [
'@openflowj//jar',
'//protocols/openflow/api:onos-protocols-openflow-api',
'//core/store/serializers:onos-core-serializers',
]
TEST_DEPS = TEST_ADAPTERS + [
'//core/api:onos-api-tests',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
#resources_root = 'src/main/resources',
resources = glob(['src/main/resources/**']),
visibility = ["//visibility:public"],
)

9
incubator/api/BUILD Normal file
View File

@ -0,0 +1,9 @@
COMPILE_DEPS = CORE_DEPS + JACKSON
TEST_DEPS = TEST_ADAPTERS
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
visibility = ["//visibility:public"],
)

18
incubator/net/BUILD Normal file
View File

@ -0,0 +1,18 @@
COMPILE_DEPS = CORE_DEPS + JACKSON + METRICS + KRYO + [
'//incubator/store:onos-incubator-store',
'//incubator/api:onos-incubator-api',
'//core/common:onos-core-common',
]
TEST_DEPS = TEST_REST + [
'//incubator/api:onos-incubator-api-tests',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
exclude_tests = [
'org.onosproject.incubator.net.virtual.impl.VirtualNetworkIntentManagerTest',
],
visibility = ["//visibility:public"],
)

15
incubator/store/BUILD Normal file
View File

@ -0,0 +1,15 @@
COMPILE_DEPS = CORE_DEPS + KRYO + [
'//core/common:onos-core-common',
'//utils/rest:onlab-rest',
'//core/store/serializers:onos-core-serializers',
'@concurrent_trees//jar',
'//incubator/api:onos-incubator-api',
]
TEST_DEPS = TEST_ADAPTERS
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
visibility = ["//visibility:public"],
)

View File

@ -1,4 +1,4 @@
# ***** This file was auto-generated at Fri, 18 May 2018 23:14:52 GMT. Do not edit this file manually. *****
# ***** This file was auto-generated at Tue, 22 May 2018 17:57:55 GMT. Do not edit this file manually. *****
# ***** Use onos-lib-gen *****
pass_thru_pom(

View File

@ -0,0 +1,17 @@
COMPILE_DEPS = CORE_DEPS + NETTY + [
'//incubator/store:onos-incubator-store',
'//incubator/api:onos-incubator-api',
'//core/common:onos-core-common',
'@openflowj//jar',
'@netty_transport//jar',
]
TEST_DEPS = TEST + [
'//core/api:onos-api-tests',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
test_deps = TEST_DEPS,
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,14 @@
GRPC_VER = '1.3.1'
COMPILE_DEPS = CORE_DEPS + [
# '@grpc//jar',
]
TEST_DEPS = TEST + [
'//core/api:onos-api-tests',
]
#osgi_jar_with_tests (
# deps = COMPILE_DEPS,
# test_deps = TEST_DEPS,
#)

View File

@ -0,0 +1,10 @@
PROTOBUF_VER = '3_2_0'
COMPILE_DEPS = CORE_DEPS + [
#'//protocols/p4runtime/proto:onos-protocols-p4runtime-proto',
#'@grpc_protobuf_' + PROTOBUF_VER + "//jar",
]
#osgi_jar_with_tests (
# deps = COMPILE_DEPS,
#)

1
tools/build/bazel/BUILD Normal file
View File

@ -0,0 +1 @@

View File

@ -0,0 +1,113 @@
# -*- mode:python; -*-
#
# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generate java test rules from given test_files.
Instead of having to create one test rule per test in the BUILD file, this rule
provides a handy way to create a bunch of test rules for the specified test
files.
"""
def testIsExcluded(exclude_tests, test):
for excluded_test in exclude_tests:
normalized_excluded_test = excluded_test.replace('.', '/')
if test.endswith(normalized_excluded_test):
return True;
return False
def generate_test_rules(name,
test_files,
deps,
exclude_tests=[],
default_test_size="small",
small_tests=[],
medium_tests=[],
large_tests=[],
enormous_tests=[],
resources=[],
flaky_tests=[],
tags=[],
prefix="",
jvm_flags=["-XX:MaxPermSize=128m"],
args=[],
visibility=None,
shard_count=1):
for test in _get_test_names(test_files):
if testIsExcluded(exclude_tests, test):
continue
test_size = default_test_size
if test in small_tests:
test_size = "small"
if test in medium_tests:
test_size = "medium"
if test in large_tests:
test_size = "large"
if test in enormous_tests:
test_size = "enormous"
flaky = 0
if (test in flaky_tests) or ("flaky" in tags):
flaky = 1
java_class = _package_from_path(
PACKAGE_NAME + "/" + _strip_right(test, ".java"))
package = java_class[:java_class.rfind(".")]
native.java_test(name = prefix + test,
runtime_deps = deps,
resources = resources,
size = test_size,
jvm_flags = jvm_flags,
args = args,
flaky = flaky,
tags = tags,
test_class = java_class,
visibility = visibility,
shard_count = shard_count)
def _get_test_names(test_files):
test_names = []
for test_file in test_files:
if not test_file.endswith("Test.java"):
continue
test_names += [test_file[:-5]]
return test_names
def _package_from_path(package_path, src_impls=None):
src_impls = src_impls or ['javatests/', 'java/']
for src_impl in src_impls:
if not src_impl.endswith('/'):
src_impl += '/'
index = _index_of_end(package_path, src_impl)
if index >= 0:
package_path = package_path[index:]
break
return package_path.replace('/', '.')
def _strip_right(str, suffix):
"""Returns str without the suffix if it ends with suffix."""
if str.endswith(suffix):
return str[0: len(str) - len(suffix)]
else:
return str
def _index_of_end(str, part):
"""If part is in str, return the index of the first character after part.
Return -1 if part is not in str."""
index = str.find(part)
if index >= 0:
return index + len(part)
return -1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,182 @@
load("//tools/build/bazel:generate_workspace.bzl", "COMPILE", "TEST")
load("//tools/build/bazel:variables.bzl", "ONOS_VERSION")
load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules")
def all_java_sources():
return native.glob(["src/main/java/**/*.java"])
def all_java_test_sources():
return native.glob(["src/test/java/**/*.java"])
def all_test_resources():
return native.glob(["src/test/resources/**"])
def all_resources(resources_root):
if resources_root == None:
return native.glob(["src/main/resources/**"])
else:
return native.glob([resources_root + '**'])
# Implementation of the rule to call bnd to make an OSGI jar file
def _bnd_impl(ctx):
jar = ctx.file.source.path
output = ctx.outputs.osgi_jar.path
cp = ""
name = ctx.attr.source.label.name
group = ctx.attr.package_name_root
version = ctx.attr.version
license = ""
importPackages = "*"
exportPackages = "*"
includeResources = ""
webContext = "NONE"
dynamicimportPackages = ""
inputDependencies = [ctx.file.source]
# determine the dependencies and build the class path
for dep in ctx.attr.deps:
file = dep.java.outputs.jars[0].class_jar
if cp:
cp += ":"
cp += file.path
inputDependencies = inputDependencies + [file]
# extract the class files for use by bnd
classes = ctx.actions.declare_file("classes")
classesPath = classes.path
jarCommand = "mkdir -p %s && cp %s %s && cd %s && jar xf *.jar" % (classesPath, jar, classesPath, classesPath)
ctx.actions.run_shell(
inputs=inputDependencies,
outputs=[classes],
command=jarCommand,
progress_message="Expanding jar file: %s" % jar,
)
inputDependencies += [classes]
# call bnd to make the OSGI jar file
arguments=[
jar,
output,
cp,
name,
group,
version,
license,
importPackages,
exportPackages,
includeResources,
webContext,
dynamicimportPackages,
classesPath,
]
ctx.actions.run(
inputs=inputDependencies,
outputs=[ctx.outputs.osgi_jar],
arguments=arguments,
progress_message="Running bnd wrapper on: %s" % ctx.attr.name,
executable=ctx.executable._bnd_exe,
)
bnd = rule(
attrs = {
"deps": attr.label_list(),
"version": attr.string(),
"package_name_root": attr.string(),
"source": attr.label(allow_single_file = True),
"_bnd_exe": attr.label(
executable = True,
cfg = "host",
allow_files = True,
default = Label("//utils/osgiwrap:osgi-jar"),
),
},
fragments = ["java"],
outputs = {
"osgi_jar": "lib%{name}.jar",
},
implementation = _bnd_impl,
)
def _fwd_bnd(name, source, deps, version, package_name_root, visibility):
bnd(name = name, source = source, deps = deps, version = version, package_name_root = package_name_root, visibility = visibility)
def wrapped_osgi_library(name, jar, deps, version = ONOS_VERSION, package_name_root = "org.onosproject", visibility = [ "//visibility:private" ]):
_fwd_bnd(name, jar, deps, version, package_name_root, visibility)
def osgi_jar_with_tests(name = None,
deps = None,
test_deps = None,
package_name_root = "org.onosproject",
srcs = None,
resources_root = None,
resources = None,
test_srcs = None,
exclude_tests = None,
test_resources = None,
visibility = [ "//visibility:public" ],
version = ONOS_VERSION):
if name == None:
name = "onos-" + native.package_name().replace("/", "-")
if srcs == None:
srcs = all_java_sources()
if resources == None:
resources = all_resources(resources_root)
if test_srcs == None:
test_srcs = all_java_test_sources()
if test_resources == None:
test_resources = all_test_resources()
if exclude_tests == None:
exclude_tests = []
if deps == None:
deps = COMPILE
if test_deps == None:
test_deps = TEST
tests_name = name + '-tests'
tests_jar_deps = list(depset(deps + test_deps)) + [ name ]
all_test_deps = tests_jar_deps + [ tests_name ]
native.java_library(name = name, srcs = srcs, resources = resources, deps = deps, visibility = visibility)
_fwd_bnd(name + '-osgi', name, deps, version, package_name_root, visibility)
if test_srcs != []:
native.java_library(name = tests_name,
srcs = test_srcs,
resources = test_resources,
deps = tests_jar_deps,
visibility = visibility)
generate_test_rules(
name = name + "-tests-gen",
test_files = test_srcs,
exclude_tests = exclude_tests,
deps = all_test_deps
)
def osgi_jar(name = None,
deps = None,
package_name_root = "org.onosproject",
srcs = None,
resources_root = None,
resources = None,
visibility = [ "//visibility:public" ],
version = ONOS_VERSION):
if srcs == None:
srcs = all_java_sources()
if deps == None:
deps = COMPILE
osgi_jar_with_tests(name = name,
deps = deps,
test_deps = [],
package_name_root = package_name_root,
srcs = srcs,
resources = resources,
resources_root = resources_root,
test_srcs = [],
exclude_tests = [],
test_resources = [],
visibility = visibility,
version = version)

View File

@ -0,0 +1,9 @@
load("//tools/build/bazel:generate_workspace.bzl",
"generated_java_libraries", "COMPILE", "CORE_DEPS", "JACKSON",
"TEST_ADAPTERS", "TEST", "TEST_REST", "METRICS", "KRYO", "NETTY")
def onos_bazel_rules() :
return
def g() :
generated_java_libraries()

View File

@ -0,0 +1,2 @@
ONOS_VERSION = "1.13.0-SNAPSHOT"

View File

@ -91,15 +91,15 @@ public class AetherResolver {
AetherResolver.session = session;
}
public static BuckArtifact getArtifact(String name, String uri, String repo) {
return new AetherResolver(repo).build(name, uri);
public static BuckArtifact getArtifact(String name, String uri, String repo, boolean generateForBazel) {
return new AetherResolver(repo).build(name, uri, generateForBazel);
}
private AetherResolver(String repoUrl) {
this.repoUrl = repoUrl;
}
private BuckArtifact build(String name, String uri) {
private BuckArtifact build(String name, String uri, boolean generateForBazel) {
uri = uri.replaceFirst("mvn:", "");
Artifact artifact = new DefaultArtifact(uri);
String originalVersion = artifact.getVersion();
@ -122,9 +122,9 @@ public class AetherResolver {
artifact.getGroupId(),
artifact.getArtifactId(),
originalVersion);
return BuckArtifact.getArtifact(name, url, sha, mavenCoords, osgiReady);
return BuckArtifact.getArtifact(name, url, sha, mavenCoords, osgiReady, generateForBazel);
}
return BuckArtifact.getArtifact(name, artifact, sha, repoUrl, osgiReady);
return BuckArtifact.getArtifact(name, artifact, sha, repoUrl, osgiReady, generateForBazel);
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@ -25,25 +25,33 @@ public abstract class BuckArtifact {
private final String name;
private final String sha;
private final boolean osgiReady;
private final boolean generateForBazel;
public static BuckArtifact getArtifact(String name, Artifact artifact, String sha, String repo, boolean osgiReady) {
return new MavenArtifact(name, artifact, sha, repo, osgiReady);
public static BuckArtifact getArtifact(String name, Artifact artifact, String sha, String repo,
boolean osgiReady, boolean generateForBazel) {
return new MavenArtifact(name, artifact, sha, repo, osgiReady, generateForBazel);
}
public static BuckArtifact getArtifact(String name, String url, String sha, String mavenCoords, boolean osgiReady) {
return new HTTPArtifact(name, url, sha, mavenCoords, osgiReady);
public static BuckArtifact getArtifact(String name, String url, String sha, String mavenCoords,
boolean osgiReady, boolean generateForBazel) {
return new HTTPArtifact(name, url, sha, mavenCoords, osgiReady, generateForBazel);
}
public static BuckArtifact getArtifact(String name, String url, String sha) {
return new HTTPArtifact(name, url, sha, null, true);
public static BuckArtifact getArtifact(String name, String url, String sha, boolean generateForBazel) {
return new HTTPArtifact(name, url, sha, null, true, generateForBazel);
}
public BuckArtifact(String name, String sha, boolean osgiReady) {
public BuckArtifact(String name, String sha, boolean osgiReady, boolean generateForBazel) {
this.name = name;
this.sha = sha;
this.osgiReady = osgiReady;
this.generateForBazel = generateForBazel;
}
public String name() {
return name;
if (!generateForBazel) {
return name;
} else {
return name.replaceAll("[.-]", "_");
}
}
abstract String fileName();
@ -51,7 +59,7 @@ public abstract class BuckArtifact {
abstract String url();
private String jarTarget() {
return name != null ? name : fileName();
return name != null ? name() : fileName();
}
private boolean isPublic() {
@ -62,20 +70,82 @@ public abstract class BuckArtifact {
return osgiReady;
}
boolean isGenerateForBazel() {
return generateForBazel;
}
String mavenCoords() {
return null;
}
private boolean isJar() {
return fileName().endsWith(".jar");
}
private boolean isHttp() {
return url().startsWith("http");
}
String getBazelJavaLibraryFragment() {
if (isJar()) {
String format =
" native.java_library (\n" +
" name = '%s',\n" +
" visibility = ['//visibility:public'],\n" +
" exports = ['@%s//jar'],\n" +
" )\n\n";
return String.format(format, jarTarget(), jarTarget());
}
return "";
}
private String extractRepo() {
// This is a hack because the code above us already got rid of the maven repo
// info for artifacts
String url = url();
if (url.startsWith("http")) {
return url.substring(0, url.indexOf(fileName()) - mavenCoords().length() - 1);
} else {
return "";
}
}
String getBazelMavenJarFragment() {
if (isJar() && mavenCoords() != null) {
String repo = extractRepo();
String repoAttribute = "";
if (!"".equals(repo)) {
repoAttribute = " repository = '" + repo + "',\n";
}
String format =
" native.maven_jar (\n" +
" name = '%s',\n" +
" artifact = '%s',\n" +
" sha1 = '%s',\n" +
"%s" +
" )\n\n";
return String.format(format, jarTarget(), mavenCoords(), sha, repoAttribute);
} else {
String format =
" native.http_jar (\n" +
" name = '%s',\n" +
" url = '%s',\n" +
" sha256 = '%s',\n" +
" )\n\n";
return String.format(format, jarTarget(), url(), sha);
}
}
public String getBuckFragment() {
String visibility = isPublic() ? "[ 'PUBLIC' ]" : "[]";
boolean isJar = fileName().endsWith(".jar");
String output = (isJar ? "remote_jar" : "remote_file") + " (\n" +
String output = (isJar() ? "remote_jar" : "remote_file") + " (\n" +
" name = '%s',\n" + // jar target
" out = '%s',\n" + // jar file name
" url = '%s',\n" + // maven url
" sha1 = '%s',\n" + // artifact sha
( isJar && mavenCoords() != null ?
( isJar() && mavenCoords() != null ?
" maven_coords = '"+ mavenCoords()+"',\n" : "" ) +
" visibility = %s,\n" +
")\n\n";
@ -87,8 +157,9 @@ public abstract class BuckArtifact {
private final String url;
private final String mavenCoords;
public HTTPArtifact(String name, String url, String sha, String mavenCoords, boolean osgiReady) {
super(name, sha, osgiReady);
public HTTPArtifact(String name, String url, String sha,
String mavenCoords, boolean osgiReady, boolean generateForBazel) {
super(name, sha, osgiReady, generateForBazel);
this.url = url;
this.mavenCoords = mavenCoords;
}
@ -114,8 +185,9 @@ public abstract class BuckArtifact {
private final Artifact artifact;
private final String repo;
private MavenArtifact(String name, Artifact artifact, String sha, String repo, boolean osgiReady) {
super(name, sha, osgiReady);
private MavenArtifact(String name, Artifact artifact, String sha,
String repo, boolean osgiReady, boolean generateForBazel) {
super(name, sha, osgiReady, generateForBazel);
this.artifact = artifact;
this.repo = repo;
}
@ -142,7 +214,7 @@ public abstract class BuckArtifact {
@Override
String mavenCoords() {
String classifer = artifact.getClassifier();
if (!isOsgiReady()) {
if (!isOsgiReady() && !isGenerateForBazel()) {
classifer = "NON-OSGI" + classifer;
}

View File

@ -55,6 +55,8 @@ public class BuckLibGenerator {
private final List<BuckArtifact> artifacts = new ArrayList<>();
private final List<BuckLibrary> libraries = new ArrayList<>();
private static boolean generateForBazel = false;
/**
* Main entry point.
*
@ -66,6 +68,10 @@ public class BuckLibGenerator {
System.exit(5);
}
if (args.length == 3 && "--bazel".equals(args[2])) {
generateForBazel = true;
}
// Parse args
String jsonFilePath = args[0];
String outputBuckPath = args[1];
@ -107,14 +113,14 @@ public class BuckLibGenerator {
System.out.flush();
BuckArtifact buckArtifact;
if (uri.startsWith("http")) {
String sha = getHttpSha(name, uri);
buckArtifact = BuckArtifact.getArtifact(name, uri, sha);
String sha = generateForBazel ? getHttpSha256(name, uri) : getHttpSha1(name, uri);
buckArtifact = BuckArtifact.getArtifact(name, uri, sha, generateForBazel);
} else if (uri.startsWith("mvn")) {
uri = uri.replaceFirst("mvn:", "");
// if (repo != null) {
// System.out.println(name + " " + repo);
// }
buckArtifact = AetherResolver.getArtifact(name, uri, repo);
buckArtifact = AetherResolver.getArtifact(name, uri, repo, generateForBazel);
} else {
throw new RuntimeException("Unsupported artifact uri: " + uri);
}
@ -145,7 +151,7 @@ public class BuckLibGenerator {
libraryTargets.add(name);
});
return BuckLibrary.getLibrary(libraryName, libraryTargets);
return BuckLibrary.getLibrary(libraryName, libraryTargets, generateForBazel);
}
public BuckLibGenerator resolve() {
@ -170,6 +176,27 @@ public class BuckLibGenerator {
return this;
}
private String generateArtifacts() {
StringBuilder sb = new StringBuilder();
if (!generateForBazel) {
artifacts.forEach(artifact -> sb.append(artifact.getBuckFragment()));
} else {
StringBuilder mavenJars = new StringBuilder();
StringBuilder javaLibraries = new StringBuilder();
mavenJars.append("def generated_maven_jars():\n");
javaLibraries.append("def generated_java_libraries():\n");
artifacts.forEach(artifact -> {
mavenJars.append(artifact.getBazelMavenJarFragment());
javaLibraries.append(artifact.getBazelJavaLibraryFragment());
});
sb.append(mavenJars).append(javaLibraries);
}
return sb.toString();
}
void write(String outputFilePath) {
DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneId.of("UTC"));
File outputFile = new File(outputFilePath);
@ -182,17 +209,19 @@ public class BuckLibGenerator {
formatter.format(Instant.now())));
writer.write("# ***** Use onos-lib-gen *****\n");
// rule to publish the onos dependency pom
writer.write("\npass_thru_pom(\n" +
" name = 'onos-dependencies-pom',\n" +
" src = 'pom.xml',\n" +
" out = 'onos-dependencies.pom',\n" +
" artifactId = 'onos-dependencies',\n" +
")\n\n");
if (!generateForBazel) {
// TODO - have to do this somehow for bazel
// rule to publish the onos dependency pom
writer.write("\npass_thru_pom(\n" +
" name = 'onos-dependencies-pom',\n" +
" src = 'pom.xml',\n" +
" out = 'onos-dependencies.pom',\n" +
" artifactId = 'onos-dependencies',\n" +
")\n\n");
}
libraries.forEach(library -> writer.print(library.getBuckFragment()));
artifacts.forEach(artifact -> writer.print(artifact.getBuckFragment()));
libraries.forEach(library -> writer.print(library.getFragment()));
writer.print(generateArtifacts());
writer.flush();
} catch (FileNotFoundException e) {
error("File not found: %s", outputFilePath);
@ -202,10 +231,18 @@ public class BuckLibGenerator {
}
}
String getHttpSha(String name, String urlStr) {
String getHttpSha1(String name, String urlStr) {
return getHttpSha(name, urlStr, "SHA-1");
}
String getHttpSha256(String name, String urlStr) {
return getHttpSha(name, urlStr, "SHA-256");
}
String getHttpSha(String name, String urlStr, String algorithm) {
//FIXME need http download cache
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
MessageDigest md = MessageDigest.getInstance(algorithm);
byte[] buffer = new byte[8192];
URL url = new URL(urlStr);
@ -225,7 +262,7 @@ public class BuckLibGenerator {
.filter(File::canRead)
.findAny();
if (cache.isPresent()) {
if (cache.isPresent() && !generateForBazel) {
try (FileInputStream stream = new FileInputStream(cache.get())) {
int read;
while ((read = stream.read(buffer)) >= 0) {

View File

@ -28,24 +28,73 @@ public class BuckLibrary {
private final String name;
private final List<String> targets;
private final boolean generateForBazel;
private final Set<Artifact> provided = new HashSet<>();
private final Set<Artifact> runtime = new HashSet<>();
public static BuckLibrary getLibrary(String libraryName, List<String> libraryTargets) {
return new BuckLibrary(libraryName, libraryTargets);
public static BuckLibrary getLibrary(String libraryName, List<String> libraryTargets, boolean generateForBazel) {
return new BuckLibrary(libraryName, libraryTargets, generateForBazel);
}
private BuckLibrary(String name, List<String> targets) {
private BuckLibrary(String name, List<String> targets, boolean generateForBazel) {
this.name = name;
this.targets = targets;
this.generateForBazel = generateForBazel;
}
private String normalizeName(String name) {
if (!name.startsWith("//")) {
return name.replaceAll("[.-]", "_");
} else {
return name;
}
}
private String convertBuckTargetName(String buckTargetName) {
return normalizeName((buckTargetName.startsWith("//") ?
buckTargetName : buckTargetName.replaceFirst(":", "@")));
}
private boolean isAllUpper(String s) {
return s.toUpperCase().equals(s);
}
public String name() {
return name;
if (!generateForBazel) {
return name;
} else {
return normalizeName(name);
}
}
public String getBuckFragment() {
public String getFragment() {
if (generateForBazel) {
return getBazelFragment();
} else {
return getBuckFragment();
}
}
private String getBazelFragment() {
StringBuilder output = new StringBuilder()
.append(name())
.append(" = [");
targets.forEach(target -> {
if (isAllUpper(target)) {
output.append(String.format("] + %s + [", target.replaceFirst(":", "")));
} else {
String pathEnd = target.startsWith("//") ? "" : "//jar";
output.append(String.format("\n '%s%s',", convertBuckTargetName(target), pathEnd));
}
});
output.append("\n]\n");
return output.toString();
}
private String getBuckFragment() {
StringBuilder output = new StringBuilder()
.append("osgi_feature_group(\n")
.append(String.format(" name = '%s',\n", name))

0
tools/build_rules/BUILD Normal file
View File

View File

@ -0,0 +1,7 @@
load("//tools/build/bazel:generate_workspace.bzl",
"generated_java_libraries", "COMPILE", "CORE_DEPS", "JACKSON",
"TEST_ADAPTERS", "TEST", "TEST_REST", "METRICS", "KRYO", "NETTY")
load("//tools/build/bazel:osgi-java-library.bzl", "osgi_jar_with_tests", "osgi_jar")
generated_java_libraries()

25
utils/junit/BUILD Normal file
View File

@ -0,0 +1,25 @@
SRC = 'src/main/java/org/onlab/**/'
TEST_SRC = 'src/test/java/org/onlab/**/'
COMPILE_DEPS = [
"@guava//jar",
"@slf4j_api//jar",
"@hamcrest_all//jar",
"@junit//jar",
]
TEST_DEPS = [
"@guava_testlib//jar",
]
osgi_jar_with_tests(
name = 'onlab-junit',
srcs = glob([SRC + '*.java']),
deps = COMPILE_DEPS,
test_srcs = glob([TEST_SRC + '*.java']),
test_deps = TEST_DEPS,
package_name_root = 'org.onlab',
visibility = ["//visibility:public"],
)

17
utils/misc/BUILD Normal file
View File

@ -0,0 +1,17 @@
COMPILE_DEPS = COMPILE + JACKSON + [
"@kryo//jar",
"@metrics_core//jar",
"@netty//jar",
"@netty_common//jar",
"@objenesis//jar",
]
osgi_jar_with_tests(
name = 'onlab-misc',
deps = COMPILE_DEPS,
package_name_root = 'org.onlab',
exclude_tests = ['org.onlab.graph.AbstractGraphPathSearchTest',
'org.onlab.graph.GraphTest',
'org.onlab.util.SlidingWindowCounterTest'],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,60 @@
/*
* Copyright 2016-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.onlab.graph.AbstractEdgeTest;
import org.onlab.graph.AdjacencyListsGraphTest;
import org.onlab.graph.BellmanFordGraphSearchTest;
import org.onlab.graph.BreadthFirstSearchTest;
import org.onlab.graph.DefaultMutablePathTest;
import org.onlab.graph.DefaultPathTest;
import org.onlab.graph.DepthFirstSearchTest;
import org.onlab.graph.DijkstraGraphSearchTest;
import org.onlab.graph.DisjointPathPairTest;
import org.onlab.graph.HeapTest;
import org.onlab.graph.KShortestPathsSearchTest;
import org.onlab.graph.LazyKShortestPathsSearchTest;
import org.onlab.graph.SrlgGraphSearchTest;
import org.onlab.graph.SuurballeGraphSearchTest;
import org.onlab.graph.TarjanGraphSearchTest;
import org.onlab.util.ImmutableByteSequenceTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AbstractEdgeTest.class,
AdjacencyListsGraphTest.class,
BellmanFordGraphSearchTest.class,
BreadthFirstSearchTest.class,
DefaultMutablePathTest.class,
DefaultPathTest.class,
DepthFirstSearchTest.class,
DijkstraGraphSearchTest.class,
DisjointPathPairTest.class,
HeapTest.class,
KShortestPathsSearchTest.class,
LazyKShortestPathsSearchTest.class,
SrlgGraphSearchTest.class,
SuurballeGraphSearchTest.class,
TarjanGraphSearchTest.class,
ImmutableByteSequenceTest.class,
})
public class MiscTestSuite {
}

8
utils/osgi/BUILD Normal file
View File

@ -0,0 +1,8 @@
COMPILE_DEPS = COMPILE
osgi_jar_with_tests(
name = 'onlab-osgi',
deps = COMPILE_DEPS,
package_name_root = 'org.onlab',
visibility = ["//visibility:public"],
)

15
utils/osgiwrap/BUILD Normal file
View File

@ -0,0 +1,15 @@
OSGIWRAP_EXECUTABLE = 'osgi-jar'
COMPILE_DEPS = [
'@guava//jar',
'@bndlib//jar',
'@org_apache_felix_scr_bnd//jar'
]
java_binary(
name = OSGIWRAP_EXECUTABLE,
srcs = glob(['src/main/java/**/*.java']),
deps = COMPILE_DEPS,
main_class = 'org.onlab.osgiwrap.OSGiWrapper',
visibility = ["//visibility:public"]
)

View File

@ -74,10 +74,11 @@ public class OSGiWrapper {
private String bundleLicense;
private String webContext;
private String destdir;
// FIXME should consider using Commons CLI, etc.
public static void main(String[] args) {
if (args.length < 12) {
if (args.length < 13) {
System.err.println("Not enough args");
System.exit(1);
}
@ -94,6 +95,7 @@ public class OSGiWrapper {
String includeResources = args[9];
String webContext = args[10];
String dynamicimportPackages = args[11];
String destdir = args[12];
String desc = Joiner.on(' ').join(Arrays.copyOfRange(args, 12, args.length));
OSGiWrapper wrapper = new OSGiWrapper(jar, output, cp,
@ -103,7 +105,8 @@ public class OSGiWrapper {
includeResources,
webContext,
dynamicimportPackages,
desc);
desc,
destdir);
wrapper.log(wrapper + "\n");
if (!wrapper.execute()) {
System.err.printf("Error generating %s\n", name);
@ -124,7 +127,8 @@ public class OSGiWrapper {
String includeResources,
String webContext,
String dynamicimportPackages,
String bundleDescription) {
String bundleDescription,
String destdir) {
this.inputJar = inputJar;
this.classpath = Lists.newArrayList(classpath.split(":"));
if (!this.classpath.contains(inputJar)) {
@ -151,6 +155,7 @@ public class OSGiWrapper {
}
this.webContext = webContext;
this.destdir = destdir;
}
private void setProperties(Analyzer analyzer) {
@ -209,6 +214,8 @@ public class OSGiWrapper {
// Scan the JAR for Felix SCR annotations and generate XML files
Map<String, String> properties = Maps.newHashMap();
// destdir hack
properties.put("destdir", destdir);
SCRDescriptorBndPlugin scrDescriptorBndPlugin = new SCRDescriptorBndPlugin();
scrDescriptorBndPlugin.setProperties(properties);
scrDescriptorBndPlugin.setReporter(analyzer);

13
utils/rest/BUILD Normal file
View File

@ -0,0 +1,13 @@
COMPILE_DEPS = COMPILE + JACKSON + [
"//utils/osgi:onlab-osgi",
"//utils/misc:onlab-misc",
"@javax_ws_rs_api//jar",
"@jersey_server//jar",
]
osgi_jar(
name = 'onlab-rest',
deps = COMPILE_DEPS,
package_name_root = 'org.onlab',
visibility = ["//visibility:public"],
)