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:
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/module1.iml" filepath="$PROJECT_DIR$/module1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"/>
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime">
|
||||
<CLASSES>
|
||||
<root url="jar://$TEMP_TEST_DIR$/kotlin-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$TEMP_TEST_DIR$/kotlin-runtime.jar!/src" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user