Search in sources :

Example 1 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.

the class BaseGradleProjectResolverExtension method populateModuleDependencies.

@Override
public void populateModuleDependencies(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule, @NotNull final DataNode<ProjectData> ideProject) {
    ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
    if (externalProject != null) {
        final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap = ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS);
        final Map<String, String> artifactsMap = ideProject.getUserData(CONFIGURATION_ARTIFACTS);
        assert artifactsMap != null;
        if (resolverCtx.isResolveModulePerSourceSet()) {
            assert sourceSetMap != null;
            processSourceSets(resolverCtx, gradleModule, externalProject, ideModule, new SourceSetsProcessor() {

                @Override
                public void process(@NotNull DataNode<? extends ModuleData> dataNode, @NotNull ExternalSourceSet sourceSet) {
                    buildDependencies(resolverCtx, sourceSetMap, artifactsMap, dataNode, sourceSet.getDependencies(), ideProject);
                }
            });
            return;
        }
    }
    final List<? extends IdeaDependency> dependencies = gradleModule.getDependencies().getAll();
    if (dependencies == null)
        return;
    List<String> orphanModules = ContainerUtil.newArrayList();
    for (IdeaDependency dependency : dependencies) {
        if (dependency == null) {
            continue;
        }
        DependencyScope scope = parseScope(dependency.getScope());
        if (dependency instanceof IdeaModuleDependency) {
            ModuleDependencyData d = buildDependency(resolverCtx, ideModule, (IdeaModuleDependency) dependency, ideProject);
            d.setExported(dependency.getExported());
            if (scope != null) {
                d.setScope(scope);
            }
            ideModule.createChild(ProjectKeys.MODULE_DEPENDENCY, d);
            ModuleData targetModule = d.getTarget();
            if (targetModule.getId().isEmpty() && targetModule.getLinkedExternalProjectPath().isEmpty()) {
                orphanModules.add(targetModule.getExternalName());
            }
        } else if (dependency instanceof IdeaSingleEntryLibraryDependency) {
            LibraryDependencyData d = buildDependency(gradleModule, ideModule, (IdeaSingleEntryLibraryDependency) dependency, ideProject);
            d.setExported(dependency.getExported());
            if (scope != null) {
                d.setScope(scope);
            }
            ideModule.createChild(ProjectKeys.LIBRARY_DEPENDENCY, d);
        }
    }
    if (!orphanModules.isEmpty()) {
        ExternalSystemTaskId taskId = resolverCtx.getExternalSystemTaskId();
        Project project = taskId.findProject();
        if (project != null) {
            String msg = "Can't find the following module" + (orphanModules.size() > 1 ? "s" : "") + ": " + StringUtil.join(orphanModules, ", ") + "\nIt can be caused by composite build configuration inside your *.gradle scripts with Gradle version older than 3.3." + "\nTry Gradle 3.3 or better or enable 'Create separate module per source set' option";
            NotificationData notification = new NotificationData("Gradle project structure problems", msg, NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
            ExternalSystemNotificationManager.getInstance(project).showNotification(taskId.getProjectSystemId(), notification);
        }
    }
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) DependencyScope(com.intellij.openapi.roots.DependencyScope) GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) Project(com.intellij.openapi.project.Project) Pair(com.intellij.openapi.util.Pair) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 2 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.

the class GradleDependenciesImportingTest method assertCompileClasspathOrdering.

