1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.lifecycle.internal;
20
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.TreeSet;
25
26 import org.apache.maven.project.MavenProject;
27
28
29
30
31
32
33
34
35
36
37 public class DependencyContext {
38
39 private static final Collection<?> UNRESOLVED = Arrays.asList();
40
41 private final MavenProject project;
42
43 private final Collection<String> scopesToCollectForCurrentProject;
44
45 private final Collection<String> scopesToResolveForCurrentProject;
46
47 private final Collection<String> scopesToCollectForAggregatedProjects;
48
49 private final Collection<String> scopesToResolveForAggregatedProjects;
50
51 private volatile Collection<?> lastDependencyArtifacts = UNRESOLVED;
52
53 private volatile int lastDependencyArtifactCount = -1;
54
55 public DependencyContext(
56 MavenProject project, Collection<String> scopesToCollect, Collection<String> scopesToResolve) {
57 this.project = project;
58 scopesToCollectForCurrentProject = scopesToCollect;
59 scopesToResolveForCurrentProject = scopesToResolve;
60 scopesToCollectForAggregatedProjects = Collections.synchronizedSet(new TreeSet<>());
61 scopesToResolveForAggregatedProjects = Collections.synchronizedSet(new TreeSet<>());
62 }
63
64 public MavenProject getProject() {
65 return project;
66 }
67
68 public Collection<String> getScopesToCollectForCurrentProject() {
69 return scopesToCollectForCurrentProject;
70 }
71
72 public Collection<String> getScopesToResolveForCurrentProject() {
73 return scopesToResolveForCurrentProject;
74 }
75
76 public Collection<String> getScopesToCollectForAggregatedProjects() {
77 return scopesToCollectForAggregatedProjects;
78 }
79
80 public Collection<String> getScopesToResolveForAggregatedProjects() {
81 return scopesToResolveForAggregatedProjects;
82 }
83
84 public boolean isResolutionRequiredForCurrentProject() {
85 return lastDependencyArtifacts != project.getDependencyArtifacts()
86 || (lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size());
87 }
88
89 public boolean isResolutionRequiredForAggregatedProjects(
90 Collection<String> scopesToCollect, Collection<String> scopesToResolve) {
91 return scopesToCollectForAggregatedProjects.addAll(scopesToCollect)
92 || scopesToResolveForAggregatedProjects.addAll(scopesToResolve);
93 }
94
95 public void synchronizeWithProjectState() {
96 lastDependencyArtifacts = project.getDependencyArtifacts();
97 lastDependencyArtifactCount = (lastDependencyArtifacts != null) ? lastDependencyArtifacts.size() : 0;
98 }
99 }