use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.
the class ProjectJdkSetupStep method doSetUpProject.
@VisibleForTesting
void doSetUpProject(@NotNull Project project, boolean androidStudio) {
LanguageLevel javaLangVersion = JDK_1_8;
Sdk projectJdk = ProjectRootManager.getInstance(project).getProjectSdk();
Sdk ideJdk = projectJdk;
if (androidStudio) {
ideJdk = myIdeSdks.getJdk();
} else if (projectJdk == null || !myJdks.isApplicableJdk(projectJdk, javaLangVersion)) {
ideJdk = myJdks.chooseOrCreateJavaSdk(javaLangVersion);
} else if (ApplicationManager.getApplication().isUnitTestMode()) {
// Let tests have a JDK when being executed inside the IDE, or when tests are executed as IDEA.
ideJdk = projectJdk;
}
if (ideJdk == null) {
SyncMessage message = new SyncMessage(DEFAULT_GROUP, ERROR, "Unable to find a JDK");
message.add(myJdks.getWrongJdkQuickFixes(project));
SyncMessages.getInstance(project).report(message);
GradleSyncState.getInstance(project).getSummary().setSyncErrorsFound(true);
return;
}
String homePath = ideJdk.getHomePath();
if (homePath != null) {
myJdks.setJdk(project, ideJdk);
PostProjectBuildTasksExecutor.getInstance(project).updateJavaLangLevelAfterBuild();
}
}
use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.
the class DependencySetupErrors method reportErrors.
public void reportErrors() {
reportModulesNotFoundIssues(getMissingModules());
for (String dependent : getMissingNames()) {
String msg = String.format("Module '%1$s' depends on modules that do not have a name.", dependent);
mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, ERROR, msg));
}
for (String dependent : getDependentsOnLibrariesWithoutBinaryPath()) {
String msg = String.format("Module '%1$s' depends on libraries that do not have a 'binary' path.", dependent);
mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, ERROR, msg));
}
for (DependencySetupErrors.InvalidModuleDependency dependency : myInvalidModuleDependencies) {
String msg = String.format("Ignoring dependency of module '%1$s' on module '%2$s'. %3$s", dependency.dependent, dependency.dependency.getName(), dependency.causeDescription);
VirtualFile buildFile = getGradleBuildFile(dependency.dependency);
assert buildFile != null;
OpenFileDescriptor navigatable = new OpenFileDescriptor(dependency.dependency.getProject(), buildFile, 0);
mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, WARNING, navigatable, msg));
}
reportModulesNotFoundIssues(getMissingModulesWithBackupLibraries());
clear();
}
use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.
the class DependencySetupErrors method reportModulesNotFoundIssues.
private void reportModulesNotFoundIssues(@NotNull List<MissingModule> missingModules) {
if (!missingModules.isEmpty()) {
MessageType type = ERROR;
for (MissingModule missingModule : missingModules) {
List<String> messageLines = new ArrayList<>();
StringBuilder text = new StringBuilder();
text.append(String.format("Unable to find module with Gradle path '%1$s' (needed by module", missingModule.dependencyPath));
addDependentsToText(text, missingModule.dependentNames);
text.append(".)");
messageLines.add(text.toString());
String backupLibraryName = missingModule.backupLibraryName;
if (isNotEmpty(backupLibraryName)) {
type = WARNING;
String msg = String.format("Linking to library '%1$s' instead.", backupLibraryName);
messageLines.add(msg);
}
mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, type, toStringArray(messageLines)));
}
// If the project is really a subset of the project, attempt to find and include missing modules.
ProjectSubset projectSubset = ProjectSubset.getInstance(myProject);
String[] selection = projectSubset.getSelection();
boolean hasSelection = selection != null && selection.length > 0;
if (type == ERROR && hasSelection && projectSubset.hasCachedModules()) {
String text = "The missing modules may have been excluded from the project subset.";
SyncMessage message = new SyncMessage(MISSING_DEPENDENCIES, MessageType.INFO, text);
message.add(new IncludeMissingModulesHyperlink(missingModules));
mySyncMessages.report(message);
}
}
}
use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.
the class DependencySetupErrorsTest method testReportErrors.
public void testReportErrors() {
myErrors.addMissingModule(":lib1", "app1", null);
myErrors.addMissingModule(":lib2", "app2", "library2.jar");
myErrors.addMissingModule(":lib2", "app1", "library2.jar");
myErrors.addMissingModule(":lib3", "app1", "library3.jar");
myErrors.addMissingName("app2");
myErrors.addMissingName("app1");
myErrors.addMissingBinaryPath("app2");
myErrors.addMissingBinaryPath("app1");
myErrors.reportErrors();
List<SyncMessage> messages = mySyncMessages.getReportedMessages();
assertThat(messages).hasSize(7);
SyncMessage message = messages.get(0);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Unable to find module with Gradle path ':lib1' (needed by module 'app1'.)", 0);
// @formatter:on
message = messages.get(1);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app1' depends on modules that do not have a name.", 0);
// @formatter:on
message = messages.get(2);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app2' depends on modules that do not have a name.", 0);
// @formatter:on
message = messages.get(3);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app1' depends on libraries that do not have a 'binary' path.", 0);
// @formatter:on
message = messages.get(4);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(ERROR).hasMessageLine("Module 'app2' depends on libraries that do not have a 'binary' path.", 0);
// @formatter:on
message = messages.get(5);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(WARNING).hasMessageLine("Unable to find module with Gradle path ':lib2' (needed by modules: 'app1', 'app2'.)", 0).hasMessageLine("Linking to library 'library2.jar' instead.", 1);
// @formatter:on
message = messages.get(6);
// @formatter:off
assertAbout(syncMessage()).that(message).hasGroup("Missing Dependencies").hasType(WARNING).hasMessageLine("Unable to find module with Gradle path ':lib3' (needed by module 'app1'.)", 0).hasMessageLine("Linking to library 'library3.jar' instead.", 1);
// @formatter:on
}
use of com.android.tools.idea.gradle.project.sync.messages.SyncMessage in project android by JetBrains.
the class ForcedPluginPreviewVersionUpgradeStep method checkAndPerformUpgrade.
@Override
public boolean checkAndPerformUpgrade(@NotNull Project project, @NotNull AndroidPluginInfo pluginInfo) {
AndroidPluginGeneration pluginGeneration = pluginInfo.getPluginGeneration();
GradleVersion recommended = GradleVersion.parse(pluginGeneration.getLatestKnownVersion());
if (!shouldPreviewBeForcedToUpgradePluginVersion(recommended.toString(), pluginInfo.getPluginVersion())) {
return false;
}
GradleSyncState syncState = GradleSyncState.getInstance(project);
// Update the sync state before starting a new one.
syncState.syncEnded();
boolean userAcceptsForcedUpgrade = new ForcedPluginPreviewVersionUpgradeDialog(project, pluginInfo).showAndGet();
if (userAcceptsForcedUpgrade) {
AndroidPluginVersionUpdater versionUpdater = AndroidPluginVersionUpdater.getInstance(project);
versionUpdater.updatePluginVersionAndSync(recommended, GradleVersion.parse(GRADLE_LATEST_VERSION), true);
} else {
String[] text = { "The project is using an incompatible version of the " + pluginGeneration.getDescription() + ".", "Please update your project to use version " + pluginGeneration.getLatestKnownVersion() + "." };
SyncMessage msg = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, text);
String pluginName = AndroidPluginGeneration.getGroupId() + GRADLE_PATH_SEPARATOR + pluginGeneration.getArtifactId();
NotificationHyperlink quickFix = new SearchInBuildFilesHyperlink(pluginName);
msg.add(quickFix);
SyncMessages.getInstance(project).report(msg);
syncState.invalidateLastSync("Force plugin upgrade declined");
}
return true;
}
Aggregations