OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | August 2008 Index

<--  Date Index  --> <--  Thread Index  -->

[fractal-commits] [8422] trunk/juliac: Example to test Juliac with absolute paths.


Title: [8422] trunk/juliac: Example to test Juliac with absolute paths.
Revision
8422
Author
seintur
Date
2008-08-30 21:58:58 +0200 (Sat, 30 Aug 2008)

Log Message

Example to test Juliac with absolute paths.

Modified Paths

Added Paths

Diff

Modified: trunk/juliac/TODO.txt (8421 => 8422)


--- trunk/juliac/TODO.txt	2008-08-29 16:39:18 UTC (rev 8421)
+++ trunk/juliac/TODO.txt	2008-08-30 19:58:58 UTC (rev 8422)
@@ -15,10 +15,6 @@
 examples/advanced/dream/
 * provide a pre-mixed version of the membranes defined by Dream
 
-examples/advanced/foobar-cases/
-* add an absolutepath example which invokes a main() which copies sources in the
-  temp directory, retrieves absolute paths and invokes Juliac.main()
-
 opt/comp/
 * provide a membrane factory
 * interceptors on control interfaces (see OO)

Property changes: trunk/juliac/examples/advanced/foobar-cases/absolutepath


Name: svn:ignore
   + target
.classpath
.project

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/README.txt (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/README.txt	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/README.txt	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,2 @@
+Test whether Juliac works correctly when invoked with absolute paths. This
+feature has been introduced in Juliac 2.1.
\ No newline at end of file

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/pom.xml (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/pom.xml	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/pom.xml	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,57 @@
+<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.objectweb.fractal.juliac</groupId>
+		<artifactId>juliac-parent</artifactId>
+		<version>2.1-SNAPSHOT</version>
+	</parent>
+
+    <groupId>org.objectweb.fractal.juliac.examples</groupId>
+    <artifactId>absolutepath</artifactId>
+    <packaging>jar</packaging>
+    <name>Absolute path example</name>
+ 
+	<dependencies>
+		<dependency>
+			<groupId>org.objectweb.fractal</groupId>
+			<artifactId>fractal-api</artifactId>
+			<version>${fractalapi.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.objectweb.fractal.julia</groupId>
+			<artifactId>julia-runtime</artifactId>
+			<version>${julia.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.objectweb.fractal.julia</groupId>
+			<artifactId>julia-mixins</artifactId>
+			<version>${julia.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.objectweb.fractal.juliac</groupId>
+			<artifactId>juliac-compiler</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.objectweb.fractal.juliac</groupId>
+			<artifactId>juliac-jdt</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.objectweb.fractal.juliac</groupId>
+			<artifactId>juliac-oo</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.4</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+
+</project>

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/java/example/absolutepath/AbsolutePathTestCase.java (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/java/example/absolutepath/AbsolutePathTestCase.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/java/example/absolutepath/AbsolutePathTestCase.java	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,153 @@
+/***
+ * Juliac
+ * 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: Lionel.Seinturier@xxxxxxxxxxxxxx
+ *
+ * Author: Lionel Seinturier
+ */
+
+package example.absolutepath;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.Test;
+import org.objectweb.fractal.api.factory.InstantiationException;
+import org.objectweb.fractal.juliac.Juliac;
+
+/**
+ * Test whether Juliac works correctly when invoked with absolute paths.
+ * 
+ * @author Lionel Seinturier <Lionel.Seinturier@xxxxxxxxxxxxxx>
+ * @since 2.1
+ */
+public class AbsolutePathTestCase {
+
+    @Test
+    public void test()
+    throws
+        IllegalArgumentException, IOException, InstantiationException,
+        java.lang.InstantiationException, IllegalAccessException,
+        ClassNotFoundException {
+        
+        /*
+         * Create a temporary directory.
+         */
+        File tmp = File.createTempFile("juliac",null);
+        File dir = tmp.getParentFile();
+        File tmpDir = new File(dir,"juliac");
+        
+        if( tmpDir.exists() ) {
+            if( tmpDir.isFile() ) {
+                tmpDir.delete();
+            }
+            else {
+                // Recursively delete the directory
+                delete(tmpDir);
+            }
+        }
+        
+        File fsrcs = new File(tmpDir,"src");
+        File fgensrc = new File(tmpDir,"gen");
+        File fgenclass = new File(tmpDir,"classes");
+        
+        fsrcs.mkdirs();
+        fgensrc.mkdirs();
+        fgenclass.mkdirs();
+        
+        /*
+         * Copy source files to the created temporary directory.
+         */
+        ClassLoader loader = getClass().getClassLoader();
+        String root = "example/absolutepath/";
+        copy(loader,root,"ClientImpl.java",fsrcs);
+        copy(loader,root,"ServerImpl.java",fsrcs);
+        copy(loader,root,"Service.java",fsrcs);
+        copy(loader,root,"ServiceAttributes.java",fsrcs);
+        
+        /*
+         * Define command line arguments for invoking Juliac.
+         */
+        String srcs = fsrcs.getAbsolutePath();
+        String gensrc = fgensrc.getAbsolutePath();
+        String genclass = fgenclass.getAbsolutePath();
+        
+        StringBuffer argline = new StringBuffer();
+        argline.append("--opt OO --compileInput --compileGenerated");
+        argline.append(" --srcs ");
+        argline.append(srcs);
+        argline.append(" --gensrc ");
+        argline.append(gensrc);
+        argline.append(" --genclass ");
+        argline.append(genclass);
+        
+        /*
+         * Invoke Juliac.
+         */
+        String[] args = argline.toString().split(" ");
+        Juliac.main(args);
+    }
+    
+    /**
+     * Recursively delete the specified directory.
+     */
+    private static void delete( File dir ) {
+        File[] files = dir.listFiles();
+        for (File file : files) {
+            if( file.isDirectory() ) {
+                delete(file);
+            }
+            file.delete();
+        }
+    }
+    
+    /**
+     * Load with the specified class loader, the resource whose root and name
+     * are specified and copy it to the specified directory.
+     * 
+     * @param loader  the class loader
+     * @param root    the root directory
+     * @param name    the resource name
+     * @param target  the directory where the resource is to be copied
+     */
+    private static void copy(
+        ClassLoader loader, String root, String name, File target )
+    throws IOException {
+        
+        String resname = root+"/"+name;
+        InputStream in = loader.getResourceAsStream(resname);
+        
+        if( in == null ) {
+            String msg = "Can not load resource: "+resname;
+            throw new IOException(msg);
+        }
+        
+        File dst = new File(target,root);
+        dst.mkdirs();
+        File file = new File(dst,name);
+        FileOutputStream fout = new FileOutputStream(file);
+        
+        int i;
+        while( (i = in.read()) != -1 ) {
+            fout.write(i);
+        }
+        fout.close();
+    }
+}

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ClientImpl.java (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ClientImpl.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ClientImpl.java	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,54 @@
+package example.absolutepath;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.objectweb.fractal.api.NoSuchInterfaceException;
+import org.objectweb.fractal.api.control.BindingController;
+import org.objectweb.fractal.api.control.IllegalBindingException;
+
+public class ClientImpl implements Runnable , BindingController {
+
+    public ClientImpl() {
+        System.err.println("CLIENT created");
+    }
+    
+    public void run() {
+        s.print("hello world");
+    }
+    
+    private Service s;
+    
+    public void bindFc(String clientItfName, Object serverItf) throws NoSuchInterfaceException, IllegalBindingException {
+        if (clientItfName.equals("s")) {
+            if (!(Service.class.isAssignableFrom(serverItf.getClass()))) {
+                throw new IllegalBindingException(((("server interfaces connected to " + clientItfName) + " must be instances of ") + (Service.class.getName())));
+            } 
+            s = ((Service)(serverItf));
+            return ;
+        } 
+        throw new NoSuchInterfaceException((("Client interface \'" + clientItfName) + "\' is undefined."));
+    }
+    
+    public String[] listFc() {
+        List<String> interfaces = new ArrayList<String>();
+        interfaces.add("s");
+        return interfaces.toArray(new String[interfaces.size()]);
+    }
+    
+    public Object lookupFc(String clientItfName) throws NoSuchInterfaceException {
+        if (clientItfName.equals("s")) {
+            return s;
+        } 
+        throw new NoSuchInterfaceException((("Client interface \'" + clientItfName) + "\' is undefined."));
+    }
+    
+    public void unbindFc(String clientItfName) throws NoSuchInterfaceException {
+        if (clientItfName.equals("s")) {
+            s = null;
+            return ;
+        } 
+        throw new NoSuchInterfaceException((("Client interface \'" + clientItfName) + "\' is undefined."));
+    }
+    
+}
\ No newline at end of file

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServerImpl.java (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServerImpl.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServerImpl.java	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,44 @@
+package example.absolutepath;
+
+
+public class ServerImpl implements Service , ServiceAttributes {
+    private String header;
+    
+    private int count;
+    
+    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;
+    }
+    
+    public void setHeader(final String header) {
+        this.header = header;
+    }
+    
+    public int getCount() {
+        return count;
+    }
+    
+    public void setCount(final int count) {
+        this.count = count;
+    }
+}
\ No newline at end of file

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/Service.java (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/Service.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/Service.java	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,6 @@
+package example.absolutepath;
+
+
+public interface Service {
+    void print(String msg);
+}
\ No newline at end of file

Added: trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServiceAttributes.java (0 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServiceAttributes.java	                        (rev 0)
+++ trunk/juliac/examples/advanced/foobar-cases/absolutepath/src/test/resources/example/absolutepath/ServiceAttributes.java	2008-08-30 19:58:58 UTC (rev 8422)
@@ -0,0 +1,10 @@
+package example.absolutepath;
+
+import org.objectweb.fractal.api.control.AttributeController;
+
+public interface ServiceAttributes extends AttributeController {
+    String getHeader();
+    void setHeader(String header);
+    int getCount();
+    void setCount(int count);
+}
\ No newline at end of file

Modified: trunk/juliac/examples/advanced/foobar-cases/pom.xml (8421 => 8422)


--- trunk/juliac/examples/advanced/foobar-cases/pom.xml	2008-08-29 16:39:18 UTC (rev 8421)
+++ trunk/juliac/examples/advanced/foobar-cases/pom.xml	2008-08-30 19:58:58 UTC (rev 8422)
@@ -14,6 +14,7 @@
     <name>Juliac advanced foobar-cases examples</name>
 
 	<modules>
+		<module>absolutepath</module>
 		<module>otherversionnumber</module>
 		<module>proxyparameters</module>
 	</modules>


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.