diff options
13 files changed, 324 insertions, 44 deletions
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 @@ -31,6 +31,10 @@ <dependencies> <dependency> <groupId>org.apache.archiva</groupId> + <artifactId>generic-metadata-support</artifactId> + </dependency> + <dependency> + <groupId>org.apache.archiva</groupId> <artifactId>npanday-support</artifactId> </dependency> <dependency> 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<String, String> 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<String, List<ArtifactDownloadInfo>>(); - + List<String> 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<String, String>(); + } - 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<String, String>(); } - + 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<String, String> getGenericMetadata() + { + return genericMetadata; + } + + public void setGenericMetadata( Map<String, String> 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 @@ <result>/WEB-INF/jsp/showArtifact.jsp</result> </action> + <action name="addMetadataProperty" class="showArtifactAction" method="addMetadataProperty"> + <result>/WEB-INF/jsp/showArtifact.jsp</result> + </action> + <action name="deleteMetadataEntry" class="showArtifactAction" method="deleteMetadataEntry"> <result name="success" type="redirect-action"> <param name="actionName">showProjectMetadata</param> 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" %> -<p> - <archiva:groupIdLink var="${groupId}" includeTop="true" /> +<div> - <c:set var="url"> - <s:url action="browseArtifact" namespace="/"> - <s:param name="groupId" value="%{#attr.groupId}"/> - <s:param name="artifactId" value="%{#attr.artifactId}"/> - </s:url> - </c:set> - <a href="${url}">${artifactId}</a> / - <strong>${version}</strong> -</p> - -<div> - <archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" /> + <div> + <s:form action="addMetadataProperty" namespace="/" method="post" validate="true" theme="simple"> + <s:hidden name="groupId" value="%{groupId}" /> + <s:hidden name="artifactId" value="%{artifactId}" /> + <s:hidden name="version" value="%{version}" /> + <s:hidden name="repositoryId" value="%{repositoryId}" /> + <table> + <tr> + <td align="center"><strong>Property Name</strong></td> + <td align="center"><strong>Property Value</strong></td> + <td/> + </tr> + <tr> + <td> + <s:textfield name="propertyName" size="30" required="true"/> + </td> + <td> + <s:textfield name="propertyValue" size="30" required="true"/> + </td> + <td align="right"> + <s:submit value="Add"/> + </td> + </tr> + </table> + </s:form> + </div> + + <div> + <c:if test="${empty genericMetadata}"> + <p> + <strong>No metadata content.</strong> + </p> + </c:if> + + <c:if test="${!empty genericMetadata}"> + <ul> + <c:forEach var="prop" items="${genericMetadata}"> + <li>${prop.key}=${prop.value}</li> + </c:forEach> + </ul> + </c:if> + </div> + + <%-- <archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" /> --%> </div> 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 --%> <div id="tabArea"> <c:choose> - <c:when test="${projectMetadata != null}"> + <c:when test="${genericMetadata != null}"> <%@ include file="/WEB-INF/jsp/include/projectMetadata.jspf" %> </c:when> <c:when test="${dependencies != null}"> @@ -251,6 +251,5 @@ </s:if> </div> </div> - </body> </html> 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<String> 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<String, String> props = new HashMap<String,String>(); + 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<String, String> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>plugins</artifactId> + <groupId>org.apache.archiva</groupId> + <version>1.4-SNAPSHOT</version> + </parent> + <artifactId>generic-metadata-support</artifactId> + <name>Generic Metadata Support</name> + <url>http://maven.apache.org</url> + <dependencies> + <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>metadata-model</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> 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<String, String> 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<String, String> properties ) + { + if( additionalProperties == null ) + { + additionalProperties = new TreeMap<String, String>(); + } + + for( String key : properties.keySet() ) + { + additionalProperties.put( key, properties.get( key ) ); + } + } + + public Map<String, String> toProperties() + { + Map<String, String> properties = new TreeMap<String, String>(); + + if( additionalProperties != null ) + { + for( String key : additionalProperties.keySet() ) + { + properties.put( key, additionalProperties.get( key ) ); + } + } + + return properties; + } + + public Map<String, String> getAdditionalProperties() + { + return additionalProperties; + } + + public void setAdditionalProperties( Map<String, String> 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<String> 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 @@ <!-- TODO: eventually not a core plugin, needs to be moved to a separate tree, with it's own Selenium tests --> <module>npanday-support</module> <module>maven1-repository</module> + <module>generic-metadata-support</module> </modules> </project>
\ No newline at end of file @@ -327,6 +327,11 @@ </dependency> <dependency> <groupId>org.apache.archiva</groupId> + <artifactId>generic-metadata-support</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.archiva</groupId> <artifactId>archiva-applet</artifactId> <version>1.4-SNAPSHOT</version> </dependency> |