use of com.android.tools.idea.gradle.project.sync.GradleSyncState 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;
}
use of com.android.tools.idea.gradle.project.sync.GradleSyncState in project android by JetBrains.
the class AndroidGradleProjectComponent method projectOpened.
/**
* This method is called when a project is created and when it is opened.
*/
@Override
public void projectOpened() {
checkForSupportedModules();
GradleSyncState syncState = GradleSyncState.getInstance(myProject);
if (syncState.isSyncInProgress()) {
// when opening a new project, the UI was not updated when sync started. Updating UI ("Build Variants" tool window, "Sync" toolbar
// button and editor notifications.
syncState.notifyStateChanged();
}
if (IdeInfo.getInstance().isAndroidStudio() && isLegacyIdeaAndroidProject(myProject) && !isApkProject(myProject)) {
trackLegacyIdeaAndroidProject();
if (shouldShowMigrateToGradleNotification()) {
// Suggest that Android Studio users use Gradle instead of IDEA project builder.
showMigrateToGradleWarning();
}
return;
}
boolean isGradleProject = isBuildWithGradle(myProject);
if (isGradleProject) {
configureGradleProject();
} else if (IdeInfo.getInstance().isAndroidStudio() && myProject.getBaseDir() != null && canImportAsGradleProject(myProject.getBaseDir())) {
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(myProject, null);
}
}
use of com.android.tools.idea.gradle.project.sync.GradleSyncState in project android by JetBrains.
the class GradleProjectSyncData method createFrom.
@Nullable
@VisibleForTesting
static GradleProjectSyncData createFrom(@NotNull Project project) throws IOException {
GradleProjectSyncData data = new GradleProjectSyncData();
File rootDirPath = getBaseDirPath(project);
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null) {
GradleModuleModel gradleModuleModel = gradleFacet.getGradleModuleModel();
if (gradleModuleModel != null) {
data.addFileChecksum(rootDirPath, gradleModuleModel.getBuildFile());
} else {
LOG.warn(String.format("Trying to create project data from a not initialized project '%1$s'. Abort.", project.getName()));
return null;
}
}
if (isGradleProjectModule(module)) {
data.addFileChecksum(rootDirPath, getGradleBuildFile(module));
data.addFileChecksum(rootDirPath, getGradleSettingsFile(rootDirPath));
data.addFileChecksum(rootDirPath, new File(rootDirPath, FN_GRADLE_PROPERTIES));
data.addFileChecksum(rootDirPath, new File(rootDirPath, FN_LOCAL_PROPERTIES));
data.addFileChecksum(rootDirPath, getGradleUserSettingsFile());
}
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
for (File externalBuildFile : ndkModuleModel.getAndroidProject().getBuildFiles()) {
data.addFileChecksum(rootDirPath, externalBuildFile);
}
}
}
GradleSyncState syncState = GradleSyncState.getInstance(project);
data.myLastGradleSyncTimestamp = syncState.getSummary().getSyncTimestamp();
return data;
}
use of com.android.tools.idea.gradle.project.sync.GradleSyncState in project android by JetBrains.
the class SyncProjectActionTest method testDoUpdateWithSyncInProgress.
public void testDoUpdateWithSyncInProgress() {
Project project = getProject();
GradleSyncState syncState = IdeComponents.replaceServiceWithMock(project, GradleSyncState.class);
when(syncState.isSyncInProgress()).thenReturn(true);
myAction.doUpdate(myEvent, project);
assertFalse(myPresentation.isEnabled());
}
use of com.android.tools.idea.gradle.project.sync.GradleSyncState in project android by JetBrains.
the class SyncProjectActionTest method testDoUpdateWithSyncNotInProgress.
public void testDoUpdateWithSyncNotInProgress() {
Project project = getProject();
GradleSyncState syncState = IdeComponents.replaceServiceWithMock(project, GradleSyncState.class);
when(syncState.isSyncInProgress()).thenReturn(false);
myAction.doUpdate(myEvent, project);
assertTrue(myPresentation.isEnabled());
}
Aggregations