summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/documentation-2x/sca-java-development-guide.html
diff options
context:
space:
mode:
Diffstat (limited to 'site/trunk/site-publish/documentation-2x/sca-java-development-guide.html')
-rw-r--r--site/trunk/site-publish/documentation-2x/sca-java-development-guide.html524
1 files changed, 524 insertions, 0 deletions
diff --git a/site/trunk/site-publish/documentation-2x/sca-java-development-guide.html b/site/trunk/site-publish/documentation-2x/sca-java-development-guide.html
new file mode 100644
index 0000000000..1eea6ce884
--- /dev/null
+++ b/site/trunk/site-publish/documentation-2x/sca-java-development-guide.html
@@ -0,0 +1,524 @@
+
+
+
+
+
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<HTML>
+ <HEAD>
+ <META name="description" content="Apache Tuscany">
+ <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture, sca, service component architecture, das, sdo, csa, ruby, opensource">
+
+ <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css">
+ <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANYxDOCx2x/$images/favicon.ico">
+ <TITLE>SCA Java Development Guide : Apache Tuscany</TITLE>
+ <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
+
+ <STYLE>
+ .spacetree * ul {
+ padding-left:0px;
+ margin-left: 0px;
+ }
+ .spacetree * li {
+ margin-left: 5px;
+ padding-left:5px;
+ }
+ </STYLE>
+
+ <BODY onload="init()">
+ <!-- topNav -->
+ <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
+ <TR class="topBar">
+ <TD align="left" valign="middle" class="topBarDiv" align="left" nowrap="">
+ <A href="https://cwiki.apache.org/geronimo"> Home</A> &gt;&nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="development-guides.html" title="Development Guides">Development Guides</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java Development Guide">SCA Java Development Guide</A>
+ </TD>
+ <TD align="right" valign="middle" nowrap="">
+ <FORM name="search" action="http://www.google.com/search" method="get">
+ <INPUT type="hidden" name="ie" value="UTF-8">
+ <INPUT type="hidden" name="oe" value="UTF-8">
+ <INPUT type="hidden" name="domains" value="">
+ <INPUT type="hidden" name="sitesearch" value="">
+ <INPUT type="text" name="q" maxlength="255" value="">
+ <INPUT type="submit" name="btnG" value="Google Search">
+ </FORM>
+ </TD>
+ </TR>
+ </TABLE>
+
+
+ <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
+ <TR class="topBar">
+ <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
+ &nbsp;<A href="index.html" title="Apache Tuscany Docs 2.x">Apache Tuscany Docs 2.x</A>&nbsp;&gt;&nbsp;<A href="index.html" title="Index">Index</A>&nbsp;&gt;&nbsp;<A href="development-guides.html" title="Development Guides">Development Guides</A>&nbsp;&gt;&nbsp;<A href="" title="SCA Java Development Guide">SCA Java Development Guide</A>
+ </TD>
+
+ <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
+ <A href="http://tuscany.apache.org/">Tuscany Home</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>&nbsp;&nbsp;
+ </TD>
+ </TR>
+ </TABLE>
+
+ <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
+ <TR>
+ <TD valign="top" align="left" width="22%" bgcolor="#F9F9F9" class="noprint">
+ <DIV class="tabletitle">Table of Contents</DIV>
+ <DIV class="spacetree">
+
+
+ </DIV>
+ </TD>
+ <TD align="left" valign="top" width="78%">
+ <!-- pageContent -->
+ <DIV id="PageContent">
+ <DIV class="pageheader" style="padding: 6px 0px 0px 0px;">
+ <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
+ <!--img src="http://geronimo.apache.org/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
+ <DIV style="margin: 0px 10px 0px 10px" class="smalltext">Apache Tuscany Docs 2.x</DIV>
+ <DIV style="margin: 0px 10px 8px 10px" class="pagetitle">SCA Java Development Guide</DIV>
+
+ <DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
+<!-- -->
+ <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=109132">
+ <IMG src="http://geronimo.apache.org/images/icons/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=109132">Edit Page</A>
+ &nbsp;
+ <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">
+ <IMG src="http://geronimo.apache.org/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Browse Space"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANYxDOCx2x">Browse Space</A>
+ &nbsp;
+ <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109132">
+ <IMG src="http://geronimo.apache.org/images/icons/add_page_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add Page"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109132">Add Page</A>
+ &nbsp;
+ <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109132">
+ <IMG src="http://geronimo.apache.org/images/icons/add_blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add News"></A>
+ <A href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANYxDOCx2x&fromPageId=109132">Add News</A>
+<!-- -->
+ </DIV>
+ </DIV>
+
+ <DIV class="pagecontent">
+ <DIV class="wiki-content">
+ <P>This document is the development guideline for SCA Java 2.x project.</P>
+
+<UL>
+ <LI><A href="#SCAJavaDevelopmentGuide-GeneralGuide">General Guide</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-GettingSource">Getting Source code</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-Setup">Setting up your development environment</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-IDE">Importing SCA modules into your Development IDE</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-CodingGuidelines">Coding Guidelines</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-Testing">Testing</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-ClientApplications">Client Applications</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-MavenBuildStructure">Maven Build Structure</A></LI>
+ <LI><B>Development Hints</B>
+ <UL>
+ <LI><A href="#SCAJavaDevelopmentGuide-SamplesinEclipse">Importing existing Tuscany SCA projects into Eclipse</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-WebappinEclipse">Generating Eclipse WTP Web Projects for Webapp samples</A></LI>
+ <LI><A href="#SCAJavaDevelopmentGuide-Ant">Generating Dependencies for Ant in Samples</A></LI>
+ </UL>
+ </LI>
+</UL>
+
+
+<H3><A name="SCAJavaDevelopmentGuide-OSGiOverviewandApproach"></A>OSGi Overview and Approach</H3>
+
+<P><A href="http://people.apache.org/~lresende/presentations/felix%20goes%20to%20tuscany.pdf" class="external-link" rel="nofollow">OSGI &amp; Tuscany</A></P>
+
+<H3><A name="SCAJavaDevelopmentGuide-GeneralGuide"></A><A name="SCAJavaDevelopmentGuide-GeneralGuide"></A> General Guide</H3>
+
+<P>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.</P>
+
+<P>Here are some general guidelines we use in this project.</P>
+<UL>
+ <LI>Java SCA sub-project aims to provide enterprise-grade service infrastructure based on SCA.</LI>
+ <LI>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.</LI>
+ <LI>The Java SCA infrastructure should provide flexibility and choice. It should not dictate programming models but support many.</LI>
+ <LI>The Java SCA infrastructure is very modularized and is designed to be highly extensible so users can customize it to fit their needs.</LI>
+</UL>
+
+
+<H3><A name="SCAJavaDevelopmentGuide-Prerequisites"></A><A name="SCAJavaDevelopmentGuide-Prerequisites"></A> Prerequisites</H3>
+
+<P>Java SCA requires the following:</P>
+<UL>
+ <LI><A href="http://java.sun.com/javase/downloads/index.jsp" class="external-link" rel="nofollow">J2SE 1.6.0+)</A></LI>
+ <LI><A href="http://maven.apache.org/" class="external-link" rel="nofollow">Apache Maven (2.2.1+)</A></LI>
+ <LI><A href="http://subversion.tigris.org/" class="external-link" rel="nofollow">Subversion (1.6+)</A> or <A href="http://tortoisesvn.tigris.org/" class="external-link" rel="nofollow">TortoiseSVN (1.6.x+)</A></LI>
+ <LI><A href="http://www.eclipse.org/downloads" class="external-link" rel="nofollow">Eclipse PDE (Ganymede ) </A></LI>
+</UL>
+
+
+<H4><A name="SCAJavaDevelopmentGuide-CheckingoutcodefromSubversion"></A>Checking out code from Subversion</H4>
+
+<P>Use the command as follows:</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+svn checkout https:<SPAN class="code-comment">//svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/</SPAN>
+</PRE>
+</DIV></DIV>
+
+<H3><A name="SCAJavaDevelopmentGuide-SettingupyourDevelopmentEnvironment"></A><A name="SCAJavaDevelopmentGuide-Setup"></A> Setting up your Development Environment</H3>
+
+<H4><A name="SCAJavaDevelopmentGuide-topdownbuild%28recommendedapproach%29"></A>top-down build (recommended approach)</H4>
+
+<P>Check out all of the java source code.</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+svn checkout https:<SPAN class="code-comment">//svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/</SPAN>
+</PRE>
+</DIV></DIV>
+<P>Building the SCA source code :</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+cd trunk
+mvn -fae clean install
+</PRE>
+</DIV></DIV>
+<P>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.</P>
+
+<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> 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.</P>
+
+<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> 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 &quot;-U&quot; parameter in the mvn command.</P>
+
+<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> 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 &quot;-o&quot; parameter in the mvn command.</P>
+
+<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>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.
+
+<P> Windows : SET MAVEN_OPTS=&quot;-Xmx512m -XX:MaxPermSize=384m&quot;<BR>
+ Unix : export MAVEN_OPTS=&quot;-Xmx512m -XX:MaxPermSize=384m&quot;</P></TD></TR></TABLE></DIV>
+
+<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>If you are using MAC OS, please see 'Special instructions for MAC OS users' section below</TD></TR></TABLE></DIV>
+
+<H3><A name="SCAJavaDevelopmentGuide-ImportingSCAmodulesintoyourDevelopmentIDE"></A><A name="SCAJavaDevelopmentGuide-IDE"></A>Importing SCA modules into your Development IDE</H3>
+
+
+<H4><A name="SCAJavaDevelopmentGuide-UsingEclipse"></A>Using Eclipse</H4>
+
+<P>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 :</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+mvn -Declipse.workspace=[path-to-eclipse-workspace] eclipse:add-maven-repo
+</PRE>
+</DIV></DIV>
+<P>In order to generate the necessary project files to import the SCA modules to Eclipse, you can use the maven eclipse plugin</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+mvn eclipse:eclipse
+</PRE>
+</DIV></DIV>
+
+<P>Now launch your Eclipse IDE, select File-&gt;Import-&gt;Existing projects into Workplace, and then import the project from SCA Modules into your Eclipse Workspace.</P>
+
+<H4><A name="SCAJavaDevelopmentGuide-UsingEclipsePDE"></A>Using Eclipse PDE</H4>
+
+<P>To help with development in an OSGi environment Tuscany also has a build profile to setup the Eclipse Plugin Development Environment:</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+mvn -fae -Peclipse
+</PRE>
+</DIV></DIV>
+
+<P>Now set the &quot;Target Platform&quot; in your Eclipse IDE by following the steps below :</P>
+
+<UL>
+ <LI>Inside eclipse, select File-&gt;Open File&quot; and open &quot;distribution/all/target/features/tuscany.target&quot;
+ <UL>
+ <LI>click &quot;Set as target platform&quot; on the upper-right side of the overview window that opened</LI>
+ </UL>
+ </LI>
+</UL>
+
+
+<P>Then as when using eclipse:eclipse launch your Eclipse IDE, select File-&gt;Import-&gt;Existing projects into Workplace, and then import the project from SCA Modules into your Eclipse Workspace.</P>
+
+<P>There are also some Tuscany Eclipse code templates available:<BR>
+<A href="https://svn.apache.org/repos/asf/tuscany/java/etc/tuscany-eclipse-codestyle.xml" class="external-link" rel="nofollow">Eclipse Style Formatter </A><BR>
+<A href="https://svn.apache.org/repos/asf/tuscany/java/etc/tuscany-eclipse-codetemplates.xml" class="external-link" rel="nofollow">Eclipse Templates </A></P>
+
+<H4><A name="SCAJavaDevelopmentGuide-EclipseBuildTroubleshooting"></A><A name="SCAJavaDevelopmentGuide-EclipseBuildTroubleshooting"></A> Eclipse Build Troubleshooting</H4>
+
+<P>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:</P>
+
+<UL>
+ <LI><B>Missing classpath variables</B> - Sometimes Java build classpath variables are incorrect or missing, for instance &quot;Unbound classpath variable: 'M2_REPO/com/sun/xml/bind/jaxb-impl/2.1.9/jaxb-impl-2.1.9.jar'&quot;. Add the classpath variable 'M2_REPOS' to your workspace. Window &gt; Preferences &gt; Java &gt; Build Path &gt; Classpath variables. Create variables for any missing variables and point them to the appropriate place in your file system. Do a complete rebuild.</LI>
+</UL>
+
+
+<UL>
+ <LI><B>Missing projects</B> - Sometimes developers add or remove project dependencies. These show up with error message &quot;The project cannot be built until build path errors are resolved&quot;. This is often a sign that your Eclipse workspace is out of sync with your local repository or the svn repository. The full remedy is to refresh your local repos (svn update), rebuild your local repos (mvn clean install -U), regenerate Eclipse projects (mvn -Declipse), reimport projects in Eclipse, and clean/rebuild your projects. You may be able to do less than this full refresh with simple changes, but the full refresh is often needed for major changes.</LI>
+</UL>
+
+
+<UL>
+ <LI><B>Project won't build</B> - 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.</LI>
+</UL>
+
+
+
+<H3><A name="SCAJavaDevelopmentGuide-SpecialinstructionsforMACOSusers"></A><A name="SCAJavaDevelopmentGuide-MacOS"></A> Special instructions for MAC OS users</H3>
+
+<P>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. </P>
+
+<P>We have created duplicate profiles in Tuscany to accommodate the most used user tasks</P>
+
+<UL>
+ <LI>Running a build : there is a default profile for the mac environment properly configuring the tools.jar property
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+ mvn clean install
+</PRE>
+</DIV></DIV></LI>
+</UL>
+
+
+<UL>
+ <LI>Creating Eclipse IDE project files : there is a &quot;eclipse-mac&quot; profile
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+ mvn -Peclipse-mac
+</PRE>
+</DIV></DIV></LI>
+</UL>
+
+
+<H4><A name="SCAJavaDevelopmentGuide-Updateyourmavensettings.xml%28%25userhome%25%2F.m2%2Fsettings.xml%29"></A>Update your maven settings.xml (%user_home%/.m2/settings.xml)</H4>
+
+<P>Updating your settings.xml with proper property configuration will make all profiles work in a MAC OS environment.</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+&lt;settings&gt;
+
+ &lt;profiles&gt;
+ &lt;profile&gt;
+ &lt;id&gt;mac-os-configuration&lt;/id&gt;
+ &lt;properties&gt;
+ &lt;tools.jar&gt;${java.home}/../Classes/classes.jar&lt;/tools.jar&gt;
+ &lt;/properties&gt;
+ &lt;/profile&gt;
+ &lt;/profiles&gt;
+
+ &lt;activeProfiles&gt;
+ &lt;activeProfile&gt;mac-os-configuration&lt;/activeProfile&gt;
+ &lt;/activeProfiles&gt;
+
+&lt;/settings&gt;
+</PRE>
+</DIV></DIV>
+
+<H3><A name="SCAJavaDevelopmentGuide-CodingGuidelines"></A><A name="SCAJavaDevelopmentGuide-CodingGuidelines"></A> Coding Guidelines</H3>
+
+<P>There are a few simple guidelines when developing for JAVA SCA:</P>
+<UL>
+ <LI>The basic coding style used is the described at <A href="http://java.sun.com/docs/codeconv/" class="external-link" rel="nofollow">Sun Java coding standards</A> 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.</LI>
+</UL>
+
+
+<UL>
+ <LI>Always include the Apache License Headers on all files (both source code files and resource files such as xml documents)</LI>
+</UL>
+
+
+<UL>
+ <LI>Include a descriptive log message for checkins, for example &quot;fixed such and such problem&quot;.</LI>
+</UL>
+
+
+<P>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 <A href="https://svn.apache.org/repos/asf/tuscany/java/etc/" class="external-link" rel="nofollow">https://svn.apache.org/repos/asf/tuscany/java/etc/</A></P>
+
+<H4><A name="SCAJavaDevelopmentGuide-Namingconventionstoincreaseconsistency"></A>Naming conventions to increase consistency</H4>
+
+<P><B>Folder Names:</B> Please use all lowercases and dashes in folder names (like in the jar names)</P>
+<UL class="alternate" type="square">
+ <LI>Maven artifact id = tuscany-&lt;folder name&gt;</LI>
+</UL>
+
+
+<P><B>Package names:</B> 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.&#42;</P>
+
+<H3><A name="SCAJavaDevelopmentGuide-Testing"></A><A name="SCAJavaDevelopmentGuide-Testing"></A> Testing</H3>
+
+<P>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.</P>
+
+<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>Note that we are using JUnit 4.2 code style in OSGI development stream</TD></TR></TABLE></DIV>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+/**
+ * Description of your test <SPAN class="code-keyword">case</SPAN> and necessary details you find necessary
+ */
+@Scope(<SPAN class="code-quote">&quot;COMPOSITE&quot;</SPAN>) @EagerInit
+<SPAN class="code-keyword">public</SPAN> class CalculatorTestCase {
+
+ <SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">static</SPAN> CalculatorService calculatorService;
+ <SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">static</SPAN> NodeLauncher launcher;
+ <SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">static</SPAN> Node node;
+
+ @Reference
+ <SPAN class="code-keyword">public</SPAN> void setCalculatorService(CalculatorService calculatorService) {
+ CalculatorTestCase.calculatorService = calculatorService;
+ }
+
+
+ @BeforeClass
+ <SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">static</SPAN> void setUpBeforeClass() <SPAN class="code-keyword">throws</SPAN> Exception {
+ launcher = NodeLauncher.newInstance();
+ <SPAN class="code-object">String</SPAN> location = ContributionLocationHelper.getContributionLocation(CalculatorClient.class);
+ node = launcher.createNode(<SPAN class="code-quote">&quot;Calculator.composite&quot;</SPAN>, <SPAN class="code-keyword">new</SPAN> Contribution(<SPAN class="code-quote">&quot;test&quot;</SPAN>, location));
+ <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;SCA Node API <SPAN class="code-object">ClassLoader</SPAN>: &quot;</SPAN> + node.getClass().getClassLoader());
+ node.start();
+ }
+
+ @AfterClass
+ <SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">static</SPAN> void tearDownAfterClass() <SPAN class="code-keyword">throws</SPAN> Exception {
+ <SPAN class="code-keyword">if</SPAN> (node != <SPAN class="code-keyword">null</SPAN>) {
+ node.stop();
+ node.destroy();
+ }
+ <SPAN class="code-keyword">if</SPAN> (launcher != <SPAN class="code-keyword">null</SPAN>) {
+ launcher.destroy();
+ }
+ }
+
+ @Test
+ <SPAN class="code-keyword">public</SPAN> void testCalculator() <SPAN class="code-keyword">throws</SPAN> Exception {
+ <SPAN class="code-comment">// Calculate
+</SPAN> 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);
+ }
+}
+</PRE>
+</DIV></DIV>
+<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> Note that we use surefire maven plugin to run the unit and integration tests, and in most cases, they are configured to match a &#42;*/*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.</P>
+
+<H3><A name="SCAJavaDevelopmentGuide-ClientApplicationsasSCAComponents"></A><A name="SCAJavaDevelopmentGuide-ClientApplications"></A> Client Applications as SCA Components</H3>
+
+<P>Below is how you can build client applications as an SCA component.</P>
+
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+@Scope(<SPAN class="code-quote">&quot;COMPOSITE&quot;</SPAN>) @EagerInit
+<SPAN class="code-keyword">public</SPAN> class CalculatorClient {
+
+ <SPAN class="code-keyword">private</SPAN> CalculatorService calculatorService;
+
+ @Reference
+ <SPAN class="code-keyword">public</SPAN> void setCalculatorService(CalculatorService calculatorService) {
+ <SPAN class="code-keyword">this</SPAN>.calculatorService = calculatorService;
+ }
+
+ @Init
+ <SPAN class="code-keyword">public</SPAN> void calculate() {
+
+ <SPAN class="code-comment">// Calculate
+</SPAN> <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;SCA API <SPAN class="code-object">ClassLoader</SPAN>: &quot;</SPAN> + print(Reference.class.getClassLoader()));
+ <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;3 + 2=&quot;</SPAN> + calculatorService.add(3, 2));
+ <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;3 - 2=&quot;</SPAN> + calculatorService.subtract(3, 2));
+ <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;3 * 2=&quot;</SPAN> + calculatorService.multiply(3, 2));
+ <SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">&quot;3 / 2=&quot;</SPAN> + calculatorService.divide(3, 2));
+ }
+
+ <SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">static</SPAN> <SPAN class="code-object">String</SPAN> print(<SPAN class="code-object">ClassLoader</SPAN> cl) {
+ <SPAN class="code-object">StringBuffer</SPAN> buf = <SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">StringBuffer</SPAN>();
+ <SPAN class="code-keyword">for</SPAN> (; cl != <SPAN class="code-keyword">null</SPAN>;) {
+ buf.append(cl.toString());
+ buf.append(' ');
+ cl = cl.getParent();
+ }
+ <SPAN class="code-keyword">return</SPAN> buf.toString();
+ }
+
+}
+</PRE>
+</DIV></DIV>
+
+<H3><A name="SCAJavaDevelopmentGuide-MavenBuildStructure"></A><A name="SCAJavaDevelopmentGuide-MavenBuildStructure"></A> Maven Build Structure</H3>
+
+<P><EM>We use the term Module to refer to the leaf of maven tree.</EM></P>
+<UL>
+ <LI>sca/pom.xml's parent will be pom/parent/pom.xml</LI>
+ <LI>Other poms will use the pom from the parent folder as parent pom</LI>
+ <LI>Group id: org.apache.tuscany.sca</LI>
+ <LI>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</LI>
+ <LI>pom names begin Apache Tuscany SCA</LI>
+ <LI>Eclipse projects are generated for all built modules using mvn eclipse:eclipse</LI>
+</UL>
+
+
+<H4><A name="SCAJavaDevelopmentGuide-Addinganewmoduleandnotreadytointegrate%3F"></A>Adding a new module and not ready to integrate?</H4>
+
+<P>'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.</P>
+
+<H2><A name="SCAJavaDevelopmentGuide-DevelopmentHints"></A>Development Hints</H2>
+
+<H3><A name="SCAJavaDevelopmentGuide-ImportingexistingTuscanySCAprojectsintoEclipse"></A><A name="SCAJavaDevelopmentGuide-SamplesinEclipse"></A>Importing existing Tuscany SCA projects into Eclipse</H3>
+
+<P>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 <A href="http://tuscany.apache.org/import-existing-tuscany-sca-projects-into-eclipse.html" class="external-link" rel="nofollow">here</A>. These are instructions for 1.x but should work OK on 2.x. </P>
+
+<H3><A name="SCAJavaDevelopmentGuide-GeneratingEclipseWTPWebProjectsforWebappsamples"></A><A name="SCAJavaDevelopmentGuide-WebappinEclipse"></A> Generating Eclipse WTP Web Projects for Webapp samples</H3>
+
+<P>If you're using Eclipse WTP and want to get WTP Web Projects generated<BR>
+for our Webapp samples you can simply pass a &#45;Dwtpversion=1.5 option to<BR>
+the usual mvn eclipse:eclipse command, like this:<BR>
+mvn &#45;Dwtpversion=1.5 &#45;Peclipse eclipse:eclipse</P>
+
+<P>The magic &#45;Dwtpversion=1.5 option will add the WTP Web project nature to<BR>
+all the Eclipse projects with &lt;packaging&gt;war&lt;/packaging&gt; in their Maven<BR>
+pom.xml. You'll then be able to add these projects to a WTP Tomcat or<BR>
+Geronimo Server configuration, to publish and run them straight from<BR>
+your Eclipse workspace.</P>
+
+<H3><A name="SCAJavaDevelopmentGuide-GeneratingDependenciesforAntinSamples"></A><A name="SCAJavaDevelopmentGuide-Ant"></A> Generating Dependencies for Ant in Samples</H3>
+
+<P>Figuring out the package dependency to include in Ant build.xml can be a pain. Here is a quick<BR>
+script which works in Linux environment for war files.</P>
+<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
+<PRE class="code-java">
+jar tvf sample-feed-aggregator-webapp.war | grep .jar | awk '{ printf <SPAN class="code-quote">&quot;%s\n&quot;</SPAN>, $8 }' |
+ sed -e <SPAN class="code-quote">&quot;s/WEB-INF\/lib\<SPAN class="code-comment">///&quot;</SPAN> | awk '{ printf <SPAN class="code-quote">&quot;&lt;include name=\&quot;</SPAN>%s\<SPAN class="code-quote">&quot;/&gt;\n&quot;</SPAN>, $1 }' | grep -v tuscany</SPAN>
+</PRE>
+</DIV></DIV>
+<TD class="confluenceTd" valign="top"></TD>
+<TABLE class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR></TR></TBODY></TABLE>
+ </DIV>
+
+ </DIV>
+ </DIV>
+ </TD>
+ </TR>
+ </TABLE>
+
+ <!-- footer -->
+ <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
+ <TR>
+ <TD align="left" valign="middle" class="footer">
+ &nbsp;&nbsp;
+ <IMG src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious">
+ <A href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'delicious','toolbar=no,width=550,height=550'); return false;">Bookmark this on Delicious</A>
+ &nbsp;&nbsp;
+ <IMG src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" height="16" alt="Digg!">
+ <A href="" onclick="window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&topic=programming');">Digg this</A>
+ <!-- Slicker, but no text
+ <script type="text/javascript">
+ digg_skin = 'icon';
+ digg_window = 'new';
+ digg_title = 'Apache Geronimo v2.2 Documentation : SCA Java Development Guide';
+ digg_topic = 'programming';
+ </script>
+ <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
+ -->
+ &nbsp;&nbsp;
+ </TD>
+ <TD align="right" valign="middle" class="footer">
+ <A href="http://cwiki.apache.org/GMOxPMGT/geronimo-privacy-policy.html">Privacy Policy</A>&nbsp;&nbsp;-&nbsp;&nbsp;
+ Copyright &copy; 2003-2010, The Apache Software Foundation, Licensed under <A href="http://www.apache.org/licenses/LICENSE-2.0">ASL 2.0.</A>&nbsp;&nbsp;
+ </TD>
+ </TR>
+ </TABLE>
+
+ </BODY>
+</HTML> \ No newline at end of file