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