use of com.intellij.openapi.roots.DependencyScope in project kotlin by JetBrains.
the class ExternalSystemImportingTestCase method assertModuleModuleDepScope.
protected void assertModuleModuleDepScope(String moduleName, String depName, DependencyScope... scopes) {
List<ModuleOrderEntry> deps = getModuleModuleDeps(moduleName, depName);
Set<DependencyScope> actualScopes = new HashSet<DependencyScope>();
for (ModuleOrderEntry dep : deps) {
actualScopes.add(dep.getScope());
}
HashSet<DependencyScope> expectedScopes = new HashSet<DependencyScope>(Arrays.asList(scopes));
assertEquals("Dependency '" + depName + "' for module '" + moduleName + "' has unexpected scope", expectedScopes, actualScopes);
}
use of com.intellij.openapi.roots.DependencyScope in project intellij-community by JetBrains.
the class ModuleSourceItemGroup method collectDependentModules.
private static void collectDependentModules(final Module module, Set<Module> modules, ArtifactEditorContext context) {
if (!modules.add(module))
return;
for (OrderEntry entry : context.getModulesProvider().getRootModel(module).getOrderEntries()) {
if (entry instanceof ModuleOrderEntry) {
final ModuleOrderEntry moduleEntry = (ModuleOrderEntry) entry;
final Module dependency = moduleEntry.getModule();
final DependencyScope scope = moduleEntry.getScope();
if (dependency != null && scope.isForProductionRuntime()) {
collectDependentModules(dependency, modules, context);
}
}
}
}
use of com.intellij.openapi.roots.DependencyScope in project intellij-community by JetBrains.
the class LibraryCompositionSettings method addLibraries.
@Nullable
public Library addLibraries(@NotNull final ModifiableRootModel rootModel, @NotNull final List<Library> addedLibraries, @Nullable final LibrariesContainer librariesContainer) {
Library newLibrary = createLibrary(rootModel, librariesContainer);
if (newLibrary != null) {
addedLibraries.add(newLibrary);
DependencyScope scope = LibraryDependencyScopeSuggester.getDefaultScope(newLibrary);
if (getLibraryLevel() != LibrariesContainer.LibraryLevel.MODULE) {
rootModel.addLibraryEntry(newLibrary).setScope(scope);
} else {
LibraryOrderEntry orderEntry = rootModel.findLibraryOrderEntry(newLibrary);
assert orderEntry != null;
orderEntry.setScope(scope);
}
}
if (mySelectedLibrary != null) {
addedLibraries.add(mySelectedLibrary);
rootModel.addLibraryEntry(mySelectedLibrary).setScope(LibraryDependencyScopeSuggester.getDefaultScope(mySelectedLibrary));
}
if (myLibraryProvider != null) {
Library library = myLibraryProvider.createLibrary(myLibraryDescription.getSuitableLibraryKinds());
addedLibraries.add(library);
rootModel.addLibraryEntry(library).setScope(LibraryDependencyScopeSuggester.getDefaultScope(library));
}
return newLibrary;
}
use of com.intellij.openapi.roots.DependencyScope in project intellij-community by JetBrains.
the class GradleProjectResolverUtil method doBuildDependencies.
private static void doBuildDependencies(@NotNull ProjectResolverContext resolverCtx, @NotNull Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap, @NotNull final Map<String, String> artifactsMap, @NotNull Map<ExternalDependencyId, ExternalDependency> mergedDependencyMap, @NotNull DataNode<? extends ExternalEntityData> ownerDataNode, @NotNull Collection<ExternalDependency> dependencies, @Nullable DataNode<ProjectData> ideProject) throws IllegalStateException {
Map<ExternalDependencyId, ExternalDependency> dependencyMap = ContainerUtil.newLinkedHashMap();
for (ExternalDependency dependency : dependencies) {
final ExternalDependency dep = dependencyMap.get(dependency.getId());
if (dep instanceof AbstractExternalDependency) {
dep.getDependencies().addAll(ContainerUtil.subtract(dependency.getDependencies(), dep.getDependencies()));
} else {
dependencyMap.put(dependency.getId(), dependency);
}
}
for (ExternalDependency dependency : dependencyMap.values()) {
final ExternalDependency mergedDependency = ContainerUtil.getOrElse(mergedDependencyMap, dependency.getId(), dependency);
DependencyScope dependencyScope = getDependencyScope(mergedDependency.getScope());
ModuleData ownerModule = null;
if (ownerDataNode.getData() instanceof ModuleData) {
ownerModule = (ModuleData) ownerDataNode.getData();
} else if (ownerDataNode.getData() instanceof DependencyData) {
ownerModule = ((DependencyData) ownerDataNode.getData()).getOwnerModule();
}
assert ownerModule != null;
DataNode<? extends ExternalEntityData> depOwnerDataNode = null;
if (mergedDependency instanceof ExternalProjectDependency) {
class ProjectDependencyInfo {
@NotNull
ModuleData myModuleData;
@Nullable
ExternalSourceSet mySourceSet;
Collection<File> dependencyArtifacts;
public ProjectDependencyInfo(@NotNull ModuleData moduleData, @Nullable ExternalSourceSet sourceSet, Collection<File> dependencyArtifacts) {
this.myModuleData = moduleData;
this.mySourceSet = sourceSet;
this.dependencyArtifacts = dependencyArtifacts;
}
}
final ExternalProjectDependency projectDependency = (ExternalProjectDependency) mergedDependency;
Collection<ProjectDependencyInfo> projectDependencyInfos = ContainerUtil.newArrayList();
String selectionReason = projectDependency.getSelectionReason();
if ("composite build substitution".equals(selectionReason) && resolverCtx.getSettings() != null) {
GradleExecutionWorkspace executionWorkspace = resolverCtx.getSettings().getExecutionWorkspace();
ModuleData moduleData = executionWorkspace.findModuleDataByArtifacts(projectDependency.getProjectDependencyArtifacts());
if (moduleData != null) {
projectDependencyInfos.add(new ProjectDependencyInfo(moduleData, null, projectDependency.getProjectDependencyArtifacts()));
}
} else {
String moduleId = getModuleId(projectDependency);
Pair<DataNode<GradleSourceSetData>, ExternalSourceSet> projectPair = sourceSetMap.get(moduleId);
if (projectPair == null) {
for (File file : projectDependency.getProjectDependencyArtifacts()) {
moduleId = artifactsMap.get(ExternalSystemApiUtil.toCanonicalPath(file.getAbsolutePath()));
if (moduleId == null)
continue;
projectPair = sourceSetMap.get(moduleId);
if (projectPair == null)
continue;
projectDependencyInfos.add(new ProjectDependencyInfo(projectPair.first.getData(), projectPair.second, Collections.singleton(file)));
}
} else {
projectDependencyInfos.add(new ProjectDependencyInfo(projectPair.first.getData(), projectPair.second, projectDependency.getProjectDependencyArtifacts()));
}
}
if (projectDependencyInfos.isEmpty()) {
final LibraryLevel level = LibraryLevel.MODULE;
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, "");
LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level);
libraryDependencyData.setScope(dependencyScope);
libraryDependencyData.setOrder(mergedDependency.getClasspathOrder());
libraryDependencyData.setExported(mergedDependency.getExported());
if (!projectDependency.getProjectDependencyArtifacts().isEmpty()) {
for (File artifact : projectDependency.getProjectDependencyArtifacts()) {
library.addPath(LibraryPathType.BINARY, artifact.getPath());
}
depOwnerDataNode = ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData);
} else {
depOwnerDataNode = ownerDataNode;
}
} else {
for (ProjectDependencyInfo projectDependencyInfo : projectDependencyInfos) {
ModuleDependencyData moduleDependencyData = new ModuleDependencyData(ownerModule, projectDependencyInfo.myModuleData);
moduleDependencyData.setScope(dependencyScope);
if (projectDependencyInfo.mySourceSet != null && "test".equals(projectDependencyInfo.mySourceSet.getName())) {
moduleDependencyData.setProductionOnTestDependency(true);
}
moduleDependencyData.setOrder(mergedDependency.getClasspathOrder());
moduleDependencyData.setExported(mergedDependency.getExported());
moduleDependencyData.setModuleDependencyArtifacts(ContainerUtil.map(projectDependencyInfo.dependencyArtifacts, File::getPath));
depOwnerDataNode = ownerDataNode.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData);
}
// since we can not determine from what project dependency artifact it was originated
if (projectDependencyInfos.size() > 1) {
depOwnerDataNode = ownerDataNode;
}
}
} else if (mergedDependency instanceof ExternalLibraryDependency) {
String libraryName = mergedDependency.getId().getPresentableName();
final LibraryLevel level = StringUtil.isNotEmpty(libraryName) ? LibraryLevel.PROJECT : LibraryLevel.MODULE;
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName);
LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level);
libraryDependencyData.setScope(dependencyScope);
libraryDependencyData.setOrder(mergedDependency.getClasspathOrder());
libraryDependencyData.setExported(mergedDependency.getExported());
library.addPath(LibraryPathType.BINARY, ((ExternalLibraryDependency) mergedDependency).getFile().getAbsolutePath());
File sourcePath = ((ExternalLibraryDependency) mergedDependency).getSource();
if (sourcePath != null) {
library.addPath(LibraryPathType.SOURCE, sourcePath.getAbsolutePath());
}
File javaDocPath = ((ExternalLibraryDependency) mergedDependency).getJavadoc();
if (javaDocPath != null) {
library.addPath(LibraryPathType.DOC, javaDocPath.getAbsolutePath());
}
depOwnerDataNode = ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData);
if (StringUtil.isNotEmpty(libraryName)) {
linkProjectLibrary(ideProject, library);
}
} else if (mergedDependency instanceof ExternalMultiLibraryDependency) {
final LibraryLevel level = LibraryLevel.MODULE;
String libraryName = mergedDependency.getId().getPresentableName();
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName);
LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level);
libraryDependencyData.setScope(dependencyScope);
libraryDependencyData.setOrder(mergedDependency.getClasspathOrder());
libraryDependencyData.setExported(mergedDependency.getExported());
for (File file : ((ExternalMultiLibraryDependency) mergedDependency).getFiles()) {
library.addPath(LibraryPathType.BINARY, file.getAbsolutePath());
}
for (File file : ((ExternalMultiLibraryDependency) mergedDependency).getSources()) {
library.addPath(LibraryPathType.SOURCE, file.getAbsolutePath());
}
for (File file : ((ExternalMultiLibraryDependency) mergedDependency).getJavadoc()) {
library.addPath(LibraryPathType.DOC, file.getAbsolutePath());
}
depOwnerDataNode = ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData);
} else if (mergedDependency instanceof FileCollectionDependency) {
final LibraryLevel level = LibraryLevel.MODULE;
String libraryName = "";
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName);
LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level);
libraryDependencyData.setScope(dependencyScope);
libraryDependencyData.setOrder(mergedDependency.getClasspathOrder());
libraryDependencyData.setExported(mergedDependency.getExported());
for (File file : ((FileCollectionDependency) mergedDependency).getFiles()) {
library.addPath(LibraryPathType.BINARY, file.getAbsolutePath());
}
ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData);
} else if (mergedDependency instanceof UnresolvedExternalDependency) {
final LibraryLevel level = LibraryLevel.PROJECT;
String libraryName = mergedDependency.getId().getPresentableName();
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName, true);
LibraryDependencyData libraryDependencyData = new LibraryDependencyData(ownerModule, library, level);
libraryDependencyData.setScope(dependencyScope);
final String failureMessage = ((UnresolvedExternalDependency) mergedDependency).getFailureMessage();
if (failureMessage != null) {
library.addPath(LibraryPathType.BINARY, failureMessage);
}
ownerDataNode.createChild(ProjectKeys.LIBRARY_DEPENDENCY, libraryDependencyData);
linkProjectLibrary(ideProject, library);
}
if (depOwnerDataNode != null) {
doBuildDependencies(resolverCtx, sourceSetMap, artifactsMap, mergedDependencyMap, depOwnerDataNode, dependency.getDependencies(), ideProject);
}
}
}
use of com.intellij.openapi.roots.DependencyScope in project intellij-community by JetBrains.
the class GradleProjectResolverUtil method buildDependencies.
public static void buildDependencies(@NotNull ProjectResolverContext resolverCtx, @NotNull Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap, @NotNull final Map<String, String> artifactsMap, @NotNull DataNode<? extends ExternalEntityData> ownerDataNode, @NotNull Collection<ExternalDependency> dependencies, @Nullable DataNode<ProjectData> ideProject) throws IllegalStateException {
Map<ExternalDependencyId, ExternalDependency> dependencyMap = ContainerUtil.newHashMap();
Queue<ExternalDependency> queue = ContainerUtil.newLinkedList(dependencies);
while (!queue.isEmpty()) {
final ExternalDependency dependency = queue.remove();
ExternalDependency seenDependency = dependencyMap.get(dependency.getId());
if (seenDependency != null) {
if (dependency instanceof ExternalLibraryDependency) {
if (seenDependency instanceof ExternalLibraryDependency && !FileUtil.filesEqual(((ExternalLibraryDependency) seenDependency).getFile(), ((ExternalLibraryDependency) dependency).getFile())) {
DefaultExternalMultiLibraryDependency mergedDependency = new DefaultExternalMultiLibraryDependency();
mergedDependency.setName(dependency.getId().getName());
mergedDependency.setGroup(dependency.getId().getGroup());
mergedDependency.setVersion(dependency.getId().getVersion());
mergedDependency.setPackaging(dependency.getId().getPackaging());
mergedDependency.setClassifier(dependency.getId().getClassifier());
mergedDependency.setScope(dependency.getScope());
mergedDependency.setClasspathOrder(dependency.getClasspathOrder());
mergedDependency.getDependencies().addAll(dependency.getDependencies());
mergedDependency.getFiles().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) seenDependency).getFile(), ((ExternalLibraryDependency) dependency).getFile()));
mergedDependency.getSources().addAll((ContainerUtil.packNullables(((ExternalLibraryDependency) seenDependency).getSource(), ((ExternalLibraryDependency) dependency).getSource())));
mergedDependency.getJavadoc().addAll((ContainerUtil.packNullables(((ExternalLibraryDependency) seenDependency).getJavadoc(), ((ExternalLibraryDependency) dependency).getJavadoc())));
dependencyMap.put(dependency.getId(), mergedDependency);
continue;
} else if (seenDependency instanceof DefaultExternalMultiLibraryDependency) {
DefaultExternalMultiLibraryDependency mergedDependency = (DefaultExternalMultiLibraryDependency) seenDependency;
mergedDependency.getFiles().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) dependency).getFile()));
mergedDependency.getSources().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) dependency).getSource()));
mergedDependency.getJavadoc().addAll(ContainerUtil.packNullables(((ExternalLibraryDependency) dependency).getJavadoc()));
continue;
}
}
DependencyScope prevScope = seenDependency.getScope() == null ? DependencyScope.COMPILE : DependencyScope.valueOf(seenDependency.getScope());
DependencyScope currentScope = dependency.getScope() == null ? DependencyScope.COMPILE : DependencyScope.valueOf(dependency.getScope());
if (prevScope.isForProductionCompile())
continue;
if (prevScope.isForProductionRuntime() && currentScope.isForProductionRuntime())
continue;
}
dependencyMap.put(new DefaultExternalDependencyId(dependency.getId()), dependency);
queue.addAll(dependency.getDependencies());
}
doBuildDependencies(resolverCtx, sourceSetMap, artifactsMap, dependencyMap, ownerDataNode, dependencies, ideProject);
}
Aggregations