Added attaching external annotations via module script.
This commit is contained in:
@@ -44,6 +44,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
import org.jetbrains.jet.utils.Progress;
|
||||
|
||||
import java.io.File;
|
||||
@@ -79,6 +80,10 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
configuration.getEnvironment().addToClasspath(new File(classpathRoot));
|
||||
}
|
||||
|
||||
for (String annotationsRoot : moduleBuilder.getAnnotationsRoots()) {
|
||||
JetCoreEnvironment.addExternalAnnotationsRoot(PathUtil.jarFileOrDirectoryToVirtualFile(new File(annotationsRoot)));
|
||||
}
|
||||
|
||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||
if (generationState == null) {
|
||||
return null;
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.JdkUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SimpleJavaSdkType;
|
||||
import com.intellij.openapi.roots.AnnotationOrderRootType;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Chunk;
|
||||
@@ -220,6 +222,13 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
script.append(" classpath += \"" + path(mainOutput) + "\"\n");
|
||||
}
|
||||
|
||||
script.append(" // External annotations\n");
|
||||
for (Module module : chunk.getModules()) {
|
||||
for (VirtualFile file : OrderEnumerator.orderEntries(module).roots(AnnotationOrderRootType.getInstance()).getRoots()) {
|
||||
script.append(" annotationsPath += \"").append(path(file)).append("\"\n");
|
||||
}
|
||||
}
|
||||
|
||||
script.append(" }\n");
|
||||
script.append("}\n");
|
||||
return script;
|
||||
|
||||
@@ -21,10 +21,17 @@ class ClasspathBuilder(val parent: ModuleBuilder) {
|
||||
}
|
||||
}
|
||||
|
||||
class AnnotationsPathBuilder(val parent: ModuleBuilder) {
|
||||
public fun plusAssign(name: String) {
|
||||
parent.addAnnotationsPathEntry(name)
|
||||
}
|
||||
}
|
||||
|
||||
open class ModuleBuilder(val name: String): Module {
|
||||
// http://youtrack.jetbrains.net/issue/KT-904
|
||||
private val sourceFiles0: ArrayList<String?> = ArrayList<String?>()
|
||||
private val classpathRoots0: ArrayList<String?> = ArrayList<String?>()
|
||||
private val annotationsRoots0: ArrayList<String?> = ArrayList<String?>()
|
||||
|
||||
val sources: SourcesBuilder
|
||||
get() = SourcesBuilder(this)
|
||||
@@ -32,6 +39,9 @@ open class ModuleBuilder(val name: String): Module {
|
||||
val classpath: ClasspathBuilder
|
||||
get() = ClasspathBuilder(this)
|
||||
|
||||
val annotationsPath: AnnotationsPathBuilder
|
||||
get() = AnnotationsPathBuilder(this)
|
||||
|
||||
public fun addSourceFiles(pattern: String) {
|
||||
sourceFiles0.add(pattern)
|
||||
}
|
||||
@@ -40,8 +50,13 @@ open class ModuleBuilder(val name: String): Module {
|
||||
classpathRoots0.add(name)
|
||||
}
|
||||
|
||||
public fun addAnnotationsPathEntry(name: String) {
|
||||
annotationsRoots0.add(name)
|
||||
}
|
||||
|
||||
public override fun getSourceFiles(): List<String?>? = sourceFiles0
|
||||
public override fun getClasspathRoots(): List<String?>? = classpathRoots0
|
||||
public override fun getAnnotationsRoots(): List<String?>? = annotationsRoots0
|
||||
public override fun getModuleName(): String? = name
|
||||
}
|
||||
|
||||
|
||||
@@ -25,4 +25,5 @@ public interface Module {
|
||||
String getModuleName();
|
||||
List<String> getSourceFiles();
|
||||
List<String> getClasspathRoots();
|
||||
List<String> getAnnotationsRoots();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user