[MRM-1283] keep track of incomplete metadata so that it can self correct and show a meaningful message to the user

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@893691 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-12-24 04:02:11 +00:00
parent 79de06cf3e
commit 1f1252456a
8 changed files with 70 additions and 5 deletions

View File

@ -166,8 +166,9 @@ public class ArchivaMetadataCreationConsumer
ProjectVersionMetadata versionMetadata = null; ProjectVersionMetadata versionMetadata = null;
try try
{ {
versionMetadata = storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), versionMetadata =
projectVersion ); storageResolver.getProjectVersion( repository.getId(), artifact.getGroupId(), artifact.getArtifactId(),
projectVersion );
} }
catch ( MetadataResolutionException e ) catch ( MetadataResolutionException e )
{ {
@ -180,6 +181,7 @@ public class ArchivaMetadataCreationConsumer
log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" ); log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" );
versionMetadata = new ProjectVersionMetadata(); versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId( projectVersion ); versionMetadata.setId( projectVersion );
versionMetadata.setIncomplete( true );
createVersionMetadata = true; createVersionMetadata = true;
} }

View File

@ -121,7 +121,11 @@ public class ShowArtifactAction
} }
catch ( MetadataResolutionException e ) 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 ) if ( versionMetadata != null )
{ {
@ -161,11 +165,22 @@ public class ShowArtifactAction
addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); addActionError( errorMsg != null ? errorMsg : "Artifact not found" );
return ERROR; return ERROR;
} }
if ( versionMetadata.isIncomplete() )
{
addIncompleteModelWarning();
}
model = versionMetadata; model = versionMetadata;
return SUCCESS; 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. * Show the artifact information tab.
*/ */

View File

@ -225,6 +225,12 @@
<%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %> <%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %>
</c:otherwise> </c:otherwise>
</c:choose> </c:choose>
<s:if test="hasActionMessages()">
<div id="messages">
<s:actionmessage />
</div>
</s:if>
</div> </div>
</div> </div>

View File

@ -339,3 +339,14 @@ div.versions a.expand {
font-size: 7pt; font-size: 7pt;
color: gray; color: gray;
} }
#messages {
background-color: yellow;
border: 1px solid orange;
margin-top: 2em;
}
#messages ul {
list-style-image: url(../images/icon_warning_sml.gif)
}

View File

@ -51,6 +51,8 @@ public class ProjectVersionMetadata
private List<Dependency> dependencies = new ArrayList<Dependency>(); private List<Dependency> dependencies = new ArrayList<Dependency>();
private boolean incomplete;
public String getId() public String getId()
{ {
return id; return id;
@ -205,4 +207,14 @@ public class ProjectVersionMetadata
{ {
this.dependencies.add( dependency ); this.dependencies.add( dependency );
} }
public boolean isIncomplete()
{
return incomplete;
}
public void setIncomplete( boolean incomplete )
{
this.incomplete = incomplete;
}
} }

View File

@ -68,7 +68,10 @@ public class DefaultMetadataResolver
metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion ); metadataRepository.getProjectVersion( repoId, namespace, projectId, projectVersion );
// TODO: do we want to detect changes as well by comparing timestamps? isProjectVersionNewerThan(updated) // 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 // 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 ); metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
if ( metadata != null ) if ( metadata != null )

View File

@ -131,6 +131,7 @@ public class FileMetadataRepository
setProperty( properties, "name", versionMetadata.getName() ); setProperty( properties, "name", versionMetadata.getName() );
setProperty( properties, "description", versionMetadata.getDescription() ); setProperty( properties, "description", versionMetadata.getDescription() );
setProperty( properties, "url", versionMetadata.getUrl() ); setProperty( properties, "url", versionMetadata.getUrl() );
setProperty( properties, "incomplete", String.valueOf( versionMetadata.isIncomplete() ) );
if ( versionMetadata.getScm() != null ) if ( versionMetadata.getScm() != null )
{ {
setProperty( properties, "scm.connection", versionMetadata.getScm().getConnection() ); setProperty( properties, "scm.connection", versionMetadata.getScm().getConnection() );
@ -653,6 +654,7 @@ public class FileMetadataRepository
versionMetadata.setName( properties.getProperty( "name" ) ); versionMetadata.setName( properties.getProperty( "name" ) );
versionMetadata.setDescription( properties.getProperty( "description" ) ); versionMetadata.setDescription( properties.getProperty( "description" ) );
versionMetadata.setUrl( properties.getProperty( "url" ) ); versionMetadata.setUrl( properties.getProperty( "url" ) );
versionMetadata.setIncomplete( Boolean.valueOf( properties.getProperty( "incomplete", "false" ) ) );
String scmConnection = properties.getProperty( "scm.connection" ); String scmConnection = properties.getProperty( "scm.connection" );
String scmDeveloperConnection = properties.getProperty( "scm.developerConnection" ); String scmDeveloperConnection = properties.getProperty( "scm.developerConnection" );

View File

@ -39,6 +39,9 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.spring.PlexusInSpringTestCase;
/**
* @todo should this be a generic MetadataRepository implementation test?
*/
public class FileMetadataRepositoryTest public class FileMetadataRepositoryTest
extends PlexusInSpringTestCase extends PlexusInSpringTestCase
{ {
@ -113,6 +116,17 @@ public class FileMetadataRepositoryTest
repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata ); 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() public void testUpdateProjectVersionMetadataWithExistingFacets()
{ {
ProjectVersionMetadata metadata = new ProjectVersionMetadata(); ProjectVersionMetadata metadata = new ProjectVersionMetadata();