Fix problem in configuration with copy runtime jar

Jar with runtime wasn't copied to library with configured classpath if runtime jar was present in default directory.

Mute configure dialog for tests
This commit is contained in:
Nikolay Krasko
2014-07-18 19:20:31 +04:00
parent ae4bac06b2
commit b20b406d8e
6 changed files with 85 additions and 17 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.configuration;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.impl.scopes.LibraryScope;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
@@ -32,6 +33,7 @@ import org.jetbrains.jet.plugin.versions.KotlinRuntimeLibraryUtil;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import static org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils.showInfoNotification;
@@ -85,15 +87,29 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
String defaultPath = getDefaultPathToJarFile(project);
boolean showPathPanelForJava = needToChooseJarPath(project);
List<Module> nonConfiguredModules = ConfigureKotlinInProjectUtils.getNonConfiguredModules(project, this);
List<Module> nonConfiguredModules = !ApplicationManager.getApplication().isUnitTestMode() ?
ConfigureKotlinInProjectUtils.getNonConfiguredModules(project, this):
Arrays.asList(ModuleManager.getInstance(project).getModules());
if (nonConfiguredModules.size() > 1 || showPathPanelForJava) {
CreateJavaLibraryDialogWithModules dialog =
new CreateJavaLibraryDialogWithModules(project, nonConfiguredModules, defaultPath, showPathPanelForJava);
dialog.show();
if (!dialog.isOK()) return;
for (Module module : dialog.getModulesToConfigure()) {
configureModuleWithLibrary(module, defaultPath, dialog.getCopyIntoPath());
List<Module> modulesToConfigure;
String copyLibIntoPath;
if (!ApplicationManager.getApplication().isUnitTestMode()) {
CreateJavaLibraryDialogWithModules dialog = new CreateJavaLibraryDialogWithModules(
project, nonConfiguredModules, defaultPath, showPathPanelForJava);
dialog.show();
if (!dialog.isOK()) return;
modulesToConfigure = dialog.getModulesToConfigure();
copyLibIntoPath = dialog.getCopyIntoPath();
}
else {
modulesToConfigure = nonConfiguredModules;
copyLibIntoPath = defaultPath;
}
for (Module module : modulesToConfigure) {
configureModuleWithLibrary(module, defaultPath, copyLibIntoPath);
}
}
else {
@@ -73,16 +73,17 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
) {
Project project = module.getProject();
FileState runtimeState = getJarState(project, getJarName(), OrderRootType.CLASSES, defaultPath, pathFromDialog);
LibraryState libraryState = getLibraryState(project);
String dirToCopyJar = getPathToCopyFileTo(project, OrderRootType.CLASSES, defaultPath, pathFromDialog);
FileState runtimeState = getJarState(project, getJarName(), OrderRootType.CLASSES, dirToCopyJar, pathFromDialog == null);
configureModuleWithLibraryClasses(module, libraryState, runtimeState, dirToCopyJar);
Library library = getKotlinLibrary(project);
assert library != null : "Kotlin library should exists when adding sources root";
FileState sourcesState = getJarState(project, getSourcesJarName(), OrderRootType.SOURCES, defaultPath, pathFromDialog);
String dirToCopySourcesJar = getPathToCopyFileTo(project, OrderRootType.SOURCES, defaultPath, pathFromDialog);
FileState sourcesState = getJarState(project, getSourcesJarName(), OrderRootType.SOURCES, dirToCopySourcesJar,
pathFromDialog == null);
configureModuleWithLibrarySources(library, sourcesState, dirToCopySourcesJar);
}
@@ -411,19 +412,17 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
@NotNull Project project,
@NotNull String jarName,
@NotNull OrderRootType jarType,
@NotNull String defaultPath,
@Nullable String pathFromDialog
@NotNull String copyPath,
boolean useBundled
) {
String pathFromLibrary = getPathFromLibrary(project, jarType);
if (getFileInDir(jarName, defaultPath).exists() ||
(pathFromDialog != null && getFileInDir(jarName, pathFromDialog).exists()) ||
(pathFromLibrary != null && getFileInDir(jarName, pathFromLibrary).exists())) {
if (getFileInDir(jarName, copyPath).exists()) {
return FileState.EXISTS;
}
else if (pathFromLibrary != null) {
return FileState.COPY;
}
else if (pathFromDialog == null) {
else if (useBundled) {
return FileState.DO_NOT_COPY;
}
else {