Find kotlin library using library name, jar name in library classes root and marker class in library scope

This commit is contained in:
Natalia.Ukhorskaya
2013-09-25 13:54:36 +04:00
parent bb42c54b7c
commit 983dfbdf3c
2 changed files with 32 additions and 6 deletions
@@ -1,11 +1,16 @@
package org.jetbrains.jet.plugin.configuration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.impl.scopes.LibraryScope;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.framework.JavaRuntimeLibraryDescription;
import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector;
import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialogWithModules;
import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
@@ -89,6 +94,16 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
return assertFileExists(getKotlinPaths().getRuntimeSourcesPath());
}
@Override
protected boolean isKotlinLibrary(@NotNull Project project, @NotNull Library library) {
if (super.isKotlinLibrary(project, library)) {
return true;
}
LibraryScope scope = new LibraryScope(project, library);
return KotlinRuntimeLibraryUtil.getKotlinRuntimeMarkerClass(scope) != null;
}
KotlinJavaModuleConfigurator() {
}
}
@@ -15,6 +15,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -170,12 +171,12 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
public Library getKotlinLibrary(@NotNull Project project) {
LibrariesContainer librariesContainer = LibrariesContainerFactory.createContainer(project);
for (Library library : librariesContainer.getLibraries(LibrariesContainer.LibraryLevel.PROJECT)) {
if (isKotlinLibrary(library)) {
if (isKotlinLibrary(project, library)) {
return library;
}
}
for (Library library : librariesContainer.getLibraries(LibrariesContainer.LibraryLevel.GLOBAL)) {
if (isKotlinLibrary(library)) {
if (isKotlinLibrary(project, library)) {
return library;
}
}
@@ -286,12 +287,12 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
}
@Nullable
private Library getKotlinLibrary(@NotNull Module module) {
private Library getKotlinLibrary(@NotNull final Module module) {
final Ref<Library> result = Ref.create(null);
OrderEnumerator.orderEntries(module).forEachLibrary(new Processor<Library>() {
@Override
public boolean process(Library library) {
if (isKotlinLibrary(library)) {
if (isKotlinLibrary(module.getProject(), library)) {
result.set(library);
return false;
}
@@ -301,8 +302,18 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
return result.get();
}
private boolean isKotlinLibrary(@NotNull Library library) {
return getLibraryName().equals(library.getName());
protected boolean isKotlinLibrary(@NotNull Project project, @NotNull Library library) {
if (getLibraryName().equals(library.getName())) {
return true;
}
for (VirtualFile root : library.getFiles(OrderRootType.CLASSES)) {
if (root.getName().equals(getJarName())) {
return true;
}
}
return false;
}
private File copyJarToDir(@NotNull String toDir) {