Skip to content
Permalink
Browse files
HBASE-22687 Added HBase Checkstyle configuration to the project
Signed-off-by: stack <stack@apache.org>
  • Loading branch information
HorizonNet committed Jul 14, 2019
1 parent aa102dd commit d90b0638e86b296e9ebc7ead2ebf48d7bb803fc8
Showing 7 changed files with 123 additions and 44 deletions.
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<!--
/**
* 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.
*/
ON MVN COMPILE NOT WORKING
If you wondering why 'mvn compile' does not work building HBase
(in particular, if you are doing it for the first time), instead do
'mvn package'. If you are interested in the full story, see
https://issues.apache.org/jira/browse/HBASE-6795.
-->
<suppressions>
<suppress checks="IllegalImport" message="org\.apache\.commons\.cli"/>
<suppress checks="ImportOrder" message="Extra separation in import group before"/>
</suppressions>
@@ -133,6 +133,13 @@
<commitIdGenerationMode>flat</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
@@ -17,6 +17,16 @@
*/
package org.apache.hbase;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
@@ -53,17 +63,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.Collectors;

/**
* HBase fixup tool version 2, for hbase-2.0.0+ clusters.
* Supercedes hbck1.
@@ -253,18 +252,13 @@ List<Boolean> bypass(String [] args)
}
}

private String readHBCK2BuildProperties() throws IOException {
private String readHBCK2BuildProperties(final String propertyKey) throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("hbck2.properties");
StringBuilder resultStringBuilder = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
}
return resultStringBuilder.toString();
final Properties properties = new Properties();
properties.load(inputStream);
return properties.getProperty(propertyKey);
}

private static final String getCommandUsage() {
// NOTE: List commands belonw alphabetically!
StringWriter sw = new StringWriter();
@@ -397,7 +391,7 @@ public int run(String[] args) throws IOException {

// Process general options.
if (commandLine.hasOption(version.getOpt())) {
System.out.println(readHBCK2BuildProperties());
System.out.println(readHBCK2BuildProperties(VERSION));
return EXIT_SUCCESS;
}
if (commandLine.hasOption(help.getOpt()) || commandLine.getArgList().isEmpty()) {
@@ -1 +1,16 @@
Version=${project.version}
# 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.
version=${project.version}
@@ -17,12 +17,18 @@
*/
package org.apache.hbase;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import junit.framework.TestCase;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.Result;
@@ -36,14 +42,6 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* Tests commands. For command-line parsing, see adjacent test.
* @see TestHBCKCommandLineParsing
@@ -17,19 +17,19 @@
*/
package org.apache.hbase;

import org.apache.commons.cli.ParseException;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.logging.log4j.LogManager;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Properties;

import static org.junit.Assert.*;
import org.apache.commons.cli.ParseException;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.logging.log4j.LogManager;
import org.junit.Test;

/**
* Does command-line parsing tests. No clusters.
@@ -63,13 +63,10 @@ public void testSetRegionStateCommandInvalidState() throws IOException {
@Test
public void testVersionOption() throws IOException {
// Read the hbck version from properties file.
String line;
String expectedVersionOutput = "";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("hbck2.properties");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
while ((line = br.readLine()) != null) {
expectedVersionOutput += line;
}
final Properties properties = new Properties();
properties.load(inputStream);
String expectedVersionOutput = properties.getProperty("version");
// Get hbck version option output.
String actualVersionOutput = retrieveOptionOutput("-v").trim();
assertEquals(expectedVersionOutput, actualVersionOutput);
32 pom.xml
@@ -128,6 +128,9 @@
<surefire.version>2.21.0</surefire.version>
<surefire.provider>surefire-junit47</surefire.provider>
<test.output.tofile>true</test.output.tofile>
<checkstyle.version>8.11</checkstyle.version>
<maven.checkstyle.version>3.0.0</maven.checkstyle.version>
<hbase.checkstyle.version>2.2.0</hbase.checkstyle.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -288,6 +291,31 @@
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<!-- Approach followed here is roughly the same as mentioned here:
https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html
-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-checkstyle</artifactId>
<version>${hbase.checkstyle.version}</version>
</dependency>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>hbase/checkstyle.xml</configLocation>
<suppressionsLocation>dev-support/checkstyle-suppressions.xml</suppressionsLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
@@ -353,6 +381,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>

0 comments on commit d90b063

Please sign in to comment.