Search in sources :

Example 1 with LocalPackage

use of com.android.repository.api.LocalPackage 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 LocalPackage

use of com.android.repository.api.LocalPackage in project android by JetBrains.

the class IdeSdks method getAndroidNdkPath.

@Nullable
public File getAndroidNdkPath() {
    AndroidSdkHandler sdkHandler = myAndroidSdks.tryToChooseSdkHandler();
    LocalPackage ndk = sdkHandler.getLocalPackage(SdkConstants.FD_NDK, new StudioLoggerProgressIndicator(IdeSdks.class));
    return ndk == null ? null : ndk.getLocation();
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with LocalPackage

use of com.android.repository.api.LocalPackage 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 4 with LocalPackage

use of com.android.repository.api.LocalPackage in project android by JetBrains.

the class PatchInstallerUtilTest method getLatestPatcher.

@Test
public void getLatestPatcher() throws Exception {
    LocalPackage target = new FakeLocalPackage("patcher;v3");
    List<LocalPackage> local = ImmutableList.of(new FakeLocalPackage("patcher;v1"), target, new FakeLocalPackage("patcher;v2"));
    RepositoryPackages packages = new RepositoryPackages(local, ImmutableList.of());
    FakeRepoManager mgr = new FakeRepoManager(new File("/sdk"), packages);
    LocalPackage patcher = PatchInstallerUtil.getLatestPatcher(mgr);
    assertEquals(target, patcher);
}
Also used : FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) LocalPackage(com.android.repository.api.LocalPackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) File(java.io.File) Test(org.junit.Test)

Example 5 with LocalPackage

use of com.android.repository.api.LocalPackage in project android by JetBrains.

the class PatchInstallerFactoryTest method cantHandleWindowsUninstallWithoutPatcher.

@Test
public void cantHandleWindowsUninstallWithoutPatcher() {
    myFileOp.setIsWindows(true);
    LocalPackage p = new FakeLocalPackage("foo");
    myRepositoryPackages.setLocalPkgInfos(ImmutableList.of(p));
    assertFalse(myInstallerFactory.canHandlePackage(p, myRepoManager, myFileOp));
}
Also used : FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) LocalPackage(com.android.repository.api.LocalPackage) FakeLocalPackage(com.android.repository.testframework.FakePackage.FakeLocalPackage) Test(org.junit.Test)

Aggregations

LocalPackage (com.android.repository.api.LocalPackage)16 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)7 Test (org.junit.Test)7 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)6 File (java.io.File)6 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)5 Revision (com.android.repository.Revision)4 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)4 ProgressIndicator (com.android.repository.api.ProgressIndicator)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 RemotePackage (com.android.repository.api.RemotePackage)2 FakeDependency (com.android.repository.testframework.FakeDependency)2 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 RepoManager (com.android.repository.api.RepoManager)1 TypeDetails (com.android.repository.impl.meta.TypeDetails)1 AndroidVersion (com.android.sdklib.AndroidVersion)1