Rechercher dans ce blog

lundi 30 avril 2012

10. Yocto-standalone module

As explained before, the common module has been implemented but we need now to specify how to use the YoctoTemplate in order to read the JSON API provided by Yoctopuce. For this module, JSON will be parsed using Jackson library.

Maven

The first step is to add Jackson dependency in the maven configuration. Add in the module configuration file:

 
35           <dependency> 
36               <groupId>org.codehaus.jackson</groupId> 
37               <artifactId>jackson-mapper-asl</artifactId> 
38               <version>1.8.5</version> 
39           </dependency>

URLConnectionReader

In order to simplify the template. A class URLConnectionReader has been created which provides only one function:


24   interface URLConnectionReader { 
25       String getContent(URL url) throws IOException; 
26   }
The function receives an URL and returns the content as a string

URLConnectionReaderImpl

The implementation of the interface is the following:
28   public class URLConnectionReaderImpl implements URLConnectionReader { 
29    
30       public String getContent(URL url) throws IOException { 
31           StringBuilder buffer = new StringBuilder(); 
32           URLConnection yc = url.openConnection(); 
33    
34           BufferedReader in = new BufferedReader(new InputStreamReader( 
35                   yc.getInputStream(), Charset.defaultCharset())); 
36           String inputLine; 
37           while ((inputLine = in.readLine()) != null) 
38               buffer.append(inputLine); 
39           in.close(); 
40           return buffer.toString(); 
41       } 
42    
43   }
Now, that we have this class ready, it becomes easy to implement the YoctoTemplate

StandaloneYoctoTemplate

For simplicity's sake, I will only show the main functions:

Synchronous query

 
46    
47       public YoctoMap query(String relativePath) { 
48           ObjectMapper mapper = new ObjectMapper(); 
49           try { 
50               URL newUrl = new URL(url, relativePath); 
51               String content = reader.getContent(newUrl); 
52               if (content == null) throw new IllegalStateException("Content is empty"); 
53               return new StandaloneYoctoMap((Map<String, Object>) mapper.readValue(content, Map.class)); 
54           } catch (IOException e) { 
55               throw new RuntimeException(e); 
56           } 
57       }

Basically, the function:

  1. calls the reader
  2. receives a string
  3. parses the string using Jackson's ObjectMapper.
  4. Returns the result in a YoctoMap object
The result will then be analyzed by the YoctoObjectImpl...

Asynchronous query

The asynchronous query will use a thread to call the reader in background, here is the implementation of the function:


 
54    
55       public void aSyncQuery(String relativePath, YoctoCallback<YoctoMap> listener) { 
56           Thread thread = new Thread(new BackgroundQuerier(relativePath, listener)); 
57           thread.start(); 
58       } 
59    
60       private class BackgroundQuerier implements Runnable { 
61    
62           private YoctoCallback<YoctoMap> listener; 
63           private String relativePath; 
64    
65           public BackgroundQuerier(String relativePath, YoctoCallback<YoctoMap> listener) { 
66               this.relativePath = relativePath; 
67               this.listener = listener; 
68           } 
69    
70           public void run() { 
71               YoctoMap result; 
72               try { 
73                   result = query(relativePath); 
74               } catch (Throwable t) { 
75                   listener.onError(t); 
76                   return; 
77               } 
78               listener.onSuccess(result); 
79           } 
80       }

dimanche 29 avril 2012

9. Unit-test and EasyMock

Now that the first functions have been implemented. It is key to verify they are working properly.

In this post, I will describe one unit test and explain how to use EasyMock to make sure that the functions are called the appropriate number of times and that the arguments are the one which are expected.

Maven

Let's start to include EasyMock and Junit in the maven configuration. In the project pom.xml, we have to add the following lines:
  
37       <dependencies> 
38           <dependency> 
39               <groupId>junit</groupId> 
40               <artifactId>junit</artifactId> 
41               <version>4.8.2</version> 
42           </dependency> 
43           <dependency> 
44               <groupId>org.easymock</groupId> 
45               <artifactId>easymock</artifactId> 
46               <version>2.0</version> 
47           </dependency> 
48       </dependencies>

Now that it is done, we can use junit and easy mock in our modules.

Unit test sample

Here is a simple example showing how to verify that the YoctoHub object successfully refresh its content.
 
39    
40       private YoctoTemplate yoctoTemplate; 
41    
42       @Before 
43       public void setUp() throws IOException { 
44           yoctoTemplate = EasyMock.createMock(YoctoTemplate.class); 
45    
46    
47           YoctoMap content = RestYoctoMock.getMap(RestYoctoMock.MAIN_JSON); 
48           EasyMock.expect(yoctoTemplate.query("/api.json")).andReturn( 
49                   content).once(); 
50    
51           content = RestYoctoMock.getMap(RestYoctoMock.COLOR_JSON); 
52           EasyMock.expect(yoctoTemplate.query("/bySerial/YRGBLED1-01934/api.json")).andReturn( 
53                   content).anyTimes(); 
54    
55    
56       } 
57    
58    
59       @Test 
60       public void testRefresh() throws Exception { 
61    
62           EasyMock.replay(yoctoTemplate); 
63           YoctoHub hub = new YoctoHub(yoctoTemplate); 
64           hub.refresh(); 
65           hub.findAll(); 
66    
67           Collection<YoctoObject> list = hub.findAll(YoctoProduct.YOCTO_METEO); 
68           for (YoctoObject object : list) 
69               System.out.println(object); 
70    
71           EasyMock.verify(yoctoTemplate); 
72       }

First, let me describe the overall structure of the junit tests:

  • At line 42, @Before means that this function must be called before each test to make sure tho initialize the objects. There is usually a misconception that it is called only once.
  • At line 59, @Test informs the junit framework that this function must be tested. Please note that we can add parameters to the function like expectation of exception.


In this example, we introduce a few items:
  • At line 44, we initialize a mock object: that means it is an object that will share the same API but that will return the results we expect
  • At line 48: we declare that the function query with parameter "/api.json" will be called exactly once and that the return of this function will be a constant.
  • At line 62, we inform the mock object that it must be ready to be called
  • At line 71, we verify that all the objects have been called the expected number of times
What are the advantages of EasyMock against a built-in mockup object. Well, they are numerous:
  • Only the expected function are mocked up, you do not end up with thousands of empty functions that are not needed for the test
  • You can specify the exact number of times a function will be called
  • You can reuse the mockup at many place and only need to called replay to reset the object.
  • The errors are pretty well described and it is easy to understand the issue. 
As we have already configured jenkins, we should already be able to see the results of the tests in an automated way:


8. Yocto-common module

The purpose of Yocto-common is to manage all the objects that can contain a VirtualHUB but will not contain the communication layer (that will be managed in the yocto-standalone module).

UML diagram

The diagram is quite straightforward:



  • All the objects that can be accessed through an URL are YoctoObject. They have all a common interface to:
    • get the name
    • get the ProductID
    • get the serial number
    • get the parent hub
    • refresh the object in an immediate or asynchronous way
  • The YoctoHub object has to provide all the devices associated
  • The YoctoMeteo and YoctoColor need a function to return their values

YoctoObjectImpl

YoctoObjectImpl is an abstract class used by all the yocto-devices, most of the functions are getters and setters except the refresh functions. 

69       public void refresh() { 
70           YoctoMap map = template.query(relativePath); 
71           internalRefresh(map); 
72       } 
73    
74       private void internalRefresh(YoctoMap map) { 
75           YoctoMap module = map.getMap("module"); 
76           logicalName = module.getString("logicalName"); 
77           String newSerialNumber = module.getString("serialNumber"); 
78           if (serialNumber == null || serialNumber.equals("")) 
79               serialNumber = newSerialNumber; 
80           else if (!serialNumber.equals(newSerialNumber)) 
81               throw new IllegalStateException("Internal error"); 
82    
83           refreshObject(map); 
84       } 
85    
86       protected abstract void refreshObject(YoctoMap map);


  1. The refresh function basically calls a template with a relative path which depends on the object:
    • the hub will always have a relative path: /api.json
    • other yoctopuce devices will have the more complex path: /by-serial/<serial>/api.json
  2. The template returns an object of type YoctoMap that provides API to access json parsed objects.
  3. When this is done, ObjImpl will fill the parameters common to all the objects and delegate to children the rest of the operation.
