mirror of https://github.com/apache/archiva.git
[MRM-380]: When trying to look at project with empty groupId
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@542604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
09eeee41d4
commit
7f4271c1df
|
@ -21,12 +21,14 @@ package org.apache.maven.archiva.consumers.database;
|
|||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationNames;
|
||||
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
|
||||
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
|
||||
import org.apache.maven.archiva.consumers.ConsumerException;
|
||||
import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArchivaProjectModel;
|
||||
import org.apache.maven.archiva.model.RepositoryURL;
|
||||
|
@ -34,11 +36,19 @@ import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
|
|||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
|
||||
import org.apache.maven.archiva.repository.layout.LayoutException;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelException;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelReader;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
|
||||
import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelFilter;
|
||||
import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectModelResolverFactory;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
import org.codehaus.plexus.registry.RegistryListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -53,7 +63,7 @@ import java.util.List;
|
|||
*/
|
||||
public class ProjectModelToDatabaseConsumer
|
||||
extends AbstractMonitoredConsumer
|
||||
implements DatabaseUnprocessedArtifactConsumer
|
||||
implements DatabaseUnprocessedArtifactConsumer, RegistryListener, Initializable
|
||||
{
|
||||
/**
|
||||
* @plexus.configuration default-value="update-db-project"
|
||||
|
@ -90,6 +100,27 @@ public class ProjectModelToDatabaseConsumer
|
|||
*/
|
||||
private ProjectModelReader project300Reader;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="expression"
|
||||
*/
|
||||
private ProjectModelFilter expressionModelFilter;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private RepositoryProjectModelResolverFactory resolverFactory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.repository.project.ProjectModelFilter"
|
||||
* role-hint="effective"
|
||||
*/
|
||||
private EffectiveProjectModelFilter effectiveModelFilter;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="database"
|
||||
*/
|
||||
private ProjectModelResolver databaseResolver;
|
||||
|
||||
private List includes;
|
||||
|
||||
public ProjectModelToDatabaseConsumer()
|
||||
|
@ -100,14 +131,12 @@ public class ProjectModelToDatabaseConsumer
|
|||
|
||||
public void beginScan()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
/* nothing to do here */
|
||||
}
|
||||
|
||||
public void completeScan()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
/* nothing to do here */
|
||||
}
|
||||
|
||||
public List getIncludedTypes()
|
||||
|
@ -120,32 +149,64 @@ public class ProjectModelToDatabaseConsumer
|
|||
{
|
||||
if ( !StringUtils.equals( "pom", artifact.getType() ) )
|
||||
{
|
||||
// Not a pom. Skip it.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( hasProjectModelInDatabase( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ) )
|
||||
{
|
||||
// Already in the database. Skip it.
|
||||
return;
|
||||
}
|
||||
|
||||
File artifactFile = toFile( artifact );
|
||||
RepositoryConfiguration repo = getRepository( artifact );
|
||||
ProjectModelReader reader = project400Reader;
|
||||
|
||||
if ( StringUtils.equals( "default", repo.getLayout() ) )
|
||||
if ( StringUtils.equals( "legacy", repo.getLayout() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
ArchivaProjectModel model = project400Reader.read( artifactFile );
|
||||
|
||||
model.setOrigin( "filesystem" );
|
||||
|
||||
dao.getProjectModelDAO().saveProjectModel( model );
|
||||
}
|
||||
catch ( ProjectModelException e )
|
||||
{
|
||||
getLogger().warn( "Unable to read project model " + artifactFile + " : " + e.getMessage(), e );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
getLogger().warn(
|
||||
"Unable to save project model " + artifactFile + " to the database : "
|
||||
+ e.getMessage(), e );
|
||||
}
|
||||
reader = project300Reader;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ArchivaProjectModel model = reader.read( artifactFile );
|
||||
|
||||
model.setOrigin( "filesystem" );
|
||||
|
||||
// Filter the model
|
||||
model = expressionModelFilter.filter( model );
|
||||
|
||||
// Resolve the project model
|
||||
model = effectiveModelFilter.filter( model );
|
||||
|
||||
dao.getProjectModelDAO().saveProjectModel( model );
|
||||
}
|
||||
catch ( ProjectModelException e )
|
||||
{
|
||||
getLogger().warn( "Unable to read project model " + artifactFile + " : " + e.getMessage(), e );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
getLogger().warn( "Unable to save project model " + artifactFile + " to the database : " + e.getMessage(),
|
||||
e );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasProjectModelInDatabase( String groupId, String artifactId, String version )
|
||||
{
|
||||
try
|
||||
{
|
||||
ArchivaProjectModel model = dao.getProjectModelDAO().getProjectModel( groupId, artifactId, version );
|
||||
return ( model != null );
|
||||
}
|
||||
catch ( ObjectNotFoundException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,4 +252,42 @@ public class ProjectModelToDatabaseConsumer
|
|||
return true;
|
||||
}
|
||||
|
||||
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
/* nothing to do here */
|
||||
}
|
||||
|
||||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
if ( ConfigurationNames.isRepositories( propertyName ) )
|
||||
{
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
throws InitializationException
|
||||
{
|
||||
update();
|
||||
archivaConfiguration.addChangeListener( this );
|
||||
}
|
||||
|
||||
private void update()
|
||||
{
|
||||
synchronized ( effectiveModelFilter )
|
||||
{
|
||||
effectiveModelFilter.clearResolvers();
|
||||
|
||||
// Add the database resolver first!
|
||||
effectiveModelFilter.addProjectModelResolver( databaseResolver );
|
||||
|
||||
List ret = this.resolverFactory.getAllResolvers();
|
||||
Iterator it = ret.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
ProjectModelResolver resolver = (ProjectModelResolver) it.next();
|
||||
effectiveModelFilter.addProjectModelResolver( resolver );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package org.apache.maven.archiva.consumers.database.project;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.model.ArchivaProjectModel;
|
||||
import org.apache.maven.archiva.model.VersionedReference;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelException;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
|
||||
|
||||
/**
|
||||
* Resolves a project model from the database.
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
* @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelResolver"
|
||||
* role-hint="database"
|
||||
*/
|
||||
public class DatabaseProjectModelResolver
|
||||
implements ProjectModelResolver
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement role-hint="jdo"
|
||||
*/
|
||||
private ArchivaDAO dao;
|
||||
|
||||
public ArchivaProjectModel resolveProjectModel( VersionedReference reference )
|
||||
throws ProjectModelException
|
||||
{
|
||||
try
|
||||
{
|
||||
ArchivaProjectModel model = dao.getProjectModelDAO().getProjectModel( reference.getGroupId(),
|
||||
reference.getArtifactId(),
|
||||
reference.getVersion() );
|
||||
return model;
|
||||
}
|
||||
catch ( ObjectNotFoundException e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ package org.apache.maven.archiva.repository;
|
|||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationNames;
|
||||
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
|
||||
import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
|
@ -51,6 +52,11 @@ public class ActiveManagedRepositories
|
|||
|
||||
private List allManagedRepositories = new ArrayList();
|
||||
|
||||
/**
|
||||
* Get the {@link List} of {@link RepositoryConfiguration} objects representing managed repositories.
|
||||
*
|
||||
* @return the {@link List} of {@link RepositoryConfiguration} objects.
|
||||
*/
|
||||
public List getAllManagedRepositories()
|
||||
{
|
||||
synchronized ( allManagedRepositories )
|
||||
|
@ -86,7 +92,7 @@ public class ActiveManagedRepositories
|
|||
allManagedRepositories.clear();
|
||||
|
||||
List configRepos = archivaConfiguration.getConfiguration().getRepositories();
|
||||
CollectionUtils.select( configRepos, LocalRepositoryPredicate.getInstance() );
|
||||
CollectionUtils.filter( configRepos, LocalRepositoryPredicate.getInstance() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.maven.archiva.repository.project.ProjectModelException;
|
|||
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelMerge;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -42,17 +43,18 @@ import java.util.Map;
|
|||
* @version $Id$
|
||||
* @plexus.component role="org.apache.maven.archiva.repository.project.ProjectModelFilter"
|
||||
* role-hint="effective"
|
||||
* instantiation-strategy="per-lookup"
|
||||
*/
|
||||
public class EffectiveProjectModelFilter implements ProjectModelFilter
|
||||
public class EffectiveProjectModelFilter
|
||||
extends AbstractLogEnabled
|
||||
implements ProjectModelFilter
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement role-hint="expression"
|
||||
*/
|
||||
private ProjectModelFilter expressionFilter;
|
||||
|
||||
|
||||
private List projectModelResolvers;
|
||||
|
||||
|
||||
public EffectiveProjectModelFilter()
|
||||
{
|
||||
projectModelResolvers = new ArrayList();
|
||||
|
@ -99,7 +101,7 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
// Setup Expression Evaluation pieces.
|
||||
effectiveProject = expressionFilter.filter( effectiveProject );
|
||||
|
||||
debug( "Starting build of effective with: " + effectiveProject );
|
||||
getLogger().debug( "Starting build of effective with: " + effectiveProject );
|
||||
|
||||
// Merge in all the parent poms.
|
||||
effectiveProject = mergeParent( effectiveProject );
|
||||
|
@ -116,6 +118,11 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
this.projectModelResolvers.remove( resolver );
|
||||
}
|
||||
|
||||
public void clearResolvers()
|
||||
{
|
||||
this.projectModelResolvers.clear();
|
||||
}
|
||||
|
||||
private void applyDependencyManagement( ArchivaProjectModel pom )
|
||||
{
|
||||
if ( ( pom.getDependencyManagement() == null ) || ( pom.getDependencies() == null ) )
|
||||
|
@ -123,7 +130,7 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
// Nothing to do. All done!
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( pom.getDependencyManagement().isEmpty() || pom.getDependencies().isEmpty() )
|
||||
{
|
||||
// Nothing to do. All done!
|
||||
|
@ -149,14 +156,9 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
}
|
||||
}
|
||||
|
||||
private void debug( String msg )
|
||||
{
|
||||
System.out.println( "## " + msg );
|
||||
}
|
||||
|
||||
private ArchivaProjectModel findProject( VersionedReference projectRef )
|
||||
{
|
||||
debug( "Trying to find project: " + projectRef );
|
||||
getLogger().debug( "Trying to find project: " + projectRef );
|
||||
Iterator it = this.projectModelResolvers.iterator();
|
||||
|
||||
while ( it.hasNext() )
|
||||
|
@ -165,15 +167,15 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
|
||||
try
|
||||
{
|
||||
debug( "Trying to find in " + resolver.getClass().getName() );
|
||||
getLogger().debug( "Trying to find in " + resolver.getClass().getName() );
|
||||
ArchivaProjectModel model = resolver.resolveProjectModel( projectRef );
|
||||
|
||||
if ( model != null )
|
||||
{
|
||||
debug( "Found it!: " + model );
|
||||
getLogger().debug( "Found it!: " + model );
|
||||
return model;
|
||||
}
|
||||
debug( "Not found." );
|
||||
getLogger().debug( "Not found." );
|
||||
}
|
||||
catch ( ProjectModelException e )
|
||||
{
|
||||
|
@ -192,14 +194,14 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
{
|
||||
ArchivaProjectModel mixedProject;
|
||||
|
||||
debug( "Parent: " + pom.getParentProject() );
|
||||
getLogger().debug( "Parent: " + pom.getParentProject() );
|
||||
|
||||
if ( pom.getParentProject() != null )
|
||||
{
|
||||
// Use parent reference.
|
||||
VersionedReference parentRef = pom.getParentProject();
|
||||
|
||||
debug( "Has parent: " + parentRef );
|
||||
getLogger().debug( "Has parent: " + parentRef );
|
||||
|
||||
// Find parent using resolvers.
|
||||
ArchivaProjectModel parentProject = findProject( parentRef );
|
||||
|
@ -219,7 +221,7 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
}
|
||||
else
|
||||
{
|
||||
debug( "No parent found" );
|
||||
getLogger().debug( "No parent found" );
|
||||
|
||||
/* Mix in the super-pom.
|
||||
*
|
||||
|
@ -245,7 +247,7 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
|
|||
private ArchivaProjectModel mixinSuperPom( ArchivaProjectModel pom )
|
||||
{
|
||||
// TODO: add super pom repositories.
|
||||
debug( "Mix in Super POM: " + pom );
|
||||
getLogger().debug( "Mix in Super POM: " + pom );
|
||||
|
||||
return pom;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,233 @@
|
|||
package org.apache.maven.archiva.repository.project.resolvers;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationNames;
|
||||
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
|
||||
import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate;
|
||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.apache.maven.archiva.repository.ArchivaConfigurationAdaptor;
|
||||
import org.apache.maven.archiva.repository.RepositoryException;
|
||||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
|
||||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
|
||||
import org.apache.maven.archiva.repository.layout.LayoutException;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelReader;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
import org.codehaus.plexus.registry.RegistryListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Factory for ProjectModelResolver objects
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
* @plexus.component role="org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectModelResolverFactory"
|
||||
*/
|
||||
public class RepositoryProjectModelResolverFactory
|
||||
extends AbstractLogEnabled
|
||||
implements RegistryListener, Initializable
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private BidirectionalRepositoryLayoutFactory layoutFactory;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="model400"
|
||||
*/
|
||||
private ProjectModelReader project400Reader;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="model300"
|
||||
*/
|
||||
private ProjectModelReader project300Reader;
|
||||
|
||||
/**
|
||||
* Get the {@link ProjectModelResolver} for the specific archiva repository.
|
||||
*
|
||||
* @param repo the repository to base resolver on.
|
||||
* @return return the resolver for the archiva repository provided.
|
||||
* @throws RepositoryException if unable to create a resolver for the provided {@link ArchivaRepository}
|
||||
*/
|
||||
public ProjectModelResolver getResolver( ArchivaRepository repo )
|
||||
throws RepositoryException
|
||||
{
|
||||
if ( resolverMap.containsKey( repo.getId() ) )
|
||||
{
|
||||
return (ProjectModelResolver) this.resolverMap.get( repo.getId() );
|
||||
}
|
||||
|
||||
ProjectModelResolver resolver = toResolver( repo );
|
||||
resolverMap.put( repo.getId(), resolver );
|
||||
|
||||
return resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ProjectModelResolver} for the specific archiva repository based on repository id.
|
||||
*
|
||||
* @param repoid the repository id to get the resolver for.
|
||||
* @return the {@link ProjectModelResolver} if found, or null if repository is not found.
|
||||
*/
|
||||
public ProjectModelResolver getResolver( String repoid )
|
||||
{
|
||||
return (ProjectModelResolver) this.resolverMap.get( repoid );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link List} of {@link ProjectModelResolver} for
|
||||
* the {@link List} of {@link ArchivaRepository} objects provided.
|
||||
*
|
||||
* @param repositoryList the {@link List} of {@link ArchivaRepository} objects to
|
||||
* get {@link ProjectModelResolver} for.
|
||||
* @return the {@link List} of {@link ProjectModelResolver} objects.
|
||||
* @throws RepositoryException if unable to convert any of the provided {@link ArchivaRepository} objects into
|
||||
* a {@link ProjectModelResolver} object.
|
||||
*/
|
||||
public List getResolverList( List repositoryList )
|
||||
throws RepositoryException
|
||||
{
|
||||
List ret = new ArrayList();
|
||||
|
||||
if ( CollectionUtils.isEmpty( repositoryList ) )
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
Iterator it = repositoryList.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
ArchivaRepository repo = (ArchivaRepository) it.next();
|
||||
ret.add( getResolver( repo ) );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire {@link List} of {@link ProjectModelResolver} that the factory is tracking.
|
||||
*
|
||||
* @return the entire list of {@link ProjectModelResolver} that is being tracked.
|
||||
*/
|
||||
public List getAllResolvers()
|
||||
{
|
||||
List ret = new ArrayList();
|
||||
|
||||
ret.addAll( this.resolverMap.values() );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
if ( ConfigurationNames.isRepositories( propertyName ) )
|
||||
{
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
private Map resolverMap = new HashMap();
|
||||
|
||||
private void update()
|
||||
{
|
||||
synchronized ( resolverMap )
|
||||
{
|
||||
resolverMap.clear();
|
||||
|
||||
List configRepos = archivaConfiguration.getConfiguration().getRepositories();
|
||||
CollectionUtils.filter( configRepos, LocalRepositoryPredicate.getInstance() );
|
||||
|
||||
Iterator it = configRepos.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
RepositoryConfiguration repoconfig = (RepositoryConfiguration) it.next();
|
||||
ArchivaRepository repo = ArchivaConfigurationAdaptor.toArchivaRepository( repoconfig );
|
||||
try
|
||||
{
|
||||
RepositoryProjectResolver resolver = toResolver( repo );
|
||||
resolverMap.put( repo.getId(), resolver );
|
||||
}
|
||||
catch ( RepositoryException e )
|
||||
{
|
||||
getLogger().warn( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RepositoryProjectResolver toResolver( ArchivaRepository repo )
|
||||
throws RepositoryException
|
||||
{
|
||||
if ( !repo.isManaged() )
|
||||
{
|
||||
throw new RepositoryException( "Unable to create RepositoryProjectResolver from non-managed repository: "
|
||||
+ repo );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repo.getLayoutType() );
|
||||
ProjectModelReader reader = project400Reader;
|
||||
|
||||
if ( StringUtils.equals( "legacy", repo.getLayoutType() ) )
|
||||
{
|
||||
reader = project300Reader;
|
||||
}
|
||||
|
||||
RepositoryProjectResolver resolver = new RepositoryProjectResolver( repo, reader, layout );
|
||||
return resolver;
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
throw new RepositoryException( "Unable to create RepositoryProjectResolver due to invalid layout spec: "
|
||||
+ repo );
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
throws InitializationException
|
||||
{
|
||||
update();
|
||||
archivaConfiguration.addChangeListener( this );
|
||||
}
|
||||
}
|
|
@ -24,16 +24,14 @@ import org.apache.maven.archiva.model.ArchivaProjectModel;
|
|||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.apache.maven.archiva.model.VersionedReference;
|
||||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
|
||||
import org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelException;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelReader;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
|
||||
import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* RepositoryProjectResolver
|
||||
* Resolve Project from filesystem.
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
|
@ -47,11 +45,11 @@ public class RepositoryProjectResolver
|
|||
|
||||
private BidirectionalRepositoryLayout layout;
|
||||
|
||||
public RepositoryProjectResolver( ArchivaRepository repository )
|
||||
public RepositoryProjectResolver( ArchivaRepository repository, ProjectModelReader reader, BidirectionalRepositoryLayout layout )
|
||||
{
|
||||
this.repository = repository;
|
||||
this.reader = new ProjectModel400Reader();
|
||||
this.layout = new DefaultBidirectionalRepositoryLayout();
|
||||
this.reader = reader;
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public ArchivaProjectModel resolveProjectModel( VersionedReference reference )
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.apache.maven.archiva.model.ArchivaProjectModel;
|
|||
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||
import org.apache.maven.archiva.model.Dependency;
|
||||
import org.apache.maven.archiva.model.Individual;
|
||||
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
|
||||
import org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelException;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
|
||||
import org.apache.maven.archiva.repository.project.ProjectModelReader;
|
||||
|
@ -71,7 +73,9 @@ public class EffectiveProjectModelFilterTest
|
|||
ArchivaRepository repo = new ArchivaRepository( "defaultTestRepo", "Default Test Repo", "file://"
|
||||
+ defaultRepoDir.getAbsolutePath() );
|
||||
|
||||
RepositoryProjectResolver resolver = new RepositoryProjectResolver( repo );
|
||||
ProjectModelReader reader = new ProjectModel400Reader();
|
||||
BidirectionalRepositoryLayout layout = new DefaultBidirectionalRepositoryLayout();
|
||||
RepositoryProjectResolver resolver = new RepositoryProjectResolver( repo, reader, layout );
|
||||
|
||||
return resolver;
|
||||
}
|
||||
|
@ -101,10 +105,10 @@ public class EffectiveProjectModelFilterTest
|
|||
assertContainsSameIndividuals( "Individuals", expectedModel.getIndividuals(), effectiveModel.getIndividuals() );
|
||||
dumpDependencyList( "Expected", expectedModel.getDependencies() );
|
||||
dumpDependencyList( "Effective", effectiveModel.getDependencies() );
|
||||
assertContainsSameDependencies( "Dependencies", expectedModel.getDependencies(),
|
||||
effectiveModel.getDependencies() );
|
||||
assertContainsSameDependencies( "DependencyManagement", expectedModel.getDependencyManagement(),
|
||||
effectiveModel.getDependencyManagement() );
|
||||
assertContainsSameDependencies( "Dependencies", expectedModel.getDependencies(), effectiveModel
|
||||
.getDependencies() );
|
||||
assertContainsSameDependencies( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
|
||||
.getDependencyManagement() );
|
||||
}
|
||||
|
||||
private void dumpDependencyList( String type, List deps )
|
||||
|
|
Loading…
Reference in New Issue