<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-builder</artifactId>
- <version>3.0-alpha-4</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
- <version>1.3-SNAPSHOT</version>
+ </dependency>
+ <!-- TODO: aim to remove this dependency -->
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-xml-tools</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
import java.io.File;
import java.util.Collection;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.xml.XMLException;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.DefaultModelBuildingRequest;
import org.apache.maven.model.building.ModelBuilder;
throw new UnsupportedOperationException();
}
- public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
+ public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
+ String projectVersion )
{
// TODO: artifactVersion translation
ManagedRepositoryConfiguration repositoryConfiguration =
archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
+ String artifactVersion = projectVersion;
+
File basedir = new File( repositoryConfiguration.getLocation() );
- File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, projectId + "-" +
- projectVersion + ".pom" );
+ if ( VersionUtil.isSnapshot( projectVersion ) )
+ {
+ // TODO: need much error handling here for incorrect metadata
+ try
+ {
+ MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read(
+ pathTranslator.toFile( basedir, namespace, projectId, projectVersion, "maven-metadata.xml" ) );
+
+ artifactVersion =
+ artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end
+ MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
+ artifactVersion =
+ artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
+ }
+ catch ( XMLException e )
+ {
+ // TODO: handle it
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion,
+ projectId + "-" + artifactVersion + ".pom" );
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setProcessPlugins( false );
return metadata;
}
- public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion )
+ public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
+ String projectVersion )
{
throw new UnsupportedOperationException();
}
--- /dev/null
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+public class MavenRepositoryMetadata
+{
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
+
+ private String lastUpdated;
+
+ private String latestVersion;
+
+ private String releasedVersion;
+
+ private List<String> availableVersions;
+
+ private Snapshot snapshotVersion;
+
+ private List<Plugin> plugins = new ArrayList<Plugin>();
+
+ public List<Plugin> getPlugins()
+ {
+ return plugins;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ public void setLastUpdated( String lastUpdated )
+ {
+ this.lastUpdated = lastUpdated;
+ }
+
+ public void setLatestVersion( String latestVersion )
+ {
+ this.latestVersion = latestVersion;
+ }
+
+ public void setReleasedVersion( String releasedVersion )
+ {
+ this.releasedVersion = releasedVersion;
+ }
+
+ public void setAvailableVersions( List<String> availableVersions )
+ {
+ this.availableVersions = availableVersions;
+ }
+
+ public void setSnapshotVersion( Snapshot snapshotVersion )
+ {
+ this.snapshotVersion = snapshotVersion;
+ }
+
+ public void addPlugin( Plugin plugin )
+ {
+ this.plugins.add( plugin );
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public String getLastUpdated()
+ {
+ return lastUpdated;
+ }
+
+ public String getLatestVersion()
+ {
+ return latestVersion;
+ }
+
+ public String getReleasedVersion()
+ {
+ return releasedVersion;
+ }
+
+ public List<String> getAvailableVersions()
+ {
+ return availableVersions;
+ }
+
+ public Snapshot getSnapshotVersion()
+ {
+ return snapshotVersion;
+ }
+
+ public static class Snapshot
+ {
+ private String timestamp;
+
+ private int buildNumber;
+
+ public void setTimestamp( String timestamp )
+ {
+ this.timestamp = timestamp;
+ }
+
+ public void setBuildNumber( int buildNumber )
+ {
+ this.buildNumber = buildNumber;
+ }
+
+ public int getBuildNumber()
+ {
+ return buildNumber;
+ }
+
+ public String getTimestamp()
+ {
+ return timestamp;
+ }
+ }
+
+ public static class Plugin
+ {
+ private String prefix;
+
+ private String artifactId;
+
+ private String name;
+
+ public void setPrefix( String prefix )
+ {
+ this.prefix = prefix;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public String getPrefix()
+ {
+ return prefix;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+ }
+}
--- /dev/null
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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 java.io.File;
+
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.maven.archiva.xml.XMLException;
+import org.apache.maven.archiva.xml.XMLReader;
+import org.dom4j.Element;
+
+/**
+ * RepositoryMetadataReader - read maven-metadata.xml files.
+ *
+ * TODO: we should improve on this, ideally using the Maven standard libraries (which are unfortunately baked into
+ * maven-core now)
+ */
+public final class MavenRepositoryMetadataReader
+{
+ private MavenRepositoryMetadataReader()
+ {
+ }
+
+ /**
+ * Read and return the {@link MavenRepositoryMetadata} 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 org.apache.maven.archiva.xml.XMLException
+ */
+ public static MavenRepositoryMetadata read( File metadataFile )
+ throws XMLException
+ {
+ XMLReader xml = new XMLReader( "metadata", metadataFile );
+ // invoke this to remove namespaces, see MRM-1136
+ xml.removeNamespaces();
+
+ MavenRepositoryMetadata metadata = new MavenRepositoryMetadata();
+
+ metadata.setGroupId( xml.getElementText( "//metadata/groupId" ) );
+ metadata.setArtifactId( xml.getElementText( "//metadata/artifactId" ) );
+ metadata.setVersion( xml.getElementText( "//metadata/version" ) );
+
+ 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 )
+ {
+ MavenRepositoryMetadata.Snapshot snapshot = new MavenRepositoryMetadata.Snapshot();
+ 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" ) )
+ {
+ MavenRepositoryMetadata.Plugin p = new MavenRepositoryMetadata.Plugin();
+ p.setPrefix( plugin.elementTextTrim( "prefix" ) );
+ p.setArtifactId( plugin.elementTextTrim( "artifactId" ) );
+ p.setName( plugin.elementTextTrim( "name" ) );
+ metadata.addPlugin( p );
+ }
+
+ return metadata;
+ }
+}
\ No newline at end of file
// TODO: more testing
}
-// public void testGetProjectVersionMetadataForTimestampedSnapshot()
-// {
-// ProjectVersionMetadata metadata =
-// resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
-// MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
-// assertEquals( "jar", facet.getPackaging() );
-// assertEquals( "http://www.apache.org/", metadata.getUrl() );
-// // TODO: more testing
-// }
+ public void testGetProjectVersionMetadataForTimestampedSnapshot()
+ {
+ ProjectVersionMetadata metadata =
+ resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
+ MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
+ assertEquals( "pom", facet.getPackaging() );
+ assertEquals( "http://www.apache.org/", metadata.getUrl() );
+ // TODO: more testing
+ }
}
--- /dev/null
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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 java.io.File;
+import java.util.Arrays;
+
+import org.apache.maven.archiva.xml.XMLException;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+/**
+ * RepositoryMetadataReaderTest
+ *
+ * @version $Id$
+ */
+public class MavenRepositoryMetadataReaderTest
+ extends PlexusInSpringTestCase
+{
+ public void testProjectMetadata()
+ throws XMLException
+ {
+ File defaultRepoDir = new File( getBasedir(), "src/test/repositories/test" );
+ File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
+
+ MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
+
+ assertNotNull( metadata );
+ assertEquals( "org.apache.maven.shared", metadata.getGroupId() );
+ assertEquals( "maven-downloader", metadata.getArtifactId() );
+ assertEquals( "1.1", metadata.getReleasedVersion() );
+ assertNull( metadata.getLatestVersion() );
+ assertEquals( Arrays.asList( "1.0", "1.1" ), metadata.getAvailableVersions() );
+ assertNull( metadata.getSnapshotVersion() );
+ assertEquals( "20061212214311", metadata.getLastUpdated() );
+ }
+
+ public void testProjectVersionMetadata()
+ throws XMLException
+ {
+ File defaultRepoDir = new File( getBasedir(), "src/test/repositories/test" );
+ File metadataFile = new File( defaultRepoDir, "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" );
+
+ MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
+
+ assertNotNull( metadata );
+ assertEquals( "org.apache", metadata.getGroupId() );
+ assertEquals( "apache", metadata.getArtifactId() );
+ assertNull( metadata.getReleasedVersion() );
+ assertNull( metadata.getLatestVersion() );
+ assertTrue( metadata.getAvailableVersions().isEmpty() );
+ assertNotNull( metadata.getSnapshotVersion() );
+ assertEquals( "20080801.151215", metadata.getSnapshotVersion().getTimestamp() );
+ assertEquals( 1, metadata.getSnapshotVersion().getBuildNumber() );
+ assertEquals( "20080801151215", metadata.getLastUpdated() );
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Shared parent. Doesn't define a lot of things about Apache like general mailing lists, but does
+ define the settings common to all projects at Apache -->
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>5-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>The Apache Software Foundation</name>
+ <description>
+ The Apache Software Foundation provides support for the Apache community of open-source software projects.
+ The Apache projects are characterized by a collaborative, consensus based development process, an open and
+ pragmatic software license, and a desire to create high quality software that leads the way in its field.
+ We consider ourselves not simply a group of projects sharing a server, but rather a community of developers
+ and users.
+ </description>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <organization>
+ <name>The Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+ <url>http://www.apache.org/</url>
+ <repositories>
+ <repository>
+ <id>apache.snapshots</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://people.apache.org/repo/m2-snapshot-repository</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+ </repositories>
+ <distributionManagement>
+ <!-- Site omitted - each project must provide their own -->
+ <repository>
+ <id>apache.releases</id>
+ <name>Apache Release Distribution Repository</name>
+ <url>scp://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository</url>
+ </repository>
+ <snapshotRepository>
+ <id>apache.snapshots</id>
+ <name>Apache Development Snapshot Repository</name>
+ <url>scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+ </snapshotRepository>
+ </distributionManagement>
+ <mailingLists>
+ <mailingList>
+ <name>Apache Announce List</name>
+ <subscribe>announce-subscribe@apache.org</subscribe>
+ <unsubscribe>announce-unsubscribe@apache.org</unsubscribe>
+ <post>announce@apache.org</post>
+ <archive>http://mail-archives.apache.org/mod_mbox/www-announce/</archive>
+ </mailingList>
+ </mailingLists>
+ <properties>
+ <organization.logo>http://www.apache.org/images/asf_logo_wide.gif</organization.logo>
+ </properties>
+ <!--
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <configuration>
+ <artifacts>
+ <artifact>org.apache:apache-distribution-resources:1.0-SNAPSHOT</artifact>
+ </artifacts>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ -->
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/maven/pom/trunk/asf</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/pom/trunk/asf</developerConnection>
+ <url>http://svn.apache.org/viewvc/maven/pom/trunk/asf</url>
+ </scm>
+</project>
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<metadata>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>5-SNAPSHOT</version>
+ <versioning>
+ <snapshot>
+ <buildNumber>1</buildNumber>
+ <timestamp>20080801.151215</timestamp>
+ </snapshot>
+ <lastUpdated>20080801151215</lastUpdated>
+ </versioning>
+</metadata>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-downloader</artifactId>
+ <version>1.0</version>
+ <versioning>
+ <release>1.1</release>
+ <versions>
+ <version>1.0</version>
+ <version>1.1</version>
+ </versions>
+ <lastUpdated>20061212214311</lastUpdated>
+ </versioning>
+</metadata>
<artifactId>maven-model</artifactId>
<version>${maven.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model-builder</artifactId>
+ <version>${maven3x.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
</dependencyManagement>
<properties>
<maven.version>2.0.8</maven.version>
+ <maven3x.version>3.0-alpha-4</maven3x.version>
<wagon.version>1.0-beta-5</wagon.version>
<redback.version>1.2.2</redback.version>
<jetty.version>6.1.19</jetty.version>