Search in sources :

Example 1 with Revision

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

the class ApiDetector method beforeCheckProject.

@Override
public void beforeCheckProject(@NonNull Context context) {
    if (mApiDatabase == null) {
        mApiDatabase = ApiLookup.get(context.getClient());
        if (mApiDatabase == null && !mWarnedMissingDb) {
            mWarnedMissingDb = true;
            context.report(IssueRegistry.LINT_ERROR, Location.create(context.file), "Can't find API database; API check not performed");
        } else {
            // See if you don't have at least version 23.0.1 of platform tools installed
            AndroidSdkHandler sdk = context.getClient().getSdk();
            if (sdk == null) {
                return;
            }
            LocalPackage pkgInfo = sdk.getLocalPackage(SdkConstants.FD_PLATFORM_TOOLS, context.getClient().getRepositoryLogger());
            if (pkgInfo == null) {
                return;
            }
            Revision revision = pkgInfo.getVersion();
            // The platform tools must be at at least the same revision
            // as the compileSdkVersion!
            // And as a special case, for 23, they must be at 23.0.1
            // because 23.0.0 accidentally shipped without Android M APIs.
            int compileSdkVersion = context.getProject().getBuildSdk();
            if (compileSdkVersion == 23) {
                if (revision.getMajor() > 23 || revision.getMajor() == 23 && (revision.getMinor() > 0 || revision.getMicro() > 0)) {
                    return;
                }
            } else if (compileSdkVersion <= revision.getMajor()) {
                return;
            }
            // Pick a location: when incrementally linting in the IDE, tie
            // it to the current file
            List<File> currentFiles = context.getProject().getSubset();
            Location location;
            if (currentFiles != null && currentFiles.size() == 1) {
                File file = currentFiles.get(0);
                String contents = context.getClient().readFile(file);
                int firstLineEnd = contents.indexOf('\n');
                if (firstLineEnd == -1) {
                    firstLineEnd = contents.length();
                }
                location = Location.create(file, new DefaultPosition(0, 0, 0), new DefaultPosition(0, firstLineEnd, firstLineEnd));
            } else {
                location = Location.create(context.file);
            }
            context.report(UNSUPPORTED, location, String.format("The SDK platform-tools version (%1$s) is too old " + " to check APIs compiled with API %2$d; please update", revision.toShortString(), compileSdkVersion));
        }
    }
}
Also used : LocalPackage(com.android.repository.api.LocalPackage) Revision(com.android.repository.Revision) AndroidSdkHandler(com.android.sdklib.repositoryv2.AndroidSdkHandler) File(java.io.File)

Example 2 with Revision

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

the class SystemInfoStatsMonitor method runEmulatorCheck.

@Nullable
private static Integer runEmulatorCheck(@NotNull String argument, @NotNull Revision lowestToolsRevisiion, @NotNull AndroidSdkHandler handler) throws ExecutionException {
    LocalPackage toolsPackage = handler.getLocalPackage(SdkConstants.FD_TOOLS, new StudioLoggerProgressIndicator(AndroidSdkInitializer.class));
    if (toolsPackage == null) {
        throw new ExecutionException("No SDK tools package");
    }
    final Revision toolsRevision = toolsPackage.getVersion();
    if (toolsRevision.compareTo(lowestToolsRevisiion) < 0) {
        return null;
    }
    File checkBinary = getEmulatorCheckBinary(handler);
    if (!checkBinary.isFile()) {
        throw new ExecutionException("No emulator-check binary in the SDK tools package");
    }
    GeneralCommandLine commandLine = new GeneralCommandLine(checkBinary.getPath(), argument);
    CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
    ProcessOutput output = process.runProcess();
    int exitCode = output.getExitCode();
    if (exitCode == EMULATOR_CHECK_ERROR_EXIT_CODE) {
        throw new ExecutionException(String.format("Emulator-check failed to check for '%s' with a generic error code %d", argument, EMULATOR_CHECK_ERROR_EXIT_CODE));
    }
    return exitCode;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) AndroidSdkInitializer(com.android.tools.idea.startup.AndroidSdkInitializer) Revision(com.android.repository.Revision) CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with Revision

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

the class AccelerationErrorSolution method createKvmInstallCommand.

@Nullable
private static GeneralCommandLine createKvmInstallCommand() {
    try {
        String version = execute("uname", "-r");
        Revision revision = toRevision(version);
        if (revision.compareTo(KARMIC_KERNEL) <= 0) {
            return generateCommand("gksudo", "aptitude -y", "install", "kvm", "libvirt-bin", "ubuntu-vm-builder", "bridge-utils");
        } else {
            return generateCommand("gksudo", "apt-get --assume-yes", "install", "qemu-kvm", "libvirt-bin", "ubuntu-vm-builder", "bridge-utils");
        }
    } catch (ExecutionException ex) {
        LOG.error(ex);
    } catch (NumberFormatException ex) {
        LOG.error(ex);
    }
    return null;
}
Also used : Revision(com.android.repository.Revision) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Revision

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

