Search in sources :

Example 6 with GradleSyncState

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;
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) SearchInBuildFilesHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.SearchInBuildFilesHyperlink) GradleVersion(com.android.ide.common.repository.GradleVersion) AndroidPluginGeneration(com.android.tools.idea.gradle.plugin.AndroidPluginGeneration) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 7 with GradleSyncState

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);
    }
}
Also used : GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState)

Example 8 with GradleSyncState

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;
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) Projects.isGradleProjectModule(com.android.tools.idea.gradle.util.Projects.isGradleProjectModule) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) VisibleForTesting(com.android.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with GradleSyncState

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());
}
Also used : Project(com.intellij.openapi.project.Project) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState)

Example 10 with GradleSyncState

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());
}
Also used : Project(com.intellij.openapi.project.Project) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState)

Aggregations

GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)15 Project (com.intellij.openapi.project.Project)6 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)2 GradleSyncSummary (com.android.tools.idea.gradle.project.sync.GradleSyncSummary)2 Module (com.intellij.openapi.module.Module)2 NotNull (org.jetbrains.annotations.NotNull)2 SdkConstants (com.android.SdkConstants)1 VisibleForTesting (com.android.annotations.VisibleForTesting)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 AndroidProject (com.android.builder.model.AndroidProject)1 Message (com.android.ide.common.blame.Message)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 ApkProjects.isApkProject (com.android.tools.idea.apk.ApkProjects.isApkProject)1 AndroidPluginGeneration (com.android.tools.idea.gradle.plugin.AndroidPluginGeneration)1 AndroidPluginVersionUpdater (com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater)1 AndroidGradleBuildConfiguration (com.android.tools.idea.gradle.project.build.compiler.AndroidGradleBuildConfiguration)1 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)1