aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-maven2-metadata
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-03-11 23:58:01 +0000
committerOlivier Lamy <olamy@apache.org>2012-03-11 23:58:01 +0000
commitcf74f31f832b0a175b5063299f9abd19349967a3 (patch)
tree6c451dc52ac8fc3b014e2f33928aee61629f035a /archiva-modules/archiva-base/archiva-maven2-metadata
parentf2557bd4765f0e6e63c5acc3c97923ae026ba489 (diff)
downloadarchiva-cf74f31f832b0a175b5063299f9abd19349967a3.tar.gz
archiva-cf74f31f832b0a175b5063299f9abd19349967a3.zip
[MRM-1567] Artifact data incomplete.
move MavenMetadataReader to a new module to avoid cyclic dependency. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1299489 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-maven2-metadata')
-rw-r--r--archiva-modules/archiva-base/archiva-maven2-metadata/pom.xml49
-rw-r--r--archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java114
2 files changed, 163 insertions, 0 deletions
diff --git a/archiva-modules/archiva-base/archiva-maven2-metadata/pom.xml b/archiva-modules/archiva-base/archiva-maven2-metadata/pom.xml
new file mode 100644
index 000000000..14da7c7ff
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-maven2-metadata/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>archiva-base</artifactId>
+ <groupId>org.apache.archiva</groupId>
+ <version>1.4-M3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>archiva-maven2-metadata</artifactId>
+ <version>1.4-M3-SNAPSHOT</version>
+
+ <name>archiva-maven2-metadata</name>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-xml-tools</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java b/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java
new file mode 100644
index 000000000..ade5a1fc0
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java
@@ -0,0 +1,114 @@
+package org.apache.archiva.maven2.metadata;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.model.ArchivaRepositoryMetadata;
+import org.apache.archiva.model.Plugin;
+import org.apache.archiva.model.SnapshotVersion;
+import org.apache.archiva.xml.XMLException;
+import org.apache.archiva.xml.XMLReader;
+import org.apache.commons.lang.math.NumberUtils;
+import org.dom4j.Element;
+
+import java.io.File;
+import java.util.Date;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+public class MavenMetadataReader
+{
+ /*
+ <?xml version="1.0" encoding="UTF-8"?>
+ <metadata modelVersion="1.1.0">
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva</artifactId>
+ <version>1.4-M3-SNAPSHOT</version>
+ <versioning>
+ <snapshot>
+ <timestamp>20120310.230917</timestamp>
+ <buildNumber>2</buildNumber>
+ </snapshot>
+ <lastUpdated>20120310230917</lastUpdated>
+ <snapshotVersions>
+ <snapshotVersion>
+ <extension>pom</extension>
+ <value>1.4-M3-20120310.230917-2</value>
+ <updated>20120310230917</updated>
+ </snapshotVersion>
+ </snapshotVersions>
+ </versioning>
+ </metadata>
+ */
+
+ /**
+ * Read and return the {@link org.apache.archiva.model.ArchivaRepositoryMetadata} object from the provided xml file.
+ *
+ * @param metadataFile the maven-metadata.xml file to read.
+ * @return the archiva repository metadata object that represents the provided file contents.
+ * @throws XMLException
+ */
+ public static ArchivaRepositoryMetadata read( File metadataFile )
+ throws XMLException
+ {
+
+ XMLReader xml = new XMLReader( "metadata", metadataFile );
+ // invoke this to remove namespaces, see MRM-1136
+ xml.removeNamespaces();
+
+ ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
+
+ metadata.setGroupId( xml.getElementText( "//metadata/groupId" ) );
+ metadata.setArtifactId( xml.getElementText( "//metadata/artifactId" ) );
+ metadata.setVersion( xml.getElementText( "//metadata/version" ) );
+ metadata.setFileLastModified( new Date( metadataFile.lastModified() ) );
+ metadata.setFileSize( metadataFile.length() );
+
+ metadata.setLastUpdated( xml.getElementText( "//metadata/versioning/lastUpdated" ) );
+ metadata.setLatestVersion( xml.getElementText( "//metadata/versioning/latest" ) );
+ metadata.setReleasedVersion( xml.getElementText( "//metadata/versioning/release" ) );
+ metadata.setAvailableVersions( xml.getElementListText( "//metadata/versioning/versions/version" ) );
+
+ Element snapshotElem = xml.getElement( "//metadata/versioning/snapshot" );
+ if ( snapshotElem != null )
+ {
+ SnapshotVersion snapshot = new SnapshotVersion();
+ snapshot.setTimestamp( snapshotElem.elementTextTrim( "timestamp" ) );
+ String tmp = snapshotElem.elementTextTrim( "buildNumber" );
+ if ( NumberUtils.isNumber( tmp ) )
+ {
+ snapshot.setBuildNumber( NumberUtils.toInt( tmp ) );
+ }
+ metadata.setSnapshotVersion( snapshot );
+ }
+
+ for ( Element plugin : xml.getElementList( "//metadata/plugins/plugin" ) )
+ {
+ Plugin p = new Plugin();
+ p.setPrefix( plugin.elementTextTrim( "prefix" ) );
+ p.setArtifactId( plugin.elementTextTrim( "artifactId" ) );
+ p.setName( plugin.elementTextTrim( "name" ) );
+ metadata.addPlugin( p );
+ }
+
+ return metadata;
+
+ }
+}