*/
String getContentType( );
+ /**
+ * Returns the type of the artifact
+ * @return
+ */
+ ArtifactType getArtifactType();
}
--- /dev/null
+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();
+}
--- /dev/null
+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
+}
*/
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;
* 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>
* <li>artifactVersion</li>
* <li>type</li>
* <li>classifier</li>
+ * <li>artifactType</li>
* </ul>
*
* @author Martin Stockhammer <martin_s@apache.org>
private String classifier;
private String remainder;
private String contentType;
+ private ArtifactType artifactType;
private ArchivaArtifact( )
{
return contentType;
}
+ @Override
+ public ArtifactType getArtifactType( )
+ {
+ return artifactType;
+ }
+
/**
* Returns the builder for creating a new artifact instance. You have to fill the
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 );
}
result = 31 * result + version.hashCode( );
result = 31 * result + type.hashCode( );
result = 31 * result + classifier.hashCode( );
+ result = 31 * result + artifactType.hashCode( );
return result;
}
return this;
}
+ @Override
+ public ArtifactOptBuilder withArtifactType( ArtifactType type )
+ {
+ item.artifactType = type;
+ return this;
+ }
+
@Override
public ArchivaArtifact build( )
{
{
item.remainder = "";
}
+ if (item.artifactType==null) {
+ item.artifactType = BaseArtifactTypes.MAIN;
+ }
return item;
}
package org.apache.archiva.repository.content.base.builder;
+import org.apache.archiva.repository.content.ArtifactType;
import org.apache.archiva.repository.content.base.ArchivaArtifact;
/**
ArtifactOptBuilder withContentType( String contentType );
+ ArtifactOptBuilder withArtifactType( ArtifactType type );
+
ArchivaArtifact build( );
}
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
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
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
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
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
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
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
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
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;
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;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
/**
* ManagedDefaultRepositoryContent
.withType( info.type )
.withArtifactVersion( info.version )
.withContentType( info.contentType )
+ .withArtifactType( info.artifactType )
.build( )
);
}
private String classifier;
private String contentType;
private StorageAsset asset;
+ private ArtifactType artifactType = BaseArtifactTypes.MAIN;
}
private ArtifactInfo getArtifactInfoFromPath(String genericVersion, StorageAsset path) {
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, "." );
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, "." );
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;
}
MavenMetadataReader metadataReader;
public static final String METADATA_FILENAME = "maven-metadata.xml";
+ public static final String METADATA_REPOSITORY_FILENAME = "maven-metadata-repository.xml";
public MavenContentHelper() {
--- /dev/null
+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
+}
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;
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;
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.*;
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( ) );
+ }
}