Repository: archiva
Updated Branches:
  refs/heads/master e5e11721b -> f93a787e7


Adding custom properties to project metadata.

Extending the project metadata to add custom properties. This may be used by
storage implementations later.


Project: http://git-wip-us.apache.org/repos/asf/archiva/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/f93a787e
Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/f93a787e
Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/f93a787e

Branch: refs/heads/master
Commit: f93a787e74f048fd4fe393819c09d898da63b4f4
Parents: e5e1172
Author: Martin Stockhammer <marti...@apache.org>
Authored: Sat Aug 12 14:49:45 2017 +0200
Committer: Martin Stockhammer <marti...@apache.org>
Committed: Sat Aug 12 14:49:45 2017 +0200

----------------------------------------------------------------------
 .../archiva/metadata/model/ProjectMetadata.java | 80 +++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva/blob/f93a787e/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java
----------------------------------------------------------------------
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 c795bb5..61326e5 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();
     }
+
+
 }

Reply via email to