mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
revert dependency results transformer
This commit is contained in:
+1
-1
@@ -480,7 +480,7 @@ public class DependencyResolverImpl implements DependencyResolver {
|
||||
Configuration deprecatedCompileConfiguration = compileDependenciesProvider.getDeprecatedCompileConfiguration();
|
||||
Configuration compileConfiguration = compileDependenciesProvider.getCompileConfiguration();
|
||||
|
||||
boolean checkCompileOnlyDeps = compileDependenciesProvider.getCompileClasspathConfiguration() != null && !compileConfiguration.getResolvedConfiguration().hasError();
|
||||
boolean checkCompileOnlyDeps = compileDependenciesProvider.getCompileClasspathConfiguration() != null;
|
||||
// since version 3.4 compileOnly no longer extends compile
|
||||
// so, we can use compileOnly configuration for the check
|
||||
if (isJavaLibraryPluginSupported) {
|
||||
|
||||
+253
-278
@@ -26,16 +26,18 @@ import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.plugins.gradle.tooling.util.resolve.DependencyResolverImpl.*;
|
||||
|
||||
public class DependencyResultsTransformer {
|
||||
private final Project myProject;
|
||||
private final SourceSetCachedFinder mySourceSetFinder;
|
||||
private final Multimap<ModuleVersionIdentifier, ResolvedArtifact> myArtifactMap;
|
||||
private final Map<ComponentIdentifier, ComponentArtifactsResult> myAuxiliaryArtifactsMap;
|
||||
private final Multimap<ModuleComponentIdentifier, ProjectDependency> myConfigurationProjectDependencies;
|
||||
private final String myScope;
|
||||
private final Multimap<ModuleVersionIdentifier, ResolvedArtifact> artifactMap;
|
||||
private final Map<ComponentIdentifier, ComponentArtifactsResult> componentResultsMap;
|
||||
private final Multimap<ModuleComponentIdentifier, ProjectDependency> configurationProjectDependencies;
|
||||
private final String scope;
|
||||
private final Set<File> resolvedDepsFiles = new HashSet<File>();
|
||||
private final Map<ModuleVersionIdentifier, Set<ExternalDependency>> myResolvedDepsCache =
|
||||
new HashMap<ModuleVersionIdentifier, Set<ExternalDependency>>();
|
||||
|
||||
private final List<DependencyResult> handledDependencyResults = new ArrayList<DependencyResult>();
|
||||
|
||||
public DependencyResultsTransformer(@NotNull final Project project,
|
||||
@NotNull final SourceSetCachedFinder sourceSetFinder,
|
||||
@@ -46,10 +48,10 @@ public class DependencyResultsTransformer {
|
||||
myProject = project;
|
||||
mySourceSetFinder = sourceSetFinder;
|
||||
|
||||
myArtifactMap = artifactMap;
|
||||
myAuxiliaryArtifactsMap = auxiliaryArtifactsMap;
|
||||
myConfigurationProjectDependencies = configurationProjectDependencies;
|
||||
myScope = scope;
|
||||
this.artifactMap = artifactMap;
|
||||
componentResultsMap = auxiliaryArtifactsMap;
|
||||
this.configurationProjectDependencies = configurationProjectDependencies;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public Set<File> getResolvedDepsFiles() {
|
||||
@@ -57,292 +59,252 @@ public class DependencyResultsTransformer {
|
||||
}
|
||||
|
||||
Set<ExternalDependency> buildExternalDependencies(Collection<? extends DependencyResult> gradleDependencies) {
|
||||
Set<DependencyResult> handledDependencyResults = new HashSet<DependencyResult>();
|
||||
Set<ExternalDependency> result = new LinkedHashSet<ExternalDependency>();
|
||||
|
||||
for (DependencyResult gradleDep : gradleDependencies) {
|
||||
Set<ExternalDependency> dependencies = new LinkedHashSet<ExternalDependency>();
|
||||
for (DependencyResult dependencyResult : gradleDependencies) {
|
||||
|
||||
// dependency cycles check
|
||||
if (handledDependencyResults.add(gradleDep)) {
|
||||
if (gradleDep instanceof ResolvedDependencyResult) {
|
||||
result.addAll(buildExternalDependencies((ResolvedDependencyResult)gradleDep));
|
||||
}
|
||||
if (!handledDependencyResults.contains(dependencyResult)) {
|
||||
handledDependencyResults.add(dependencyResult);
|
||||
|
||||
if (gradleDep instanceof UnresolvedDependencyResult) {
|
||||
result.addAll(buildExternalDependencies((UnresolvedDependencyResult)gradleDep));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dependencyResult instanceof ResolvedDependencyResult) {
|
||||
ResolvedComponentResult componentResult = ((ResolvedDependencyResult)dependencyResult).getSelected();
|
||||
ComponentSelector componentSelector = dependencyResult.getRequested();
|
||||
ModuleComponentIdentifier componentIdentifier = toComponentIdentifier(componentResult.getModuleVersion());
|
||||
|
||||
return result;
|
||||
}
|
||||
String name = componentResult.getModuleVersion().getName();
|
||||
String group = componentResult.getModuleVersion().getGroup();
|
||||
String version = componentResult.getModuleVersion().getVersion();
|
||||
String selectionReason = componentResult.getSelectionReason().getDescription();
|
||||
|
||||
private Set<ExternalDependency> buildExternalDependencies(UnresolvedDependencyResult unresolvedGradleDep) {
|
||||
ComponentSelector attempted = unresolvedGradleDep.getAttempted();
|
||||
if (attempted instanceof ModuleComponentSelector) {
|
||||
final ModuleComponentSelector attemptedMCSelector = (ModuleComponentSelector)attempted;
|
||||
return Collections.<ExternalDependency>singleton(createUnresolvedExternalDep(attemptedMCSelector,
|
||||
unresolvedGradleDep.getFailure().getMessage()));
|
||||
}
|
||||
return Collections.emptySet();
|
||||
}
|
||||
boolean resolveFromArtifacts = componentSelector instanceof ModuleComponentSelector;
|
||||
|
||||
if (componentSelector instanceof ProjectComponentSelector) {
|
||||
Collection<ProjectDependency> projectDependencies = configurationProjectDependencies.get(componentIdentifier);
|
||||
Collection<Configuration> dependencyConfigurations;
|
||||
if (projectDependencies.isEmpty()) {
|
||||
Project dependencyProject = myProject.findProject(((ProjectComponentSelector)componentSelector).getProjectPath());
|
||||
if (dependencyProject != null) {
|
||||
Configuration dependencyProjectConfiguration =
|
||||
dependencyProject.getConfigurations().getByName(Dependency.DEFAULT_CONFIGURATION);
|
||||
dependencyConfigurations = Collections.singleton(dependencyProjectConfiguration);
|
||||
} else {
|
||||
dependencyConfigurations = Collections.emptySet();
|
||||
resolveFromArtifacts = true;
|
||||
selectionReason = "composite build substitution";
|
||||
}
|
||||
} else {
|
||||
dependencyConfigurations = new ArrayList<Configuration>();
|
||||
for (ProjectDependency dependency : projectDependencies) {
|
||||
dependencyConfigurations.add(getTargetConfiguration(dependency));
|
||||
}
|
||||
}
|
||||
|
||||
for (Configuration it : dependencyConfigurations) {
|
||||
if (it.getName().equals(Dependency.DEFAULT_CONFIGURATION)) {
|
||||
DefaultExternalProjectDependency dependency = new DefaultExternalProjectDependency();
|
||||
dependency.setName( name);
|
||||
dependency.setGroup(group);
|
||||
dependency.setVersion(version);
|
||||
dependency.setScope(scope);
|
||||
dependency.setSelectionReason(selectionReason);
|
||||
dependency.setProjectPath(((ProjectComponentSelector)componentSelector).getProjectPath());
|
||||
dependency.setConfigurationName(it.getName());
|
||||
Set<File> artifacts = it.getAllArtifacts().getFiles().getFiles();
|
||||
dependency.setProjectDependencyArtifacts(artifacts);
|
||||
setProjectDependencyArtifactsSources(dependency, artifacts, mySourceSetFinder);
|
||||
|
||||
resolvedDepsFiles.addAll(dependency.getProjectDependencyArtifacts());
|
||||
|
||||
if (it.getArtifacts().size() == 1) {
|
||||
PublishArtifact publishArtifact = it.getAllArtifacts().iterator().next();
|
||||
dependency.setClassifier(publishArtifact.getClassifier());
|
||||
dependency.setPackaging(publishArtifact.getExtension() != null ? publishArtifact.getExtension() : "jar");
|
||||
}
|
||||
|
||||
if (!componentResult.equals(dependencyResult.getFrom())) {
|
||||
dependency.getDependencies().addAll(
|
||||
buildExternalDependencies(componentResult.getDependencies())
|
||||
);
|
||||
}
|
||||
dependencies.add(dependency);
|
||||
}
|
||||
else {
|
||||
DefaultExternalProjectDependency dependency = new DefaultExternalProjectDependency();
|
||||
dependency.setName(name);
|
||||
dependency.setGroup(group);
|
||||
dependency.setVersion(version);
|
||||
dependency.setScope(scope);
|
||||
dependency.setSelectionReason(selectionReason);
|
||||
dependency.setProjectPath(((ProjectComponentSelector)componentSelector).getProjectPath());
|
||||
dependency.setConfigurationName(it.getName());
|
||||
Set<File> artifactsFiles = it.getAllArtifacts().getFiles().getFiles();
|
||||
dependency.setProjectDependencyArtifacts(artifactsFiles);
|
||||
setProjectDependencyArtifactsSources(dependency, artifactsFiles, mySourceSetFinder);
|
||||
|
||||
resolvedDepsFiles.addAll(dependency.getProjectDependencyArtifacts());
|
||||
|
||||
if (it.getArtifacts().size() == 1) {
|
||||
PublishArtifact publishArtifact = it.getAllArtifacts().iterator().next();
|
||||
dependency.setClassifier(publishArtifact.getClassifier());
|
||||
dependency.setPackaging(publishArtifact.getExtension() != null ? publishArtifact.getExtension() : "jar");
|
||||
}
|
||||
|
||||
if (!componentResult.equals(dependencyResult.getFrom())) {
|
||||
|
||||
dependency.getDependencies().addAll(
|
||||
buildExternalDependencies(componentResult.getDependencies())
|
||||
);
|
||||
}
|
||||
|
||||
dependencies.add(dependency);
|
||||
|
||||
List<File> files = new ArrayList<File>();
|
||||
PublishArtifactSet artifacts = it.getArtifacts();
|
||||
if (artifacts != null && !artifacts.isEmpty()) {
|
||||
PublishArtifact artifact = artifacts.iterator().next();
|
||||
final MetaProperty taskProperty = DefaultGroovyMethods.hasProperty(artifact, "archiveTask");
|
||||
if (taskProperty != null && (taskProperty.getProperty(artifact) instanceof AbstractArchiveTask)) {
|
||||
|
||||
AbstractArchiveTask archiveTask = (AbstractArchiveTask)taskProperty.getProperty(artifact);
|
||||
resolvedDepsFiles.add(new File(archiveTask.getDestinationDir(), archiveTask.getArchiveName()));
|
||||
|
||||
|
||||
private Set<ExternalDependency> buildExternalDependencies(ResolvedDependencyResult resolvedGradleDep) {
|
||||
Set<ExternalDependency> result = new LinkedHashSet<ExternalDependency>();
|
||||
try {
|
||||
final Method mainSpecGetter = AbstractCopyTask.class.getDeclaredMethod("getMainSpec");
|
||||
mainSpecGetter.setAccessible(true);
|
||||
Object mainSpec = mainSpecGetter.invoke(archiveTask);
|
||||
|
||||
ResolvedComponentResult componentResult = resolvedGradleDep.getSelected();
|
||||
ComponentSelector componentSelector = resolvedGradleDep.getRequested();
|
||||
ModuleVersionIdentifier moduleVersionId = componentResult.getModuleVersion();
|
||||
ModuleComponentIdentifier componentIdentifier = DependencyResolverImpl.toComponentIdentifier(moduleVersionId);
|
||||
String selectionReason = componentResult.getSelectionReason().getDescription();
|
||||
final List<MetaMethod> sourcePathGetters =
|
||||
DefaultGroovyMethods.respondsTo(mainSpec, "getSourcePaths", new Object[]{});
|
||||
if (!sourcePathGetters.isEmpty()) {
|
||||
Set<Object> sourcePaths = (Set<Object>)sourcePathGetters.get(0).doMethodInvoke(mainSpec, new Object[]{});
|
||||
if (sourcePaths != null) {
|
||||
for (Object path : sourcePaths) {
|
||||
if (path instanceof String) {
|
||||
File file = new File((String)path);
|
||||
if (file.isAbsolute()) {
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
else if (path instanceof SourceSetOutput) {
|
||||
files.addAll(((SourceSetOutput)path).getFiles());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean resolveFromArtifacts = false;
|
||||
|
||||
Set<ExternalDependency> cached = myResolvedDepsCache.get(moduleVersionId);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
if (componentSelector instanceof ProjectComponentSelector) {
|
||||
final ProjectComponentSelector selector = (ProjectComponentSelector)componentSelector;
|
||||
|
||||
final Collection<Configuration> dependencyConfigurations =
|
||||
getProjectDepsConfigurations(selector.getProjectPath(),
|
||||
myConfigurationProjectDependencies.get(componentIdentifier));
|
||||
|
||||
if (dependencyConfigurations.isEmpty()) {
|
||||
resolveFromArtifacts = true;
|
||||
selectionReason = "composite build substitution";
|
||||
}
|
||||
|
||||
for (Configuration it : dependencyConfigurations) {
|
||||
DefaultExternalProjectDependency dependency = createExternalProjectDep(moduleVersionId,
|
||||
selectionReason,
|
||||
selector.getProjectPath(),
|
||||
it.getName());
|
||||
processProjectDependencyConfiguration(resolvedGradleDep, result, componentResult, it, dependency);
|
||||
}
|
||||
}
|
||||
|
||||
if (componentSelector instanceof ModuleComponentSelector || resolveFromArtifacts) {
|
||||
Collection<ResolvedArtifact> artifacts = myArtifactMap.get(moduleVersionId);
|
||||
|
||||
final Set<ExternalDependency> transitiveDeps = buildExternalDependencies(componentResult.getDependencies());
|
||||
if (artifacts != null && artifacts.isEmpty()) {
|
||||
result.addAll(transitiveDeps);
|
||||
}
|
||||
|
||||
boolean first = true;
|
||||
|
||||
if (artifacts != null) {
|
||||
for (ResolvedArtifact artifact: artifacts) {
|
||||
final ExternalDependency dependency = transformResolvedArtifact(moduleVersionId, componentIdentifier, selectionReason, artifact);
|
||||
|
||||
if (first) {
|
||||
dependency.getDependencies().addAll(transitiveDeps);
|
||||
first = false;
|
||||
}
|
||||
result.add(dependency);
|
||||
resolvedDepsFiles.add(artifact.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myResolvedDepsCache.put(moduleVersionId, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<Configuration> getProjectDepsConfigurations(@NotNull final String projectPath,
|
||||
@NotNull final Collection<ProjectDependency> projectDependencies) {
|
||||
Collection<Configuration> dependencyConfigurations;
|
||||
if (projectDependencies.isEmpty()) {
|
||||
Project dependencyProject = myProject.findProject(projectPath);
|
||||
if (dependencyProject != null) {
|
||||
Configuration dependencyProjectConfiguration =
|
||||
dependencyProject.getConfigurations().getByName(Dependency.DEFAULT_CONFIGURATION);
|
||||
dependencyConfigurations = Collections.singleton(dependencyProjectConfiguration);
|
||||
} else {
|
||||
dependencyConfigurations = Collections.emptySet();
|
||||
}
|
||||
} else {
|
||||
dependencyConfigurations = new ArrayList<Configuration>();
|
||||
for (ProjectDependency dependency : projectDependencies) {
|
||||
dependencyConfigurations.add(DependencyResolverImpl.getTargetConfiguration(dependency));
|
||||
}
|
||||
}
|
||||
return dependencyConfigurations;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ExternalDependency transformResolvedArtifact(@NotNull final ModuleVersionIdentifier moduleVersionId,
|
||||
@NotNull final ModuleComponentIdentifier componentIdentifier,
|
||||
@NotNull final String selectionReason,
|
||||
@NotNull final ResolvedArtifact artifact) {
|
||||
String packaging = artifact.getExtension() != null ? artifact.getExtension() : "jar";
|
||||
String classifier = artifact.getClassifier();
|
||||
final ExternalDependency dependency;
|
||||
|
||||
if (DependencyResolverImpl.isProjectDependencyArtifact(artifact)) {
|
||||
final String projectPath = ((ProjectComponentIdentifier)artifact.getId().getComponentIdentifier()).getProjectPath();
|
||||
dependency = createExternalProjectDep(moduleVersionId,
|
||||
selectionReason,
|
||||
projectPath,
|
||||
Dependency.DEFAULT_CONFIGURATION);
|
||||
|
||||
DefaultExternalProjectDependency projectDependency = (DefaultExternalProjectDependency)dependency;
|
||||
|
||||
List<File> files = new ArrayList<File>();
|
||||
for (ResolvedArtifact resolvedArtifact : myArtifactMap.get(moduleVersionId)) {
|
||||
files.add(resolvedArtifact.getFile());
|
||||
}
|
||||
|
||||
projectDependency.setProjectDependencyArtifacts(files);
|
||||
projectDependency.setProjectDependencyArtifactsSources(DependencyResolverImpl.findArtifactSources(files, mySourceSetFinder));
|
||||
resolvedDepsFiles.addAll(projectDependency.getProjectDependencyArtifacts());
|
||||
}
|
||||
else {
|
||||
dependency = createExternalLibraryDep(moduleVersionId, selectionReason);
|
||||
DefaultExternalLibraryDependency libraryDependency = (DefaultExternalLibraryDependency)dependency;
|
||||
|
||||
libraryDependency.setPackaging(packaging);
|
||||
libraryDependency.setClassifier(classifier);
|
||||
libraryDependency.setFile(artifact.getFile());
|
||||
|
||||
ComponentArtifactsResult artifactsResult = myAuxiliaryArtifactsMap.get(componentIdentifier);
|
||||
if (artifactsResult != null) {
|
||||
ResolvedArtifactResult sourcesResult = findMatchingArtifact(artifact, artifactsResult, SourcesArtifact.class);
|
||||
if (sourcesResult != null) {
|
||||
libraryDependency.setSource(sourcesResult.getFile());
|
||||
}
|
||||
|
||||
ResolvedArtifactResult javadocResult = findMatchingArtifact(artifact, artifactsResult, JavadocArtifact.class);
|
||||
if (javadocResult != null) {
|
||||
libraryDependency.setJavadoc(javadocResult.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
return dependency;
|
||||
}
|
||||
|
||||
private void processProjectDependencyConfiguration(@NotNull final ResolvedDependencyResult resolvedGradleDep,
|
||||
@NotNull final Set<ExternalDependency> result,
|
||||
@NotNull final ResolvedComponentResult resolvedComponent,
|
||||
@NotNull final Configuration projectDepConfiguration,
|
||||
@NotNull final DefaultExternalProjectDependency externalDependency) {
|
||||
Set<File> artifactsFiles = projectDepConfiguration.getAllArtifacts().getFiles().getFiles();
|
||||
externalDependency.setProjectDependencyArtifacts(artifactsFiles);
|
||||
externalDependency.setProjectDependencyArtifactsSources(DependencyResolverImpl.findArtifactSources(artifactsFiles, mySourceSetFinder));
|
||||
resolvedDepsFiles.addAll(externalDependency.getProjectDependencyArtifacts());
|
||||
|
||||
if (projectDepConfiguration.getArtifacts().size() == 1) {
|
||||
PublishArtifact publishArtifact = projectDepConfiguration.getAllArtifacts().iterator().next();
|
||||
externalDependency.setClassifier(publishArtifact.getClassifier());
|
||||
externalDependency.setPackaging(publishArtifact.getExtension() != null ? publishArtifact.getExtension() : "jar");
|
||||
}
|
||||
|
||||
if (!resolvedComponent.equals(resolvedGradleDep.getFrom())) {
|
||||
externalDependency.getDependencies().addAll(buildExternalDependencies(resolvedComponent.getDependencies()));
|
||||
}
|
||||
result.add(externalDependency);
|
||||
|
||||
if (!projectDepConfiguration.getName().equals(Dependency.DEFAULT_CONFIGURATION)) {
|
||||
List<File> configurationSources = new ArrayList<File>();
|
||||
PublishArtifactSet artifacts = projectDepConfiguration.getArtifacts();
|
||||
|
||||
if (artifacts != null && !artifacts.isEmpty()) {
|
||||
configurationSources.addAll(collectSourcesOfPublishedArtifacts(artifacts));
|
||||
}
|
||||
|
||||
if (!configurationSources.isEmpty()) {
|
||||
final DefaultFileCollectionDependency fileCollectionDependency = new DefaultFileCollectionDependency(configurationSources);
|
||||
fileCollectionDependency.setScope(myScope);
|
||||
result.add(fileCollectionDependency);
|
||||
resolvedDepsFiles.addAll(configurationSources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<File> collectSourcesOfPublishedArtifacts(@NotNull final PublishArtifactSet artifacts) {
|
||||
final List<File> files = new ArrayList<File>();
|
||||
|
||||
PublishArtifact artifact = artifacts.iterator().next();
|
||||
final MetaProperty taskProperty = DefaultGroovyMethods.hasProperty(artifact, "archiveTask");
|
||||
if (taskProperty != null && (taskProperty.getProperty(artifact) instanceof AbstractArchiveTask)) {
|
||||
|
||||
AbstractArchiveTask archiveTask = (AbstractArchiveTask)taskProperty.getProperty(artifact);
|
||||
resolvedDepsFiles.add(new File(archiveTask.getDestinationDir(), archiveTask.getArchiveName()));
|
||||
|
||||
try {
|
||||
final Method mainSpecGetter = AbstractCopyTask.class.getDeclaredMethod("getMainSpec");
|
||||
mainSpecGetter.setAccessible(true);
|
||||
Object mainSpec = mainSpecGetter.invoke(archiveTask);
|
||||
|
||||
final List<MetaMethod> sourcePathGetters =
|
||||
DefaultGroovyMethods.respondsTo(mainSpec, "getSourcePaths", new Object[]{});
|
||||
if (!sourcePathGetters.isEmpty()) {
|
||||
Set<Object> sourcePaths = (Set<Object>)sourcePathGetters.get(0).doMethodInvoke(mainSpec, new Object[]{});
|
||||
if (sourcePaths != null) {
|
||||
for (Object path : sourcePaths) {
|
||||
if (path instanceof String) {
|
||||
File file = new File((String)path);
|
||||
if (file.isAbsolute()) {
|
||||
files.add(file);
|
||||
if (!files.isEmpty()) {
|
||||
final DefaultFileCollectionDependency fileCollectionDependency = new DefaultFileCollectionDependency(files);
|
||||
fileCollectionDependency.setScope(scope);
|
||||
dependencies.add(fileCollectionDependency);
|
||||
resolvedDepsFiles.addAll(files);
|
||||
}
|
||||
}
|
||||
else if (path instanceof SourceSetOutput) {
|
||||
files.addAll(((SourceSetOutput)path).getFiles());
|
||||
}
|
||||
}
|
||||
|
||||
if (resolveFromArtifacts) {
|
||||
Collection<ResolvedArtifact> artifacts = artifactMap.get(componentResult.getModuleVersion());
|
||||
|
||||
if (artifacts != null && artifacts.isEmpty()) {
|
||||
dependencies.addAll(
|
||||
buildExternalDependencies(componentResult.getDependencies())
|
||||
);
|
||||
}
|
||||
|
||||
boolean first = true;
|
||||
|
||||
if (artifacts != null) {
|
||||
for (ResolvedArtifact artifact: artifacts) {
|
||||
String packaging = artifact.getExtension() != null ? artifact.getExtension() : "jar";
|
||||
String classifier = artifact.getClassifier();
|
||||
final ExternalDependency dependency;
|
||||
if (isProjectDependencyArtifact(artifact)) {
|
||||
ProjectComponentIdentifier artifactComponentIdentifier =
|
||||
(ProjectComponentIdentifier)artifact.getId().getComponentIdentifier();
|
||||
|
||||
dependency = new DefaultExternalProjectDependency();
|
||||
DefaultExternalProjectDependency dDep = (DefaultExternalProjectDependency)dependency;
|
||||
dDep.setName(name);
|
||||
dDep.setGroup(group);
|
||||
dDep.setVersion(version);
|
||||
dDep.setScope(scope);
|
||||
dDep.setSelectionReason(selectionReason);
|
||||
dDep.setProjectPath(artifactComponentIdentifier.getProjectPath());
|
||||
dDep.setConfigurationName(Dependency.DEFAULT_CONFIGURATION);
|
||||
|
||||
List<File> files = new ArrayList<File>();
|
||||
for (ResolvedArtifact resolvedArtifact : artifactMap.get(componentResult.getModuleVersion())) {
|
||||
files.add(resolvedArtifact.getFile());
|
||||
}
|
||||
dDep.setProjectDependencyArtifacts(files);
|
||||
setProjectDependencyArtifactsSources(dDep, files, mySourceSetFinder);
|
||||
resolvedDepsFiles.addAll(dDep.getProjectDependencyArtifacts());
|
||||
}
|
||||
else {
|
||||
dependency = new DefaultExternalLibraryDependency();
|
||||
DefaultExternalLibraryDependency dDep = (DefaultExternalLibraryDependency)dependency;
|
||||
dDep.setName(name);
|
||||
dDep.setGroup(group);
|
||||
dDep.setPackaging(packaging);
|
||||
dDep.setClassifier(classifier);
|
||||
dDep.setVersion(version);
|
||||
dDep.setScope(scope);
|
||||
dDep.setSelectionReason(selectionReason);
|
||||
dDep.setFile(artifact.getFile());
|
||||
|
||||
ComponentArtifactsResult artifactsResult = componentResultsMap.get(componentIdentifier);
|
||||
if (artifactsResult != null) {
|
||||
ResolvedArtifactResult sourcesResult = findMatchingArtifact(artifact, artifactsResult, SourcesArtifact.class);
|
||||
if (sourcesResult != null) {
|
||||
((DefaultExternalLibraryDependency)dependency).setSource(sourcesResult.getFile());
|
||||
}
|
||||
|
||||
ResolvedArtifactResult javadocResult = findMatchingArtifact(artifact, artifactsResult, JavadocArtifact.class);
|
||||
if (javadocResult != null) {
|
||||
((DefaultExternalLibraryDependency)dependency).setJavadoc(javadocResult.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (first) {
|
||||
dependency.getDependencies().addAll(
|
||||
buildExternalDependencies(componentResult.getDependencies())
|
||||
);
|
||||
first = false;
|
||||
}
|
||||
|
||||
dependencies.add(dependency);
|
||||
resolvedDepsFiles.add(artifact.getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
if (dependencyResult instanceof UnresolvedDependencyResult) {
|
||||
ComponentSelector attempted = ((UnresolvedDependencyResult)dependencyResult).getAttempted();
|
||||
if (attempted instanceof ModuleComponentSelector) {
|
||||
final ModuleComponentSelector attemptedMCSelector = (ModuleComponentSelector)attempted;
|
||||
final DefaultUnresolvedExternalDependency dependency = new DefaultUnresolvedExternalDependency();
|
||||
dependency.setName(attemptedMCSelector.getModule());
|
||||
dependency.setGroup(attemptedMCSelector.getGroup());
|
||||
dependency.setVersion(attemptedMCSelector.getVersion());
|
||||
dependency.setScope(scope);
|
||||
dependency.setFailureMessage(((UnresolvedDependencyResult)dependencyResult).getFailure().getMessage());
|
||||
|
||||
dependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
private ExternalLibraryDependency createExternalLibraryDep(@NotNull final ModuleVersionIdentifier moduleVersionId,
|
||||
@NotNull final String selectionReason) {
|
||||
DefaultExternalLibraryDependency dDep = new DefaultExternalLibraryDependency();
|
||||
dDep.setName(moduleVersionId.getName());
|
||||
dDep.setGroup(moduleVersionId.getGroup());
|
||||
dDep.setVersion(moduleVersionId.getVersion());
|
||||
dDep.setSelectionReason(selectionReason);
|
||||
dDep.setScope(myScope);
|
||||
return dDep;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DefaultExternalProjectDependency createExternalProjectDep(@NotNull final ModuleVersionIdentifier moduleVersionId,
|
||||
@NotNull final String selectionReason,
|
||||
@NotNull final String projectPath,
|
||||
@NotNull final String configurationName) {
|
||||
DefaultExternalProjectDependency dependency = new DefaultExternalProjectDependency();
|
||||
dependency.setName(moduleVersionId.getName());
|
||||
dependency.setGroup(moduleVersionId.getGroup());
|
||||
dependency.setVersion(moduleVersionId.getVersion());
|
||||
dependency.setScope(myScope);
|
||||
dependency.setSelectionReason(selectionReason);
|
||||
dependency.setProjectPath(projectPath);
|
||||
dependency.setConfigurationName(configurationName);
|
||||
return dependency;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DefaultUnresolvedExternalDependency createUnresolvedExternalDep(@NotNull final ModuleComponentSelector attemptedMCSelector,
|
||||
@NotNull final String message) {
|
||||
final DefaultUnresolvedExternalDependency dependency = new DefaultUnresolvedExternalDependency();
|
||||
dependency.setName(attemptedMCSelector.getModule());
|
||||
dependency.setGroup(attemptedMCSelector.getGroup());
|
||||
dependency.setVersion(attemptedMCSelector.getVersion());
|
||||
dependency.setScope(myScope);
|
||||
dependency.setFailureMessage(message);
|
||||
return dependency;
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -364,4 +326,17 @@ public class DependencyResultsTransformer {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void setProjectDependencyArtifactsSources(DefaultExternalProjectDependency projectDependency,
|
||||
Collection<File> artifactFiles,
|
||||
SourceSetCachedFinder sourceSetFinder) {
|
||||
List<File> artifactSources = new ArrayList<File>();
|
||||
for (File artifactFile : artifactFiles) {
|
||||
Set<File> sources = sourceSetFinder.findSourcesByArtifact(artifactFile.getPath());
|
||||
if (sources != null) {
|
||||
artifactSources.addAll(sources);
|
||||
}
|
||||
}
|
||||
projectDependency.setProjectDependencyArtifactsSources(artifactSources);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user