accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmil...@apache.org
Subject [accumulo-examples] branch master updated: Add import-control checkstyle for checking API (#34)
Date Tue, 29 Jan 2019 21:21:37 GMT
This is an automated email from the ASF dual-hosted git repository.

mmiller pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new 8e62331  Add import-control checkstyle for checking API (#34)
8e62331 is described below

commit 8e6233125053971b16c26d1bff1144353625304b
Author: Mike Miller <mmiller@apache.org>
AuthorDate: Tue Jan 29 16:21:33 2019 -0500

    Add import-control checkstyle for checking API (#34)
    
    * Also moved maven files to contrib directory, dropping build directory
    * Updated checkstyle to latest version
    * Add exceptions to hold the line for API
    * Use guava PeekingIterator
---
 {build => contrib}/Eclipse-Accumulo-Codestyle.xml  |  0
 {build => contrib}/checkstyle.xml                  |  8 ++--
 contrib/import-control.xml                         | 45 ++++++++++++++++++++++
 pom.xml                                            | 25 +++++++++---
 .../examples/filedata/ChunkInputFormat.java        |  6 ++-
 .../examples/filedata/ChunkInputStream.java        |  3 +-
 .../accumulo/examples/filedata/FileDataQuery.java  |  6 ++-
 .../examples/filedata/ChunkInputStreamIT.java      |  6 ++-
 .../examples/filedata/ChunkInputStreamTest.java    | 25 ++++++------
 9 files changed, 94 insertions(+), 30 deletions(-)

diff --git a/build/Eclipse-Accumulo-Codestyle.xml b/contrib/Eclipse-Accumulo-Codestyle.xml
similarity index 100%
rename from build/Eclipse-Accumulo-Codestyle.xml
rename to contrib/Eclipse-Accumulo-Codestyle.xml
diff --git a/build/checkstyle.xml b/contrib/checkstyle.xml
old mode 100755
new mode 100644
similarity index 71%
rename from build/checkstyle.xml
rename to contrib/checkstyle.xml
index 4bfef83..590efce
--- a/build/checkstyle.xml
+++ b/contrib/checkstyle.xml
@@ -17,11 +17,9 @@
 <module name="Checker">
   <property name="charset" value="UTF-8"/>
   <module name="TreeWalker">
-    <module name="RegexpSinglelineJava">
-      <!--check that only Accumulo public APIs are imported-->
-      <property name="format" value="import\s+org\.apache\.accumulo\.(.*\.(impl|thrift|crypto)\..*|(?!core|minicluster|examples).*|core\.(?!client|data|security|cli|iterators).*)"/>
-      <property name="ignoreComments" value="true" />
-      <property name="message" value="Accumulo non-public classes imported" />
+    <!--check that only Accumulo public APIs are imported-->
+    <module name="ImportControl">
+      <property name="file" value="contrib/import-control.xml"/>
     </module>
   </module>
 </module>
diff --git a/contrib/import-control.xml b/contrib/import-control.xml
new file mode 100644
index 0000000..22da90b
--- /dev/null
+++ b/contrib/import-control.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<!DOCTYPE import-control PUBLIC
+    "-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
+    "https://checkstyle.org/dtds/import_control_1_4.dtd">
+
+<!-- This checkstyle rule is configured to ensure only use of Accumulo API -->
+<import-control pkg="org.apache.accumulo.examples" strategyOnMismatch="allowed">
+    <!-- allow this package -->
+    <allow pkg="org.apache.accumulo.examples"/>
+    <!-- API packages -->
+    <allow pkg="org.apache.accumulo.core.client"/>
+    <allow pkg="org.apache.accumulo.core.data"/>
+    <allow pkg="org.apache.accumulo.core.security"/>
+    <allow pkg="org.apache.accumulo.core.iterators"/>
+    <allow pkg="org.apache.accumulo.minicluster"/>
+    <allow pkg="org.apache.accumulo.hadoop.mapreduce"/>
+
+    <!-- exceptions for this project -->
+    <allow pkg="org.apache.accumulo.core.conf"/>
+    <allow class="org.apache.accumulo.core.constraints.Constraint"/>
+
+    <!-- TODO refactor code to remove the following exceptions -->
+    <allow class="org.apache.accumulo.tracer.TraceDump"/>
+    <allow class="org.apache.accumulo.core.trace.DistributedTrace"/>
+    <allow class="org.apache.accumulo.core.util.format.DefaultFormatter"/>
+    <allow class="org.apache.accumulo.core.util.TextUtil"/>
+    <!-- End TODO section -->
+
+    <!-- disallow everything else coming from accumulo -->
+    <disallow pkg="org.apache.accumulo"/>
+</import-control>
diff --git a/pom.xml b/pom.xml
index d4da5f2..037758e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
     <slf4j.version>1.7.21</slf4j.version>
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
-    <eclipseFormatterStyle>build/Eclipse-Accumulo-Codestyle.xml</eclipseFormatterStyle>
+    <eclipseFormatterStyle>contrib/Eclipse-Accumulo-Codestyle.xml</eclipseFormatterStyle>
   </properties>
   <dependencyManagement>
     <dependencies>
@@ -186,14 +186,27 @@
         </executions>
       </plugin>
       <plugin>
-        <!-- This was added to ensure project only uses public API. Run with the following:
-              mvn checkstyle:checkstyle
-         -->
+        <!-- This was added to ensure project only uses public API -->
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>2.17</version>
+        <version>3.0.0</version>
+        <executions>
+          <execution>
+            <id>check-style</id>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+        <dependencies>
+          <dependency>
+            <groupId>com.puppycrawl.tools</groupId>
+            <artifactId>checkstyle</artifactId>
+            <version>8.17</version>
+          </dependency>
+        </dependencies>
         <configuration>
-          <configLocation>build/checkstyle.xml</configLocation>
+          <configLocation>contrib/checkstyle.xml</configLocation>
         </configuration>
       </plugin>
       <plugin>
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java
index dd14bc0..50c385b 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java
@@ -25,12 +25,14 @@ import java.util.Map.Entry;
 import org.apache.accumulo.core.client.mapreduce.InputFormatBase;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.util.PeekingIterator;
 import org.apache.accumulo.core.util.format.DefaultFormatter;
 import org.apache.hadoop.mapreduce.InputSplit;
 import org.apache.hadoop.mapreduce.RecordReader;
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 
+import com.google.common.collect.Iterators;
+import com.google.common.collect.PeekingIterator;
+
 /**
  * An InputFormat that turns the file data ingested with {@link FileDataIngest} into an InputStream
  * using {@link ChunkInputStream}. Mappers used with this InputFormat must close the InputStream.
@@ -45,7 +47,7 @@ public class ChunkInputFormat extends InputFormatBase<List<Entry<Key,Value>>,Inp
       @Override
       public void initialize(InputSplit inSplit, TaskAttemptContext attempt) throws IOException
{
         super.initialize(inSplit, attempt);
-        peekingScannerIterator = new PeekingIterator<>(scannerIterator);
+        peekingScannerIterator = Iterators.peekingIterator(scannerIterator);
         currentK = new ArrayList<>();
         currentV = new ChunkInputStream();
       }
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java
index af521f0..efe6c12 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java
@@ -25,11 +25,12 @@ import java.util.TreeSet;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.PartialKey;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.util.PeekingIterator;
 import org.apache.hadoop.io.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.PeekingIterator;
+
 /**
  * An input stream that reads file data stored in one or more Accumulo values. Used by
  * {@link ChunkInputFormat} to present input streams to a mapper.
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java b/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java
index 3d5d78a..daa6713 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java
@@ -30,7 +30,9 @@ import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.util.PeekingIterator;
+
+import com.google.common.collect.Iterators;
+import com.google.common.collect.PeekingIterator;
 
 /**
  * Retrieves file data based on the hash of the file. Used by the
@@ -56,7 +58,7 @@ public class FileDataQuery {
     scanner.setRange(new Range(hash));
     scanner.setBatchSize(1);
     lastRefs.clear();
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(scanner.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(scanner.iterator());
     if (pi.hasNext()) {
       while (!pi.peek().getKey().getColumnFamily().equals(FileDataIngest.CHUNK_CF)) {
         lastRefs.add(pi.peek());
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java
index 2bff26c..138867b 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java
@@ -40,7 +40,6 @@ import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.security.ColumnVisibility;
-import org.apache.accumulo.core.util.PeekingIterator;
 import org.apache.accumulo.harness.AccumuloClusterHarness;
 import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
 import org.apache.hadoop.conf.Configuration;
@@ -49,6 +48,9 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.Iterators;
+import com.google.common.collect.PeekingIterator;
+
 public class ChunkInputStreamIT extends AccumuloClusterHarness {
 
   @Override
@@ -155,7 +157,7 @@ public class ChunkInputStreamIT extends AccumuloClusterHarness {
     ChunkInputStream cis = new ChunkInputStream();
     byte[] b = new byte[20];
     int read;
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(scan.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(scan.iterator());
 
     cis.setSource(pi);
     assertEquals(read = cis.read(b), 8);
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
index 8096d79..2ff9892 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
@@ -28,13 +28,15 @@ import java.util.Map.Entry;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.KeyValue;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.util.PeekingIterator;
 import org.apache.hadoop.io.Text;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Iterators;
+import com.google.common.collect.PeekingIterator;
+
 public class ChunkInputStreamTest {
   private static final Logger log = LoggerFactory.getLogger(ChunkInputStream.class);
   private List<Entry<Key,Value>> data;
@@ -103,8 +105,7 @@ public class ChunkInputStreamTest {
   @Test
   public void testExceptionOnMultipleSetSourceWithoutClose() throws IOException {
     ChunkInputStream cis = new ChunkInputStream();
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(data.iterator());
-    pi = new PeekingIterator<>(data.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(data.iterator());
     cis.setSource(pi);
     try {
       cis.setSource(pi);
@@ -118,7 +119,7 @@ public class ChunkInputStreamTest {
   @Test
   public void testExceptionOnGetVisBeforeClose() throws IOException {
     ChunkInputStream cis = new ChunkInputStream();
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(data.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(data.iterator());
 
     cis.setSource(pi);
     try {
@@ -136,7 +137,7 @@ public class ChunkInputStreamTest {
     ChunkInputStream cis = new ChunkInputStream();
     byte[] b = new byte[5];
 
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(data.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(data.iterator());
 
     cis.setSource(pi);
     int read;
@@ -188,7 +189,7 @@ public class ChunkInputStreamTest {
     ChunkInputStream cis = new ChunkInputStream();
     byte[] b = new byte[20];
     int read;
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(data.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(data.iterator());
 
     cis.setSource(pi);
     assertEquals(read = cis.read(b), 8);
@@ -247,7 +248,7 @@ public class ChunkInputStreamTest {
     ChunkInputStream cis = new ChunkInputStream();
     byte[] b = new byte[20];
     int read;
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(baddata.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(baddata.iterator());
 
     cis.setSource(pi);
     assumeExceptionOnRead(cis, b);
@@ -293,7 +294,7 @@ public class ChunkInputStreamTest {
 
     assertFalse(pi.hasNext());
 
-    pi = new PeekingIterator<>(baddata.iterator());
+    pi = Iterators.peekingIterator(baddata.iterator());
     cis.setSource(pi);
     assumeExceptionOnClose(cis);
   }
@@ -303,7 +304,7 @@ public class ChunkInputStreamTest {
     ChunkInputStream cis = new ChunkInputStream();
     byte[] b = new byte[20];
     int read;
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(baddata.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(baddata.iterator());
 
     cis.setSource(pi);
     assumeExceptionOnRead(cis, b);
@@ -344,7 +345,7 @@ public class ChunkInputStreamTest {
 
     assertFalse(pi.hasNext());
 
-    pi = new PeekingIterator<>(baddata.iterator());
+    pi = Iterators.peekingIterator(baddata.iterator());
     cis.setSource(pi);
     assumeExceptionOnClose(cis);
   }
@@ -354,7 +355,7 @@ public class ChunkInputStreamTest {
     ChunkInputStream cis = new ChunkInputStream();
     byte[] b = new byte[20];
     int read;
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(multidata.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(multidata.iterator());
 
     b = new byte[20];
 
@@ -381,7 +382,7 @@ public class ChunkInputStreamTest {
   @Test
   public void testSingleByteRead() throws IOException {
     ChunkInputStream cis = new ChunkInputStream();
-    PeekingIterator<Entry<Key,Value>> pi = new PeekingIterator<>(data.iterator());
+    PeekingIterator<Entry<Key,Value>> pi = Iterators.peekingIterator(data.iterator());
 
     cis.setSource(pi);
     assertEquals((byte) 'a', (byte) cis.read());


Mime
View raw message