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