1 package org.apache.maven.shared.jar.identification.exposers;
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.artifact.Artifact;
23 import org.apache.maven.shared.jar.JarAnalyzer;
24 import org.apache.maven.shared.jar.identification.JarIdentification;
25 import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
26 import org.apache.maven.shared.jar.identification.hash.JarHashAnalyzer;
27 import org.apache.maven.shared.jar.identification.repository.RepositoryHashSearch;
28 import org.codehaus.plexus.logging.AbstractLogEnabled;
29
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
33
34
35
36
37
38
39
40
41
42
43
44
45 public class RepositorySearchExposer
46 extends AbstractLogEnabled
47 implements JarIdentificationExposer
48 {
49
50
51
52
53
54
55 private RepositoryHashSearch repositoryHashSearch;
56
57
58
59
60
61
62 private JarHashAnalyzer fileHashAnalyzer;
63
64
65
66
67
68
69 private JarHashAnalyzer bytecodeHashAnalyzer;
70
71 public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
72 {
73 List repohits = new ArrayList();
74
75 String hash = fileHashAnalyzer.computeHash( jarAnalyzer );
76 if ( hash != null )
77 {
78 repohits.addAll( repositoryHashSearch.searchFileHash( hash ) );
79 }
80
81 String bytecodehash = bytecodeHashAnalyzer.computeHash( jarAnalyzer );
82 if ( bytecodehash != null )
83 {
84 repohits.addAll( repositoryHashSearch.searchBytecodeHash( bytecodehash ) );
85 }
86
87 if ( !repohits.isEmpty() )
88 {
89
90 Iterator it = repohits.iterator();
91 while ( it.hasNext() )
92 {
93 Artifact artifact = (Artifact) it.next();
94 identification.addAndSetGroupId( artifact.getGroupId() );
95 identification.addAndSetArtifactId( artifact.getArtifactId() );
96 identification.addAndSetVersion( artifact.getVersion() );
97 }
98 }
99 }
100
101 public void setRepositoryHashSearch( RepositoryHashSearch repo )
102 {
103 this.repositoryHashSearch = repo;
104 }
105
106 public void setFileHashAnalyzer( JarHashAnalyzer fileHashAnalyzer )
107 {
108 this.fileHashAnalyzer = fileHashAnalyzer;
109 }
110
111 public void setBytecodeHashAnalyzer( JarHashAnalyzer bytecodeHashAnalyzer )
112 {
113 this.bytecodeHashAnalyzer = bytecodeHashAnalyzer;
114 }
115 }