├── .gitignore
├── .github
├── FUNDING.yml
└── workflows
│ └── codeql-analysis.yml
├── code-assert-core
├── images
│ └── packages.png
└── src
│ ├── test
│ ├── resources
│ │ ├── test.jar
│ │ ├── test.zip
│ │ ├── example_class1.bin
│ │ └── example_class2.bin
│ └── java
│ │ ├── guru
│ │ └── nidi
│ │ │ └── codeassert
│ │ │ ├── dependency
│ │ │ ├── a
│ │ │ │ ├── A2.java
│ │ │ │ ├── b
│ │ │ │ │ └── Ab1.java
│ │ │ │ ├── A1.java
│ │ │ │ └── a
│ │ │ │ │ └── Aa1.java
│ │ │ ├── b
│ │ │ │ ├── B2.java
│ │ │ │ ├── B1.java
│ │ │ │ ├── a
│ │ │ │ │ ├── Ba1.java
│ │ │ │ │ └── Ba2.java
│ │ │ │ └── b
│ │ │ │ │ └── Bb1.java
│ │ │ └── c
│ │ │ │ ├── b
│ │ │ │ └── Cb1.java
│ │ │ │ ├── C2.java
│ │ │ │ ├── C1.java
│ │ │ │ └── a
│ │ │ │ └── Ca1.java
│ │ │ ├── model
│ │ │ ├── p4
│ │ │ │ ├── p2
│ │ │ │ │ └── Type2.java
│ │ │ │ ├── p3
│ │ │ │ │ └── Type3.java
│ │ │ │ ├── p4
│ │ │ │ │ └── Type4.java
│ │ │ │ ├── p5
│ │ │ │ │ └── Type5.java
│ │ │ │ ├── p10
│ │ │ │ │ └── Type10.java
│ │ │ │ ├── p6
│ │ │ │ │ └── Type6.java
│ │ │ │ ├── p7
│ │ │ │ │ └── Type7.java
│ │ │ │ ├── p8
│ │ │ │ │ └── Type8.java
│ │ │ │ ├── p9
│ │ │ │ │ └── Type9.java
│ │ │ │ ├── p1
│ │ │ │ │ └── Type1.java
│ │ │ │ ├── SubGenericParameters.java
│ │ │ │ └── GenericParameters.java
│ │ │ ├── p2
│ │ │ │ └── ExampleEnum.java
│ │ │ ├── p3
│ │ │ │ └── ExampleSecondEnum.java
│ │ │ ├── p1
│ │ │ │ └── ExampleInnerAnnotation.java
│ │ │ ├── p5
│ │ │ │ ├── ClassRetentionAnnotation.java
│ │ │ │ ├── SourceRetentionAnnotation.java
│ │ │ │ ├── package-info.java
│ │ │ │ └── Annotations.java
│ │ │ ├── ExampleInterface.java
│ │ │ ├── ExampleAnnotation.java
│ │ │ ├── ExampleAbstractClass.java
│ │ │ ├── AnalyzerTest.java
│ │ │ ├── Path.java
│ │ │ └── ExampleConcreteClass.java
│ │ │ ├── junit
│ │ │ ├── EmptyCodeAssertCoreTest.java
│ │ │ └── EmptyCodeAssertCoreJunit5Test.java
│ │ │ ├── snippets
│ │ │ ├── CodeTest.java
│ │ │ ├── CodeCoverage.java
│ │ │ └── DependencyTest.java
│ │ │ └── util
│ │ │ └── ListUtilsTest.java
│ │ └── CodeCoverage.java
│ └── main
│ └── java
│ └── guru
│ └── nidi
│ └── codeassert
│ ├── Analyzer.java
│ ├── jacoco
│ ├── CoverageType.java
│ ├── JacocoResult.java
│ ├── Coverages.java
│ └── CoverageCollector.java
│ ├── model
│ ├── UsingElementMatcher.java
│ ├── UsingElement.java
│ ├── ModelBuilder.java
│ ├── AttributeInfo.java
│ ├── PublicMemberInInternalTypeMatcher.java
│ └── Scope.java
│ ├── config
│ ├── Action.java
│ ├── NamedLocation.java
│ ├── UsageCounter.java
│ ├── ValuedLocation.java
│ ├── Ignore.java
│ ├── Language.java
│ ├── CollectorConfig.java
│ ├── For.java
│ ├── ActionResult.java
│ └── CollectorTemplate.java
│ ├── dependency
│ ├── DependencyEntry.java
│ ├── RuleAccessor.java
│ ├── DependencyResult.java
│ ├── AmbiguousRuleException.java
│ ├── Usage.java
│ ├── MatcherUtils.java
│ ├── CodeElement.java
│ └── DependencyCollector.java
│ ├── junit
│ ├── CodeAssertTestType.java
│ ├── UnusedActionsMatcher.java
│ ├── CodeAssertCoreTestBase.java
│ ├── CodeAssertCoreTest.java
│ ├── CodeAssertCoreJunit5Test.java
│ └── CodeAssertCoreMatchers.java
│ ├── AnalyzerException.java
│ ├── util
│ ├── ResultMatcher.java
│ ├── CountSet.java
│ └── ListUtils.java
│ ├── io
│ └── Visualized.java
│ └── AnalyzerResult.java
├── code-assert-gui
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── public
│ │ │ │ └── index.html
│ │ └── java
│ │ │ └── guru
│ │ │ └── nidi
│ │ │ └── codeassert
│ │ │ └── gui
│ │ │ ├── AppController.java
│ │ │ ├── Application.java
│ │ │ ├── CodePackageSerializer.java
│ │ │ └── CodeClassSerializer.java
│ └── test
│ │ └── resources
│ │ └── logback-test.xml
└── pom.xml
├── .travis.yml
├── code-assert
└── src
│ ├── test
│ ├── java
│ │ ├── guru
│ │ │ └── nidi
│ │ │ │ └── codeassert
│ │ │ │ ├── Bugs2.java
│ │ │ │ ├── Bugs.java
│ │ │ │ ├── snippets
│ │ │ │ ├── KtlintTest.java
│ │ │ │ ├── DetektTest.java
│ │ │ │ ├── CodeCoverage.java
│ │ │ │ ├── CheckstyleTest.java
│ │ │ │ ├── FindBugsTest.java
│ │ │ │ ├── ReuseTest.java
│ │ │ │ └── DependencyTest.java
│ │ │ │ ├── detekt
│ │ │ │ └── DetektAnalyzerTest.java
│ │ │ │ └── ktlint
│ │ │ │ └── KtlintAnalyzerTest.java
│ │ └── CodeCoverage.java
│ └── kotlin
│ │ └── guru
│ │ └── nidi
│ │ └── codeassert
│ │ └── Linker.kt
│ └── main
│ └── java
│ └── guru
│ └── nidi
│ └── codeassert
│ ├── pmd
│ ├── PropertyField.java
│ ├── JavaUtilLoggerConfigurer.java
│ ├── CpdResult.java
│ ├── PmdResult.java
│ ├── PmdMatcher.java
│ ├── CpdMatcher.java
│ ├── CpdMatchCollector.java
│ ├── PmdUtils.java
│ └── PmdRuleset.java
│ ├── ktlint
│ ├── LocatedLintError.java
│ ├── KtlintResult.java
│ ├── KtlintMatcher.java
│ └── KtlintCollector.java
│ ├── detekt
│ ├── DetektResult.java
│ ├── TypedDetektFinding.java
│ ├── DetektMatcher.java
│ └── DetektCollector.java
│ ├── findbugs
│ ├── FindBugsResult.java
│ └── FindBugsConfigs.java
│ ├── checkstyle
│ ├── CheckstyleResult.java
│ ├── CheckstyleMatcher.java
│ └── CheckstyleConfigs.java
│ └── junit
│ ├── kotlin
│ └── KotlinCodeAssertMatchers.java
│ └── CodeAssertTestBase.java
├── owasp-suppression.xml
├── JDepend-LICENSE
├── pom.xml
└── code-assert-maven-plugin
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | target/
3 | *.iml
4 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [nidi3]
4 |
--------------------------------------------------------------------------------
/code-assert-core/images/packages.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nidi3/code-assert/HEAD/code-assert-core/images/packages.png
--------------------------------------------------------------------------------
/code-assert-core/src/test/resources/test.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nidi3/code-assert/HEAD/code-assert-core/src/test/resources/test.jar
--------------------------------------------------------------------------------
/code-assert-core/src/test/resources/test.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nidi3/code-assert/HEAD/code-assert-core/src/test/resources/test.zip
--------------------------------------------------------------------------------
/code-assert-core/src/test/resources/example_class1.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nidi3/code-assert/HEAD/code-assert-core/src/test/resources/example_class1.bin
--------------------------------------------------------------------------------
/code-assert-core/src/test/resources/example_class2.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nidi3/code-assert/HEAD/code-assert-core/src/test/resources/example_class2.bin
--------------------------------------------------------------------------------
/code-assert-gui/src/main/resources/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Dependencies
6 |
7 |
8 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: bash
2 | dist: xenial
3 | os:
4 | - windows
5 | - linux
6 |
7 | env:
8 | - JDK="adopt@1.8.0-242"
9 |
10 | cache:
11 | directories:
12 | - $HOME/.m2
13 |
14 | before_install:
15 | - curl "https://raw.githubusercontent.com/nidi3/Mavis-CI/master/mavis.sh" --output mavis.sh
16 | - source mavis.sh
17 | - install_jdk
18 | - install_maven
19 |
20 | before_script:
21 | before_script
22 |
23 | script:
24 | script
25 |
26 | after_success:
27 | - bash <(curl -s https://codecov.io/bash)
28 |
--------------------------------------------------------------------------------
/code-assert-gui/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/a/A2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.a;
17 |
18 | public class A2 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/b/B2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.b;
17 |
18 | public class B2 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/a/b/Ab1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.a.b;
17 |
18 | public class Ab1 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/c/b/Cb1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.c.b;
17 |
18 | public class Cb1 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p2/Type2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p2;
17 |
18 | public class Type2 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p3/Type3.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p3;
17 |
18 | public class Type3 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p4/Type4.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p4;
17 |
18 | public class Type4 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p5/Type5.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p5;
17 |
18 | public class Type5 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p10/Type10.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p10;
17 |
18 | public class Type10 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p6/Type6.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p6;
17 |
18 | public interface Type6 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p7/Type7.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p7;
17 |
18 | public interface Type7 {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p8/Type8.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p8;
17 |
18 | public class Type8 extends Exception {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p9/Type9.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p9;
17 |
18 | public class Type9 extends Exception {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/Analyzer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert;
17 |
18 | public interface Analyzer {
19 | AnalyzerResult analyze();
20 | }
21 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p2/ExampleEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p2;
17 |
18 | public enum ExampleEnum {
19 | E1,
20 | E2
21 | }
22 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/junit/EmptyCodeAssertCoreTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | class EmptyCodeAssertCoreTest extends CodeAssertCoreTest {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/p1/Type1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4.p1;
17 |
18 | public class Type1 {
19 | public class Type1Sub {
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p3/ExampleSecondEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p3;
17 |
18 | public enum ExampleSecondEnum {
19 | NO_DEPENDENCIES_ON_ME
20 | }
21 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/Bugs2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert;
17 |
18 | public class Bugs2 {
19 | private Bugs2() {
20 | Integer a = new Integer(44);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/jacoco/CoverageType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.jacoco;
17 |
18 | public enum CoverageType {
19 | INSTRUCTION, BRANCH, LINE, COMPLEXITY, METHOD
20 | }
21 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/junit/EmptyCodeAssertCoreJunit5Test.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | class EmptyCodeAssertCoreJunit5Test extends CodeAssertCoreJunit5Test {
19 | }
20 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/model/UsingElementMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | public interface UsingElementMatcher {
19 | boolean matches(UsingElement> elem);
20 | }
21 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/a/A1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.a;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.c.C1;
20 |
21 | public class A1 {
22 | C1 c1;
23 | }
24 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/c/C2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.c;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.b.B1;
20 |
21 | public class C2 {
22 | B1 b1;
23 | }
24 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p1/ExampleInnerAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p1;
17 |
18 | public @interface ExampleInnerAnnotation {
19 | Class>[] value() default {};
20 | }
21 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/a/a/Aa1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.a.a;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.b.a.Ba1;
20 |
21 | public class Aa1 {
22 | Ba1 ba1;
23 | }
24 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/SubGenericParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4;
17 |
18 | import guru.nidi.codeassert.model.p4.p1.Type1;
19 |
20 | class SubGenericParameters extends GenericParameters {
21 | }
22 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/c/C1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.c;
17 |
18 | import guru.nidi.codeassert.dependency.a.A1;
19 | import guru.nidi.codeassert.dependency.b.B1;
20 |
21 | public class C1 {
22 | A1 a1;
23 | B1 b1;
24 | }
25 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/b/B1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.b;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.a.A1;
20 | import guru.nidi.codeassert.dependency.c.C1;
21 |
22 | public class B1 {
23 | A1 a1;
24 | C1 c1;
25 | }
26 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/c/a/Ca1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.c.a;
17 |
18 | import guru.nidi.codeassert.dependency.a.a.Aa1;
19 | import guru.nidi.codeassert.dependency.b.a.Ba1;
20 |
21 | public class Ca1 {
22 | Aa1 aa1;
23 | Ba1 ba1;
24 | }
25 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/b/a/Ba1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.b.a;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.a.a.Aa1;
20 | import guru.nidi.codeassert.dependency.a.b.Ab1;
21 |
22 | public class Ba1 {
23 | Aa1 aa1;
24 | Ab1 ab1;
25 | }
26 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/b/a/Ba2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.b.a;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.c.a.Ca1;
20 | import guru.nidi.codeassert.dependency.c.b.Cb1;
21 |
22 | public class Ba2 {
23 | Ca1 ca1;
24 | Cb1 cb1;
25 | }
26 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/dependency/b/b/Bb1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency.b.b;
17 |
18 |
19 | import guru.nidi.codeassert.dependency.c.a.Ca1;
20 | import guru.nidi.codeassert.dependency.c.b.Cb1;
21 |
22 | public class Bb1 {
23 | Ca1 ca1;
24 | Cb1 cb1;
25 | }
26 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/CodeCoverage.java:
--------------------------------------------------------------------------------
1 | import guru.nidi.codeassert.config.For;
2 | import guru.nidi.codeassert.jacoco.CoverageCollector;
3 | import guru.nidi.codeassert.jacoco.JacocoAnalyzer;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static guru.nidi.codeassert.jacoco.CoverageType.*;
7 | import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.hasEnoughCoverage;
8 | import static org.hamcrest.MatcherAssert.assertThat;
9 |
10 | public class CodeCoverage {
11 | @Test
12 | void coverage() {
13 | JacocoAnalyzer analyzer = new JacocoAnalyzer(new CoverageCollector(BRANCH, LINE, METHOD).just(
14 | For.allPackages().setMinima(75, 80, 80),
15 | For.thePackage("*.detekt").setMinima(35, 80, 65),
16 | For.thePackage("*.findbugs").setMinima(70, 80, 80),
17 | For.thePackage("*.junit").setMinima(35, 55, 50)
18 | ));
19 | assertThat(analyzer.analyze(), hasEnoughCoverage());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/PropertyField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import java.lang.annotation.*;
19 |
20 | @Retention(RetentionPolicy.RUNTIME)
21 | @Target(ElementType.FIELD)
22 | public @interface PropertyField {
23 | String rule();
24 |
25 | String property();
26 | }
27 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p5/ClassRetentionAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p5;
17 |
18 |
19 | import java.lang.annotation.Retention;
20 |
21 | import static java.lang.annotation.RetentionPolicy.CLASS;
22 |
23 | @Retention(CLASS)
24 | public @interface ClassRetentionAnnotation {
25 | }
26 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p5/SourceRetentionAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p5;
17 |
18 |
19 | import java.lang.annotation.Retention;
20 |
21 | import static java.lang.annotation.RetentionPolicy.SOURCE;
22 |
23 | @Retention(SOURCE)
24 | public @interface SourceRetentionAnnotation {
25 | }
26 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/Action.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | /**
19 | * Actions are created using the In and For classes.
20 | *
21 | * @param the type of issues this action works on.
22 | * @see In
23 | * @see For
24 | */
25 | public interface Action {
26 | ActionResult accept(T issue);
27 | }
28 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/dependency/DependencyEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency;
17 |
18 | public class DependencyEntry {
19 | final String name;
20 | final String className;
21 |
22 | DependencyEntry(String name, String className) {
23 | this.name = name;
24 | this.className = className;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/junit/CodeAssertTestType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | public enum CodeAssertTestType {
19 | DEPENDENCIES, CIRCULAR_DEPENDENCIES, STRUCTURE,
20 | FIND_BUGS, FIND_BUGS_UNUSED_ACTIONS,
21 | PMD, PMD_UNUSED_ACTIONS,
22 | CPD, CPD_UNUSED_ACTIONS,
23 | CHECKSTYLE, CHECKSTYLE_UNUSED_ACTIONS
24 | }
25 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/AnalyzerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert;
17 |
18 | public class AnalyzerException extends RuntimeException {
19 | public AnalyzerException(String message) {
20 | super(message);
21 | }
22 |
23 | public AnalyzerException(String message, Throwable cause) {
24 | super(message, cause);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p5/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | @SourceRetentionAnnotation
17 | @ClassRetentionAnnotation
18 | @ExampleAnnotation(c3 = @ExampleInnerAnnotation, c4 = ExampleEnum.E1)
19 | package guru.nidi.codeassert.model.p5;
20 |
21 | import guru.nidi.codeassert.model.ExampleAnnotation;
22 | import guru.nidi.codeassert.model.p1.ExampleInnerAnnotation;
23 | import guru.nidi.codeassert.model.p2.ExampleEnum;
24 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/CodeCoverage.java:
--------------------------------------------------------------------------------
1 | import guru.nidi.codeassert.config.For;
2 | import guru.nidi.codeassert.jacoco.CoverageCollector;
3 | import guru.nidi.codeassert.jacoco.JacocoAnalyzer;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static guru.nidi.codeassert.jacoco.CoverageType.*;
7 | import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.hasEnoughCoverage;
8 | import static org.hamcrest.MatcherAssert.assertThat;
9 |
10 | public class CodeCoverage {
11 | @Test
12 | void coverage() {
13 | JacocoAnalyzer analyzer = new JacocoAnalyzer(new CoverageCollector(BRANCH, LINE, METHOD).just(
14 | For.allPackages().setMinima(75, 75, 75),
15 | For.thePackage("*.codeassert").setMinima(75, 75, 65),
16 | For.thePackage("*.config").setMinima(70, 75, 70),
17 | For.thePackage("*.io").setMinima(0, 0, 0),
18 | For.thePackage("*.junit").setMinima(40, 50, 55),
19 | For.thePackage("*.util").setMinima(50, 45, 55)
20 | ));
21 | assertThat(analyzer.analyze(), hasEnoughCoverage());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/JavaUtilLoggerConfigurer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import org.slf4j.bridge.SLF4JBridgeHandler;
19 |
20 | final class JavaUtilLoggerConfigurer {
21 | static {
22 | SLF4JBridgeHandler.removeHandlersForRootLogger();
23 | SLF4JBridgeHandler.install();
24 | }
25 |
26 | private JavaUtilLoggerConfigurer() {
27 | }
28 |
29 | static void init() {
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/code-assert-gui/src/main/java/guru/nidi/codeassert/gui/AppController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.gui;
17 |
18 | import guru.nidi.codeassert.model.Model;
19 | import org.springframework.web.bind.annotation.*;
20 |
21 | import java.io.File;
22 |
23 | @RestController
24 | public class AppController {
25 |
26 | @GetMapping("model")
27 | public Model model(@RequestParam String jarfile) {
28 | return Model.from(new File(jarfile)).read();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p5/Annotations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p5;
17 |
18 | import guru.nidi.codeassert.model.ExampleAnnotation;
19 | import guru.nidi.codeassert.model.p1.ExampleInnerAnnotation;
20 | import guru.nidi.codeassert.model.p2.ExampleEnum;
21 |
22 | @ExampleAnnotation(c3 = @ExampleInnerAnnotation, c4 = ExampleEnum.E1)
23 | @ClassRetentionAnnotation
24 | @SourceRetentionAnnotation
25 | public class Annotations {
26 | }
27 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/util/ResultMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.util;
17 |
18 | import guru.nidi.codeassert.AnalyzerResult;
19 | import org.hamcrest.TypeSafeMatcher;
20 |
21 | import java.util.List;
22 |
23 | public abstract class ResultMatcher>, S> extends TypeSafeMatcher {
24 | @Override
25 | protected boolean matchesSafely(T item) {
26 | return item.findings().isEmpty();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/dependency/RuleAccessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency;
17 |
18 | import guru.nidi.codeassert.config.LocationMatcher;
19 |
20 | import java.util.Set;
21 |
22 | interface RuleAccessor {
23 | RuleAccessor MAY_BE_USED = rule -> rule.usedBy.may;
24 | RuleAccessor MUST_BE_USED = rule -> rule.usedBy.must;
25 | RuleAccessor MUST_NOT_BE_USED = rule -> rule.usedBy.mustNot;
26 |
27 | Set access(DependencyRule rule);
28 | }
29 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/CpdResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import guru.nidi.codeassert.Analyzer;
19 | import guru.nidi.codeassert.AnalyzerResult;
20 | import net.sourceforge.pmd.cpd.Match;
21 |
22 | import java.util.List;
23 |
24 | public class CpdResult extends AnalyzerResult> {
25 | CpdResult(Analyzer> analyzer, List findings, List unusedActions) {
26 | super(analyzer, findings, unusedActions);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/ktlint/LocatedLintError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.ktlint;
17 |
18 | import java.io.File;
19 |
20 | public class LocatedLintError {
21 | final File file;
22 | final int line;
23 | final String ruleId;
24 | final String detail;
25 |
26 | LocatedLintError(File file, int line, String ruleId, String detail) {
27 | this.file = file;
28 | this.line = line;
29 | this.ruleId = ruleId;
30 | this.detail = detail;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/Bugs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert;
17 |
18 | public class Bugs {
19 | public void bugs() {
20 | Object a = new Integer(5);
21 | }
22 |
23 | public void more() {
24 | Object a = new Integer(5);
25 | }
26 |
27 | public static class InnerBugs {
28 | private InnerBugs() {
29 | //not seen by PMD?
30 | }
31 |
32 | public void bugs() {
33 | Object a = new Integer(5);
34 | }
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/dependency/DependencyResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency;
17 |
18 | import guru.nidi.codeassert.Analyzer;
19 | import guru.nidi.codeassert.AnalyzerResult;
20 |
21 | import java.util.List;
22 |
23 | public class DependencyResult extends AnalyzerResult {
24 | DependencyResult(Analyzer analyzer,
25 | Dependencies findings, List unusedActions) {
26 | super(analyzer, findings, unusedActions);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/ktlint/KtlintResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.ktlint;
17 |
18 | import guru.nidi.codeassert.Analyzer;
19 | import guru.nidi.codeassert.AnalyzerResult;
20 |
21 | import java.util.List;
22 |
23 | public class KtlintResult extends AnalyzerResult> {
24 | KtlintResult(Analyzer> analyzer,
25 | List findings, List unusedActions) {
26 | super(analyzer, findings, unusedActions);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/PmdResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import guru.nidi.codeassert.Analyzer;
19 | import guru.nidi.codeassert.AnalyzerResult;
20 | import net.sourceforge.pmd.RuleViolation;
21 |
22 | import java.util.List;
23 |
24 | public class PmdResult extends AnalyzerResult> {
25 | PmdResult(Analyzer> analyzer, List findings, List unusedActions) {
26 | super(analyzer, findings, unusedActions);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/ExampleInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import java.math.BigDecimal;
19 |
20 | /**
21 | * @author Mike Clark
22 | * @author Clarkware Consulting, Inc.
23 | */
24 |
25 | public interface ExampleInterface {
26 |
27 | void a();
28 |
29 | java.util.Vector b(String[] s, java.text.NumberFormat nf);
30 |
31 | void c(BigDecimal bd, byte[] b) throws java.rmi.RemoteException;
32 |
33 | java.io.File[] d() throws java.io.IOException;
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/detekt/DetektResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.detekt;
17 |
18 | import guru.nidi.codeassert.Analyzer;
19 | import guru.nidi.codeassert.AnalyzerResult;
20 |
21 | import java.util.List;
22 |
23 | public class DetektResult extends AnalyzerResult> {
24 | DetektResult(Analyzer> analyzer,
25 | List findings, List unusedActions) {
26 | super(analyzer, findings, unusedActions);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/findbugs/FindBugsResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.findbugs;
17 |
18 | import edu.umd.cs.findbugs.BugInstance;
19 | import guru.nidi.codeassert.Analyzer;
20 | import guru.nidi.codeassert.AnalyzerResult;
21 |
22 | import java.util.List;
23 |
24 | public class FindBugsResult extends AnalyzerResult> {
25 | FindBugsResult(Analyzer> analyzer,
26 | List findings, List unusedActions) {
27 | super(analyzer, findings, unusedActions);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/checkstyle/CheckstyleResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.checkstyle;
17 |
18 | import com.puppycrawl.tools.checkstyle.api.AuditEvent;
19 | import guru.nidi.codeassert.Analyzer;
20 | import guru.nidi.codeassert.AnalyzerResult;
21 |
22 | import java.util.List;
23 |
24 | public class CheckstyleResult extends AnalyzerResult> {
25 | CheckstyleResult(Analyzer> analyzer,
26 | List findings, List unusedActions) {
27 | super(analyzer, findings, unusedActions);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/NamedLocation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | public class NamedLocation {
19 | final String name;
20 | final Language language;
21 | final String className;
22 | final String method;
23 | final boolean strictNameMatch;
24 |
25 | public NamedLocation(String name, Language language, String className, String method, boolean strictNameMatch) {
26 | this.name = name;
27 | this.language = language;
28 | this.className = className;
29 | this.method = method;
30 | this.strictNameMatch = strictNameMatch;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/util/CountSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.util;
17 |
18 | import java.util.*;
19 |
20 | public class CountSet {
21 | private final Map map = new HashMap<>();
22 |
23 | public void add(T elem) {
24 | final Integer c = map.get(elem);
25 | map.put(elem, (c == null ? 0 : c) + 1);
26 | }
27 |
28 | public boolean contains(T elem) {
29 | return map.containsKey(elem);
30 | }
31 |
32 | public Map asMap() {
33 | return map;
34 | }
35 |
36 | public Set asSet() {
37 | return map.keySet();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/owasp-suppression.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CVE-2019-9658
5 | CVE-2019-10782
6 | cpe:2.3:a:checkstyle:checkstyle:6.19
7 |
8 |
9 | CVE-2019-10086
10 | cpe:2.3:a:apache:commons_beanutils:1.9.2
11 |
12 |
13 | CVE-2018-10237
14 | CVE-2020-8908
15 | cpe:2.3:a:google:guava:19.0
16 |
17 |
18 | Directory traversal in org.codehaus.plexus.util.Expand
19 | Possible XML Injection
20 | cpe:2.3:a:plexus-utils_project:plexus-utils:3.0.20
21 |
22 |
23 | CVE-2019-7722
24 | cpe:2.3:a:pmd_project:pmd:5.8.1
25 |
26 |
27 | CVE-2020-10683
28 | cpe:/a:dom4j_project:dom4j
29 |
30 |
31 | CVE-2020-15250
32 | cpe:2.3:a:junit:junit:4.13.1
33 |
34 |
35 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/UsageCounter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 | public class UsageCounter {
22 | private final Map, Integer> usage = new HashMap<>();
23 |
24 | public int getCount(Action> action) {
25 | final Integer c = usage.get(action);
26 | return c == null ? 0 : c;
27 | }
28 |
29 | public boolean accept(ActionResult accept) {
30 | final Integer count = usage.get(accept.action);
31 | usage.put(accept.action, (count == null ? 0 : count) + 1);
32 | return accept.accept;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/io/Visualized.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.io;
17 |
18 | import guru.nidi.graphviz.engine.Format;
19 | import guru.nidi.graphviz.engine.Graphviz;
20 |
21 | import java.awt.image.BufferedImage;
22 | import java.io.File;
23 | import java.io.IOException;
24 |
25 | public class Visualized {
26 | private final Graphviz graphviz;
27 |
28 | Visualized(Graphviz graphviz) {
29 | this.graphviz = graphviz;
30 | }
31 |
32 | public void toFile(File target) throws IOException {
33 | graphviz.render(Format.PNG).toFile(target);
34 | }
35 |
36 | public BufferedImage asImage() {
37 | return graphviz.render(Format.PNG).toImage();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/junit/kotlin/KotlinCodeAssertMatchers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit.kotlin;
17 |
18 | import guru.nidi.codeassert.detekt.DetektMatcher;
19 | import guru.nidi.codeassert.detekt.DetektResult;
20 | import guru.nidi.codeassert.ktlint.KtlintMatcher;
21 | import guru.nidi.codeassert.ktlint.KtlintResult;
22 | import org.hamcrest.Matcher;
23 |
24 | public final class KotlinCodeAssertMatchers {
25 | private KotlinCodeAssertMatchers() {
26 | }
27 |
28 | public static Matcher hasNoKtlintIssues() {
29 | return new KtlintMatcher();
30 | }
31 |
32 | public static Matcher hasNoDetektIssues() {
33 | return new DetektMatcher();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/jacoco/JacocoResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.jacoco;
17 |
18 | import guru.nidi.codeassert.Analyzer;
19 | import guru.nidi.codeassert.AnalyzerResult;
20 | import guru.nidi.codeassert.config.ValuedLocation;
21 |
22 | import java.util.List;
23 |
24 | public class JacocoResult extends AnalyzerResult> {
25 | private final CoverageType[] types;
26 |
27 | JacocoResult(Analyzer> analyzer, List findings,
28 | List unusedActions, CoverageType[] types) {
29 | super(analyzer, findings, unusedActions);
30 | this.types = types;
31 | }
32 |
33 | public CoverageType[] getTypes() {
34 | return types;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/AnalyzerResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert;
17 |
18 | import java.util.List;
19 |
20 | public class AnalyzerResult {
21 | private final Analyzer analyzer;
22 | private final T findings;
23 | private final List unusedActions;
24 |
25 | public AnalyzerResult(Analyzer analyzer, T findings, List unusedActions) {
26 | this.analyzer = analyzer;
27 | this.findings = findings;
28 | this.unusedActions = unusedActions;
29 | }
30 |
31 | public Analyzer analyzer() {
32 | return analyzer;
33 | }
34 |
35 | public T findings() {
36 | return findings;
37 | }
38 |
39 | public List unusedActions() {
40 | return unusedActions;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/ExampleAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 |
19 | import guru.nidi.codeassert.model.p1.ExampleInnerAnnotation;
20 | import guru.nidi.codeassert.model.p2.ExampleEnum;
21 | import guru.nidi.codeassert.model.p3.ExampleSecondEnum;
22 |
23 | import java.lang.annotation.Retention;
24 |
25 | import static guru.nidi.codeassert.model.p3.ExampleSecondEnum.NO_DEPENDENCIES_ON_ME;
26 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
27 |
28 | @Retention(RUNTIME)
29 | public @interface ExampleAnnotation {
30 |
31 | Class> c1() default Object.class;
32 |
33 | Class> c2() default Object.class;
34 |
35 | ExampleInnerAnnotation c3();
36 |
37 | ExampleEnum c4();
38 |
39 | ExampleSecondEnum c5() default NO_DEPENDENCIES_ON_ME;
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/ExampleAbstractClass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 |
19 | import java.math.BigDecimal;
20 |
21 | /**
22 | * @author Mike Clark
23 | * @author Clarkware Consulting, Inc.
24 | */
25 |
26 | public abstract class ExampleAbstractClass implements ExampleInterface, java.io.Serializable {
27 |
28 | private java.lang.reflect.Method method;
29 |
30 | public ExampleAbstractClass() {
31 | }
32 |
33 | public void a() {
34 | java.net.URL url;
35 | }
36 |
37 | public java.util.Vector b(String[] s, java.text.NumberFormat nf) {
38 | return null;
39 | }
40 |
41 | public void c(BigDecimal bd, byte[] b) throws java.rmi.RemoteException {
42 |
43 | }
44 |
45 | public abstract java.io.File[] d() throws java.io.IOException;
46 | }
47 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/ValuedLocation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | public class ValuedLocation {
19 | final String pack;
20 | final String clazz;
21 | final double[] values;
22 | final double[] appliedLimits;
23 |
24 | public ValuedLocation(String pack, String clazz, double[] values) {
25 | this.pack = pack;
26 | this.clazz = clazz;
27 | this.values = values;
28 | appliedLimits = new double[values.length];
29 | }
30 |
31 | public String getPack() {
32 | return pack;
33 | }
34 |
35 | public String getClazz() {
36 | return clazz;
37 | }
38 |
39 | public double[] getValues() {
40 | return values;
41 | }
42 |
43 | public double[] getAppliedLimits() {
44 | return appliedLimits;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/Ignore.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | import java.util.List;
19 |
20 | public class Ignore implements Action {
21 | private final LocationNameMatcher matcher;
22 |
23 | Ignore(List locs, List names) {
24 | matcher = new LocationNameMatcher(locs, names);
25 | }
26 |
27 | @Override
28 | public ActionResult accept(NamedLocation namedLocation) {
29 | final boolean matches = matcher.matches(namedLocation.name, namedLocation.language,
30 | namedLocation.className, namedLocation.method, namedLocation.strictNameMatch);
31 | return ActionResult.rejectIfFalse(!matches, this, 5);
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return " ignore " + matcher.toString();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/AnalyzerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import guru.nidi.codeassert.config.AnalyzerConfig;
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static org.hamcrest.CoreMatchers.anyOf;
22 | import static org.hamcrest.CoreMatchers.equalTo;
23 | import static org.hamcrest.MatcherAssert.assertThat;
24 | import static org.junit.jupiter.api.Assertions.assertEquals;
25 |
26 | class AnalyzerTest {
27 | final Model model = Model.from(AnalyzerConfig.maven().mainAndTest("guru/nidi/codeassert/model").getClasses()).read();
28 |
29 | @Test
30 | void packages() {
31 | assertEquals(41, model.getPackages().size());
32 | }
33 |
34 | @Test
35 | void classes() {
36 | assertThat(model.getClasses().size(), anyOf(equalTo(139), equalTo(140), equalTo(141), equalTo(142)));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/jacoco/Coverages.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.jacoco;
17 |
18 | import java.util.*;
19 | import java.util.stream.Stream;
20 |
21 | public class Coverages {
22 | final Set coverages = new TreeSet<>();
23 | final Map perPackage = new TreeMap<>();
24 | Coverage global;
25 |
26 | public void add(Coverage coverage) {
27 | coverages.add(coverage);
28 | final Coverage pc = perPackage.get(coverage.pack);
29 | perPackage.put(coverage.pack, pc == null ? coverage.withClazz("") : pc.combined(coverage));
30 | global = global == null ? coverage : global.combined(coverage);
31 | }
32 |
33 | Stream asStream() {
34 | return Stream.concat(Stream.concat(
35 | Stream.of(global), perPackage.values().stream()), coverages.stream());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/code-assert-gui/src/main/java/guru/nidi/codeassert/gui/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.gui;
17 |
18 | import com.fasterxml.jackson.databind.Module;
19 | import com.fasterxml.jackson.databind.module.SimpleModule;
20 | import guru.nidi.codeassert.model.CodeClass;
21 | import guru.nidi.codeassert.model.CodePackage;
22 | import org.springframework.boot.SpringApplication;
23 | import org.springframework.boot.autoconfigure.SpringBootApplication;
24 | import org.springframework.context.annotation.Bean;
25 |
26 | @SpringBootApplication
27 | public class Application {
28 | public static void main(String[] args) {
29 | SpringApplication.run(Application.class, args);
30 | }
31 |
32 | @Bean
33 | Module jacksonModule() {
34 | return new SimpleModule()
35 | .addSerializer(new CodePackageSerializer(CodePackage.class))
36 | .addSerializer(new CodeClassSerializer(CodeClass.class));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/Language.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | import java.util.List;
19 |
20 | import static java.util.Arrays.asList;
21 |
22 | public enum Language {
23 | JAVA("java", asList(".java")),
24 | KOTLIN("kotlin", asList(".kt", ".kts")),
25 | SCALA("scala", asList(".scala")),
26 | GROOVY("groovy", asList(".groovy", ".gvy", ".gy", ".gsh"));
27 |
28 | final String path;
29 | final List suffices;
30 |
31 | Language(String path, List suffices) {
32 | this.path = path;
33 | this.suffices = suffices;
34 | }
35 |
36 | public static Language byFilename(String filename) {
37 | final String suffix = filename.substring(filename.lastIndexOf('.'));
38 | for (final Language lang : values()) {
39 | if (lang.suffices.contains(suffix)) {
40 | return lang;
41 | }
42 | }
43 | return null;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/dependency/AmbiguousRuleException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency;
17 |
18 | import guru.nidi.codeassert.model.UsingElement;
19 |
20 | public class AmbiguousRuleException extends RuntimeException {
21 | private final DependencyRule rule;
22 | private final UsingElement> from;
23 | private final UsingElement> to;
24 |
25 | AmbiguousRuleException(DependencyRule rule, UsingElement> from, UsingElement> to) {
26 | this.rule = rule;
27 | this.from = from;
28 | this.to = to;
29 | }
30 |
31 | public DependencyRule getRule() {
32 | return rule;
33 | }
34 |
35 | public UsingElement> getFrom() {
36 | return from;
37 | }
38 |
39 | public UsingElement> getTo() {
40 | return to;
41 | }
42 |
43 | @Override
44 | public String getMessage() {
45 | return rule + " is ambiguous for dependency " + from + " -> " + to;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/ktlint/KtlintMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.ktlint;
17 |
18 | import guru.nidi.codeassert.util.ResultMatcher;
19 | import org.hamcrest.Description;
20 |
21 | import static java.lang.System.lineSeparator;
22 |
23 | public class KtlintMatcher extends ResultMatcher {
24 | public void describeTo(Description description) {
25 | description.appendText("Has no ktlint issues");
26 | }
27 |
28 | @Override
29 | protected void describeMismatchSafely(KtlintResult item, Description description) {
30 | for (final LocatedLintError error : item.findings()) {
31 | description.appendText(lineSeparator()).appendText(printError(error));
32 | }
33 | }
34 |
35 | private String printError(LocatedLintError error) {
36 | return String.format("%-35s %s:%d %s",
37 | error.ruleId, error.file.getAbsolutePath(), error.line, error.detail);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/junit/UnusedActionsMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | import guru.nidi.codeassert.AnalyzerResult;
19 | import org.hamcrest.Description;
20 | import org.hamcrest.TypeSafeMatcher;
21 |
22 | import static java.lang.System.lineSeparator;
23 |
24 | public class UnusedActionsMatcher> extends TypeSafeMatcher {
25 | @Override
26 | protected boolean matchesSafely(T item) {
27 | return item.unusedActions().isEmpty();
28 | }
29 |
30 | public void describeTo(Description description) {
31 | description.appendText("Has no unused actions");
32 | }
33 |
34 | @Override
35 | protected void describeMismatchSafely(T item, Description description) {
36 | description.appendText("Found unused actions:");
37 | for (final String action : item.unusedActions()) {
38 | description.appendText(lineSeparator()).appendText(action);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/JDepend-LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 1999-2004 Clarkware Consulting, Inc.
2 | All Rights Reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions
6 | are met:
7 |
8 | 1. Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 |
11 | 2. Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 |
15 | 3. Neither the name of Clarkware Consulting, Inc. nor the names of its
16 | contributors may be used to endorse or promote products derived
17 | from this software without prior written permission. For written
18 | permission, please contact clarkware@clarkware.com.
19 |
20 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
21 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 | CLARKWARE CONSULTING OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/detekt/TypedDetektFinding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.detekt;
17 |
18 | import io.gitlab.arturbosch.detekt.api.*;
19 |
20 | import java.io.File;
21 |
22 | public class TypedDetektFinding {
23 | final File basedir;
24 | final Entity entity;
25 | final String type;
26 | final String name;
27 | final Severity severity;
28 | final String description;
29 |
30 | TypedDetektFinding(File basedir, Entity entity, String type, String name, Severity severity, String description) {
31 | this.basedir = basedir;
32 | this.entity = entity;
33 | this.type = type;
34 | this.name = name;
35 | this.severity = severity;
36 | this.description = description;
37 | }
38 |
39 | TypedDetektFinding(File basedir, String type, Finding finding) {
40 | this(basedir, finding.getEntity(), type, finding.getId(),
41 | finding.getIssue().getSeverity(), finding.getIssue().getDescription());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/Path.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import java.io.File;
19 |
20 | public final class Path {
21 | private static final String PACKAGE = "guru/nidi/codeassert/model/";
22 | private static final String TEST_RESOURCES = "src/test/resources/";
23 | private static final String TEST_JAVAS = "src/test/java/" + PACKAGE;
24 | public static final String TEST_CLASSES = "target/test-classes/" + PACKAGE;
25 | public static final String CLASSES = "target/classes/" + PACKAGE;
26 |
27 | private Path() {
28 | }
29 |
30 | public static File testJava(String name) {
31 | return new File(TEST_JAVAS + name + ".java");
32 | }
33 |
34 | public static File testClass(String name) {
35 | return new File(TEST_CLASSES + name + ".class");
36 | }
37 |
38 | public static File testResource(String name) {
39 | return new File(TEST_RESOURCES + name);
40 | }
41 |
42 | public static File clazz(String name) {
43 | return new File(CLASSES + name + ".class");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/snippets/KtlintTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import guru.nidi.codeassert.config.AnalyzerConfig;
19 | import guru.nidi.codeassert.config.In;
20 | import guru.nidi.codeassert.ktlint.*;
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import static guru.nidi.codeassert.config.Language.KOTLIN;
25 | import static guru.nidi.codeassert.junit.kotlin.KotlinCodeAssertMatchers.hasNoKtlintIssues;
26 | import static org.hamcrest.MatcherAssert.assertThat;
27 |
28 | @Disabled
29 | //## ktlint
30 | public class KtlintTest {
31 | @Test
32 | public void analyze() {
33 | // Analyze all sources in src/main/kotlin
34 | AnalyzerConfig config = AnalyzerConfig.maven(KOTLIN).main();
35 |
36 | KtlintCollector collector = new KtlintCollector()
37 | .just(In.classes("Linker").ignore("no-semi"));
38 |
39 | KtlintResult result = new KtlintAnalyzer(config, collector).analyze();
40 |
41 | assertThat(result, hasNoKtlintIssues());
42 | }
43 | }
44 | //##
45 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/snippets/DetektTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import guru.nidi.codeassert.config.AnalyzerConfig;
19 | import guru.nidi.codeassert.config.In;
20 | import guru.nidi.codeassert.detekt.*;
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import static guru.nidi.codeassert.config.Language.KOTLIN;
25 | import static guru.nidi.codeassert.junit.kotlin.KotlinCodeAssertMatchers.hasNoDetektIssues;
26 | import static org.hamcrest.MatcherAssert.assertThat;
27 |
28 | @Disabled
29 | //## detekt
30 | public class DetektTest {
31 | @Test
32 | public void analyze() {
33 | // Analyze all sources in src/main/kotlin
34 | AnalyzerConfig config = AnalyzerConfig.maven(KOTLIN).main();
35 |
36 | DetektCollector collector = new DetektCollector()
37 | .just(In.classes("Linker").ignore("MaxLineLength"));
38 |
39 | DetektResult result = new DetektAnalyzer(config, collector).analyze();
40 |
41 | assertThat(result, hasNoDetektIssues());
42 | }
43 | }
44 | //##
45 |
--------------------------------------------------------------------------------
/code-assert-gui/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | code-assert-parent
6 | guru.nidi
7 | 0.9.16-SNAPSHOT
8 |
9 |
10 | code-assert-gui
11 | ${project.artifactId}
12 |
13 |
14 | guru.nidi.codeassert.gui
15 |
16 |
17 |
18 |
19 |
20 | org.springframework.boot
21 | spring-boot-dependencies
22 | 2.4.2
23 | pom
24 | import
25 |
26 |
27 |
28 |
29 |
30 |
31 | guru.nidi
32 | code-assert
33 | ${project.version}
34 | compile
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-web
39 |
40 |
41 | com.fasterxml.jackson.core
42 | jackson-databind
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/junit/CodeAssertCoreTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | import guru.nidi.codeassert.dependency.DependencyResult;
19 | import guru.nidi.codeassert.model.Model;
20 |
21 | import java.util.EnumSet;
22 |
23 | public class CodeAssertCoreTestBase {
24 | private Model model;
25 | private DependencyResult dependencyResult;
26 |
27 | protected EnumSet defaultTests() {
28 | return EnumSet.allOf(CodeAssertTestType.class);
29 | }
30 |
31 | protected Model createModel() {
32 | return null;
33 | }
34 |
35 | protected DependencyResult analyzeDependencies() {
36 | return null;
37 | }
38 |
39 | protected synchronized Model model() {
40 | if (model == null) {
41 | model = createModel();
42 | }
43 | return model;
44 | }
45 |
46 | protected synchronized DependencyResult dependencyResult() {
47 | if (dependencyResult == null) {
48 | dependencyResult = analyzeDependencies();
49 | }
50 | return dependencyResult;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/PmdMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import guru.nidi.codeassert.util.ResultMatcher;
19 | import net.sourceforge.pmd.Rule;
20 | import net.sourceforge.pmd.RuleViolation;
21 | import org.hamcrest.Description;
22 |
23 | import static java.lang.System.lineSeparator;
24 |
25 | public class PmdMatcher extends ResultMatcher {
26 | public void describeTo(Description description) {
27 | description.appendText("Has no PMD issues");
28 | }
29 |
30 | @Override
31 | protected void describeMismatchSafely(PmdResult item, Description description) {
32 | for (final RuleViolation violation : item.findings()) {
33 | description.appendText(lineSeparator()).appendText(printViolation(violation));
34 | }
35 | }
36 |
37 | private String printViolation(RuleViolation viol) {
38 | final Rule rule = viol.getRule();
39 | return String.format("%-11s %-45s %s:%d %s",
40 | rule.getPriority(), rule.getName(), viol.getFilename(), viol.getBeginLine(), viol.getDescription());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/snippets/CodeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import guru.nidi.codeassert.config.AnalyzerConfig;
19 | import guru.nidi.codeassert.dependency.*;
20 | import guru.nidi.codeassert.junit.CodeAssertCoreJunit5Test;
21 | import org.junit.jupiter.api.Disabled;
22 |
23 | import static guru.nidi.codeassert.dependency.DependencyRules.denyAll;
24 |
25 | @Disabled
26 | //## codeTest
27 | //extend CodeAssertTest if you still use JUnit 4
28 | public class CodeTest extends CodeAssertCoreJunit5Test {
29 |
30 | private static final AnalyzerConfig CONFIG = AnalyzerConfig.maven().main();
31 |
32 | @Override
33 | protected DependencyResult analyzeDependencies() {
34 | class MyProject extends DependencyRuler {
35 | DependencyRule packages;
36 |
37 | @Override
38 | public void defineRules() {
39 | //TODO
40 | }
41 | }
42 |
43 | final DependencyRules rules = denyAll().withExternals("java.*").withRelativeRules(new MyProject());
44 | return new DependencyAnalyzer(CONFIG).rules(rules).analyze();
45 | }
46 | }
47 | //##
48 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/checkstyle/CheckstyleMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.checkstyle;
17 |
18 | import com.puppycrawl.tools.checkstyle.api.AuditEvent;
19 | import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
20 | import guru.nidi.codeassert.util.ResultMatcher;
21 | import org.hamcrest.Description;
22 |
23 | import static java.lang.System.lineSeparator;
24 |
25 | public class CheckstyleMatcher extends ResultMatcher {
26 | public void describeTo(Description description) {
27 | description.appendText("Has no Checkstyle issues");
28 | }
29 |
30 | @Override
31 | protected void describeMismatchSafely(CheckstyleResult item, Description description) {
32 | for (final AuditEvent event : item.findings()) {
33 | description.appendText(lineSeparator()).appendText(printEvent(event));
34 | }
35 | }
36 |
37 | private String printEvent(AuditEvent event) {
38 | final LocalizedMessage msg = event.getLocalizedMessage();
39 | return String.format("%-8s %-40s %s:%d %s",
40 | msg.getSeverityLevel(), msg.getKey(), event.getFileName(), event.getLine(), event.getMessage());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/snippets/CodeCoverage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import guru.nidi.codeassert.config.For;
19 | import guru.nidi.codeassert.jacoco.CoverageCollector;
20 | import guru.nidi.codeassert.jacoco.JacocoAnalyzer;
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import static guru.nidi.codeassert.jacoco.CoverageType.*;
25 | import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.hasEnoughCoverage;
26 | import static org.hamcrest.MatcherAssert.assertThat;
27 |
28 | @Disabled
29 | //## codeCoverage
30 | public class CodeCoverage {
31 | @Test
32 | public void coverage() {
33 | // Coverage of branches must be at least 70%, lines 80% and methods 90%
34 | // This is checked globally and for all packages except for entities.
35 | JacocoAnalyzer analyzer = new JacocoAnalyzer(new CoverageCollector(BRANCH, LINE, METHOD)
36 | .just(For.global().setMinima(70, 80, 90))
37 | .just(For.allPackages().setMinima(70, 80, 90))
38 | .just(For.thePackage("org.proj.entity.*").setNoMinima()));
39 | assertThat(analyzer.analyze(), hasEnoughCoverage());
40 | }
41 | }
42 | //##
43 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/snippets/CodeCoverage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import guru.nidi.codeassert.config.For;
19 | import guru.nidi.codeassert.jacoco.CoverageCollector;
20 | import guru.nidi.codeassert.jacoco.JacocoAnalyzer;
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import static guru.nidi.codeassert.jacoco.CoverageType.*;
25 | import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.hasEnoughCoverage;
26 | import static org.hamcrest.MatcherAssert.assertThat;
27 |
28 | @Disabled
29 | //## codeCoverage
30 | public class CodeCoverage {
31 | @Test
32 | public void coverage() {
33 | // Coverage of branches must be at least 70%, lines 80% and methods 90%
34 | // This is checked globally and for all packages except for entities.
35 | JacocoAnalyzer analyzer = new JacocoAnalyzer(new CoverageCollector(BRANCH, LINE, METHOD)
36 | .just(For.global().setMinima(70, 80, 90))
37 | .just(For.allPackages().setMinima(70, 80, 90))
38 | .just(For.thePackage("org.proj.entity.*").setNoMinima()));
39 | assertThat(analyzer.analyze(), hasEnoughCoverage());
40 | }
41 | }
42 | //##
43 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/detekt/DetektMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.detekt;
17 |
18 | import guru.nidi.codeassert.util.ResultMatcher;
19 | import io.gitlab.arturbosch.detekt.api.Location;
20 | import org.hamcrest.Description;
21 |
22 | import java.io.File;
23 |
24 | import static java.lang.System.lineSeparator;
25 |
26 | public class DetektMatcher extends ResultMatcher {
27 | public void describeTo(Description description) {
28 | description.appendText("Has no detekt issues");
29 | }
30 |
31 | @Override
32 | protected void describeMismatchSafely(DetektResult item, Description description) {
33 | for (final TypedDetektFinding error : item.findings()) {
34 | description.appendText(lineSeparator()).appendText(printError(error));
35 | }
36 | }
37 |
38 | private String printError(TypedDetektFinding finding) {
39 | final Location location = finding.entity.getLocation();
40 | final String path = new File(location.getFile()).getAbsolutePath();
41 | return String.format("%-15s %-15s %-30s %s:%d %s", finding.severity, finding.type, finding.name,
42 | path, location.getSource().getLine(), finding.description);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/model/p4/GenericParameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model.p4;
17 |
18 | import guru.nidi.codeassert.model.p4.p1.Type1;
19 | import guru.nidi.codeassert.model.p4.p10.Type10;
20 | import guru.nidi.codeassert.model.p4.p2.Type2;
21 | import guru.nidi.codeassert.model.p4.p3.Type3;
22 | import guru.nidi.codeassert.model.p4.p4.Type4;
23 | import guru.nidi.codeassert.model.p4.p5.Type5;
24 | import guru.nidi.codeassert.model.p4.p6.Type6;
25 | import guru.nidi.codeassert.model.p4.p7.Type7;
26 | import guru.nidi.codeassert.model.p4.p8.Type8;
27 | import guru.nidi.codeassert.model.p4.p9.Type9;
28 |
29 | import java.util.ArrayList;
30 | import java.util.List;
31 |
32 | public class GenericParameters {
33 | private List list;
34 | private List> l2 = new ArrayList();
35 |
36 | private List method4(Type7 t7, X x) {
37 | return null;
38 | }
39 |
40 | private List extends Type4> method42() throws Type8 {
41 | return null;
42 | }
43 |
44 | private void method5(List super Type5> param, List> sub) throws E {
45 | }
46 |
47 | private List method6(List a) {
48 | return null;
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/code-assert-gui/src/main/java/guru/nidi/codeassert/gui/CodePackageSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.gui;
17 |
18 | import com.fasterxml.jackson.core.JsonGenerator;
19 | import com.fasterxml.jackson.databind.SerializerProvider;
20 | import com.fasterxml.jackson.databind.ser.std.StdSerializer;
21 | import guru.nidi.codeassert.model.CodeClass;
22 | import guru.nidi.codeassert.model.CodePackage;
23 |
24 | import java.io.IOException;
25 |
26 | public class CodePackageSerializer extends StdSerializer {
27 | protected CodePackageSerializer(Class t) {
28 | super(t);
29 | }
30 |
31 | @Override
32 | public void serialize(CodePackage value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
33 | gen.writeStartObject();
34 | gen.writeStringField("name", value.getName());
35 | gen.writeArrayFieldStart("classes");
36 | for (final CodeClass clazz : value.getClasses()) {
37 | gen.writeString(clazz.getName());
38 | }
39 | gen.writeEndArray();
40 | gen.writeArrayFieldStart("uses");
41 | for (final CodePackage pack : value.uses()) {
42 | gen.writeString(pack.getName());
43 | }
44 | gen.writeEndArray();
45 | gen.writeEndObject();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/CollectorConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | import java.util.List;
19 |
20 | import static guru.nidi.codeassert.util.ListUtils.andJoin;
21 | import static java.util.Arrays.asList;
22 |
23 | public final class CollectorConfig {
24 | public final String reason;
25 | public final boolean ignoreUnused;
26 | public final List actions;
27 |
28 | private CollectorConfig(String reason, boolean ignoreUnused, List actions) {
29 | this.reason = reason;
30 | this.ignoreUnused = ignoreUnused;
31 | this.actions = actions;
32 | }
33 |
34 | public CollectorConfig ignoringUnused() {
35 | return new CollectorConfig<>(reason, true, actions);
36 | }
37 |
38 | @SafeVarargs
39 | public static CollectorConfig because(String reason, A... actions) {
40 | return new CollectorConfig<>(reason, false, asList(actions));
41 | }
42 |
43 | @SafeVarargs
44 | public static CollectorConfig just(A... actions) {
45 | return because(null, actions);
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return andJoin(" " + (reason == null ? "just" : ("because " + reason)), actions);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | guru.nidi
8 | guru-nidi-parent-pom
9 | 1.1.35
10 |
11 |
12 |
13 | code-assert-parent
14 | 0.9.16-SNAPSHOT
15 | pom
16 |
17 | ${project.artifactId}
18 | Assert that the java code of a project satisfies certain checks.
19 | https://github.com/nidi3/code-assert
20 | 2015
21 |
22 |
23 | 1.8
24 | owasp-suppression.xml
25 |
26 |
27 |
28 | code-assert-core
29 | code-assert
30 | code-assert-maven-plugin
31 | code-assert-gui
32 |
33 |
34 |
35 | scm:git:https://github.com/nidi3/code-assert
36 | scm:git:https://github.com/nidi3/code-assert
37 | https://github.com/nidi3/code-assert
38 | HEAD
39 |
40 |
41 |
42 |
43 |
44 |
45 | guru.nidi.maven.plugins
46 | snippets-maven-plugin
47 | 1.0.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/model/UsingElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import guru.nidi.codeassert.config.LocationMatcher;
19 |
20 | import java.util.Collection;
21 | import java.util.List;
22 |
23 | public abstract class UsingElement {
24 | public abstract T self();
25 |
26 | public abstract String getName();
27 |
28 | public abstract String getPackageName();
29 |
30 | public abstract Collection usedVia(UsingElement other);
31 |
32 | public abstract boolean isMatchedBy(LocationMatcher matcher);
33 |
34 | public abstract Collection uses();
35 |
36 | public boolean uses(T elem) {
37 | return uses().contains(elem);
38 | }
39 |
40 | public int mostSpecificMatch(Collection matchers) {
41 | int s = 0;
42 | for (final LocationMatcher matcher : matchers) {
43 | if (isMatchedBy(matcher) && matcher.specificity() > s) {
44 | s = matcher.specificity();
45 | }
46 | }
47 | return s;
48 | }
49 |
50 | public boolean matchesAny(List extends UsingElementMatcher> matchers) {
51 | for (final UsingElementMatcher matcher : matchers) {
52 | if (matcher.matches(this)) {
53 | return true;
54 | }
55 | }
56 | return false;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/For.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | public final class For {
19 | private final Location loc;
20 | private final String pack;
21 | private final String clazz;
22 |
23 | private For(Location loc, String pack, String clazz) {
24 | this.loc = loc;
25 | this.pack = pack;
26 | this.clazz = clazz;
27 | }
28 |
29 | public static For global() {
30 | return new For(null, "", "");
31 | }
32 |
33 | public static For allPackages() {
34 | return new For(null, "*", "");
35 | }
36 |
37 | public static For allClasses() {
38 | return new For(null, "*", "*");
39 | }
40 |
41 | public static For thePackage(String pack) {
42 | return new For(null, pack, "");
43 | }
44 |
45 | public static For allInPackage(String pack) {
46 | return new For(null, pack, "*");
47 | }
48 |
49 | public static For loc(String loc) {
50 | return new For(Location.of(loc), null, null);
51 | }
52 |
53 | public static For clazz(Class> clazz) {
54 | return loc(clazz.getName());
55 | }
56 |
57 | public Minima setMinima(int... values) {
58 | return new Minima(loc, pack, clazz, values);
59 | }
60 |
61 | public Minima setNoMinima() {
62 | return new Minima(loc, pack, clazz);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/dependency/Usage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency;
17 |
18 | import guru.nidi.codeassert.config.LocationMatcher;
19 |
20 | import java.util.HashSet;
21 | import java.util.Set;
22 |
23 | class Usage {
24 | final Set must = new HashSet<>();
25 | final Set may = new HashSet<>();
26 | final Set mustNot = new HashSet<>();
27 |
28 | Usage copy() {
29 | final Usage u = new Usage();
30 | u.must.addAll(must);
31 | u.may.addAll(may);
32 | u.mustNot.addAll(mustNot);
33 | return u;
34 | }
35 |
36 | void must(CodeElement... rules) {
37 | for (final CodeElement rule : rules) {
38 | must.add(rule.pattern);
39 | }
40 | }
41 |
42 | void may(CodeElement... rules) {
43 | for (final CodeElement rule : rules) {
44 | may.add(rule.pattern);
45 | }
46 | }
47 |
48 | void mustNot(CodeElement... rules) {
49 | for (final CodeElement rule : rules) {
50 | mustNot.add(rule.pattern);
51 | }
52 | }
53 |
54 | boolean isEmpty() {
55 | return must.isEmpty() && may.isEmpty() && mustNot.isEmpty();
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return "must " + must + ", may " + may + ", must not " + mustNot;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/util/ListUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.util;
17 |
18 | import java.util.*;
19 |
20 | import static java.lang.System.lineSeparator;
21 | import static java.util.Arrays.asList;
22 |
23 | public final class ListUtils {
24 | private ListUtils() {
25 | }
26 |
27 | public static String andJoin(Object first, Object[] os) {
28 | return andJoin(first, asList(os));
29 | }
30 |
31 | public static String andJoin(Object first, List> os) {
32 | return first.toString() + lineSeparator() + join(lineSeparator(), os);
33 | }
34 |
35 | public static String join(String sep, Object[] os) {
36 | return join(sep, asList(os));
37 | }
38 |
39 | public static String join(String sep, List> os) {
40 | final StringBuilder res = new StringBuilder();
41 | for (final Object o : os) {
42 | res.append(sep).append(o);
43 | }
44 | return os.isEmpty() ? "" : res.substring(sep.length());
45 | }
46 |
47 | public static List concat(List a, List b) {
48 | final ArrayList res = new ArrayList<>(a);
49 | res.addAll(b);
50 | return res;
51 | }
52 |
53 | public static > EnumSet concat(EnumSet a, EnumSet b) {
54 | final EnumSet res = EnumSet.copyOf(a);
55 | res.addAll(b);
56 | return res;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/model/ModelBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import java.io.File;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import static java.util.Arrays.asList;
23 |
24 | public class ModelBuilder {
25 | private final List files = new ArrayList<>();
26 | private final List ignorePackages = new ArrayList<>();
27 | private final List mergePackages = new ArrayList<>();
28 |
29 | ModelBuilder() {
30 | }
31 |
32 | public ModelBuilder and(File... files) {
33 | return and(asList(files));
34 | }
35 |
36 | public ModelBuilder and(List files) {
37 | this.files.addAll(files);
38 | return this;
39 | }
40 |
41 | public ModelBuilder ignoringPackages(String... packages) {
42 | return ignoringPackages(asList(packages));
43 | }
44 |
45 | public ModelBuilder ignoringPackages(List packages) {
46 | ignorePackages.addAll(packages);
47 | return this;
48 | }
49 |
50 | public ModelBuilder mergingPackages(String... packages) {
51 | return mergingPackages(asList(packages));
52 | }
53 |
54 | public ModelBuilder mergingPackages(List packages) {
55 | mergePackages.addAll(packages);
56 | return this;
57 | }
58 |
59 | public Model read() {
60 | return new Model(ignorePackages, mergePackages).read(files);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/config/ActionResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.config;
17 |
18 | public class ActionResult {
19 | final boolean accept;
20 | final Action> action;
21 | final int quality;
22 |
23 | public ActionResult(boolean accept, Action> action, int quality) {
24 | this.accept = accept;
25 | this.action = action;
26 | this.quality = quality;
27 | }
28 |
29 | public static ActionResult accept(Action> action, int quality) {
30 | return new ActionResult(true, action, quality);
31 | }
32 |
33 | public static ActionResult reject(Action> action, int quality) {
34 | return new ActionResult(false, action, quality);
35 | }
36 |
37 | public static ActionResult undecided(Action> action) {
38 | return new ActionResult(false, action, 0);
39 | }
40 |
41 | public static ActionResult acceptIfTrue(boolean accept, Action> action, int quality) {
42 | return accept ? accept(action, quality) : undecided(action);
43 | }
44 |
45 | public static ActionResult rejectIfFalse(boolean accept, Action> action, int quality) {
46 | return accept ? undecided(action) : reject(action, quality);
47 | }
48 |
49 | public boolean isUndecided() {
50 | return quality == 0;
51 | }
52 |
53 | public ActionResult orMoreQuality(ActionResult result) {
54 | return quality >= result.quality ? this : result;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/snippets/CheckstyleTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
19 | import guru.nidi.codeassert.checkstyle.*;
20 | import guru.nidi.codeassert.config.AnalyzerConfig;
21 | import guru.nidi.codeassert.config.In;
22 | import org.junit.jupiter.api.Disabled;
23 | import org.junit.jupiter.api.Test;
24 |
25 | import static guru.nidi.codeassert.junit.CodeAssertMatchers.hasNoCheckstyleIssues;
26 | import static org.hamcrest.MatcherAssert.assertThat;
27 |
28 | @Disabled
29 | //## checkstyle
30 | public class CheckstyleTest {
31 | @Test
32 | public void checkstyle() {
33 | // Analyze all sources in src/main/java
34 | AnalyzerConfig config = AnalyzerConfig.maven().main();
35 |
36 | // Only treat issues with severity WARNING or higher
37 | StyleEventCollector collector = new StyleEventCollector().severity(SeverityLevel.WARNING)
38 | .just(In.everywhere().ignore("import.avoidStar", "javadoc.missing"))
39 | .because("in tests, long lines are ok", In.classes("*Test").ignore("maxLineLen"));
40 |
41 | //use google checks, but adjust max line length
42 | final StyleChecks checks = StyleChecks.google().maxLineLen(120);
43 |
44 | CheckstyleResult result = new CheckstyleAnalyzer(config, checks, collector).analyze();
45 | assertThat(result, hasNoCheckstyleIssues());
46 | }
47 | }
48 | //##
49 |
--------------------------------------------------------------------------------
/code-assert-gui/src/main/java/guru/nidi/codeassert/gui/CodeClassSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.gui;
17 |
18 | import com.fasterxml.jackson.core.JsonGenerator;
19 | import com.fasterxml.jackson.databind.SerializerProvider;
20 | import com.fasterxml.jackson.databind.ser.std.StdSerializer;
21 | import guru.nidi.codeassert.model.CodeClass;
22 | import guru.nidi.codeassert.model.CodePackage;
23 |
24 | import java.io.IOException;
25 | import java.util.Map;
26 |
27 | public class CodeClassSerializer extends StdSerializer {
28 | protected CodeClassSerializer(Class t) {
29 | super(t);
30 | }
31 |
32 | @Override
33 | public void serialize(CodeClass value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
34 | gen.writeStartObject();
35 | gen.writeStringField("name", value.getName());
36 | gen.writeStringField("package", value.getPackage().getName());
37 | gen.writeNumberField("size", value.getTotalSize());
38 | gen.writeArrayFieldStart("usePackages");
39 | for (final CodePackage pack : value.usedPackages()) {
40 | gen.writeString(pack.getName());
41 | }
42 | gen.writeEndArray();
43 | gen.writeObjectFieldStart("useClasses");
44 | for (final Map.Entry entry : value.usedClassCounts().entrySet()) {
45 | gen.writeNumberField(entry.getKey().getName(), entry.getValue());
46 | }
47 | gen.writeEndObject();
48 | gen.writeEndObject();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/junit/CodeAssertCoreTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | import org.junit.Ignore;
19 | import org.junit.Test;
20 |
21 | import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.*;
22 | import static guru.nidi.codeassert.junit.CodeAssertTestType.*;
23 | import static org.hamcrest.MatcherAssert.assertThat;
24 | import static org.junit.Assume.assumeFalse;
25 | import static org.junit.Assume.assumeTrue;
26 |
27 | @Ignore("This is made to be subclassed")
28 | public class CodeAssertCoreTest extends CodeAssertCoreTestBase {
29 | @Test
30 | public void dependencies() {
31 | assumeTrue("Dependencies test excluded.", defaultTests().contains(DEPENDENCIES));
32 | assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
33 | assertThat(dependencyResult(), matchesRulesExactly());
34 | }
35 |
36 | @Test
37 | public void circularDependencies() {
38 | assumeTrue("Circular dependencies test excluded.", defaultTests().contains(CIRCULAR_DEPENDENCIES));
39 | assumeFalse("analyzeDependencies() not implemented.", dependencyResult() == null);
40 | assertThat(dependencyResult(), hasNoCycles());
41 | }
42 |
43 | @Test
44 | public void codeStructure() {
45 | assumeTrue("Structure tests excluded.", defaultTests().contains(STRUCTURE));
46 | assumeFalse("createModel() not implemented.", createModel() == null);
47 | assertThat(createModel(), exposesNoInternalTypes());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/junit/CodeAssertCoreJunit5Test.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | import org.junit.jupiter.api.Disabled;
19 | import org.junit.jupiter.api.Test;
20 |
21 | import static guru.nidi.codeassert.junit.CodeAssertCoreMatchers.*;
22 | import static guru.nidi.codeassert.junit.CodeAssertTestType.*;
23 | import static org.hamcrest.MatcherAssert.assertThat;
24 | import static org.junit.jupiter.api.Assumptions.assumeFalse;
25 | import static org.junit.jupiter.api.Assumptions.assumeTrue;
26 |
27 | @Disabled("This is made to be subclassed")
28 | public class CodeAssertCoreJunit5Test extends CodeAssertCoreTestBase {
29 | @Test
30 | void dependencies() {
31 | assumeTrue(defaultTests().contains(DEPENDENCIES), "Dependencies test excluded.");
32 | assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
33 | assertThat(dependencyResult(), matchesRulesExactly());
34 | }
35 |
36 | @Test
37 | void circularDependencies() {
38 | assumeTrue(defaultTests().contains(CIRCULAR_DEPENDENCIES), "Circular dependencies test excluded.");
39 | assumeFalse(dependencyResult() == null, "analyzeDependencies() not implemented.");
40 | assertThat(dependencyResult(), hasNoCycles());
41 | }
42 |
43 | @Test
44 | void codeStructure() {
45 | assumeTrue(defaultTests().contains(STRUCTURE), "Structure tests excluded.");
46 | assumeFalse(createModel() == null, "createModel() not implemented.");
47 | assertThat(createModel(), exposesNoInternalTypes());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/findbugs/FindBugsConfigs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.findbugs;
17 |
18 | import guru.nidi.codeassert.config.*;
19 |
20 | import static guru.nidi.codeassert.config.Language.KOTLIN;
21 |
22 | public final class FindBugsConfigs {
23 | private FindBugsConfigs() {
24 | }
25 |
26 | public static CollectorTemplate minimalFindBugsIgnore() {
27 | return CollectorTemplate.forA(BugCollector.class)
28 | .because("modern compilers are clever", In.everywhere().ignore(
29 | "SBSC_USE_STRINGBUFFER_CONCATENATION"))
30 | .because("it's compiler generated code", In.languages(KOTLIN).ignore(
31 | "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", "BC_BAD_CAST_TO_ABSTRACT_COLLECTION"))
32 | .because("it's compiler generated code, but why?", In.languages(KOTLIN).ignore(
33 | "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE"))
34 | .because("findbugs seems to be cleverer than kotlin compiler", In.languages(KOTLIN).ignore(
35 | "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"))
36 | .because("inline methods seem to cause this", In.languages(KOTLIN).ignore(
37 | "UPM_UNCALLED_PRIVATE_METHOD"));
38 | }
39 |
40 | public static CollectorTemplate dependencyTestIgnore(Class> dependencyTest) {
41 | return CollectorTemplate.of(Ignore.class).just(In.clazz(dependencyTest)
42 | .ignore("NP_UNWRITTEN_FIELD", "UWF_UNWRITTEN_FIELD", "UUF_UNUSED_FIELD"));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/code-assert-core/src/test/java/guru/nidi/codeassert/util/ListUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.util;
17 |
18 | import org.junit.jupiter.api.Test;
19 |
20 | import static guru.nidi.codeassert.util.ListUtils.andJoin;
21 | import static guru.nidi.codeassert.util.ListUtils.join;
22 | import static java.util.Arrays.asList;
23 | import static org.junit.jupiter.api.Assertions.assertEquals;
24 |
25 | class ListUtilsTest {
26 |
27 | @Test
28 | void emptyArray() {
29 | assertEquals("", join(",", new String[]{}));
30 | }
31 |
32 | @Test
33 | void oneElementArray() {
34 | assertEquals("a", join(",", new String[]{"a"}));
35 | }
36 |
37 | @Test
38 | void multiElementArray() {
39 | assertEquals("a,b", join(",", new String[]{"a", "b"}));
40 | }
41 |
42 | @Test
43 | void notStringArray() {
44 | assertEquals("1,2", join(",", new Integer[]{1, 2}));
45 | }
46 |
47 | @Test
48 | void emptyList() {
49 | assertEquals("", join(",", asList()));
50 | }
51 |
52 | @Test
53 | void oneElementList() {
54 | assertEquals("a", join(",", asList("a")));
55 | }
56 |
57 | @Test
58 | void multiElementList() {
59 | assertEquals("a,b", join(",", asList("a", "b")));
60 | }
61 |
62 | @Test
63 | void notStringList() {
64 | assertEquals("1,2", join(",", asList(1, 2)));
65 | }
66 |
67 | @Test
68 | void andJoinArray() {
69 | assertEquals(String.format("start%n1%n2"), andJoin("start", new Integer[]{1, 2}));
70 | }
71 |
72 | @Test
73 | void andJoinList() {
74 | assertEquals(String.format("start%n1%n2"), andJoin("start", asList(1, 2)));
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/dependency/MatcherUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.dependency;
17 |
18 | import guru.nidi.codeassert.config.LocationMatcher;
19 |
20 | import java.util.*;
21 |
22 | import static java.lang.System.lineSeparator;
23 | import static java.util.Collections.sort;
24 |
25 | final class MatcherUtils {
26 | private MatcherUtils() {
27 | }
28 |
29 | static String deps(String prefix, Map deps) {
30 | final StringBuilder s = new StringBuilder();
31 | for (final String dep : sorted(deps.keySet())) {
32 | s.append(prefix).append(dep);
33 | final Set by = deps.get(dep).getVias();
34 | if (!by.isEmpty()) {
35 | s.append(" (by ").append(join(by)).append(')');
36 | }
37 | s.append(lineSeparator());
38 | }
39 | return s.toString();
40 | }
41 |
42 | static String join(Collection packs) {
43 | final StringBuilder s = new StringBuilder();
44 | for (final String pack : sorted(packs)) {
45 | s.append(", ").append(pack);
46 | }
47 | return s.length() > 0 ? s.substring(2) : s.toString();
48 | }
49 |
50 | static List sorted(Collection ss) {
51 | final List sorted = new ArrayList<>(ss);
52 | sort(sorted);
53 | return sorted;
54 | }
55 |
56 | static List sortedPatterns(Collection patterns) {
57 | final List ss = new ArrayList<>();
58 | for (final LocationMatcher pattern : patterns) {
59 | ss.add(pattern.toString());
60 | }
61 | return sorted(ss);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/model/AttributeInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import java.io.DataInputStream;
19 | import java.io.IOException;
20 |
21 | final class AttributeInfo {
22 | final String name;
23 | final byte[] value;
24 |
25 | private AttributeInfo(String name, byte[] value) {
26 | this.name = name;
27 | this.value = value;
28 | }
29 |
30 | static AttributeInfo fromData(DataInputStream in, ConstantPool constantPool) throws IOException {
31 | final String name = constantPool.getUtf8(in.readUnsignedShort());
32 | final int attributeLength = in.readInt();
33 | final byte[] value = new byte[attributeLength];
34 | for (int b = 0; b < attributeLength; b++) {
35 | value[b] = in.readByte();
36 | }
37 |
38 | return new AttributeInfo(name, value);
39 | }
40 |
41 | boolean isAnnotation() {
42 | return "RuntimeVisibleAnnotations".equals(name) || "RuntimeInvisibleAnnotations".equals(name);
43 | }
44 |
45 | boolean isSignature() {
46 | return "Signature".equals(name);
47 | }
48 |
49 | boolean isSource() {
50 | return "SourceFile".equals(name);
51 | }
52 |
53 | boolean isCode() {
54 | return "Code".equals(name);
55 | }
56 |
57 | String sourceFile(ConstantPool constantPool) throws IOException {
58 | final int b0 = value[0] < 0 ? value[0] + 256 : value[0];
59 | final int b1 = value[1] < 0 ? value[1] + 256 : value[1];
60 | final int pe = b0 * 256 + b1;
61 | return constantPool.getUtf8(pe);
62 | }
63 |
64 | int u2(int index) {
65 | return (value[index] << 8 & 0xFF00) | (value[index + 1] & 0xFF);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/CpdMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import guru.nidi.codeassert.util.ResultMatcher;
19 | import net.sourceforge.pmd.cpd.Mark;
20 | import net.sourceforge.pmd.cpd.Match;
21 | import org.hamcrest.Description;
22 |
23 | import java.util.*;
24 |
25 | import static java.lang.System.lineSeparator;
26 |
27 | public class CpdMatcher extends ResultMatcher {
28 | private static final Comparator MARK_COMPARATOR = Comparator.comparing(Mark::getFilename);
29 |
30 | public void describeTo(Description description) {
31 | description.appendText("Has no code duplications");
32 | }
33 |
34 | @Override
35 | protected void describeMismatchSafely(CpdResult item, Description description) {
36 | for (final Match match : item.findings()) {
37 | description.appendText(lineSeparator()).appendText(printMatch(match));
38 | }
39 | }
40 |
41 | private String printMatch(Match match) {
42 | final StringBuilder s = new StringBuilder();
43 | boolean first = true;
44 | for (final Mark mark : getMarks(match)) {
45 | s.append(first ? String.format("%-4d ", match.getTokenCount()) : " ");
46 | first = false;
47 | s.append(String.format("%s:%d-%d%n", mark.getFilename(), mark.getBeginLine(), mark.getEndLine()));
48 | }
49 | return s.substring(0, s.length() - lineSeparator().length());
50 | }
51 |
52 | private List getMarks(Match match) {
53 | final List marks = new ArrayList<>();
54 | for (final Mark mark : match) {
55 | marks.add(mark);
56 | }
57 | marks.sort(MARK_COMPARATOR);
58 | return marks;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/snippets/FindBugsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import edu.umd.cs.findbugs.Priorities;
19 | import guru.nidi.codeassert.config.AnalyzerConfig;
20 | import guru.nidi.codeassert.config.In;
21 | import guru.nidi.codeassert.dependency.DependencyRules;
22 | import guru.nidi.codeassert.findbugs.*;
23 | import guru.nidi.codeassert.pmd.PmdRuleset;
24 | import org.junit.jupiter.api.Disabled;
25 | import org.junit.jupiter.api.Test;
26 |
27 | import static guru.nidi.codeassert.junit.CodeAssertMatchers.hasNoBugs;
28 | import static org.hamcrest.MatcherAssert.assertThat;
29 |
30 | @Disabled
31 | //## findBugs
32 | public class FindBugsTest {
33 | @Test
34 | public void findBugs() {
35 | // Analyze all sources in src/main/java
36 | AnalyzerConfig config = AnalyzerConfig.maven().main();
37 |
38 | // Only treat bugs with rank < 17 and with NORMAL_PRIORITY or higher
39 | // Ignore the given bug types in the given classes / methods.
40 | BugCollector collector = new BugCollector().maxRank(17).minPriority(Priorities.NORMAL_PRIORITY)
41 | .just(In.everywhere().ignore("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR"))
42 | .because("It's checked and OK like this",
43 | In.classes(DependencyRules.class, PmdRuleset.class).ignore("DP_DO_INSIDE_DO_PRIVILEGED"),
44 | In.classes("*Test", "Rulesets")
45 | .and(In.classes("ClassFileParser").withMethods("doParse"))
46 | .ignore("URF_UNREAD_FIELD"));
47 |
48 | FindBugsResult result = new FindBugsAnalyzer(config, collector).analyze();
49 | assertThat(result, hasNoBugs());
50 | }
51 | }
52 | //##
53 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/junit/CodeAssertTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | import guru.nidi.codeassert.checkstyle.CheckstyleResult;
19 | import guru.nidi.codeassert.findbugs.FindBugsResult;
20 | import guru.nidi.codeassert.pmd.CpdResult;
21 | import guru.nidi.codeassert.pmd.PmdResult;
22 |
23 | public class CodeAssertTestBase extends CodeAssertCoreTestBase {
24 | private FindBugsResult findBugsResult;
25 | private PmdResult pmdResult;
26 | private CpdResult cpdResult;
27 | private CheckstyleResult checkstyleResult;
28 |
29 | protected FindBugsResult analyzeFindBugs() {
30 | return null;
31 | }
32 |
33 | protected PmdResult analyzePmd() {
34 | return null;
35 | }
36 |
37 | protected CpdResult analyzeCpd() {
38 | return null;
39 | }
40 |
41 | protected CheckstyleResult analyzeCheckstyle() {
42 | return null;
43 | }
44 |
45 | protected synchronized FindBugsResult findBugsResult() {
46 | if (findBugsResult == null) {
47 | findBugsResult = analyzeFindBugs();
48 | }
49 | return findBugsResult;
50 | }
51 |
52 | protected synchronized PmdResult pmdResult() {
53 | if (pmdResult == null) {
54 | pmdResult = analyzePmd();
55 | }
56 | return pmdResult;
57 | }
58 |
59 | protected synchronized CpdResult cpdResult() {
60 | if (cpdResult == null) {
61 | cpdResult = analyzeCpd();
62 | }
63 | return cpdResult;
64 | }
65 |
66 | protected synchronized CheckstyleResult checkstyleResult() {
67 | if (checkstyleResult == null) {
68 | checkstyleResult = analyzeCheckstyle();
69 | }
70 | return checkstyleResult;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/code-assert/src/test/java/guru/nidi/codeassert/snippets/ReuseTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.snippets;
17 |
18 | import guru.nidi.codeassert.config.*;
19 | import guru.nidi.codeassert.pmd.*;
20 | import net.sourceforge.pmd.RulePriority;
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import static guru.nidi.codeassert.config.Language.KOTLIN;
25 | import static guru.nidi.codeassert.junit.CodeAssertMatchers.hasNoPmdViolations;
26 | import static guru.nidi.codeassert.pmd.PmdRulesets.*;
27 | import static org.hamcrest.MatcherAssert.assertThat;
28 |
29 | @Disabled
30 | public class ReuseTest {
31 | private final AnalyzerConfig config = AnalyzerConfig.maven().main();
32 | private final PmdRuleset[] rules = new PmdRuleset[]{basic(), braces(), design(), empty(), optimizations()};
33 |
34 | //## reuse
35 | private final CollectorTemplate pmdTestCollector = CollectorTemplate.forA(PmdViolationCollector.class)
36 | .because("It's a test", In.classes("*Test")
37 | .ignore("JUnitSpelling", "AvoidDuplicateLiterals", "SignatureDeclareThrowsException"))
38 | .because("It's compiler generated code", In.languages(KOTLIN)
39 | .ignore("BC_BAD_CAST_TO_ABSTRACT_COLLECTION"));
40 |
41 | @Test
42 | public void pmd() {
43 | PmdViolationCollector collector = new PmdViolationCollector().minPriority(RulePriority.MEDIUM)
44 | .apply(pmdTestCollector)
45 | .because("It's not severe and occurs often", In.everywhere().ignore("MethodArgumentCouldBeFinal"));
46 |
47 | PmdAnalyzer analyzer = new PmdAnalyzer(config, collector).withRulesets(rules);
48 | assertThat(analyzer.analyze(), hasNoPmdViolations());
49 | }
50 | //##
51 | }
52 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/junit/CodeAssertCoreMatchers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.junit;
17 |
18 | import guru.nidi.codeassert.AnalyzerResult;
19 | import guru.nidi.codeassert.dependency.*;
20 | import guru.nidi.codeassert.jacoco.CoverageMatcher;
21 | import guru.nidi.codeassert.jacoco.JacocoResult;
22 | import guru.nidi.codeassert.model.*;
23 | import org.hamcrest.Matcher;
24 |
25 | public final class CodeAssertCoreMatchers {
26 | private CodeAssertCoreMatchers() {
27 | }
28 |
29 | public static Matcher matchesRules() {
30 | return new DependencyResultMatcher(false, false);
31 | }
32 |
33 | public static Matcher matchesRulesExactly() {
34 | return new DependencyResultMatcher(true, true);
35 | }
36 |
37 | public static Matcher matchesRulesIgnoringNonExisting() {
38 | return new DependencyResultMatcher(false, true);
39 | }
40 |
41 | public static Matcher matchesRulesIgnoringUndefined() {
42 | return new DependencyResultMatcher(true, false);
43 | }
44 |
45 | public static Matcher exposesNoInternalTypes() {
46 | return new InternalTypeInPublicApiMatcher();
47 | }
48 |
49 | public static Matcher hasNoPublicMembersInInternalTypes() {
50 | return new PublicMemberInInternalTypeMatcher();
51 | }
52 |
53 | public static Matcher hasNoCycles() {
54 | return new DependencyCycleMatcher();
55 | }
56 |
57 | public static > Matcher hasNoUnusedActions() {
58 | return new UnusedActionsMatcher<>();
59 | }
60 |
61 | public static Matcher hasEnoughCoverage() {
62 | return new CoverageMatcher();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/code-assert-core/src/main/java/guru/nidi/codeassert/model/PublicMemberInInternalTypeMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.model;
17 |
18 | import org.hamcrest.Description;
19 | import org.hamcrest.TypeSafeMatcher;
20 |
21 | import java.lang.reflect.Modifier;
22 | import java.util.*;
23 | import java.util.Map.Entry;
24 |
25 | //TODO exclude interface implementing methods
26 | public class PublicMemberInInternalTypeMatcher extends TypeSafeMatcher {
27 | private final Map> findings = new HashMap<>();
28 |
29 | @Override
30 | protected boolean matchesSafely(Model model) {
31 | for (final CodeClass clazz : model.getClasses()) {
32 | if (!Modifier.isPublic(clazz.flags)) {
33 | checkMembers(clazz);
34 | }
35 | }
36 | return findings.isEmpty();
37 | }
38 |
39 | private void checkMembers(CodeClass clazz) {
40 | for (final MemberInfo member : clazz.getMembers()) {
41 | if (Modifier.isPublic(member.getAccessFlags())) {
42 | final List classFindings = findings.computeIfAbsent(clazz.getName(), s -> new ArrayList<>());
43 | classFindings.add(member.getName());
44 | }
45 | }
46 | }
47 |
48 | public void describeTo(Description description) {
49 | description.appendText("Internal types have no public members.");
50 | }
51 |
52 | @Override
53 | protected void describeMismatchSafely(Model model, Description description) {
54 | description.appendText("Found these public members in internal types:\n");
55 | for (final Entry> classFinding : findings.entrySet()) {
56 | description.appendText(classFinding.getKey() + ": " + classFinding.getValue() + "\n");
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/ktlint/KtlintCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.ktlint;
17 |
18 | import guru.nidi.codeassert.config.*;
19 |
20 | import java.util.List;
21 |
22 | import static guru.nidi.codeassert.util.ListUtils.andJoin;
23 |
24 | public class KtlintCollector extends BaseCollector {
25 | @Override
26 | public KtlintCollector config(final CollectorConfig... configs) {
27 | return new KtlintCollector() {
28 | @Override
29 | public ActionResult accept(LocatedLintError issue) {
30 | return accept(issue, KtlintCollector.this, configs);
31 | }
32 |
33 | public List unused(UsageCounter counter) {
34 | return unused(counter, KtlintCollector.this, configs);
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | return andJoin(KtlintCollector.this, configs);
40 | }
41 | };
42 | }
43 |
44 | @Override
45 | public ActionResult accept(LocatedLintError issue) {
46 | return ActionResult.accept(null, 1);
47 | }
48 |
49 | @Override
50 | protected ActionResult doAccept(LocatedLintError issue, Ignore action) {
51 | final String className = guessClassFromFile(issue.file.getAbsolutePath(), Language.KOTLIN);
52 | final Language language = Language.byFilename(issue.file.getName());
53 | return action.accept(new NamedLocation(issue.ruleId, language, className, null, true));
54 | }
55 |
56 | @Override
57 | public List unused(UsageCounter counter) {
58 | return unusedNullAction(counter, false);
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "";
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/checkstyle/CheckstyleConfigs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.checkstyle;
17 |
18 | import guru.nidi.codeassert.config.*;
19 |
20 | import static com.puppycrawl.tools.checkstyle.api.TokenTypes.*;
21 |
22 | public final class CheckstyleConfigs {
23 | private static final String VARIABLE_PATTERN = "^[a-z][a-zA-Z0-9]*$";
24 |
25 | private CheckstyleConfigs() {
26 | }
27 |
28 | public static StyleChecks.Google adjustedGoogleStyleChecks() {
29 | return StyleChecks.google()
30 | .maxLineLen(120).indentBasic(4).indentCase(4)
31 | .paramName(VARIABLE_PATTERN)
32 | .catchParamName(VARIABLE_PATTERN)
33 | .localVarName(VARIABLE_PATTERN)
34 | .memberName(VARIABLE_PATTERN)
35 | .methodName(VARIABLE_PATTERN)
36 | .emptyLineSeparatorTokens(IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
37 | STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF);
38 | }
39 |
40 | public static CollectorTemplate minimalCheckstyleIgnore() {
41 | return CollectorTemplate.of(Ignore.class)
42 | .because("I don't agree", In.everywhere()
43 | .ignore("import.avoidStar", "custom.import.order.nonGroup.expected", "custom.import.order.lex",
44 | "javadoc.packageInfo", "javadoc.missing",
45 | "multiple.variable.declarations.comma", "final.parameter",
46 | "design.forExtension", "hidden.field", "inline.conditional.avoid", "magic.number"));
47 | }
48 |
49 | public static StyleChecks.Sun adjustedSunStyleChecks() {
50 | return StyleChecks.sun().maxLineLen(120).allowDefaultAccessMembers(true);
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/CpdMatchCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import guru.nidi.codeassert.config.*;
19 | import net.sourceforge.pmd.cpd.Mark;
20 | import net.sourceforge.pmd.cpd.Match;
21 |
22 | import java.util.List;
23 |
24 | import static guru.nidi.codeassert.util.ListUtils.andJoin;
25 | import static java.util.Collections.emptyList;
26 |
27 | public class CpdMatchCollector extends BaseCollector {
28 | @Override
29 | public CpdMatchCollector config(final CollectorConfig... configs) {
30 | return new CpdMatchCollector() {
31 | @Override
32 | public ActionResult accept(Match issue) {
33 | return accept(issue, CpdMatchCollector.this, configs);
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return andJoin(CpdMatchCollector.this, configs);
39 | }
40 | };
41 | }
42 |
43 | @Override
44 | protected ActionResult doAccept(Match issue, Ignore action) {
45 | ActionResult res = ActionResult.undecided(null);
46 | for (final Mark mark : issue) {
47 | final Language language = Language.byFilename(mark.getFilename());
48 | res = res.orMoreQuality(action.accept(
49 | new NamedLocation(mark.getSourceCodeSlice(), language, PmdUtils.className(mark), "", false)));
50 | }
51 | return res;
52 | }
53 |
54 | @Override
55 | public ActionResult accept(Match issue) {
56 | return ActionResult.accept(null, 1);
57 | }
58 |
59 | @Override
60 | public List unused(UsageCounter counter) {
61 | return emptyList();
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return "";
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/PmdUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import net.sourceforge.pmd.RuleViolation;
19 | import net.sourceforge.pmd.cpd.Mark;
20 |
21 | final class PmdUtils {
22 | private PmdUtils() {
23 | }
24 |
25 | public static String className(Mark mark) {
26 | return className(null, mark.getFilename());
27 | }
28 |
29 | public static String className(RuleViolation violation) {
30 | if (violation.getClassName().length() > 0) {
31 | return (violation.getPackageName().length() > 0 ? (violation.getPackageName() + ".") : "")
32 | + violation.getClassName();
33 | }
34 | return className(violation.getPackageName(), violation.getFilename());
35 | }
36 |
37 | private static String className(String packageName, String rawFilename) {
38 | if (rawFilename.length() > 0) {
39 | final String filename = rawFilename.replace('\\', '/');
40 | final int last = filename.lastIndexOf('/');
41 | String prefix = "";
42 | if (packageName != null && packageName.length() > 0) {
43 | prefix = packageName + ".";
44 | } else {
45 | //TODO can this heuristic be improved?
46 | //TODO problem with "/graphviz-java/src/main/java/..." matches first "java/"
47 | final int src = filename.indexOf("src/") + 3;
48 | final int java = filename.indexOf("java/") + 4;
49 | final int later = Math.max(src, java);
50 | if (later >= 4) {
51 | prefix = filename.substring(later + 1, last + 1).replace('/', '.');
52 | }
53 | }
54 | return prefix + filename.substring(last + 1, filename.length() - 5);
55 | }
56 | return "?";
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/code-assert/src/main/java/guru/nidi/codeassert/pmd/PmdRuleset.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2015 Stefan Niederhauser (nidin@gmx.ch)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package guru.nidi.codeassert.pmd;
17 |
18 | import guru.nidi.codeassert.AnalyzerException;
19 | import net.sourceforge.pmd.*;
20 |
21 | import java.lang.reflect.Field;
22 |
23 | public class PmdRuleset {
24 | final String name;
25 |
26 | public PmdRuleset(String name) {
27 | this.name = name;
28 | }
29 |
30 | public void apply(RuleSets ruleSets) {
31 | for (final Field descField : getClass().getDeclaredFields()) {
32 | final PropertyField propertyField = descField.getAnnotation(PropertyField.class);
33 | if (propertyField != null) {
34 | try {
35 | descField.setAccessible(true);
36 | final Object value = descField.get(this);
37 | if (value != null) {
38 | setProperty(ruleSets, propertyField.rule(), propertyField.property(), value);
39 | }
40 | } catch (IllegalAccessException e) {
41 | throw new AnalyzerException("Could not read property " + descField.getName()
42 | + " from class " + getClass(), e);
43 | }
44 | }
45 | }
46 | }
47 |
48 | private void setProperty(RuleSets ruleSets, String rule, String property, Object value) {
49 | final Rule r = ruleSets.getRuleByName(rule);
50 | if (r == null) {
51 | throw new AnalyzerException("Rule '" + rule + "' not existing.");
52 | }
53 | final PropertyDescriptor