diff options
author | Alex Ruiz <alruiz@google.com> | 2014-06-30 11:06:52 -0700 |
---|---|---|
committer | Alex Ruiz <alruiz@google.com> | 2014-07-01 14:46:29 -0700 |
commit | e5f0bf8b613d573a79ea176b267e94fe3c43158c (patch) | |
tree | b043385615a1145a23af13a59eb9b00419deb0e4 | |
parent | 85a1a7f2ce2c1dbe69521ba374e90364ed1f17c7 (diff) | |
download | idea-e5f0bf8b613d573a79ea176b267e94fe3c43158c.tar.gz |
Now we check at startup that the IDE does not have an old copy of builder-model jar file.
Fixes:
https://code.google.com/p/android/issues/detail?id=72582
Change-Id: Iab14ade98f31dc0290e2763605c85bc407002b37
-rwxr-xr-x | android/src/com/android/tools/idea/startup/AndroidStudioSpecificInitializer.java | 47 | ||||
-rw-r--r-- | android/testSrc/com/android/tools/idea/startup/AndroidStudioSpecificInitializerTest.java | 32 |
2 files changed, 79 insertions, 0 deletions
diff --git a/android/src/com/android/tools/idea/startup/AndroidStudioSpecificInitializer.java b/android/src/com/android/tools/idea/startup/AndroidStudioSpecificInitializer.java index fb085e9c399..3581f5beb62 100755 --- a/android/src/com/android/tools/idea/startup/AndroidStudioSpecificInitializer.java +++ b/android/src/com/android/tools/idea/startup/AndroidStudioSpecificInitializer.java @@ -26,6 +26,7 @@ import com.android.tools.idea.sdk.VersionCheck; import com.android.tools.idea.sdk.wizard.SdkQuickfixWizard; import com.android.tools.idea.wizard.ExperimentalActionsForTesting; import com.android.utils.Pair; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import com.google.common.io.Closeables; import com.intellij.debugger.settings.NodeRendererSettings; @@ -52,7 +53,9 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkAdditionalData; import com.intellij.openapi.projectRoots.SdkModificator; import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.codeStyle.CodeStyleScheme; @@ -114,6 +117,7 @@ public class AndroidStudioSpecificInitializer implements Runnable { @Override public void run() { + checkInstallation(); cleanUpIdePreferences(); if (!Boolean.getBoolean(USE_IDEA_NEW_PROJECT_WIZARDS)) { @@ -168,6 +172,49 @@ public class AndroidStudioSpecificInitializer implements Runnable { checkAndSetAndroidSdkSources(); } + private static void checkInstallation() { + String studioHome = PathManager.getHomePath(); + if (StringUtil.isEmpty(studioHome)) { + LOG.info("Unable to find Studio home directory"); + return; + } + File studioHomePath = new File(FileUtil.toSystemDependentName(studioHome)); + if (!studioHomePath.isDirectory()) { + LOG.info(String.format("The path '%1$s' does not belong to an existing directory", studioHomePath.getPath())); + return; + } + File androidPluginLibFolderPath = new File(studioHomePath, FileUtil.join("plugins", "android", "lib")); + if (!androidPluginLibFolderPath.isDirectory()) { + LOG.info(String.format("The path '%1$s' does not belong to an existing directory", androidPluginLibFolderPath.getPath())); + return; + } + + File[] children = FileUtil.notNullize(androidPluginLibFolderPath.listFiles()); + if (hasMoreThanOneBuilderModelFile(children)) { + String msg = "Your Android Studio installation is corrupt and will not work properly. " + + "(Found multiple versions of builder-model-*.jar in plugins/android/lib.)\n" + + "This usually happens if Android Studio is extracted into an existing older version.\n\n" + + "Please reinstall (and make sure the new installation directory is empty first.)"; + String title = "Corrupt Installation"; + Messages.showDialog(msg, title, new String[]{"Proceed Anyway"}, 0, Messages.getErrorIcon()); + } + } + + @VisibleForTesting + static boolean hasMoreThanOneBuilderModelFile(@NotNull File[] libraryFiles) { + int builderModelFileCount = 0; + + for (File file : libraryFiles) { + String fileName = file.getName(); + if (fileName.startsWith("builder-model-") && SdkConstants.EXT_JAR.equals(FileUtilRt.getExtension(fileName))) { + if (++builderModelFileCount > 1) { + return true; + } + } + } + + return false; + } private static void cleanUpIdePreferences() { try { diff --git a/android/testSrc/com/android/tools/idea/startup/AndroidStudioSpecificInitializerTest.java b/android/testSrc/com/android/tools/idea/startup/AndroidStudioSpecificInitializerTest.java new file mode 100644 index 00000000000..a5971f071c8 --- /dev/null +++ b/android/testSrc/com/android/tools/idea/startup/AndroidStudioSpecificInitializerTest.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.tools.idea.startup; + +import junit.framework.TestCase; + +import java.io.File; + +public class AndroidStudioSpecificInitializerTest extends TestCase { + public void testHasMoreThanOneBuilderModelFileWithTwoOrMoreBuilderModelFiles() { + File[] files = {new File("builder-model-0.11.0.jar"), new File("builder-model-0.12.0.jar")}; + assertTrue(AndroidStudioSpecificInitializer.hasMoreThanOneBuilderModelFile(files)); + } + + public void testHasMoreThanOneBuilderModelFileWithOneBuilderModelFile() { + File[] files = {new File("builder-model-0.12.0.jar")}; + assertFalse(AndroidStudioSpecificInitializer.hasMoreThanOneBuilderModelFile(files)); + } +} |