diff --git a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java index e6ec1cadafb..724a0b152b2 100644 --- a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java +++ b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java @@ -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 nonConfiguredModules = ConfigureKotlinInProjectUtils.getNonConfiguredModules(project, this); + List 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 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 { diff --git a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinWithLibraryConfigurator.java b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinWithLibraryConfigurator.java index 3782a3210f7..fb9f07089fd 100644 --- a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinWithLibraryConfigurator.java +++ b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinWithLibraryConfigurator.java @@ -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 { diff --git a/idea/testData/configuration/libraryNonDefault/lib/kotlin-runtime.jar b/idea/testData/configuration/libraryNonDefault/lib/kotlin-runtime.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/configuration/libraryNonDefault/module1.iml b/idea/testData/configuration/libraryNonDefault/module1.iml new file mode 100644 index 00000000000..c7649d2d5da --- /dev/null +++ b/idea/testData/configuration/libraryNonDefault/module1.iml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/idea/testData/configuration/libraryNonDefault/projectFile.ipr b/idea/testData/configuration/libraryNonDefault/projectFile.ipr new file mode 100644 index 00000000000..e31006eb15e --- /dev/null +++ b/idea/testData/configuration/libraryNonDefault/projectFile.ipr @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureKotlinTest.java b/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureKotlinTest.java index c8cbba06bc3..027a895b1b4 100644 --- a/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureKotlinTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/configuration/ConfigureKotlinTest.java @@ -16,13 +16,13 @@ package org.jetbrains.jet.plugin.configuration; +import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.testFramework.PlatformTestCase; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.utils.PathUtil; import java.io.File; @@ -38,6 +38,21 @@ public class ConfigureKotlinTest extends PlatformTestCase { private static final KotlinJavaModuleConfigurator JAVA_CONFIGURATOR = new KotlinJavaModuleConfigurator(); private static final KotlinJsModuleConfigurator JS_CONFIGURATOR = new KotlinJsModuleConfigurator(); + @Override + protected void tearDown() throws Exception { + PathMacros.getInstance().removeMacro("TEMP_TEST_DIR"); + + super.tearDown(); + } + + @Override + protected void initApplication() throws Exception { + super.initApplication(); + + File tempLibDir = FileUtil.createTempDirectory("temp", null); + PathMacros.getInstance().setMacro("TEMP_TEST_DIR", tempLibDir.getAbsolutePath()); + } + public void testNewLibrary_copyJar() { doTestOneJavaModule(FileState.COPY, LibraryState.NEW_LIBRARY); } @@ -88,6 +103,16 @@ public class ConfigureKotlinTest extends PlatformTestCase { } } + public void testLibraryNonDefault_libExistInDefault() throws IOException { + Module module = getModule(); + + assertFalse("Module " + module.getName() + " should not be configured", JAVA_CONFIGURATOR.isConfigured(module)); + JAVA_CONFIGURATOR.configure(myProject); + assertTrue("Module " + module.getName() + " should be configured", JAVA_CONFIGURATOR.isConfigured(getModule())); + assertFalse("Module " + getModule().getName() + " should not be configured as JavaScript Module", + JS_CONFIGURATOR.isConfigured(getModule())); + } + public void testNewLibrary_jarExists_js() { doTestOneJsModule(FileState.EXISTS, LibraryState.NEW_LIBRARY); }