Search in sources :

Example 6 with GradleVersion

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();
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 7 with GradleVersion

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();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 8 with GradleVersion

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);
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 9 with GradleVersion

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;
}
Also used : ChooseGradleHomeDialog(com.android.tools.idea.gradle.project.ChooseGradleHomeDialog) IOException(java.io.IOException) GradleVersion(com.android.ide.common.repository.GradleVersion) GradleUtil.isSupportedGradleVersion(com.android.tools.idea.gradle.util.GradleUtil.isSupportedGradleVersion) File(java.io.File)

Example 10 with GradleVersion

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;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) Revision(com.android.repository.Revision) LintClient(com.android.tools.lint.client.api.LintClient) LintIdeClient(com.android.tools.idea.lint.LintIdeClient) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleVersion (com.android.ide.common.repository.GradleVersion)77 File (java.io.File)25 Test (org.junit.Test)16 Module (com.intellij.openapi.module.Module)12 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)11 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)5 IOException (java.io.IOException)5 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)4 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)3 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)3 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)3 ZipFile (java.util.zip.ZipFile)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 Variant (com.android.builder.model.Variant)2 IDevice (com.android.ddmlib.IDevice)2 Revision (com.android.repository.Revision)2 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2