1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.nuxeo.build.ant.artifact;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.StringTokenizer;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Project;
28 import org.eclipse.aether.graph.DependencyNode;
29 import org.eclipse.aether.util.artifact.JavaScopes;
30 import org.nuxeo.build.maven.filter.Filter;
31
32
33
34
35 public class NuxeoExpandTask extends ExpandTask {
36
37 private Map<String, Boolean> includedScopes = new HashMap<>();
38
39 private boolean includeCompileScope = true;
40
41 private boolean includeProvidedScope = false;
42
43 private boolean includeRuntimeScope = true;
44
45 private boolean includeTestScope = false;
46
47 private boolean includeSystemScope = true;
48
49 private String[] groupPrefixes = new String[] { "org.nuxeo" };
50
51
52
53
54
55 public void setGroupPrefixes(String groupPrefixes) {
56 List<String> prefixes = new ArrayList<>();
57 StringTokenizer st = new StringTokenizer(groupPrefixes, ",");
58 while (st.hasMoreTokens()) {
59 prefixes.add(st.nextToken());
60 }
61 this.groupPrefixes = prefixes.toArray(new String[0]);
62 }
63
64 public NuxeoExpandTask() {
65 super();
66 setDepth("all");
67 }
68
69 @Override
70 public void execute() throws BuildException {
71 getIncludedScopes().put(JavaScopes.COMPILE, includeCompileScope);
72 getIncludedScopes().put(JavaScopes.PROVIDED, includeProvidedScope);
73 getIncludedScopes().put(JavaScopes.RUNTIME, includeRuntimeScope);
74 getIncludedScopes().put(JavaScopes.TEST, includeTestScope);
75 getIncludedScopes().put(JavaScopes.SYSTEM, includeSystemScope);
76
77 filter.addFilter(new Filter() {
78
79 @Override
80 public boolean accept(Artifact artifact) {
81 return true;
82 }
83
84 @Override
85 public boolean accept(DependencyNode node,
86 List<DependencyNode> parents) {
87 if (node.getDependency().isOptional()) {
88 return false;
89 }
90 if ("".equals(node.getDependency().getScope())) {
91 log("Node with no scope accepted (root node?): " + node,
92 Project.MSG_DEBUG);
93 return true;
94 }
95 return getIncludedScopes().get(node.getDependency().getScope());
96 }
97 });
98 super.execute();
99 }
100
101 @Override
102 protected boolean acceptNode(DependencyNode node) {
103 for (String prefix : groupPrefixes) {
104 if (node.getArtifact().getGroupId().startsWith(prefix)) {
105 return true;
106 }
107 }
108 return false;
109 }
110
111
112
113
114 protected Map<String, Boolean> getIncludedScopes() {
115 return includedScopes;
116 }
117
118
119
120
121 public void setIncludeCompileScope(boolean includeCompileScope) {
122 this.includeCompileScope = includeCompileScope;
123 }
124
125
126
127
128 public void setIncludeProvidedScope(boolean includeProvidedScope) {
129 this.includeProvidedScope = includeProvidedScope;
130 }
131
132
133
134
135 public void setIncludeRuntimeScope(boolean includeRuntimeScope) {
136 this.includeRuntimeScope = includeRuntimeScope;
137 }
138
139
140
141
142 public void setIncludeTestScope(boolean includeTestScope) {
143 this.includeTestScope = includeTestScope;
144 }
145
146
147
148
149 public void setIncludeSystemScope(boolean includeSystemScope) {
150 this.includeSystemScope = includeSystemScope;
151 }
152 }