Commit 8b2bdb37 authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Remove resources from compilation round.

parent 8a854c38
......@@ -24,7 +24,6 @@
package org.objectweb.fractal.juliac;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -50,19 +49,6 @@ public class CompilationRound {
inputFiles.addAll(sfs);
}
/**
* Add a resource file. Resource files are copied to the class directory
* when the {@link #compile(CompileSupportItf)} method is executed.
*
* @param sf the source file containing the resource
* @since 2.6
*/
public void addResource( SourceFile sf ) {
resourceFiles.add(sf);
Logger logger = jconf.getLogger();
logger.info(sf.getFullName());
}
/**
* Add a generated file.
*
......@@ -125,26 +111,7 @@ public class CompilationRound {
}
}
/**
* Copy resources to the class directory.
*
* @since 2.6
*/
public void copyResources() throws IOException {
File classDir = jconf.getClassDir();
for (SourceFile sf : resourceFiles) {
String fileName = sf.getFullName();
File file = new File(classDir,fileName);
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file);
byte[] content = sf.getContent();
fos.write(content);
fos.close();
}
}
public List<SourceFile> getInputFiles() { return inputFiles; }
public List<SourceFile> getResourceFiles() { return resourceFiles; }
public List<SourceFile> getGeneratedFiles() { return generatedFiles; }
public List<String> getOutputFileNames() { return outputFiles; }
public File getClassDir() throws IOException {
......@@ -161,9 +128,6 @@ public class CompilationRound {
/** The source files which are given as input to Juliac. */
private List<SourceFile> inputFiles = new ArrayList<>();
/** The resource files. */
private List<SourceFile> resourceFiles = new ArrayList<>();
/** The source files which are generated by Juliac. */
private List<SourceFile> generatedFiles = new ArrayList<>();
......
......@@ -528,22 +528,6 @@ public class Juliac {
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
/*
* Copy resources to the class directory.
*/
logger.info("Copying resources...");
List<SourceFile> resourceFiles = round.getResourceFiles();
if( resourceFiles.size() > 0 ) {
round.copyResources();
for (SourceFile sf : resourceFiles) {
logger.fine(" "+sf.getFullName());
}
final String msg =
resourceFiles.size()+" file(s) copied to "+
round.getClassDir().getAbsolutePath();
logger.info(msg);
}
/*
* Compile input and generated source files.
*/
......@@ -613,9 +597,6 @@ public class Juliac {
CompilationRounds rounds = jconf.getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
// Copy resource files to the class directory
round.copyResources();
// Compile input and generated source files
CompileSupportItf compiler = lookupUnique(CompileSupportItf.class);
round.compile(compiler);
......@@ -689,26 +670,6 @@ public class Juliac {
fis.close();
total++;
}
// Iterate on each resource file contained in the round
List<SourceFile> sfs = round.getResourceFiles();
for (SourceFile sf : sfs) {
String fileName = sf.getFullName();
byte[] content = sf.getContent();
// Create a new entry in the jar file
JarEntry je = new JarEntry(fileName);
je.setSize(content.length);
jos.putNextEntry(je);
// Dump the content of the resource file in the jar file
jos.write(content);
// Close the entry in the jar file
jos.closeEntry();
total++;
}
}
// Close the jar file
......
......@@ -294,23 +294,19 @@ public class JuliacConfig {
* @param sf the resource file
* @source 2.6
*/
public void addResource( SourceFile sf ) throws IOException {
public void addResource( String filename, StringBuffer sb )
throws IOException {
String fileName = sf.getFullName();
byte[] content = sf.getContent();
// Copy the resource to the directory for generated code
File genDir = getGenDir();
File file = new File(genDir,fileName);
// Copy the resource to the class directory
File genDir = getClassDir();
File file = new File(genDir,filename);
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file);
byte[] content = sb.toString().getBytes();
fos.write(content);
fos.close();
// Add the resource to the current compilation round
CompilationRounds rounds = getCompilationRounds();
CompilationRound round = rounds.getCurrentCompilationRound();
round.addResource(sf);
logger.info(filename+" copied to "+file.getAbsolutePath());
}
public String[] getSrclibs() {
......
......@@ -45,8 +45,6 @@ import org.objectweb.fractal.fraclet.types.Constants;
import org.objectweb.fractal.fraclet.types.Step;
import org.objectweb.fractal.julia.type.BasicInterfaceType;
import org.objectweb.fractal.juliac.Juliac;
import org.objectweb.fractal.juliac.SourceFile;
import org.objectweb.fractal.juliac.SourceFileString;
import org.objectweb.fractal.juliac.api.generator.SourceCodeGeneratorItf;
import org.objectweb.fractal.juliac.commons.lang.ClassHelper;
import org.objectweb.fractal.juliac.commons.lang.reflect.MethodHelper;
......@@ -336,8 +334,8 @@ public class FracletGenerator {
*
* TODO do not compile if no file has been generated
*/
SourceFile sf = new SourceFileString(adl,sb.toString(),"fractal");
jc.getJuliacConfig().addResource(sf);
String filename = adl.replace('.','/')+".fractal";
jc.getJuliacConfig().addResource(filename,sb);
jc.build();
/*
......
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