Commit 9afc0e8b authored by dfournier's avatar dfournier
Browse files

* Fix generate factory class checking and loading issue

* Added support for text properties
* Update helloworld-composite
* Add helloworld-property example
parent 2c969077
......@@ -15,6 +15,11 @@
<name>Assembly Factory Examples : HelloWorld Composite</name>
<dependencies>
<dependency>
<groupId>org.scorware.assembly.example</groupId>
<artifactId>helloworld</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.scorware.assembly</groupId>
<artifactId>factory</artifactId>
......@@ -45,51 +50,35 @@
</dependencies>
<build>
<plugins>
<plugins>
<plugin>
<groupId>org.scorware.assembly</groupId>
<artifactId>generate-factory</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>generate-factory</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<srcs>src/main/java src/main/resources</srcs>
<mixins>org.scorware.tinfi:mixins:${tinfi.version}:sources org.objectweb.fractal.julia:julia-mixins:${julia-mixins.version}:sources</mixins>
<composite>helloworldAssembly</composite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.objectweb.fractal.fractaladl.juliac.plugin</groupId>
<artifactId>maven-juliac-plugin</artifactId>
<version>${juliac.version}</version>
<executions>
<execution>
<id>juliac-compile</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- ================================================= -->
<!-- Choose one of the following for SCA components -->
<!-- with a control membrane: -->
<!-- - FCOOCtrlSourceCodeGenerator: object-oriented -->
<!-- - FCCompCtrlSourceCodeGenerator: component-based -->
<!-- ================================================= -->
<srcs>src/main/java</srcs>
<opt>org.scorware.tinfi.juliac.FCOOCtrlSourceCodeGenerator</opt>
<mixins>org.scorware.tinfi:mixins:${tinfi.version}:sources org.objectweb.fractal.julia:julia-mixins:${julia-mixins.version}:sources</mixins>
<!-- opt>org.scorware.tinfi.juliac.FCCompCtrlSourceCodeGenerator</opt -->
<!-- mixins>org.scorware.tinfi:mixins:${project.version}:sources org.objectweb.fractal.julia:julia-mixins:${julia.version}:sources org.objectweb.fractal.julia:koch-mixins:${julia.version}:sources</mixins -->
<types>example.hw.HelloWorldAssembly</types>
<sysargs>julia.config=tinfi.cfg</sysargs>
<!-- verbose>true</verbose -->
</configuration>
<dependencies>
<dependency>
<groupId>org.scorware.tinfi</groupId>
<artifactId>mixins</artifactId>
<version>${tinfi.version}</version>
<classifier>sources</classifier>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</build>
<properties>
<main>example.hw.Client</main>
<main>example.hw.ClientComposite</main>
</properties>
</project>
......@@ -27,7 +27,7 @@ import org.objectweb.fractal.api.Component;
import org.scorware.assembly.AssemblyFactory;
import org.scorware.tinfi.TinfiDomain;
public class Client {
public class ClientComposite {
public static void main(String args []) {
Component scaDomain;
......
package example.hw;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
public class ClientImpl implements Runnable {
public ClientImpl() {
System.err.println("CLIENT created");
}
@Init
public void init() {
System.err.println("CLIENT initialized");
}
public void run() {
s.print("hello world");
}
@Reference
public Service s;
}
\ No newline at end of file
package example.hw;
import org.osoa.sca.annotations.Property;
public class ServerImpl implements Service {
private String header = "->";
private int count = 1;
public ServerImpl() {
System.err.println("SERVER created");
}
public void print(final String msg) {
new Exception() {
private static final long serialVersionUID = 2182742162070453637L;
public String toString() {
return "Server: print method called";
}
}.printStackTrace();
System.err.println("Server: begin printing...");
for (int i = 0 ; i < (count) ; ++i) {
System.err.println(((header) + msg));
}
System.err.println("Server: print done.");
}
public String getHeader() {
return header;
}
@Property
public void setHeader(final String header) {
this.header = header;
}
public int getCount() {
return count;
}
@Property
public void setCount(final int count) {
this.count = count;
}
}
\ No newline at end of file
package example.hw;
public interface Service {
void print(String msg);
}
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.scorware.assembly.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>org.scorware.assembly.example</groupId>
<artifactId>helloworld-property</artifactId>
<packaging>jar</packaging>
<name>Assembly Factory Examples : HelloWorld with Property</name>
<!-- ========================================================= -->
<!-- Dependencies for generating and compiling the application -->
<!-- ========================================================= -->
<dependencies>
<dependency><!-- Needed in all cases -->
<groupId>org.scorware.tinfi</groupId>
<artifactId>compiler</artifactId>
<version>${tinfi.version}</version>
</dependency>
<dependency><!-- Needed in all cases -->
<groupId>org.objectweb.fractal.fractaladl.juliac</groupId>
<artifactId>runtime</artifactId>
<version>${juliac.version}</version>
</dependency>
<dependency><!-- Artifact specified in the <mixins> tag -->
<groupId>org.scorware.tinfi</groupId>
<artifactId>mixins</artifactId>
<version>${tinfi.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency><!-- Artifact specified in the <mixins> tag -->
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-mixins</artifactId>
<version>${julia-mixins.version}</version>
<classifier>sources</classifier>
</dependency>
<!-- <dependency> Used for generating property classes from xsd -->
<!-- <groupId>javax.xml.bind</groupId>-->
<!-- <artifactId>jaxb-api</artifactId>-->
<!-- <version>2.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.scorware.assembly</groupId>
<artifactId>factory</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.scorware.assembly.example</groupId>
<artifactId>helloworld</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<!-- <build>-->
<!---->
<!-- <plugins>-->
<!---->
<!-- <plugin>-->
<!-- <groupId>com.sun.tools.xjc.maven2</groupId>-->
<!-- <artifactId>maven-jaxb-plugin</artifactId>-->
<!-- <version>1.1</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>generate</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- <configuration>-->
<!-- <generatePackage>example.hw</generatePackage>-->
<!-- <includeSchemas>-->
<!-- <includeSchema>**/*.xsd</includeSchema>-->
<!-- </includeSchemas>-->
<!-- <extension>true</extension>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!---->
<!-- </plugins>-->
<!---->
<!-- </build>-->
<properties>
<main>example.hw.Client</main>
</properties>
<!-- <repositories>-->
<!-- <repository>-->
<!-- <id>maven2-repository.dev.java.net</id>-->
<!-- <name>Java.net Maven 2 Repository</name>-->
<!-- <url>http://download.java.net/maven/2</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>maven-repository.dev.java.net</id>-->
<!-- <name>Java.net Maven 1 Repository (legacy)</name>-->
<!-- <url>http://download.java.net/maven/1</url>-->
<!-- <layout>legacy</layout>-->
<!-- </repository>-->
<!-- </repositories>-->
<!-- <pluginRepositories>-->
<!-- <pluginRepository>-->
<!-- <id>maven2-repository.dev.java.net</id>-->
<!-- <name>Java.net Maven 2 Repository</name>-->
<!-- <url>http://download.java.net/maven/2</url>-->
<!-- </pluginRepository>-->
<!-- <pluginRepository>-->
<!-- <id>maven-repository.dev.java.net</id>-->
<!-- <name>Java.net Maven 1 Repository (legacy)</name>-->
<!-- <url>http://download.java.net/maven/1</url>-->
<!-- <layout>legacy</layout>-->
<!-- </pluginRepository>-->
<!-- </pluginRepositories>-->
</project>
############################################################
# Default Logging Configuration File
#
# You can use a different file by specifying a filename
# with the java.util.logging.config.file system property.
# For example java -Djava.util.logging.config.file=myfile
############################################################
############################################################
# Global properties
############################################################
# "handlers" specifies a comma separated list of log Handler
# classes. These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# By default we only configure a ConsoleHandler, which will only
# show messages at the INFO and above levels.
handlers= java.util.logging.ConsoleHandler
# To also add the FileHandler, use the following line instead.
#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers. For any given facility this global level
# can be overriden by a facility specific level
# Note that the ConsoleHandler also has a separate level
# setting to limit messages printed to the console.
.level = OFF
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
# Limit the message that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = OFF
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
# For example, set the com.xyz.foo logger to only log SEVERE
# messages: com.xyz.foo.level = SEVERE
spoonlet.level = OFF
spoonlet.fractal.level = OFF
spoonlet.fractaladl.level = OFF
<?xml version="1.0" encoding="UTF-8"?>
<!-- Assembly Factory Examples : HelloWorld -->
<!-- Copyright (C) 2008 INRIA, USTL -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: Damien.Fournier@inria.fr -->
<!-- -->
<!-- Author: Damien Fournier -->
<composite xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://helloworld" xmlns:hw="http://helloworld"
xmlns:data="http://example/hw"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="helloworld">
<service name="r" promote="client/r">
<interface.java interface="java.lang.Runnable" />
<binding.sca />
</service>
<component name="client">
<service name="r">
<interface.java interface="java.lang.Runnable" />
<binding.sca />
</service>
<reference name="s" target="server/s">
<interface.java interface="example.hw.Service" />
<binding.sca />
</reference>
<implementation.java class="example.hw.ClientImpl" />
</component>
<component name="server">
<service name="s">
<interface.java interface="example.hw.Service" />
<binding.sca />
</service>
<property name="header">
Message :
</property>
<implementation.java class="example.hw.ServerImpl" />
</component>
</composite>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:data="http://example/hw"
targetNamespace="http://example/hw"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="1.0"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc">
<annotation>
<appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</appinfo>
</annotation>
<element name="Message" type="data:MessageType" />
<complexType name="MessageType">
<sequence>
<element name="pre" type="string"/>
<element name="post" type="string"/>
</sequence>
</complexType>
</schema>
......@@ -40,7 +40,6 @@ public class ScaPropertyImpl implements ScaProperty {
SCAPropertyController pc = (SCAPropertyController) component
.getFcInterface("sca-property-controller");
System.out.println("controller found");
QName propertyObject = (property.getElement() != null) ? property
.getElement() : property.getType();
......
......@@ -62,336 +62,352 @@ import org.apache.maven.project.MavenProject;
*/
public class GenerateFactoryMojo extends AbstractMojo {
private static final String FACTORY_GENERATE = "org.scorware.assembly.AssemblyFactoryGenerate";
private static final String CODE_GENERATOR = "org.scorware.tinfi.juliac.FCOOCtrlSourceCodeGenerator";
private static final String JULIA_CONFIG = "tinfi.cfg";
/**
* path to the main composite
*
* @parameter
*/
private String composite;
/**
* Space-separated list of source roots.
*
* @parameter
*/
private String srcs;
/**
* The source artifacts which contains the mixin layers.
*
* @parameter
*/
private String mixins;
/**
* The directory containing the generated source code.
*
* @parameter
*/
private String gensrc;
/**
* Directory containing the result of the compilation of the generated source
* code.
*
* @parameter
*/
private String genclass;
/**
* Directory containing the packaged version of the generated code.
*
* @parameter
*/
private String genjar;
/**
* The Maven project reference.
*
* @parameter expression="${project}"
* @required
*/
private MavenProject project;
public Component getGenerateFactory() throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
IllegalLifeCycleException, NoSuchInterfaceException,
java.lang.InstantiationException, InstantiationException {
Class<?> cl = Class.forName(FACTORY_GENERATE);
Object o = cl.newInstance();
Factory factory = (Factory) o;
Component c = factory.newFcInstance();
Fractal.getLifeCycleController(c).startFc();
return c;
}
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException, MojoFailureException {
// Set fractal.provider
if(System.getProperty("fractal.provider") == null)
System.setProperty("fractal.provider",
"org.objectweb.fractal.adl.juliac.runtime.Juliac");
// Set Logger OFF
Logger logger = Logger.getLogger("assembly-factory");
logger.setLevel(Level.OFF);
Component generateFactory = null;
try {
generateFactory = this.getGenerateFactory();
} catch (Exception e1) {
e1.printStackTrace();
}
File baseDir = project.getBasedir();
String s;
/*
* Set julia.config to tinfi
*/
System.setProperty("julia.config", JULIA_CONFIG);
/*
* Source root. <srcs>
*/
s = srcs;
String[] src = s == null ? new String[0] : s.split(" ");
/*
* Directory containing the generated source code. <gensrc>
*/
String genDirName = gensrc;
if (genDirName == null) {
genDirName = "target/generated-sources/main/java";
}