HBASE-21635 Use maven enforcer to ban imports from illegal packages

This commit is contained in:
zhangduo 2018-12-23 18:25:42 +08:00 committed by Duo Zhang
parent 7c0a3cc265
commit 97fd647de2
3 changed files with 107 additions and 25 deletions

View File

@ -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;
/**

View File

@ -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++) {

83
pom.xml
View File

@ -1077,6 +1077,11 @@
<artifactId>extra-enforcer-rules</artifactId>
<version>${extra.enforcer.version}</version>
</dependency>
<dependency>
<groupId>de.skuzzle.enforcer</groupId>
<artifactId>restrict-imports-enforcer-rule</artifactId>
<version>${restrict-imports.enforcer.version}</version>
</dependency>
</dependencies>
<!-- version set by parent -->
<executions>
@ -1188,6 +1193,79 @@
<skip>${skip.license.check}</skip>
</configuration>
</execution>
<execution>
<id>banned-illegal-imports</id>
<phase>process-sources</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Use SLF4j for logging</reason>
<bannedImports>
<bannedImport>org.apache.commons.logging.Log</bannedImport>
<bannedImport>org.apache.commons.logging.LogFactory</bannedImport>
</bannedImports>
</restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Use shaded version in hbase-thirdparty</reason>
<bannedImports>
<bannedImport>com.google.common.**</bannedImport>
<bannedImport>io.netty.**</bannedImport>
<bannedImport>org.apache.commons.cli.**</bannedImport>
<bannedImport>org.apache.commons.collections.**</bannedImport>
<bannedImport>org.apache.commons.collections4.**</bannedImport>
</bannedImports>
</restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Do not use shaded classes from other dependencies</reason>
<bannedImports>
<bannedImport>org.apache.curator.shaded.**</bannedImport>
<bannedImport>org.apache.htrace.shaded.**</bannedImport>
</bannedImports>
</restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Use shaded gson in hbase-thirdparty</reason>
<bannedImports>
<bannedImport>org.codehaus.jackson.**</bannedImport>
</bannedImports>
</restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Use commons lang 3</reason>
<bannedImports>
<bannedImport>org.apache.commons.lang.**</bannedImport>
</bannedImports>
</restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Use yetus IA and IS annotations</reason>
<bannedImports>
<bannedImport>org.apache.hadoop.classificatio.**</bannedImport>
</bannedImports>
</restrictImports>
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
<includeTestCode>true</includeTestCode>
<commentLineBufferSize>512</commentLineBufferSize>
<reason>Do not use htrace v3</reason>
<bannedImports>
<bannedImport>org.htrace.**</bannedImport>
</bannedImports>
</restrictImports>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<!-- parent-module only plugins -->
@ -1599,8 +1677,9 @@
<!-- Surefire argLine defaults to Linux, cygwin argLine is used in the os.windows profile -->
<argLine>${hbase-surefire.argLine}</argLine>
<jacoco.version>0.7.5.201505241946</jacoco.version>
<extra.enforcer.version>1.0-beta-6</extra.enforcer.version>
<enforcer.version>3.0.0-M1</enforcer.version>
<extra.enforcer.version>1.0-beta-9</extra.enforcer.version>
<enforcer.version>3.0.0-M2</enforcer.version>
<restrict-imports.enforcer.version>0.14.0</restrict-imports.enforcer.version>
<!-- Location of test resources -->
<test.build.classes>${project.build.directory}/test-classes</test.build.classes>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>