Add nested tag "externalannotations" to tags "withKotlin" and "kotlinc"

This commit is contained in:
Erokhin Stanislav
2013-10-25 19:10:07 +04:00
parent 35bc3cd587
commit 694eed595b
3 changed files with 54 additions and 12 deletions
@@ -43,6 +43,7 @@ public class BytecodeCompilerTask extends Task {
private File jar;
private File stdlib;
private Path src;
private Path externalAnnotations;
private File module;
private Path compileClasspath;
private boolean includeRuntime = true;
@@ -70,6 +71,17 @@ public class BytecodeCompilerTask extends Task {
return src.createPath();
}
public void setExternalAnnotations(Path externalAnnotations) {
this.externalAnnotations = externalAnnotations;
}
public Path createExternalAnnotations() {
if (externalAnnotations == null) {
externalAnnotations = new Path(getProject());
}
return externalAnnotations.createPath();
}
public void setModule(File module) {
this.module = module;
}
@@ -123,6 +135,7 @@ public class BytecodeCompilerTask extends Task {
BytecodeCompiler compiler = new BytecodeCompiler();
String stdlibPath = (this.stdlib != null ? getPath(this.stdlib) : null);
String[] classpath = (this.compileClasspath != null ? this.compileClasspath.list() : null);
String[] externalAnnotationsPath = (this.externalAnnotations != null) ? this.externalAnnotations.list() : null;
if (this.src != null) {
@@ -136,10 +149,10 @@ public class BytecodeCompilerTask extends Task {
log(String.format("Compiling [%s] => [%s]", Arrays.toString(source), destination));
if (this.output != null) {
compiler.sourcesToDir(source, destination, stdlibPath, classpath);
compiler.sourcesToDir(source, destination, stdlibPath, classpath, externalAnnotationsPath);
}
else {
compiler.sourcesToJar(source, destination, this.includeRuntime, stdlibPath, classpath);
compiler.sourcesToJar(source, destination, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath);
}
}
else if (this.module != null) {
@@ -154,7 +167,7 @@ public class BytecodeCompilerTask extends Task {
log(jarPath != null ? String.format("Compiling [%s] => [%s]", modulePath, jarPath) :
String.format("Compiling [%s]", modulePath));
compiler.moduleToJar(modulePath, jarPath, this.includeRuntime, stdlibPath, classpath);
compiler.moduleToJar(modulePath, jarPath, this.includeRuntime, stdlibPath, classpath, externalAnnotationsPath);
}
else {
throw new CompileEnvironmentException("\"src\" or \"module\" should be specified");
@@ -20,8 +20,22 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
import org.apache.tools.ant.taskdefs.compilers.Javac13;
import org.apache.tools.ant.types.Path;
public class KotlinCompilerAdapter extends DefaultCompilerAdapter {
private Path externalAnnotations;
public void setExternalAnnotations(Path externalAnnotations) {
this.externalAnnotations = externalAnnotations;
}
public Path createExternalAnnotations() {
if (externalAnnotations == null) {
externalAnnotations = new Path(getProject());
}
return externalAnnotations.createPath();
}
@Override
public boolean execute() throws BuildException {
Javac javac = getJavac();
@@ -30,6 +44,7 @@ public class KotlinCompilerAdapter extends DefaultCompilerAdapter {
kotlinTask.setOutput(javac.getDestdir());
kotlinTask.setClasspath(javac.getClasspath());
kotlinTask.setSrc(javac.getSrcdir());
kotlinTask.setExternalAnnotations(externalAnnotations);
kotlinTask.execute();
@@ -63,13 +63,16 @@ public class BytecodeCompiler {
* @param sourceRoots
* @return compile environment instance
*/
private JetCoreEnvironment env(String stdlib, String[] classpath, String[] sourceRoots) {
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, sourceRoots);
private JetCoreEnvironment env(String stdlib, String[] classpath, String[] externalAnnotationsPath, String[] sourceRoots) {
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourceRoots);
return JetCoreEnvironment.createForProduction(Disposer.newDisposable(), configuration);
}
private CompilerConfiguration createConfiguration(String stdlib, String[] classpath, String[] sourceRoots) {
private CompilerConfiguration createConfiguration(@Nullable String stdlib,
@Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath,
@NotNull String[] sourceRoots) {
KotlinPaths paths = getKotlinPathsForAntTask();
CompilerConfiguration configuration = new CompilerConfiguration();
configuration.add(CLASSPATH_KEY, PathUtil.findRtJar());
@@ -87,6 +90,11 @@ public class BytecodeCompiler {
configuration.add(CLASSPATH_KEY, new File(path));
}
}
if ((externalAnnotationsPath != null) && (externalAnnotationsPath.length > 0)) {
for (String path : externalAnnotationsPath) {
configuration.add(ANNOTATIONS_PATH_KEY, new File(path));
}
}
File jdkAnnotationsPath = paths.getJdkAnnotationsPath();
if (jdkAnnotationsPath.exists()) {
configuration.add(ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
@@ -141,9 +149,13 @@ public class BytecodeCompiler {
* @param stdlib "kotlin-runtime.jar" path
* @param classpath compilation classpath, can be <code>null</code> or empty
*/
public void sourcesToDir(@NotNull String[] src, @NotNull String output, @Nullable String stdlib, @Nullable String[] classpath) {
public void sourcesToDir(@NotNull String[] src,
@NotNull String output,
@Nullable String stdlib,
@Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath) {
try {
JetCoreEnvironment environment = env(stdlib, classpath, src);
JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src);
boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, null, new File(output), true);
if (!success) {
@@ -169,9 +181,10 @@ public class BytecodeCompiler {
@NotNull String jar,
boolean includeRuntime,
@Nullable String stdlib,
@Nullable String[] classpath) {
@Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath) {
try {
JetCoreEnvironment environment = env(stdlib, classpath, src);
JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src);
boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment, new File(jar), null, includeRuntime);
if (!success) {
@@ -197,7 +210,8 @@ public class BytecodeCompiler {
@NotNull String jar,
boolean includeRuntime,
@Nullable String stdlib,
@Nullable String[] classpath) {
@Nullable String[] classpath,
@Nullable String[] externalAnnotationsPath) {
try {
ModuleChunk modules = CompileEnvironmentUtil.loadModuleDescriptions(getKotlinPathsForAntTask(), module,
MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);
@@ -205,7 +219,7 @@ public class BytecodeCompiler {
for (Module m : modules.getModules()) {
sourcesRoots.addAll(m.getSourceFiles());
}
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, sourcesRoots.toArray(new String[0]));
CompilerConfiguration configuration = createConfiguration(stdlib, classpath, externalAnnotationsPath, sourcesRoots.toArray(new String[0]));
File directory = new File(module).getParentFile();
boolean success = KotlinToJVMBytecodeCompiler.compileModules(configuration, modules, directory, new File(jar), includeRuntime);
if (!success) {