Return-Path: Delivered-To: apmail-maven-archiva-commits-archive@locus.apache.org Received: (qmail 51640 invoked from network); 14 Jun 2007 10:47:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Jun 2007 10:47:35 -0000 Received: (qmail 66132 invoked by uid 500); 14 Jun 2007 10:47:31 -0000 Delivered-To: apmail-maven-archiva-commits-archive@maven.apache.org Received: (qmail 66077 invoked by uid 500); 14 Jun 2007 10:47:30 -0000 Mailing-List: contact archiva-commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: archiva-dev@maven.apache.org Delivered-To: mailing list archiva-commits@maven.apache.org Received: (qmail 66018 invoked by uid 99); 14 Jun 2007 10:47:29 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2007 03:47:29 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jun 2007 03:47:25 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id EC6B41A981A; Thu, 14 Jun 2007 03:47:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r547209 - in /maven/archiva/trunk: archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/... Date: Thu, 14 Jun 2007 10:47:03 -0000 To: archiva-commits@maven.apache.org From: oching@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070614104704.EC6B41A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oching Date: Thu Jun 14 03:47:02 2007 New Revision: 547209 URL: http://svn.apache.org/viewvc?view=rev&rev=547209 Log: 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) Added: maven/archiva/trunk/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java Modified: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml Modified: maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java?view=diff&rev=547209&r1=547208&r2=547209 ============================================================================== --- maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java (original) +++ maven/archiva/trunk/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java Thu Jun 14 03:47:02 2007 @@ -33,15 +33,19 @@ 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 @@ // 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 ) { @@ -297,6 +313,96 @@ ProjectModelResolver wrapped = new WrappedDatabaseProjectModelResolver( dao, resolver ); effectiveModelFilter.addProjectModelResolver( wrapped ); } + } + } + + 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 ); } } } Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java?view=diff&rev=547209&r1=547208&r2=547209 ============================================================================== --- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java (original) +++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java Thu Jun 14 03:47:02 2007 @@ -25,7 +25,7 @@ * @author Joakim Erdfelt * @version $Id$ */ -class FilenameParts +public class FilenameParts { public String artifactId; Added: maven/archiva/trunk/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java?view=auto&rev=547209 ============================================================================== --- maven/archiva/trunk/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java (added) +++ maven/archiva/trunk/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java Thu Jun 14 03:47:02 2007 @@ -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 + *

+ * Maria Odea Ching + */ +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; + } +} Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java?view=diff&rev=547209&r1=547208&r2=547209 ============================================================================== --- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java (original) +++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java Thu Jun 14 03:47:02 2007 @@ -90,7 +90,17 @@ public String artifact() throws ObjectNotFoundException, ArchivaDatabaseException { - this.model = repoBrowsing.selectVersion( groupId, artifactId, version ); + 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; } Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml?view=diff&rev=547209&r1=547208&r2=547209 ============================================================================== --- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml (original) +++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml Thu Jun 14 03:47:02 2007 @@ -192,7 +192,8 @@ - /WEB-INF/jsp/showArtifact.jsp + /WEB-INF/jsp/generalError.jsp + /WEB-INF/jsp/showArtifact.jsp