diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-03-12 19:51:35 +0100 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-03-12 19:51:35 +0100 |
commit | 3fcc770c79d89fd77fed0a1c7173afdf74d10503 (patch) | |
tree | dfacd7e289a4a9631d29e888833ad4b24471b89d /archiva-modules/archiva-base | |
parent | fb63a9d09d27c93a4884130cbc436582c0573639 (diff) | |
download | archiva-3fcc770c79d89fd77fed0a1c7173afdf74d10503.tar.gz archiva-3fcc770c79d89fd77fed0a1c7173afdf74d10503.zip |
Adding artefact type and additional tests
Diffstat (limited to 'archiva-modules/archiva-base')
6 files changed, 156 insertions, 1 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java index 71ef83ef0..a86d1c372 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/Artifact.java @@ -125,5 +125,10 @@ public interface Artifact extends ContentItem */ String getContentType( ); + /** + * Returns the type of the artifact + * @return + */ + ArtifactType getArtifactType(); } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ArtifactType.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ArtifactType.java new file mode 100644 index 000000000..7e5276552 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ArtifactType.java @@ -0,0 +1,30 @@ +package org.apache.archiva.repository.content; + +/* + * 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. + */ + +/** + * + * Type of the artifact to distinguish different flavours. + * + * @author Martin Stockhammer <martin_s@apache.org> + */ +public interface ArtifactType +{ + String name(); +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/BaseArtifactTypes.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/BaseArtifactTypes.java new file mode 100644 index 000000000..b1a2020b8 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/BaseArtifactTypes.java @@ -0,0 +1,35 @@ +package org.apache.archiva.repository.content; + +/* + * 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. + */ + +/** + * Basic artifact types. + * <ul> + * <li>{@link #MAIN}: Standard type</li> + * <li>{@link #METADATA}: if this artifact represents a metadata file</li> + * <li>{@link #RELATED}: artifact that is related to a main artifact</li> + * <li>{@link #UNKNOWN}: Unknown type</li> + * </ul> + * + * @author Martin Stockhammer <martin_s@apache.org> + */ +public enum BaseArtifactTypes implements ArtifactType +{ + MAIN,RELATED,METADATA,UNKNOWN +} 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 index 5d28e83b3..b17a9c5af 100644 --- 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 @@ -20,6 +20,8 @@ package org.apache.archiva.repository.content.base; */ import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.ArtifactType; +import org.apache.archiva.repository.content.BaseArtifactTypes; import org.apache.archiva.repository.content.Version; import org.apache.archiva.repository.content.base.builder.ArtifactOptBuilder; import org.apache.archiva.repository.content.base.builder.ArtifactVersionBuilder; @@ -34,7 +36,7 @@ import org.apache.commons.lang3.StringUtils; * You have to use the builder method {@link #withAsset(StorageAsset)} to create a instance. * The build() method can be called after the required attributes are set. * <p> - * Artifact are equal if the following coordinates match: + * Artifacts are equal if the following coordinates match: * <ul> * <li>repository</li> * <li>asset</li> @@ -43,6 +45,7 @@ import org.apache.commons.lang3.StringUtils; * <li>artifactVersion</li> * <li>type</li> * <li>classifier</li> + * <li>artifactType</li> * </ul> * * @author Martin Stockhammer <martin_s@apache.org> @@ -56,6 +59,7 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact private String classifier; private String remainder; private String contentType; + private ArtifactType artifactType; private ArchivaArtifact( ) { @@ -105,6 +109,12 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact return contentType; } + @Override + public ArtifactType getArtifactType( ) + { + return artifactType; + } + /** * Returns the builder for creating a new artifact instance. You have to fill the @@ -132,6 +142,7 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact if ( !artifactVersion.equals( that.artifactVersion ) ) return false; if ( !version.equals( that.version ) ) return false; if ( !type.equals( that.type ) ) return false; + if ( !artifactType.equals(that.artifactType)) return false; return classifier.equals( that.classifier ); } @@ -144,6 +155,7 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact result = 31 * result + version.hashCode( ); result = 31 * result + type.hashCode( ); result = 31 * result + classifier.hashCode( ); + result = 31 * result + artifactType.hashCode( ); return result; } @@ -233,6 +245,13 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact } @Override + public ArtifactOptBuilder withArtifactType( ArtifactType type ) + { + item.artifactType = type; + return this; + } + + @Override public ArchivaArtifact build( ) { super.build( ); @@ -256,6 +275,9 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact { item.remainder = ""; } + if (item.artifactType==null) { + item.artifactType = BaseArtifactTypes.MAIN; + } return item; } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/builder/ArtifactOptBuilder.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/builder/ArtifactOptBuilder.java index 3ac93c16c..03ef69831 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/builder/ArtifactOptBuilder.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/builder/ArtifactOptBuilder.java @@ -18,6 +18,7 @@ package org.apache.archiva.repository.content.base.builder; +import org.apache.archiva.repository.content.ArtifactType; import org.apache.archiva.repository.content.base.ArchivaArtifact; /** @@ -37,5 +38,7 @@ public interface ArtifactOptBuilder ArtifactOptBuilder withContentType( String contentType ); + ArtifactOptBuilder withArtifactType( ArtifactType type ); + ArchivaArtifact build( ); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaItemSelectorTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaItemSelectorTest.java index 7ab3c412c..2af58cb10 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaItemSelectorTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/content/base/ArchivaItemSelectorTest.java @@ -39,6 +39,14 @@ class ArchivaItemSelectorTest assertFalse( selector.hasType( ) ); assertFalse( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + + assertEquals( "", selector.getNamespace( ) ); + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getType( ) ); + assertEquals( "", selector.getClassifier( ) ); + assertNotNull( selector.getAttributes( ) ); } @Test @@ -53,6 +61,14 @@ class ArchivaItemSelectorTest assertFalse( selector.hasType( ) ); assertFalse( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + + assertEquals( "", selector.getProjectId( ) ); + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getType( ) ); + assertEquals( "", selector.getClassifier( ) ); + assertNotNull( selector.getAttributes( ) ); } @Test @@ -67,6 +83,14 @@ class ArchivaItemSelectorTest assertFalse( selector.hasType( ) ); assertFalse( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + + + assertEquals( "", selector.getNamespace( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getType( ) ); + assertEquals( "", selector.getClassifier( ) ); + assertNotNull( selector.getAttributes( ) ); } @Test @@ -81,6 +105,14 @@ class ArchivaItemSelectorTest assertFalse( selector.hasType( ) ); assertFalse( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + + assertEquals( "", selector.getNamespace( ) ); + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getType( ) ); + assertEquals( "", selector.getClassifier( ) ); + assertNotNull( selector.getAttributes( ) ); + } @Test @@ -96,6 +128,12 @@ class ArchivaItemSelectorTest assertFalse( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + assertEquals( "", selector.getNamespace( ) ); + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getType( ) ); + assertEquals( "", selector.getClassifier( ) ); + assertNotNull( selector.getAttributes( ) ); } @Test @@ -110,6 +148,13 @@ class ArchivaItemSelectorTest assertTrue( selector.hasType( ) ); assertFalse( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + + assertEquals( "", selector.getNamespace( ) ); + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getClassifier( ) ); + assertNotNull( selector.getAttributes( ) ); } @Test @@ -124,6 +169,14 @@ class ArchivaItemSelectorTest assertFalse( selector.hasType( ) ); assertTrue( selector.hasClassifier( ) ); assertFalse( selector.hasAttributes( ) ); + + assertEquals( "", selector.getNamespace( ) ); + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getType( ) ); + assertNotNull( selector.getAttributes( ) ); + } @Test @@ -140,6 +193,13 @@ class ArchivaItemSelectorTest assertFalse( selector.hasType( ) ); assertFalse( selector.hasClassifier( ) ); assertTrue( selector.hasAttributes( ) ); + + assertEquals( "", selector.getVersion( ) ); + assertEquals( "", selector.getArtifactId( ) ); + assertEquals( "", selector.getArtifactVersion( ) ); + assertEquals( "", selector.getType( ) ); + assertEquals( "", selector.getClassifier( ) ); + } }
\ No newline at end of file |