Search in sources :

Example 21 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class AvdWizardUtils method emulatorSupportsWebp.

@VisibleForTesting
static boolean emulatorSupportsWebp(@NotNull AndroidSdkHandler sdkHandler) {
    ProgressIndicator log = new StudioLoggerProgressIndicator(AvdWizardUtils.class);
    LocalPackage sdkPackage = sdkHandler.getLocalPackage(FD_EMULATOR, log);
    if (sdkPackage == null) {
        sdkPackage = sdkHandler.getLocalPackage(FD_TOOLS, log);
    }
    if (sdkPackage != null) {
        Revision version = sdkPackage.getVersion();
        // >= 25.2.3?
        if (version.getMajor() > 25 || version.getMajor() == 25 && (version.getMinor() > 2 || version.getMinor() == 2 && version.getMicro() >= 3)) {
            return true;
        }
    }
    return false;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) Revision(com.android.repository.Revision) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) VisibleForTesting(com.android.annotations.VisibleForTesting)

Example 22 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class DistributionService method loadDistributionsFromJson.

@Nullable
private static List<Distribution> loadDistributionsFromJson(String jsonString) {
    Type fullRevisionType = new TypeToken<Revision>() {
    }.getType();
    GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(fullRevisionType, new JsonDeserializer<Revision>() {

        @Override
        public Revision deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
            return Revision.parseRevision(json.getAsString());
        }
    });
    Gson gson = gsonBuilder.create();
    Type listType = new TypeToken<ArrayList<Distribution>>() {
    }.getType();
    try {
        return gson.fromJson(jsonString, listType);
    } catch (JsonParseException e) {
        LOG.error("Parse exception while reading distributions.json", e);
    }
    return null;
}
Also used : Type(java.lang.reflect.Type) Revision(com.android.repository.Revision) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class VersionCheck method checkVersion.

/**
   * Verifies that the Android SDK Tools revision is at least {@link #MIN_TOOLS_REV}
   *
   * @param sdkPath the path of the Android SDK.
   * @return the result of the check.
   */
@NotNull
public static VersionCheckResult checkVersion(@NotNull String sdkPath) {
    File toolsDir = new File(sdkPath, SdkConstants.OS_SDK_TOOLS_FOLDER);
    Revision toolsRevision = new Revision(Integer.MAX_VALUE);
    BufferedReader reader = null;
    try {
        File sourceProperties = new File(toolsDir, SdkConstants.FN_SOURCE_PROP);
        //noinspection IOResourceOpenedButNotSafelyClosed
        reader = new BufferedReader(new FileReader(sourceProperties));
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher m = SOURCE_PROPERTY_PATTERN.matcher(line);
            if (m.matches()) {
                try {
                    toolsRevision = Revision.parseRevision(m.group(1));
                } catch (NumberFormatException ignore) {
                }
                break;
            }
        }
    } catch (IOException e) {
        String msg = String.format("Failed to read file: '%1$s' for Android SDK at '%2$s'", SdkConstants.FN_SOURCE_PROP, sdkPath);
        LOG.info(msg, e);
    } finally {
        try {
            Closeables.close(reader, true);
        } catch (IOException e) {
        // Cannot happen
        }
    }
    return new VersionCheckResult(toolsRevision);
}
Also used : Revision(com.android.repository.Revision) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class PatchInstallingRestarter method processPatch.

/**
   * Either restart and install the given patch or delete it (if it's already installed).
   */
