Skip to content

Commit 16d1384

Browse files
committed
Added findbugs to the build
Added comments
1 parent 08f1aed commit 16d1384

14 files changed

+312
-81
lines changed

pom.xml

+26
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,30 @@
2626
<scope>test</scope>
2727
</dependency>
2828
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.codehaus.mojo</groupId>
34+
<artifactId>findbugs-maven-plugin</artifactId>
35+
<version>3.0.4</version>
36+
<configuration>
37+
<effort>Max</effort>
38+
<threshold>Low</threshold>
39+
<xmlOutput>true</xmlOutput>
40+
<failOnError>false</failOnError>
41+
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<id>analyze-compile</id>
46+
<phase>compile</phase>
47+
<goals>
48+
<goal>check</goal>
49+
</goals>
50+
</execution>
51+
</executions>
52+
</plugin>
53+
</plugins>
54+
</build>
2955
</project>

src/main/java/it/jnrpe/yaclp/Argument.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import java.util.List;

src/main/java/it/jnrpe/yaclp/ArgumentBuilder.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

18+
/**
19+
* Builds an argument parser.
20+
*/
321
public class ArgumentBuilder {
422
private final String name;
523
private boolean mandatory = true;
@@ -8,15 +26,29 @@ private ArgumentBuilder(final String name) {
826
this.name = name;
927
}
1028

29+
/**
30+
* Returns an instance of the builder for an argument with the given name.
31+
* @param name the name of the argument
32+
* @return the builder
33+
*/
1134
public static ArgumentBuilder forArgument(final String name) {
1235
return new ArgumentBuilder(name);
1336
}
1437

15-
public ArgumentBuilder mandatory(boolean mandatory) {
38+
/**
39+
* Whether the argument is mandatory or not
40+
* @param mandatory Whether the argument is mandatory or not
41+
* @return the builder
42+
*/
43+
public ArgumentBuilder mandatory(final boolean mandatory) {
1644
this.mandatory = mandatory;
1745
return this;
1846
}
1947

48+
/**
49+
* Builds the argument with the provided options.
50+
* @return the newly build argument
51+
*/
2052
public IArgument build() {
2153
return new Argument(name, mandatory);
2254
}

src/main/java/it/jnrpe/yaclp/CommandLine.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import java.util.ArrayList;

src/main/java/it/jnrpe/yaclp/HelpFormatter.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import it.jnrpe.yaclp.help.OptionHelpFormatter;
@@ -6,6 +21,9 @@
621
import java.io.PrintStream;
722
import java.util.List;
823

24+
/**
25+
* Utility class for providing help info.
26+
*/
927
public class HelpFormatter {
1028

1129
private final String appName;
@@ -51,9 +69,6 @@ private int getOptionLength(IOption opt) {
5169
}
5270

5371
private String formatUsage() {
54-
StringBuilder usage = new StringBuilder(appName)
55-
.append(" ");
56-
5772
List<IOption> options = parser.getOptions();
5873
String[] opts = new String[options.size()];
5974
for (int i = 0; i < opts.length; i++) {
+15-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

3-
/**
4-
* Created by ziccardi on 11/01/2017.
5-
*/
618
public interface IArgument {
719
String getName();
820
}

src/main/java/it/jnrpe/yaclp/IOption.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import java.util.List;

src/main/java/it/jnrpe/yaclp/MutuallyExclusiveOptionBuilder.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import java.util.ArrayList;
419
import java.util.List;
520

621
/**
7-
* Created by ziccardi on 11/01/2017.
22+
* Builder for mutually exclusive options
823
*/
924
public class MutuallyExclusiveOptionBuilder {
1025
private List<IOption> options = new ArrayList<IOption>();
@@ -14,21 +29,40 @@ public class MutuallyExclusiveOptionBuilder {
1429
MutuallyExclusiveOptionBuilder() {
1530
}
1631

32+
/**
33+
* Call this method many time to add all the options than can't be specified together.
34+
* @param option the option
35+
* @return the builder
36+
*/
1737
public MutuallyExclusiveOptionBuilder withOption(final IOption option) {
1838
this.options.add(option);
1939
return this;
2040
}
2141

42+
/**
43+
* If mandatory, one of the option MUST be present in the command line
44+
* @param mandatory whether the option is mandatory or not
45+
* @return the builder
46+
*/
2247
public MutuallyExclusiveOptionBuilder mandatory(boolean mandatory) {
2348
this.mandatory = mandatory;
2449
return this;
2550
}
2651

52+
/**
53+
* Description for this mutually exlusive option group.
54+
* @param description the description
55+
* @return the builder
56+
*/
2757
public MutuallyExclusiveOptionBuilder description(final String description) {
2858
this.description = description;
2959
return this;
3060
}
3161

62+
/**
63+
* Builds the option as configured.
64+
* @return the newly build option
65+
*/
3266
public IOption build() {
3367
MutuallyExclusiveOptions opt = new MutuallyExclusiveOptions(options.toArray(new IOption[options.size()]));
3468
opt.setMandatory(mandatory);

src/main/java/it/jnrpe/yaclp/MutuallyExclusiveOptions.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import org.apache.commons.lang.StringUtils;

src/main/java/it/jnrpe/yaclp/Option.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

318
import java.util.ArrayList;

src/main/java/it/jnrpe/yaclp/OptionBuilder.java

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Massimiliano Ziccardi
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+
*******************************************************************************/
116
package it.jnrpe.yaclp;
217

18+
/**
19+
* Entry point for option builders.
20+
*/
321
public class OptionBuilder {
422

523
public static SimpleOptionBuilder forOption(final String shortName, final String longName){

0 commit comments

Comments
 (0)