Search in sources :

Example 51 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class RecommendedPluginVersionUpgradeStep method checkAndPerformUpgrade.

@Override
public boolean checkAndPerformUpgrade(@NotNull Project project, @NotNull AndroidPluginInfo pluginInfo) {
    if (shouldRecommendUpgrade(pluginInfo)) {
        GradleVersion current = pluginInfo.getPluginVersion();
        assert current != null;
        AndroidPluginGeneration pluginGeneration = pluginInfo.getPluginGeneration();
        GradleVersion recommended = GradleVersion.parse(pluginGeneration.getLatestKnownVersion());
        RecommendedPluginVersionUpdateDialog updateDialog = new RecommendedPluginVersionUpdateDialog(project, current, recommended);
        boolean userAcceptsUpgrade = updateDialog.showAndGet();
        if (userAcceptsUpgrade) {
            AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
            GradleVersion latestGradleVersion = GradleVersion.parse(GRADLE_LATEST_VERSION);
            AndroidPluginVersionUpdater.UpdateResult result = updater.updatePluginVersionAndSync(recommended, latestGradleVersion, false);
            if (result.versionUpdateSuccess()) {
                // plugin version updated and a project sync was requested. No need to continue.
                return true;
            }
        }
    }
    return false;
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion) AndroidPluginGeneration(com.android.tools.idea.gradle.plugin.AndroidPluginGeneration) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)

Example 52 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class GradleRenderErrorContributor method reportIssue170841.

private void reportIssue170841(RenderLogger logger, AndroidFacet facet) {
    Map<String, Throwable> brokenClasses = logger.getBrokenClasses();
    if (brokenClasses == null || brokenClasses.isEmpty() || facet == null) {
        return;
    }
    AndroidModuleModel model = AndroidModuleModel.get(facet);
    if (model == null || !model.getFeatures().isLayoutRenderingIssuePresent()) {
        return;
    }
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            FixAndroidGradlePluginVersionHyperlink quickFix = new FixAndroidGradlePluginVersionHyperlink(GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION), null);
            quickFix.executeIfClicked(facet.getModule().getProject(), new HyperlinkEvent(this, HyperlinkEvent.EventType.ACTIVATED, null, quickFix.getUrl()));
        }
    };
    HtmlBuilder builder = new HtmlBuilder();
    HtmlLinkManager linkManager = logger.getLinkManager();
    builder.add("Tip: Either ").addLink("update the Gradle plugin build version to 1.2.3", linkManager.createRunnableLink(runnable)).add(" or later, or downgrade to version 1.1.3, or as a workaround, ");
    builder.beginList().listItem().addLink("", "Build the project", ", then", linkManager.createBuildProjectUrl()).listItem().addLink("", "Gradle Sync the project", ", then", linkManager.createSyncProjectUrl()).listItem().addLink("Manually ", "refresh the layout", " (or restart the IDE)", linkManager.createRefreshRenderUrl()).endList();
    builder.newline();
    GradleVersion modelVersion = model.getModelVersion();
    addIssue().setSeverity(HighlightSeverity.ERROR).setSummary("Using an obsolete version of the Gradle plugin (" + modelVersion + "); " + "this can lead to layouts not rendering correctly.").setHtmlContent(builder).build();
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) HtmlBuilder(com.android.utils.HtmlBuilder) GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 53 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class RecommendedPluginVersionUpgradeStep method shouldRecommendUpgradeBasedOnPluginVersion.

private static boolean shouldRecommendUpgradeBasedOnPluginVersion(@NotNull AndroidPluginInfo androidPluginInfo) {
    GradleVersion current = androidPluginInfo.getPluginVersion();
    String recommended = androidPluginInfo.getPluginGeneration().getLatestKnownVersion();
    return current != null && current.compareTo(recommended) < 0;
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 54 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class BuildTools23Rc1ValidationStrategy method validate.

// Build Tools 23 only works with Android plugin 1.3 or newer. Verify that the project is using compatible Build Tools/Android plugin
// versions.
@Override
void validate(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    if (!isOneDotThreeOrNewer(androidModel.getAndroidProject())) {
        String version = myBuildToolsVersionReader.getBuildToolsVersion(module);
        if (version != null) {
            List<String> segments = Splitter.on(' ').omitEmptyStrings().splitToList(version);
            GradleVersion parsed = GradleVersion.parse(segments.get(0));
            if (parsed.getMajor() == 23 && parsed.getMinor() == 0 && parsed.getMicro() == 0) {
                String preview = "rc1";
                if (preview.equals(parsed.getPreviewType()) || (segments.size() > 1 && preview.equals(segments.get(1)))) {
                    myModules.add(module.getName());
                }
            }
        }
    }
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 55 with GradleVersion

use of com.android.ide.common.repository.GradleVersion in project android by JetBrains.

the class PluginVersionUpgrade method log.

private static void log(@NotNull AndroidPluginInfo pluginInfo) {
    GradleVersion current = pluginInfo.getPluginVersion();
    String recommended = pluginInfo.getPluginGeneration().getLatestKnownVersion();
    String message = String.format("Gradle model version: %1$s, recommended version for IDE: %2$s", current, recommended);
    getLog().info(message);
}
Also used : GradleVersion(com.android.ide.common.repository.GradleVersion)

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