0
# Maven Repository Metadata
1
2
Maven Repository Metadata provides a data model and processing logic for Maven repository metadata files (`repository-metadata.xml`) that exist in Maven repositories at the directory level. It defines the structure for three types of directory metadata: groupId level (containing plugin information), groupId/artifactId level (containing versioning information), and groupId/artifactId/version level (containing snapshot-specific information).
3
4
## Package Information
5
6
- **Package Name**: maven-repository-metadata
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add as Maven dependency:
10
11
```xml
12
<dependency>
13
<groupId>org.apache.maven</groupId>
14
<artifactId>maven-repository-metadata</artifactId>
15
<version>3.9.11</version>
16
</dependency>
17
```
18
19
## Core Imports
20
21
```java
22
import org.apache.maven.artifact.repository.metadata.Metadata;
23
import org.apache.maven.artifact.repository.metadata.Versioning;
24
import org.apache.maven.artifact.repository.metadata.Snapshot;
25
import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
26
import org.apache.maven.artifact.repository.metadata.Plugin;
27
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
28
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
29
```
30
31
## Basic Usage
32
33
```java
34
import org.apache.maven.artifact.repository.metadata.Metadata;
35
import org.apache.maven.artifact.repository.metadata.Versioning;
36
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
37
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
38
import java.io.FileReader;
39
import java.io.FileWriter;
40
41
// Reading metadata from XML file
42
MetadataXpp3Reader reader = new MetadataXpp3Reader();
43
Metadata metadata = reader.read(new FileReader("repository-metadata.xml"));
44
45
// Creating new metadata programmatically
46
Metadata newMetadata = new Metadata();
47
newMetadata.setGroupId("com.example");
48
newMetadata.setArtifactId("my-library");
49
50
Versioning versioning = new Versioning();
51
versioning.addVersion("1.0.0");
52
versioning.addVersion("1.1.0");
53
versioning.setLatest("1.1.0");
54
versioning.setRelease("1.1.0");
55
versioning.updateTimestamp();
56
newMetadata.setVersioning(versioning);
57
58
// Merging metadata from different sources
59
boolean changed = existingMetadata.merge(newMetadata);
60
61
// Writing metadata to XML file
62
MetadataXpp3Writer writer = new MetadataXpp3Writer();
63
writer.write(new FileWriter("output-metadata.xml"), metadata);
64
```
65
66
## Architecture
67
68
The library is built around several key components:
69
70
- **Data Model Classes**: Type-safe objects representing metadata structure (Metadata, Versioning, Snapshot, SnapshotVersion, Plugin)
71
- **XML Processing**: Readers and writers for XML serialization using XPP3 pull parser
72
- **Modello Generation**: Classes are generated from MDO (Model Description Object) definitions
73
- **Merging Logic**: Intelligent merging capabilities for combining metadata from multiple sources
74
- **Timestamp Management**: UTC timestamp handling with proper formatting for repository operations
75
76
## Capabilities
77
78
### Core Metadata Model
79
80
Central data model classes for representing repository metadata structure and managing metadata at different directory levels.
81
82
```java { .api }
83
// Root metadata class
84
class Metadata implements Serializable, Cloneable {
85
public String getGroupId();
86
public String getArtifactId();
87
public String getVersion();
88
public Versioning getVersioning();
89
public List<Plugin> getPlugins();
90
public boolean merge(Metadata sourceMetadata);
91
}
92
93
// Version management
94
class Versioning implements Serializable, Cloneable {
95
public String getLatest();
96
public String getRelease();
97
public List<String> getVersions();
98
public String getLastUpdated();
99
public Snapshot getSnapshot();
100
public List<SnapshotVersion> getSnapshotVersions();
101
public void updateTimestamp();
102
}
103
```
104
105
[Core Metadata Model](./core-model.md)
106
107
### Snapshot Management
108
109
Comprehensive snapshot artifact handling for SNAPSHOT versions, including build numbers, timestamps, and sub-artifact tracking.
110
111
```java { .api }
112
class Snapshot implements Serializable, Cloneable {
113
public String getTimestamp();
114
public int getBuildNumber();
115
public boolean isLocalCopy();
116
}
117
118
class SnapshotVersion implements Serializable, Cloneable {
119
public String getClassifier();
120
public String getExtension();
121
public String getVersion();
122
public String getUpdated();
123
}
124
```
125
126
[Snapshot Management](./snapshot-management.md)
127
128
### Plugin Registry
129
130
Plugin mapping information for groupId-level metadata, enabling Maven plugin resolution by prefix.
131
132
```java { .api }
133
class Plugin implements Serializable, Cloneable {
134
public String getName();
135
public String getPrefix();
136
public String getArtifactId();
137
}
138
```
139
140
[Plugin Registry](./plugin-registry.md)
141
142
### XML Processing
143
144
XML reading and writing capabilities for repository metadata files with flexible parsing options and content transformation.
145
146
```java { .api }
147
class MetadataXpp3Reader {
148
public Metadata read(InputStream in) throws IOException, XmlPullParserException;
149
public Metadata read(Reader reader, boolean strict) throws IOException, XmlPullParserException;
150
}
151
152
class MetadataXpp3Writer {
153
public void write(Writer writer, Metadata metadata) throws IOException;
154
public void write(OutputStream out, Metadata metadata) throws IOException;
155
}
156
```
157
158
[XML Processing](./xml-processing.md)
159
160
## Types
161
162
```java { .api }
163
// Content transformation interface for XML reading (nested in MetadataXpp3Reader)
164
public static interface ContentTransformer {
165
String transform(String source, String fieldName);
166
}
167
```