@@ -125,5 +125,10 @@ public interface Artifact extends ContentItem | |||
*/ | |||
String getContentType( ); | |||
/** | |||
* Returns the type of the artifact | |||
* @return | |||
*/ | |||
ArtifactType getArtifactType(); | |||
} |
@@ -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(); | |||
} |
@@ -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 | |||
} |
@@ -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; | |||
} | |||
@@ -232,6 +244,13 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact | |||
return this; | |||
} | |||
@Override | |||
public ArtifactOptBuilder withArtifactType( ArtifactType type ) | |||
{ | |||
item.artifactType = type; | |||
return this; | |||
} | |||
@Override | |||
public ArchivaArtifact build( ) | |||
{ | |||
@@ -256,6 +275,9 @@ public class ArchivaArtifact extends ArchivaContentItem implements Artifact | |||
{ | |||
item.remainder = ""; | |||
} | |||
if (item.artifactType==null) { | |||
item.artifactType = BaseArtifactTypes.MAIN; | |||
} | |||
return item; | |||
} |
@@ -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( ); | |||
} |
@@ -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( ) ); | |||
} | |||
} |
@@ -35,9 +35,11 @@ import org.apache.archiva.repository.LayoutException; | |||
import org.apache.archiva.repository.ManagedRepository; | |||
import org.apache.archiva.repository.ManagedRepositoryContent; | |||
import org.apache.archiva.repository.content.Artifact; | |||
import org.apache.archiva.repository.content.ArtifactType; | |||
import org.apache.archiva.repository.content.ContentItem; | |||
import org.apache.archiva.repository.content.ItemNotFoundException; | |||
import org.apache.archiva.repository.content.ItemSelector; | |||
import org.apache.archiva.repository.content.BaseArtifactTypes; | |||
import org.apache.archiva.repository.content.Namespace; | |||
import org.apache.archiva.repository.content.Project; | |||
import org.apache.archiva.repository.content.Version; | |||
@@ -56,7 +58,6 @@ import org.apache.commons.lang3.StringUtils; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
import javax.naming.Name; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.nio.file.Files; | |||
@@ -72,7 +73,6 @@ import java.util.regex.Matcher; | |||
import java.util.regex.Pattern; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
import java.util.stream.StreamSupport; | |||
/** | |||
* ManagedDefaultRepositoryContent | |||
@@ -320,6 +320,7 @@ public class ManagedDefaultRepositoryContent | |||
.withType( info.type ) | |||
.withArtifactVersion( info.version ) | |||
.withContentType( info.contentType ) | |||
.withArtifactType( info.artifactType ) | |||
.build( ) | |||
); | |||
} | |||
@@ -397,6 +398,7 @@ public class ManagedDefaultRepositoryContent | |||
private String classifier; | |||
private String contentType; | |||
private StorageAsset asset; | |||
private ArtifactType artifactType = BaseArtifactTypes.MAIN; | |||
} | |||
private ArtifactInfo getArtifactInfoFromPath(String genericVersion, StorageAsset path) { | |||
@@ -427,18 +429,21 @@ public class ManagedDefaultRepositoryContent | |||
info.remainder = classPostfix; | |||
} | |||
} else { | |||
log.error( "Artifact does not match the maven name pattern {}", path ); | |||
log.debug( "Artifact does not match the maven name pattern {}", path ); | |||
info.artifactType = BaseArtifactTypes.UNKNOWN; | |||
info.classifier = ""; | |||
info.remainder = StringUtils.substringAfter( fileName, prefix ); | |||
} | |||
} else { | |||
log.error( "Artifact does not match the snapshot version pattern {}", path ); | |||
log.debug( "Artifact does not match the snapshot version pattern {}", path ); | |||
info.artifactType = BaseArtifactTypes.UNKNOWN; | |||
info.version = ""; | |||
info.classifier = ""; | |||
info.remainder = StringUtils.substringAfter( fileName, prefix ); | |||
} | |||
} else { | |||
log.error( "Artifact does not match the maven name pattern: {}", path ); | |||
log.debug( "Artifact does not match the maven name pattern: {}", path ); | |||
info.artifactType = BaseArtifactTypes.UNKNOWN; | |||
info.version = ""; | |||
info.classifier = ""; | |||
info.remainder = StringUtils.substringAfterLast( fileName, "." ); | |||
@@ -458,7 +463,8 @@ public class ManagedDefaultRepositoryContent | |||
info.remainder = classPostfix; | |||
} | |||
} else { | |||
log.error( "Artifact does not match the version pattern {}", path ); | |||
log.debug( "Artifact does not match the version pattern {}", path ); | |||
info.artifactType = BaseArtifactTypes.UNKNOWN; | |||
info.version = ""; | |||
info.classifier = ""; | |||
info.remainder = StringUtils.substringAfterLast( fileName, "." ); | |||
@@ -472,6 +478,11 @@ public class ManagedDefaultRepositoryContent | |||
info.contentType = ""; | |||
// | |||
} | |||
if (MavenContentHelper.METADATA_FILENAME.equalsIgnoreCase( fileName )) { | |||
info.artifactType = BaseArtifactTypes.METADATA; | |||
} else if (MavenContentHelper.METADATA_REPOSITORY_FILENAME.equalsIgnoreCase( fileName )) { | |||
info.artifactType = MavenTypes.REPOSITORY_METADATA; | |||
} | |||
return info; | |||
} |
@@ -52,6 +52,7 @@ public class MavenContentHelper | |||
MavenMetadataReader metadataReader; | |||
public static final String METADATA_FILENAME = "maven-metadata.xml"; | |||
public static final String METADATA_REPOSITORY_FILENAME = "maven-metadata-repository.xml"; | |||
public MavenContentHelper() { | |||
@@ -0,0 +1,29 @@ | |||
package org.apache.archiva.repository.maven.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. | |||
*/ | |||
import org.apache.archiva.repository.content.ArtifactType; | |||
/** | |||
* @author Martin Stockhammer <martin_s@apache.org> | |||
*/ | |||
public enum MavenTypes implements ArtifactType | |||
{ | |||
REPOSITORY_METADATA | |||
} |
@@ -30,6 +30,8 @@ import org.apache.archiva.repository.EditableManagedRepository; | |||
import org.apache.archiva.repository.LayoutException; | |||
import org.apache.archiva.repository.ManagedRepositoryContent; | |||
import org.apache.archiva.repository.RepositoryContent; | |||
import org.apache.archiva.repository.content.Artifact; | |||
import org.apache.archiva.repository.content.BaseArtifactTypes; | |||
import org.apache.archiva.repository.content.ItemSelector; | |||
import org.apache.archiva.repository.content.Project; | |||
import org.apache.archiva.repository.content.Version; | |||
@@ -42,6 +44,7 @@ import org.junit.Test; | |||
import javax.inject.Inject; | |||
import javax.inject.Named; | |||
import javax.jcr.Item; | |||
import java.io.IOException; | |||
import java.net.URISyntaxException; | |||
import java.nio.file.Files; | |||
@@ -51,8 +54,10 @@ import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
import static org.junit.Assert.*; | |||
@@ -451,4 +456,22 @@ public class ManagedDefaultRepositoryContentTest | |||
assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) ); | |||
} | |||
@Test | |||
public void testGetArtifactStreamWithVersionSelector() { | |||
ItemSelector selector = ArchivaItemSelector.builder( ) | |||
.withNamespace( "javax.sql" ) | |||
.withProjectId( "jdbc" ) | |||
.withVersion( "2.0" ).build(); | |||
Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ); | |||
assertNotNull( stream ); | |||
List<? extends Artifact> results = stream.collect( Collectors.toList( ) ); | |||
assertEquals( 2, results.size( ) ); | |||
Artifact mainArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "jdbc-2.0.jar" ) ).findFirst( ).get( ); | |||
assertNotNull( mainArtifact ); | |||
assertEquals( BaseArtifactTypes.MAIN, mainArtifact.getArtifactType( ) ); | |||
Artifact metaArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "maven-metadata-repository.xml" ) ).findFirst( ).get( ); | |||
assertNotNull( metaArtifact ); | |||
assertEquals( MavenTypes.REPOSITORY_METADATA, metaArtifact.getArtifactType( ) ); | |||
} | |||
} |