1 | |
package org.apache.maven.index.creator; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.io.IOException; |
24 | |
import java.util.Arrays; |
25 | |
import java.util.Collection; |
26 | |
import java.util.Collections; |
27 | |
|
28 | |
import org.apache.lucene.document.Document; |
29 | |
import org.apache.maven.index.ArtifactContext; |
30 | |
import org.apache.maven.index.ArtifactInfo; |
31 | |
import org.apache.maven.index.IndexerField; |
32 | |
import org.apache.maven.index.context.IndexCreator; |
33 | |
import org.apache.maven.index.util.zip.ZipFacade; |
34 | |
import org.apache.maven.index.util.zip.ZipHandle; |
35 | |
import org.codehaus.plexus.component.annotations.Component; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
@Component( role = IndexCreator.class, hint = MavenArchetypeArtifactInfoIndexCreator.ID ) |
46 | |
public class MavenArchetypeArtifactInfoIndexCreator |
47 | |
extends AbstractIndexCreator |
48 | |
{ |
49 | |
public static final String ID = "maven-archetype"; |
50 | |
|
51 | |
private static final String MAVEN_ARCHETYPE_PACKAGING = "maven-archetype"; |
52 | |
|
53 | 1 | private static final String[] ARCHETYPE_XML_LOCATIONS = { "META-INF/maven/archetype.xml", "META-INF/archetype.xml", |
54 | |
"META-INF/maven/archetype-metadata.xml" }; |
55 | |
|
56 | |
public MavenArchetypeArtifactInfoIndexCreator() |
57 | |
{ |
58 | 200 | super( ID, Arrays.asList( MinimalArtifactInfoIndexCreator.ID ) ); |
59 | 200 | } |
60 | |
|
61 | |
public void populateArtifactInfo( ArtifactContext ac ) |
62 | |
{ |
63 | 5236 | File artifact = ac.getArtifact(); |
64 | |
|
65 | 5236 | ArtifactInfo ai = ac.getArtifactInfo(); |
66 | |
|
67 | |
|
68 | 5236 | if ( artifact != null && artifact.isFile() && !MAVEN_ARCHETYPE_PACKAGING.equals( ai.packaging ) |
69 | |
&& artifact.getName().endsWith( ".jar" ) ) |
70 | |
{ |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 4161 | checkMavenArchetype( ai, artifact ); |
76 | |
} |
77 | 5236 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
private void checkMavenArchetype( ArtifactInfo ai, File artifact ) |
86 | |
{ |
87 | 4161 | ZipHandle handle = null; |
88 | |
|
89 | |
try |
90 | |
{ |
91 | 4161 | handle = ZipFacade.getZipHandle( artifact ); |
92 | |
|
93 | 15279 | for ( String path : ARCHETYPE_XML_LOCATIONS ) |
94 | |
{ |
95 | 11573 | if ( handle.hasEntry( path ) ) |
96 | |
{ |
97 | 364 | ai.packaging = MAVEN_ARCHETYPE_PACKAGING; |
98 | |
|
99 | |
return; |
100 | |
} |
101 | |
} |
102 | |
} |
103 | 91 | catch ( Exception e ) |
104 | |
{ |
105 | 91 | if ( getLogger().isDebugEnabled() ) |
106 | |
{ |
107 | 0 | getLogger().info( |
108 | |
"Failed to parse Maven artifact " + artifact.getAbsolutePath() + " due to exception:", e ); |
109 | |
} |
110 | |
else |
111 | |
{ |
112 | 91 | getLogger().info( |
113 | |
"Failed to parse Maven artifact " + artifact.getAbsolutePath() + " due to " + e.getMessage() ); |
114 | |
} |
115 | |
} |
116 | |
finally |
117 | |
{ |
118 | 0 | try |
119 | |
{ |
120 | 4161 | ZipFacade.close( handle ); |
121 | |
} |
122 | 0 | catch ( IOException ex ) |
123 | |
{ |
124 | 4525 | } |
125 | 0 | } |
126 | 3797 | } |
127 | |
|
128 | |
public void updateDocument( ArtifactInfo ai, Document doc ) |
129 | |
{ |
130 | |
|
131 | 6348 | } |
132 | |
|
133 | |
public boolean updateArtifactInfo( Document doc, ArtifactInfo ai ) |
134 | |
{ |
135 | |
|
136 | |
|
137 | 221519 | return false; |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
@Override |
143 | |
public String toString() |
144 | |
{ |
145 | 0 | return ID; |
146 | |
} |
147 | |
|
148 | |
public Collection<IndexerField> getIndexerFields() |
149 | |
{ |
150 | |
|
151 | 329 | return Collections.emptyList(); |
152 | |
} |
153 | |
} |