Now that the synchronous refresh has been described, let's try to describe the asynchronous version:
 
56       public void refresh(final YoctoCallback<Void> callback) { 
57           template.aSyncQuery(relativePath, new YoctoCallback<YoctoMap>() { 
58               public void onSuccess(YoctoMap result) { 
59                   internalRefresh(result); 
60                   callback.onSuccess(null); 
61               } 
62    
63               public void onError(Throwable t) { 
64                   callback.onError(t); 
65               } 
66           }); 
67       }

For the asynchronous refresh, the aSyncQuery from the template is called and a callback will be called when the result has been fetched. When fetched, the first thing to do it to refresh the object and then to call the callback function provided to the function.

YoctoTemplate

The YoctoTemplate is an interface that is implemented in other modules but here is the source code of this interface:

public interface YoctoTemplate { 
24       public YoctoMap query(String relativePath); 
25    
26       public void aSyncQuery(String relativePath, YoctoCallback<YoctoMap> listener); 
27    
28   }

Difficult to be simpler!

YoctoMap

We have seen that the YoctoMap is the object returned by the YoctoTemplate, but what is it? It is a interface that helps us to access the JSON result in a xPath approach:


public interface YoctoMap { 
22    
23       public YoctoMap getMap(String name); 
24    
25       public String getString(String name); 
26    
27       public int getInt(String name); 
28    
29       public YoctoList getList(String name); 
30   }

For example, to access an object, the code: map.getMap("module").getString("logicalName") will allow getting the logicalName of a device.

There is nothing particularly complex in this module, the code consists mainly of implementing the different devices provided by yoctopuce.

7. Yoctopuce

Now, we can start the analysis part of Yoctopuce devices. These devices are low cost devices that you plug on your USB port.  For the purpose of this demo, I bought this device: https://www.yoctopuce.com/EN/products/yocto-meteo

If you have a native interface, you can directly use a library but in my case, I do not. So, I will use a tool called VirtualHub which provides a simple REST interface.

When the yocto-meteo is plugged and VirtualHub is running. You should be able to go on http://127.0.0.1:4444 and see this page:





This means that the devices and VirtualHub are working properly. We can see there are two devices:


  • VirtualHub: the device to which the different functions are plugged. In this case only yocto-meteo but we could envision there are more.
  • Yocto-meteo: the device itself. In this screenshot, we could click on the it and get the temperature, humidity and pressure.
Anyway, we do not care about this UI. We are analyzing how to access it from a java source code, so let's use the JSON url which is: http://127.0.0.1:4444/api.json. The result you should get is something like this:


{
"module":{"productName":"VirtualHub","serialNumber":"VIRTHUB0-480741bdd3","logicalName":"","productId":0,"productRelease":1,"firmwareRelease":"6019","persistentSettings":0,"luminosity":50,"beacon":0,"upTime":4245111515,"usbCurrent":0,"realmHTTP":"YoctoDevices","adminPassword":"","userPassword":"","rebootCountdown":0,"usbBandwidth":0},
"services":{
"whitePages":[
{"serialNumber":"VIRTHUB0-480741bdd3","logicalName":"","productName":"VirtualHub","productId":0,"networkUrl":"/api","beacon":0,"index":0},
{"serialNumber":"METEOMK1-0268C","logicalName":"","productName":"Yocto-Meteo","productId":24,"networkUrl":"/bySerial/METEOMK1-0268C/api","beacon":0,"index":1}],
"yellowPages":{
"DataLogger":[
{"hardwareId":"METEOMK1-0268C.dataLogger","logicalName":"","advertisedValue":"OFF","index":0}],
"Temperature":[
{"hardwareId":"METEOMK1-0268C.temperature","logicalName":"","advertisedValue":"23.4","index":1}],
"Pressure":[
{"hardwareId":"METEOMK1-0268C.pressure","logicalName":"","advertisedValue":"958.0","index":2}],
"Humidity":[
{"hardwareId":"METEOMK1-0268C.humidity","logicalName":"","advertisedValue":"44.0","index":3}]}}}

