GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added Checkstyle target and made it happy. · toddamn/sample-java-project@80eee70

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • build.xml
  • doc
    • sun_checks.xml
  • src/sample/java/project
    • SampleJavaProject.java
    • package-info.java
  • test/sample/java/project
    • SampleJavaProjectTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎build.xml‎

Copy file name to clipboardExpand all lines: build.xml
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<property name="test.dir" value="test"/>
77
<property name="build.classes.dir" value="${build.dir}/classes"/>
88
<property name="test.classes.dir" value="${build.dir}/test"/>
9+
910
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
11+
<taskdef resource="checkstyletask.properties"/>
1012

1113
<target name="init">
1214
<mkdir dir="${build.classes.dir}"/>
@@ -56,6 +58,12 @@
5658
</for>
5759
</target>
5860

61+
<target name="check">
62+
<checkstyle config="doc/sun_checks.xml">
63+
<fileset dir="src" includes="**/*.java"/>
64+
</checkstyle>
65+
</target>
66+
5967
<!-- JUnit -->
6068

6169
<target name="test-init" depends="init">
Collapse file

‎doc/sun_checks.xml‎

Copy file name to clipboard
+189Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration that checks the sun coding conventions from:
9+
10+
- the Java Language Specification at
11+
http://java.sun.com/docs/books/jls/second_edition/html/index.html
12+
13+
- the Sun Code Conventions at http://java.sun.com/docs/codeconv/
14+
15+
- the Javadoc guidelines at
16+
http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
17+
18+
- the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
19+
20+
- some best practices
21+
22+
Checkstyle is very configurable. Be sure to read the documentation at
23+
http://checkstyle.sf.net (or in your downloaded distribution).
24+
25+
Most Checks are configurable, be sure to consult the documentation.
26+
27+
To completely disable a check, just comment it out or delete it from the file.
28+
29+
Finally, it is worth reading the documentation.
30+
31+
-->
32+
33+
<module name="Checker">
34+
<!--
35+
If you set the basedir property below, then all reported file
36+
names will be relative to the specified directory. See
37+
http://checkstyle.sourceforge.net/5.x/config.html#Checker
38+
39+
<property name="basedir" value="${basedir}"/>
40+
-->
41+
42+
<!-- Checks that a package-info.java file exists for each package. -->
43+
<!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
44+
<module name="JavadocPackage"/>
45+
46+
<!-- Checks whether files end with a new line. -->
47+
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
48+
<module name="NewlineAtEndOfFile"/>
49+
50+
<!-- Checks that property files contain the same keys. -->
51+
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
52+
<module name="Translation"/>
53+
54+
<!-- Checks for Size Violations. -->
55+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
56+
<module name="FileLength"/>
57+
58+
<!-- Checks for whitespace -->
59+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
60+
<module name="FileTabCharacter"/>
61+
62+
<!-- Miscellaneous other checks. -->
63+
<!-- See http://checkstyle.sf.net/config_misc.html -->
64+
<module name="RegexpSingleline">
65+
<property name="format" value="\s+$"/>
66+
<property name="minimum" value="0"/>
67+
<property name="maximum" value="0"/>
68+
<property name="message" value="Line has trailing spaces."/>
69+
</module>
70+
71+
<module name="TreeWalker">
72+
73+
<!-- Checks for Javadoc comments. -->
74+
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
75+
<module name="JavadocMethod"/>
76+
<module name="JavadocType"/>
77+
<module name="JavadocVariable"/>
78+
<module name="JavadocStyle"/>
79+
80+
81+
<!-- Checks for Naming Conventions. -->
82+
<!-- See http://checkstyle.sf.net/config_naming.html -->
83+
<module name="ConstantName"/>
84+
<module name="LocalFinalVariableName"/>
85+
<module name="LocalVariableName"/>
86+
<module name="MemberName"/>
87+
<module name="MethodName"/>
88+
<module name="PackageName"/>
89+
<module name="ParameterName"/>
90+
<module name="StaticVariableName"/>
91+
<module name="TypeName"/>
92+
93+
94+
<!-- Checks for Headers -->
95+
<!-- See http://checkstyle.sf.net/config_header.html -->
96+
<!-- <module name="Header"> -->
97+
<!-- The follow property value demonstrates the ability -->
98+
<!-- to have access to ANT properties. In this case it uses -->
99+
<!-- the ${basedir} property to allow Checkstyle to be run -->
100+
<!-- from any directory within a project. See property -->
101+
<!-- expansion, -->
102+
<!-- http://checkstyle.sf.net/config.html#properties -->
103+
<!-- <property -->
104+
<!-- name="headerFile" -->
105+
<!-- value="${basedir}/java.header"/> -->
106+
<!-- </module> -->
107+
108+
<!-- Following interprets the header file as regular expressions. -->
109+
<!-- <module name="RegexpHeader"/> -->
110+
111+
112+
<!-- Checks for imports -->
113+
<!-- See http://checkstyle.sf.net/config_import.html -->
114+
<module name="AvoidStarImport"/>
115+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
116+
<module name="RedundantImport"/>
117+
<module name="UnusedImports"/>
118+
119+
120+
<!-- Checks for Size Violations. -->
121+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
122+
<module name="LineLength"/>
123+
<module name="MethodLength"/>
124+
<module name="ParameterNumber"/>
125+
126+
127+
<!-- Checks for whitespace -->
128+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
129+
<module name="EmptyForIteratorPad"/>
130+
<module name="GenericWhitespace"/>
131+
<module name="MethodParamPad"/>
132+
<module name="NoWhitespaceAfter"/>
133+
<module name="NoWhitespaceBefore"/>
134+
<module name="OperatorWrap"/>
135+
<module name="ParenPad"/>
136+
<module name="TypecastParenPad"/>
137+
<module name="WhitespaceAfter"/>
138+
<module name="WhitespaceAround"/>
139+
140+
141+
<!-- Modifier Checks -->
142+
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
143+
<module name="ModifierOrder"/>
144+
<module name="RedundantModifier"/>
145+
146+
147+
<!-- Checks for blocks. You know, those {}'s -->
148+
<!-- See http://checkstyle.sf.net/config_blocks.html -->
149+
<module name="AvoidNestedBlocks"/>
150+
<module name="EmptyBlock"/>
151+
<module name="LeftCurly"/>
152+
<module name="NeedBraces"/>
153+
<module name="RightCurly"/>
154+
155+
156+
<!-- Checks for common coding problems -->
157+
<!-- See http://checkstyle.sf.net/config_coding.html -->
158+
<module name="AvoidInlineConditionals"/>
159+
<module name="DoubleCheckedLocking"/> <!-- MY FAVOURITE -->
160+
<module name="EmptyStatement"/>
161+
<module name="EqualsHashCode"/>
162+
<module name="HiddenField"/>
163+
<module name="IllegalInstantiation"/>
164+
<module name="InnerAssignment"/>
165+
<module name="MagicNumber"/>
166+
<module name="MissingSwitchDefault"/>
167+
<module name="RedundantThrows"/>
168+
<module name="SimplifyBooleanExpression"/>
169+
<module name="SimplifyBooleanReturn"/>
170+
171+
<!-- Checks for class design -->
172+
<!-- See http://checkstyle.sf.net/config_design.html -->
173+
<module name="DesignForExtension"/>
174+
<module name="FinalClass"/>
175+
<module name="HideUtilityClassConstructor"/>
176+
<module name="InterfaceIsType"/>
177+
<module name="VisibilityModifier"/>
178+
179+
180+
<!-- Miscellaneous other checks. -->
181+
<!-- See http://checkstyle.sf.net/config_misc.html -->
182+
<module name="ArrayTypeStyle"/>
183+
<module name="FinalParameters"/>
184+
<module name="TodoComment"/>
185+
<module name="UpperEll"/>
186+
187+
</module>
188+
189+
</module>
Collapse file

