]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1283] keep track of incomplete metadata so that it can self correct and show...
authorBrett Porter <brett@apache.org>
Thu, 24 Dec 2009 04:02:11 +0000 (04:02 +0000)
committerBrett Porter <brett@apache.org>
Thu, 24 Dec 2009 04:02:11 +0000 (04:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@893691 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java

index ae967dae8d8dd5df9817acac101a6ba1048203ac..fec93b15eec628526df450e2d969c340ed857713 100644 (file)
@@ -166,8 +166,9 @@ public class ArchivaMetadataCreationConsumer
         ProjectVersionMetadata versionMetadata = null;
         try
         {
-            versionMetadata = storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(),
-                                               projectVersion );
+            versionMetadata =
+                storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(),
+                                                   projectVersion );
         }
         catch ( MetadataResolutionException e )
         {
@@ -180,6 +181,7 @@ public class ArchivaMetadataCreationConsumer
             log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" );
             versionMetadata = new ProjectVersionMetadata();
             versionMetadata.setId( projectVersion );
+            versionMetadata.setIncomplete( true );
             createVersionMetadata = true;
         }
 
index 9f2502481104b5ac80a9e045d6b537204ba25cec..523ed0a85ddc0110182c5ca39f69184909e84fce 100644 (file)
@@ -121,7 +121,11 @@ public class ShowArtifactAction
                 }
                 catch ( MetadataResolutionException e )
                 {
-                    errorMsg = e.getMessage();
+                    addIncompleteModelWarning();
+                    
+                    // TODO: need a consistent way to construct this - same in ArchivaMetadataCreationConsumer
+                    versionMetadata = new ProjectVersionMetadata();
+                    versionMetadata.setId( version );
                 }
                 if ( versionMetadata != null )
                 {
@@ -161,11 +165,22 @@ public class ShowArtifactAction
             addActionError( errorMsg != null ? errorMsg : "Artifact not found" );
             return ERROR;
         }
+
+        if ( versionMetadata.isIncomplete() )
+        {
+            addIncompleteModelWarning();
+        }
+
         model = versionMetadata;
 
         return SUCCESS;
     }
 
+    private void addIncompleteModelWarning()
+    {
+        addActionMessage( "The model may be incomplete due to a previous error in resolving information. Refer to the repository problem reports for more information." );
+    }
+
     /**
      * Show the artifact information tab.
      */
index 37df9fb6a30725c729b0d01f62694812d7ca1e4f..641b6d52d3251ffb0d4f85ef9153cde00d8d2504 100644 (file)
         <%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %>
       </c:otherwise>
     </c:choose>
+
+    <s:if test="hasActionMessages()">
+      <div id="messages">
+        <s:actionmessage />
+      </div>
+    </s:if>
   </div>
 </div>
 
index f9c47eb88ee2be3c7776323c9209574d23b32da3..ef9c51eac533c32b775a5f94ed46b1e35f91931c 100644 (file)
@@ -338,4 +338,15 @@ div.versions {
 div.versions a.expand {
     font-size: 7pt;
        color: gray;    
-}
\ No newline at end of file
+}
+
+#messages {
+    background-color: yellow;
+    border: 1px solid orange;
+    margin-top: 2em;
+}
+
+#messages ul {
+    list-style-image: url(../images/icon_warning_sml.gif)
+}
+
index e6dcabe840ca72bc6ab7d5fbd655e7abf9fcffde..9973c45c4efaeb382eeeca105a360667f27a0e7a 100644 (file)
@@ -51,6 +51,8 @@ public class ProjectVersionMetadata
 
     private List<Dependency> dependencies = new ArrayList<Dependency>();
 
+    private boolean incomplete;
+
     public String getId()
     {
         return id;
@@ -205,4 +207,14 @@ public class ProjectVersionMetadata
     {
         this.dependencies.add( dependency );
     }
+
+    public boolean isIncomplete()
+    {
+        return incomplete;
+    }
+
+    public void setIncomplete( boolean incomplete )
+    {
+        this.incomplete = incomplete;
+    }
 }
index 15fd9c48572d44a2b34bb744cc2a33a9163a97bb..a0d7d7f905fdbabc3008cb2a114c3812bda253de 100644 (file)
@@ -68,7 +68,10 @@ public class DefaultMetadataResolver
             metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion );
         // TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated)
         //       in such cases we might also remove/update stale metadata, including adjusting plugin-based facets
-        if ( metadata == null )
+        //       This would also be better than checking for completeness - we can then refresh only when fixed (though
+        //       sometimes this has an additional dependency - such as a parent - requesting the user to force an update
+        //       may then work here and be more efficient than always trying again)
+        if ( metadata == null || metadata.isIncomplete() )
         {
             metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
             if ( metadata != null )
index ac1b03c6ee96937c9f613c5c43d0a5d2c6dbb988..6011dbca8f0c6822497704dd08096b98d479d705 100644 (file)
@@ -131,6 +131,7 @@ public class FileMetadataRepository
         setProperty( properties, "name", versionMetadata.getName() );
         setProperty( properties, "description", versionMetadata.getDescription() );
         setProperty( properties, "url", versionMetadata.getUrl() );
+        setProperty( properties, "incomplete", String.valueOf( versionMetadata.isIncomplete() ) );
         if ( versionMetadata.getScm() != null )
         {
             setProperty( properties, "scm.connection", versionMetadata.getScm().getConnection() );
@@ -653,6 +654,7 @@ public class FileMetadataRepository
             versionMetadata.setName( properties.getProperty( "name" ) );
             versionMetadata.setDescription( properties.getProperty( "description" ) );
             versionMetadata.setUrl( properties.getProperty( "url" ) );
+            versionMetadata.setIncomplete( Boolean.valueOf( properties.getProperty( "incomplete", "false" ) ) );
 
             String scmConnection = properties.getProperty( "scm.connection" );
             String scmDeveloperConnection = properties.getProperty( "scm.developerConnection" );
index 0cfb2a7ba633358cda30367c1edc559724ca83b1..915b0190f798961d5efb013aa91d5cb4d47d7854 100644 (file)
@@ -39,6 +39,9 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.commons.io.FileUtils;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
+/**
+ * @todo should this be a generic MetadataRepository implementation test?
+ */
 public class FileMetadataRepositoryTest
     extends PlexusInSpringTestCase
 {
@@ -113,6 +116,17 @@ public class FileMetadataRepositoryTest
         repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
     }
 
+    public void testUpdateProjectVersionMetadataIncomplete()
+    {
+        ProjectVersionMetadata metadata = new ProjectVersionMetadata();
+        metadata.setId( TEST_PROJECT_VERSION );
+        metadata.setIncomplete( true );
+        repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
+
+        metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
+        assertEquals( true, metadata.isIncomplete() );
+    }
+
     public void testUpdateProjectVersionMetadataWithExistingFacets()
     {
         ProjectVersionMetadata metadata = new ProjectVersionMetadata();