Reverting problematic commits:
fa500f453dAlex Tkachman Today 19:47725bebc23fAlex Tkachman Today 19:36
This commit is contained in:
Generated
-1
@@ -15,7 +15,6 @@
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
<entry name="?*.jet" />
|
||||
<entry name="/**/?*.kt" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="false" useClasspath="true" />
|
||||
</component>
|
||||
|
||||
@@ -3,13 +3,9 @@
|
||||
<property name="build.number" value="snapshot"/>
|
||||
<property name="output.name" value="kotlin-${build.number}"/>
|
||||
|
||||
<path id="libs">
|
||||
<path id="classpath">
|
||||
<fileset dir="${basedir}/ideaSDK" includes="*.jar"/>
|
||||
<fileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath">
|
||||
<path refid="libs"/>
|
||||
<pathelement path="${output}/classes/runtime"/>
|
||||
</path>
|
||||
|
||||
@@ -43,23 +39,14 @@
|
||||
<arg value="${basedir}/stdlib/ktSrc"/>
|
||||
<arg value="-output"/>
|
||||
<arg value="${basedir}/classes/stdlib"/>
|
||||
<arg value="-stdlib"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="compileTests" depends="compile">
|
||||
<mkdir dir="${output}/classes/tests"/>
|
||||
<javac destdir="${output}/classes/tests" debug="true" debuglevel="lines,vars,source">
|
||||
<src path="${basedir}/compiler/tests"/>
|
||||
<classpath refid="classpath.kotlin"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="jarRT" depends="compileStdlib">
|
||||
<target name="jarRT" depends="compile">
|
||||
<jar destfile="${output}/kotlin-runtime.jar">
|
||||
<fileset dir="${output}/classes/runtime"/>
|
||||
<fileset dir="${output}/classes/stdlib"/>
|
||||
<fileset dir="${basedir}/stdlib/ktSrc/" includes="**/*"/>
|
||||
<!--<fileset dir="${output}/classes/stdlib"/>-->
|
||||
<fileset dir="${basedir}" includes="stdlib/ktSrc/**/*"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
@@ -70,7 +57,6 @@
|
||||
<src refid="sourcepath"/>
|
||||
<classpath refid="classpath"/>
|
||||
</javac>
|
||||
<copy file="${basedir}/compiler/frontend/src/jet/Library.jet" tofile="${output}/classes/compiler/jet/Library.jet"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile">
|
||||
@@ -84,32 +70,6 @@
|
||||
<delete dir="${output}"/>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compileTests,jar,jarRT">
|
||||
<mkdir dir="${output}/reports"/>
|
||||
<junit printsummary="yes" haltonerror="false" haltonfailure="false">
|
||||
<classpath>
|
||||
<pathelement location="${output}/kotlin-compiler.jar"/>
|
||||
<pathelement location="${output}/kotlin-runtime.jar"/>
|
||||
<pathelement location="${output}/classes/tests"/>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
|
||||
<formatter type="brief"/>
|
||||
<formatter type="xml"/>
|
||||
|
||||
<batchtest todir="${output}/reports">
|
||||
<fileset dir="${basedir}/compiler/tests">
|
||||
<include name="**/*Test.java"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
|
||||
<junitreport>
|
||||
<fileset dir="${output}/reports" includes="TEST-*.xml"/>
|
||||
<report format="frames" todir="${output}/reports/html"/>
|
||||
</junitreport>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="clean,jarRT,jar">
|
||||
<zip destfile="${output}/${output.name}.zip">
|
||||
<zipfileset prefix="${output.name}/bin" filemode="755" dir="${basedir}/compiler/cli/bin"/>
|
||||
|
||||
+81
-67
@@ -1,16 +1,19 @@
|
||||
package org.jetbrains.jet.compiler;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
import jet.ExtensionFunction0;
|
||||
import jet.ExtensionFunction10;
|
||||
import jet.Function1;
|
||||
import jet.modules.IModuleBuilder;
|
||||
import jet.modules.IModuleSetBuilder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
@@ -19,6 +22,7 @@ import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
@@ -26,13 +30,74 @@ import java.util.List;
|
||||
import java.util.jar.*;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
* The environment for compiling a bunch of source files or
|
||||
*
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class AbstractCompileEnvironment {
|
||||
protected Project project;
|
||||
public class CompileEnvironment {
|
||||
private JetCoreEnvironment myEnvironment;
|
||||
private final Disposable myRootDisposable;
|
||||
private PrintStream myErrorStream = System.out;
|
||||
|
||||
protected abstract void addToClasspath(File file);
|
||||
public CompileEnvironment() {
|
||||
myRootDisposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
};
|
||||
myEnvironment = new JetCoreEnvironment(myRootDisposable);
|
||||
}
|
||||
|
||||
public void setErrorStream(PrintStream errorStream) {
|
||||
myErrorStream = errorStream;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
Disposer.dispose(myRootDisposable);
|
||||
}
|
||||
|
||||
public boolean initializeKotlinRuntime() {
|
||||
return initializeKotlinRuntime(myEnvironment);
|
||||
}
|
||||
|
||||
public static boolean initializeKotlinRuntime(JetCoreEnvironment environment) {
|
||||
final File unpackedRuntimePath = getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
environment.addToClasspath(unpackedRuntimePath);
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
environment.addToClasspath(runtimeJarPath);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static File getUnpackedRuntimePath() {
|
||||
URL url = CompileEnvironment.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("file")) {
|
||||
return new File(url.getPath()).getParentFile().getParentFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static File getRuntimeJarPath() {
|
||||
URL url = CompileEnvironment.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("jar")) {
|
||||
String path = url.getPath();
|
||||
return new File(path.substring(path.indexOf(":") + 1, path.indexOf("!/")));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setJavaRuntime(File rtJarPath) {
|
||||
myEnvironment.addToClasspath(rtJarPath);
|
||||
}
|
||||
|
||||
public static File findRtJar(boolean failOnError) {
|
||||
String javaHome = System.getenv("JAVA_HOME");
|
||||
File rtJar;
|
||||
@@ -99,52 +164,6 @@ public abstract class AbstractCompileEnvironment {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract VirtualFileSystem getLocalFileSystem();
|
||||
|
||||
public abstract VirtualFileSystem getJarFileSystem();
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public static File getUnpackedRuntimePath() {
|
||||
URL url = CoreCompileEnvironment.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("file")) {
|
||||
return new File(url.getPath()).getParentFile().getParentFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static File getRuntimeJarPath() {
|
||||
URL url = CoreCompileEnvironment.class.getClassLoader().getResource("jet/JetObject.class");
|
||||
if (url != null && url.getProtocol().equals("jar")) {
|
||||
String path = url.getPath();
|
||||
return new File(path.substring(path.indexOf(":") + 1, path.indexOf("!/")));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean initializeKotlinRuntime(AbstractCompileEnvironment environment) {
|
||||
final File unpackedRuntimePath = getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
environment.addToClasspath(unpackedRuntimePath);
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
environment.addToClasspath(runtimeJarPath);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setJavaRuntime(File rtJarPath) {
|
||||
addToClasspath(rtJarPath);
|
||||
}
|
||||
|
||||
public void compileModuleScript(String moduleFile, String jarPath, boolean jarRuntime) {
|
||||
final IModuleSetBuilder moduleSetBuilder = loadModuleScript(moduleFile);
|
||||
if (moduleSetBuilder == null) {
|
||||
@@ -164,11 +183,11 @@ public abstract class AbstractCompileEnvironment {
|
||||
}
|
||||
|
||||
public IModuleSetBuilder loadModuleScript(String moduleFile) {
|
||||
CompileSession scriptCompileSession = new CompileSession(this);
|
||||
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
||||
scriptCompileSession.addSources(moduleFile);
|
||||
scriptCompileSession.addStdLibSources();
|
||||
|
||||
if (!scriptCompileSession.analyze(System.out)) {
|
||||
if (!scriptCompileSession.analyze(myErrorStream)) {
|
||||
return null;
|
||||
}
|
||||
final ClassFileFactory factory = scriptCompileSession.generate();
|
||||
@@ -204,22 +223,22 @@ public abstract class AbstractCompileEnvironment {
|
||||
}
|
||||
|
||||
public ClassFileFactory compileModule(IModuleBuilder moduleBuilder, String directory) {
|
||||
CompileSession moduleCompileSession = new CompileSession(this);
|
||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||
moduleCompileSession.addStdLibSources();
|
||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||
moduleCompileSession.addSources(new File(directory, sourceFile).getPath());
|
||||
}
|
||||
for (String classpathRoot : moduleBuilder.getClasspathRoots()) {
|
||||
addToClasspath(new File(classpathRoot));
|
||||
myEnvironment.addToClasspath(new File(classpathRoot));
|
||||
}
|
||||
if (!moduleCompileSession.analyze(System.out)) {
|
||||
if (!moduleCompileSession.analyze(myErrorStream)) {
|
||||
return null;
|
||||
}
|
||||
return moduleCompileSession.generate();
|
||||
}
|
||||
|
||||
private static String getHomeDirectory() {
|
||||
return new File(PathManager.getResourceRoot(CoreCompileEnvironment.class, "/org/jetbrains/jet/compiler/CoreCompileEnvironment.class")).getParentFile().getParentFile().getParent();
|
||||
return new File(PathManager.getResourceRoot(CompileEnvironment.class, "/org/jetbrains/jet/compiler/CompileEnvironment.class")).getParentFile().getParentFile().getParent();
|
||||
}
|
||||
|
||||
private static final List<String> sanitized = Arrays.asList("kotlin/", "std/");
|
||||
@@ -312,11 +331,10 @@ public abstract class AbstractCompileEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime, boolean stdlib) {
|
||||
CompileSession session = new CompileSession(this);
|
||||
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
session.addSources(sourceFileOrDir);
|
||||
if(!stdlib)
|
||||
session.addStdLibSources();
|
||||
session.addStdLibSources();
|
||||
|
||||
String mainClass = null;
|
||||
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
||||
@@ -325,7 +343,7 @@ public abstract class AbstractCompileEnvironment {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!session.analyze(System.out)) {
|
||||
if (!session.analyze(myErrorStream)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -358,8 +376,4 @@ public abstract class AbstractCompileEnvironment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean initializeKotlinRuntime() {
|
||||
return initializeKotlinRuntime(this);
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,11 @@ import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.CompilationErrorHandler;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -19,7 +18,6 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,13 +26,13 @@ import java.util.List;
|
||||
* @author yole
|
||||
*/
|
||||
public class CompileSession {
|
||||
private final JetCoreEnvironment myEnvironment;
|
||||
private final List<JetNamespace> mySourceFileNamespaces = new ArrayList<JetNamespace>();
|
||||
private final List<JetNamespace> myLibrarySourceFileNamespaces = new ArrayList<JetNamespace>();
|
||||
private List<String> myErrors = new ArrayList<String>();
|
||||
private BindingContext myBindingContext;
|
||||
private AbstractCompileEnvironment myEnvironment;
|
||||
|
||||
public CompileSession(AbstractCompileEnvironment environment) {
|
||||
public CompileSession(JetCoreEnvironment environment) {
|
||||
myEnvironment = environment;
|
||||
}
|
||||
|
||||
@@ -52,32 +50,28 @@ public class CompileSession {
|
||||
return;
|
||||
}
|
||||
|
||||
addSources(new File(path), mySourceFileNamespaces);
|
||||
addSources(new File(path));
|
||||
}
|
||||
|
||||
private void addSources(File file, List<JetNamespace> namespaces) {
|
||||
private void addSources(File file) {
|
||||
if(file.isDirectory()) {
|
||||
for (File child : file.listFiles()) {
|
||||
addSources(child, namespaces);
|
||||
addSources(child);
|
||||
}
|
||||
}
|
||||
else {
|
||||
VirtualFile fileByPath = myEnvironment.getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
||||
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(fileByPath);
|
||||
if(psiFile instanceof JetFile) {
|
||||
namespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
mySourceFileNamespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addSources(VirtualFile vFile) {
|
||||
addSources(vFile, mySourceFileNamespaces);
|
||||
}
|
||||
|
||||
public void addSources(VirtualFile vFile, List<JetNamespace> namespaces) {
|
||||
if (vFile.isDirectory()) {
|
||||
for (VirtualFile virtualFile : vFile.getChildren()) {
|
||||
addSources(virtualFile, namespaces);
|
||||
addSources(virtualFile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -90,28 +84,10 @@ public class CompileSession {
|
||||
}
|
||||
}
|
||||
|
||||
public void addSources(VirtualFile[] allFiles) {
|
||||
for(VirtualFile vFile: allFiles) {
|
||||
if (vFile.getFileType() == JetFileType.INSTANCE) {
|
||||
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(vFile);
|
||||
if (psiFile instanceof JetFile) {
|
||||
mySourceFileNamespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<JetNamespace> getSourceFileNamespaces() {
|
||||
return mySourceFileNamespaces;
|
||||
}
|
||||
|
||||
public BindingContext analyze() {
|
||||
List<JetNamespace> allNamespaces = new ArrayList<JetNamespace>(mySourceFileNamespaces);
|
||||
allNamespaces.addAll(myLibrarySourceFileNamespaces);
|
||||
return AnalyzerFacade.analyzeNamespacesWithJavaIntegration(
|
||||
myEnvironment.getProject(), allNamespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
}
|
||||
|
||||
public boolean analyze(final PrintStream out) {
|
||||
if (!myErrors.isEmpty()) {
|
||||
for (String error : myErrors) {
|
||||
@@ -119,19 +95,18 @@ public class CompileSession {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
myBindingContext = analyze();
|
||||
List<JetNamespace> allNamespaces = new ArrayList<JetNamespace>(mySourceFileNamespaces);
|
||||
allNamespaces.addAll(myLibrarySourceFileNamespaces);
|
||||
myBindingContext = AnalyzerFacade.analyzeNamespacesWithJavaIntegration(
|
||||
myEnvironment.getProject(), allNamespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
ErrorCollector errorCollector = new ErrorCollector(myBindingContext);
|
||||
errorCollector.report(out);
|
||||
return !errorCollector.hasErrors;
|
||||
}
|
||||
|
||||
public ClassFileFactory generate() {
|
||||
return generate(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
}
|
||||
|
||||
public ClassFileFactory generate(CompilationErrorHandler handler) {
|
||||
GenerationState generationState = new GenerationState(myEnvironment.getProject(), ClassBuilderFactory.BINARIES);
|
||||
generationState.compileCorrectNamespaces(myBindingContext, mySourceFileNamespaces, handler);
|
||||
generationState.compileCorrectNamespaces(myBindingContext, mySourceFileNamespaces);
|
||||
return generationState.getFactory();
|
||||
}
|
||||
|
||||
@@ -142,25 +117,16 @@ public class CompileSession {
|
||||
}
|
||||
|
||||
public boolean addStdLibSources() {
|
||||
return addStdLibSources(false);
|
||||
}
|
||||
|
||||
public boolean addStdLibSources(boolean forAnalize) {
|
||||
/*
|
||||
@todo
|
||||
We add sources as library sources in case of jar
|
||||
but as regular one if there is no jar
|
||||
*/
|
||||
final File unpackedRuntimePath = CoreCompileEnvironment.getUnpackedRuntimePath();
|
||||
final File unpackedRuntimePath = CompileEnvironment.getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
addSources(new File(unpackedRuntimePath, "stdlib/ktSrc").getAbsoluteFile(), forAnalize ? myLibrarySourceFileNamespaces : mySourceFileNamespaces);
|
||||
addSources(new File(unpackedRuntimePath, "../../../stdlib/ktSrc").getAbsoluteFile());
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = CoreCompileEnvironment.getRuntimeJarPath();
|
||||
final File runtimeJarPath = CompileEnvironment.getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
VirtualFile runtimeJar = myEnvironment.getLocalFileSystem().findFileByPath(runtimeJarPath.getAbsolutePath());
|
||||
VirtualFile jarRoot = myEnvironment.getJarFileSystem().findFileByPath(runtimeJar.getPath() + "!/stdlib/ktSrc");
|
||||
addSources(jarRoot, myLibrarySourceFileNamespaces);
|
||||
addSources(jarRoot);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
@@ -168,8 +134,4 @@ public class CompileSession {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<JetNamespace> getLibrarySourceFileNamespaces() {
|
||||
return myLibrarySourceFileNamespaces;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package org.jetbrains.jet.compiler;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import com.intellij.util.Processor;
|
||||
import jet.ExtensionFunction0;
|
||||
import jet.modules.IModuleBuilder;
|
||||
import jet.modules.IModuleSetBuilder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.jar.*;
|
||||
|
||||
/**
|
||||
* The environment for compiling a bunch of source files or
|
||||
*
|
||||
* @author yole
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class CoreCompileEnvironment extends AbstractCompileEnvironment {
|
||||
private final Disposable myRootDisposable;
|
||||
private final VirtualFileSystem localFileSystem;
|
||||
private VirtualFileSystem jarFileSystem;
|
||||
private JetCoreEnvironment myEnvironment;
|
||||
|
||||
public CoreCompileEnvironment() {
|
||||
myRootDisposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
};
|
||||
myEnvironment = new JetCoreEnvironment(myRootDisposable);
|
||||
localFileSystem = myEnvironment.getLocalFileSystem();
|
||||
jarFileSystem = myEnvironment.getJarFileSystem();
|
||||
project = myEnvironment.getProject();
|
||||
}
|
||||
|
||||
public CoreCompileEnvironment(JetCoreEnvironment myEnvironment) {
|
||||
this.myRootDisposable = null;
|
||||
this.myEnvironment = myEnvironment;
|
||||
localFileSystem = myEnvironment.getLocalFileSystem();
|
||||
jarFileSystem = myEnvironment.getJarFileSystem();
|
||||
project = myEnvironment.getProject();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if(myRootDisposable != null)
|
||||
Disposer.dispose(myRootDisposable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToClasspath(File file) {
|
||||
myEnvironment.addToClasspath(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFileSystem getLocalFileSystem() {
|
||||
return localFileSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFileSystem getJarFileSystem() {
|
||||
return jarFileSystem;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@ package org.jetbrains.jet.cli;
|
||||
|
||||
import com.sampullara.cli.Args;
|
||||
import com.sampullara.cli.Argument;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironmentException;
|
||||
|
||||
/**
|
||||
@@ -26,8 +25,6 @@ public class KotlinCompiler {
|
||||
public String module;
|
||||
@Argument(value = "includeRuntime", description = "include Kotlin runtime in to resulting jar")
|
||||
public boolean includeRuntime;
|
||||
@Argument(value = "stdlib", description = "means that we compile stdlib itself")
|
||||
public boolean stdlib;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -42,10 +39,10 @@ public class KotlinCompiler {
|
||||
return;
|
||||
}
|
||||
|
||||
CoreCompileEnvironment environment = new CoreCompileEnvironment();
|
||||
CompileEnvironment environment = new CompileEnvironment();
|
||||
|
||||
try {
|
||||
environment.setJavaRuntime(AbstractCompileEnvironment.findRtJar(true));
|
||||
environment.setJavaRuntime(CompileEnvironment.findRtJar(true));
|
||||
if (!environment.initializeKotlinRuntime()) {
|
||||
System.out.println("No runtime library found");
|
||||
return;
|
||||
@@ -56,7 +53,7 @@ public class KotlinCompiler {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime, arguments.stdlib);
|
||||
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
||||
}
|
||||
} catch (CompileEnvironmentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import kotlin.modules.*
|
||||
|
||||
val modules = module("smoke") {
|
||||
source files "src/Smoke.kt"
|
||||
testSource files "test/SmokeTest.kt"
|
||||
source files "Smoke.kt"
|
||||
jar name System.getProperty("java.io.tmpdir") + "/smoke.jar"
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import std.io
|
||||
|
||||
import junit.framework.*
|
||||
|
||||
class SmokeTest() : TestCase() {
|
||||
fun testMe() {
|
||||
println("test")
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
@@ -36,7 +36,7 @@ public class CompileJavaAgainstKotlinTest extends UsefulTestCase {
|
||||
|
||||
private final File ktFile;
|
||||
private final File javaFile;
|
||||
private CoreCompileEnvironment jetCoreEnvironment;
|
||||
private JetCoreEnvironment jetCoreEnvironment;
|
||||
private File tmpdir;
|
||||
|
||||
public CompileJavaAgainstKotlinTest(File ktFile) {
|
||||
@@ -80,7 +80,7 @@ public class CompileJavaAgainstKotlinTest extends UsefulTestCase {
|
||||
|
||||
ClassFileFactory classFileFactory = state.getFactory();
|
||||
|
||||
CoreCompileEnvironment.writeToOutputDirectory(classFileFactory, tmpdir.getPath());
|
||||
CompileEnvironment.writeToOutputDirectory(classFileFactory, tmpdir.getPath());
|
||||
|
||||
Disposer.dispose(myTestRootDisposable);
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
@@ -29,7 +28,7 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
||||
@NonNls
|
||||
protected final String myFullDataPath;
|
||||
protected JetFile myFile;
|
||||
protected CoreCompileEnvironment myEnvironment;
|
||||
protected JetCoreEnvironment myEnvironment;
|
||||
|
||||
public JetLiteFixture(@NonNls String dataPath) {
|
||||
myFullDataPath = getTestDataPath() + "/" + dataPath;
|
||||
@@ -58,8 +57,8 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void createEnvironmentWithFullJdk() {
|
||||
myEnvironment = new CoreCompileEnvironment(new JetCoreEnvironment(getTestRootDisposable()));
|
||||
final File rtJar = AbstractCompileEnvironment.findRtJar(true);
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable());
|
||||
final File rtJar = CompileEnvironment.findRtJar(true);
|
||||
myEnvironment.addToClasspath(rtJar);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.jetbrains.jet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
@@ -138,12 +137,12 @@ public class JetTestUtils {
|
||||
}
|
||||
|
||||
|
||||
public static CoreCompileEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
||||
JetCoreEnvironment environment = new JetCoreEnvironment(disposable);
|
||||
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||
environment.addToClasspath(rtJar);
|
||||
environment.addToClasspath(new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar"));
|
||||
return new CoreCompileEnvironment(environment);
|
||||
return environment;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -49,7 +49,7 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
}
|
||||
};
|
||||
|
||||
private CoreCompileEnvironment jetCoreEnvironment;
|
||||
private JetCoreEnvironment jetCoreEnvironment;
|
||||
private File tmpdir;
|
||||
|
||||
private final File testFile;
|
||||
@@ -72,7 +72,7 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
}
|
||||
|
||||
private void createMockCoreEnvironment() {
|
||||
jetCoreEnvironment = new CoreCompileEnvironment(new JetCoreEnvironment(myTestRootDisposable));
|
||||
jetCoreEnvironment = new JetCoreEnvironment(myTestRootDisposable);
|
||||
|
||||
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||
jetCoreEnvironment.addToClasspath(rtJar);
|
||||
@@ -95,7 +95,7 @@ public class ReadClassDataTest extends UsefulTestCase {
|
||||
|
||||
ClassFileFactory classFileFactory = state.getFactory();
|
||||
|
||||
CoreCompileEnvironment.writeToOutputDirectory(classFileFactory, tmpdir.getPath());
|
||||
CompileEnvironment.writeToOutputDirectory(classFileFactory, tmpdir.getPath());
|
||||
|
||||
NamespaceDescriptor namespaceFromSource = (NamespaceDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, psiFile.getRootNamespace());
|
||||
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
@@ -33,7 +46,7 @@ public class StdlibTest extends CodegenTestCase {
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
CoreCompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||
session.addSources(myFile.getVirtualFile());
|
||||
session.addStdLibSources();
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.jar.JarInputStream;
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class CompileEnvironmentTest extends TestCase {
|
||||
private CoreCompileEnvironment environment;
|
||||
private CompileEnvironment environment;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
environment = new CoreCompileEnvironment();
|
||||
environment = new CompileEnvironment();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +33,7 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testSmoke() throws IOException {
|
||||
final File activeRtJar = AbstractCompileEnvironment.findRtJar(true);
|
||||
final File activeRtJar = CompileEnvironment.findRtJar(true);
|
||||
environment.setJavaRuntime(activeRtJar);
|
||||
environment.initializeKotlinRuntime();
|
||||
final String testDataDir = JetParsingTest.getTestDataDir() + "/compiler/smoke/";
|
||||
@@ -45,7 +45,7 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
assertNotNull(factory.asBytes("Smoke/namespace.class"));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
CoreCompileEnvironment.writeToJar(factory, baos, null, false);
|
||||
CompileEnvironment.writeToJar(factory, baos, null, false);
|
||||
JarInputStream is = new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
final List<String> entries = listEntries(is);
|
||||
assertTrue(entries.contains("Smoke/namespace.class"));
|
||||
@@ -93,7 +93,7 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
tempFile = new File(tempFile.getAbsolutePath());
|
||||
tempFile.mkdir();
|
||||
try {
|
||||
KotlinCompiler.main(Arrays.asList("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/src/Smoke.kt", "-output", tempFile.getAbsolutePath()).toArray(new String[0]));
|
||||
KotlinCompiler.main(Arrays.asList("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt", "-output", tempFile.getAbsolutePath()).toArray(new String[0]));
|
||||
assertEquals(1, tempFile.listFiles().length);
|
||||
assertEquals(1, tempFile.listFiles()[0].listFiles().length);
|
||||
}
|
||||
|
||||
@@ -13,12 +13,6 @@
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
<module-components>
|
||||
<component>
|
||||
<implementation-class>org.jetbrains.jet.plugin.compiler.JetLibraryManager</implementation-class>
|
||||
</component>
|
||||
</module-components>
|
||||
|
||||
<actions>
|
||||
<action id="ShowJetExpressionType" class="org.jetbrains.jet.plugin.actions.ShowExpressionTypeAction"
|
||||
text="Show Expression Type">
|
||||
|
||||
@@ -17,7 +17,6 @@ import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.Chunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -28,7 +27,6 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.compiler.CompilerMessageCategory.ERROR;
|
||||
@@ -67,12 +65,19 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PluginCompilerEnvironment compilerEnvironment = new PluginCompilerEnvironment(compileContext.getProject());
|
||||
CompileSession compileSession = new CompileSession(compilerEnvironment);
|
||||
compileSession.addSources(compileContext.getCompileScope().getFiles(null, true));
|
||||
compileSession.addStdLibSources();
|
||||
VirtualFile[] allFiles = compileContext.getCompileScope().getFiles(null, true);
|
||||
|
||||
BindingContext bindingContext = compileSession.analyze();
|
||||
GenerationState generationState = new GenerationState(compileContext.getProject(), ClassBuilderFactory.BINARIES);
|
||||
List<JetNamespace> namespaces = Lists.newArrayList();
|
||||
for (VirtualFile virtualFile : allFiles) {
|
||||
PsiFile psiFile = PsiManager.getInstance(compileContext.getProject()).findFile(virtualFile);
|
||||
if (psiFile instanceof JetFile) {
|
||||
namespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
}
|
||||
}
|
||||
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacade.analyzeNamespacesWithJavaIntegration(compileContext.getProject(), namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
|
||||
boolean errors = false;
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
@@ -91,7 +96,7 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
|
||||
if (!errors) {
|
||||
final ClassFileFactory factory = compileSession.generate(new CompilationErrorHandler() {
|
||||
generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
|
||||
@Override
|
||||
public void reportException(Throwable exception, String fileUrl) {
|
||||
if(exception instanceof CompilationException) {
|
||||
@@ -102,7 +107,22 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
}
|
||||
});
|
||||
///////////
|
||||
// GenerationState generationState2 = new GenerationState(compileContext.getProject(), ClassBuilderFactory.TEXT);
|
||||
// generationState2.compileCorrectNamespaces(bindingContext, namespaces);
|
||||
// StringBuilder answer = new StringBuilder();
|
||||
//
|
||||
// final ClassFileFactory factory2 = generationState2.getFactory();
|
||||
// List<String> files2 = factory2.files();
|
||||
// for (String file : files2) {
|
||||
// answer.append("@").append(file).append('\n');
|
||||
// answer.append(factory2.asText(file));
|
||||
// }
|
||||
// System.out.println(answer.toString());
|
||||
///////////
|
||||
|
||||
|
||||
final ClassFileFactory factory = generationState.getFactory();
|
||||
List<String> files = factory.files();
|
||||
for (String file : files) {
|
||||
File target = new File(outputDir.getPath(), file);
|
||||
@@ -115,6 +135,23 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Map<Module, ModuleCompileState> moduleMap = new HashMap<Module, ModuleCompileState>();
|
||||
//
|
||||
// for (VirtualFile virtualFile : virtualFiles) {
|
||||
// Module module = compileContext.getModuleByFile(virtualFile);
|
||||
// ModuleCompileState state = moduleMap.get(module);
|
||||
// if (state == null) {
|
||||
// state = new ModuleCompileState(compileContext, module, outputSink);
|
||||
// moduleMap.put(module, state);
|
||||
// }
|
||||
// state.compile(virtualFile);
|
||||
// }
|
||||
//
|
||||
// for (ModuleCompileState state : moduleMap.values()) {
|
||||
// state.done();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void report(Diagnostic diagnostic, CompilerMessageCategory severity, CompileContext compileContext) {
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package org.jetbrains.jet.plugin.compiler;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleComponent;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.ModuleLibraryTable;
|
||||
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class JetLibraryManager implements ModuleComponent {
|
||||
public static final String KOTLIN_STD_LIB = "KotlinStdLib";
|
||||
private Module module;
|
||||
private Library kotlin;
|
||||
|
||||
public JetLibraryManager(Module module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moduleAdded() {
|
||||
if(ApplicationManager.getApplication().isUnitTestMode())
|
||||
return;
|
||||
|
||||
final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
|
||||
kotlin = ApplicationManager.getApplication().runReadAction(new Computable<Library>() {
|
||||
@Override
|
||||
public Library compute() {
|
||||
return libraryTable.getLibraryByName(KOTLIN_STD_LIB);
|
||||
}
|
||||
});
|
||||
if(kotlin == null) {
|
||||
kotlin = ApplicationManager.getApplication().runWriteAction(new Computable<Library>() {
|
||||
@Override
|
||||
public Library compute() {
|
||||
Library library = libraryTable.createLibrary(KOTLIN_STD_LIB);
|
||||
Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
final File unpackedRuntimePath = AbstractCompileEnvironment.getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
modifiableModel.addRoot(LocalFileSystem.getInstance().findFileByIoFile(unpackedRuntimePath), OrderRootType.CLASSES);
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = AbstractCompileEnvironment.getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
modifiableModel.addRoot(LocalFileSystem.getInstance().findFileByIoFile(unpackedRuntimePath), OrderRootType.CLASSES);
|
||||
}
|
||||
else {
|
||||
// todo
|
||||
}
|
||||
}
|
||||
modifiableModel.commit();
|
||||
return library;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel modifiableModel = rootManager.getModifiableModel();
|
||||
LibraryOrderEntry libraryOrderEntry = modifiableModel.findLibraryOrderEntry(kotlin);
|
||||
if(libraryOrderEntry == null) {
|
||||
modifiableModel.addLibraryEntry(kotlin);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
modifiableModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
return JetLibraryManager.class.getCanonicalName();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.jetbrains.jet.plugin.compiler;
|
||||
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFileSystem;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class PluginCompilerEnvironment extends AbstractCompileEnvironment {
|
||||
public PluginCompilerEnvironment(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addToClasspath(File file) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFileSystem getLocalFileSystem() {
|
||||
return LocalFileSystem.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualFileSystem getJarFileSystem() {
|
||||
return JarFileSystem.getInstance();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -41,11 +40,6 @@ public final class WholeProjectAnalyzerFacade {
|
||||
final Set<JetDeclaration> namespaces = Sets.newLinkedHashSet();
|
||||
final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
|
||||
|
||||
PluginCompilerEnvironment environment = new PluginCompilerEnvironment(project);
|
||||
CompileSession session = new CompileSession(environment);
|
||||
session.addStdLibSources(true);
|
||||
namespaces.addAll(session.getLibrarySourceFileNamespaces());
|
||||
|
||||
if (rootManager != null /* && !ApplicationManager.getApplication().isUnitTestMode() */) {
|
||||
VirtualFile[] contentRoots = rootManager.getContentRoots();
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ import com.intellij.openapi.progress.impl.ProgressManagerImpl;
|
||||
import com.intellij.pom.PomModel;
|
||||
import com.intellij.pom.core.impl.PomModelImpl;
|
||||
import org.jetbrains.jet.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.compiler.AbstractCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CoreCompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
@@ -62,9 +61,9 @@ public class NamespaceToPackage {
|
||||
}
|
||||
});
|
||||
|
||||
CoreCompileEnvironment compileEnvironment = new CoreCompileEnvironment();
|
||||
CompileEnvironment compileEnvironment = new CompileEnvironment();
|
||||
|
||||
compileEnvironment.setJavaRuntime(AbstractCompileEnvironment.findRtJar(true));
|
||||
compileEnvironment.setJavaRuntime(CompileEnvironment.findRtJar(true));
|
||||
if (!compileEnvironment.initializeKotlinRuntime()) {
|
||||
System.out.println("foo");
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,4 +82,4 @@ fun <T> java.lang.Iterable<T>.contains(item : T) : Boolean {
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -21,13 +21,9 @@ class ModuleSetBuilder(): IModuleSetBuilder {
|
||||
override fun getModules(): List<IModuleBuilder?>? = modules
|
||||
}
|
||||
|
||||
class SourcesBuilder() {
|
||||
protected val sourceFiles: ArrayList<String?> = ArrayList<String?>()
|
||||
|
||||
fun files(vararg pattern: String) {
|
||||
for(p in pattern) {
|
||||
sourceFiles.add(p)
|
||||
}
|
||||
class SourcesBuilder(val parent: ModuleBuilder) {
|
||||
fun files(pattern: String) {
|
||||
parent.addSourceFiles(pattern)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,18 +40,23 @@ class JarBuilder(val parent: ModuleBuilder) {
|
||||
}
|
||||
|
||||
open class ModuleBuilder(val name: String): IModuleBuilder {
|
||||
val source = SourcesBuilder()
|
||||
val testSource = SourcesBuilder()
|
||||
|
||||
val sourceFiles: ArrayList<String?> = ArrayList<String?>()
|
||||
val classpathRoots: ArrayList<String?> = ArrayList<String?>()
|
||||
var _jarName: String? = null
|
||||
|
||||
val source: SourcesBuilder
|
||||
get() = SourcesBuilder(this)
|
||||
|
||||
val classpath: ClasspathBuilder
|
||||
get() = ClasspathBuilder(this)
|
||||
|
||||
val jar: JarBuilder
|
||||
get() = JarBuilder(this)
|
||||
|
||||
fun addSourceFiles(pattern: String) {
|
||||
sourceFiles.add(pattern)
|
||||
}
|
||||
|
||||
fun addClasspathEntry(name: String) {
|
||||
classpathRoots.add(name)
|
||||
}
|
||||
@@ -64,8 +65,7 @@ open class ModuleBuilder(val name: String): IModuleBuilder {
|
||||
_jarName = name
|
||||
}
|
||||
|
||||
override fun getSourceFiles(): List<String?>? = source.sourceFiles
|
||||
override fun getTestSourceFiles(): List<String?>? = testSource.sourceFiles
|
||||
override fun getSourceFiles(): List<String?>? = sourceFiles
|
||||
override fun getClasspathRoots(): List<String?>? = classpathRoots
|
||||
override fun getModuleName(): String? = name
|
||||
override fun getJarName(): String? = _jarName
|
||||
@@ -8,7 +8,6 @@ import java.util.List;
|
||||
public interface IModuleBuilder {
|
||||
String getModuleName();
|
||||
List<String> getSourceFiles();
|
||||
List<String> getTestSourceFiles();
|
||||
List<String> getClasspathRoots();
|
||||
String getJarName();
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="stdlib" />
|
||||
<orderEntry type="module" module-name="testlib" />
|
||||
<orderEntry type="library" name="KotlinStdLib" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="KotlinStdLib" level="project" />
|
||||
<orderEntry type="module" module-name="stdlib" exported="" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user