...
- General Guide
- Getting Source code
- Setting up your development environment
- Importing SCA modules into your Development IDE
- Coding Guidelines
- Testing
- Client Applications
- Maven Build Structure
- Development Hints
...
Java SCA requires the following:
- JDK 5.0+ (J2SE 1.56.0+)
- Apache Maven (2.02.71+)
- Subversion (1.56+) or TortoiseSVN (1.56.x+)
- Eclipse PDE (Ganymede )
...
Code Block |
---|
svn checkout https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/sca |
Anchor | ||||
---|---|---|---|---|
|
...
Code Block |
---|
svn checkout https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/sca |
Building the SCA source code :
Code Block |
---|
cd trunk
mvn -fae clean install
|
It should work even if you start with an empty Maven local repository, and it should always work, however when you are building for Tuscany for the first time there are a lot of dependencies which must be downloaded so the first build can take a long time and it may fail with problems retrieving the dependencies.
...
Info |
---|
The SCA build consumes a good amount of memory, in case you are seeing issues during the build, set a MAVEN_OPTS environment variable to allocate more memory for the build process. Windows : SET MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=384m" |
Info |
---|
If you are using MAC OS, please see 'Special instructions for MAC OS users' section below |
Anchor | |||
---|---|---|---|
Anchor | |||
|
...
Code Block |
---|
mvn eclipse:eclipse |
To help with development in an OSGi environment Tuscany also has a build profile to setup the Eclipse Plugin Development Environment:
Now launch your Eclipse IDE, select File->Import->Existing projects into Workplace, and then import the project from SCA Modules into your Eclipse Workspace.
Using Eclipse PDE
To help with development in an OSGi environment Tuscany also has a build profile to setup the Eclipse Plugin Development Environment:
Code Blockcode |
---|
mvn -fae -Peclipse |
Now set the "Target Platform" in your Eclipse IDE by following the steps below :
...
- Project won't build - Sometimes a particular project will not build despite repeated efforts. Consider if this project is necessary to the task at hand. You may be able to delete the problematic Eclipse project and continue with other work.
Anchor |
---|
...
|
...
|
Some plugins used in the Tuscany build requires a explicit dependency on some classes from JDK tools.jar, which is in a different place in the MAC OS environment.
We have created duplicate profiles in Tuscany to accommodate the most used user tasks
- Running a build : there is a default profile for the mac environment properly configuring the tools.jar property
Code Block mvn clean install
- Creating Eclipse IDE project files : there is a "eclipse-mac" profile
Code Block mvn -Peclipse-mac
Update your maven settings.xml (%user_home%/.m2/settings.xml)
Updating your settings.xml with proper property configuration will make all profiles work in a MAC OS environment.
Code Block |
---|
<settings>
<profiles>
<profile>
<id>mac-os-configuration</id>
<properties>
<tools.jar>${java.home}/../Classes/classes.jar</tools.jar>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>mac-os-configuration</activeProfile>
</activeProfiles>
</settings>
|
Anchor | ||||
---|---|---|---|---|
|
There are a few simple guidelines when developing for JAVA SCA:
- The basic coding style used is the described at Sun Java coding standards but the main thing is to be consistent with the existing code you're updating, so for example, if you're updating a method that uses the braces on the same line style don't add code with the hanging braces style.
- Always include the Apache License Headers on all files (both source code files and resource files such as xml documents)
- Include a descriptive log message for checkins, for example "fixed such and such problem".
While Tuscany does not yet have an official style or template, here are some templates that folks have been using and have been checked into the build which are stored at https://svn.apache.org/repos/asf/tuscany/java/etc/
Naming conventions to increase consistency
Folder Names: Please use all lowercases and dashes in folder names (like in the jar names)
- Maven artifact id = tuscany-<folder name>
Package names: Package names within modules should include the module name so that source code can be located in the source tree easily. So, for example, java/sca/module/implementation-java would be in package structure org.apache.tuscany.implementation.java.*
Anchor | ||||
---|---|---|---|---|
|
Tuscany uses
There are a few simple guidelines when developing for JAVA SCA:
- The basic coding style used is the described at Sun Java coding standards but the main thing is to be consistent with the existing code you're updating, so for example, if you're updating a method that uses the braces on the same line style don't add code with the hanging braces style.
- Always include the Apache License Headers on all files (both source code files and resource files such as xml documents)
- Include a descriptive log message for checkins, for example "fixed such and such problem".
While Tuscany does not yet have an official style or template, here are some templates that folks have been using and have been checked into the build which are stored at https://svn.apache.org/repos/asf/tuscany/java/etc/
Naming conventions to increase consistency
Folder Names: Please use all lowercases and dashes in folder names (like in the jar names)
- Maven artifact id = tuscany-<folder name>
Package names: Package names within modules should include the module name so that source code can be located in the source tree easily. So, for example, java/sca/module/implementation-java would be in package structure org.apache.tuscany.implementation.java.*
...
Tuscany uses plain junit test cases to perform unit and integration testing, below is an example that can also be used as a template for writing new test cases; it demonstrates how to bootstrap the Tuscany SCA runtime in your test case, and because they are based on junit, you can run it from your IDE of choice or from Maven.
...
Code Block |
---|
@Scope("COMPOSITE") @EagerInit public class CalculatorClient { private CalculatorService calculatorService; @Reference public void setCalculatorService(CalculatorService calculatorService) { this.calculatorService = calculatorService; } private CalculatorService calculatorService; @Reference@Init public void setCalculatorServicecalculate(CalculatorService calculatorService) { // Calculate this.calculatorService = calculatorService; } System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader())); @Init public void calculate() { // CalculateSystem.out.println("3 + 2=" + calculatorService.add(3, 2)); System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); System.out.println("SCA3 API ClassLoader: * 2=" + print(Reference.class.getClassLoader(calculatorService.multiply(3, 2))); System.out.println("3 + 2=" + calculatorService.add(3, 2));"3 / 2=" + calculatorService.divide(3, 2)); } private static String print(ClassLoader cl) { System.out.println("3 - 2=" + calculatorService.subtract(3, 2)StringBuffer buf = new StringBuffer(); for System.out.println("3 * 2=" + calculatorService.multiply(3, 2));(; cl != null;) { System.out.println("3 / 2=" + calculatorService.divide(3, 2buf.append(cl.toString()); } private static String print(ClassLoader cl) { buf.append(' '); StringBuffer bufcl = new StringBuffercl.getParent(); } for (; cl != null;) { buf.append(cl.toString()); buf.append(' '); cl = cl.getParent(); } return buf.toString(); } } |
...
return buf.toString();
}
}
|
Anchor | ||||
---|---|---|---|---|
|
We use the term Module to refer to the leaf of maven tree.
- sca/pom.xml's parent will be pom/parent/pom.xml
- Other poms will use the pom from the parent folder as parent pom
- Group id: org.apache.tuscany.sca
- Version of our modules will be specified once in java/sca/pom.xml, child poms don't need specify a version as they get it from their parent
- pom names begin Apache Tuscany SCA
- Eclipse projects are generated for all built modules using mvn eclipse:eclipse
Adding a new module and not ready to integrate?
'work-in-progress' modules can be worked on in the same source tree and yet not break the top-down build. You can do this by not listing your module(s) in java/sca/modules/pom.xml.
Development Hints
Anchor | ||||
---|---|---|---|---|
|
This section has talked about how to get set up ready to develop Tuscany. If you need to import existing samples into Eclipse to work on there are some instructions here. These are instructions for 1.x but should work OK on 2.x.
We use the term Module to refer to the leaf of maven tree.
- sca/pom.xml's parent will be pom/parent/pom.xml
- Other poms will use the pom from the parent folder as parent pom
- Group id: org.apache.tuscany.sca
- Version of our modules will be specified once in java/sca/pom.xml, child poms don't need specify a version as they get it from their parent
- pom names begin Apache Tuscany SCA
- Eclipse projects are generated for all built modules using mvn eclipse:eclipse
Adding a new module and not ready to integrate?
'work-in-progress' modules can be worked on in the same source tree and yet not break the top-down build. You can do this by not listing your module(s) in java/sca/modules/pom.xml.
...
Anchor | ||||
---|---|---|---|---|
|
...
The magic -Dwtpversion=1.5 option will add the WTP Web project nature to
all the Eclipse projects with <packaging>war</packaging> in their Maven
pom.xml. You'll then be able to add these projects to a WTP Tomcat or
Geronimo Server configuration, to publish and run them straight from
your Eclipse workspace.h3:
Anchor | ||||
---|---|---|---|---|
|
Figuring out the package dependency to include in Ant build.xml can be a pain. Here is a quick
script which works in Linux environment for war files.
...