mirror of https://github.com/apache/archiva.git
MRM-409 and MRM-376
-Added pom validation in ProjectModelToDatabaseConsumer -Added handling of ObjectNotFoundException in ShowArtifactAction -Created a new class CorruptArtifactReport for corrupt/invalid pom or artifact repository problem (to be added in database) git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@547209 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
03561e57c8
commit
4d18f5723d
|
@ -33,15 +33,19 @@ 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;
|
||||
import org.apache.maven.archiva.model.RepositoryProblem;
|
||||
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.layout.FilenameParts;
|
||||
import org.apache.maven.archiva.repository.layout.RepositoryLayoutUtils;
|
||||
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.apache.maven.archiva.reporting.artifact.CorruptArtifactReport;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
|
@ -181,11 +185,23 @@ public class ProjectModelToDatabaseConsumer
|
|||
// Resolve the project model
|
||||
model = effectiveModelFilter.filter( model );
|
||||
|
||||
if( isValidModel( model, artifact ) )
|
||||
{
|
||||
dao.getProjectModelDAO().saveProjectModel( model );
|
||||
}
|
||||
else
|
||||
{
|
||||
getLogger().warn( "Invalid or corrupt pom. Project model " + model
|
||||
+ " was not added in the database." );
|
||||
}
|
||||
|
||||
dao.getProjectModelDAO().saveProjectModel( model );
|
||||
}
|
||||
catch ( ProjectModelException e )
|
||||
{
|
||||
getLogger().warn( "Unable to read project model " + artifactFile + " : " + e.getMessage(), e );
|
||||
|
||||
addProblem( artifact, "Unable to read project model " + artifactFile + " : " + e.getMessage() );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
|
@ -299,4 +315,94 @@ public class ProjectModelToDatabaseConsumer
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String toPath( ArchivaArtifact artifact )
|
||||
{
|
||||
try
|
||||
{
|
||||
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( artifact );
|
||||
return layout.toPath( artifact );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
getLogger().warn( "Unable to calculate path for artifact: " + artifact );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidModel( ArchivaProjectModel model, ArchivaArtifact artifact )
|
||||
throws ConsumerException
|
||||
{
|
||||
File artifactFile = toFile( artifact );
|
||||
|
||||
try
|
||||
{
|
||||
FilenameParts parts = RepositoryLayoutUtils.splitFilename( artifactFile.getName(), null );
|
||||
if ( !parts.artifactId.equalsIgnoreCase( model.getArtifactId() ) )
|
||||
{
|
||||
getLogger().warn( "Project Model " + model + " artifactId: " + model.getArtifactId() +
|
||||
" does not match the pom file's artifactId: " + parts.artifactId );
|
||||
|
||||
addProblem( artifact, "Project Model " + model + " artifactId: " + model.getArtifactId() +
|
||||
" does not match the pom file's artifactId: " + parts.artifactId );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !parts.version.equalsIgnoreCase( model.getVersion() ) )
|
||||
{
|
||||
getLogger().warn( "Project Model " + model + " artifactId: " + model.getArtifactId() +
|
||||
" does not match the pom file's artifactId: " + parts.artifactId );
|
||||
|
||||
addProblem( artifact, "Project Model " + model + " version: " + model.getVersion() +
|
||||
" does not match the pom file's version: " + parts.version );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//check if the file name matches the values indicated in the pom
|
||||
if( !artifactFile.getName().equalsIgnoreCase( model.getArtifactId() + "-" + model.getVersion() + "-" + parts.classifier) )
|
||||
{
|
||||
getLogger().warn( "Artifact " + artifact + " does not match the artifactId and/or version " +
|
||||
"specified in the project model " + model );
|
||||
|
||||
addProblem( artifact, "Artifact " + artifact + " does not match the artifactId and/or version " +
|
||||
"specified in the project model " + model );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
catch ( LayoutException le )
|
||||
{
|
||||
throw new ConsumerException( le.getMessage() );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addProblem( ArchivaArtifact artifact, String msg )
|
||||
throws ConsumerException
|
||||
{
|
||||
RepositoryProblem problem = new RepositoryProblem();
|
||||
problem.setRepositoryId( artifact.getModel().getRepositoryId() );
|
||||
problem.setPath( toPath( artifact ) );
|
||||
problem.setGroupId( artifact.getGroupId() );
|
||||
problem.setArtifactId( artifact.getArtifactId() );
|
||||
problem.setVersion( artifact.getVersion() );
|
||||
problem.setType( CorruptArtifactReport.PROBLEM_TYPE_CORRUPT_ARTIFACT );
|
||||
problem.setOrigin( getId() );
|
||||
problem.setMessage( msg );
|
||||
|
||||
try
|
||||
{
|
||||
dao.getRepositoryProblemDAO().saveRepositoryProblem( problem );
|
||||
}
|
||||
catch ( ArchivaDatabaseException e )
|
||||
{
|
||||
String emsg = "Unable to save problem with artifact location to DB: " + e.getMessage();
|
||||
getLogger().warn( emsg, e );
|
||||
throw new ConsumerException( emsg, e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ package org.apache.maven.archiva.repository.layout;
|
|||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
class FilenameParts
|
||||
public class FilenameParts
|
||||
{
|
||||
public String artifactId;
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package org.apache.maven.archiva.reporting.artifact;
|
||||
|
||||
/*
|
||||
* 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.reporting.DynamicReportSource;
|
||||
import org.apache.maven.archiva.reporting.DataLimits;
|
||||
import org.apache.maven.archiva.database.ArchivaDAO;
|
||||
import org.apache.maven.archiva.database.Constraint;
|
||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
||||
import org.apache.maven.archiva.database.ArchivaDatabaseException;
|
||||
import org.apache.maven.archiva.database.constraints.RepositoryProblemByTypeConstraint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Report for corrupt artifacts
|
||||
* <p/>
|
||||
* <a href="mailto:oching@apache.org">Maria Odea Ching</a>
|
||||
*/
|
||||
public class CorruptArtifactReport
|
||||
implements DynamicReportSource
|
||||
{
|
||||
public static final String PROBLEM_TYPE_CORRUPT_ARTIFACT = "corrupt-artifact";
|
||||
|
||||
/**
|
||||
* @plexus.configuration default-value="Corrupt Artifact Report"
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* @plexus.requirement role-hint="jdo"
|
||||
*/
|
||||
private ArchivaDAO dao;
|
||||
|
||||
private Constraint constraint;
|
||||
|
||||
public CorruptArtifactReport()
|
||||
{
|
||||
constraint = new RepositoryProblemByTypeConstraint( PROBLEM_TYPE_CORRUPT_ARTIFACT );
|
||||
}
|
||||
|
||||
public List getData()
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
return dao.getRepositoryProblemDAO().queryRepositoryProblems( constraint );
|
||||
}
|
||||
|
||||
public List getData( DataLimits limits )
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
return dao.getRepositoryProblemDAO().queryRepositoryProblems( constraint );
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -89,8 +89,18 @@ public class ShowArtifactAction
|
|||
*/
|
||||
public String artifact()
|
||||
throws ObjectNotFoundException, ArchivaDatabaseException
|
||||
{
|
||||
try
|
||||
{
|
||||
this.model = repoBrowsing.selectVersion( groupId, artifactId, version );
|
||||
}
|
||||
catch ( ObjectNotFoundException oe )
|
||||
{
|
||||
addActionError( "Unable to find project model for [" + groupId + ":" + artifactId
|
||||
+ ":" + version + "]." );
|
||||
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
|
@ -192,7 +192,8 @@
|
|||
</action>
|
||||
|
||||
<action name="showArtifact" class="showArtifactAction" method="artifact">
|
||||
<result>/WEB-INF/jsp/showArtifact.jsp</result>
|
||||
<result name="error">/WEB-INF/jsp/generalError.jsp</result>
|
||||
<result name="success">/WEB-INF/jsp/showArtifact.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="showArtifactMailingLists" class="showArtifactAction" method="mailingLists">
|
||||
|
|
Loading…
Reference in New Issue