]> source.dussan.org Git - archiva.git/commitdiff
Adding implementation of artifact
authorMartin Stockhammer <martin_s@apache.org>
Wed, 12 Feb 2020 20:47:11 +0000 (21:47 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Wed, 12 Feb 2020 20:47:11 +0000 (21:47 +0100)
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java [new file with mode: 0644]

index cd1f2e24f0f4b244eb900a74b4e4061e73c6642b..474f8241bf3ef431c2ac56e0e9dc54f41c0880b9 100644 (file)
@@ -78,12 +78,6 @@ public interface Artifact extends ContentItem
      */
     Version getVersion();
 
-    /**
-     * Returns the project this artifact is part of.
-     * @return the project object
-     */
-    Project getProject();
-
     /**
      * Returns the type of the artifact. The type is some hint about the usage of the artifact.
      * Implementations may always return a empty string, if it is not used.
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaArtifact.java
new file mode 100644 (file)
index 0000000..7ac99a7
--- /dev/null
@@ -0,0 +1,200 @@
+package org.apache.archiva.repository.content.base;
+
+/*
+ * 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.repository.content.Artifact;
+import org.apache.archiva.repository.content.Version;
+import org.apache.archiva.repository.storage.StorageAsset;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ *
+ * Base implementation of artifact. A builder is used to create instances.
+ *
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public class ArchivaArtifact extends ArchivaContentItem implements Artifact
+{
+    private String namespace;
+    private String id;
+    private String artifactVersion;
+    private Version version;
+    private String type;
+    private String classifier;
+    private String remainder;
+    private String contentType;
+    private StorageAsset asset;
+
+    private ArchivaArtifact() {
+
+    }
+
+    @Override
+    public String getNamespace( )
+    {
+        return namespace;
+    }
+
+    @Override
+    public String getId( )
+    {
+        return id;
+    }
+
+    @Override
+    public String getArtifactVersion( )
+    {
+        return artifactVersion;
+    }
+
+    @Override
+    public Version getVersion( )
+    {
+        return version;
+    }
+
+    @Override
+    public String getType( )
+    {
+        return type;
+    }
+
+    @Override
+    public String getClassifier( )
+    {
+        return classifier;
+    }
+
+    @Override
+    public String getRemainder( )
+    {
+        return remainder;
+    }
+
+    @Override
+    public String getContentType( )
+    {
+        return contentType;
+    }
+
+    @Override
+    public StorageAsset getAsset( )
+    {
+        return asset;
+    }
+
+    public static ArtifactVersionBuilder withId(String id) {
+        return new Builder( ).withId( id );
+    }
+
+
+    public interface ArtifactVersionBuilder {
+        VersionBuilder withArtifactVersion( String version );
+    }
+    public interface VersionBuilder {
+        AssetBuilder withVersion( Version version );
+    }
+    public interface AssetBuilder {
+        Builder withAsset( StorageAsset asset );
+    }
+
+
+    public static class Builder implements ArtifactVersionBuilder, VersionBuilder,
+        AssetBuilder
+    {
+        ArchivaArtifact artifact = new ArchivaArtifact( );
+
+        public ArtifactVersionBuilder withId(String id) {
+            artifact.id = id;
+            return this;
+        }
+
+
+        @Override
+        public VersionBuilder withArtifactVersion( String version )
+        {
+            if ( StringUtils.isEmpty( version ) ) {
+                throw new IllegalArgumentException( "version may not be null or empty" );
+            }
+            artifact.artifactVersion = version;
+            return this;
+        }
+
+        @Override
+        public AssetBuilder withVersion( Version version )
+        {
+            if (version==null) {
+                throw new IllegalArgumentException( "version may not be null" );
+            }
+            artifact.version = version;
+            return this;
+        }
+
+        public Builder withAsset(StorageAsset asset) {
+            if (asset==null) {
+                throw new IllegalArgumentException( "Asset may not be null" );
+            }
+            artifact.asset = asset;
+            return this;
+        }
+
+        public Builder withNamespace(String namespace) {
+            artifact.namespace = namespace;
+            return this;
+        }
+
+        public Builder withType(String type) {
+            artifact.type = type;
+            return this;
+        }
+
+        public Builder withClassifier(String classifier) {
+            artifact.classifier = classifier;
+            return this;
+        }
+
+        public Builder withRemainder(String remainder) {
+            artifact.remainder = remainder;
+            return this;
+        }
+
+        public Builder withContentType(String contentType) {
+            artifact.contentType = contentType;
+            return this;
+        }
+
+        public ArchivaArtifact build() {
+            if (artifact.namespace==null) {
+                artifact.namespace = "";
+            }
+            if (artifact.classifier==null) {
+                artifact.classifier = "";
+            }
+            if (artifact.type == null)  {
+                artifact.type = "";
+            }
+            if (artifact.contentType==null) {
+                artifact.contentType = "";
+            }
+
+            return artifact;
+        }
+    }
+}