From f93a787e74f048fd4fe393819c09d898da63b4f4 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 12 Aug 2017 14:49:45 +0200 Subject: [PATCH] Adding custom properties to project metadata. Extending the project metadata to add custom properties. This may be used by storage implementations later. --- .../metadata/model/ProjectMetadata.java | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java index c795bb5db..61326e5ef 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java @@ -19,39 +19,117 @@ package org.apache.archiva.metadata.model; * under the License. */ +import java.util.Properties; + +/** + * Metadata on project level. + * Namely the namespace and the project id. But different repository types may + * add additional metadata information. + * + */ public class ProjectMetadata { + private Properties customProperties; + private String namespace; private String id; + /** + * Sets the project id. + * @param id + */ public void setId( String id ) { this.id = id; } - + + /** + * Returns the project id. + * @return + */ public String getId() { return id; } + /** + * Returns the namespace where the project resides. + * @return The namespace. + */ public String getNamespace() { return namespace; } + /** + * Sets the namespace. Namespaces are strings that may contain '.' characters to separate + * the hierarchy levels. + * @return + */ public void setNamespace( String namespace ) { this.namespace = namespace; } + /** + * Adds a custom property. Repository storage implementations may add custom properties + * on the project level. + * @param key + * @param value + */ + public void addProperty(String key, String value) { + Properties props = getProperties(); + props.setProperty( key, value ); + } + + /** + * Replaces all custom properties with the given properties object. + * The given object is stored by reference and not copied. + * @param properties + */ + public void setProperties(Properties properties) { + this.customProperties = properties; + } + + + /** + * Returns the object with all custom properties. + * If there are no custom properties set, a empty object will be returned. + * + * @return The custom properties. + */ + public Properties getProperties() { + if (customProperties==null) + { + Properties props = new Properties( ); + this.customProperties = props; + return props; + } else { + return this.customProperties; + } + } + + /** + * Returns true, if there are custom properties set. + * @return True, if there exist custom properties. + */ + public boolean hasProperties() { + return this.customProperties != null && this.customProperties.size()>0; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder( "ProjectMetadata{" ); sb.append( "namespace='" ).append( namespace ).append( '\'' ); sb.append( ", id='" ).append( id ).append( '\'' ); + if (customProperties!=null) { + sb.append(", custom: '").append(customProperties.toString()).append('\''); + } sb.append( '}' ); return sb.toString(); } + + } -- 2.39.5