Search in sources :

Example 1 with OpenFileHyperlink

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

the class JdkModuleSetupStep method reportWrongJdkError.

@NotNull
private SyncMessage reportWrongJdkError(@NotNull Project project, @NotNull String text, @NotNull VirtualFile buildFile) {
    int line = -1;
    int column = -1;
    Document document = FileDocumentManager.getInstance().getDocument(buildFile);
    if (document != null) {
        int offset = myCompileSdkVersionFinder.findOffsetIn(document.getText());
        if (offset > -1) {
            line = document.getLineNumber(offset);
            if (line > -1) {
                int lineStartOffset = document.getLineStartOffset(line);
                column = offset - lineStartOffset;
            }
        }
    }
    PositionInFile position = new PositionInFile(buildFile, line, column);
    SyncMessage msg = new SyncMessage(project, PROJECT_CONFIGURATION_SYNC_MESSAGE_GROUP, ERROR, position, text);
    List<NotificationHyperlink> quickFixes = Lists.newArrayList(myJdks.getWrongJdkQuickFixes(project));
    quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), "Open build.gradle File", line, column));
    msg.add(quickFixes);
    return msg;
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) Document(com.intellij.openapi.editor.Document) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with OpenFileHyperlink

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

the class GenericErrorHandler method getQuickFixHyperlinks.

@NotNull
private List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull String text) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    List<String> message = Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text);
    String lastLine = message.get(message.size() - 1);
    if (lastLine != null) {
        Pair<String, Integer> errorLocation = getErrorLocation(lastLine);
        if (errorLocation != null) {
            String filePath = errorLocation.getFirst();
            int line = errorLocation.getSecond();
            hyperlinks.add(new OpenFileHyperlink(filePath, line - 1));
            return hyperlinks;
        }
    }
    // Error messages may contain a file path and line number, but we need to add a hyperlink to open the file at those coordinates.
    String filePath = notification.getFilePath();
    if (isNotEmpty(filePath)) {
        // lines are zero based.
        int lineIndex = notification.getLine() - 1;
        int column = notification.getColumn();
        hyperlinks.add(new OpenFileHyperlink(filePath, "Open File", lineIndex, column));
    }
    return hyperlinks;
}
Also used : ArrayList(java.util.ArrayList) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with OpenFileHyperlink

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

the class GradleDslMethodNotFoundErrorHandlerTest method testHandleErrorWithMethodNotFoundInSettingsFile.

public void testHandleErrorWithMethodNotFoundInSettingsFile() throws Exception {
    loadSimpleApplication();
    File settingsFile = new File(getBaseDirPath(getProject()), FN_SETTINGS_GRADLE);
    assertAbout(file()).that(settingsFile).isFile();
    writeToFile(settingsFile, "incude ':app'");
    requestSyncAndGetExpectedFailure();
    SyncMessagesStub.NotificationUpdate notificationUpdate = mySyncMessagesStub.getNotificationUpdate();
    assertNotNull(notificationUpdate);
    assertThat(notificationUpdate.getText()).contains("Gradle DSL method not found: 'incude()'");
    // Verify hyperlinks are correct.
    List<NotificationHyperlink> quickFixes = notificationUpdate.getFixes();
    assertThat(quickFixes).hasSize(1);
    NotificationHyperlink quickFix = quickFixes.get(0);
    assertThat(quickFix).isInstanceOf(OpenFileHyperlink.class);
    // Ensure the error message contains the location of the error.
    OpenFileHyperlink openFileQuickFix = (OpenFileHyperlink) quickFix;
    assertEquals(settingsFile.getPath(), openFileQuickFix.getFilePath());
    assertEquals(0, openFileQuickFix.getLineNumber());
}
Also used : SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) FileUtil.loadFile(com.intellij.openapi.util.io.FileUtil.loadFile) FileUtil.writeToFile(com.intellij.openapi.util.io.FileUtil.writeToFile) File(java.io.File) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 4 with OpenFileHyperlink

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

the class OldAndroidPluginErrorHandler method getQuickFixHyperlinks.

@Override
@NotNull
protected List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    hyperlinks.add(new FixAndroidGradlePluginVersionHyperlink());
    AndroidPluginInfo result = searchInBuildFilesOnly(project);
    if (result != null && result.getPluginBuildFile() != null) {
        hyperlinks.add(new OpenFileHyperlink(result.getPluginBuildFile().getPath()));
    }
    return hyperlinks;
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ArrayList(java.util.ArrayList) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with OpenFileHyperlink

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

the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.

@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    boolean buildToolInstalled = false;
    AndroidSdkHandler sdkHandler = null;
    AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (androidSdkData != null) {
        sdkHandler = androidSdkData.getSdkHandler();
    }
    if (sdkHandler != null) {
        ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
        RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
        LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
        buildToolInstalled = buildTool != null;
    }
    if (module != null) {
        VirtualFile buildFile = getGradleBuildFile(module);
        AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
        if (!buildToolInstalled) {
            if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
            } else {
                hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
            }
        } else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
            hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
        }
        if (buildFile != null) {
            hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
        }
    }
    return hyperlinks;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalPackage(com.android.repository.api.LocalPackage) FixBuildToolsVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixBuildToolsVersionHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) InstallBuildToolsHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallBuildToolsHyperlink) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) OpenFileHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)8 OpenFileHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.OpenFileHyperlink)8 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)5 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 LocalPackage (com.android.repository.api.LocalPackage)1 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)1 FixBuildToolsVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixBuildToolsVersionHyperlink)1 InstallBuildToolsHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.InstallBuildToolsHyperlink)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 SyncMessagesStub (com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub)1 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 Document (com.intellij.openapi.editor.Document)1 FileUtil.loadFile (com.intellij.openapi.util.io.FileUtil.loadFile)1