Search in sources :

Example 6 with DependencyScope

use of com.intellij.openapi.roots.DependencyScope 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 7 with DependencyScope

use of com.intellij.openapi.roots.DependencyScope in project intellij-community by JetBrains.

the class GradleProjectResolverUtil method getModuleId.

@NotNull
public static String getModuleId(@NotNull ExternalProjectDependency projectDependency) {
    DependencyScope dependencyScope = getDependencyScope(projectDependency.getScope());
    String projectPath = projectDependency.getProjectPath();
    String moduleId = StringUtil.isEmpty(projectPath) || ":".equals(projectPath) ? projectDependency.getName() : projectPath;
    if (Dependency.DEFAULT_CONFIGURATION.equals(projectDependency.getConfigurationName())) {
        moduleId += dependencyScope == DependencyScope.TEST ? ":test" : ":main";
    } else {
        moduleId += (':' + projectDependency.getConfigurationName());
    }
    return moduleId;
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with DependencyScope

use of com.intellij.openapi.roots.DependencyScope in project android by JetBrains.

the class DependenciesModuleSetupStep method updateDependency.

private void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JarLibraryDependency dependency) {
    DependencyScope scope = parseScope(dependency.getScope());
    File binaryPath = dependency.getBinaryPath();
    if (binaryPath == null) {
        DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
        setupErrors.addMissingBinaryPath(module.getName());
        return;
    }
    // Gradle API doesn't provide library name at the moment.
    String name = binaryPath.isFile() ? getNameWithoutExtension(binaryPath) : sanitizeFileName(binaryPath.getPath());
    myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, name, scope, binaryPath, dependency.getSourcePath(), dependency.getJavadocPath());
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) File(java.io.File)

Example 9 with DependencyScope

use of com.intellij.openapi.roots.DependencyScope in project intellij-plugins by JetBrains.

the class FlexModuleConverter method convertDependencyType.

private static void convertDependencyType(Element orderEntry, ModifiableDependencyType dependencyType) {
    DependencyScope scope = DependencyScope.readExternal(orderEntry);
    boolean isExported = orderEntry.getAttribute(ModuleLibraryOrderEntryImpl.EXPORTED_ATTR) != null;
    dependencyType.setLinkageType(FlexUtils.convertLinkageType(scope, isExported));
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope)

Example 10 with DependencyScope

use of com.intellij.openapi.roots.DependencyScope in project intellij-community by JetBrains.

the class AddExternalLibraryToDependenciesQuickFix method invoke.

@Override
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
    DependencyScope scope = suggestScopeByLocation(myCurrentModule, myReference.getElement());
    JavaProjectModelModificationService.getInstance(project).addDependency(myCurrentModule, myLibraryDescriptor, scope).done(aVoid -> new WriteAction() {

        protected void run(@NotNull final Result result) {
            try {
                importClass(myCurrentModule, editor, myReference, myQualifiedClassName);
            } catch (IndexNotReadyException e) {
                LOG.info(e);
            }
        }
    }.execute());
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) WriteAction(com.intellij.openapi.application.WriteAction) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Aggregations

DependencyScope (com.intellij.openapi.roots.DependencyScope)13 NotNull (org.jetbrains.annotations.NotNull)4 File (java.io.File)3 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)2 Nullable (org.jetbrains.annotations.Nullable)2 DefaultExternalDependencyId (org.jetbrains.plugins.gradle.DefaultExternalDependencyId)2 ExternalDependencyId (org.jetbrains.plugins.gradle.ExternalDependencyId)2 DependencySetupErrors (com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors)1 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)1 Module (com.intellij.openapi.module.Module)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Project (com.intellij.openapi.project.Project)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1