private void processPatch(File androidSdkPath, StudioLoggerProgressIndicator progress, File patchDir) {
    RepoPackage pendingPackage = null;
    File installDir = null;
    try {
        RepoManager mgr = mySdkHandler.getSdkManager(progress);
        Repository repo = InstallerUtil.readPendingPackageXml(patchDir, mgr, myFileOp, progress);
        if (repo != null) {
            File patch = new File(patchDir, PatchInstallerUtil.PATCH_JAR_FN);
            pendingPackage = repo.getLocalPackage();
            boolean remote = false;
            if (pendingPackage != null) {
                // If the pending package was local, use the corresponding installed local package.
                installDir = mgr.getPackages().getLocalPackages().get(pendingPackage.getPath()).getLocation();
            } else {
                // Otherwise it's remote.
                pendingPackage = repo.getRemotePackage().get(0);
                installDir = ((RemotePackage) pendingPackage).getInstallDir(mgr, progress);
                remote = true;
            }
            File existingPackageXml = new File(installDir, LocalRepoLoaderImpl.PACKAGE_XML_FN);
            File oldPackageXml = new File(patchDir, OLD_PACKAGE_XML_FN);
            if (patch.exists() && existingPackageXml.renameTo(oldPackageXml)) {
            // This will exit the app.
            //          Main.installPatch("sdk", PatchInstallerUtil.PATCH_JAR_FN, FileUtil.getTempDirectory(), patch, installDir.getAbsolutePath());
            } else {
                // The patch is already installed, or was cancelled.
                String relativePath = FileOpUtils.makeRelative(androidSdkPath, installDir, myFileOp);
                // Use the old mechanism to get the version, since it's actually part of the package itself. Thus we can tell if the patch
                // has already been applied.
                Revision rev = AndroidCommonUtils.parsePackageRevision(androidSdkPath.getPath(), relativePath);
                if (rev != null && rev.equals(pendingPackage.getVersion())) {
                    // We need to make sure the listeners are fired, so create an installer that does nothing and invoke it.
                    InstallerFactory dummyFactory = new DummyInstallerFactory();
                    dummyFactory.setListenerFactory(new StudioSdkInstallListenerFactory(mySdkHandler));
                    if (remote) {
                        Installer installer = dummyFactory.createInstaller((RemotePackage) pendingPackage, mgr, new StudioDownloader(), myFileOp);
                        installer.complete(progress);
                    } else {
                        Uninstaller uninstaller = dummyFactory.createUninstaller((LocalPackage) pendingPackage, mgr, myFileOp);
                        uninstaller.complete(progress);
                    }
                } else {
                    // something went wrong. Move the old package.xml back into place.
                    progress.logWarning("Failed to find version information in " + new File(androidSdkPath, SdkConstants.FN_SOURCE_PROP));
                    oldPackageXml.renameTo(existingPackageXml);
                }
            }
        }
    } catch (Exception e) {
        StringBuilder message = new StringBuilder("A problem occurred while installing ");
        message.append(pendingPackage != null ? pendingPackage.getDisplayName() : "an SDK package");
        if (installDir != null) {
            message.append(" in ").append(installDir);
        }
        message.append(". Please try again.");
        Messages.showErrorDialog(message.toString(), "Error Launching SDK Component Installer");
        progress.logWarning("Failed to install SDK package", e);
    }
    // If we get here we either got an error or the patch was already installed. Delete the patch dir.
    try {
        myFileOp.deleteFileOrFolder(patchDir);
    } catch (Exception e) {
        progress.logWarning("Problem during patch cleanup", e);
    }
}
Also used : AbstractInstaller(com.android.repository.impl.installer.AbstractInstaller) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) AbstractInstallerFactory(com.android.repository.impl.installer.AbstractInstallerFactory) Revision(com.android.repository.Revision) AbstractUninstaller(com.android.repository.impl.installer.AbstractUninstaller) File(java.io.File) StudioSdkInstallListenerFactory(com.android.tools.idea.sdk.install.StudioSdkInstallListenerFactory)

Example 25 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class Platform method findLatestCompatibleBuildTool.

private String findLatestCompatibleBuildTool() {
    Revision revision = null;
    String path = null;
    for (RemotePackage remote : getRepositoryPackages().getRemotePackages().values()) {
        if (!remote.getPath().startsWith(SdkConstants.FD_BUILD_TOOLS)) {
            continue;
        }
        Revision testRevision = remote.getVersion();
        if (testRevision.getMajor() == myVersion.getApiLevel() && (revision == null || testRevision.compareTo(revision) > 0)) {
            revision = testRevision;
            path = remote.getPath();
        }
    }
    return path;
}
Also used : Revision(com.android.repository.Revision) RemotePackage(com.android.repository.api.RemotePackage)

Aggregations

Revision (com.android.repository.Revision)37 Test (org.junit.Test)11 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)10 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)9 File (java.io.File)8 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)6 UpdatableExternalComponent (com.intellij.ide.externalComponents.UpdatableExternalComponent)6 Nullable (org.jetbrains.annotations.Nullable)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 LocalPackage (com.android.repository.api.LocalPackage)4 BuildToolInfo (com.android.sdklib.BuildToolInfo)4 StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)4 NotNull (org.jetbrains.annotations.NotNull)4 Installer (com.android.repository.api.Installer)3 FakeDownloader (com.android.repository.testframework.FakeDownloader)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 ExternalUpdate (com.intellij.openapi.updateSettings.impl.ExternalUpdate)3 UpdateSettings (com.intellij.openapi.updateSettings.impl.UpdateSettings)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2