protected void assertCompileClasspathOrdering(String moduleName) {
    Module module = getModule(moduleName);
    String sourceSetName = getSourceSetName(module);
    assertNotNull("Can not find the sourceSet for the module", sourceSetName);
    ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
    settings.setExternalProjectPath(getExternalProjectPath(module));
    String id = getExternalProjectId(module);
    String gradlePath = id.startsWith(":") ? trimEnd(id, sourceSetName) : "";
    settings.setTaskNames(Collections.singletonList(gradlePath + ":print" + capitalize(sourceSetName) + "CompileDependencies"));
    settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
    settings.setScriptParameters("--quiet");
    ExternalSystemProgressNotificationManager notificationManager = ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
    StringBuilder gradleClasspath = new StringBuilder();
    ExternalSystemTaskNotificationListenerAdapter listener = new ExternalSystemTaskNotificationListenerAdapter() {

        @Override
        public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
            gradleClasspath.append(text);
        }
    };
    notificationManager.addNotificationListener(listener);
    ExternalSystemUtil.runTask(settings, DefaultRunExecutor.EXECUTOR_ID, myProject, GradleConstants.SYSTEM_ID, null, ProgressExecutionMode.NO_PROGRESS_SYNC);
    notificationManager.removeNotificationListener(listener);
    List<String> ideClasspath = ContainerUtil.newArrayList();
    ModuleRootManager.getInstance(module).orderEntries().withoutSdk().withoutModuleSourceEntries().compileOnly().productionOnly().forEach(entry -> {
        if (entry instanceof ModuleOrderEntry) {
            Module moduleDep = ((ModuleOrderEntry) entry).getModule();
            String sourceSetDepName = getSourceSetName(moduleDep);
            assert sourceSetDepName != "main";
            String gradleProjectDepName = trimStart(trimEnd(getExternalProjectId(moduleDep), ":main"), ":");
            String version = getExternalProjectVersion(moduleDep);
            version = "unspecified".equals(version) ? "" : "-" + version;
            ideClasspath.add(gradleProjectDepName + version + ".jar");
        } else {
            ideClasspath.add(entry.getFiles(OrderRootType.CLASSES)[0].getName());
        }
        return true;
    });
    assertEquals(join(ideClasspath, " "), gradleClasspath.toString().trim());
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) Module(com.intellij.openapi.module.Module) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemProgressNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 3 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project freeline by alibaba.

the class UpdateAction method updateAction.

/**
     * 更新操作
     *
     * @param newVersion
     * @param gradleBuildModels
     */
protected void updateAction(final String newVersion, final Map<GradleBuildModel, List<ArtifactDependencyModel>> gradleBuildModels) {
    CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    for (GradleBuildModel file : gradleBuildModels.keySet()) {
                        List<ArtifactDependencyModel> models = gradleBuildModels.get(file);
                        for (ArtifactDependencyModel dependencyModel1 : models) {
                            ArtifactDependencyModelWrapper dependencyModel = new ArtifactDependencyModelWrapper(dependencyModel1);
                            if (isClasspathLibrary(dependencyModel)) {
                                dependencyModel1.setVersion(newVersion);
                            }
                            if (isDependencyLibrary(dependencyModel)) {
                                file.dependencies().remove(dependencyModel1);
                            }
                        }
                        file.applyChanges();
                    }
                    GradleUtil.executeTask(currentProject, "initFreeline", "-Pmirror", new ExternalSystemTaskNotificationListenerAdapter() {

                        @Override
                        public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
                            super.onTaskOutput(id, text, stdOut);
                        }
                    });
                }
            });
        }
    });
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) ArtifactDependencyModelWrapper(com.antfortune.freeline.idea.models.ArtifactDependencyModelWrapper)

Example 4 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.

the class ExternalSystemResolveProjectTask method doExecute.

