use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class ChooseActivityTypeStep method determineGradlePluginVersion.
/**
* Find the most appropriated Gradle Plugin version for the specified project.
* @param project If {@code null} (ie we are creating a new project) returns the recommended gradle version.
*/
@NotNull
private static String determineGradlePluginVersion(@Nullable Project project) {
String defaultGradleVersion = AndroidPluginGeneration.ORIGINAL.getLatestKnownVersion();
if (project == null) {
return defaultGradleVersion;
}
GradleVersion versionInUse = GradleUtil.getAndroidGradleModelVersionInUse(project);
if (versionInUse != null) {
return versionInUse.toString();
}
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.searchInBuildFilesOnly(project);
GradleVersion pluginVersion = (androidPluginInfo == null) ? null : androidPluginInfo.getPluginVersion();
return (pluginVersion == null) ? defaultGradleVersion : pluginVersion.toString();
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class BuildSignedApkTest method openAndSignUsingV1AndV2.
@Test
public void openAndSignUsingV1AndV2() throws IOException {
GradleVersion latestVersion = GradleVersion.parse(SdkConstants.GRADLE_PLUGIN_LATEST_VERSION);
assume().that(latestVersion.compareIgnoringQualifiers(GradleSignStep.MIN_SIGNATURE_SELECTION_VERSION)).isAtLeast(0);
File jksFile = new File(myTemporaryFolder.getRoot(), "jks");
File dstFolder = myTemporaryFolder.newFolder("dst");
guiTest.importSimpleApplication().openFromMenu(BuildSignedApkDialogKeystoreStepFixture::find, "Build", "Generate Signed APK...").createNew().keyStorePath(jksFile.getAbsolutePath()).password("passwd").passwordConfirm("passwd").alias("key").keyPassword("passwd2").keyPasswordConfirm("passwd2").validity("3").firstAndLastName("Android Studio").organizationalUnit("Android").organization("Google").cityOrLocality("Mountain View").stateOrProvince("California").countryCode("US").clickOk().keyStorePassword("passwd").keyAlias("key").keyPassword("passwd2").clickNext().apkDestinationFolder(dstFolder.getAbsolutePath()).setV1SignatureEnabled(true).setV2SignatureEnabled(true).clickFinish();
// We should verify that a V2 signature is present, but that is hard to do here.
File[] apks = dstFolder.listFiles();
assertThat(apks).hasLength(1);
File apk = apks[0];
try (ZipFile zf = new ZipFile(apk)) {
assertThat(zf.getEntry("META-INF/CERT.SF")).isNotNull();
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class ExternalRepository method doRefreshFor.
private void doRefreshFor(@NotNull final String groupId, @NotNull final String artifactId) {
String url = String.format(URL_TEMPLATE, groupId.replaceAll("\\.", "/"), artifactId);
Document document;
try {
document = JDOMUtil.loadDocument(URI.create(url).toURL());
} catch (JDOMException e) {
LOG.warn(String.format("Unexpected exception occurred on attempt to parse document from %s (checking the latest version " + "for artifact '%s:%s')", url, groupId, artifactId));
return;
} catch (IOException e) {
LOG.warn(String.format("Unexpected I/O exception occurred on attempt to check the latest version for artifact '%s:%s' at " + "external repository (url %s)", groupId, artifactId, url));
return;
}
Element versioning = document.getRootElement().getChild(MAVEN_METADATA_VERSIONING);
if (versioning == null) {
LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown format - expected to find a <%s> element under a root element but it's not there", groupId, artifactId, url, MAVEN_METADATA_VERSIONING));
return;
}
Element latest = versioning.getChild(MAVEN_METADATA_LATEST);
if (latest == null) {
LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown format - expected to find a <%s> element under a <%s> element but it's not there", groupId, artifactId, url, MAVEN_METADATA_LATEST, MAVEN_METADATA_VERSIONING));
return;
}
try {
GradleVersion version = GradleVersion.parse(latest.getText());
myLatestVersionCache.put(Pair.create(groupId, artifactId), version);
} catch (NumberFormatException e) {
LOG.warn(String.format("Can't check the latest version for artifact '%s:%s'. Reason: artifact metadata info downloaded from " + "%s has unknown version format - '%s'", groupId, artifactId, url, latest.getText()));
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class PostSyncProjectSetup method attemptToGenerateSources.
private void attemptToGenerateSources(@NotNull Request request) {
if (!request.isGenerateSourcesAfterSync()) {
return;
}
boolean cleanProjectAfterSync = request.isCleanProjectAfterSync();
if (!cleanProjectAfterSync) {
// Figure out if the plugin version changed. If it did, force a clean.
// See: https://code.google.com/p/android/issues/detail?id=216616
Map<String, GradleVersion> previousPluginVersionsPerModule = getPluginVersionsPerModule(myProject);
storePluginVersionsPerModule(myProject);
if (previousPluginVersionsPerModule != null && !previousPluginVersionsPerModule.isEmpty()) {
Map<String, GradleVersion> currentPluginVersionsPerModule = getPluginVersionsPerModule(myProject);
assert currentPluginVersionsPerModule != null;
for (Map.Entry<String, GradleVersion> entry : currentPluginVersionsPerModule.entrySet()) {
String modulePath = entry.getKey();
GradleVersion previous = previousPluginVersionsPerModule.get(modulePath);
if (previous == null || entry.getValue().compareTo(previous) != 0) {
cleanProjectAfterSync = true;
break;
}
}
}
}
myProjectBuilder.generateSourcesOnly(cleanProjectAfterSync);
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class ForcedPluginPreviewVersionUpgradeStep method checkAndPerformUpgrade.
@Override
public boolean checkAndPerformUpgrade(@NotNull Project project, @NotNull AndroidPluginInfo pluginInfo) {
AndroidPluginGeneration pluginGeneration = pluginInfo.getPluginGeneration();
GradleVersion recommended = GradleVersion.parse(pluginGeneration.getLatestKnownVersion());
if (!shouldPreviewBeForcedToUpgradePluginVersion(recommended.toString(), pluginInfo.getPluginVersion())) {
return false;
}
GradleSyncState syncState = GradleSyncState.getInstance(project);
// Update the sync state before starting a new one.
syncState.syncEnded();
boolean userAcceptsForcedUpgrade = new ForcedPluginPreviewVersionUpgradeDialog(project, pluginInfo).showAndGet();
if (userAcceptsForcedUpgrade) {
AndroidPluginVersionUpdater versionUpdater = AndroidPluginVersionUpdater.getInstance(project);
versionUpdater.updatePluginVersionAndSync(recommended, GradleVersion.parse(GRADLE_LATEST_VERSION), true);
} else {
String[] text = { "The project is using an incompatible version of the " + pluginGeneration.getDescription() + ".", "Please update your project to use version " + pluginGeneration.getLatestKnownVersion() + "." };
SyncMessage msg = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, text);
String pluginName = AndroidPluginGeneration.getGroupId() + GRADLE_PATH_SEPARATOR + pluginGeneration.getArtifactId();
NotificationHyperlink quickFix = new SearchInBuildFilesHyperlink(pluginName);
msg.add(quickFix);
SyncMessages.getInstance(project).report(msg);
syncState.invalidateLastSync("Force plugin upgrade declined");
}
return true;
}
Aggregations