All true craftsmen need the best tools to do their finest work, and programmers are no different. Java Power Tools delivers 30 open source tools designed to improve the development practices of Java developers in any size team or organization. Each chapter includes a series of short articles about one particular tool -- whether it's for build systems, version control, or other aspects of the development process -- giving you the equivalent of 30 short reference books in one package. No matter which development method your team chooses, whether it's Agile, RUP, XP, SCRUM, or one of many others available, Java Power Tools provides practical techniques and tools to help you optimize the process. The book discusses key Java development problem areas and best practices, and focuses on open source tools that can help increase productivity in each area of the development cycle, including:Build tools including Ant and Maven 2 Version control tools such as CVS and Subversion, the two most prominent open source tools Quality metrics tools that measure different aspects of code quality, including CheckStyle, PMD, FindBugs and Jupiter Technical documentation tools that can help you generate good technical documentation without spending too much effort writing and maintaining it Unit Testing tools including JUnit 4, TestNG, and the open source coverage tool Cobertura Integration, Load and Performance Testing to integrate performance tests into unit tests, load-test your application, and automatically test web services, Swing interfaces and web interfaces Issue management tools including Bugzilla and Trac Continuous Integration tools such as Continuum, Cruise Control, LuntBuild and Hudson If you are a Java developer, these tools can help improve your development practices, and make your life easier in the process. Lead developers, software architects and people interested in the wider picture will be able to gather from these pages some useful ideas about improving your project infrastructure and best practices.
Author(s): John Ferguson Smart
Publisher: O’Reilly Media
Year: 2008
Language: English
Pages: 912
Table of Contents......Page 7
Foreword......Page 19
Preface......Page 21
How This Book Is Organized......Page 22
Unit Testing......Page 23
Issue Management Tools......Page 24
Who Should Read This Book......Page 25
Contributing Authors......Page 26
Technical Reviewers......Page 28
Conventions......Page 29
About the Title......Page 30
Acknowledgments......Page 31
Safari® Enabled......Page 32
How to Contact Us......Page 33
Introduction......Page 35
Part I. Build Tools......Page 39
1.2 Installing Ant......Page 43
Installing Ant on a Unix Machine......Page 44
ANT_OPTS and ANT_ARGS: Some Other Useful Environment Variables......Page 45
Basic Ant Concepts......Page 46
A Simple Ant Build File......Page 47
Running Ant......Page 50
Documenting Your Project......Page 52
1.4 Compiling Your Java Code in Ant......Page 53
1.5 Customizing Your Build Script Using Properties......Page 55
Using JUnit in Ant......Page 59
Preparing Your Build for Automated Tests......Page 60
Using the Task......Page 65
Running Multiple Tests......Page 69
Generating HTML Test Reports......Page 72
Using Asserts in Your Test Cases......Page 76
1.7 Generating Documentation with Javadoc......Page 77
Generating a JAR File......Page 79
Generating a WAR File or an EAR File......Page 82
Copying Files......Page 83
1.10 Bootstrapping Your Build Scripts......Page 85
1.11 Using Maven Dependencies in Ant with the Maven Tasks......Page 87
Declaring and Using Maven Dependencies in Ant......Page 88
Packaging the Dependencies......Page 89
Using an Existing Maven POM File......Page 90
1.13 Using Ant in NetBeans......Page 91
1.14 Manipulating XML with XMLTask......Page 92
Examples......Page 93
DTDs and XMLTask......Page 95
Driving Ant via XMLTask......Page 96
Maintaining documents with comments......Page 97
1.15 Conclusion......Page 98
2.1 Maven and the Development Build Process......Page 99
2.3 Installing Maven......Page 100
Installing Maven on a Unix Machine......Page 101
An Introduction to Declarative Build Management......Page 102
Project Context and Artifacts......Page 107
A Human-Readable Project Description......Page 109
Defining the Development Team......Page 110
Managing Dependencies......Page 111
Customizing Your Build Process......Page 112
Defining Build Profiles......Page 113
2.5 Understanding the Maven 2 Lifecycle......Page 115
2.6 The Maven Directory Structure......Page 117
Using a Proxy......Page 118
Defining Arbitrary Environment-Specific Variables......Page 119
2.8 Dependency Management in Maven 2......Page 120
Declaring Dependencies......Page 121
Managing Transitive Dependencies......Page 123
Dependency Scope......Page 125
Handling Proprietary Dependencies......Page 127
Refactoring Your Dependencies Using Properties......Page 128
2.10 Project Inheritance and Aggregation......Page 129
2.11 Creating a Project Template with Archetypes......Page 134
2.12 Compiling Code......Page 138
2.13 Testing Your Code......Page 139
2.14 Packaging and Deploying Your Application......Page 143
2.15 Deploying an Application Using Cargo......Page 145
2.16 Using Maven in Eclipse......Page 149
2.18 Using Plug-Ins to Customize the Build Process......Page 151
Creating a Plug-In......Page 152
Manipulating the Build Lifecycle......Page 156
Hooking into Maven......Page 158
Using Plexus Components......Page 159
Installing Archiva......Page 160
Configuring Repositories in Archiva......Page 162
User Management......Page 163
Running Archiva on Another Port......Page 164
Archiva Proxy Connectors......Page 165
Setting Up Remote Repositories......Page 167
Configuring Archiva Behind a Proxy......Page 168
Using Maven with Archiva......Page 169
Manually Deploying a File to an Archiva Repository......Page 172
Setting Up the Maven Repository Using Artifactory......Page 173
The Artifactory directory structure......Page 174
Deploy in Tomcat 6......Page 175
Set up the Maven repositories......Page 176
Configure Maven using project “pom.xml”......Page 178
Configure Maven using settings.xml......Page 180
Building using the new Maven repository......Page 181
Installing artifacts from Maven command line......Page 182
Running Artifactory Through a Proxy......Page 183
Adding Other Remote Repositories......Page 184
Using Existing build.xml Files......Page 185
Embedding Ant Code in the POM......Page 186
External Dependencies......Page 187
Making Ant Plug-Ins......Page 188
Generating Ant Script from a POM......Page 190
2.22 Advanced Archetypes......Page 191
Creating Your Own Archetypes......Page 192
Creating Assemblies......Page 195
Built-in Descriptors......Page 197
Assemblies with Profiles......Page 198
Part II. Version Control Tools......Page 201
3.1 An Introduction to CVS......Page 203
3.3 Creating a New Project in CVS......Page 204
3.4 Checking Out a Project......Page 206
3.5 Working with Your Files—Updating and Committing......Page 208
3.7 Working with Keyword Substitution......Page 212
3.8 Working with Binary Files......Page 213
3.9 Tags in CVS......Page 216
3.10 Creating Branches in CVS......Page 217
3.11 Merging Changes from a Branch......Page 218
3.12 Viewing Change History......Page 219
3.13 Reverting Changes......Page 221
3.14 Using CVS in Windows......Page 223
Revision Numbers and Atomic Updates......Page 225
Handling Binary Files......Page 228
4.3 Subversion Repository Types......Page 229
4.4 Setting Up a Subversion Repository......Page 231
4.5 Setting Up a New Subversion Project......Page 233
4.6 Checking Out Your Working Copy......Page 235
4.7 Importing Existing Files into Subversion......Page 236
4.8 Understanding Subversion Repository URLs......Page 238
Updating Your Work Directory......Page 239
Working with Your Local Copy......Page 240
Committing Your Work......Page 242
4.10 Seeing Where You’re At: The Status Command......Page 243
4.11 Resolving Conflicts......Page 246
4.12 Using Tags, Branches, and Merges......Page 248
4.13 Rolling Back to a Previous Revision......Page 252
4.14 Using File Locking with Binary Files......Page 253
4.15 Breaking and Stealing Locks......Page 255
4.16 Making Locked Files Read-Only with the svn:needs-lock Property......Page 257
Forcing the File Type with svn:mime-type......Page 258
Making Subversion Ignore Files with svn:ignore......Page 259
Handling OS-Specific End-of-Lines with svn:eol-style......Page 260
4.18 Change History in Subversion: Logging and Blaming......Page 261
4.19 Setting Up a Subversion Server with svnserve......Page 262
4.20 Setting Up a Secure svnserve Server......Page 266
4.21 Setting Up a WebDAV/DeltaV Enabled Subversion Server......Page 267
4.22 Setting Up a Secure WebDAV/DeltaV Server......Page 272
4.23 Customizing Subversion with Hook Scripts......Page 273
4.24 Installing Subversion As a Windows Service......Page 274
4.25 Backing Up and Restoring a Subversion Repository......Page 276
Installing Subclipse......Page 277
Defining a Repository......Page 278
Adding a New Project to the Repository......Page 279
Creating a Project from the Subversion Repository......Page 280
Working with Files......Page 281
Branching and Merging......Page 282
Installing Subversion Support......Page 283
Creating a Subversion-Based Project......Page 284
Working with Your Files......Page 285
Keeping Track of Changes......Page 286
Branching and Merging......Page 287
4.28 Using Subversion in Windows......Page 288
Using TortoiseSVN in Windows Explorer......Page 289
Importing a New Project into the Repository......Page 291
Obtaining a Working Copy......Page 293
Committing Your Changes with TortoiseSVN......Page 294
Exploring the Repository......Page 296
4.29 Defect Tracking and Change Control......Page 298
Installing the Task......Page 300
Checking Out a Project......Page 301
Exporting a Directory Structure......Page 302
4.31 Conclusion......Page 303
Part III. Continuous Integration......Page 305
5.2 Installing a Continuum Server......Page 309
5.3 Manually Starting and Stopping the Server......Page 313
5.5 Running the Continuum Server in Verbose Mode......Page 314
5.7 Adding a Maven Project......Page 315
5.9 Adding a Shell Project......Page 318
5.10 Managing Your Project Builds......Page 319
5.11 Managing Users......Page 320
5.12 Setting Up Notifiers......Page 321
5.13 Configuring and Scheduling Builds......Page 323
5.15 Configuring the Continuum Mail Server......Page 326
5.16 Configuring the Continuum Web Site Ports......Page 327
5.17 Automatically Generating a Maven Site with Continuum......Page 328
5.18 Configuring a Manual Build Task......Page 329
5.19 Conclusion......Page 331
6.1 An Introduction to CruiseControl......Page 333
6.2 Installing CruiseControl......Page 334
6.3 Configuring an Ant Project......Page 335
6.4 Keeping People Notified with Publishers......Page 341
6.5 Setting Up a Maven 2 Project in CruiseControl......Page 347
6.6 The CruiseControl Dashboard......Page 349
CruiseControl Configuration Tool......Page 350
Firefox and Thunderbird Integration......Page 351
6.8 Conclusion......Page 352
7.2 Installing LuntBuild......Page 353
7.3 Configuring the LuntBuild Server......Page 355
7.4 Adding a Project......Page 357
Configuring the Project Basics......Page 358
VCS Adaptors......Page 360
Builders......Page 361
Scheduling......Page 362
7.5 Using Project Variables for Version Numbering......Page 364
7.6 Build Results Diagnostics......Page 366
7.7 Using LuntBuild with Eclipse......Page 369
Introduction......Page 371
Extending Luntbuild with Extension Points......Page 372
Creating a Cobertura Luntbuild Extension......Page 373
Using the Extension......Page 374
Running Cobertura with Ant......Page 376
Extending Maven to Support LuntBuild......Page 379
Creating the Mojo......Page 380
Luntbuild Configuration......Page 382
7.10 Conclusion......Page 385
8.2 Installing Hudson......Page 387
8.3 Managing the Hudson Home Directory......Page 388
8.4 Installing Upgrades......Page 389
8.5 Configuring Hudson......Page 390
Building a Freestyle Project......Page 392
Building a Maven Project......Page 396
8.7 Organizing Your Jobs......Page 397
8.8 Monitoring Your Builds......Page 398
8.9 Viewing and Promoting a Particular Build......Page 399
8.10 Managing Users......Page 400
8.11 Authentication and Security......Page 402
8.13 Hudson Plug-Ins......Page 403
8.14 Keeping Track of Test Results......Page 404
8.15 Keeping Track of Code Metrics......Page 405
8.16 Reporting on Code Coverage......Page 406
9.2 Installing Openfire......Page 411
9.4 Authenticating Users in an External Database......Page 412
9.5 Authenticating Users Against a POP3 Server......Page 415
9.6 Virtual Team Meetings with the Group Chat......Page 416
9.8 Using Openfire with Continuum......Page 417
9.11 Sending Jabber Messages from a Java Application Using the Smack API......Page 420
9.13 Receiving Messages Using the Smack API......Page 423
Part IV. Unit Testing......Page 425
10.1 JUnit 3.8 and JUnit 4......Page 427
10.2 Unit Testing with JUnit 4......Page 428
10.3 Setting Up and Optimizing Your Unit Test Cases......Page 430
10.4 Simple Performance Testing Using Timeouts......Page 431
10.5 Checking for Exceptions the Easy Way......Page 432
10.6 Using Parameterized Tests......Page 433
10.7 Using assertThat and the Hamcrest Library......Page 436
10.8 JUnit 4 Theories......Page 438
10.9 Using JUnit 4 with Maven 2......Page 440
10.10 Using JUnit 4 with Ant......Page 441
Running Individual Tests......Page 444
Running Tests Conditionally......Page 445
10.12 Integration Tests......Page 446
10.13 Using JUnit 4 in Eclipse......Page 447
11.2 Creating Simple Unit Tests with TestNG......Page 451
11.3 Defining TestNG Test Suites......Page 453
11.4 The TestNG Eclipse Plug-In......Page 454
Installing the TestNG Plug-In......Page 455
Running TestNG Tests......Page 456
11.5 Using TestNG in Ant......Page 458
11.6 Using TestNG with Maven 2......Page 462
11.7 Managing the Test Lifecycle......Page 463
11.8 Using Test Groups......Page 468
11.9 Managing Dependencies......Page 470
11.10 Parallel Testing......Page 473
11.11 Test Parameters and Data-Driven Testing......Page 474
11.13 Handling Partial Failures......Page 475
11.14 Rerunning Failed Tests......Page 476
12.1 Test Coverage......Page 479
12.2 Running Cobertura from Ant......Page 480
12.3 Checking the Code Coverage of TestNG Tests......Page 483
12.4 Interpreting the Cobertura Report......Page 485
12.5 Enforcing High Code Coverage......Page 488
12.6 Generating Cobertura Reports in Maven......Page 489
12.7 Integrating Coverage Tests into the Maven Build Process......Page 491
12.8 Code Coverage in Eclipse......Page 494
12.9 Conclusion......Page 496
Part V. Integration, Functional, Load, and Performance Testing......Page 497
13.0 Introduction......Page 501
13.1 Testing a Struts Application......Page 502
13.3 Mock Tests Using StrutsTestCase......Page 503
13.4 Testing Struts Error Handling......Page 508
13.6 First-Level Performance Testing......Page 509
13.7 Conclusion......Page 510
Purpose of DbUnit......Page 511
Running with DbUnit......Page 512
DatabaseTestCase......Page 513
IDatabaseConnection......Page 514
ITableMetaData......Page 515
14.3 Example Application......Page 516
14.4 Priming the Database......Page 517
Verifying Querying a Single Row......Page 518
Specifying NULLs by Omission......Page 523
Specifying NULLs by DTD......Page 524
Verifying an UPDATE......Page 526
Verifying a DELETE......Page 527
Verifying an INSERT, Ignoring the Key......Page 528
Verifying an INSERT, with the Key......Page 529
Using NULL with a ValueReplacer......Page 531
Using an Image ValueReplacer......Page 533
Using an XLS Dataset......Page 536
Using an InlineDataSet......Page 538
14.8 Dealing with Custom Data Types......Page 540
Specifying an INTERVALDS Data Type......Page 541
Injecting the Test Fixture......Page 544
Using Transaction Rollback Teardown......Page 547
Testing a Stored Procedure......Page 550
Testing a View......Page 551
Importing a Dataset with Ant......Page 552
15.1 Introducing JUnitPerf......Page 555
15.2 Measuring Performance with TimedTests......Page 556
15.3 SimulatingLoad with LoadTests......Page 558
15.5 Separating Performance Tests from Unit Tests in Ant......Page 561
15.6 Separating Performance Tests from Unit Tests in Maven......Page 562
16.0 Introduction......Page 565
16.2 Testing a Simple Web Application......Page 566
Scheduling Your Tests......Page 567
Setting Up the HTTP Request Configuration Elements......Page 568
Adding an HTTP Request......Page 570
16.3 Structuring Your Test Case......Page 572
Visualizing Performance with the Graph Listener......Page 575
Getting More Details with the View Results Tree Listener......Page 576
Getting the Executive Summary......Page 578
16.5 Using the JMeter Proxy to Record a Test Case......Page 579
16.6 Testing Using Variables......Page 581
16.7 Testing on Multiple Machines......Page 582
17.1 An Introduction to SoapUI......Page 585
When Is SoapUI Appropriate?......Page 586
17.3 Installing a Local Web Service......Page 587
17.4 Testing Web Services with SoapUI......Page 589
17.5 Load-Testing with SoapUI......Page 595
17.6 Running SoapUI from the Command Line......Page 599
17.7 Running SoapUI from Ant......Page 601
17.8 Running SoapUI from Maven......Page 602
17.9 Continuous Testing......Page 603
17.10 Conclusion......Page 604
18.2 Connecting To and Monitoring a Java Application with jConsole......Page 607
18.3 Monitoring a Remote Tomcat Application with jConsole......Page 610
18.4 Detecting and Identifying Memory Leaks with the JDK Tools......Page 612
18.5 Diagnosing Memory Leaks Using Heap Dumps, jmap, and jhat......Page 617
18.6 Detecting Deadlocks......Page 620
19.2 The Eclipse Test & Performance Tools Platform......Page 623
19.5 Basic Profiling with TPTP......Page 625
19.6 Studying Memory Use with the Basic Memory Analysis Results......Page 631
19.7 Analyzing Execution Time......Page 633
19.9 Using Filters to Refine Your Results......Page 635
19.10 Profiling a Web Application......Page 637
19.11 Conclusion......Page 638
Introduction......Page 641
Using the Selenium IDE......Page 642
Writing Selenium Test Scripts......Page 644
An introduction to Selenese......Page 645
Referring to objects on the web page......Page 646
Using variables......Page 649
Using assertions......Page 654
Running a Selenium Test Suite with Selenium Core......Page 656
Writing JUnit Tests with Selenium......Page 659
Using Selenium with Ant......Page 664
Using Selenium with Maven......Page 665
Testing GUIs Is Hard......Page 671
Testing GUIs with FEST......Page 672
Following Windows with FEST......Page 675
Verifying Test Failures......Page 676
Testing Legacy Applications......Page 679
20.3 Conclusion......Page 680
Part VI. Quality Metrics Tools......Page 681
21.1 Using Checkstyle to Enforce Coding Standards......Page 685
21.2 Using Checkstyle in Eclipse......Page 687
21.3 Customizing Checkstyle Rules in Eclipse......Page 690
21.4 Customizing Checkstyle Rules Using the XML Configuration Files......Page 693
21.5 Customizing Checkstyle: Common Rules That You Can Do Without, and Some That You Could Use......Page 695
21.6 Defining Rules for Source Code Headers with Checkstyle......Page 698
21.7 Suppressing Checkstyle Tests......Page 700
21.8 Using Checkstyle with Ant......Page 701
21.9 Using Checkstyle with Maven......Page 702
Installing the PMD Plug-In......Page 705
Detecting and Displaying Errors......Page 706
22.4 More on the PMD Rulesets......Page 708
22.5 Writing Your Own PMD Ruleset......Page 712
22.6 Generating a PMD Report in Eclipse......Page 713
22.7 Suppressing PMD Rules......Page 714
22.8 Detecting Cut-and-Paste with CPD......Page 715
22.9 Using PMD in Ant......Page 717
22.10 Using PMD in Maven......Page 719
23.1 FindBugs: A Specialized Bug Killer......Page 723
Installing the FindBugs Plug-In......Page 725
23.3 Selectively Suppressing Rules with FindBug Filters......Page 726
23.4 Using FindBugs Annotations......Page 729
23.5 Using FindBugs in Ant......Page 730
23.6 Using FindBugs in Maven......Page 733
23.7 Conclusion......Page 734
24.1 Introducing Jupiter—A Code Review Tool for Eclipse......Page 735
24.2 Installing Jupiter in Eclipse......Page 736
24.3 Understanding the Jupiter Code Review Process......Page 737
24.4 Conducting Personal Code Reviews......Page 738
24.5 Configuration......Page 739
24.7 Individual Reviews......Page 744
24.8 Team Review......Page 746
24.9 Rework Phase......Page 750
24.10 Jupiter Behind the Scenes......Page 752
24.11 Conclusion......Page 753
25.1 Introduction to Mylyn......Page 755
25.2 Installing Mylyn......Page 756
25.3 Tracking Tasks and Issues......Page 757
25.4 Interacting with Task Repositories......Page 760
25.5 Focusing on a Task with Context Management......Page 764
25.6 Using the Eclipse Change Sets......Page 766
25.7 Sharing Context with Other Developers......Page 767
25.8 Conclusion......Page 769
26.1 QALab......Page 771
Using QALab in Ant......Page 772
Using QALab in Maven......Page 778
26.2 Source Code Management Metrics with StatSCM......Page 779
26.3 Statistics in Ant with StatSVN......Page 780
Extracting the Subversion Logfiles......Page 781
Generating the StatSVN Reports......Page 782
Part VII. Issue Management Tools......Page 783
27.2 Installing Bugzilla......Page 785
Installing the Bugzilla Application......Page 786
Installing the Perl Modules......Page 787
Installing the Bugzilla Application......Page 788
27.3 Setting Up Your Bugzilla Environment......Page 789
27.4 Managing User Accounts......Page 790
27.5 Restricting Access Using User Groups......Page 792
27.6 Configuring a Product......Page 794
27.8 Managing Groups of Products with Classifications......Page 796
27.9 Searching for Bugs......Page 797
27.10 Creating a New Bug......Page 799
27.11 The Lifecycle of a Bugzilla Bug......Page 800
27.12 Scheduling Notifications (Whining)......Page 802
27.13 Customizing Fields in Bugzilla......Page 804
27.14 Conclusion......Page 805
28.1 An Introduction to Trac......Page 807
28.2 Installing Trac......Page 808
28.3 Setting Up a Trac Project......Page 810
28.4 Running Trac on the Standalone Server......Page 812
28.5 Setting Up Tracd As a Windows Service......Page 813
28.6 Installing Trac on an Apache Server......Page 814
28.7 Administrating the Trac Site......Page 815
28.8 Managing User Accounts......Page 817
28.9 Tailoring the Trac Web Site: Using the Wiki Function......Page 821
28.10 Using the Trac Ticket Management System......Page 825
Creating a New Ticket......Page 826
The Lifecycle of a Trac Ticket......Page 827
28.11 Updating Trac Issues from Subversion......Page 828
28.12 Customizing Trac Ticket Fields......Page 830
28.13 Setting Up Email Notifications......Page 831
28.14 Reporting Using Trac Queries and Reports......Page 833
Trac Milestones......Page 835
28.16 Browsing the Source Code Repository......Page 837
28.17 Using RSS and ICalendar......Page 840
28.18 Customizing a Wiki Page with Python......Page 841
28.19 Conclusion......Page 842
Part VIII. Technical Documentation Tools......Page 843
29.1 The Maven 2 Project Web Site As a Communication Tool......Page 845
Describing the Project......Page 846
Linking into the Issue Tracking System......Page 847
The Continuous Integration System......Page 848
The Project Team......Page 849
The Source Repository......Page 850
29.3 Integrating Reports into Your Site......Page 851
Test Coverage Reports......Page 852
Change and Configuration Management......Page 853
29.4 Creating a Dedicated Maven Site Project......Page 856
29.5 Defining the Site Outline......Page 857
APT......Page 859
FML......Page 862
29.7 Using Snippets......Page 863
Changing Skins......Page 864
Creating Your Own Style......Page 865
Velocity Manipulation......Page 866
29.9 Distributing Your Site......Page 867
Introduction......Page 869
An Overview of SchemaSpy......Page 870
Using SchemaSpy......Page 874
Using SchemaSpy in Ant......Page 875
Using SchemaSpy in Maven......Page 876
The Doxygen Reports......Page 878
Installing Doxygen......Page 879
Configuring Doxygen......Page 880
Running Doxygen from the Command Line......Page 882
Using Doxygen with Ant......Page 883
Links and references......Page 885
Documenting packages......Page 886
30.3 Embedding UML Diagrams in Your Javadoc with UmlGraph......Page 887
Using UmlGraph in Ant......Page 889
Using UmlGraph in Maven......Page 890
30.4 Conclusion......Page 891
Bibliography......Page 893
Index......Page 895