the class TemplateManager method getHighestVersionedTemplateRoot.

@NotNull
private List<File> getHighestVersionedTemplateRoot(@NotNull File artifactNameRoot) {
    List<File> templateDirectories = Lists.newArrayList();
    File highestVersionDir = null;
    Revision highestVersionNumber = null;
    for (File versionDir : listFiles(artifactNameRoot)) {
        if (!versionDir.isDirectory() || versionDir.isHidden()) {
            continue;
        }
        // Find the highest version of this AAR
        Revision revision;
        try {
            revision = Revision.parseRevision(versionDir.getName());
        } catch (NumberFormatException e) {
            // Revision was not parse-able, consider it to be the lowest version revision
            revision = Revision.NOT_SPECIFIED;
        }
        if (highestVersionNumber == null || revision.compareTo(highestVersionNumber) > 0) {
            highestVersionNumber = revision;
            highestVersionDir = versionDir;
        }
    }
    if (highestVersionDir != null) {
        String name = artifactNameRoot.getName() + "-" + highestVersionNumber.toString();
        File inflated = new File(myAarCache, name);
        if (!inflated.isDirectory()) {
            // Only unzip once
            File zipFile = new File(highestVersionDir, TEMPLATE_ZIP_NAME);
            if (zipFile.isFile()) {
                try {
                    ZipUtil.unzip(null, inflated, zipFile, null, null, true);
                } catch (IOException e) {
                    LOG.error(e);
                }
            }
        }
        if (inflated.isDirectory()) {
            templateDirectories.add(inflated);
        }
    }
    return templateDirectories;
}
Also used : Revision(com.android.repository.Revision) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Revision

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

the class RepositoryUrlManager method resolveDynamicCoordinateVersion.

@Nullable
@VisibleForTesting
String resolveDynamicCoordinateVersion(@NotNull GradleCoordinate coordinate, @Nullable Project project, @NotNull AndroidSdkHandler sdkHandler) {
    if (coordinate.getGroupId() == null || coordinate.getArtifactId() == null) {
        return null;
    }
    String filter = coordinate.getRevision();
    if (!filter.endsWith("+")) {
        // Already resolved. That was easy.
        return filter;
    }
    filter = filter.substring(0, filter.length() - 1);
    File sdkLocation = sdkHandler.getLocation();
    if (sdkLocation != null) {
        // If this coordinate points to an artifact in one of our repositories, mark it will a comment if they don't
        // have that repository available.
        String libraryCoordinate = getLibraryRevision(coordinate.getGroupId(), coordinate.getArtifactId(), filter, false, sdkLocation, sdkHandler.getFileOp());
        if (libraryCoordinate != null) {
            return libraryCoordinate;
        }
        // If that didn't yield any matches, try again, this time allowing preview platforms.
        // This is necessary if the artifact filter includes enough of a version where there are
        // only preview matches.
        libraryCoordinate = getLibraryRevision(coordinate.getGroupId(), coordinate.getArtifactId(), filter, true, sdkLocation, sdkHandler.getFileOp());
        if (libraryCoordinate != null) {
            return libraryCoordinate;
        }
    }
    // Regular Gradle dependency? Look in Gradle cache
    GradleVersion versionFound = GradleLocalCache.getInstance().findLatestArtifactVersion(coordinate, project, filter);
    if (versionFound != null) {
        return versionFound.toString();
    }
    // Maybe it's available for download as an SDK component
    RemotePackage sdkPackage = SdkMavenRepository.findLatestRemoteVersion(coordinate, sdkHandler, new StudioLoggerProgressIndicator(getClass()));
    if (sdkPackage != null) {
        GradleCoordinate found = SdkMavenRepository.getCoordinateFromSdkPath(sdkPackage.getPath());
        if (found != null) {
            return found.getRevision();
        }
    }
    // Perform network lookup to resolve current best version, if possible
    if (project != null) {
        LintClient client = new LintIdeClient(project);
        Revision latest = GradleDetector.getLatestVersionFromRemoteRepo(client, coordinate, coordinate.isPreview());
        if (latest != null) {
            String version = latest.toShortString();
            if (version.startsWith(filter)) {
                return version;
            }
        }
    }
    return null;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) Revision(com.android.repository.Revision) LintClient(com.android.tools.lint.client.api.LintClient) LintIdeClient(com.android.tools.idea.lint.LintIdeClient) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

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