diff options
author | Maria Odea B. Ching <oching@apache.org> | 2007-06-14 10:47:02 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2007-06-14 10:47:02 +0000 |
commit | 4d18f5723d50a7289c1c55805cb34cd80b9c528a (patch) | |
tree | 9d8db56384ebcb0d4024ab730b5e6b70536b82c2 | |
parent | 03561e57c8cded9314bfe318ed8cb235adf10153 (diff) | |
download | archiva-4d18f5723d50a7289c1c55805cb34cd80b9c528a.tar.gz archiva-4d18f5723d50a7289c1c55805cb34cd80b9c528a.zip |
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
5 files changed, 195 insertions, 3 deletions
diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java index 763c2c2ba..688e52add 100644 --- a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java +++ b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java @@ -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 ); + } + } } diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java index 9ef6c98fb..252c4d125 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/FilenameParts.java @@ -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; diff --git a/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java b/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java new file mode 100644 index 000000000..502489310 --- /dev/null +++ b/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/CorruptArtifactReport.java @@ -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; + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index 408335bbd..2cc60ef86 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -90,7 +90,17 @@ public class ShowArtifactAction 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; } diff --git a/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 804d537ec..cabc9f9d3 100644 --- a/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -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"> |