Skip to content

Commit c890fef

Browse files
committed
remove dependencies from code-assert-core
1 parent 071ec55 commit c890fef

File tree

10 files changed

+445
-44
lines changed

10 files changed

+445
-44
lines changed

README.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ If it does so, these standard checks will be executed:
322322
[//]: # (codeTest)
323323
```java
324324
//extend CodeAssertTest if you still use JUnit 4
325-
public class CodeTest extends CodeAssertJunit5Test {
325+
public class CodeTest extends CodeAssertCoreJunit5Test {
326326

327327
private static final AnalyzerConfig CONFIG = AnalyzerConfig.maven().main();
328328

@@ -340,27 +340,6 @@ public class CodeTest extends CodeAssertJunit5Test {
340340
final DependencyRules rules = denyAll().withExternals("java.*").withRelativeRules(new MyProject());
341341
return new DependencyAnalyzer(CONFIG).rules(rules).analyze();
342342
}
343-
344-
@Override
345-
protected FindBugsResult analyzeFindBugs() {
346-
final BugCollector bugCollector = new BugCollector().just(
347-
In.classes("*Exception").ignore("SE_BAD_FIELD"));
348-
return new FindBugsAnalyzer(CONFIG, bugCollector).analyze();
349-
}
350-
351-
@Override
352-
protected CheckstyleResult analyzeCheckstyle() {
353-
final StyleEventCollector bugCollector = new StyleEventCollector().just(
354-
In.everywhere().ignore("javadoc.missing"));
355-
return new CheckstyleAnalyzer(CONFIG, StyleChecks.google(), bugCollector).analyze();
356-
}
357-
358-
@Override
359-
protected PmdResult analyzePmd() {
360-
final PmdViolationCollector collector = new PmdViolationCollector().just(
361-
In.everywhere().ignore("MethodArgumentCouldBeFinal"));
362-
return new PmdAnalyzer(CONFIG, collector).withRulesets(basic(), braces()).analyze();
363-
}
364343
}
365344
```
366345
[//]: # (end)

code-assert-core/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@
8888
<artifactId>hamcrest-core</artifactId>
8989
<version>1.3</version>
9090
</dependency>
91-
<dependency>
92-
<groupId>commons-io</groupId>
93-
<artifactId>commons-io</artifactId>
94-
<version>2.7</version>
95-
</dependency>
9691

9792
<dependency>
9893
<groupId>junit</groupId>
@@ -110,15 +105,6 @@
110105
<groupId>org.slf4j</groupId>
111106
<artifactId>slf4j-api</artifactId>
112107
</dependency>
113-
<dependency>
114-
<groupId>org.slf4j</groupId>
115-
<artifactId>jcl-over-slf4j</artifactId>
116-
</dependency>
117-
<dependency>
118-
<groupId>org.slf4j</groupId>
119-
<artifactId>jul-to-slf4j</artifactId>
120-
</dependency>
121-
122108
<dependency>
123109
<groupId>org.slf4j</groupId>
124110
<artifactId>slf4j-simple</artifactId>

code-assert-core/src/main/java/guru/nidi/codeassert/AnalyzerResult.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,9 @@
1515
*/
1616
package guru.nidi.codeassert;
1717

18-
import org.slf4j.bridge.SLF4JBridgeHandler;
19-
2018
import java.util.List;
2119

2220
public class AnalyzerResult<T> {
23-
static {
24-
SLF4JBridgeHandler.removeHandlersForRootLogger();
25-
SLF4JBridgeHandler.install();
26-
}
27-
2821
private final Analyzer<T> analyzer;
2922
private final T findings;
3023
private final List<String> unusedActions;

code-assert-core/src/main/java/guru/nidi/codeassert/model/ClassFileParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package guru.nidi.codeassert.model;
1717

18-
import org.apache.commons.io.input.CountingInputStream;
18+
import guru.nidi.codeassert.util.CountingInputStream;
1919

2020
import java.io.*;
2121
import java.util.ArrayList;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package guru.nidi.codeassert.util;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
22+
/**
23+
* A decorating input stream that counts the number of bytes that have passed
24+
* through the stream so far.
25+
* <p>
26+
* A typical use case would be during debugging, to ensure that data is being
27+
* read as expected.
28+
*/
29+
public class CountingInputStream extends ProxyInputStream {
30+
31+
/**
32+
* The count of bytes that have passed.
33+
*/
34+
private long count;
35+
36+
/**
37+
* Constructs a new CountingInputStream.
38+
*
39+
* @param in the InputStream to delegate to
40+
*/
41+
public CountingInputStream(final InputStream in) {
42+
super(in);
43+
}
44+
45+
//-----------------------------------------------------------------------
46+
47+
/**
48+
* Skips the stream over the specified number of bytes, adding the skipped
49+
* amount to the count.
50+
*
51+
* @param length the number of bytes to skip
52+
* @return the actual number of bytes skipped
53+
* @throws IOException if an I/O error occurs
54+
* @see java.io.InputStream#skip(long)
55+
*/
56+
@Override
57+
public synchronized long skip(final long length) throws IOException {
58+
final long skip = super.skip(length);
59+
this.count += skip;
60+
return skip;
61+
}
62+
63+
/**
64+
* Adds the number of read bytes to the count.
65+
*
66+
* @param n number of bytes read, or -1 if no more bytes are available
67+
* @since 2.0
68+
*/
69+
@Override
70+
protected synchronized void afterRead(final int n) {
71+
if (n != EOF) {
72+
this.count += n;
73+
}
74+
}
75+
76+
//-----------------------------------------------------------------------
77+
78+
/**
79+
* The number of bytes that have passed through this stream.
80+
* <p>
81+
* NOTE: From v1.3 this method throws an ArithmeticException if the
82+
* count is greater than can be expressed by an <code>int</code>.
83+
* See {@link #getByteCount()} for a method using a <code>long</code>.
84+
*
85+
* @return the number of bytes accumulated
86+
* @throws ArithmeticException if the byte count is too large
87+
*/
88+
public int getCount() {
89+
final long result = getByteCount();
90+
if (result > Integer.MAX_VALUE) {
91+
throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
92+
}
93+
return (int) result;
94+
}
95+
96+
/**
97+
* Set the byte count back to 0.
98+
* <p>
99+
* NOTE: From v1.3 this method throws an ArithmeticException if the
100+
* count is greater than can be expressed by an <code>int</code>.
101+
* See {@link #resetByteCount()} for a method using a <code>long</code>.
102+
*
103+
* @return the count previous to resetting
104+
* @throws ArithmeticException if the byte count is too large
105+
*/
106+
public int resetCount() {
107+
final long result = resetByteCount();
108+
if (result > Integer.MAX_VALUE) {
109+
throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int");
110+
}
111+
return (int) result;
112+
}
113+
114+
/**
115+
* The number of bytes that have passed through this stream.
116+
* <p>
117+
* NOTE: This method is an alternative for <code>getCount()</code>
118+
* and was added because that method returns an integer which will
119+
* result in incorrect count for files over 2GB.
120+
*
121+
* @return the number of bytes accumulated
122+
* @since 1.3
123+
*/
124+
public synchronized long getByteCount() {
125+
return this.count;
126+
}
127+
128+
/**
129+
* Set the byte count back to 0.
130+
* <p>
131+
* NOTE: This method is an alternative for <code>resetCount()</code>
132+
* and was added because that method returns an integer which will
133+
* result in incorrect count for files over 2GB.
134+
*
135+
* @return the count previous to resetting
136+
* @since 1.3
137+
*/
138+
public synchronized long resetByteCount() {
139+
final long tmp = this.count;
140+
this.count = 0;
141+
return tmp;
142+
}
143+
144+
}

0 commit comments

Comments
 (0)