1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
<!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="http://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico">
<TITLE>SCA Java 2.x Development Guide : Apache Tuscany</TITLE>
<META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
<BODY onload="init()">
<TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg">
<TR>
<TD valing="top" align="left">
<A href="http://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A>
</TD>
<TD>
<A href="http://tuscany.apache.org/"><IMG src="http://tuscany.apache.org/images/TuscanyLogo.jpg" border="0"></A>
</TD>
<TD width="100%">
</TD>
<!--td align="right">
<img src="http://incubator.apache.org/tuscany/images/apache- incubator- logo.png" border="0">
</td-->
<!-- Adds the edit page link to the top banner-->
<TD valign="bottom">
<DIV style="padding: 2px 10px; margin: 0px;">
<A href="http://cwiki.apache.org/confluence/pages/editpage.action?pageId=100579">
<IMG src="http://tuscany.apache.org/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
</DIV>
</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%">
<A href="home.html" title="Apache Tuscany">Apache Tuscany</A> > <A href="home.html" title="Home">Home</A> > <A href="sca-overview.html" title="SCA Overview">SCA Overview</A> > <A href="sca-java.html" title="SCA Java">SCA Java</A> > <A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Java SCA Documentation Menu</A> > <A href="" title="SCA Java 2.x Development Guide">SCA Java 2.x Development Guide</A>
</TD>
<TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
<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>
</TD>
</TR>
</TABLE>
<TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
<TR>
<TD align="left" valign="top">
<DIV id="PageContent">
<DIV class="pagecontent">
<DIV class="wiki-content">
<TABLE class="sectionMacroWithBorder" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR>
<TD class="confluenceTd" valign="top" width="15%">
<DIV class="panel" style="background-color: #ECF4D1;border-color: #C3CDA1;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #C3CDA1;background-color: #C3CDA1;"><B>General</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="home.html" title="Home">Home</A><BR>
<A href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="nofollow">License </A><BR>
<A href="sca-java-get-involved.html" title="SCA Java Get Involved">Get Involved</A><BR>
<A href="sca-java-found-a-bug.html" title="SCA Java Found A Bug">Found a Bug?</A></P>
</DIV></DIV>
<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java.html" title="SCA Java">SCA Java Home</A><BR>
<A href="tuscany-dashboard.html" title="Tuscany Dashboard">SCA Dashboard</A><BR>
<A href="java-sca-tools.html" title="Java SCA Tools">Tools </A><BR>
<A href="tuscany-sca-java-faq.html" title="Tuscany SCA Java - FAQ">FAQ</A></P>
</DIV></DIV>
<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java 1.x</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java-releases.html" title="SCA Java Releases">Downloads</A><BR>
<A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Documentation</A><BR>
<A href="https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk/" rel="nofollow">1.x Source Code</A><BR>
<A href="http://tinyurl.com/8rlxd3" rel="nofollow">Roadmap</A></P>
</DIV></DIV>
<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java 2.x</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java-2x-releases.html" title="SCA Java 2.x Releases">Downloads</A><BR>
<A href="http://tuscany.apache.org/documentation-2x/" rel="nofollow">Documentation</A><BR>
<A href="https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/" rel="nofollow">2.x Source Code</A><BR>
<A href="http://tinyurl.com/8rlxd3" rel="nofollow">Roadmap</A></P>
</DIV></DIV>
<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>Documentation</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sca-java-user-guide.html" title="SCA Java User Guide">User Guide</A><BR>
<A href="sca-java-architecture-guide.html" title="SCA Java Architecture Guide">Architecture Guide</A><BR>
<A href="sca-java-development-guide.html" title="SCA Java Development Guide">Developer Guide</A><BR>
<A href="sca-java-extension-development-guide.html" title="SCA Java Extension Development Guide">Extension Developer Guide</A></P>
</DIV></DIV>
<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>Resources</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="tuscany-sca-java-faq.html" title="Tuscany SCA Java - FAQ">FAQ</A><BR>
<A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sca" rel="nofollow">Source Code</A></P>
</DIV></DIV>
</TD>
<TD class="confluenceTd" valign="top" width="85%">
<DIV class="panel" style="background-color: #ECF4D1;border-color: #C3CDA1;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #C3CDA1;background-color: #C3CDA1;"><B>How to get involved in development of Java SCA?</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P>This document is the development guideline for SCA Java project.</P>
<UL>
<LI><A href="#SCAJava2.xDevelopmentGuide-GeneralGuide" title="#General Guide">General Guide\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-GettingSource" title="#Getting Source">Getting Source code\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-Setup" title="#Setup">Setting up your development environment\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-IDE" title="#IDE">Importing SCA modules into your Development IDE\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-CodingGuidelines" title="#Coding Guidelines">Coding Guidelines\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-Testing" title="#Testing">Testing\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-ClientApplications">Client Applications</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-MavenBuildStructure" title="#Maven Build Structure">Maven Build Structure\</A></LI>
<LI><B>Development Hints</B>
<UL>
<LI><A href="#SCAJava2.xDevelopmentGuide-WebappinEclipse" title="#Webapp in Eclipse">Generating Eclipse WTP Web Projects for Webapp samples\</A></LI>
<LI><A href="#SCAJava2.xDevelopmentGuide-Ant" title="#Ant">Generating Dependencies for Ant in Samples\</A></LI>
</UL>
</LI>
</UL>
<P><BR clear="all">
</P>
</DIV></DIV>
<H3><A name="SCAJava2.xDevelopmentGuide-OSGiOverviewandApproach"></A>OSGi Overview and Approach</H3>
<P><A href="http://people.apache.org/~lresende/presentations/felix%20goes%20to%20tuscany.pdf" rel="nofollow">OSGI & Tuscany</A></P>
<H3><A name="SCAJava2.xDevelopmentGuide-GeneralGuide"></A><A name="SCAJava2.xDevelopmentGuide-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="SCAJava2.xDevelopmentGuide-Prerequisites"></A><A name="SCAJava2.xDevelopmentGuide-Prerequisites"></A> Prerequisites</H3>
<P>Java SCA requires the following:</P>
<UL>
<LI><A href="http://java.sun.com/j2se/1.5.0" rel="nofollow">JDK 5.0+ (J2SE 1.5.0+)</A></LI>
<LI><A href="http://maven.apache.org/" rel="nofollow">Apache Maven (2.0.9+)</A></LI>
<LI><A href="http://subversion.tigris.org/" rel="nofollow">Subversion (1.5+)</A> or <A href="http://tortoisesvn.tigris.org/" rel="nofollow">TortoiseSVN (1.5.x+)</A></LI>
<LI><A href="http://www.eclipse.org/downloads" rel="nofollow">Eclipse PDE (Ganymede ) </A></LI>
</UL>
<H4><A name="SCAJava2.xDevelopmentGuide-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/java/sca</SPAN>
</PRE>
</DIV></DIV>
<H3><A name="SCAJava2.xDevelopmentGuide-SettingupyourDevelopmentEnvironment"></A><A name="SCAJava2.xDevelopmentGuide-Setup"></A> Setting up your Development Environment</H3>
<H4><A name="SCAJava2.xDevelopmentGuide-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/java/sca</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">
mvn -Psetup clean install
mvn -fae clean install
cd distribution
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="http://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="http://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 "-U" parameter in the mvn command.</P>
<P><IMG class="emoticon" src="http://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 "-o" parameter in the mvn command.</P>
<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><P> 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>
<P> Windows : SET MAVEN_OPTS=-Xmx512m<BR>
Unix : export MAVEN_OPTS=-Xmx512m</P></TD></TR></TABLE></DIV>
<H3><A name="SCAJava2.xDevelopmentGuide-ImportingSCAmodulesintoyourDevelopmentIDE"></A><A name="SCAJava2.xDevelopmentGuide-IDE"></A>Importing SCA modules into your Development IDE</H3>
<H4><A name="SCAJava2.xDevelopmentGuide-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 -fae -Peclipse eclipse:eclipse
</PRE>
</DIV></DIV>
<P>Now, launch your Eclipse IDE, select File->Import->Existing projects into Workplace, and then import the project from SCA Modules into your Eclipse Workspace.</P>
<P>Now, launch your Eclipse IDE, select File->Import->Existing projects into Workplace, and then import the "PDE Target" project (from distribution/pdetarget) into your Eclipse Workspace.</P>
<UL>
<LI>Import distribution/pdetarget</LI>
<LI>Inside eclipse, open tuscany-distribution-pdetarget project
<UL>
<LI>open target/tuscany-distribution-pdetarget.target</LI>
<LI>click "Set as target platform" on the upper-right side of the overview window that opened</LI>
</UL>
</LI>
</UL>
<P>There are some Tuscany Eclipse code templates available:<BR>
<A href="https://svn.apache.org/repos/asf/tuscany/java/etc/tuscany-eclipse-codestyle.xml" rel="nofollow">Eclipse Style Formatter </A><BR>
<A href="https://svn.apache.org/repos/asf/tuscany/java/etc/tuscany-eclipse-codetemplates.xml" rel="nofollow">Eclipse Templates </A></P>
<H3><A name="SCAJava2.xDevelopmentGuide-CodingGuidelines"></A><A name="SCAJava2.xDevelopmentGuide-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/" 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 "fixed such and such problem".</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/" rel="nofollow">https://svn.apache.org/repos/asf/tuscany/java/etc/</A></P>
<H4><A name="SCAJava2.xDevelopmentGuide-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-<folder name></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.*</P>
<H3><A name="SCAJava2.xDevelopmentGuide-Testing"></A><A name="SCAJava2.xDevelopmentGuide-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="http://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><P>Note that we are using JUnit 4.2 code style in OSGI development stream</P></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">"COMPOSITE"</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">"Calculator.composite"</SPAN>, <SPAN class="code-keyword">new</SPAN> Contribution(<SPAN class="code-quote">"test"</SPAN>, location));
<SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"SCA Node API <SPAN class="code-object">ClassLoader</SPAN>: "</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="http://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 **/*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="SCAJava2.xDevelopmentGuide-ClientApplicationsasSCAComponents"></A><A name="SCAJava2.xDevelopmentGuide-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">"COMPOSITE"</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">"SCA API <SPAN class="code-object">ClassLoader</SPAN>: "</SPAN> + print(Reference.class.getClassLoader()));
<SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"3 + 2="</SPAN> + calculatorService.add(3, 2));
<SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"3 - 2="</SPAN> + calculatorService.subtract(3, 2));
<SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"3 * 2="</SPAN> + calculatorService.multiply(3, 2));
<SPAN class="code-object">System</SPAN>.out.println(<SPAN class="code-quote">"3 / 2="</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="SCAJava2.xDevelopmentGuide-MavenBuildStructure"></A><A name="SCAJava2.xDevelopmentGuide-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 -Peclipse eclipse:eclipse</LI>
</UL>
<H4><A name="SCAJava2.xDevelopmentGuide-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="SCAJava2.xDevelopmentGuide-DevelopmentHints"></A>Development Hints</H2>
<H3><A name="SCAJava2.xDevelopmentGuide-GeneratingEclipseWTPWebProjectsforWebappsamples"></A><A name="SCAJava2.xDevelopmentGuide-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 -Dwtpversion=1.5 option to<BR>
the usual mvn eclipse:eclipse command, like this:<BR>
mvn -Dwtpversion=1.5 -Peclipse eclipse:eclipse</P>
<P>The magic -Dwtpversion=1.5 option will add the WTP Web project nature to<BR>
all the Eclipse projects with <packaging>war</packaging> 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>
<P>h3:<A name="SCAJava2.xDevelopmentGuide-Ant"></A> Generating Dependencies for Ant in Samples</P>
<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">"%s\n"</SPAN>, $8 }' | sed -e <SPAN class="code-quote">"s/WEB-INF\/lib\<SPAN class="code-comment">///"</SPAN> | awk '{ printf <SPAN class="code-quote">"<include name=\"</SPAN>%s\<SPAN class="code-quote">"/>\n"</SPAN>, $1 }' | grep -v tuscany</SPAN>
</PRE>
</DIV></DIV></TD></TR></TBODY></TABLE>
</DIV>
</DIV>
</DIV>
</TD>
</TR>
</TABLE>
<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript">
_uacct = "UA-1174707-5";
urchinTracker();
</SCRIPT>
<A href="http://www.statcounter.com/" target="_blank"><IMG src="http://c26.statcounter.com/counter.php?sc_project=2619156&java=0&security=94bd7e7d&invisible=0" alt="website stats" border="0"></A>
<DIV class="footer">
Copyright © 2003-2008, The Apache Software Foundation
</DIV>
</BODY>
</HTML>
|