Skip to content

Commit 75617a5

Browse files
authored
Merge pull request #2 from swesteme/main
Updated project settings and code style.
2 parents c64300c + fd1ea6f commit 75617a5

18 files changed

+368
-53
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.idea
22
target
33
work
4-
multiselect-parameter-plugin.iml
4+
*.iml
5+
.classpath
6+
.project

.mvn/checkstyle-suppressions.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
5+
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
6+
7+
<suppressions>
8+
<suppress files="release\.properties" checks="[a-zA-Z0-9]*"/>
9+
<suppress files=".+\.properties" checks=".+" />
10+
</suppressions>

.mvn/checkstyle.xml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?xml version="1.0"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
-->
19+
20+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
21+
22+
<!-- commons math customization of default Checkstyle behavior -->
23+
<module name="Checker">
24+
<property name="localeLanguage" value="en"/>
25+
26+
<module name="TreeWalker">
27+
28+
<module name="Indentation">
29+
<property name="caseIndent" value="0"/>
30+
</module>
31+
32+
<!-- Operator must be at end of wrapped line -->
33+
<module name="OperatorWrap">
34+
<property name="option" value="eol"/>
35+
</module>
36+
37+
<!-- No if/else/do/for/while without braces -->
38+
<module name="NeedBraces"/>
39+
<module name="LeftCurly"/>
40+
<module name="RightCurly"/>
41+
42+
<!-- Interfaces must be types (not just constants) -->
43+
<module name="InterfaceIsType"/>
44+
45+
<!-- Must have class / interface header comments -->
46+
<module name="JavadocType">
47+
<property name="scope" value="public"/>
48+
</module>
49+
50+
<!-- Require method javadocs, allow undeclared RTE -->
51+
<module name="JavadocMethod"/>
52+
53+
<module name="AvoidNestedBlocks"/>
54+
55+
<module name="EmptyCatchBlock">
56+
<property name="exceptionVariableName" value="expected|ignore"/>
57+
</module>
58+
59+
<!-- Require field javadoc -->
60+
<module name="JavadocVariable"/>
61+
62+
<!-- No public fields -->
63+
<module name="VisibilityModifier">
64+
<property name="protectedAllowed" value="true"/>
65+
</module>
66+
67+
<!-- Require hash code override when equals is -->
68+
<module name="EqualsHashCode"/>
69+
70+
<!-- Disallow unnecessary instantiation of Boolean, String -->
71+
<module name="IllegalInstantiation">
72+
<property name="classes" value="java.lang.Boolean, java.lang.String"/>
73+
</module>
74+
75+
<!-- Import should be explicit, really needed and only from pure java packages -->
76+
<module name="AvoidStarImport"/>
77+
<module name="UnusedImports"/>
78+
<module name="IllegalImport"/>
79+
80+
<!-- Utility class should not be instantiated, they must have a private constructor -->
81+
<module name="HideUtilityClassConstructor"/>
82+
83+
<!-- Switch statements should be complete and with independent cases -->
84+
<module name="FallThrough"/>
85+
<module name="MissingSwitchDefault"/>
86+
87+
<!-- Constant names should obey the traditional all uppercase naming convention -->
88+
<module name="ConstantName"/>
89+
90+
<!-- Method parameters and local variables should not hide fields, except in constructors and setters -->
91+
<module name="HiddenField">
92+
<property name="ignoreConstructorParameter" value="true"/>
93+
<property name="ignoreSetter" value="true"/>
94+
</module>
95+
96+
<!-- No trailing whitespace -->
97+
<module name="Regexp">
98+
<property name="format" value="[ \t]+$"/>
99+
<property name="illegalPattern" value="true"/>
100+
<property name="message" value="Trailing whitespace"/>
101+
</module>
102+
103+
<!-- No System.out.println() statements -->
104+
<module name="Regexp">
105+
<!-- no sysouts -->
106+
<property name="format" value="System\.out\.println"/>
107+
<property name="illegalPattern" value="true"/>
108+
</module>
109+
110+
<!-- Authors should be in pom.xml file -->
111+
<module name="Regexp">
112+
<property name="format" value="@author"/>
113+
<property name="illegalPattern" value="true"/>
114+
<property name="message" value="developers names should be in pom file"/>
115+
</module>
116+
117+
<!-- Use a consistent way to put modifiers -->
118+
<module name="RedundantModifier"/>
119+
<module name="ModifierOrder"/>
120+
121+
<!-- Use a consistent way to put declarations -->
122+
<module name="DeclarationOrder"/>
123+
124+
<!-- Don't add up parentheses when they are not required -->
125+
<module name="UnnecessaryParentheses"/>
126+
127+
<!-- Don't use = or != for string comparisons -->
128+
<module name="StringLiteralEquality"/>
129+
130+
<!-- Don't declare multiple variables in the same statement -->
131+
<module name="MultipleVariableDeclarations"/>
132+
133+
<!-- String literals more than one character long should not be repeated several times -->
134+
<!-- the "unchecked" string is also accepted to allow @SuppressWarnings("unchecked") -->
135+
<module name="MultipleStringLiterals">
136+
<property name="ignoreStringsRegexp" value='^(("")|(".")|("unchecked"))$'/>
137+
</module>
138+
139+
</module>
140+
141+
<!-- No tabs allowed! -->
142+
<module name="FileTabCharacter"/>
143+
144+
<!-- Require files to end with newline characters -->
145+
<module name="NewlineAtEndOfFile"/>
146+
147+
<!-- Require package javadoc -->
148+
<module name="JavadocPackage"/>
149+
</module>