There are a few interesting sections which are useful:


  • services.whitePages: contains the description of all the modules
  • service.yellowPages: contains the relevant values for the different modules
I decided to use the whitePages to get the information even if it is slightly more complex...

So, let's look on an whitePage entry:

{"serialNumber":"METEOMK1-0268C","logicalName":"","productName":"YoctoMeteo","productId":24,"networkUrl":"/bySerial/METEOMK1-0268C/api","beacon":0,"index":1}]

We can see already a lot of information:


  • The serial number which is unique to each yoctopuce device
  • The productId corresponding to the device. ProductName provides the same human-readable value
  • networkUrl: corresponds to the URL where to access the particular device values.
Let's take a deeper look on the network url and try to append the current URL + networkURL (http://127.0.0.1:4444/bySerial/METEOMK1-0268C/api): we get this page:


This provides us all the information about the selected device, in this case the yocto-meteo. As before, we do not care about the fancy widgets but only about the data: so let's append .json to the URL:



{
"module":{"productName":"Yocto-Meteo","serialNumber":"METEOMK1-0268C","logicalName":"","productId":24,"productRelease":1,"firmwareRelease":"5991","persistentSettings":2,"luminosity":50,"beacon":0,"upTime":231437,"usbCurrent":27,"realmHTTP":"YoctoDevices","adminPassword":"","userPassword":"","rebootCountdown":0,"usbBandwidth":0},
"humidity":{"logicalName":"","advertisedValue":"38.0","currentValue":2490368,"lowestValue":2490368,"highestValue":3145728},
"pressure":{"logicalName":"","advertisedValue":"959.0","currentValue":62783488,"lowestValue":62717952,"highestValue":62849024},
"temperature":{"logicalName":"","advertisedValue":"25.6","currentValue":1675264,"lowestValue":1458176,"highestValue":1675264},
"dataLogger":{"logicalName":"","advertisedValue":"OFF","oldestRunIndex":0,"currentRunIndex":1,"samplingInterval":1,"timeUTC":0,"recording":0,"autoStart":0,"clearHistory":0}}

And we get here, the temperature, pressure, humidity, etc. Now that we have everything, we can start the development and write a JAVA API.

samedi 28 avril 2012

6. Code coverage

Maven post was not containing the full configuration. For simplicity sake, I deliberately removed the code coverage section.

Now that jenkins and maven are configured, we can now take some time to configure the code coverage. For this part, I use Cobertura because it runs under Jenkins and it is easy to use...

To configure it, there are two things to do:


  1. Configure the Maven configuration 
  2. Configure Jenkins to support Cobertura

Configure Maven

To configure maven, we have to edit the project pom.xml to set that cobertura must be run. We will run cobertura during the package goal:

 
49    
50    
51       <profiles> 
52           <!-- Jenkins by default defines a property BUILD_NUMBER which is used to enable the profile. --> 
53           <profile> 
54               <id>jenkins</id> 
55               <activation> 
56                   <property> 
57                       <name>env.BUILD_NUMBER</name> 
58                   </property> 
59               </activation> 
60               <build> 
61                   <pluginManagement> 
62                       <plugins> 
63                           <plugin> 
64                               <groupId>org.codehaus.mojo</groupId> 
65                               <artifactId>cobertura-maven-plugin</artifactId> 
66                               <version>2.5.1</version> 
67                               <configuration> 
68                                   <formats> 
69                                       <format>xml</format> 
70                                   </formats> 
71                               </configuration> 
72                               <executions> 
73                                   <execution> 
74                                       <phase>package</phase> 
75                                       <goals> 
76                                           <goal>cobertura</goal> 
77                                       </goals> 
78                                   </execution> 
79                               </executions> 
80    
81                           </plugin> 
82                       </plugins> 
83                   </pluginManagement> 
84    
85                   <plugins> 
86                       <plugin> 
87                           <groupId>org.codehaus.mojo</groupId> 
88                           <artifactId>findbugs-maven-plugin</artifactId> 
89                           <version>2.4.0</version> 
90                           <executions> 
91                               <execution> 
92                                   <phase>package</phase> 
93                                   <goals> 
94                                       <goal>findbugs</goal> 
95                                   </goals> 
96                               </execution> 
97                           </executions> 
98                       </plugin> 
99                   </plugins> 
100              </build> 
101          </profile> 
102      </profiles>

