Search in sources :

Example 46 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class UniquePathModuleValidatorStrategyTest method testFixAndReportFoundIssues.

public void testFixAndReportFoundIssues() throws Exception {
    Project project = getProject();
    SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(project);
    ProjectSubset projectSubset = IdeComponents.replaceServiceWithMock(project, ProjectSubset.class);
    when(projectSubset.isFeatureEnabled()).thenReturn(false);
    Multimap<String, Module> modulesByPath = myStrategy.getModulesByPath();
    modulesByPath.putAll("path", Lists.newArrayList(myModule1, myModule2));
    when(myModule1.getName()).thenReturn("module1");
    when(myModule2.getName()).thenReturn("module2");
    myStrategy.fixAndReportFoundIssues();
    SyncMessage message = syncMessages.getFirstReportedMessage();
    assertNotNull(message);
    assertAbout(syncMessage()).that(message).hasMessageLine("The modules ['module1', 'module2'] point to same directory in the file system.", 0);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) Module(com.intellij.openapi.module.Module)

Example 47 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class JdkModuleSetupStepTest method testSetUpInAndroidStudio.

public void testSetUpInAndroidStudio() throws Exception {
    loadSimpleApplication();
    Module appModule = myModules.getAppModule();
    AndroidModuleModel androidModel = AndroidModuleModel.get(appModule);
    assertNotNull(androidModel);
    Sdk jdk = mock(Sdk.class);
    when(myIdeSdks.getJdk()).thenReturn(jdk);
    when(myJdks.isApplicableJdk(jdk, JDK_1_7)).thenReturn(false);
    SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(getProject());
    mySetupStep.setUpInAndroidStudio(appModule, androidModel);
    SyncMessage message = syncMessages.getFirstReportedMessage();
    assertNotNull(message);
    String[] text = message.getText();
    assertThat(text).isNotEmpty();
    assertThat(text[0]).matches("compileSdkVersion (.*) requires compiling with JDK 7 or newer.");
    GradleSyncSummary summary = GradleSyncState.getInstance(getProject()).getSummary();
    assertTrue(summary.hasSyncErrors());
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GradleSyncSummary(com.android.tools.idea.gradle.project.sync.GradleSyncSummary) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 48 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class DependencySetupTest method WithUnresolvedDependencies.

// Fails in Bazel PSQ because of missing dependencies in the prebuilt Android SDK.
public void WithUnresolvedDependencies() throws Exception {
    loadSimpleApplication();
    File buildFilePath = getBuildFilePath("app");
    VirtualFile buildFile = findFileByIoFile(buildFilePath, true);
    assertNotNull(buildFile);
    boolean versionChanged = false;
    Project project = getProject();
    GradleBuildModel buildModel = GradleBuildModel.parseBuildFile(buildFile, project);
    for (ArtifactDependencyModel artifact : buildModel.dependencies().artifacts()) {
        if ("com.android.support".equals(artifact.group().value()) && "appcompat-v7".equals(artifact.name().value())) {
            artifact.setVersion("100.0.0");
            versionChanged = true;
            break;
        }
    }
    assertTrue(versionChanged);
    runWriteCommandAction(project, buildModel::applyChanges);
    LocalFileSystem.getInstance().refresh(false);
    SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(project);
    requestSyncAndWait();
    SyncMessage reportedMessage = syncMessages.getFirstReportedMessage();
    assertNotNull(reportedMessage);
    String[] text = reportedMessage.getText();
    assertThat(text).isNotEmpty();
    assertEquals("Failed to resolve: com.android.support:appcompat-v7:100.0.0", text[0]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) GradleUtil.getAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File)

Example 49 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class ExternalNdkBuildIssuesReporterTest method testReportWithWarning.

public void testReportWithWarning() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    Module appModule = myModules.getAppModule();
    String nativeToolOutput = "Failed to compile something";
    when(mySyncIssue.getData()).thenReturn(nativeToolOutput);
    VirtualFile buildFile = getGradleBuildFile(appModule);
    assertNotNull(buildFile);
    int line = 6;
    int column = 8;
    SourcePosition sourcePosition = new SourcePosition(line, column, 0);
    SourceFilePosition sourceFilePosition = new SourceFilePosition(virtualToIoFile(buildFile), sourcePosition);
    Message compilerMessage = new Message(WARNING, nativeToolOutput, sourceFilePosition);
    List<Message> compilerMessages = Lists.newArrayList(compilerMessage);
    when(myOutputParser.parseGradleOutput(nativeToolOutput)).thenReturn(compilerMessages);
    myReporter.report(mySyncIssue, appModule, buildFile);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    assertThat(message.getText()).hasLength(1);
    assertAbout(syncMessage()).that(message).hasMessageLine(nativeToolOutput, 0);
    PositionInFile position = message.getPosition();
    assertNotNull(position);
    assertEquals(buildFile, position.file);
    assertEquals(line, position.line);
    assertEquals(column, position.column);
    assertThat(message.getQuickFixes()).isEmpty();
    assertFalse(myErrorHandler.isInvoked());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) SyncMessageSubject.syncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessageSubject.syncMessage) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Message(com.android.ide.common.blame.Message) SourcePosition(com.android.ide.common.blame.SourcePosition) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) Module(com.intellij.openapi.module.Module)

Example 50 with SyncMessage

use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.

the class SyncIssuesReporterTest method testReportUsingDefaultStrategy.

public void testReportUsingDefaultStrategy() throws Exception {
    loadSimpleApplication();
    mySyncMessagesStub.clearReportedMessages();
    when(mySyncIssue.getType()).thenReturn(TYPE_GRADLE_TOO_OLD);
    when(mySyncIssue.getSeverity()).thenReturn(SEVERITY_ERROR);
    when(myStrategy2.getSupportedIssueType()).thenReturn(TYPE_UNRESOLVED_DEPENDENCY);
    SyncIssuesReporter reporter = new SyncIssuesReporter(myStrategy1, myStrategy2);
    Module appModule = myModules.getAppModule();
    VirtualFile buildFile = getGradleBuildFile(appModule);
    reporter.report(Lists.newArrayList(mySyncIssue), appModule);
    SyncMessage message = mySyncMessagesStub.getFirstReportedMessage();
    assertNotNull(message);
    verify(myStrategy1, never()).report(mySyncIssue, appModule, buildFile);
    verify(myStrategy2, never()).report(mySyncIssue, appModule, buildFile);
    assertTrue(GradleSyncState.getInstance(getProject()).getSummary().hasSyncErrors());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Module(com.intellij.openapi.module.Module)

Aggregations

SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)55 Module (com.intellij.openapi.module.Module)18 Project (com.intellij.openapi.project.Project)14 SyncMessagesStub (com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub)12 NotificationHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)11 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 AndroidProject (com.android.builder.model.AndroidProject)5 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)5 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 GradleVersion (com.android.ide.common.repository.GradleVersion)3 ProjectSubset (com.android.tools.idea.gradle.project.subset.ProjectSubset)3 ComponentVersionReader (com.android.tools.idea.gradle.project.sync.compatibility.version.ComponentVersionReader)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Message (com.android.ide.common.blame.Message)2 AndroidVersion (com.android.sdklib.AndroidVersion)2 AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2