‎src/sample/java/project/SampleJavaProject.java‎

Copy file name to clipboard
+27-3Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
package sample.java.project;
22

3+
/**
4+
* The main class.
5+
*
6+
* This is the main class of the application. It contains the main()
7+
* method, the first method called.
8+
*/
39
public class SampleJavaProject {
4-
public static void main(String[] args) {
5-
System.out.println("Hello world!");
10+
11+
/**
12+
* The main class.
13+
*
14+
* Print the "Hello, world!" string.
15+
*
16+
* @param args application input arguments
17+
*/
18+
public static void main(final String[] args) {
19+
System.out.println("Hello, world!");
620
}
721

8-
public int add(int a, int b) {
22+
/**
23+
* Add two integers together.
24+
*
25+
* This is a dumb method that is here for the purposed of unit
26+
* testing.
27+
*
28+
* @param a first number
29+
* @param b second number
30+
* @return sum of the numbers
31+
*/
32+
public final int add(final int a, final int b) {
933
return a + b;
1034
}
1135
}
Collapse file

‎src/sample/java/project/package-info.java‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* An example ant-based Java project.
3+
*/
4+
package sample.java.project;
Collapse file

‎test/sample/java/project/SampleJavaProjectTest.java‎

Copy file name to clipboardExpand all lines: test/sample/java/project/SampleJavaProjectTest.java
+25-5Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,38 @@
22

33
import junit.framework.TestCase;
44

5+
/**
6+
* A sample JUnit test.
7+
*
8+
* This test exists as a placeholder for the test unit framework.
9+
*/
510
public class SampleJavaProjectTest extends TestCase {
6-
public SampleJavaProjectTest(String name) {
11+
12+
/**
13+
* JUnit boilerplate.
14+
*
15+
* @param name the name string
16+
*/
17+
public SampleJavaProjectTest(final String name) {
718
super(name);
819
}
920

10-
SampleJavaProject sjp;
21+
/**
22+
* Holds an instance of the class we are testing.
23+
*/
24+
private SampleJavaProject sjp;
1125

12-
public void setUp() {
26+
/**
27+
* JUnit set up method.
28+
*/
29+
public final void setUp() {
1330
sjp = new SampleJavaProject();
1431
}
1532

16-
public void testAdd() {
17-
assert(sjp.add(3, 4) == 7);
33+
/**
34+
* Tests the add() method in the main class.
35+
*/
36+
public final void testAdd() {
37+
assertEquals(sjp.add(3, 4), 7);
1838
}
1939
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.