You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2024/09/19 17:00:37 UTC
(httpcomponents-stylecheck) branch master updated (04b5788 -> 07cff17)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-stylecheck.git
discard 04b5788 Added custom TestCase method visibility check
new 69b674f Updated NOTICE
new e6a6a12 Added custom TestCase method visibility check
new 07cff17 Added EmptyCatchBlockCheck, DefaultComesLastCheck, UnnecessaryParenthesesCheck, UnusedLocalVariableCheck, GenericWhitespaceCheck, SingleSpaceSeparatorCheck and WhitespaceAroundCheck
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (04b5788)
\
N -- N -- N refs/heads/master (07cff17)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
NOTICE.txt | 2 +-
pom.xml | 9 ---------
src/main/resources/hc-stylecheck/default.xml | 27 +++++++++++++++++++++++++++
3 files changed, 28 insertions(+), 10 deletions(-)
(httpcomponents-stylecheck) 02/03: Added custom TestCase method visibility check
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-stylecheck.git
commit e6a6a1291104de4e770711de3f93c54dd0799111
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Sep 19 11:53:45 2024 +0200
Added custom TestCase method visibility check
---
pom.xml | 60 ++++++++++--
.../stylecheck/TestCaseMethodVisibilityCheck.java | 102 +++++++++++++++++++++
src/main/resources/hc-stylecheck/default.xml | 10 ++
.../org/apache/hc/stylecheck/messages.properties | 1 +
4 files changed, 163 insertions(+), 10 deletions(-)
diff --git a/pom.xml b/pom.xml
index 78bafb8..4daf852 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,17 +38,57 @@
<description>Shared stylecheck plugin configuration for Apache HttpComponents projects</description>
<packaging>jar</packaging>
- <organization>
- <name>The Apache Software Foundation</name>
- <url>http://www.apache.org/</url>
- </organization>
+ <organization>
+ <name>The Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
- <scm>
- <connection>scm:git:https://git-wip-us.apache.org/repos/asf/httpcomponents-stylecheck.git</connection>
- <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/httpcomponents-stylecheck.git</developerConnection>
- <url>https://github.com/apache/httpcomponents-stylecheck/tree/${project.scm.tag}</url>
- <tag>master</tag>
- </scm>
+ <scm>
+ <connection>scm:git:https://git-wip-us.apache.org/repos/asf/httpcomponents-stylecheck.git</connection>
+ <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/httpcomponents-stylecheck.git</developerConnection>
+ <url>https://github.com/apache/httpcomponents-stylecheck/tree/${project.scm.tag}</url>
+ <tag>master</tag>
+ </scm>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
+ <checkstyle.version>9.3</checkstyle.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${checkstyle.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!-- org.apache.maven.plugins, alpha order by artifact id -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>${maven.compiler.source}</source>
+ <target>${maven.compiler.target}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
<profiles>
<profile>
diff --git a/src/main/java/org/apache/hc/stylecheck/TestCaseMethodVisibilityCheck.java b/src/main/java/org/apache/hc/stylecheck/TestCaseMethodVisibilityCheck.java
new file mode 100644
index 0000000..f71400d
--- /dev/null
+++ b/src/main/java/org/apache/hc/stylecheck/TestCaseMethodVisibilityCheck.java
@@ -0,0 +1,102 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.stylecheck;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+
+import com.puppycrawl.tools.checkstyle.StatelessCheck;
+import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.TokenTypes;
+import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
+import com.puppycrawl.tools.checkstyle.utils.TokenUtil;
+
+@StatelessCheck
+public final class TestCaseMethodVisibilityCheck extends AbstractCheck {
+
+ private static final Set<String> TARGET_ANNOTATIONS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ "BeforeAll",
+ "BeforeEach",
+ "Test",
+ "AfterEach",
+ "AfterAll")));
+
+ public static final String MSG_KEY = "testcase.method.visibility";
+
+ @Override
+ public int[] getDefaultTokens() {
+ return getAcceptableTokens();
+ }
+
+ @Override
+ public int[] getRequiredTokens() {
+ return CommonUtil.EMPTY_INT_ARRAY;
+ }
+
+ @Override
+ public int[] getAcceptableTokens() {
+ return new int[]{
+ TokenTypes.METHOD_DEF
+ };
+ }
+
+ @Override
+ public void visitToken(final DetailAST ast) {
+ if (ast.getType() == TokenTypes.METHOD_DEF && isAnnotatedAsTest(ast)) {
+ final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
+ final DetailAST publicModifier = modifiers.findFirstToken(TokenTypes.LITERAL_PUBLIC);
+ if (publicModifier != null) {
+ log(publicModifier, MSG_KEY, "public");
+ }
+ DetailAST privateModifier = modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE);
+ if (privateModifier != null) {
+ log(modifiers, MSG_KEY, "private");
+ }
+ }
+ }
+
+ private static boolean isAnnotatedAsTest(DetailAST methodDef) {
+ final DetailAST modifiers = methodDef.findFirstToken(TokenTypes.MODIFIERS);
+ final Optional<DetailAST> annotation = TokenUtil.findFirstTokenByPredicate(modifiers, currentToken ->
+ currentToken.getType() == TokenTypes.ANNOTATION && TARGET_ANNOTATIONS.contains(getAnnotationName(currentToken)));
+ return annotation.isPresent();
+ }
+
+ private static String getAnnotationName(DetailAST annotation) {
+ final DetailAST dotAst = annotation.findFirstToken(TokenTypes.DOT);
+ if (dotAst == null) {
+ return annotation.findFirstToken(TokenTypes.IDENT).getText();
+ } else {
+ return dotAst.findFirstToken(TokenTypes.IDENT).getText();
+ }
+ }
+
+}
diff --git a/src/main/resources/hc-stylecheck/default.xml b/src/main/resources/hc-stylecheck/default.xml
index dd0b39b..1ddd771 100644
--- a/src/main/resources/hc-stylecheck/default.xml
+++ b/src/main/resources/hc-stylecheck/default.xml
@@ -21,6 +21,15 @@
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
+<!--
+
+Version 3 - changes since 2
+=====================================
+
+Added org.apache.hc.stylecheck.TestCaseMethodVisibilityCheck
+
+-->
+
<module name="Checker">
<module name="TreeWalker">
<module name="AvoidStarImport"/>
@@ -36,6 +45,7 @@
<module name="MissingDeprecated"/>
<module name="MissingOverride"/>
<module name="EmptyStatement"/>
+ <module name="org.apache.hc.stylecheck.TestCaseMethodVisibilityCheck"/>
</module>
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}" />
diff --git a/src/main/resources/org/apache/hc/stylecheck/messages.properties b/src/main/resources/org/apache/hc/stylecheck/messages.properties
new file mode 100644
index 0000000..3cdb2f5
--- /dev/null
+++ b/src/main/resources/org/apache/hc/stylecheck/messages.properties
@@ -0,0 +1 @@
+testcase.method.visibility=Test method has {0} visibility. It should be package private.
\ No newline at end of file
(httpcomponents-stylecheck) 01/03: Updated NOTICE
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-stylecheck.git
commit 69b674f8f58bdc4324f41971df6fc5e57adbe763
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Sep 19 13:02:25 2024 +0200
Updated NOTICE
---
NOTICE.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/NOTICE.txt b/NOTICE.txt
index 17da355..5fc5f59 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
Apache HttpComponents Stylecheck Plugin Configuration
-Copyright 2013-2020 The Apache Software Foundation
+Copyright 2013-2024 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
(httpcomponents-stylecheck) 03/03: Added EmptyCatchBlockCheck, DefaultComesLastCheck, UnnecessaryParenthesesCheck, UnusedLocalVariableCheck, GenericWhitespaceCheck, SingleSpaceSeparatorCheck and WhitespaceAroundCheck
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-stylecheck.git
commit 07cff17a54e5e5768efff98ab285cb408de91d87
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Sep 19 18:59:55 2024 +0200
Added EmptyCatchBlockCheck, DefaultComesLastCheck, UnnecessaryParenthesesCheck, UnusedLocalVariableCheck, GenericWhitespaceCheck, SingleSpaceSeparatorCheck and WhitespaceAroundCheck
---
src/main/resources/hc-stylecheck/default.xml | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/main/resources/hc-stylecheck/default.xml b/src/main/resources/hc-stylecheck/default.xml
index 1ddd771..8407430 100644
--- a/src/main/resources/hc-stylecheck/default.xml
+++ b/src/main/resources/hc-stylecheck/default.xml
@@ -27,6 +27,13 @@ Version 3 - changes since 2
=====================================
Added org.apache.hc.stylecheck.TestCaseMethodVisibilityCheck
+Added EmptyCatchBlockCheck
+Added DefaultComesLastCheck
+Added UnnecessaryParenthesesCheck
+Added UnusedLocalVariableCheck
+Added GenericWhitespaceCheck
+Added SingleSpaceSeparatorCheck
+Added WhitespaceAroundCheck
-->
@@ -46,6 +53,17 @@ Added org.apache.hc.stylecheck.TestCaseMethodVisibilityCheck
<module name="MissingOverride"/>
<module name="EmptyStatement"/>
<module name="org.apache.hc.stylecheck.TestCaseMethodVisibilityCheck"/>
+ <module name="EmptyCatchBlockCheck">
+ <property name="exceptionVariableName" value="^(expected|ignore|ignored)$"/>
+ </module>
+ <module name="DefaultComesLastCheck"/>
+ <module name="UnnecessaryParenthesesCheck"/>
+ <module name="UnusedLocalVariableCheck"/>
+ <module name="GenericWhitespaceCheck"/>
+ <module name="SingleSpaceSeparatorCheck"/>
+ <module name="WhitespaceAroundCheck">
+ <property name="ignoreEnhancedForColon" value="true"/>
+ </module>
</module>
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}" />