pom.xml

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<groupId>io.jenkins.plugins</groupId>
1111
<artifactId>multiselect-parameter</artifactId>
1212
<version>1.2-SNAPSHOT</version>
13-
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
13+
<url>https://github.com/jenkinsci/${project.artifactId}-plugin/blob/main/README.md</url>
1414
<packaging>hpi</packaging>
1515
<properties>
1616
<jenkins.version>2.235.1</jenkins.version>
@@ -26,6 +26,33 @@
2626
<email>jenkins@westemeyer.de</email>
2727
</developer>
2828
</developers>
29+
30+
<profiles>
31+
<profile>
32+
<id>jacoco</id>
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.jacoco</groupId>
37+
<artifactId>jacoco-maven-plugin</artifactId>
38+
<executions>
39+
<execution>
40+
<goals>
41+
<goal>prepare-agent</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
<configuration>
46+
<excludes>
47+
<exclude>**/Messages.class</exclude>
48+
</excludes>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</profile>
54+
</profiles>
55+
2956
<licenses>
3057
<license>
3158
<name>MIT License</name>
@@ -58,7 +85,44 @@
5885
</dependency>
5986
</dependencies>
6087
<build>
88+
<pluginManagement>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-checkstyle-plugin</artifactId>
93+
<version>3.1.1</version>
94+
<dependencies>
95+
<dependency>
96+
<groupId>com.puppycrawl.tools</groupId>
97+
<artifactId>checkstyle</artifactId>
98+
<version>8.36.2</version>
99+
</dependency>
100+
</dependencies>
101+
</plugin>
102+
</plugins>
103+
</pluginManagement>
61104
<plugins>
105+
<plugin>
106+
<artifactId>maven-checkstyle-plugin</artifactId>
107+
<configuration>
108+
<configLocation>${project.basedir}/.mvn/checkstyle.xml</configLocation>
109+
<suppressionsLocation>${project.basedir}/.mvn/checkstyle-suppressions.xml</suppressionsLocation>
110+
<includeTestSourceDirectory>false</includeTestSourceDirectory>
111+
<sourceDirectories>
112+
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
113+
</sourceDirectories>
114+
<testSourceDirectories>
115+
<sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
116+
</testSourceDirectories>
117+
</configuration>
118+
<executions>
119+
<execution>
120+
<goals>
121+
<goal>check</goal>
122+
</goals>
123+
</execution>
124+
</executions>
125+
</plugin>
62126
<plugin>
63127
<artifactId>maven-javadoc-plugin</artifactId>
64128
<configuration>

