This week's book giveaway is in the Flex forum.
We're giving away four copies of Flex 4 in Action and have Tariq Ahmed, Dan Orlando, John C. Bland II & Joel Hooks on-line!
See this thread for details.
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » Developer Certification (SCJD)
 
RSS feed
 
New topic
Author

Submission Jar: test case + Ant build script

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Messages: 1456

Hi all,

This is the test case (JUnit 4) I used to check if the submission jar is valid and contains all necessary files (in the appropriate directories). It checks also some source requirements:
- are interfaces DBMain (= Sun's interface) and Data in the correct package?
- are the exceptions (mentioned in Sun's interface) in the correct package?
- does Data implement DBMain?
- do the exceptions (mentioned in Sun's interface) have 2 constructors: one with zero-argument constructor and one with String argument?

My assignment was URLyBird 1.3.1, so if you have another assignment, make sure you make the necessary changes to the test case before using it. I decided also to have a simple plain text userguide. So if you have a HTML one, you will need to make changes too.



And this is the Ant build script. I put this script in the root of my sources and defined all directories (in the build script) with a relative path. After building the submission jar I executed all tests I had (including the test case above). And of course the build script just copies the necessary files, no moving or deleting (except for the generated files of course). So you don't have to worry that suddenly your source files disappeared for example
The build script creates:
- the runme.jar
- the javadoc (for all members/classes except private ones, and creates also links for every class from the Java API)
- the RMI stubs (if you don't want it, just comment/delete the line <rmic ... />)
- the submission jar

Just complete the properties and then you can run the build script with the target of your choice (javadoc, create-executable-jar, create-submission-jar or the default one buildAndTest).



This build script was for me a real life-saver, because I submitted my assignment just 15 minutes before I had to leave to take the essay exam (making my choices.txt took a whole lot longer than I thought) and thanks to this build script I was 100% sure that I wasn't forgetting anything and my submission jar was

If you should have any questions about use or modifications, just let me know by replying to this thread (and I'll try answering them).

Good luck with your assignments!
Kind regards,
Roel

[edit] changed the javadoc target and increase readibility (according to Andrew's remark)

This message was edited 6 times. Last update was at by Roel De Nijs


SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
http://www.zvcvalaar.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Messages: 1219

Howdy, Roel!!!

This is great! Thank you so much for sharing this valuable tool. I'm sure this will be of great value to everyone still working on the assignment, and certainly will help people to submit the final project with everything in the right place.

Cheers, Bob "John Lennon" Perillo
SCJP 5.0, SCWCD, SCJD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Messages: 1456

Hi all,

Everybody knows Roberto Perillo 's famous data locking test (you can find it here). It is easy to add this test to the build script:
- first modify the test so it 's adapted to your Data class
- be sure to put the test in the test directory (property "dir.test")
- then just add the following line to the target "buildAndTest" (after the comment "execute tests")



That's it! And likewise you can add every test you want to the build script. If the test is a JUnit test case then you have to add it like the TestJarSubmission test is added. If it is just a Java program then you can add just as Roberto's data locking test.

Kind regards,
Roel

This message was edited 1 time. Last update was at by Roel De Nijs


SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
http://www.zvcvalaar.be/
Andrew Monkhouse
author and jackaroo
Sheriff

Joined: Mar 28, 2003
Messages: 7700

Hi Roel,

This is great - thanks for sharing. Do you feel like adding a link to this in the JavaRanch SCJD FAQ? (The FAQ is just a wiki page - you can edit it yourself).

Roel De Nijs wrote:to have a bit a readible thread I changed the javadoc call a bit: if you want to use the build file you just have to delete ...> and <...

To get around that particular problem, I tend to split my lines - even in the production code. I personally feel the following is a little easier to read (and a little easier to remove a single line if I need to):


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Messages: 1456

Andrew Monkhouse wrote:To get around that particular problem, I tend to split my lines - even in the production code.

Normally I also split my lines (because indeed it is easier to read/maintain), I have no idea why I didn't do it here

Andrew Monkhouse wrote:Do you feel like adding a link to this in the JavaRanch SCJD FAQ?

I added the link.

Kind regards,
Roel

SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
http://www.zvcvalaar.be/
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Messages: 158

There is also a similar test and ant script - http://www.coderanch.com/t/189448/Developer-Certification-SCJD/certification/Assignment-submission-file-structure-verification - these are the ones I used (slightly modified) for my assignment verification test and build script.

What is useful in that ant build and you could also add to yours is the javadoccheck target.

SCJP 1.4 100%
SCJD 99.5%
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Messages: 1456

Hi Alecsandru,

I never used the doc check utility, so i don't have any idea what it does and what's the added value. I think if you add verbose="true" you will see what javadoc is doing and when a problem occurs (like a parameter that is not defined in the parameter list,...) an error message is shown to the console (cfr. the "Generate Javadoc" menu-item from Eclipse).

Kind regards,
Roel

SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
http://www.zvcvalaar.be/
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Messages: 158

DocCheck generates HTML reports about how well your code is documented. You should try it

SCJP 1.4 100%
SCJD 99.5%
Vasya Pupkin
Ranch Hand

Joined: Dec 06, 2006
Messages: 39

Roel, thanks again for your shared code.
I was debating with myself for a while about writing build.xml
I was postponing it till the very last minute, and here you are with your build script.
I finally had some time to run your code. It did not take long to modify everything for my needs (B&S).

Alecsandru Cocarla, thanks for the reference too. PMD and javadoccheck appear to be very helpful.

SCJP, SCJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Messages: 1456

Alecsandru Cocarla wrote:DocCheck generates HTML reports about how well your code is documented. You should try it

I tried the docCheck on my source code and I don't think it has any added value (but of course that is just my opinion). If i take a look at the generated reports it tells me that I have missing comments for 10 methods and I have 4 minor errors of category 4 (Text/Link Error). If i have a closer look I see the following:
- 8 methods don't have comments in DBMain interface (that's normal, because I decided not to change a thing about sun's given interface and have javadoc in my own created interface)
- the other 2 methods without having a comment are the methods values() and valueOf(String) of an enum (probably a normal issue because docCheck should be used with jdk 1.2, 1.3 and 1.4, no specific mention of jdk 1.5 or higher)
- the 4 minor errors are the same: "Html Error in First Sentence --Missing a period" (these errors can be solved by adding a period after {@inheritDoc})

Then of course I added some real javadoc errors to see how docCheck handles these ones: an empty return-tag and a non-existing parameter name after the param-tag. DocCheck shows in the report I have also 3 minor errors of category 3 (Tag Error) and that is as expected. But like I said in a previous post the javadoc tool will show you the same errors:

...
MyInterface.java:72: warning - @return tag has no arguments.
MyInterface.java:59: warning - @param argument "parameter2" is not a parameter name.
...
2 warnings

So no added value at all in my humble opinion.

Vasya Pupkin wrote:PMD and javadoccheck appear to be very helpful.

I also did a test with PMD and I have to say that is really useful. I let PMD check the sources that I submitted and it found approximately 250 violations. But i didn't agree with all the violations (like the one that says you should only have 1 return statement in a method). But it is certainly worth your while. And it has also various plugins for IDE, so if you use it through an IDE you can indicate which rules must be checked and about which you don't care.
I think you should certainly run PMD once to see how you can improve your source code (but of course this is again my humble opinion, because I didn't do it myself but in my defense: I didn't know the existence of this plugin/tool )

Vasya Pupkin wrote:Roel, thanks again for your shared code. I finally had some time to run your code. It did not take long to modify everything for my needs (B&S).

I'm glad it was useful for you.

Kind regards,
Roel

SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
http://www.zvcvalaar.be/
Nilesh Thali
Greenhorn

Joined: Jan 13, 2009
Messages: 16

Adding Roel's answer from my question about "javadoc -overview" in a separate post:

Roel De Nijs wrote:Hi Nilesh,

This certainly is the first topic having my name in the title

Nilesh Thali wrote:Addressing this to you, Roel, since you created this extremely handy ant build file

Glad I could help and share with the community

It would have been better if you asked your question in the thread where I posted my Ant-file, so everybody using that build file, could also read your question (and my answer). So someone else with the same question, wouldn't have to post it again, because you already did.

More info about the overview comment file, you can read here. This section of the javadoc tool documentation covers all your questions, so I would suggest just reading it and it will (hopefully) clear all your doubts.

Kind regards,
Roel
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » Developer Certification (SCJD)
 
RSS feed
 
New topic
IntelliJ open source