import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
import org.slf4j.Logger;
public void processFile( String path )
throws ConsumerException
{
- // note that we do minimal processing including checksums and POM information for performance of
- // the initial scan. Any request for this information will be intercepted and populated on-demand
- // or picked up by subsequent scans
-
- ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath( repoId, path );
-
- ProjectMetadata project = new ProjectMetadata();
- project.setNamespace( artifact.getNamespace() );
- project.setId( artifact.getProject() );
-
- String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
+ // note that we do minimal processing including checksums and POM information for performance of
+ // the initial scan. Any request for this information will be intercepted and populated on-demand
+ // or picked up by subsequent scans
+
+ ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath( repoId, path );
+
+ ProjectMetadata project = new ProjectMetadata();
+ project.setNamespace( artifact.getNamespace() );
+ project.setId( artifact.getProject() );
+
+ String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
+
MetadataRepository metadataRepository = repositorySession.getRepository();
boolean createVersionMetadata = false;
log.warn( "Error occurred persisting metadata for artifact: " + path + "; message: " + e.getMessage(), e );
repositorySession.revert();
}
+ catch ( RepositoryStorageRuntimeException e )
+ {
+ log.warn( "Error occurred persisting metadata for artifact: " + path + "; message: " + e.getMessage(), e );
+ repositorySession.revert();
+ }
finally
{
repositorySession.close();
<artifactId>wagon-http</artifactId>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
* under the License.
*/
-import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.apache.archiva.repository.events.RepositoryListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
throw new MetadataResolutionException( e.getMessage(), e );
}
- catch ( RepositoryAdminException e )
+ catch ( RepositoryStorageMetadataNotFoundException e )
{
for ( RepositoryListener listener : listeners )
{
listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
}
- throw new MetadataResolutionException( e.getMessage(), e );
+ // no need to rethrow - return null
}
- catch ( RepositoryStorageMetadataNotFoundException e )
+ catch ( RepositoryStorageRuntimeException e )
{
for ( RepositoryListener listener : listeners )
{
listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
}
- // no need to rethrow - return null
+ throw new MetadataResolutionException( e.getMessage(), e );
}
+
}
return metadata;
}
public Collection<String> resolveRootNamespaces( RepositorySession session, String repoId )
throws MetadataResolutionException
{
- MetadataRepository metadataRepository = session.getRepository();
- Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId );
- Collection<String> storageNamespaces =
- repositoryStorage.listRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) );
- if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
+ try
{
- if ( log.isDebugEnabled() )
- {
- log.debug( "Resolved root namespaces from storage: " + storageNamespaces );
- }
- for ( String n : storageNamespaces )
+ MetadataRepository metadataRepository = session.getRepository();
+ Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId );
+ Collection<String> storageNamespaces =
+ repositoryStorage.listRootNamespaces( repoId, new ExcludesFilter<String>( namespaces ) );
+ if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
{
- try
+ if ( log.isDebugEnabled() )
{
- metadataRepository.updateNamespace( repoId, n );
+ log.debug( "Resolved root namespaces from storage: " + storageNamespaces );
}
- catch ( MetadataRepositoryException e )
+ for ( String n : storageNamespaces )
{
- log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ try
+ {
+ metadataRepository.updateNamespace( repoId, n );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ }
}
- }
- session.markDirty();
+ session.markDirty();
- namespaces = new ArrayList<String>( namespaces );
- namespaces.addAll( storageNamespaces );
+ namespaces = new ArrayList<String>( namespaces );
+ namespaces.addAll( storageNamespaces );
+ }
+ return namespaces;
+ }
+ catch ( RepositoryStorageRuntimeException e )
+ {
+ throw new MetadataResolutionException( e.getMessage(), e );
}
- return namespaces;
}
public Collection<String> resolveNamespaces( RepositorySession session, String repoId, String namespace )
throws MetadataResolutionException
{
- MetadataRepository metadataRepository = session.getRepository();
- Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace );
- Collection<String> exclusions = new ArrayList<String>( namespaces );
- exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) );
- Collection<String> storageNamespaces =
- repositoryStorage.listNamespaces( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
- if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
+ try
{
- if ( log.isDebugEnabled() )
- {
- log.debug( "Resolved namespaces from storage: " + storageNamespaces );
- }
- for ( String n : storageNamespaces )
+ MetadataRepository metadataRepository = session.getRepository();
+ Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace );
+ Collection<String> exclusions = new ArrayList<String>( namespaces );
+ exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) );
+ Collection<String> storageNamespaces =
+ repositoryStorage.listNamespaces( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
+ if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
{
- try
- {
- metadataRepository.updateNamespace( repoId, namespace + "." + n );
- }
- catch ( MetadataRepositoryException e )
+
+ log.debug( "Resolved namespaces from storage: {}", storageNamespaces );
+ for ( String n : storageNamespaces )
{
- log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ try
+ {
+ metadataRepository.updateNamespace( repoId, namespace + "." + n );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ }
}
- }
- session.markDirty();
+ session.markDirty();
- namespaces = new ArrayList<String>( namespaces );
- namespaces.addAll( storageNamespaces );
+ namespaces = new ArrayList<String>( namespaces );
+ namespaces.addAll( storageNamespaces );
+ }
+ return namespaces;
+ }
+ catch ( RepositoryStorageRuntimeException e )
+ {
+ throw new MetadataResolutionException( e.getMessage(), e );
}
- return namespaces;
}
public Collection<String> resolveProjects( RepositorySession session, String repoId, String namespace )
throws MetadataResolutionException
{
- MetadataRepository metadataRepository = session.getRepository();
- Collection<String> projects = metadataRepository.getProjects( repoId, namespace );
- Collection<String> exclusions = new ArrayList<String>( projects );
- exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) );
- Collection<String> storageProjects =
- repositoryStorage.listProjects( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
- if ( storageProjects != null && !storageProjects.isEmpty() )
+ try
{
- if ( log.isDebugEnabled() )
- {
- log.debug( "Resolved projects from storage: " + storageProjects );
- }
- for ( String projectId : storageProjects )
+ MetadataRepository metadataRepository = session.getRepository();
+ Collection<String> projects = metadataRepository.getProjects( repoId, namespace );
+ Collection<String> exclusions = new ArrayList<String>( projects );
+ exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) );
+ Collection<String> storageProjects =
+ repositoryStorage.listProjects( repoId, namespace, new ExcludesFilter<String>( exclusions ) );
+ if ( storageProjects != null && !storageProjects.isEmpty() )
{
- ProjectMetadata projectMetadata = repositoryStorage.readProjectMetadata( repoId, namespace, projectId );
- if ( projectMetadata != null )
+
+ log.debug( "Resolved projects from storage: {}", storageProjects );
+ for ( String projectId : storageProjects )
{
- try
- {
- metadataRepository.updateProject( repoId, projectMetadata );
- }
- catch ( MetadataRepositoryException e )
+ ProjectMetadata projectMetadata =
+ repositoryStorage.readProjectMetadata( repoId, namespace, projectId );
+ if ( projectMetadata != null )
{
- log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ try
+ {
+ metadataRepository.updateProject( repoId, projectMetadata );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ }
}
}
- }
- session.markDirty();
+ session.markDirty();
- projects = new ArrayList<String>( projects );
- projects.addAll( storageProjects );
+ projects = new ArrayList<String>( projects );
+ projects.addAll( storageProjects );
+ }
+ return projects;
+ }
+ catch ( RepositoryStorageRuntimeException e )
+ {
+ throw new MetadataResolutionException( e.getMessage(), e );
}
- return projects;
}
public Collection<String> resolveProjectVersions( RepositorySession session, String repoId, String namespace,
String projectId )
throws MetadataResolutionException
{
- MetadataRepository metadataRepository = session.getRepository();
- Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
- Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions( repoId, namespace, projectId,
- new ExcludesFilter<String>(
- projectVersions ) );
- if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() )
+ try
{
- if ( log.isDebugEnabled() )
- {
- log.debug( "Resolved project versions from storage: " + storageProjectVersions );
- }
- for ( String projectVersion : storageProjectVersions )
+ MetadataRepository metadataRepository = session.getRepository();
+ Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
+ Collection<String> storageProjectVersions =
+ repositoryStorage.listProjectVersions( repoId, namespace, projectId,
+ new ExcludesFilter<String>( projectVersions ) );
+ if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() )
{
- try
- {
- ProjectVersionMetadata versionMetadata =
- repositoryStorage.readProjectVersionMetadata( repoId, namespace, projectId, projectVersion );
- for ( RepositoryListener listener : listeners )
- {
- listener.addArtifact( session, repoId, namespace, projectId, versionMetadata );
- }
+ log.debug( "Resolved project versions from storage: {}", storageProjectVersions );
- metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata );
- }
- catch ( MetadataRepositoryException e )
- {
- log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
- }
- catch ( RepositoryStorageMetadataInvalidException e )
+ for ( String projectVersion : storageProjectVersions )
{
- log.warn( "Not update project in metadata repository due to an error resolving it from storage: "
- + e.getMessage() );
+ try
+ {
+ ProjectVersionMetadata versionMetadata =
+ repositoryStorage.readProjectVersionMetadata( repoId, namespace, projectId,
+ projectVersion );
+ for ( RepositoryListener listener : listeners )
+ {
+ listener.addArtifact( session, repoId, namespace, projectId, versionMetadata );
+ }
- for ( RepositoryListener listener : listeners )
+ metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata );
+ }
+ catch ( MetadataRepositoryException e )
{
- listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
+ log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
}
- }
- catch ( RepositoryStorageMetadataNotFoundException e )
- {
- for ( RepositoryListener listener : listeners )
+ catch ( RepositoryStorageMetadataInvalidException e )
{
- listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
+ log.warn(
+ "Not update project in metadata repository due to an error resolving it from storage: "
+ + e.getMessage() );
+
+ for ( RepositoryListener listener : listeners )
+ {
+ listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
+ }
+ }
+ catch ( RepositoryStorageMetadataNotFoundException e )
+ {
+ for ( RepositoryListener listener : listeners )
+ {
+ listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
+ }
}
}
- }
- session.markDirty();
+ session.markDirty();
- projectVersions = new ArrayList<String>( projectVersions );
- projectVersions.addAll( storageProjectVersions );
+ projectVersions = new ArrayList<String>( projectVersions );
+ projectVersions.addAll( storageProjectVersions );
+ }
+ return projectVersions;
+ }
+ catch ( RepositoryStorageRuntimeException e )
+ {
+ throw new MetadataResolutionException( e.getMessage(), e );
}
- return projectVersions;
}
public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession session, String repoId, String namespace,
String projectId, String projectVersion )
throws MetadataResolutionException
{
- MetadataRepository metadataRepository = session.getRepository();
- Collection<ArtifactMetadata> artifacts =
- metadataRepository.getArtifacts( repoId, namespace, projectId, projectVersion );
- ExcludesFilter<String> filter = new ExcludesFilter<String>( createArtifactIdList( artifacts ) );
- Collection<ArtifactMetadata> storageArtifacts =
- repositoryStorage.readArtifactsMetadata( repoId, namespace, projectId, projectVersion, filter );
- if ( storageArtifacts != null && !storageArtifacts.isEmpty() )
+ try
{
- if ( log.isDebugEnabled() )
- {
- log.debug( "Resolved artifacts from storage: " + storageArtifacts );
- }
- for ( ArtifactMetadata artifact : storageArtifacts )
+ MetadataRepository metadataRepository = session.getRepository();
+ Collection<ArtifactMetadata> artifacts =
+ metadataRepository.getArtifacts( repoId, namespace, projectId, projectVersion );
+ ExcludesFilter<String> filter = new ExcludesFilter<String>( createArtifactIdList( artifacts ) );
+ Collection<ArtifactMetadata> storageArtifacts =
+ repositoryStorage.readArtifactsMetadata( repoId, namespace, projectId, projectVersion, filter );
+ if ( storageArtifacts != null && !storageArtifacts.isEmpty() )
{
- try
+ if ( log.isDebugEnabled() )
{
- metadataRepository.updateArtifact( repoId, namespace, projectId, projectVersion, artifact );
+ log.debug( "Resolved artifacts from storage: " + storageArtifacts );
}
- catch ( MetadataRepositoryException e )
+ for ( ArtifactMetadata artifact : storageArtifacts )
{
- log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ try
+ {
+ metadataRepository.updateArtifact( repoId, namespace, projectId, projectVersion, artifact );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Unable to persist resolved information: " + e.getMessage(), e );
+ }
}
- }
- session.markDirty();
+ session.markDirty();
- artifacts = new ArrayList<ArtifactMetadata>( artifacts );
- artifacts.addAll( storageArtifacts );
+ artifacts = new ArrayList<ArtifactMetadata>( artifacts );
+ artifacts.addAll( storageArtifacts );
+ }
+ return artifacts;
+ }
+ catch ( RepositoryStorageRuntimeException e )
+ {
+ for ( RepositoryListener listener : listeners )
+ {
+ listener.addArtifactProblem( session, repoId, namespace, projectId, projectVersion, e );
+ }
+ throw new MetadataResolutionException( e.getMessage(), e );
}
- return artifacts;
}
private Collection<String> createArtifactIdList( Collection<ArtifactMetadata> artifacts )
* under the License.
*/
-import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
ProjectVersionMetadata readProjectVersionMetadata( String repoId, String namespace, String projectId,
String projectVersion )
throws RepositoryStorageMetadataInvalidException, RepositoryStorageMetadataNotFoundException,
- RepositoryAdminException;
+ RepositoryStorageRuntimeException;
Collection<String> listRootNamespaces( String repoId, Filter<String> filter )
- throws RepositoryAdminException;
+ throws RepositoryStorageRuntimeException;
Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter )
- throws RepositoryAdminException;
+ throws RepositoryStorageRuntimeException;
Collection<String> listProjects( String repoId, String namespace, Filter<String> filter )
- throws RepositoryAdminException;
+ throws RepositoryStorageRuntimeException;
Collection<String> listProjectVersions( String repoId, String namespace, String projectId, Filter<String> filter )
- throws RepositoryAdminException;
+ throws RepositoryStorageRuntimeException;
Collection<ArtifactMetadata> readArtifactsMetadata( String repoId, String namespace, String projectId,
String projectVersion, Filter<String> filter )
- throws RepositoryAdminException;
+ throws RepositoryStorageRuntimeException;
// FIXME: reconsider this API, do we want to expose storage format in the form of a path?
ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path )
- throws RepositoryAdminException;
+ throws RepositoryStorageRuntimeException;
}
--- /dev/null
+package org.apache.archiva.metadata.repository.storage;
+
+/*
+ * 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.
+ */
+
+/**
+ * @since 1.4-M3
+ * @author Olivier Lamy
+ */
+public class RepositoryStorageRuntimeException
+ extends RepositoryStorageMetadataException
+{
+ public RepositoryStorageRuntimeException( String id, String msg )
+ {
+ super( id, msg );
+ }
+
+ public RepositoryStorageRuntimeException( String id, String msg, Throwable throwable )
+ {
+ super( id, msg, throwable );
+ }
+}
<artifactId>wagon-http</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>net.sf.beanlib</groupId>
+ <artifactId>beanlib</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
<plugins>
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.archiva.xml.XMLException;
public ProjectVersionMetadata readProjectVersionMetadata( String repoId, String namespace, String projectId,
String projectVersion )
throws RepositoryStorageMetadataNotFoundException, RepositoryStorageMetadataInvalidException,
- RepositoryAdminException
+ RepositoryStorageRuntimeException
{
+ try
+ {
+ ManagedRepository repositoryConfiguration = managedRepositoryAdmin.getManagedRepository( repoId );
- ManagedRepository repositoryConfiguration = managedRepositoryAdmin.getManagedRepository( repoId );
-
- String artifactVersion = projectVersion;
+ String artifactVersion = projectVersion;
- File basedir = new File( repositoryConfiguration.getLocation() );
- if ( VersionUtil.isSnapshot( projectVersion ) )
- {
- File metadataFile =
- pathTranslator.toFile( basedir, namespace, projectId, projectVersion, METADATA_FILENAME );
- try
+ File basedir = new File( repositoryConfiguration.getLocation() );
+ if ( VersionUtil.isSnapshot( projectVersion ) )
{
- MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
+ File metadataFile =
+ pathTranslator.toFile( basedir, namespace, projectId, projectVersion, METADATA_FILENAME );
+ try
+ {
+ MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
- // re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
- MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
- if ( snapshotVersion != null )
+ // re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
+ MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
+ if ( snapshotVersion != null )
+ {
+ artifactVersion =
+ artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end
+ artifactVersion =
+ artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
+ }
+ }
+ catch ( XMLException e )
{
- artifactVersion =
- artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end
- artifactVersion =
- artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
+ // unable to parse metadata - log it, and continue with the version as the original SNAPSHOT version
+ log.warn( "Invalid metadata: " + metadataFile + " - " + e.getMessage() );
}
}
- catch ( XMLException e )
- {
- // unable to parse metadata - log it, and continue with the version as the original SNAPSHOT version
- log.warn( "Invalid metadata: " + metadataFile + " - " + e.getMessage() );
- }
- }
- // TODO: won't work well with some other layouts, might need to convert artifact parts to ID by path translator
- String id = projectId + "-" + artifactVersion + ".pom";
- File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, id );
+ // TODO: won't work well with some other layouts, might need to convert artifact parts to ID by path translator
+ String id = projectId + "-" + artifactVersion + ".pom";
+ File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion, id );
- if ( !file.exists() )
- {
- // metadata could not be resolved
- throw new RepositoryStorageMetadataNotFoundException(
- "The artifact's POM file '" + file.getAbsolutePath() + "' was missing" );
- }
+ if ( !file.exists() )
+ {
+ // metadata could not be resolved
+ throw new RepositoryStorageMetadataNotFoundException(
+ "The artifact's POM file '" + file.getAbsolutePath() + "' was missing" );
+ }
- // TODO: this is a workaround until we can properly resolve using proxies as well - this doesn't cache
- // anything locally!
- List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();
- Map<String, NetworkProxy> networkProxies = new HashMap<String, NetworkProxy>();
+ // TODO: this is a workaround until we can properly resolve using proxies as well - this doesn't cache
+ // anything locally!
+ List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();
+ Map<String, NetworkProxy> networkProxies = new HashMap<String, NetworkProxy>();
- Map<String, List<ProxyConnector>> proxyConnectorsMap = proxyConnectorAdmin.getProxyConnectorAsMap();
- List<ProxyConnector> proxyConnectors = proxyConnectorsMap.get( repoId );
- if ( proxyConnectors != null )
- {
- for ( ProxyConnector proxyConnector : proxyConnectors )
+ Map<String, List<ProxyConnector>> proxyConnectorsMap = proxyConnectorAdmin.getProxyConnectorAsMap();
+ List<ProxyConnector> proxyConnectors = proxyConnectorsMap.get( repoId );
+ if ( proxyConnectors != null )
{
- RemoteRepository remoteRepoConfig =
- remoteRepositoryAdmin.getRemoteRepository( proxyConnector.getTargetRepoId() );
-
- if ( remoteRepoConfig != null )
+ for ( ProxyConnector proxyConnector : proxyConnectors )
{
- remoteRepositories.add( remoteRepoConfig );
-
- NetworkProxy networkProxyConfig = networkProxyAdmin.getNetworkProxy( proxyConnector.getProxyId() );
+ RemoteRepository remoteRepoConfig =
+ remoteRepositoryAdmin.getRemoteRepository( proxyConnector.getTargetRepoId() );
- if ( networkProxyConfig != null )
+ if ( remoteRepoConfig != null )
{
- // key/value: remote repo ID/proxy info
- networkProxies.put( proxyConnector.getTargetRepoId(), networkProxyConfig );
+ remoteRepositories.add( remoteRepoConfig );
+
+ NetworkProxy networkProxyConfig =
+ networkProxyAdmin.getNetworkProxy( proxyConnector.getProxyId() );
+
+ if ( networkProxyConfig != null )
+ {
+ // key/value: remote repo ID/proxy info
+ networkProxies.put( proxyConnector.getTargetRepoId(), networkProxyConfig );
+ }
}
}
}
- }
-
- ModelBuildingRequest req = new DefaultModelBuildingRequest();
- req.setProcessPlugins( false );
- req.setPomFile( file );
- // MRM-1411
- req.setModelResolver(
- new RepositoryModelResolver( basedir, pathTranslator, wagonFactory, remoteRepositories, networkProxies,
- repositoryConfiguration ) );
- req.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
+ ModelBuildingRequest req = new DefaultModelBuildingRequest();
+ req.setProcessPlugins( false );
+ req.setPomFile( file );
- Model model;
- try
- {
- model = builder.build( req ).getEffectiveModel();
- }
- catch ( ModelBuildingException e )
- {
- String msg = "The artifact's POM file '" + file + "' was invalid: " + e.getMessage();
+ // MRM-1411
+ req.setModelResolver(
+ new RepositoryModelResolver( basedir, pathTranslator, wagonFactory, remoteRepositories, networkProxies,
+ repositoryConfiguration ) );
+ req.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
- List<ModelProblem> modelProblems = e.getProblems();
- for ( ModelProblem problem : modelProblems )
+ Model model;
+ try
{
- // MRM-1411, related to MRM-1335
- // this means that the problem was that the parent wasn't resolved!
- if ( problem.getException() instanceof FileNotFoundException && e.getModelId() != null &&
- !e.getModelId().equals( problem.getModelId() ) )
- {
- log.warn( "The artifact's parent POM file '" + file + "' cannot be resolved. " +
- "Using defaults for project version metadata.." );
-
- ProjectVersionMetadata metadata = new ProjectVersionMetadata();
- metadata.setId( projectVersion );
-
- MavenProjectFacet facet = new MavenProjectFacet();
- facet.setGroupId( namespace );
- facet.setArtifactId( projectId );
- facet.setPackaging( "jar" );
- metadata.addFacet( facet );
-
- String errMsg =
- "Error in resolving artifact's parent POM file. " + problem.getException().getMessage();
- RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
- repoProblemFacet.setRepositoryId( repoId );
- repoProblemFacet.setId( repoId );
- repoProblemFacet.setMessage( errMsg );
- repoProblemFacet.setProblem( errMsg );
- repoProblemFacet.setProject( projectId );
- repoProblemFacet.setVersion( projectVersion );
- repoProblemFacet.setNamespace( namespace );
-
- metadata.addFacet( repoProblemFacet );
-
- return metadata;
- }
+ model = builder.build( req ).getEffectiveModel();
}
+ catch ( ModelBuildingException e )
+ {
+ String msg = "The artifact's POM file '" + file + "' was invalid: " + e.getMessage();
- throw new RepositoryStorageMetadataInvalidException( "invalid-pom", msg, e );
- }
+ List<ModelProblem> modelProblems = e.getProblems();
+ for ( ModelProblem problem : modelProblems )
+ {
+ // MRM-1411, related to MRM-1335
+ // this means that the problem was that the parent wasn't resolved!
+ if ( problem.getException() instanceof FileNotFoundException && e.getModelId() != null &&
+ !e.getModelId().equals( problem.getModelId() ) )
+ {
+ log.warn( "The artifact's parent POM file '" + file + "' cannot be resolved. " +
+ "Using defaults for project version metadata.." );
+
+ ProjectVersionMetadata metadata = new ProjectVersionMetadata();
+ metadata.setId( projectVersion );
+
+ MavenProjectFacet facet = new MavenProjectFacet();
+ facet.setGroupId( namespace );
+ facet.setArtifactId( projectId );
+ facet.setPackaging( "jar" );
+ metadata.addFacet( facet );
+
+ String errMsg =
+ "Error in resolving artifact's parent POM file. " + problem.getException().getMessage();
+ RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
+ repoProblemFacet.setRepositoryId( repoId );
+ repoProblemFacet.setId( repoId );
+ repoProblemFacet.setMessage( errMsg );
+ repoProblemFacet.setProblem( errMsg );
+ repoProblemFacet.setProject( projectId );
+ repoProblemFacet.setVersion( projectVersion );
+ repoProblemFacet.setNamespace( namespace );
+
+ metadata.addFacet( repoProblemFacet );
+
+ return metadata;
+ }
+ }
- // Check if the POM is in the correct location
- boolean correctGroupId = namespace.equals( model.getGroupId() );
- boolean correctArtifactId = projectId.equals( model.getArtifactId() );
- boolean correctVersion = projectVersion.equals( model.getVersion() );
- if ( !correctGroupId || !correctArtifactId || !correctVersion )
- {
- StringBuilder message = new StringBuilder( "Incorrect POM coordinates in '" + file + "':" );
- if ( !correctGroupId )
- {
- message.append( "\nIncorrect group ID: " ).append( model.getGroupId() );
+ throw new RepositoryStorageMetadataInvalidException( "invalid-pom", msg, e );
}
- if ( !correctArtifactId )
+
+ // Check if the POM is in the correct location
+ boolean correctGroupId = namespace.equals( model.getGroupId() );
+ boolean correctArtifactId = projectId.equals( model.getArtifactId() );
+ boolean correctVersion = projectVersion.equals( model.getVersion() );
+ if ( !correctGroupId || !correctArtifactId || !correctVersion )
{
- message.append( "\nIncorrect artifact ID: " ).append( model.getArtifactId() );
+ StringBuilder message = new StringBuilder( "Incorrect POM coordinates in '" + file + "':" );
+ if ( !correctGroupId )
+ {
+ message.append( "\nIncorrect group ID: " ).append( model.getGroupId() );
+ }
+ if ( !correctArtifactId )
+ {
+ message.append( "\nIncorrect artifact ID: " ).append( model.getArtifactId() );
+ }
+ if ( !correctVersion )
+ {
+ message.append( "\nIncorrect version: " ).append( model.getVersion() );
+ }
+
+ throw new RepositoryStorageMetadataInvalidException( "mislocated-pom", message.toString() );
}
- if ( !correctVersion )
+
+ ProjectVersionMetadata metadata = new ProjectVersionMetadata();
+ metadata.setCiManagement( convertCiManagement( model.getCiManagement() ) );
+ metadata.setDescription( model.getDescription() );
+ metadata.setId( projectVersion );
+ metadata.setIssueManagement( convertIssueManagement( model.getIssueManagement() ) );
+ metadata.setLicenses( convertLicenses( model.getLicenses() ) );
+ metadata.setMailingLists( convertMailingLists( model.getMailingLists() ) );
+ metadata.setDependencies( convertDependencies( model.getDependencies() ) );
+ metadata.setName( model.getName() );
+ metadata.setOrganization( convertOrganization( model.getOrganization() ) );
+ metadata.setScm( convertScm( model.getScm() ) );
+ metadata.setUrl( model.getUrl() );
+
+ MavenProjectFacet facet = new MavenProjectFacet();
+ facet.setGroupId( model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId() );
+ facet.setArtifactId( model.getArtifactId() );
+ facet.setPackaging( model.getPackaging() );
+ if ( model.getParent() != null )
{
- message.append( "\nIncorrect version: " ).append( model.getVersion() );
+ MavenProjectParent parent = new MavenProjectParent();
+ parent.setGroupId( model.getParent().getGroupId() );
+ parent.setArtifactId( model.getParent().getArtifactId() );
+ parent.setVersion( model.getParent().getVersion() );
+ facet.setParent( parent );
}
+ metadata.addFacet( facet );
- throw new RepositoryStorageMetadataInvalidException( "mislocated-pom", message.toString() );
+ return metadata;
}
-
- ProjectVersionMetadata metadata = new ProjectVersionMetadata();
- metadata.setCiManagement( convertCiManagement( model.getCiManagement() ) );
- metadata.setDescription( model.getDescription() );
- metadata.setId( projectVersion );
- metadata.setIssueManagement( convertIssueManagement( model.getIssueManagement() ) );
- metadata.setLicenses( convertLicenses( model.getLicenses() ) );
- metadata.setMailingLists( convertMailingLists( model.getMailingLists() ) );
- metadata.setDependencies( convertDependencies( model.getDependencies() ) );
- metadata.setName( model.getName() );
- metadata.setOrganization( convertOrganization( model.getOrganization() ) );
- metadata.setScm( convertScm( model.getScm() ) );
- metadata.setUrl( model.getUrl() );
-
- MavenProjectFacet facet = new MavenProjectFacet();
- facet.setGroupId( model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId() );
- facet.setArtifactId( model.getArtifactId() );
- facet.setPackaging( model.getPackaging() );
- if ( model.getParent() != null )
+ catch ( RepositoryAdminException e )
{
- MavenProjectParent parent = new MavenProjectParent();
- parent.setGroupId( model.getParent().getGroupId() );
- parent.setArtifactId( model.getParent().getArtifactId() );
- parent.setVersion( model.getParent().getVersion() );
- facet.setParent( parent );
+ throw new RepositoryStorageRuntimeException( "repo-admin", e.getMessage() );
}
- metadata.addFacet( facet );
-
- return metadata;
-
}
public void setWagonFactory( WagonFactory wagonFactory )
}
public Collection<String> listRootNamespaces( String repoId, Filter<String> filter )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
File dir = getRepositoryBasedir( repoId );
}
private File getRepositoryBasedir( String repoId )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
- ManagedRepository repositoryConfiguration = managedRepositoryAdmin.getManagedRepository( repoId );
+ try
+ {
+ ManagedRepository repositoryConfiguration = managedRepositoryAdmin.getManagedRepository( repoId );
- return new File( repositoryConfiguration.getLocation() );
+ return new File( repositoryConfiguration.getLocation() );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ throw new RepositoryStorageRuntimeException( "repo-admin", e.getMessage() );
+ }
}
public Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace );
}
public Collection<String> listProjects( String repoId, String namespace, Filter<String> filter )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace );
public Collection<String> listProjectVersions( String repoId, String namespace, String projectId,
Filter<String> filter )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace, projectId );
public Collection<ArtifactMetadata> readArtifactsMetadata( String repoId, String namespace, String projectId,
String projectVersion, Filter<String> filter )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace, projectId, projectVersion );
}
public ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path )
- throws RepositoryAdminException
+ throws RepositoryStorageRuntimeException
{
ArtifactMetadata metadata = pathTranslator.getArtifactForPath( repoId, path );
--- /dev/null
+package org.apache.archiva.configuration;
+/*
+ * 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 net.sf.beanlib.provider.replicator.BeanReplicator;
+import org.apache.archiva.admin.model.AuditInformation;
+import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.admin.model.beans.NetworkProxy;
+import org.apache.archiva.admin.model.beans.ProxyConnector;
+import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
+import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
+import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorOrderComparator;
+import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.index.context.IndexingContext;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service
+public class MockRepoAdmin
+ implements RemoteRepositoryAdmin, ManagedRepositoryAdmin, ProxyConnectorAdmin, NetworkProxyAdmin
+{
+ @Inject
+ @Named( value = "archivaConfiguration#test" )
+ private ArchivaConfiguration archivaConfiguration;
+
+ public List<RemoteRepository> getRemoteRepositories()
+ throws RepositoryAdminException
+ {
+ List<RemoteRepository> remoteRepositories =
+ new ArrayList<RemoteRepository>( archivaConfiguration.getConfiguration().getRemoteRepositories().size() );
+ for ( RemoteRepositoryConfiguration repositoryConfiguration : archivaConfiguration.getConfiguration().getRemoteRepositories() )
+ {
+ RemoteRepository remoteRepository =
+ new RemoteRepository( repositoryConfiguration.getId(), repositoryConfiguration.getName(),
+ repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(),
+ repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(),
+ repositoryConfiguration.getTimeout() );
+ remoteRepository.setDownloadRemoteIndex( repositoryConfiguration.isDownloadRemoteIndex() );
+ remoteRepository.setRemoteIndexUrl( repositoryConfiguration.getRemoteIndexUrl() );
+ remoteRepository.setCronExpression( repositoryConfiguration.getRefreshCronExpression() );
+ remoteRepository.setIndexDirectory( repositoryConfiguration.getIndexDir() );
+ remoteRepository.setRemoteDownloadNetworkProxyId(
+ repositoryConfiguration.getRemoteDownloadNetworkProxyId() );
+ remoteRepository.setRemoteDownloadTimeout( repositoryConfiguration.getRemoteDownloadTimeout() );
+ remoteRepository.setDownloadRemoteIndexOnStartup(
+ repositoryConfiguration.isDownloadRemoteIndexOnStartup() );
+ remoteRepositories.add( remoteRepository );
+ }
+ return remoteRepositories;
+ }
+
+ public RemoteRepository getRemoteRepository( String repositoryId )
+ throws RepositoryAdminException
+ {
+ for ( RemoteRepository remoteRepository : getRemoteRepositories() )
+ {
+ if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
+ {
+ return remoteRepository;
+ }
+ }
+ return null;
+ }
+
+ public Boolean deleteRemoteRepository( String repositoryId, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public IndexingContext createIndexContext( RemoteRepository repository )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<ManagedRepository> getManagedRepositories()
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ManagedRepository getManagedRepository( String repositoryId )
+ throws RepositoryAdminException
+ {
+ for ( ManagedRepositoryConfiguration repoConfig : archivaConfiguration.getConfiguration().getManagedRepositories() )
+ {
+ if ( StringUtils.equals( repositoryId, repoConfig.getId() ) )
+ {
+ return new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
+ repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
+ repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
+ repoConfig.getIndexDir(), repoConfig.isScanned(),
+ repoConfig.getDaysOlder(), repoConfig.getRetentionCount(),
+ repoConfig.isDeleteReleasedSnapshots(), false );
+ }
+ }
+ return null;
+ }
+
+ public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
+ boolean deleteContent )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
+ AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
+ AuditInformation auditInformation, boolean resetStats )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public IndexingContext createIndexContext( ManagedRepository repository )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<ProxyConnector> getProxyConnectors()
+ throws RepositoryAdminException
+ {
+ List<ProxyConnectorConfiguration> proxyConnectorConfigurations =
+ archivaConfiguration.getConfiguration().getProxyConnectors();
+ List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>( proxyConnectorConfigurations.size() );
+ for ( ProxyConnectorConfiguration configuration : proxyConnectorConfigurations )
+ {
+ proxyConnectors.add( getProxyConnector( configuration ) );
+ }
+ Collections.sort( proxyConnectors, ProxyConnectorOrderComparator.getInstance() );
+ return proxyConnectors;
+ }
+
+ public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
+ throws RepositoryAdminException
+ {
+ Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<String, List<ProxyConnector>>();
+
+ Iterator<ProxyConnector> it = getProxyConnectors().iterator();
+ while ( it.hasNext() )
+ {
+ ProxyConnector proxyConfig = it.next();
+ String key = proxyConfig.getSourceRepoId();
+
+ List<ProxyConnector> connectors = proxyConnectorMap.get( key );
+ if ( connectors == null )
+ {
+ connectors = new ArrayList<ProxyConnector>( 1 );
+ proxyConnectorMap.put( key, connectors );
+ }
+
+ connectors.add( proxyConfig );
+
+ Collections.sort( connectors, ProxyConnectorOrderComparator.getInstance() );
+ }
+
+ return proxyConnectorMap;
+ }
+
+ public List<NetworkProxy> getNetworkProxies()
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public NetworkProxy getNetworkProxy( String networkProxyId )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration )
+ {
+ return proxyConnectorConfiguration == null
+ ? null
+ : new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class );
+ }
+}
*/
import junit.framework.TestCase;
+import org.apache.archiva.common.utils.FileUtil;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.commons.io.FileUtils;
-import org.apache.archiva.common.utils.FileUtil;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.configuration.Configuration;
-import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.wagon.Wagon;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.util.Comparator;
import java.util.List;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class Maven2RepositoryMetadataResolverTest
extends TestCase
{
private static final Filter<String> ALL = new AllFilter<String>();
@Inject
- @Named(value = "repositoryStorage#maven2")
+ @Named( value = "repositoryStorage#maven2" )
private Maven2RepositoryStorage storage;
private static final String TEST_REPO_ID = "test";
public void testGetProjectVersionMetadata()
throws Exception
{
- ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva",
- "archiva-common", "1.2.1" );
+ ProjectVersionMetadata metadata =
+ storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertEquals( "jar", facet.getPackaging() );
assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
public void testGetArtifactMetadata()
throws Exception
{
- Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID,
- "org.codehaus.plexus",
- "plexus-spring", "1.2", ALL );
+ Collection<ArtifactMetadata> springArtifacts =
+ storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
public void testGetArtifactMetadataSnapshots()
throws Exception
{
- Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test",
- "test-artifact", "1.0-SNAPSHOT",
- ALL );
+ Collection<ArtifactMetadata> testArtifacts =
+ storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
public void testGetProjectVersionMetadataForTimestampedSnapshot()
throws Exception
{
- ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache",
- "5-SNAPSHOT" );
+ ProjectVersionMetadata metadata =
+ storage.readProjectVersionMetadata( 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() );
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
"target/test-repository/com/example/test/test-artifact-module-a" );
- ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
- "test-artifact-module-a", "1.0" );
+ ProjectVersionMetadata metadata =
+ storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertEquals( "jar", facet.getPackaging() );
@Test
public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
- throws Exception
+ throws Exception
{
// remove configuration
Configuration config = configuration.getConfiguration();
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
"target/test-repository/com/example/test/test-artifact-module-a" );
- ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
- "test-artifact-module-a", "1.0" );
+ ProjectVersionMetadata metadata =
+ storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
assertEquals( "1.0", metadata.getId() );
- MavenProjectFacet facet = ( MavenProjectFacet ) metadata.getFacet( MavenProjectFacet.FACET_ID );
+ MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertNotNull( facet );
assertEquals( "com.example.test", facet.getGroupId() );
assertEquals( "test-artifact-module-a", facet.getArtifactId() );
@Test
public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
- throws Exception
+ throws Exception
{
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
"target/test-repository/com/example/test/test-artifact-module-a" );
- ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
+ ProjectVersionMetadata metadata =
+ storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
assertEquals( "1.1", metadata.getId() );
- MavenProjectFacet facet = ( MavenProjectFacet ) metadata.getFacet( MavenProjectFacet.FACET_ID );
+ MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertNotNull( facet );
assertEquals( "com.example.test", facet.getGroupId() );
assertEquals( "missing-parent", facet.getArtifactId() );
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
"target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
- ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
- "test-snapshot-artifact-module-a", "1.1-SNAPSHOT" );
+ ProjectVersionMetadata metadata =
+ storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
+ "1.1-SNAPSHOT" );
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertEquals( "jar", facet.getPackaging() );
@Test
public void testGetRootNamespaces()
+ throws Exception
{
assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
}
@Test
public void testGetNamespaces()
+ throws Exception
{
assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
- assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "com.example.test",
- ALL ) );
+ assertEquals( Collections.<String>emptyList(),
+ storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
- assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva",
- ALL ) );
- assertEquals( Arrays.asList( "plugins", "shared" ), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven",
- ALL ) );
- assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins",
- ALL ) );
- assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared",
- ALL ) );
+ assertEquals( Collections.<String>emptyList(),
+ storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
+ assertEquals( Arrays.asList( "plugins", "shared" ),
+ storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
+ assertEquals( Collections.<String>emptyList(),
+ storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
+ assertEquals( Collections.<String>emptyList(),
+ storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
- assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus",
- ALL ) );
+ assertEquals( Collections.<String>emptyList(),
+ storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
}
@Test
public void testGetProjects()
+ throws Exception
{
assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
- "missing-metadata", "missing-parent", "test-artifact" ), storage.listProjects( TEST_REPO_ID,
- "com.example.test",
- ALL ) );
+ "missing-metadata", "missing-parent", "test-artifact" ),
+ storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
- assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins",
- ALL ) );
- assertEquals( Arrays.asList( "maven-downloader" ), storage.listProjects( TEST_REPO_ID,
- "org.apache.maven.shared", ALL ) );
+ assertEquals( Collections.<String>emptyList(),
+ storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
+ assertEquals( Arrays.asList( "maven-downloader" ),
+ storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
}
@Test
public void testGetProjectVersions()
+ throws Exception
{
- assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
- "incomplete-metadata", ALL ) );
- assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
- "malformed-metadata", ALL ) );
- assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
- "missing-metadata", ALL ) );
- assertEquals( Arrays.asList( "1.0" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
- "invalid-pom", ALL ) );
-
- assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache",
- "apache", ALL ) );
-
- assertEquals( Arrays.asList( "1.2.1", "1.2.2" ), storage.listProjectVersions( TEST_REPO_ID,
- "org.apache.archiva", "archiva",
- ALL ) );
- assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
- "archiva-base", ALL ) );
- assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
- "archiva-common", ALL ) );
- assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
- "archiva-modules", ALL ) );
- assertEquals( Arrays.asList( "3" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
- "archiva-parent", ALL ) );
-
- assertEquals( Collections.<String>emptyList(), storage.listProjectVersions( TEST_REPO_ID,
- "org.apache.maven.shared",
- "maven-downloader", ALL ) );
+ assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
+ storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
+ assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
+ storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
+ assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
+ storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
+ assertEquals( Arrays.asList( "1.0" ),
+ storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
+
+ assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
+
+ assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
+ assertEquals( Arrays.asList( "1.2.1" ),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
+ assertEquals( Arrays.asList( "1.2.1" ),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
+ assertEquals( Arrays.asList( "1.2.1" ),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
+ assertEquals( Arrays.asList( "3" ),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
+
+ assertEquals( Collections.<String>emptyList(),
+ storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
}
@Test
public void testGetArtifacts()
+ throws Exception
{
- List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
- "org.codehaus.plexus",
- "plexus-spring",
- "1.2",
- ALL ) );
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
+ storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
assertEquals( 3, artifacts.size() );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
@Test
public void testGetArtifactsFiltered()
+ throws Exception
{
- ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
- "plexus-spring-1.2.pom" ) );
- List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
- "org.codehaus.plexus",
- "plexus-spring",
- "1.2",
- filter ) );
+ ExcludesFilter<String> filter =
+ new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
+ storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) );
assertEquals( 2, artifacts.size() );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
@Test
public void testGetArtifactsTimestampedSnapshots()
+ throws Exception
{
- List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
- "com.example.test",
- "missing-metadata",
- "1.0-SNAPSHOT",
- ALL ) );
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
+ storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT",
+ ALL ) );
assertEquals( 1, artifacts.size() );
ArtifactMetadata artifact = artifacts.get( 0 );
}
private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
- throws IOException
+ throws IOException
{
- for( String path : pathsToBeDeleted )
+ for ( String path : pathsToBeDeleted )
{
- File dir = new File( FileUtil.getBasedir(), path );
+ File dir = new File( FileUtil.getBasedir(), path );
FileUtils.deleteDirectory( dir );
assertFalse( dir.exists() );
}
File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
- File parentPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
+ File parentPom =
+ new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
FileUtils.deleteDirectory( dest );
}
private File copyTestArtifactWithParent( String srcPath, String destPath )
- throws IOException
+ throws IOException
{
File src = new File( FileUtil.getBasedir(), srcPath );
File dest = new File( FileUtil.getBasedir(), destPath );
<exclude>org.codehaus.plexus.registry:plexus-registry-api</exclude>
<exclude>org.codehaus.plexus.registry:plexus-registry-commons</exclude>
<exclude>>org.codehaus.plexus:plexus-taskqueue</exclude>
- <exclude>org.apache.maven.wagon:wagon-http-lightweight</exclude>
</excludes>
</bannedDependencies>
</rules>