This document is the development guideline for SCA Java 2.x project.
Welcome to the Tuscany SCA Java subproject project. We look forward to your participation and try to help you get on board. Feel free to ask your questions on the mailing list.
Here are some general guidelines we use in this project.
Java SCA requires the following:
Use the command as follows:
svn checkout https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/ |
Check out all of the java source code.
svn checkout https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/ |
Building the SCA source code :
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.
There can be occasional problems downloading artifacts from remote Maven repositories so if mvn fails with network related sounding messages sometimes just trying again can fix the problem.
The trunk code sometimes has SNAPSHOT dependencies which can get out of date in your local repository so if you see odd build failures try updating the SNAPSHOT jars by using the "-U" parameter in the mvn command.
Once you have done a top-down build, and your local maven repository is populated, you can start using the maven off line option to speed up the build process by using the "-o" parameter in the mvn command.
|
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" |
|
If you are using MAC OS, please see 'Special instructions for MAC OS users' section below |
If this is the first time you are using your workspace with maven m2 local repository, you will need to tell your Eclipse workspace the location of the directory, and you can do this with the following command :
mvn -Declipse.workspace=[path-to-eclipse-workspace] eclipse:add-maven-repo |
In order to generate the necessary project files to import the SCA modules to Eclipse, you can use the maven eclipse plugin
mvn eclipse:eclipse |
Now launch your Eclipse IDE, select File->Import->Existing projects into Workplace, and then import the project from SCA Modules into your Eclipse Workspace.
To help with development in an OSGi environment Tuscany also has a build profile to setup the Eclipse Plugin Development Environment:
mvn -fae -Peclipse |
Now set the "Target Platform" in your Eclipse IDE by following the steps below :
Then as when using eclipse:eclipse launch your Eclipse IDE, select File->Import->Existing projects into Workplace, and then import the project from SCA Modules into your Eclipse Workspace.
There are also some Tuscany Eclipse code templates available:
Eclipse Style Formatter
Eclipse Templates
Sometimes a Maven build will work from the command line, yet the same component will not build in the Eclipse environment. Of course, developers try to prevent this from happening, but it does happen and makes for a valid Jira. In the meantime, here are some steps that might help correct build issues in the Eclipse environment:
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
mvn clean install |
mvn -Peclipse-mac |
Updating your settings.xml with proper property configuration will make all profiles work in a MAC OS environment.
<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>
|
There are a few simple guidelines when developing for JAVA SCA:
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/
Folder Names: Please use all lowercases and dashes in folder names (like in the jar names)
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.
|
Note that we are using JUnit 4.2 code style in OSGI development stream |
/**
* Description of your test case and necessary details you find necessary
*/
@Scope("COMPOSITE") @EagerInit
public class CalculatorTestCase {
private static CalculatorService calculatorService;
private static NodeLauncher launcher;
private static Node node;
@Reference
public void setCalculatorService(CalculatorService calculatorService) {
CalculatorTestCase.calculatorService = calculatorService;
}
@BeforeClass
public static void setUpBeforeClass() throws Exception {
launcher = NodeLauncher.newInstance();
String location = ContributionLocationHelper.getContributionLocation(CalculatorClient.class);
node = launcher.createNode("Calculator.composite", new Contribution("test", location));
System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader());
node.start();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
if (node != null) {
node.stop();
node.destroy();
}
if (launcher != null) {
launcher.destroy();
}
}
@Test
public void testCalculator() throws Exception {
// Calculate
assertEquals(calculatorService.add(3, 2), 5.0);
assertEquals(calculatorService.subtract(3, 2), 1.0);
assertEquals(calculatorService.multiply(3, 2), 6.0);
assertEquals(calculatorService.divide(3, 2), 1.5);
}
}
|
Note that we use surefire maven plugin to run the unit and integration tests, and in most cases, they are configured to match a **/*TestCase.java file name pattern. Because of this, if your test case has a different file name pattern, you might execute it from your IDE of choice, but the maven build won't execute the test.
Below is how you can build client applications as an SCA component.
@Scope("COMPOSITE") @EagerInit
public class CalculatorClient {
private CalculatorService calculatorService;
@Reference
public void setCalculatorService(CalculatorService calculatorService) {
this.calculatorService = calculatorService;
}
@Init
public void calculate() {
// Calculate
System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader()));
System.out.println("3 + 2=" + calculatorService.add(3, 2));
System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
System.out.println("3 / 2=" + calculatorService.divide(3, 2));
}
private static String print(ClassLoader cl) {
StringBuffer buf = new StringBuffer();
for (; cl != null;) {
buf.append(cl.toString());
buf.append(' ');
cl = cl.getParent();
}
return buf.toString();
}
}
|
We use the term Module to refer to the leaf of maven tree.
'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.
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.
If you're using Eclipse WTP and want to get WTP Web Projects generated
for our Webapp samples you can simply pass a -Dwtpversion=1.5 option to
the usual mvn eclipse:eclipse command, like this:
mvn -Dwtpversion=1.5 -Peclipse eclipse:eclipse
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.
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.
jar tvf sample-feed-aggregator-webapp.war | grep .jar | awk '{ printf "%s\n", $8 }' |
sed -e "s/WEB-INF\/lib\///" | awk '{ printf "<include name=\"%s\"/>\n", $1 }' | grep -v tuscany
|