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));
}
}
}
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();
}
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;
}
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);
}
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));
}
Aggregations