@SuppressWarnings("unchecked")
protected void doExecute() throws Exception {
    final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
    Project ideProject = getIdeProject();
    RemoteExternalSystemProjectResolver resolver = manager.getFacade(ideProject, myProjectPath, getExternalSystemId()).getResolver();
    ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(ideProject, myProjectPath, getExternalSystemId());
    if (StringUtil.isNotEmpty(myVmOptions)) {
        settings.withVmOptions(ParametersListUtil.parse(myVmOptions));
    }
    if (StringUtil.isNotEmpty(myArguments)) {
        settings.withArguments(ParametersListUtil.parse(myArguments));
    }
    ExternalSystemProgressNotificationManagerImpl progressNotificationManager = (ExternalSystemProgressNotificationManagerImpl) ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
    ExternalSystemTaskId id = getId();
    progressNotificationManager.onStart(id, myProjectPath);
    try {
        DataNode<ProjectData> project = resolver.resolveProjectInfo(id, myProjectPath, myIsPreviewMode, settings);
        if (project != null) {
            myExternalProject.set(project);
            ExternalSystemManager<?, ?, ?, ?, ?> systemManager = ExternalSystemApiUtil.getManager(getExternalSystemId());
            assert systemManager != null;
            Set<String> externalModulePaths = ContainerUtil.newHashSet();
            Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(project, ProjectKeys.MODULE);
            for (DataNode<ModuleData> node : moduleNodes) {
                externalModulePaths.add(node.getData().getLinkedExternalProjectPath());
            }
            String projectPath = project.getData().getLinkedExternalProjectPath();
            ExternalProjectSettings linkedProjectSettings = systemManager.getSettingsProvider().fun(ideProject).getLinkedProjectSettings(projectPath);
            if (linkedProjectSettings != null) {
                linkedProjectSettings.setModules(externalModulePaths);
            }
        }
        progressNotificationManager.onSuccess(id);
    } finally {
        progressNotificationManager.onEnd(id);
    }
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) ExternalSystemProgressNotificationManagerImpl(com.intellij.openapi.externalSystem.service.remote.ExternalSystemProgressNotificationManagerImpl) ExternalSystemFacadeManager(com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager) ExternalSystemProgressNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) Project(com.intellij.openapi.project.Project) RemoteExternalSystemProjectResolver(com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolver) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalSystemExecutionSettings(com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 5 with ExternalSystemTaskId

use of com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId in project intellij-community by JetBrains.

the class GradleTaskManager method executeTasks.

@Override
public void executeTasks(@NotNull final ExternalSystemTaskId id, @NotNull final List<String> taskNames, @NotNull String projectPath, @Nullable GradleExecutionSettings settings, @Nullable final String jvmAgentSetup, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException {
    // TODO add support for external process mode
    if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) {
        for (GradleTaskManagerExtension gradleTaskManagerExtension : GradleTaskManagerExtension.EP_NAME.getExtensions()) {
            if (gradleTaskManagerExtension.executeTasks(id, taskNames, projectPath, settings, jvmAgentSetup, listener)) {
                return;
            }
        }
    }
    GradleExecutionSettings effectiveSettings = settings == null ? new GradleExecutionSettings(null, null, DistributionType.BUNDLED, false) : settings;
    Function<ProjectConnection, Void> f = connection -> {
        final List<String> initScripts = ContainerUtil.newArrayList();
        final GradleProjectResolverExtension projectResolverChain = GradleProjectResolver.createProjectResolverChain(effectiveSettings);
        for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; resolverExtension = resolverExtension.getNext()) {
            final String resolverClassName = resolverExtension.getClass().getName();
            resolverExtension.enhanceTaskProcessing(taskNames, jvmAgentSetup, script -> {
                if (StringUtil.isNotEmpty(script)) {
                    ContainerUtil.addAllNotNull(initScripts, "//-- Generated by " + resolverClassName, script, "//");
                }
            });
        }
        final String initScript = effectiveSettings.getUserData(INIT_SCRIPT_KEY);
        if (StringUtil.isNotEmpty(initScript)) {
            ContainerUtil.addAll(initScripts, "//-- Additional script", initScript, "//");
        }
        if (!initScripts.isEmpty()) {
            try {
                File tempFile = GradleExecutionHelper.writeToFileGradleInitScript(StringUtil.join(initScripts, SystemProperties.getLineSeparator()));
                effectiveSettings.withArguments(GradleConstants.INIT_SCRIPT_CMD_OPTION, tempFile.getAbsolutePath());
            } catch (IOException e) {
                throw new ExternalSystemException(e);
            }
        }
        GradleVersion gradleVersion = GradleExecutionHelper.getGradleVersion(connection);
        if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.5")) < 0) {
            listener.onStatusChange(new ExternalSystemTaskExecutionEvent(id, new ExternalSystemProgressEventUnsupportedImpl(gradleVersion + " does not support executions view")));
        }
        for (GradleBuildParticipant buildParticipant : effectiveSettings.getExecutionWorkspace().getBuildParticipants()) {
            effectiveSettings.withArguments(GradleConstants.INCLUDE_BUILD_CMD_OPTION, buildParticipant.getProjectPath());
        }
        BuildLauncher launcher = myHelper.getBuildLauncher(id, connection, effectiveSettings, listener);
        launcher.forTasks(ArrayUtil.toStringArray(taskNames));
        if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
            myCancellationMap.put(id, new UnsupportedCancellationToken());
        } else {
            final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
            launcher.withCancellationToken(cancellationTokenSource.token());
            myCancellationMap.put(id, cancellationTokenSource);
        }
        try {
            launcher.run();
        } finally {
            myCancellationMap.remove(id);
        }
        return null;
    };
    myHelper.execute(projectPath, effectiveSettings, f);
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) ArrayUtil(com.intellij.util.ArrayUtil) GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) GradleProjectResolver(org.jetbrains.plugins.gradle.service.project.GradleProjectResolver) ContainerUtil(com.intellij.util.containers.ContainerUtil) GradleExecutionHelper(org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) UnsupportedCancellationToken(org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken) Map(java.util.Map) GradleConnector(org.gradle.tooling.GradleConnector) GradleBuildParticipant(org.jetbrains.plugins.gradle.settings.GradleBuildParticipant) GradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension) GradleVersion(org.gradle.util.GradleVersion) BuildLauncher(org.gradle.tooling.BuildLauncher) ExternalSystemTaskManager(com.intellij.openapi.externalSystem.task.ExternalSystemTaskManager) StringUtil(com.intellij.openapi.util.text.StringUtil) ExternalSystemTaskExecutionEvent(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent) Key(com.intellij.openapi.util.Key) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) CancellationTokenSource(org.gradle.tooling.CancellationTokenSource) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType) List(java.util.List) SystemProperties(com.intellij.util.SystemProperties) Function(com.intellij.util.Function) ExternalSystemProgressEventUnsupportedImpl(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEventUnsupportedImpl) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) ProjectConnection(org.gradle.tooling.ProjectConnection) NotNull(org.jetbrains.annotations.NotNull) GradleProjectResolverExtension(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension) UnsupportedCancellationToken(org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken) ProjectConnection(org.gradle.tooling.ProjectConnection) ExternalSystemTaskExecutionEvent(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemTaskExecutionEvent) IOException(java.io.IOException) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) BuildLauncher(org.gradle.tooling.BuildLauncher) CancellationTokenSource(org.gradle.tooling.CancellationTokenSource) List(java.util.List) GradleVersion(org.gradle.util.GradleVersion) File(java.io.File) GradleBuildParticipant(org.jetbrains.plugins.gradle.settings.GradleBuildParticipant) ExternalSystemProgressEventUnsupportedImpl(com.intellij.openapi.externalSystem.model.task.event.ExternalSystemProgressEventUnsupportedImpl)

Aggregations

ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)9 ExternalSystemTaskNotificationListenerAdapter (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter)5 NotNull (org.jetbrains.annotations.NotNull)5 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)3 ExternalSystemProgressNotificationManager (com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager)3 Project (com.intellij.openapi.project.Project)3 GradleExecutionSettings (org.jetbrains.plugins.gradle.settings.GradleExecutionSettings)3 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 Function (com.intellij.util.Function)2 List (java.util.List)2 CancellationTokenSource (org.gradle.tooling.CancellationTokenSource)2 ProjectConnection (org.gradle.tooling.ProjectConnection)2 Nullable (org.jetbrains.annotations.Nullable)2 GradleExecutionHelper (org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper)2 GradleProjectResolverExtension (org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension)2 AndroidProject (com.android.builder.model.AndroidProject)1 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)1 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1