1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.googlecode.t7mp;
17
18 import java.util.Collection;
19 import java.util.Map;
20
21 import org.apache.maven.model.Dependency;
22
23 import com.google.common.base.Predicate;
24 import com.google.common.collect.Maps;
25
26 final class FindVersionPredicate implements Predicate<Dependency> {
27
28 private final Map<String, AbstractArtifact> searchMap = Maps.newHashMap();
29 private final PluginLog log;
30
31 public FindVersionPredicate(Collection<AbstractArtifact> noVersionArtifacts, PluginLog log) {
32 this.log = log;
33 for (AbstractArtifact artifact : noVersionArtifacts) {
34 String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getClassifier();
35 log.debug("put key [" + key + "] to map for artifact [" + artifact + "]");
36 searchMap.put(key, artifact);
37 }
38 }
39
40 @Override
41 public boolean apply(Dependency artifact) {
42 String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":" + artifact.getClassifier();
43 log.debug("Search with key [" + key + "] for artifact " + artifact.toString());
44 if (searchMap.containsKey(key)) {
45 log.debug("Found something with key [" + key + "] for artifact " + artifact.toString());
46 searchMap.get(key).setVersion(artifact.getVersion());
47 return true;
48 }
49 return false;
50 }
51
52 }