Commit 33a1c757 authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Remove no longer supported feature.

parent 902db41f
Test whether the packaging of code in jar files works.
Feature introduced in Juliac 2.2.4.
<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.ow2.fractal.juliac.examples</groupId>
<artifactId>foobar-cases</artifactId>
<version>2.7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>generate-in-jar</artifactId>
<packaging>jar</packaging>
<name>Juliac Example Generate in a Jar File</name>
<dependencies>
<!-- ============================= -->
<!-- Dependency for generated code -->
<!-- ============================= -->
<dependency>
<groupId>org.ow2.fractal.juliac</groupId>
<artifactId>juliac-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.fractal.juliac</groupId>
<artifactId>juliac-oo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.fractal.juliac</groupId>
<artifactId>juliac-julia-membranes-oo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.fractal.juliac</groupId>
<artifactId>juliac-jcapi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- ============================================================ -->
<!-- Main program for launching the tests. -->
<!-- Workaround for class loading issue with the surefire plugin. -->
<!-- ============================================================ -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>example.hw.HelloWorldTestCase</mainClass>
<systemProperties>
<property>
<key>basedir</key>
<value>${basedir}</value>
</property>
</systemProperties>
</configuration>
<executions>
<execution>
<id>run-all-tests</id>
<phase>test</phase>
<goals><goal>java</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/***
* Juliac
* Copyright (C) 2009-2017 Inria, Univ. Lille 1
*
* 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: fractal@ow2.org
*
* Author: Lionel Seinturier
*/
package example.hw;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.julia.type.BasicComponentType;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
import org.objectweb.fractal.juliac.CompilationRound;
import org.objectweb.fractal.juliac.CompilationRounds;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.SourceFile;
import org.objectweb.fractal.juliac.SourceFileString;
import org.objectweb.fractal.juliac.commons.io.Console;
import org.objectweb.fractal.juliac.compile.jcapi.CompileSupportImpl;
import org.objectweb.fractal.juliac.conf.JuliacConfig;
import org.objectweb.fractal.juliac.module.JuliacModuleItf;
import org.objectweb.fractal.juliac.opt.oo.FCOOCtrlSourceCodeGenerator;
import org.objectweb.fractal.juliac.runtime.JuliacBootstrapComponentImpl;
import org.objectweb.fractal.util.Fractal;
/**
* Generate some code in jar files and load the packed class to check that the
* packaging works.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 2.2.4
*/
public class HelloWorldTestCase {
public static void main( String[] args )
throws
IOException, InstantiationException, IllegalLifeCycleException,
NoSuchInterfaceException {
HelloWorldTestCase hwtc = new HelloWorldTestCase();
hwtc.setUp();
hwtc.testHelloWorld();
hwtc.tearDown();
}
private Juliac jc;
@Before
public void setUp() throws IOException {
jc = new Juliac();
JuliacConfig jconf = new JuliacConfig();
jc.setJuliacConfig(jconf);
String prop = System.getProperty("basedir");
File baseDir = prop == null ? new File(".") : new File(prop);
jconf.setBaseDir(baseDir);
JuliacModuleItf jdt = new CompileSupportImpl();
JuliacModuleItf fcscg = new FCOOCtrlSourceCodeGenerator();
jdt.init(jc);
fcscg.init(jc);
}
@After
public void tearDown() throws IOException {
jc.close();
}
@Test
public void testHelloWorld()
throws
IOException, InstantiationException,
IllegalLifeCycleException, NoSuchInterfaceException {
// Create a new source file
String qname = "example.hw.HelloWorldImpl";
SourceFile sf = new SourceFileString(qname,content,"java");
List<SourceFile> sfs = new ArrayList<SourceFile>();
sfs.add(sf);
// Add the source file in the input files
JuliacConfig jconf = jc.getJuliacConfig();
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
round.addInput(sfs);
// Compile, generate and package the code
jc.buildQuiet();
InterfaceType it =
new BasicInterfaceType(
"r",Runnable.class.getName(),false,false,false);
Type type = new BasicComponentType(new InterfaceType[]{it});
Object controllerDesc = "primitive";
jc.generate(type,controllerDesc,qname,null);
jc.buildQuiet();
jc.packGeneratedFiles();
// Create a class loader with the generated jar file
File jarFile = jconf.getClassJarFile();
URL url = jarFile.toURI().toURL();
ClassLoader parent = getClass().getClassLoader();
URLClassLoader ucl = new URLClassLoader(new URL[]{url},parent);
// Instantiate the component
JuliacBootstrapComponentImpl boot = new JuliacBootstrapComponentImpl();
Object desc = new Object[]{ucl,controllerDesc};
Component comp = boot.newFcInstance(type,desc,qname);
// Direct the output of the example to a temporary file
Console console = Console.getConsole(CONSOLE_ID);
// Invoke the run() operation on the component
Fractal.getLifeCycleController(comp).startFc();
Runnable r = (Runnable) comp.getFcInterface("r");
r.run();
Fractal.getLifeCycleController(comp).stopFc();
// Compare the result with the expected result
console.close();
console.dump(System.err);
console.assertEquals(expecteds);
}
final private static String CONSOLE_ID = "generate-in-jar-";
final private static String content =
"package example.hw;\n"+
"public class HelloWorldImpl implements java.lang.Runnable {"+
" public void run() {"+
" "+Console.class.getName()+" console = "+Console.class.getName()+".getConsole(\""+CONSOLE_ID+"\");"+
" console.println(\"Hello World!\");"+
" }"+
"}";
final static private String[] expecteds = new String[]{"Hello World!"};
}
......@@ -20,7 +20,6 @@
<!-- are system dependent. See absolutepath/pom.xml -->
<!-- <module>absolutepath</module> -->
<module>generate-in-jar</module>
<module>generate-proxies</module>
<module>proxyparameters</module>
</modules>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment