2016/05/28 - Apache Tuscany has been retired.

For more information, please explore the Attic.

 
 Apache Tuscany > Home > SCA Overview > SCA Java > Java SCA Documentation Menu > SCA Java Development Guide User List | Dev List | Issue Tracker  
Resources

General Guide

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 sub-project aims to provide enterprise-grade service infrastructure based on SCA.
  • Tuscany SCA is not just a reference implementation. We encourage innovation based on the tenets of SCA. A lot of work we do provides feedback to the specifications.
  • The Java SCA infrastructure should provide flexibility and choice. It should not dictate programming models but support many.
  • The Java SCA infrastructure is very modularized and is designed to be highly extensible so users can customize it to fit their needs.

Prerequisites

Java SCA requires the following:

Getting Source code

The Java SCA project Subversion repository is located at https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk/.
The repository can also be viewed online at http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/

Anyone can check code out of Subversion. You only need to specify a username and password in order to update the Subversion repository, and only Tuscany committers have the permissions to do so.

Checking out code from Subversion

Use the command as follows (note that it uses http scheme so if you're a committer change it to https):

svn checkout http://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk/ sca-java-1.x

Committing Changes to Subversion

Any Tuscany committer should have a shell account on svn.apache.org. Before you can commit, you'll need to set a Subversion password for yourself. To do that, log in to svn.apache.org and run the command svnpasswd.

Tuscany committers should configure these properties in the svn per-user config. On Unix-like systems, this area appears as a directory named .subversion in the user's home directory. On Win32 systems, Subversion creates a folder named Subversion, typically inside the Application Data area of the user's profile directory (C:\Documents and Settings\<user name>\Application Data\Subversion, which, by the way, is usually a hidden directory).

Please make sure the following properties are set in the "config" file:

[miscellany]
...
enable-auto-props = yes

[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.

*.c = svn:eol-style=native
*.cpp = svn:eol-style=native
*.h = svn:eol-style=native
*.dsp = svn:eol-style=CRLF
*.dsw = svn:eol-style=CRLF
*.sh = svn:eol-style=native;svn:executable
*.txt = svn:eol-style=native
*.png = svn:mime-type=image/png
*.jpg = svn:mime-type=image/jpeg
Makefile = svn:eol-style=native

*.java = svn:eol-style=native;svn:keywords=Rev Date
*.xml = svn:eol-style=native;svn:keywords=Rev Date
*.xsd = svn:eol-style=native;svn:keywords=Rev Date
*.html = svn:eol-style=native;svn:keywords=Rev Date
*.properties = svn:eol-style=native;svn:keywords=Rev Date
*.jelly = svn:eol-style=native;svn:keywords=Rev Date
*.ipr = svn:eol-style=native
*.iml = svn:eol-style=native

Once your password is set, you can use a command like this to commit:

svn commit

If Subversion can't figure out your username, you can tell it explicitly:

svn --username <name> commit

Subversion will prompt you for a password, and once you've entered it, it will remember it for you. Note this is the password you configured with svnpasswd not your shell or other password.

Setting up your Development Environment

Build tree structure

The build tree is designed to facilitate modular development and releases. Maven modules are grouped by how they are released under an hierarchy. Java SCA currently have the below module hierarchy :

-java
 |-- sca
     |-- demos                SCA demo applications
     |-- distribution         SCA distributions
     |-- itest                SCA Integration Tests
     |-- modules              SCA Implementation Modules (core, runtimes, contribution, extensions, etc)
     |-- samples              SCA Sample Applications
     |-- tools                SCA Tools (Eclipse plugins, wsdl2java, java2wsdl, etc)
     |-- tutorial             SCA Tutorial

The individual modules can be built separately or build with top-down build.

top-down build (recommended approach)

Check out all of the java source code.

svn checkout http://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk/ sca-java-1.x

Building the SCA source code is simple

cd sca-java-1.x
mvn

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 with:

mvn -U

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

mvn -o
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
Unix : export MAVEN_OPTS=-Xmx512m

The "trunk" is always in very active development, and sometimes you might experience issues trying to build some modules, in that case you can tell maven to continue building other modules
mvn -fae clean install

or either skip all unit tests

mvn -fae -Dmaven.test.skip=true clean install

or run tests, but do not stop building if one of the tests fails

mvn -fn clean install

Building the binary and source distributions

The binary and source distribution release artifacts are created by running maven in the distribution folder, for example:

cd sca-java-1.x/distribution
mvn clean install -o

The distribution artifacts can then be found in the folder named "target" within the distribution folder.

Importing SCA modules into your Development IDE

Using Eclipse

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

cd sca-java-1.x
mvn eclipse:eclipse

Now, launch your Eclipse IDE, select File->Import->Existing projects into Workplace, and then select the base SCA directory (e.g java/sca) and then press Finish, this should import all SCA modules into your Eclipse Workspace.

There are some Tuscany Eclipse code templates available:
Eclipse Style Formatter
Eclipse Templates

Understanding SCA code path

Here is a walk through of key methods/functions which help you get started with SCA Java development.

Coding Guidelines

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".

Some other useful suggestions:

Clean Code
  • use correct visibility, private, default, public, avoid protected
  • make methods static if not using object state
  • make sure javadoc is in sync or remove that javadoc
  • no javadoc on overridden methods
  • test cases in same package to avoid having to over-open access to methods
  • don't create artificial dependencies by using constants from another module
  • don't extend/implement a 'constant' interface
  • avoid creating another private layer over a public interface/spi
  • remove old code, don't leave it commented out, very confusing
  • use functional programming names for functions that convert an object
  • add javadoc to private methods
  • review class javadoc and make sure it's accurate
  • inline methods used only once, or make them clean static functions
  • put utility methods in a Util class with package visibility
  • use static imports
  • use scoped variables
  • no stars in OSGi exports
  • correct use of generics, see the effective Java book
Unit/Integration Tests
  • put comments in test cases
  • review test cases and make sure they're included in the build
  • use junit 4 only, check correct use of @BeforeClass or @Before
  • use static imports for assert statements
Formatting
  • use Tuscany eclipse code style/formatter
  • no tabs
  • no excessive line wrapping

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.*

Testing

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.

/**
 * Description of your test case and necessary details you find necessary
 */
public class YourTestCase extends TestCase {
    private SCADomain domain;
    private YourService service;


    @Override
    protected void setUp() throws Exception {
    	domain = SCADomain.newInstance("YourTest.composite");
        service = domain.getService(YourService.class, "serviceName");
    }

    @Override
    protected void tearDown() throws Exception {
    	domain.close();
    }


   ...
}

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.

Maven Build Structure

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 -Peclipse 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.

Reporting issues and providing patches

Reporting an Issue or Asking For New Features

Please use ApacheJIRA system to report bugs or request new features. First time users need to create a login.

Search the existing JIRAs to see if what you want to create is already there. If not, create a new one. Make sure JIRAs are categorized correctly using JIRA categories and are created under the correct component area. Please include as much information as possible in your JIRA to help resolve the issue quicker. This can include version of the software used, platforms running on, steps to reproduce, test case, details of your requirement or even a patch if you have one.

Submitting a Patch

Please follow the steps below to create a patch. It will be reviewed and committed by a committer in the project.

  • Perform a full build with all tests enabled for the module the fix is for. Specific build procedures vary by sub-project.
  • Confirm that the problem is fixed and include a test case where possible to help the person who is applying the patch to verify the fix.
  • Generate the patch using svn diff File > patchfile
  • Try to give your patch files meaningful names, including the JIRA number
  • Add your patch file as an attachment to the associated JIRA issue
    • Clicking on the 'Patch Available' box in the screen where the patch is being submitted will help identify available patches quicker.

How do I get my JIRAs into a release?

You can always propose a release and drive the release with the content that you want. Another way to get a JIRA into a release is by providing a patch or working with other community members (volunteers) to help you get the problem fixed. You can also help by providing test cases.

Each release is managed by a release manager. Make sure that the Release Manager is aware of why a fix to a JIRA is important to your business. In general, the best attempt is made to include as many JIRAs as possible depending on the level of community help. The voting mechanism in the JIRA system can be used to raise the importance of a JIRA to the attention of the release manager. Adding comments in the JIRA would help the release manager understand why a JIRA is important to include in a given release.

How is a release done?

Anyone can volunteer to be a release manager and drive a release. Based on Apache guidelines, a release requires at least three PMC +1 votes and more +1s than -1s. A release can not be vetoed so a -1 does not block a release. The steps for how to create a Tuscany release are documented here

Development Hints

Generating Eclipse WTP Web Projects for Webapp samples

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.

h3: Generating Dependencies for Ant in Samples

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

How to do a release of Tuscany?

Here is the Checklist for doing a Tuscany SCA Java release .

website stats