EclipseCon2005 Tutorial25
EclipseCon2005 Tutorial25
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Agenda
Eclipse Functional Architecture Managing Your Workspace(s) and Projects Configuring Java Projects and Shared Libraries Rapid Development: Content Assist, Quick Fix, Code Navigation Update Manager: Adding new Features and Plug-ins Eclipse & Agile Development Team Ownership & CVS Continuous Integration with Ant JUnit Testing Refactoring Coding Standards
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Configuring Java Projects and Shared Libraries Update Manager: Adding new Features and Plug-ins
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
UML2
Other contributions build on these infrastructure libraries. For example, the Web Tools Platform (WTP) uses EMF, XSD, and GEF.
10
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Configuring Java Projects and Shared Libraries Update Manager: Adding new Features and Plug-ins
Installation Folders
You may have more than one version of Eclipse installed (e.g. 3.0.1 and 3.1 M5) Install plug-in contributions in folders separate from your Eclipse product folder (e.g. eclipse-contrib)
12
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
13
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Help > About Eclipse Platform Feature Details Plug-in Details Configuration Details (e.g. JVM)
14
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Go to the Workbench
15
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Resource Perspective
16
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Java Perspective
17
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
hyperModel Perspective
18
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Project 1 * 1 * File
19
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Projects
Projects are special entities in your workspace. A project is a container that groups resources into buildable, reusable units:
A project collects together a set of files and folders. A project's location controls where the project's resources are stored in the local file system. A project's build specification controls how its resources are built. A project can carry session and persistent properties. A project can be open or closed; a closed project is passive and has a minimal in-memory footprint. A project can refer to other projects.
The type of project is determined by its project natures (there can be more than one), which are assigned by a wizard when a project is created.
20
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Linked folders and files appear as an integral part of your Eclipse project, but they must be located directly within a project, not nested within a subfolder.
21
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Select Variables
Best Practice:
Avoid absolute path locations in all project configurations Create a path variable pointing to the external base path Extend a variable to pick a file or folder at that location
Manage all path variables via Preferences > Workbench > Linked Resources
22
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Multiple Workspaces
If you create multiple workspace locations, then the project resources contained within each workspace should be independent of those in other workspaces. However, independent projects may be included in the same workspace. Some common reasons for multiple workspaces include:
Independent work topics, possibly managed in different version control repositories (although projects within one workspace can be associated with any number of repositories). You are a consultant and need to maintain clear separation between client resources. Two or more workspaces are used to distinguish concurrent work on maintenance branch versions in CVS.
To create a new workspace, simply start Eclipse and enter a new location in the Workspace Launcher dialog.
23
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Product Catalog
Catalog name : String description : Sting startDate : Date endDate : Date getItems() : List addItem(item : CatalogItem) : void +contains CatalogItem +items 0..* name : String description : String listPrice : Amount sku : String identifier : Identifier +supplier 0..1 Party (from ubl)
1..*
ProductBundle 0..*
25
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
26
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
27
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
28
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
29
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
30
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Add new Java comment tags to be extracted into Task entries. STORY could allow annotating Java classes with user story documentation.
31
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Rapid Development:
Content Assist, Quick Fix, Code Navigation
Configuring Java Projects and Shared Libraries Update Manager: Adding new Features and Plug-ins
Most of these features are becoming standard capabilities in other non-Java plug-ins. For example, the new Web Tools Platform supports these features for JSP, XML, XSD, CSS, and other editors.
33
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Editor Hovers
34
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
35
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Source Navigation
F3: Navigate to a type, method, or field at the current cursor location. Ctrl+Shift+T: Open an editor for any Java type that is available in your workspace. Also via menu Navigate > Open Type or using a toolbar icon. Ctrl+O: Open a lookup dialog containing a list of members in the current Java editor. Start typing characters to limit the list and press Enter to go to the selected member. A quick alternative to the Outline view. Ctrl+F3: Open a member lookup dialog for the class name at the current cursor location; e.g. position on Date and press Ctrl+F3 to review and lookup one of its methods.
36
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
You can control several aspects of how Content Assist is invoked or the way its changes are made to your code. See the Java > Editor > Code Assist preference page. These preferences include use of a period character . to trigger content assist suggestions for method completion.
37
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
38
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Remove an unneeded catch block when the exception is not thrown within its try block.
39
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
40
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Hierarchy Explorer
Type Hierarchy Supertype Hierarchy
F4
selected type in the editor
Ctrl+Shift+H
open dialog to select a type
Ctrl+T
open quick type hierarchy popup for selection in the editor Select a type in the hierarchy to display its fields and methods in the lower pane.
41
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
42
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Functional Architecture Managing Your Workspace(s) and Projects Rapid Development
Content Assist, Quick Fix, Code Navigation
orders.webapp .test
ubl
44
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
45
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Each Java project is configured with a builder that automatically compiles every .java file from the source folders and saves the .class files into an output folder. Your source folder must contain subfolders for the complete package hierarchy as used by your Java source files.
automatic when you use the New Java Package wizard.
Source Configure the source and output folders. If you initially create a project without separate source and output folders, you can change it here. Multiple source folders can be used in one project; e.g. to separate application source code from unit tests.
46
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
orders.webapp
orders
catalog
Project Dependencies
Configuring project: com.eclipsedistilled.orders
orders.webapp .test
ubl
Output folders from two projects are included in the build path and their classes are available while compiling classes in this project: com.eclipsedistilled.orders These other project classes are available in Quick Assist completion lists, so typing cat then Ctrl+Space will now include the Catalog and CatalogItem classes in the pick list while writing the Order class.
Projects Check-off other projects in the workspace whose output folders should be added to this build path.
47
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
48
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
49
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
User Libraries
Define a named group of interdependent JAR libraries Add a User Library to one or more projects as a single collection Similar to the JRE System Library added to all Java projects Configure Javadoc location and source attachments as part of the user library. Weakness: requires absolute path reference to JARs in the library.
User Library Define a named group of related JAR files that are added to one ore more project build paths.
50
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
51
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Team Preferences
Code style and format Code templates Comment templates Task tags Java JRE version (1.3, 1.4, or 1.5) Compiler options (flagging errors and warnings) Team file content types (e.g. binary or text)
52
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Eclipse Functional Architecture Managing Your Workspace(s) and Projects Rapid Development
Content Assist, Quick Fix, Code Navigation
54
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Configuration changes are saved in configuration subfolder of eclipse home Launch eclipse with clean command option if you change plug-ins without using Update Manager. This flushes cached plug-in information.
55
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
56
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
57
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Agile Practices
Team Ownership with CVS Continuous Integration with Ant Continuous Testing with JUnit Refactoring Coding Standards
V 2
Release Roadmap
Plan Releases
Iterate
Accept ?
Small Releases
Features
UseC ase s
De f ec ts
Requirements Re ou s rc sts e s Te
59
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Iterate
Prioritize Estimate Tasks Negotiate Scope Take Responsibility Elaborate Requirements Design
De fe ct s
ra Ite
n tio
ni an Pl
Code
ng
60
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
61
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
62
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Agile Practices
64
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
CVS Workflow
CVS Uses an optimistic model for coordinating work assumes that conflicting edits on the same lines are rare 1. Start fresh. Before starting work, update the resources in your workspace with the latest from the repository. 2. Run all unit tests. Run the unit tests and be sure that they all pass. If the system is broken when you start, you'll have more difficulty testing your own changes. 3. Make changes. Add, delete, and edit resources in your local workspace. If necessary, write new unit tests that exercise the new behavior. Debug until the new feature is working successfully. 4. Run all unit tests again. Run all unit tests again to ensure that none of the changes broke other components that you thought were unrelated. 5. Synchronize. When you are ready to commit your work, synchronize with the repository. First, examine incoming changes and add them to your local workspace. Resolve conflicts. Rerun unit tests to verify integrity of what you are about to commit. Finally, commit your changes.
65
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Get Connected
Eclipse Distilled in CVS
Host: Repository path: User: Password: Connection type: cvs.sourceforge.net /cvsroot/eclipsedistill anonymous -pserver
66
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
67
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
68
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Check Out to linked folder location Add this external folder location as a project named libraries in several workspaces
69
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Recommendation
create a workspace project named eclipse-config, commit to a CVS module that holds shared team configuration files
70
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
71
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
72
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Make this change on the Team > File Content preferences page before committing new resources. Otherwise, these unknown types will be versioned as Binary files and line-oriented text comparison or CVS merge will not be available.
73
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
74
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Commit All selected outgoing files with no conflicts are committed to the repository. Override and Commit This command operates on conflicts by replacing the remote repository resources with the local contents. Use this command with caution, only on conflicts where you want to ignore changes made in the repository by another developer.
75
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
1. Generate Java code from XML Schemas that define UBL data types and enumerated code lists 2. Run all JUnit tests and generate an HTML report of the test results 3. Generate Javadoc HTML files from the source code 4. Automate the entire project build and test process so that it can be run either inside or outside of Eclipse
com.eclipsdistilled.ubl src (Java source) schemas xsd codelist (several .xsd files) common (several .xsd files) ubl.wsdl build.xml build.xml build doc
77
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Other non-Java tools can be configured and (optionally) automated as External Tools Large builds can be run inside or outside of Eclipse using Ant
78
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Project. Each build file contains one project. Its not necessary for an Ant project to be equivalent to an Eclipse project; an Ant project represents a logical group of related targets. Target. An Ant project contains one or more targets that produce the build output, such as a library archive, or perform interim steps such as compiling source code or running tests. Dependencies between targets assure that prerequisites are completed before a target is run. Task. Each target contains tasks that represent its individual operations. Ant includes a long list of built-in tasks for performing operations such as copying files, running the Java compiler, or setting property values. Other tools can contribute new tasks that extend Ants capabilities.
79 Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Ant Editor
Tip: Use a small number of consistent names for your build files. Any names other than build.xml must be associated with the Ant Editor. In the preference page Workbench > File Associations, add javadoc.xml and associate it with the Ant Editor.
80
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
81
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
82
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
83
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
84
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Enable or disable this builder by checking the XSD Codelists item on the projects Builders page.
85
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
This property causes the auto-build to write source directly into the projects src folder.
86
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Agile Practices Team Ownership with CVS Continuous Integration with Ant
Focus on writing the tests that will catch most bugs; dont worry about the fact that you cant catch every bug.
88
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
89
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Separate Project
Preferred configuration No unit test libraries are added to your primary project classpath
Add junit.jar to the project classpath
90
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
OrderLine
1..*
<<enumeration>> MeasureUnitCodeContent
Write unit tests for order pricing calculation. Pseudo code: LineItem amount = quantity baseQuantity * priceAmount Order totalAmount = sum( LineItem amount )
91
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
0..*
Your test classes will inherit from TestCase and will implement one or more test methods having this pattern: testXxx() for example, testSetCurrency()
92
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
93
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
94
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
95
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Make sure that all tests are fully automatic and that they check their own results.
Dont forget to test whether exceptions are raised when things are expected to go wrong.
97
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Fast View
Test results summary on status bar icon Double click error trace to go to test/app source Failure: JUnit assertion or fail was invoked Error: Unexpected error, e.g. NullPointerException
98
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Compare Results
available when assertEquals() is used to compare two string value
99
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Run all tests in batch build Use JUnit XML formatter and
create an HTML report of results
<junitreport todir="${test.data.dir}"> <fileset dir="${test.data.dir}" includes="TEST-*.xml" /> <report format="frames" todir="${test.reports.dir}" /> </junitreport> <!-- Build fails if any of the unit tests fail --> <fail if="test.failed" message="JUnit tests failed. Check log and/or reports."/>
100
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Agile Practices Team Ownership with CVS Continuous Integration with Ant Continuous Testing with JUnit
Refactoring
Coding Standards
When to Refactor
Refactoring is done is small bursts when you encounter bad smells in your code:
Duplicated code Large classes Long methods Tightly coupled components
Whenever you have difficulty understanding or modifying some code, try to find the cause of this difficulty and refactor it away. Most common reason to refactor is when you need to add a new feature to your software. Eclipse automates many of the common Java refactorings described in Martin Fowlers book, Refactoring: Improving the Design of Existing Code
102
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
103
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Rename Package
Alt+Shift+T: Shows the refactoring menu for the view/editor selection. Alt+Shift+R: Starts a Rename refactoring operation on the view/editor selection.
104
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Extract Interface
Select each class in the ubl.datatypes.impl package and choose the Refactor > Extract Interface command Invoke Refactor > Move (Alt+Shift+V) to move the resulting interface to the ubl.datatypes package
105
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Introduce Factory
The refactoring operation inserts this method into the factory class:
public class DatatypesFactory { public static AmountImpl createAmount(double val, CurrencyCodeContent curr) { return new AmountImpl(val, curr); } }
106
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
107
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
108
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
109
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Agile Practices Team Ownership with CVS Continuous Integration with Ant Continuous Testing with JUnit Refactoring
Coding Standards
111
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Code Formatter
To customize the formatter, press the New button and enter a name for your profile, e.g. Acme Corporation Export your customized formatting rules and share them with your team
Ctrl+Shift+F: Format the selected lines in the current Java editor, or format all lines if there is no selection. Or invoke via the editor context menu Source > Format.
112
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
113
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
114
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Alt+Shift+J: Insert a Javadoc comment for the declaration contained by the current cursor position: a class, field, or method. Or invoke via the editor context menu Source > Add Javadoc Comment.
115
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0
Auditing Compliance
116
Eclipse Distilled: A Quick Start to Agile Development 2005 by David Carlson; made available under the EPL v1.0