Search in sources :

Example 1 with FixAndroidGradlePluginVersionHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink in project android by JetBrains.

the class AndroidGradlePluginVersionReader method getQuickFixes.

@Override
@NotNull
public List<NotificationHyperlink> getQuickFixes(@NotNull Module module, @Nullable VersionRange expectedVersion, @Nullable PositionInFile location) {
    AndroidPluginInfo pluginInfo = AndroidPluginInfo.find(module.getProject());
    if (isSupportedGeneration(pluginInfo)) {
        String version = pluginInfo.getPluginGeneration().getLatestKnownVersion();
        List<NotificationHyperlink> quickFixes = new ArrayList<>();
        quickFixes.add(new FixAndroidGradlePluginVersionHyperlink(GradleVersion.parse(version), GradleVersion.parse(GRADLE_LATEST_VERSION)));
        quickFixes.add(new OpenUrlHyperlink("https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle", "Open Documentation"));
        return quickFixes;
    }
    return emptyList();
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ArrayList(java.util.ArrayList) OpenUrlHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FixAndroidGradlePluginVersionHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink in project android by JetBrains.

the class GradleVersionReaderTest method testGetQuickFixes.

public void testGetQuickFixes() throws Exception {
    loadSimpleApplication();
    Module appModule = myModules.getAppModule();
    List<NotificationHyperlink> quickFixes = myVersionReader.getQuickFixes(appModule, null, null);
    assertThat(quickFixes).hasSize(2);
    NotificationHyperlink quickFix = quickFixes.get(0);
    assertThat(quickFix).isInstanceOf(FixAndroidGradlePluginVersionHyperlink.class);
    FixAndroidGradlePluginVersionHyperlink fixAndroidGradlePluginQuickFix = (FixAndroidGradlePluginVersionHyperlink) quickFix;
    assertEquals(BuildEnvironment.getInstance().getGradlePluginVersion(), fixAndroidGradlePluginQuickFix.getPluginVersion().toString());
    GradleVersion gradleVersion = fixAndroidGradlePluginQuickFix.getGradleVersion();
    assertNotNull(gradleVersion);
    assertEquals(GRADLE_LATEST_VERSION, gradleVersion.toString());
    quickFix = quickFixes.get(1);
    assertThat(quickFix).isInstanceOf(OpenUrlHyperlink.class);
    OpenUrlHyperlink openUrlQuickFix = (OpenUrlHyperlink) quickFix;
    assertEquals("https://developer.android.com/studio/releases/index.html#Revisions", openUrlQuickFix.getUrl());
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) OpenUrlHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 3 with FixAndroidGradlePluginVersionHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink in project android by JetBrains.

the class AndroidGradleExperimentalPluginVersionReaderTest method testGetQuickFixesWithExperimentalPlugin.

public void testGetQuickFixesWithExperimentalPlugin() throws Exception {
    loadProject(EXPERIMENTAL_PLUGIN);
    Module appModule = myModules.getAppModule();
    List<NotificationHyperlink> quickFixes = myVersionReader.getQuickFixes(appModule, VersionRange.parse("[0.7.0, +)"), null);
    assertThat(quickFixes).hasSize(2);
    NotificationHyperlink quickFix = quickFixes.get(0);
    assertThat(quickFix).isInstanceOf(FixAndroidGradlePluginVersionHyperlink.class);
    FixAndroidGradlePluginVersionHyperlink fixAndroidGradlePluginQuickFix = (FixAndroidGradlePluginVersionHyperlink) quickFix;
    assertEquals(BuildEnvironment.getInstance().getExperimentalPluginVersion(), fixAndroidGradlePluginQuickFix.getPluginVersion().toString());
    quickFix = quickFixes.get(1);
    assertThat(quickFix).isInstanceOf(OpenUrlHyperlink.class);
    OpenUrlHyperlink openUrlQuickFix = (OpenUrlHyperlink) quickFix;
    assertEquals("https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle", openUrlQuickFix.getUrl());
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) OpenUrlHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink) Module(com.intellij.openapi.module.Module) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 4 with FixAndroidGradlePluginVersionHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink 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 5 with FixAndroidGradlePluginVersionHyperlink

use of com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink in project android by JetBrains.

the class LayoutRenderingIssueValidationStrategy method fixAndReportFoundIssues.

@Override
void fixAndReportFoundIssues() {
    if (myModelVersion != null) {
        String text = String.format("Using an obsolete version of the Gradle plugin (%1$s);", myModelVersion);
        text += " this can lead to layouts not rendering correctly.";
        SyncMessage message = new SyncMessage(DEFAULT_GROUP, WARNING, text);
        message.add(Arrays.asList(new FixAndroidGradlePluginVersionHyperlink(), new OpenUrlHyperlink("https://code.google.com/p/android/issues/detail?id=170841", "More Info...")));
        SyncMessages.getInstance(getProject()).report(message);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) OpenUrlHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink)

Aggregations

FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)10 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)8 OpenUrlHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.OpenUrlHyperlink)6 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)4 GradleVersion (com.android.ide.common.repository.GradleVersion)3 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)3 Module (com.intellij.openapi.module.Module)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 OpenFileHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)1 HtmlBuilder (com.android.utils.HtmlBuilder)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1