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