1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.internal.ant.tasks;
20
21 import org.apache.maven.resolver.internal.ant.AntRepoSys;
22 import org.apache.maven.resolver.internal.ant.types.Dependencies;
23 import org.apache.maven.resolver.internal.ant.types.LocalRepository;
24 import org.apache.maven.resolver.internal.ant.types.RemoteRepositories;
25 import org.apache.maven.resolver.internal.ant.types.RemoteRepository;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Task;
28 import org.apache.tools.ant.types.Reference;
29 import org.eclipse.aether.collection.CollectResult;
30
31
32
33 public abstract class AbstractResolvingTask extends Task {
34
35 protected Dependencies dependencies;
36
37 protected RemoteRepositories remoteRepositories;
38
39 protected LocalRepository localRepository;
40
41 public void addDependencies(final Dependencies dependencies) {
42 if (this.dependencies != null) {
43 throw new BuildException("You must not specify multiple <dependencies> elements");
44 }
45 this.dependencies = dependencies;
46 }
47
48 public void setDependenciesRef(final Reference ref) {
49 if (dependencies == null) {
50 dependencies = new Dependencies();
51 dependencies.setProject(getProject());
52 }
53 dependencies.setRefid(ref);
54 }
55
56 public LocalRepository createLocalRepo() {
57 if (localRepository != null) {
58 throw new BuildException("You must not specify multiple <localRepo> elements");
59 }
60 localRepository = new LocalRepository(this);
61 return localRepository;
62 }
63
64 private RemoteRepositories getRemoteRepos() {
65 if (remoteRepositories == null) {
66 remoteRepositories = new RemoteRepositories();
67 remoteRepositories.setProject(getProject());
68 }
69 return remoteRepositories;
70 }
71
72 public void addRemoteRepo(final RemoteRepository repository) {
73 getRemoteRepos().addRemoterepo(repository);
74 }
75
76 public void addRemoteRepos(final RemoteRepositories repositories) {
77 getRemoteRepos().addRemoterepos(repositories);
78 }
79
80 public void setRemoteReposRef(final Reference ref) {
81 final RemoteRepositories repos = new RemoteRepositories();
82 repos.setProject(getProject());
83 repos.setRefid(ref);
84 getRemoteRepos().addRemoterepos(repos);
85 }
86
87 protected CollectResult collectDependencies() {
88 return AntRepoSys.getInstance(getProject())
89 .collectDependencies(this, dependencies, localRepository, remoteRepositories);
90 }
91 }