This project has retired. For details please refer to its
Attic page.
MavenMetadataReader xref
1 package org.apache.archiva.maven2.metadata;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.archiva.model.ArchivaRepositoryMetadata;
22 import org.apache.archiva.model.Plugin;
23 import org.apache.archiva.model.SnapshotVersion;
24 import org.apache.archiva.xml.XMLException;
25 import org.apache.archiva.xml.XMLReader;
26 import org.apache.commons.lang.math.NumberUtils;
27 import org.dom4j.Element;
28
29 import java.io.File;
30 import java.util.Date;
31
32
33
34
35
36 public class MavenMetadataReader
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public static ArchivaRepositoryMetadata read( File metadataFile )
69 throws XMLException
70 {
71
72 XMLReader xml = new XMLReader( "metadata", metadataFile );
73
74 xml.removeNamespaces();
75
76 ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
77
78 metadata.setGroupId( xml.getElementText( "//metadata/groupId" ) );
79 metadata.setArtifactId( xml.getElementText( "//metadata/artifactId" ) );
80 metadata.setVersion( xml.getElementText( "//metadata/version" ) );
81 metadata.setFileLastModified( new Date( metadataFile.lastModified() ) );
82 metadata.setFileSize( metadataFile.length() );
83
84 metadata.setLastUpdated( xml.getElementText( "//metadata/versioning/lastUpdated" ) );
85 metadata.setLatestVersion( xml.getElementText( "//metadata/versioning/latest" ) );
86 metadata.setReleasedVersion( xml.getElementText( "//metadata/versioning/release" ) );
87 metadata.setAvailableVersions( xml.getElementListText( "//metadata/versioning/versions/version" ) );
88
89 Element snapshotElem = xml.getElement( "//metadata/versioning/snapshot" );
90 if ( snapshotElem != null )
91 {
92 SnapshotVersion snapshot = new SnapshotVersion();
93 snapshot.setTimestamp( snapshotElem.elementTextTrim( "timestamp" ) );
94 String tmp = snapshotElem.elementTextTrim( "buildNumber" );
95 if ( NumberUtils.isNumber( tmp ) )
96 {
97 snapshot.setBuildNumber( NumberUtils.toInt( tmp ) );
98 }
99 metadata.setSnapshotVersion( snapshot );
100 }
101
102 for ( Element plugin : xml.getElementList( "//metadata/plugins/plugin" ) )
103 {
104 Plugin p = new Plugin();
105 p.setPrefix( plugin.elementTextTrim( "prefix" ) );
106 p.setArtifactId( plugin.elementTextTrim( "artifactId" ) );
107 p.setName( plugin.elementTextTrim( "name" ) );
108 metadata.addPlugin( p );
109 }
110
111 return metadata;
112
113 }
114 }