diff --git a/lib/BUCK b/lib/BUCK index 12f9b45f79..234763086f 100644 --- a/lib/BUCK +++ b/lib/BUCK @@ -1,4 +1,4 @@ -# ***** This file was auto-generated at Wed, 13 Jun 2018 22:38:24 GMT. Do not edit this file manually. ***** +# ***** This file was auto-generated at Tue, 19 Jun 2018 22:30:22 GMT. Do not edit this file manually. ***** # ***** Use onos-lib-gen ***** pass_thru_pom( @@ -223,6 +223,15 @@ remote_jar ( visibility = [ 'PUBLIC' ], ) +remote_jar ( + name = 'commons-cli', + out = 'commons-cli-1.3.jar', + url = 'mvn:commons-cli:commons-cli:jar:1.3', + sha1 = 'a48653b6bcd06b5e61ed63739ca601701fcb6a6c', + maven_coords = 'commons-cli:commons-cli:1.3', + visibility = [ 'PUBLIC' ], +) + remote_jar ( name = 'commons-collections', out = 'commons-collections-3.2.2.jar', diff --git a/lib/deps.json b/lib/deps.json index ea4b309d91..c8c8512a42 100644 --- a/lib/deps.json +++ b/lib/deps.json @@ -118,6 +118,7 @@ "asm": "mvn:org.ow2.asm:asm:5.0.4", "atomix": "mvn:io.atomix:atomix:2.0.22", "commons-codec": "mvn:commons-codec:commons-codec:1.10", + "commons-cli": "mvn:commons-cli:commons-cli:1.3", "commons-collections": "mvn:commons-collections:commons-collections:3.2.2", "commons-configuration": "mvn:commons-configuration:commons-configuration:1.10", "commons-io": "mvn:commons-io:commons-io:2.6", diff --git a/tools/build/bazel/checkstyle.bzl b/tools/build/bazel/checkstyle.bzl new file mode 100644 index 0000000000..d27ac57766 --- /dev/null +++ b/tools/build/bazel/checkstyle.bzl @@ -0,0 +1,85 @@ +""" + Copyright 2018-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. +""" + + +""" + Implementation of the rule to call checkstyle +""" +def _checkstyle_impl(ctx): + classpath = "" + need_colon = False + for file in ctx.files._classpath: + if need_colon: + classpath += ":" + need_colon = True + classpath += file.path + + cmd = " ".join( + ["java -cp %s com.puppycrawl.tools.checkstyle.Main" % classpath] + + ["-c %s" % ctx.attr._config.files.to_list()[0].path] + + [src_file.path for src_file in ctx.files.srcs]) + + ctx.actions.write( + output = ctx.outputs.executable, + content = cmd, + ) + + inputs = (ctx.files.srcs + + ctx.files._classpath + + ctx.attr._config.files.to_list() + + ctx.attr._suppressions.files.to_list() + + ctx.attr._java_header.files.to_list()) + + runfiles = ctx.runfiles(files = inputs) + return [DefaultInfo(runfiles = runfiles)] + + +""" + Rule definition for calling checkstyle +""" +_execute_checkstyle_test = rule( + test = True, + attrs = { + "_classpath": attr.label_list(default=[ + Label("@checkstyle//jar"), + Label("@commons_beanutils//jar"), + Label("@commons_cli//jar"), + Label("@commons_collections//jar"), + Label("@antlr//jar"), + Label("@guava//jar"), + Label("@commons_logging//jar"), + ]), + "srcs": attr.label_list(allow_files = FileType([".java"])), + "_config": attr.label(default=Label("//tools/build/conf:checkstyle_xml")), + "_suppressions": attr.label(default=Label("//tools/build/conf:suppressions_xml")), + "_java_header": attr.label(default=Label("//tools/build/conf:onos_java_header")), + }, + + implementation = _checkstyle_impl, +) + +""" + Macro to instantiate the checkstyle rule for a given set of sources. + + Args: + name: name of the target to generate. Required. + srcs: list of source file targets to run checkstyle on. Required. + size: test size constraint. Optional, defaults to "small" +""" +def checkstyle_test(name, srcs): + _execute_checkstyle_test(name = name, srcs = srcs, size = "small") + + diff --git a/tools/build/bazel/generate_workspace.bzl b/tools/build/bazel/generate_workspace.bzl index c41008e654..39ccf93abf 100644 --- a/tools/build/bazel/generate_workspace.bzl +++ b/tools/build/bazel/generate_workspace.bzl @@ -1,4 +1,4 @@ -# ***** This file was auto-generated at Wed, 13 Jun 2018 22:38:28 GMT. Do not edit this file manually. ***** +# ***** This file was auto-generated at Tue, 19 Jun 2018 22:30:34 GMT. Do not edit this file manually. ***** # ***** Use onos-lib-gen ***** load("//tools/build/bazel:variables.bzl", "ONOS_GROUP_ID", "ONOS_VERSION") @@ -142,6 +142,12 @@ def generated_maven_jars(): sha1 = "4b95f4897fa13f2cd904aee711aeafc0c5295cd8", ) + native.maven_jar( + name = "commons_cli", + artifact = "commons-cli:commons-cli:1.3", + sha1 = "a48653b6bcd06b5e61ed63739ca601701fcb6a6c", + ) + native.maven_jar( name = "commons_collections", artifact = "commons-collections:commons-collections:3.2.2", @@ -1140,6 +1146,12 @@ def generated_java_libraries(): exports = ["@commons_codec//jar"], ) + native.java_library( + name = "commons_cli", + visibility = ["//visibility:public"], + exports = ["@commons_cli//jar"], + ) + native.java_library( name = "commons_collections", visibility = ["//visibility:public"], @@ -2100,6 +2112,7 @@ artifact_map[str(Label("@amqp_client//jar"))] = "mvn:com.rabbitmq:amqp-client:ja artifact_map[str(Label("@asm//jar"))] = "mvn:org.ow2.asm:asm:jar:5.0.4" artifact_map[str(Label("@atomix//jar"))] = "mvn:io.atomix:atomix:jar:2.0.22" artifact_map[str(Label("@commons_codec//jar"))] = "mvn:commons-codec:commons-codec:jar:1.10" +artifact_map[str(Label("@commons_cli//jar"))] = "mvn:commons-cli:commons-cli:jar:1.3" artifact_map[str(Label("@commons_collections//jar"))] = "mvn:commons-collections:commons-collections:jar:3.2.2" artifact_map[str(Label("@commons_configuration//jar"))] = "mvn:commons-configuration:commons-configuration:jar:1.10" artifact_map[str(Label("@commons_io//jar"))] = "mvn:commons-io:commons-io:jar:2.6" diff --git a/tools/build/bazel/osgi_java_library.bzl b/tools/build/bazel/osgi_java_library.bzl index bb07140c34..342a49a17d 100644 --- a/tools/build/bazel/osgi_java_library.bzl +++ b/tools/build/bazel/osgi_java_library.bzl @@ -17,6 +17,7 @@ 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") +load("//tools/build/bazel:checkstyle.bzl", "checkstyle_test") def _all_java_sources(): return native.glob(["src/main/java/**/*.java"]) @@ -451,6 +452,11 @@ def osgi_jar_with_tests( deps = all_test_deps, ) + checkstyle_test( + name = name + "_checkstyle_test", + srcs = srcs, + ) + """ Creates an OSGI jar file from a set of source files. diff --git a/tools/build/conf/BUILD b/tools/build/conf/BUILD new file mode 100644 index 0000000000..22a1ecf043 --- /dev/null +++ b/tools/build/conf/BUILD @@ -0,0 +1,23 @@ +checkstyle_source = "src/main/resources/onos/checkstyle.xml" + +suppression_source = "src/main/resources/onos/suppressions.xml" + +header_source = "src/main/resources/onos/onos-java.header" + +filegroup( + name = "checkstyle_xml", + srcs = [checkstyle_source], + visibility = ["//visibility:public"], +) + +filegroup( + name = "suppressions_xml", + srcs = [suppression_source], + visibility = ["//visibility:public"], +) + +filegroup( + name = "onos_java_header", + srcs = [header_source], + visibility = ["//visibility:public"], +) diff --git a/tools/build/conf/src/main/resources/onos/checkstyle.xml b/tools/build/conf/src/main/resources/onos/checkstyle.xml index d3cc7300de..21ac8daa5a 100644 --- a/tools/build/conf/src/main/resources/onos/checkstyle.xml +++ b/tools/build/conf/src/main/resources/onos/checkstyle.xml @@ -122,6 +122,10 @@ + + + + @@ -164,13 +168,13 @@ - + - + @@ -309,7 +313,7 @@ - +