A few explanations are needed:

  • We set here a profile: that means this goal is run only when a particular "user" is running the target. It is good in this case because cobertura will not be run in developer's environment but only by jenkins
  • The plugin is specified to run during the package phase

Configure Jenkins

Now that maven is configured, we can configure Jenkins to use cobertura and this is quite easy:

  1. Install the Cobertura plugin: Jenkins Cobertura plugin. It will be installed with a couple of dependencies.
  2. Go in the project settings and set that you want to run the following goals:
    • package: to run cobertura
    • cobertura:cobertura: to build the result
  3. Go in the project settings and set that you want to display the coverage report. You are asked for a report pattern: set: **/target/site/cobertura/coverage.xml. This will inform cobertura where the pattern are stored and that they are in xml (exactly what we set in the pom.xml.
Now you can run a build and you will see the code coverage of the project.

lundi 23 avril 2012

5. Jenkins (2/2)

Jenkins is now installed and configured. We will now configure it to work with Github and build the yocto-meteo project.

You should be able to access Jenkins through the previous URL on port 8080. For my case it is: http://192.158.1.59:8080


  1. Go in the plugins tab and select github plugin.
  2. Select install and restart jenkins afterward
Jenkins is now up and running but not configured yet. 

  1. Go in the configuration tab
  2. Jenkins virtual appliance is shipped with Sun java 1.6. Let's set it in the JDK section:
    • Select a name for the jdk
    • Unset the "Install automatically" flag
    • Set the JAVA_HOME path with /usr/lib/jvm/java
  3. Maven is available by default but set it to install it automatically in the Maven section
  4. In GitHub plugin:
    1. Set "Let Jenkins auto-manage hook URLs"
    2. Set your credentials to github
  5. Select Save. 
Now, we have a jenkins virtual appliance fully functional but we still need to configure the project... We will now create a build and junit job


  1. Select "New Job". 
  2. Set the name "yocto-meteo" and set the radio button: "Maven project". You should then see a big page where you can configure the job
  3. Select Git as the source code repository
  4. Enter the Git URL: https://github.com/jfontignie/yocto-meteo
  5. Select "Build when a change is pushed to GitHub. The build will be automatically performed every time submit something. It is very useful if you send an email when an issue is found. 
  6. Select "Build periodically" and enter "0 3 * * *". It will perform a build every night at 3 AM.
  7. Select "Check the versioning tool" and enter: "*/5 * * * *" in order to check for new changes every 5 minutes

Congratulations, you have now a build environment and a source code repository. We can now really start the project.



4. Jenkins (1/2)

Now, that we have the source code repository. I would like to put in place a continuous integration environment. An environment that I like and which is pretty easy to use is Jenkins. It provides automatic build verification, junit tests, etc.

In this post, I will explain:


  1. How to install Jenkins
  2. How to configure Jenkins
  3. How to use Jenkins

If you already know how it works, forget this post and read the next one!

Jenkins installation

Normally, we should install a new OS, configure the OS, install the Jenkins dependencies, configure the Jenkins dependencies and so on, and so on... It would take ages to do it and it is absolutely not interesting. In order to go faster, we will install a virtual appliance and configure only the minimal...

A virtual appliance is a virtual machine (VM) already configured that we can boot in an hypervisor (in my case VMWare workstation). The first boot will configure a few things on the VM and we can use it afterward.

Download the Jenkins virtual appliance

The Jenkins virtual appliance can be downloaded here: http://susestudio.com/a/u1OC8F/jenkins. There are a few login steps to perform but eventually you should get the VM. In my case, it was called: Jenkins-i686-0.0.5.vmx.tar.gz.

  1. Download the virtual appliance
  2. Decompress the file, you should get a folder containing two files:
    • vmx: is the configuration of the VM.
    • vmdk: the VM's virtual disk
  3. Let's copy the folder in the VMWare "Virtual Machines" folder

Start Jenkins virtual appliance

Now that we have downloaded, decompressed and moved the folder at the correct location, let's start the virtual appliance for the first time...

  1. Start VMWare workstation
  2. Go in File->Open
  3. Select the vmx file in the folder
  4. Normally, you should have a new VM in your VMs list.
  5. Let's start the virtual appliance.

Configure the virtual appliance

The first boot is very important in virtual appliances as it will configure the virtual machine and if things go wrong, it may be pretty complex to reset some settings. 

  1. The first time you start, you should be asked to upgrade the virtual machine: Select "Upgrade". Usually, you do not have to bother about this option as it may be useful only if you plan to downgrade to an older VMWare version which is rarely the case.
  2. When starting, you should get the following screen:
  3. If you did not press any key, the configuration should start. If it does not, press <enter>
  4. After a couple of seconds, you should get the Timezone configuration panel. Select your timezone and select "Next". Please note that the mouse should not work and you will have to play with the tab button to select the proper timezone...
  5. After a couple of more seconds, you should get the following screen. Congratulations, your VM is up and running.
Now that the virtual appliance is running, you should be able to configure the virtual machine using your browser which will be easier...


  1. On the VM, you should see a green line. Go  on this URL with your browser... The username is "root" and password "ch@ngeme"
  2. You should get an error message related to Java, do not bother about it for the moment... Configure the password, the users, etc.
  3. Now, let's go to the "Software Repositories" panel and disable webyast and java. It seems that there was a bug in webyast and upgrading it was causing it to crash.... 
  4. It will take a very long time...
  5. After a while, everything should be installed, reboot the VM now.
This concludes the install of the Jenkins virtual appliance. In next post, we will see how to configure Jenkins.

3. Maven

"Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information."
http://maven.apache.org/

The purpose of maven in this project will be to create builds, unit tests and be able to manage through a few XML scripts. In this project, we will have three configuration file:

  • yocto-api: managing the different modules and the whole build
  • yocto-common: will provide all the objects to manage yoctopuce devices. It does not contain the communication piece (as we will create one module as standalone jar and the other as a GWT module).
  • yocto-standalone: will contain the communication layer in case we run in standard JRE.

Yocto-api

The first step is to create the root configuration. This configuration will contain the description of the project and the different modules and dependencies which are needed.
To create a project, the command mvn archetype:generate and we have to specify a few items: groupId,artifactId,version, etc. But for simplicity, I decided that Intellij Idea would create it for me. So I create a new project with Intellij Idea and selected that I wanted a Maven project. And that's all! My project was created,I started to make a first few changes and I obtained such pom.xml file:

1    <?xml version="1.0" encoding="UTF-8"?> 
2     
3    <project xmlns="http://maven.apache.org/POM/4.0.0" 
4             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
5             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
6             http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
7        <modelVersion>4.0.0</modelVersion> 
8     
9        <properties> 
10           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
11       </properties> 
12    
13       <groupId>yocto-api</groupId> 
14       <artifactId>yocto-api</artifactId> 
15       <packaging>pom</packaging> 
16       <version>1.0</version> 
17       <modules> 
18           <module>yocto-standalone</module> 
19           <module>yocto-common</module> 
20       </modules> 
21    
22       <dependencies> 
23           <dependency> 
24               <groupId>junit</groupId> 
25               <artifactId>junit</artifactId> 
26               <version>4.8.2</version> 
27           </dependency> 
28           <dependency> 
29               <groupId>org.easymock</groupId> 
30               <artifactId>easymock</artifactId> 
31               <version>2.0</version> 
32           </dependency> 
33       </dependencies>
Let me describe a bit some items here:
  • The project has been called: yocto-api:yocto-api. The name is silly but I am not very imaginative. The version is 1.0.
  • The project has two modules: yocto-standalone and yocto-common. I will explain them later. But
  • I have added a few dependencies to the project: these are libraries that are used by the source code. Junit and easyMock are used for unit tests. This will be described in a future post. The good point is that only setting this is needed to use them. the Jars will be downloaded automatically by maven on http://repo.maven.apache.org/. You can get the list here as well: http://mvnrepository.com/
Now, let's describe one module: yocto-standalone. Yocto-common is straightforward...

Yocto-standalone

As explained before, yocto-standalone will only provide the communication layer to communicate with the yoctopuce devices.

1    <?xml version="1.0" encoding="UTF-8"?> 
2    <project xmlns="http://maven.apache.org/POM/4.0.0" 
3             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
4             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
5        <parent> 
6            <artifactId>yocto-api</artifactId> 
7            <groupId>yocto-api</groupId> 
8            <version>1.0</version> 
9        </parent> 
10       <modelVersion>4.0.0</modelVersion> 
11    
12       <artifactId>yocto-standalone</artifactId> 
13    
14       <dependencies> 
15           <dependency> 
16               <groupId>yocto-api</groupId> 
17               <artifactId>yocto-common</artifactId> 
18               <version>1.0</version> 
19           </dependency> 
20           <dependency> 
21               <groupId>org.codehaus.jackson</groupId> 
22               <artifactId>jackson-mapper-asl</artifactId> 
23               <version>1.8.5</version> 
24           </dependency> 
25    
26       </dependencies>

We can see that the code is very similar to the main pom.xml file except the dependencies because this module requires:
  • yocto-common as yocto-common contains all the classes needed for the standalone version
  • jackson to manage the json objects returned by the yoctopuce devices.
This is only what needed to be done. we can now run a few goals using the maven command: compile,clean,test,etc.

2. Github

The first thing we will put in place is the code repository. This is pretty easy and straightforward. The Source versioning tool we will use is GitHub.

To put the environment in place, we need git command-line and SSH, I did not have anything to do as it is included in macport...


  1. Create an account for  Git. I created a free account as the code is planned to be GPL, I did not bother about the licensing.
  2. I created a repository which is pretty straightforward. Please note that Github provides very useful information on how to put the environment in place.
  3. I generated an SSH key, and put the public key in Github. So that I can log to git without having to put the credentials.
  4. In Intellij idea, I set the VCS to Github and entered all the parameters to log on GitHub.


I can now access my code repository on: https://github.com/jfontignie/yocto-meteo. And that's all, the environment is ready for development.

jeudi 12 avril 2012

1. Introduction

When I look for projects, I usually found some code samples on a particular technology but it is quite rare to find:
  • How to install the test framework
  • How to put the project in production
  • How to use the VCS
The goal of this blog is to introduce a small project and explain the different steps of development. I will not go in details and will only provide a small overview of the project.

Overview

The goal of the project is to provide a map where you can see all the yoctopuce devices from the people who have come on the page. Yoctopuce provide a meteo sensor device that can be plugged through USB. In this project, we would like to have the following flow:


  1. An user goes on the web page with his browser
  2. The web page is loaded and tries to contact known yoctopuce device URL: http://127.0.0.1:4444
  3. If it is successful
    1. The Web page analyzes which yoctopuce devices are plugged
    2. The Web page stores the data in the database with the current location
  4. The webpage loads and displays the world map with all the yoctopuce devices stored in the database




In this blog, I will describe:
  1. Prepare GIT to store the source code
  2. Configure the maven project
  3. Configure and install a virtual appliance with Jenkins
  4. Run a code coverage with Cobertura in Jenkins
  5. Use yoctopuce devices
  6. Basic introduction of java API for yoctopuce
  7. GWT introduction
  8. Put in production with google app engine