From 1794af3da52cbf29f2b88d50e3ad416f8ddecd52 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Fri, 4 Jun 2010 02:11:25 +0000 Subject: [PATCH] [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic metadata" plugin o added new facet for generic properties o display correct metadata in Metadata tab o add new properties to metadata from UI git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@951239 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-web/archiva-webapp/pom.xml | 4 + .../web/action/ShowArtifactAction.java | 99 +++++++++++++++++-- .../src/main/resources/struts.xml | 4 + .../WEB-INF/jsp/include/projectMetadata.jspf | 59 ++++++++--- .../main/webapp/WEB-INF/jsp/showArtifact.jsp | 3 +- .../web/action/AbstractActionTestCase.java | 16 ++- .../web/action/ShowArtifactActionTest.java | 25 ++--- .../plugins/generic-metadata-support/pom.xml | 25 +++++ .../generic/GenericMetadataFacet.java | 83 ++++++++++++++++ .../generic/GenericMetadataFacetFactory.java | 42 ++++++++ .../file/FileMetadataRepository.java | 2 +- archiva-modules/plugins/pom.xml | 1 + pom.xml | 5 + 13 files changed, 324 insertions(+), 44 deletions(-) create mode 100644 archiva-modules/plugins/generic-metadata-support/pom.xml create mode 100644 archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java create mode 100644 archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index e27a14479..ee89fe97c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -29,6 +29,10 @@ war Archiva Web :: Application + + org.apache.archiva + generic-metadata-support + org.apache.archiva npanday-support diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index 077dcad61..eed67d571 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.action; */ import com.opensymphony.xwork2.Validateable; + +import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.License; @@ -42,9 +44,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; /** * Browse the repository. @@ -107,7 +111,14 @@ public class ShowArtifactAction private String deleteItem; private String itemValue; + + private Map genericMetadata; + + private String propertyName; + + private String propertyValue; + /** * Show the versioned project information tab. * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though @@ -141,7 +152,7 @@ public class ShowArtifactAction { ProjectVersionMetadata versionMetadata = null; artifacts = new LinkedHashMap>(); - + List repos = getObservableRepos(); for ( String repoId : repos ) @@ -277,20 +288,60 @@ public class ShowArtifactAction public String projectMetadata() { - projectMetadata = getProjectVersionMetadata(); - String errorMsg = null; + String result = artifact(); + + if( model.getFacet( GenericMetadataFacet.FACET_ID ) != null ) + { + genericMetadata = model.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); + } + + if( genericMetadata == null ) + { + genericMetadata = new HashMap(); + } - if ( projectMetadata == null ) + return result; + } + + public String addMetadataProperty() + { + ProjectVersionMetadata projectMetadata = getProjectVersionMetadata(); + String errorMsg = null; + + if( projectMetadata == null ) { addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); return ERROR; } - - if ( projectMetadata.isIncomplete() ) + + if( projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ) == null ) { - addIncompleteModelWarning(); + genericMetadata = new HashMap(); } - + else + { + genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); + } + + genericMetadata.put( propertyName, propertyValue ); + + GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet(); + genericMetadataFacet.fromProperties( genericMetadata ); + + // add updated facet + projectMetadata.addFacet( genericMetadataFacet ); + + metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata ); + + projectMetadata = getProjectVersionMetadata(); + + genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); + + model = projectMetadata; + + propertyName = ""; + propertyValue = ""; + return SUCCESS; } @@ -507,6 +558,36 @@ public class ShowArtifactAction { this.itemValue = itemValue; } + + public Map getGenericMetadata() + { + return genericMetadata; + } + + public void setGenericMetadata( Map genericMetadata ) + { + this.genericMetadata = genericMetadata; + } + + public String getPropertyName() + { + return propertyName; + } + + public void setPropertyName( String propertyName ) + { + this.propertyName = propertyName; + } + + public String getPropertyValue() + { + return propertyValue; + } + + public void setPropertyValue( String propertyValue ) + { + this.propertyValue = propertyValue; + } // TODO: move this into the artifact metadata itself via facets where necessary @@ -629,7 +710,5 @@ public class ShowArtifactAction { return path; } - - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml index a93499d44..1da4912a8 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml @@ -222,6 +222,10 @@ /WEB-INF/jsp/showArtifact.jsp + + /WEB-INF/jsp/showArtifact.jsp + + showProjectMetadata diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf index 6e5202a7a..65f3be1f7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf @@ -22,19 +22,50 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="archiva" uri="/WEB-INF/taglib.tld" %> -

- +

- - - - - - - ${artifactId} / - ${version} -

- -
- +
+ + + + + + + + + + + + + + + +
Property NameProperty Value +
+ + + + + +
+
+
+ +
+ +

+ No metadata content. +

+
+ + +
    + +
  • ${prop.key}=${prop.value}
  • +
    +
+
+
+ + <%-- --%>
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp index d54e73462..24b7cf49a 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp @@ -220,7 +220,7 @@ <%-- TODO: panels? this is ugly as is --%>
- + <%@ include file="/WEB-INF/jsp/include/projectMetadata.jspf" %> @@ -251,6 +251,5 @@
- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java index 73ba58bca..a95cebf52 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java @@ -19,8 +19,11 @@ package org.apache.maven.archiva.web.action; * under the License. */ +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.model.CiManagement; import org.apache.archiva.metadata.model.IssueManagement; import org.apache.archiva.metadata.model.License; @@ -84,7 +87,11 @@ public abstract class AbstractActionTestCase protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection"; protected static final String TEST_SCM_URL = "scmUrl"; - + + protected static final String TEST_GENERIC_METADATA_PROPERTY_NAME = "rating"; + + protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars"; + protected void setObservableRepos( List repoIds ) { UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class ); @@ -176,6 +183,13 @@ public abstract class AbstractActionTestCase parent.setVersion( TEST_PARENT_VERSION ); mavenProjectFacet.setParent( parent ); model.addFacet( mavenProjectFacet ); + + GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet(); + Map props = new HashMap(); + props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE ); + genericMetadataFacet.setAdditionalProperties( props ); + model.addFacet( genericMetadataFacet ); + return model; } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java index aa00d21ac..cb56754ff 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java @@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.action; */ import com.opensymphony.xwork2.Action; + +import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.MailingList; @@ -371,14 +373,7 @@ public class ShowArtifactActionTest public void testGetProjectMetadata() { ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION ); - Dependency dependency1 = createDependencyBasic( "artifactId1" ); - Dependency dependency2 = createDependencyExtended( "artifactId2" ); - versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) ); - - MailingList ml1 = createMailingList( "Users List", "users" ); - MailingList ml2 = createMailingList( "Developers List", "dev" ); - versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) ); - + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); setActionParameters(); @@ -388,15 +383,13 @@ public class ShowArtifactActionTest assertActionSuccess( action, result ); assertActionParameters( action ); - ProjectVersionMetadata projectMetadata = action.getProjectMetadata(); - assertDefaultModel( projectMetadata ); - - assertNotNull( projectMetadata.getDependencies() ); - assertDependencyBasic( projectMetadata.getDependencies().get( 0 ), "artifactId1" ); - assertDependencyExtended( projectMetadata.getDependencies().get( 1 ), "artifactId2" ); - + + Map genericMetadata = action.getGenericMetadata(); + assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) ); + assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE ); + assertEquals( TEST_REPO, action.getRepositoryId() ); - assertNull( action.getModel() ); + assertNotNull( action.getModel() ); assertNull( action.getDependees() ); assertNull( action.getDependencies() ); assertNull( action.getMailingLists() ); diff --git a/archiva-modules/plugins/generic-metadata-support/pom.xml b/archiva-modules/plugins/generic-metadata-support/pom.xml new file mode 100644 index 000000000..c8b34ce81 --- /dev/null +++ b/archiva-modules/plugins/generic-metadata-support/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + plugins + org.apache.archiva + 1.4-SNAPSHOT + + generic-metadata-support + Generic Metadata Support + http://maven.apache.org + + + org.apache.archiva + metadata-model + + + junit + junit + 3.8.1 + test + + + diff --git a/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java new file mode 100644 index 000000000..8bbe94553 --- /dev/null +++ b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java @@ -0,0 +1,83 @@ +package org.apache.archiva.metadata.generic; + +/* + * 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 java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.archiva.metadata.model.MetadataFacet; + +public class GenericMetadataFacet + implements MetadataFacet +{ + private Map additionalProperties; + + public static final String FACET_ID = "org.apache.archiva.metadata.generic"; + + public String getFacetId() + { + return FACET_ID; + } + + public String getName() + { + return ""; + } + + public void fromProperties( Map properties ) + { + if( additionalProperties == null ) + { + additionalProperties = new TreeMap(); + } + + for( String key : properties.keySet() ) + { + additionalProperties.put( key, properties.get( key ) ); + } + } + + public Map toProperties() + { + Map properties = new TreeMap(); + + if( additionalProperties != null ) + { + for( String key : additionalProperties.keySet() ) + { + properties.put( key, additionalProperties.get( key ) ); + } + } + + return properties; + } + + public Map getAdditionalProperties() + { + return additionalProperties; + } + + public void setAdditionalProperties( Map additionalProperties ) + { + this.additionalProperties = additionalProperties; + } + +} diff --git a/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java new file mode 100644 index 000000000..e8e9a7d45 --- /dev/null +++ b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacetFactory.java @@ -0,0 +1,42 @@ +package org.apache.archiva.metadata.generic; + +/* + * 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.archiva.metadata.model.MetadataFacet; +import org.apache.archiva.metadata.model.MetadataFacetFactory; + +/** + * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.generic" + */ +public class GenericMetadataFacetFactory + implements MetadataFacetFactory +{ + + public MetadataFacet createMetadataFacet() + { + return new GenericMetadataFacet(); + } + + public MetadataFacet createMetadataFacet( String repositoryId, String name ) + { + throw new UnsupportedOperationException( "There is no valid name for project version facets" ); + } + +} diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index b391173cf..d35f46073 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -618,7 +618,7 @@ public class FileMetadataRepository private String join( Collection ids ) { - if ( !ids.isEmpty() ) + if ( ids != null && !ids.isEmpty() ) { StringBuilder s = new StringBuilder(); for ( String id : ids ) diff --git a/archiva-modules/plugins/pom.xml b/archiva-modules/plugins/pom.xml index 14e84fca5..6f24b170f 100644 --- a/archiva-modules/plugins/pom.xml +++ b/archiva-modules/plugins/pom.xml @@ -35,5 +35,6 @@ npanday-support maven1-repository + generic-metadata-support \ No newline at end of file diff --git a/pom.xml b/pom.xml index 363b1a491..883eda030 100644 --- a/pom.xml +++ b/pom.xml @@ -325,6 +325,11 @@ maven2-repository 1.4-SNAPSHOT
+ + org.apache.archiva + generic-metadata-support + 1.4-SNAPSHOT + org.apache.archiva archiva-applet -- 2.39.5