mirror of
https://github.com/apache/archiva.git
synced 2025-03-09 02:10:00 +00:00
[MRM-692]
Applied patch submitted by Dario Oliveros -added RepositoryProblemByArtifactConstraint for querying repo problems by artifact -remove repo problems if artifact no longer exists in the repo git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@628473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
681c994753
commit
c1744c0312
@ -22,9 +22,13 @@
|
||||
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
|
||||
import org.apache.maven.archiva.consumers.ConsumerException;
|
||||
import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
|
||||
import org.apache.maven.archiva.database.Constraint;
|
||||
import org.apache.maven.archiva.database.RepositoryProblemDAO;
|
||||
import org.apache.maven.archiva.database.constraints.RepositoryProblemByArtifactConstraint;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.database.ArtifactDAO;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.model.RepositoryProblem;
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RepositoryContentFactory;
|
||||
import org.apache.maven.archiva.repository.RepositoryException;
|
||||
@ -61,7 +65,12 @@ public class DatabaseCleanupRemoveArtifactConsumer
|
||||
* @plexus.requirement role-hint="jdo"
|
||||
*/
|
||||
private ArtifactDAO artifactDAO;
|
||||
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="jdo"
|
||||
*/
|
||||
private RepositoryProblemDAO repositoryProblemDAO;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
@ -80,34 +89,47 @@ public void completeScan()
|
||||
|
||||
public List<String> getIncludedTypes()
|
||||
{
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void processArchivaArtifact( ArchivaArtifact artifact )
|
||||
throws ConsumerException
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagedRepositoryContent repositoryContent =
|
||||
repositoryFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
|
||||
|
||||
File file = new File( repositoryContent.getRepoRoot(), repositoryContent.toPath( artifact ) );
|
||||
|
||||
if( !file.exists() )
|
||||
{
|
||||
artifactDAO.deleteArtifact( artifact );
|
||||
}
|
||||
}
|
||||
catch ( RepositoryException re )
|
||||
{
|
||||
throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " +
|
||||
re.getMessage() );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagedRepositoryContent repositoryContent =
|
||||
repositoryFactory.getManagedRepositoryContent( artifact.getModel().getRepositoryId() );
|
||||
|
||||
File file = new File( repositoryContent.getRepoRoot(), repositoryContent.toPath( artifact ) );
|
||||
|
||||
if( !file.exists() )
|
||||
{
|
||||
artifactDAO.deleteArtifact( artifact );
|
||||
|
||||
// Remove all repository problems related to this artifact
|
||||
Constraint artifactConstraint = new RepositoryProblemByArtifactConstraint( artifact );
|
||||
List<RepositoryProblem> repositoryProblems =
|
||||
repositoryProblemDAO.queryRepositoryProblems( artifactConstraint );
|
||||
|
||||
if ( repositoryProblems != null )
|
||||
{
|
||||
for ( RepositoryProblem repositoryProblem : repositoryProblems )
|
||||
{
|
||||
repositoryProblemDAO.deleteRepositoryProblem( repositoryProblem );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( RepositoryException re )
|
||||
{
|
||||
throw new ConsumerException( "Can't run database cleanup remove artifact consumer: " +
|
||||
re.getMessage() );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
throw new ConsumerException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
@ -128,9 +150,14 @@ public void setArtifactDAO( ArtifactDAO artifactDAO)
|
||||
{
|
||||
this.artifactDAO = artifactDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setRepositoryProblemDAO( RepositoryProblemDAO repositoryProblemDAO )
|
||||
{
|
||||
this.repositoryProblemDAO = repositoryProblemDAO;
|
||||
}
|
||||
|
||||
public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
|
||||
{
|
||||
this.repositoryFactory = repositoryFactory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,11 @@
|
||||
import org.easymock.MockControl;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.database.ArtifactDAO;
|
||||
import org.apache.maven.archiva.database.RepositoryProblemDAO;
|
||||
|
||||
/**
|
||||
* Test for DatabaseCleanupRemoveArtifactConsumerTest
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
|
||||
*/
|
||||
public class DatabaseCleanupRemoveArtifactConsumerTest
|
||||
@ -35,6 +36,10 @@ public class DatabaseCleanupRemoveArtifactConsumerTest
|
||||
|
||||
private ArtifactDAO artifactDAOMock;
|
||||
|
||||
private MockControl repositoryProblemDAOControl;
|
||||
|
||||
private RepositoryProblemDAO repositoryProblemDAOMock;
|
||||
|
||||
private DatabaseCleanupRemoveArtifactConsumer dbCleanupRemoveArtifactConsumer;
|
||||
|
||||
public void setUp()
|
||||
@ -48,8 +53,14 @@ public void setUp()
|
||||
|
||||
artifactDAOMock = (ArtifactDAO) artifactDAOControl.getMock();
|
||||
|
||||
repositoryProblemDAOControl = MockControl.createControl( RepositoryProblemDAO.class );
|
||||
|
||||
repositoryProblemDAOMock = (RepositoryProblemDAO) repositoryProblemDAOControl.getMock();
|
||||
|
||||
dbCleanupRemoveArtifactConsumer.setArtifactDAO( artifactDAOMock );
|
||||
|
||||
|
||||
dbCleanupRemoveArtifactConsumer.setRepositoryProblemDAO( repositoryProblemDAOMock );
|
||||
|
||||
dbCleanupRemoveArtifactConsumer.setRepositoryFactory( repositoryFactory );
|
||||
}
|
||||
|
||||
@ -60,9 +71,13 @@ public void testIfArtifactWasNotDeleted()
|
||||
|
||||
artifactDAOControl.replay();
|
||||
|
||||
repositoryProblemDAOControl.replay();
|
||||
|
||||
dbCleanupRemoveArtifactConsumer.processArchivaArtifact( artifact );
|
||||
|
||||
artifactDAOControl.verify();
|
||||
|
||||
repositoryProblemDAOControl.verify();
|
||||
}
|
||||
|
||||
public void testIfArtifactWasDeleted()
|
||||
@ -73,10 +88,10 @@ public void testIfArtifactWasDeleted()
|
||||
artifactDAOMock.deleteArtifact( artifact );
|
||||
|
||||
artifactDAOControl.replay();
|
||||
|
||||
|
||||
dbCleanupRemoveArtifactConsumer.processArchivaArtifact( artifact );
|
||||
|
||||
artifactDAOControl.verify();
|
||||
artifactDAOControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package org.apache.maven.archiva.database.constraints;
|
||||
|
||||
/*
|
||||
* 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.Constraint;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
|
||||
/**
|
||||
* RepositoryProblemByArtifactConstraint
|
||||
*/
|
||||
public class RepositoryProblemByArtifactConstraint
|
||||
extends AbstractDeclarativeConstraint
|
||||
implements Constraint
|
||||
{
|
||||
private String whereClause;
|
||||
|
||||
private void createWhereClause( ArchivaArtifact artifact )
|
||||
{
|
||||
whereClause =
|
||||
"groupId.like(desiredGroupId) && artifactId.like(desiredArtifactId) && version.like(desiredVersion)";
|
||||
declParams = new String[] { "String desiredGroupId" , "String desiredArtifactId" , "String desiredVersion"};
|
||||
params = new Object[] { artifact.getGroupId() + "%" , artifact.getArtifactId() + "%", artifact.getVersion() + "%"};
|
||||
}
|
||||
|
||||
public RepositoryProblemByArtifactConstraint( ArchivaArtifact desiredArtifact )
|
||||
{
|
||||
super();
|
||||
createWhereClause( desiredArtifact );
|
||||
}
|
||||
|
||||
public String getSortColumn()
|
||||
{
|
||||
return "artifactId";
|
||||
}
|
||||
|
||||
public String getWhereCondition()
|
||||
{
|
||||
return whereClause;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user