src/main/java/de/westemeyer/plugins/multiselect/MultiselectDecisionTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class MultiselectDecisionTree implements Serializable {
3636
private List<MultiselectDecisionItem> itemList = new ArrayList<>();
3737

3838
/** Meta information about build variables/columns. */
39-
List<MultiselectVariableDescriptor> variableDescriptions = new ArrayList<>();
39+
private List<MultiselectVariableDescriptor> variableDescriptions = new ArrayList<>();
4040

4141
/**
4242
* Get initial values for column when first displaying list of select boxes in "build with parameters" view.

src/main/java/de/westemeyer/plugins/multiselect/MultiselectParameterDefinition.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class MultiselectParameterDefinition extends ParameterDefinition {
3838
/** Logger for this object. */
3939
private static final Logger LOGGER = Logger.getLogger(MultiselectParameterDefinition.class.getName());
4040

41+
/** Configured parameter name constant. */
42+
private static final String PARAMETER_NAME = "name";
43+
4144
/** Job CSV configuration content. */
4245
private MultiselectDecisionTree decisionTree;
4346

@@ -72,13 +75,13 @@ public String[] getItemList(Integer[] coordinates) {
7275
Queue<Integer> itemPath = createCoordinates(coordinates);
7376
List<String> returnList = new ArrayList<>();
7477
try {
75-
decisionTree.visitSelectedItems(itemPath, ((item, column) -> {
78+
decisionTree.visitSelectedItems(itemPath, (item, column) -> {
7679
// return values from last coordinate
7780
if (itemPath.isEmpty()) {
7881
item.getChildren().forEach(child -> returnList.add(child.getDisplayLabel()));
7982
}
8083
return true;
81-
}));
84+
});
8285
} catch (Exception e) {
8386
LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
8487
}
@@ -124,7 +127,7 @@ public MultiselectParameterValue createValue(Map<String, Object> jsonObject) {
124127
// convert json object to map of strings to integers (values from parameter form)
125128
jsonObject.forEach((key, value) -> {
126129
// exclude parameter name
127-
if (!key.equals("name") && value instanceof String && ((String) value).length() > 0) {
130+
if (!key.equals(PARAMETER_NAME) && value instanceof String && ((String) value).length() > 0) {
128131
try {
129132
// store new key combination in map
130133
selectedValues.put(key, Integer.valueOf((String) value));
@@ -230,7 +233,7 @@ public String getDisplayName() {
230233

231234
@Override
232235
public ParameterDefinition newInstance(@Nullable StaplerRequest req, @Nonnull JSONObject formData) {
233-
return newInstance(formData.getString("configuration"), formData.getString("name"), formData.getString("description"));
236+
return newInstance(formData.getString("configuration"), formData.getString(PARAMETER_NAME), formData.getString("description"));
234237
}
235238

236239
/**

src/main/java/de/westemeyer/plugins/multiselect/UUIDGenerator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ class UUIDGenerator {
1111
private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyzABZDEFGHIJKLMNOPQRSTUVWXYZ";
1212

1313
/** Random number generator. */
14-
static final SecureRandom numberGenerator = new SecureRandom();
14+
private static final SecureRandom NUMBER_GENERATOR = new SecureRandom();
15+
16+
/**
17+
* Private constructor for utility class.
18+
*/
19+
private UUIDGenerator() {
20+
}
1521

1622
/**
1723
* Static method to generate a new UUID.
24+
* @param length length of generated UUID
1825
* @return new UUID
1926
*/
2027
static String generateUUID(int length) {
@@ -23,7 +30,7 @@ static String generateUUID(int length) {
2330

2431
// concatenate 30 random characters
2532
for (int i = 0; i < length; ++i) {
26-
uuid.append(ALPHABET.charAt(numberGenerator.nextInt(ALPHABET.length() - 1)));
33+
uuid.append(ALPHABET.charAt(NUMBER_GENERATOR.nextInt(ALPHABET.length() - 1)));
2734
}
2835

2936
// return new string from builder object
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Main package for multiselect parameters plugin.
3+
*/
4+
package de.westemeyer.plugins.multiselect;

src/main/java/de/westemeyer/plugins/multiselect/parser/CsvParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Parser implementation to use for CSV configuration type.
2222
*/
2323
public class CsvParser implements ConfigParser {
24+
/** Logger for csv parser. */
2425
private static final Logger LOGGER = Logger.getLogger(CsvParser.class.getName());
2526

2627
/** Form validation result, null if everything is OK. */

src/main/java/de/westemeyer/plugins/multiselect/parser/ValueConstructionHelper.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* keep a map inside the parameter values themselves.
1414
*/
1515
public class ValueConstructionHelper {
16+
/** Delimiter for toString output. */
17+
private static final String DELIMITER = ", ";
18+
1619
/** Lookup table. */
1720
private final Map<String, ValueConstructionHelper> lookup = new LinkedHashMap<>();
1821

@@ -56,10 +59,10 @@ public MultiselectDecisionItem getDecisionItem() {
5659
@Override
5760
public String toString() {
5861
if (decisionItem == null) {
59-
return String.join(", ", lookup.keySet());
62+
return String.join(DELIMITER, lookup.keySet());
6063
}
6164

62-
return decisionItem.getValue() + " -> " + String.join(", ", lookup.keySet());
65+
return decisionItem.getValue() + " -> " + String.join(DELIMITER, lookup.keySet());
6366
}
6467

6568
/**
@@ -73,13 +76,13 @@ public List<MultiselectDecisionItem> createItemList() {
7376
// iterate lookup table
7477
lookup.values().forEach(helper -> {
7578
// get the value...
76-
MultiselectDecisionItem decisionItem = helper.getDecisionItem();
79+
MultiselectDecisionItem item = helper.getDecisionItem();
7780

7881
// ... add it to list of child items
79-
items.add(decisionItem);
82+
items.add(item);
8083

8184
// ... and set its children recursively
82-
decisionItem.setChildren(helper.createItemList());
85+
item.setChildren(helper.createItemList());
8386
});
8487

8588
// return list of items

0 commit comments

Comments
 (0)