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.*;
22
23 import org.apache.maven.project.MavenProject;
24
25
26
27
28
29
30
31
32
33
34 public class DependencyContext {
35
36 private final MavenProject project;
37
38 private final Collection<String> scopesToCollectForCurrentProject;
39
40 private final Collection<String> scopesToResolveForCurrentProject;
41
42 private final Collection<String> scopesToCollectForAggregatedProjects;
43
44 private final Collection<String> scopesToResolveForAggregatedProjects;
45
46 private volatile Collection<?> lastDependencyArtifacts = Collections.emptyList();
47
48 private volatile int lastDependencyArtifactCount = -1;
49
50 public DependencyContext(
51 MavenProject project, Collection<String> scopesToCollect, Collection<String> scopesToResolve) {
52 this.project = project;
53 scopesToCollectForCurrentProject = scopesToCollect;
54 scopesToResolveForCurrentProject = scopesToResolve;
55 scopesToCollectForAggregatedProjects = Collections.synchronizedSet(new TreeSet<>());
56 scopesToResolveForAggregatedProjects = Collections.synchronizedSet(new TreeSet<>());
57 }
58
59 public MavenProject getProject() {
60 return project;
61 }
62
63 public Collection<String> getScopesToCollectForCurrentProject() {
64 return scopesToCollectForCurrentProject;
65 }
66
67 public Collection<String> getScopesToResolveForCurrentProject() {
68 return scopesToResolveForCurrentProject;
69 }
70
71 public Collection<String> getScopesToCollectForAggregatedProjects() {
72 return scopesToCollectForAggregatedProjects;
73 }
74
75 public Collection<String> getScopesToResolveForAggregatedProjects() {
76 return scopesToResolveForAggregatedProjects;
77 }
78
79 public boolean isResolutionRequiredForCurrentProject() {
80 return lastDependencyArtifacts != project.getDependencyArtifacts()
81 || (lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size());
82 }
83
84 public boolean isResolutionRequiredForAggregatedProjects(
85 Collection<String> scopesToCollect, Collection<String> scopesToResolve) {
86 return scopesToCollectForAggregatedProjects.addAll(scopesToCollect)
87 || scopesToResolveForAggregatedProjects.addAll(scopesToResolve);
88 }
89
90 public void synchronizeWithProjectState() {
91 lastDependencyArtifacts = project.getDependencyArtifacts();
92 lastDependencyArtifactCount = (lastDependencyArtifacts != null) ? lastDependencyArtifacts.size() : 0;
93 }
94 }