View Javadoc

1   /**
2    * Copyright (C) 2010-2012 Joerg Bellmann <joerg.bellmann@googlemail.com>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }