Respect -output even if compiling module script

This commit is contained in:
Maxim Shafirov
2012-02-01 21:26:31 +04:00
parent 2478582670
commit f58bbb8de6
3 changed files with 13 additions and 8 deletions
@@ -90,6 +90,6 @@ public class BytecodeCompiler {
* @param classpath compilation classpath, can be <code>null</code> or empty
*/
public void moduleToJar ( String module, String jar, boolean includeRuntime, String stdlib, String[] classpath ) {
env( stdlib, classpath ).compileModuleScript( module, jar, includeRuntime );
env( stdlib, classpath ).compileModuleScript( module, jar, null, includeRuntime );
}
}
@@ -100,7 +100,7 @@ public class KotlinCompiler {
}
if (arguments.module != null) {
environment.compileModuleScript(arguments.module, arguments.jar, arguments.includeRuntime);
environment.compileModuleScript(arguments.module, arguments.jar, arguments.outputDir, arguments.includeRuntime);
return 0;
}
else {
@@ -130,7 +130,7 @@ public class CompileEnvironment {
return null;
}
public void compileModuleScript(String moduleFile, String jarPath, boolean jarRuntime) {
public void compileModuleScript(String moduleFile, @Nullable String jarPath, @Nullable String outputDir, boolean jarRuntime) {
final List<Module> modules = loadModuleScript(moduleFile);
if (modules == null) {
@@ -144,11 +144,16 @@ public class CompileEnvironment {
final String directory = new File(moduleFile).getParent();
for (Module moduleBuilder : modules) {
ClassFileFactory moduleFactory = compileModule(moduleBuilder, directory);
final String path = jarPath != null ? jarPath : new File(directory, moduleBuilder.getModuleName() + ".jar").getPath();
try {
writeToJar(moduleFactory, new FileOutputStream(path), null, jarRuntime);
} catch (FileNotFoundException e) {
throw new CompileEnvironmentException("Invalid jar path " + path, e);
if (outputDir != null) {
writeToOutputDirectory(moduleFactory, outputDir);
}
else {
String path = jarPath != null ? jarPath : new File(directory, moduleBuilder.getModuleName() + ".jar").getPath();
try {
writeToJar(moduleFactory, new FileOutputStream(path), null, jarRuntime);
} catch (FileNotFoundException e) {
throw new CompileEnvironmentException("Invalid jar path " + path, e);
}
}
}
}