Fix exception when there is a non-configured library

This commit is contained in:
Natalia.Ukhorskaya
2013-09-20 14:28:13 +04:00
parent 9cbe0ef8c5
commit f34003deac
2 changed files with 29 additions and 22 deletions
@@ -59,7 +59,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
@NotNull Module module, @NotNull Module module,
@NotNull LibraryState libraryState, @NotNull LibraryState libraryState,
@NotNull FileState jarState, @NotNull FileState jarState,
@Nullable String dirWithJar @NotNull String dirToCopyJarTo
) { ) {
Project project = module.getProject(); Project project = module.getProject();
@@ -70,13 +70,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
break; break;
} }
case COPY: { case COPY: {
String pathToJarFromLibrary = getPathToJarFromLibrary(project); copyJarToDir(dirToCopyJarTo);
if (pathToJarFromLibrary != null) {
copyJarToDir(pathToJarFromLibrary);
}
else {
showError("Cannot copy jar to root for " + getLibraryName() + " library");
}
break; break;
} }
case DO_NOT_COPY: { case DO_NOT_COPY: {
@@ -88,14 +82,11 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
case NON_CONFIGURED_LIBRARY: case NON_CONFIGURED_LIBRARY:
switch (jarState) { switch (jarState) {
case EXISTS: { case EXISTS: {
assert dirWithJar != addJarToExistedLibrary(project, getJarFile(dirToCopyJarTo));
null : "Jar file exists, so dirWithJar must be non-null: should be default path to lib directory";
addJarToExistedLibrary(project, getJarFile(dirWithJar));
break; break;
} }
case COPY: { case COPY: {
assert dirWithJar != null : "Path to copy should be visible in configuration dialog and must be non-null"; File file = copyJarToDir(dirToCopyJarTo);
File file = copyJarToDir(dirWithJar);
addJarToExistedLibrary(project, file); addJarToExistedLibrary(project, file);
break; break;
} }
@@ -108,14 +99,11 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
case NEW_LIBRARY: case NEW_LIBRARY:
switch (jarState) { switch (jarState) {
case EXISTS: { case EXISTS: {
assert dirWithJar != addJarToNewLibrary(project, getJarFile(dirToCopyJarTo));
null : "Jar file exists, so dirWithJar must be non-null: should be default path to lib directory";
addJarToNewLibrary(project, getJarFile(dirWithJar));
break; break;
} }
case COPY: { case COPY: {
assert dirWithJar != null : "Path to copy should be visible in configuration dialog and must be non-null"; File file = copyJarToDir(dirToCopyJarTo);
File file = copyJarToDir(dirWithJar);
addJarToNewLibrary(project, file); addJarToNewLibrary(project, file);
break; break;
} }
@@ -171,7 +159,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
FileState runtimeState = getJarState(project, defaultPath, pathFromDialog); FileState runtimeState = getJarState(project, defaultPath, pathFromDialog);
LibraryState libraryState = getLibraryState(project); LibraryState libraryState = getLibraryState(project);
String dirToCopyJar = isJarPresent(defaultPath) ? defaultPath : pathFromDialog; String dirToCopyJar = getPathToCopyFileTo(project, defaultPath, pathFromDialog);
configureModuleWithLibrary(module, libraryState, runtimeState, dirToCopyJar); configureModuleWithLibrary(module, libraryState, runtimeState, dirToCopyJar);
} }
@@ -315,6 +303,9 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
(pathFormLibrary != null && getJarFile(pathFormLibrary).exists())) { (pathFormLibrary != null && getJarFile(pathFormLibrary).exists())) {
return FileState.EXISTS; return FileState.EXISTS;
} }
else if (pathFormLibrary != null) {
return FileState.COPY;
}
else if (pathFromDialog == null) { else if (pathFromDialog == null) {
return FileState.DO_NOT_COPY; return FileState.DO_NOT_COPY;
} }
@@ -323,6 +314,22 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
} }
@NotNull
private String getPathToCopyFileTo(
@NotNull Project project,
@NotNull String defaultDir,
@Nullable String pathFromDialog
) {
if (pathFromDialog != null) {
return pathFromDialog;
}
String pathFormLibrary = getPathToJarFromLibrary(project);
if (pathFormLibrary != null) {
return pathFormLibrary;
}
return defaultDir;
}
KotlinWithLibraryConfigurator() { KotlinWithLibraryConfigurator() {
} }
} }
@@ -140,7 +140,7 @@ public class ConfigureKotlinTest extends PlatformTestCase {
} }
} }
@Nullable @NotNull
private static String getPathToJar(@NotNull FileState runtimeState, @NotNull String jarFromDist, @NotNull String jarFromTemp) { private static String getPathToJar(@NotNull FileState runtimeState, @NotNull String jarFromDist, @NotNull String jarFromTemp) {
switch (runtimeState) { switch (runtimeState) {
case EXISTS: case EXISTS:
@@ -148,9 +148,9 @@ public class ConfigureKotlinTest extends PlatformTestCase {
case COPY: case COPY:
return jarFromTemp; return jarFromTemp;
case DO_NOT_COPY: case DO_NOT_COPY:
return null; return jarFromDist;
} }
return null; return jarFromDist;
} }
private static void configure(@NotNull Module module, @NotNull FileState jarState, @NotNull LibraryState libraryState, @NotNull KotlinProjectConfigurator configurator) { private static void configure(@NotNull Module module, @NotNull FileState jarState, @NotNull LibraryState libraryState, @NotNull KotlinProjectConfigurator configurator) {