use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class BuildSignedApkTest method mustHaveAtLeastV1OrV2Sign.
@Test
public void mustHaveAtLeastV1OrV2Sign() 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(false).setV2SignatureEnabled(false).clickFinishAndDismissErrorDialog().setV1SignatureEnabled(true).clickFinish();
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class BuildSignedApkTest method openAndSignUsingV2Only.
@Test
public void openAndSignUsingV2Only() 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(false).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")).isNull();
}
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class VersionRange method contains.
public boolean contains(@NotNull String value) {
if (myParsedMinVersion != null) {
boolean contains = false;
GradleVersion version = GradleVersion.tryParse(value);
if (version != null) {
if (myMinVersionInclusive) {
contains = version.compareIgnoringQualifiers(myParsedMinVersion) >= 0;
} else {
contains = version.compareIgnoringQualifiers(myParsedMinVersion) > 0;
}
if (contains && myParsedMaxVersion != null) {
if (myMaxVersionInclusive) {
contains = version.compareIgnoringQualifiers(myParsedMaxVersion) <= 0;
} else {
contains = version.compareIgnoringQualifiers(myParsedMaxVersion) < 0;
}
}
}
return contains;
}
return value.equals(myMinVersion) || value.equals(myMaxVersion);
}
use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.
the class GradleDistributionCleanUpTask method createWrapperIfNecessary.
private boolean createWrapperIfNecessary(@NotNull Project project, @NotNull GradleProjectSettings gradleSettings, @Nullable DistributionType distributionType) {
boolean createWrapper = false;
boolean chooseLocalGradleHome = false;
if (distributionType == null) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return true;
}
String msg = createUseWrapperQuestion("Gradle settings for this project are not configured yet.");
int answer = showOkCancelDialog(project, msg, GRADLE_SYNC_MSG_TITLE, getQuestionIcon());
createWrapper = answer == OK;
} else if (distributionType == DEFAULT_WRAPPED) {
createWrapper = true;
} else if (distributionType == LOCAL) {
String gradleHome = gradleSettings.getGradleHome();
String msg = null;
if (isEmpty(gradleHome)) {
msg = createUseWrapperQuestion("The path of the local Gradle distribution to use is not set.");
} else {
File gradleHomePath = new File(toSystemDependentName(gradleHome));
if (!gradleHomePath.isDirectory()) {
String reason = String.format("The path\n'%1$s'\n, set as a local Gradle distribution, does not belong to an existing directory.", gradleHomePath.getPath());
msg = createUseWrapperQuestion(reason);
} else {
GradleVersion gradleVersion = GradleVersions.getInstance().getGradleVersion(gradleHomePath);
if (gradleVersion == null) {
String reason = String.format("The path\n'%1$s'\n, does not belong to a Gradle distribution.", gradleHomePath.getPath());
msg = createUseWrapperQuestion(reason);
} else if (!isSupportedGradleVersion(gradleVersion)) {
String reason = String.format("Gradle version %1$s is not supported.", gradleHomePath.getPath());
msg = createUseWrapperQuestion(reason);
}
}
}
if (msg != null) {
int answer = showOkCancelDialog(project, msg, GRADLE_SYNC_MSG_TITLE, getQuestionIcon());
createWrapper = answer == OK;
chooseLocalGradleHome = !createWrapper;
}
}
if (createWrapper) {
File projectPath = getBaseDirPath(project);
// attempt to delete the whole gradle wrapper folder.
File gradleDirPath = new File(projectPath, SdkConstants.FD_GRADLE);
if (!delete(gradleDirPath)) {
// deletion failed. Let sync continue.
return true;
}
try {
GradleWrapper.create(projectPath);
if (distributionType == null) {
gradleSettings.setDistributionType(DEFAULT_WRAPPED);
}
return true;
} catch (IOException e) {
Logger.getInstance(getClass()).info("Failed to create Gradle wrapper for project '" + project.getName() + "'", e);
}
} else if (distributionType == null || chooseLocalGradleHome) {
ChooseGradleHomeDialog dialog = new ChooseGradleHomeDialog();
if (dialog.showAndGet()) {
String enteredGradleHomePath = dialog.getEnteredGradleHomePath();
gradleSettings.setGradleHome(enteredGradleHomePath);
gradleSettings.setDistributionType(LOCAL);
return true;
}
}
return false;
}
use of com.android.ide.common.repository.GradleVersion 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