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
46 public class RepositorySearchExposer
47 extends AbstractLogEnabled
48 implements JarIdentificationExposer
49 {
50
51
52
53
54
55
56 private RepositoryHashSearch repositoryHashSearch;
57
58
59
60
61
62
63 private JarHashAnalyzer fileHashAnalyzer;
64
65
66
67
68
69
70 private JarHashAnalyzer bytecodeHashAnalyzer;
71
72 public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
73 {
74 List repohits = new ArrayList();
75
76 String hash = fileHashAnalyzer.computeHash( jarAnalyzer );
77 if ( hash != null )
78 {
79 repohits.addAll( repositoryHashSearch.searchFileHash( hash ) );
80 }
81
82 String bytecodehash = bytecodeHashAnalyzer.computeHash( jarAnalyzer );
83 if ( bytecodehash != null )
84 {
85 repohits.addAll( repositoryHashSearch.searchBytecodeHash( bytecodehash ) );
86 }
87
88 if ( !repohits.isEmpty() )
89 {
90
91 Iterator it = repohits.iterator();
92 while ( it.hasNext() )
93 {
94 Artifact artifact = (Artifact) it.next();
95 identification.addAndSetGroupId( artifact.getGroupId() );
96 identification.addAndSetArtifactId( artifact.getArtifactId() );
97 identification.addAndSetVersion( artifact.getVersion() );
98 }
99 }
100 }
101
102 public void setRepositoryHashSearch( RepositoryHashSearch repo )
103 {
104 this.repositoryHashSearch = repo;
105 }
106
107 public void setFileHashAnalyzer( JarHashAnalyzer fileHashAnalyzer )
108 {
109 this.fileHashAnalyzer = fileHashAnalyzer;
110 }
111
112 public void setBytecodeHashAnalyzer( JarHashAnalyzer bytecodeHashAnalyzer )
113 {
114 this.bytecodeHashAnalyzer = bytecodeHashAnalyzer;
115 }
116 }