Revamp support for building third-party apps via maven
- Publish onos-dependencies (autogenerated from deps.json). With most
3rd-party dependencies listed as <dependencyManagement> to avoid
version conflicts, and a minimal set listed as <dependencies> to
simplify child poms. Similarly, we provide a number of plugins already
configured as <pluginManagement> to support the whole life-cycle of
apps (from build, to reporting and release).
- Update Maven plugins to work with JDK 11 (checkstyle, pmd, etc.)
- Publish onos-build-conf (with common checkstyle and pmd confs)
- Removed unused checkstyle code
- Fix OSGi version mismatch in deps.json to consistently depend on
release 6 (the one supported by Karaf 4)
- Update/simplify archetypes to use onos-dependencies as the parent pom
Change-Id: Ic09b34e13fb49eb3d96df623b53a3617bbf7b7e4
diff --git a/tools/build/conf/BUILD b/tools/build/conf/BUILD
index 1eb4fae..bf1effb 100644
--- a/tools/build/conf/BUILD
+++ b/tools/build/conf/BUILD
@@ -1,3 +1,5 @@
+load("//tools/build/bazel:pom_file.bzl", "pom_file")
+
checkstyle_source = "src/main/resources/onos/checkstyle.xml"
suppression_source = "src/main/resources/onos/suppressions.xml"
@@ -27,3 +29,9 @@
resources = glob(["src/main/resources/onos/**"]),
visibility = ["//visibility:public"],
)
+
+pom_file(
+ name = "onos-build-conf-pom",
+ artifact = "onos-build-conf",
+ visibility = ["//visibility:public"],
+)
diff --git a/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java b/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java
deleted file mode 100644
index ab1f7eb..0000000
--- a/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * 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.onosproject.checkstyle;
-
-import com.puppycrawl.tools.checkstyle.Checker;
-import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
-import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
-import com.puppycrawl.tools.checkstyle.PropertiesExpander;
-import com.puppycrawl.tools.checkstyle.api.AuditEvent;
-import com.puppycrawl.tools.checkstyle.api.AuditListener;
-import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
-import com.puppycrawl.tools.checkstyle.api.Configuration;
-import org.onosproject.buckdaemon.BuckTask;
-import org.onosproject.buckdaemon.BuckTaskContext;
-
-import java.io.File;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.stream.Collectors;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-
-/**
- * Buck task for executing checkstyle on the specified project files.
- */
-public class CheckstyleRunner implements BuckTask {
-
- private final Configuration config;
-
- public CheckstyleRunner(String configLocation, String suppressionLocation) {
- try {
- // create a configuration
- DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader
- .loadConfiguration(configLocation, new PropertiesExpander(System.getProperties()));
-
- // add the suppression file to the configuration
- DefaultConfiguration suppressions = new DefaultConfiguration("SuppressionFilter");
- suppressions.addAttribute("file", suppressionLocation);
- config.addChild(suppressions);
-
- this.config = config;
- } catch (CheckstyleException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void execute(BuckTaskContext context) {
- List<String> input = context.input();
- if (input.size() < 3 || input.get(2).length() == 0) {
- return;
- }
- String project = input.get(0);
- String baseDir = input.get(1);
-
- // create a listener for output
- StringAuditor listener = new StringAuditor(context);
- listener.setProjectName(project);
- listener.setBaseDir(baseDir);
-
- // create Checker object and run it
- final Checker checker = new Checker();
- final ClassLoader moduleClassLoader = Checker.class.getClassLoader();
- checker.setModuleClassLoader(moduleClassLoader);
-
- try {
- checker.configure(config);
- checker.addListener(listener);
-
- // run Checker
- List<File> fileList = input.subList(2, input.size()).stream()
- .filter(s -> !s.contains("/:")) // Yes, fighting a hack with a hack.
- .map(File::new)
- .collect(Collectors.toList());
- int errorCounter = checker.process(fileList);
- if (errorCounter > 0) {
- context.output("CHECKSTYLE ERROR");
- }
-
- listener.await();
- } catch (CheckstyleException | InterruptedException e) {
- e.printStackTrace(); //dump exeception to stderr
- throw new RuntimeException(e);
- } finally {
- checker.destroy();
- }
-
- }
-
- static class StringAuditor implements AuditListener {
-
- private final BuckTaskContext context;
- private CountDownLatch finishedLatch = new CountDownLatch(1);
- private String baseDir = "";
- private String project = "";
-
- StringAuditor(BuckTaskContext context) {
- this.context = context;
- }
-
- public void setBaseDir(String base) {
- this.baseDir = base;
- }
-
- public void setProjectName(String projectName) {
- this.project = projectName;
- }
-
- public void await() throws InterruptedException {
- finishedLatch.await();
- }
-
- @Override
- public void auditStarted(AuditEvent evt) {
- }
-
- @Override
- public void auditFinished(AuditEvent evt) {
- finishedLatch.countDown();
- }
-
- @Override
- public void fileStarted(AuditEvent evt) {
- }
-
- @Override
- public void fileFinished(AuditEvent evt) {
- }
-
- @Override
- public void addError(AuditEvent evt) {
- switch (evt.getSeverityLevel()) {
- case ERROR:
- StringBuilder output = new StringBuilder();
- String fileName = evt.getFileName();
- if (!isNullOrEmpty(baseDir)) {
- int index = fileName.indexOf(baseDir);
- if (index >= 0) {
- fileName = fileName.substring(index + baseDir.length() + 1);
- if (!isNullOrEmpty(project)) {
- output.append(project).append(':');
- }
- }
- }
- output.append(fileName).append(':').append(evt.getLine());
- if (evt.getColumn() > 0) {
- output.append(':').append(evt.getColumn());
- }
- output.append(": ").append(evt.getMessage());
- context.output(output.toString());
- break;
- case IGNORE:
- case INFO:
- case WARNING:
- default:
- break;
- }
- }
-
- @Override
- public void addException(AuditEvent evt, Throwable throwable) {
- addError(evt);
- context.output(throwable.getMessage());
- }
- }
-
-}
diff --git a/tools/build/conf/src/main/java/org/onosproject/checkstyle/package-info.java b/tools/build/conf/src/main/java/org/onosproject/checkstyle/package-info.java
deleted file mode 100644
index 241a819..0000000
--- a/tools/build/conf/src/main/java/org/onosproject/checkstyle/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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.
- */
-/**
- * checkstyle runner for BuckDaemon.
- */
-package org.onosproject.checkstyle;
diff --git a/tools/build/conf/src/main/resources/onos/checkstyle-mvn.xml b/tools/build/conf/src/main/resources/onos/checkstyle-mvn.xml
index a236f73..fcad23f 100644
--- a/tools/build/conf/src/main/resources/onos/checkstyle-mvn.xml
+++ b/tools/build/conf/src/main/resources/onos/checkstyle-mvn.xml
@@ -115,6 +115,14 @@
<property name="message" value="javafx classes are not supported by all JDKs."/>
</module>
+ <!-- Don't allow usage of RuntimeException -->
+ <module name="RegexpSingleline">
+ <property name="format" value="throw[ ]*new[ ]*RuntimeException"/>
+ <property name="minimum" value="0"/>
+ <property name="maximum" value="0"/>
+ <property name="message" value="Don't throw generic exception types"/>
+ </module>
+
<!-- Checks for Headers -->
<!-- See http://checkstyle.sf.net/config_header.html -->
<!-- <module name="Header"> -->
@@ -122,12 +130,6 @@
<!-- <property name="fileExtensions" value="java"/> -->
<!-- </module> -->
- <module name="RegexpHeader">
- <!-- The following line is different for maven due to how the maven checkstyle plugin works -->
- <property name="headerFile" value="${checkstyle.header.file}"/>
- <property name="fileExtensions" value="java"/>
- </module>
-
<module name="SuppressWarningsFilter" />
<module name="SuppressWithPlainTextCommentFilter"/>
@@ -164,13 +166,13 @@
<property name="suppressLoadErrors" value="true"/>
</module>
<module name="JavadocType">
- <property name="severity" value="warning"/>
+ <property name="severity" value="ignore"/>
</module>
<module name="JavadocVariable">
<!-- Suppress check for private member Javadocs.
Possibly revist fixing these. -->
<property name="scope" value="public"/>
- <property name="severity" value="warning"/>
+ <property name="severity" value="ignore"/>
</module>
<module name="JavadocStyle"/>
<!-- @author tag should not be used -->
@@ -309,7 +311,7 @@
<module name="InterfaceIsType"/>
<module name="VisibilityModifier">
- <property name="severity" value="warning"/>
+ <property name="severity" value="ignore"/>
</module>
diff --git a/tools/build/conf/src/main/resources/onos/pmd.xml b/tools/build/conf/src/main/resources/onos/pmd.xml
index 156e6f9..19bac09 100644
--- a/tools/build/conf/src/main/resources/onos/pmd.xml
+++ b/tools/build/conf/src/main/resources/onos/pmd.xml
@@ -15,63 +15,59 @@
~ limitations under the License.
-->
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- name="ONOS Rules"
- xmlns="http://pmd.sf.net/ruleset/1.0.0"
- xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
- xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" >
+ name="ONOS Rules"
+ xmlns="http://pmd.sf.net/ruleset/1.0.0"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
+ xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>ONOS PMD rules</description>
- <rule ref="rulesets/java/unnecessary.xml" >
- <exclude name="UselessParentheses" />
+
+ <rule ref="category/java/errorprone.xml">
+ <exclude name="EmptyCatchBlock"/>
</rule>
- <rule ref="rulesets/java/basic.xml">
- <exclude name="EmptyCatchBlock"/>
+ <rule ref="category/java/errorprone.xml/EmptyCatchBlock">
+ <properties>
+ <property name="allowCommentedBlocks" value="true"/>
+ </properties>
</rule>
- <rule ref="rulesets/java/basic.xml/EmptyCatchBlock">
- <properties>
- <property name="allowCommentedBlocks" value="true"/>
- </properties>
- </rule>
- <rule ref="rulesets/java/unusedcode.xml">
- <!-- Explicit public keyword in interface methods is acceptable -->
- <exclude name="UnusedModifier" />
- </rule>
- <rule ref="rulesets/java/imports.xml"/>
+ <rule ref="category/java/bestpractices.xml"/>
<rule ref="rulesets/java/optimizations.xml">
- <exclude name="LocalVariableCouldBeFinal" />
- <exclude name="MethodArgumentCouldBeFinal" />
- <exclude name="AvoidInstantiatingObjectsInLoops" />
+ <exclude name="AvoidInstantiatingObjectsInLoops"/>
</rule>
<rule ref="rulesets/java/strings.xml">
- <exclude name="AvoidDuplicateLiterals" />
+ <exclude name="AvoidDuplicateLiterals"/>
</rule>
<rule ref="rulesets/java/braces.xml"/>
- <rule ref="rulesets/java/naming.xml">
- <exclude name="AvoidInstantiatingObjectsInLoops" />
- <exclude name="ShortClassName" />
- <exclude name="ShortMethodName" />
- <exclude name="ShortVariable" />
- <exclude name="LongVariable" />
+ <rule ref="category/java/codestyle.xml">
+ <!-- Explicit public keyword in interface methods is acceptable -->
+ <exclude name="UnnecessaryModifier"/>
+ <exclude name="UselessParentheses"/>
+ <exclude name="ShortClassName"/>
+ <exclude name="ShortMethodName"/>
+ <exclude name="ShortVariable"/>
+ <exclude name="LongVariable"/>
+ <exclude name="MethodArgumentCouldBeFinal"/>
+ <exclude name="LocalVariableCouldBeFinal"/>
</rule>
- <rule ref="rulesets/java/naming.xml/VariableNamingConventions">
- <properties>
- <!-- ONOS allows the name "log" for static final Loggers -->
- <property name="violationSuppressRegex" value=".*'log'.*"/>
- </properties>
+ <rule ref="category/java/codestyle.xml/VariableNamingConventions">
+ <properties>
+ <!-- ONOS allows the name "log" for static final Loggers -->
+ <property name="violationSuppressRegex" value=".*'log'.*"/>
+ </properties>
</rule>
<rule ref="rulesets/java/clone.xml"/>
<rule ref="rulesets/java/strictexception.xml"/>
<rule ref="rulesets/java/design.xml">
- <exclude name="GodClass" />
+ <exclude name="GodClass"/>
</rule>
<rule ref="rulesets/java/coupling.xml">
- <exclude name="LawOfDemeter" />
- <exclude name="ExcessiveImports" />
- <!-- Suppress Removed misconfigured rule warning -->
- <exclude name="LoosePackageCoupling" />
+ <exclude name="LawOfDemeter"/>
+ <exclude name="ExcessiveImports"/>
+ <!-- Suppress Removed misconfigured rule warning -->
+ <exclude name="LoosePackageCoupling"/>
</rule>
</ruleset>
diff --git a/tools/build/conf/src/main/resources/onos/suppressions.xml b/tools/build/conf/src/main/resources/onos/suppressions.xml
index c4e43e2..9f433a7 100644
--- a/tools/build/conf/src/main/resources/onos/suppressions.xml
+++ b/tools/build/conf/src/main/resources/onos/suppressions.xml
@@ -61,4 +61,6 @@
<!-- Suppressions for yangutils generated code -->
<suppress files="org.onosproject.yang.gen.v1.*" checks="Javadoc.*" />
+
+ <suppress files="ApiDocRegistrator.java" checks="JavadocPackage" />
</suppressions>