archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
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 GMT
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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @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
+ * <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;
+    }
+}

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 @@
     </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">



Mime
View raw message