From ad285eae4f799ed71360679742219c20f6188242 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 24 Dec 2018 11:30:13 +0800 Subject: [PATCH] HBASE-21635 Use maven enforcer to ban imports from illegal packages --- .../hadoop/hbase/master/DeadServer.java | 17 ++-- .../hbase/regionserver/CellChunkMap.java | 1 - .../TestBalancerStatusTagInJMXMetrics.java | 32 +++---- pom.xml | 83 ++++++++++++++++++- 4 files changed, 107 insertions(+), 26 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java index 4183201c614..05847923cee 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java @@ -18,15 +18,6 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.yetus.audience.InterfaceAudience; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.apache.hadoop.hbase.util.Pair; - -import com.google.common.base.Preconditions; - import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -37,6 +28,14 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +import org.apache.hadoop.hbase.util.Pair; +import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hbase.thirdparty.com.google.common.base.Preconditions; /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java index 0ef54a13e33..a2c18206271 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellChunkMap.java @@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.regionserver; import java.nio.ByteBuffer; -import com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.hbase.Cell; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.util.Bytes; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java index 9f566210a87..d23436d3b4c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java @@ -1,22 +1,25 @@ /** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you 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. + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.hadoop.hbase.master.balancer; import static org.junit.Assert.assertEquals; import java.util.Random; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; @@ -31,6 +34,8 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Category({ MediumTests.class }) public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase { @@ -39,7 +44,7 @@ public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase { public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestBalancerStatusTagInJMXMetrics.class); - private static final Log LOG = LogFactory.getLog(TestBalancerStatusTagInJMXMetrics.class); + private static final Logger LOG = LoggerFactory.getLogger(TestBalancerStatusTagInJMXMetrics.class); private static HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static int connectorPort = 61120; private static HMaster master; @@ -51,7 +56,6 @@ public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase { */ @BeforeClass public static void setupBeforeClass() throws Exception { - conf = UTIL.getConfiguration(); Random rand = new Random(); for (int i = 0; i < 10; i++) { diff --git a/pom.xml b/pom.xml index 1c59b52dc06..91cc74084e1 100755 --- a/pom.xml +++ b/pom.xml @@ -969,6 +969,11 @@ extra-enforcer-rules ${extra.enforcer.version} + + de.skuzzle.enforcer + restrict-imports-enforcer-rule + ${restrict-imports.enforcer.version} + @@ -1064,6 +1069,79 @@ ${skip.license.check} + + banned-illegal-imports + process-sources + + enforce + + + + + true + 512 + Use SLF4j for logging + + org.apache.commons.logging.Log + org.apache.commons.logging.LogFactory + + + + true + 512 + Use shaded version in hbase-thirdparty + + com.google.common.** + io.netty.** + org.apache.commons.cli.** + org.apache.commons.collections.** + org.apache.commons.collections4.** + + + + true + 512 + Do not use shaded classes from other dependencies + + org.apache.curator.shaded.** + org.apache.htrace.shaded.** + + + + true + 512 + Use shaded gson in hbase-thirdparty + + org.codehaus.jackson.** + + + + true + 512 + Use commons lang 3 + + org.apache.commons.lang.** + + + + true + 512 + Use yetus IA and IS annotations + + org.apache.hadoop.classificatio.** + + + + true + 512 + Do not use htrace v3 + + org.htrace.** + + + + + @@ -1465,8 +1543,9 @@ ${hbase-surefire.argLine} 0.7.5.201505241946 - 1.0-beta-6 - 3.0.0-M1 + 1.0-beta-9 + 3.0.0-M2 + 0.14.0 ${project.build.directory}/test-classes yyyy-MM-dd'T'HH:mm:ss'Z'