import com.opensymphony.xwork2.Validateable;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
// we don't want the implementation being that intelligent - so another resolver to do the
// "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
- versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
+ try
+ {
+ versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
+ }
+ catch ( MetadataResolverException e )
+ {
+ addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
+ return ERROR;
+ }
if ( versionMetadata != null )
{
repositoryId = repoId;
}
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
+ throws MetadataResolverException
{
ProjectVersionMetadata metadata = metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion );
// TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated)
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;
public interface MetadataResolver
{
ProjectMetadata getProject( String repoId, String namespace, String projectId );
- ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion );
+ ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
+ throws MetadataResolverException;
Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion );
}
--- /dev/null
+package org.apache.archiva.metadata.repository;
+
+/*
+ * 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.
+ */
+
+public class MetadataResolverException
+ extends Exception
+{
+ public MetadataResolverException( String message, Exception cause )
+ {
+ super( message, cause );
+ }
+}
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.MetadataResolverException;
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.model.building.ModelBuilder;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelBuildingRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver" role-hint="maven2"
*/
private RepositoryPathTranslator pathTranslator;
+ private final static Logger log = LoggerFactory.getLogger( Maven2RepositoryMetadataResolver.class );
+
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
{
throw new UnsupportedOperationException();
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
+ throws MetadataResolverException
{
ManagedRepositoryConfiguration repositoryConfiguration =
archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
if ( VersionUtil.isSnapshot( projectVersion ) )
{
// TODO: need much error handling here for incorrect metadata
+ File metadataFile =
+ pathTranslator.toFile( basedir, namespace, projectId, projectVersion, "maven-metadata.xml" );
try
{
- MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read(
- pathTranslator.toFile( basedir, namespace, projectId, projectVersion, "maven-metadata.xml" ) );
+ MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
artifactVersion =
artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end
}
catch ( XMLException e )
{
- // TODO: handle it
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ // unable to parse metadata - log it, and continue with the version as the original SNAPSHOT version
+ log.warn( "Invalid metadata: " + metadataFile + " - " + e.getMessage() );
}
}
}
catch ( ModelBuildingException e )
{
- // TODO: handle it
- throw new RuntimeException( e );
+ throw new MetadataResolverException( "Unable to build Maven POM to derive metadata from: " + e.getMessage(), e );
}
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
}
public void testGetProjectVersionMetadata()
+ throws MetadataResolverException
{
ProjectVersionMetadata metadata =
resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
}
public void testGetProjectVersionMetadataForTimestampedSnapshot()
+ throws MetadataResolverException
{
ProjectVersionMetadata metadata =
resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );