* under the License.
*/
+import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
+import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
+
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" );
+ // TODO: won't support extensions - need to refactor away this class
+ private static final ArtifactMappingProvider mapping = new DefaultArtifactMappingProvider();
+
static
{
typeToExtensionMap = new HashMap<String, String>();
typeToExtensionMap.put( "ejb-client", "jar" );
typeToExtensionMap.put( "ejb", "jar" );
- typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
- typeToExtensionMap.put( "distribution-zip", "zip" );
typeToExtensionMap.put( "java-source", "jar" );
- typeToExtensionMap.put( "javadoc.jar", "jar" );
typeToExtensionMap.put( "javadoc", "jar" );
- typeToExtensionMap.put( "aspect", "jar" );
- typeToExtensionMap.put( "uberjar", "jar" );
+ typeToExtensionMap.put( "test-jar", "jar" );
typeToExtensionMap.put( MAVEN_PLUGIN, "jar" );
- typeToExtensionMap.put( MAVEN_ONE_PLUGIN, "jar" );
+
typeToExtensionMap.put( MAVEN_ARCHETYPE, "jar" );
+
+ // TODO: move to maven 1 plugin
+ typeToExtensionMap.put( MAVEN_ONE_PLUGIN, "jar" );
+ typeToExtensionMap.put( "javadoc.jar", "jar" );
+ typeToExtensionMap.put( "uberjar", "jar" );
+ typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
+ typeToExtensionMap.put( "distribution-zip", "zip" );
+ typeToExtensionMap.put( "aspect", "jar" );
}
public static String getExtension( String type )
// Try specialized types first.
if ( typeToExtensionMap.containsKey( type ) )
{
- return (String) typeToExtensionMap.get( type );
+ return typeToExtensionMap.get( type );
}
// Return type
public static String mapExtensionAndClassifierToType( String classifier, String extension,
String defaultExtension )
{
- if ( "sources".equals( classifier ) )
- {
- return "java-source";
- }
- else if ( "javadoc".equals( classifier ) )
+ String value = mapping.mapClassifierAndExtensionToType( classifier, extension );
+ if ( value == null )
{
- return "javadoc";
+ value = mapToMaven1Type( extension );
}
- return mapExtensionToType( extension, defaultExtension );
+ return value != null ? value : defaultExtension;
}
public static String mapExtensionToType( String extension )
{
- return mapExtensionToType( extension, extension );
+ String value = mapToMaven1Type( extension );
+
+ return value != null ? value : extension;
}
- private static String mapExtensionToType( String extension, String defaultExtension )
+ private static String mapToMaven1Type( String extension )
{
+ // TODO: Maven 1 plugin
+ String value = null;
if ( "tar.gz".equals( extension ) )
{
- return "distribution-tgz";
+ value = "distribution-tgz";
}
else if ( "tar.bz2".equals( extension ) )
{
- return "distribution-bzip";
+ value = "distribution-bzip";
}
else if ( "zip".equals( extension ) )
{
- return "distribution-zip";
+ value = "distribution-zip";
}
- return defaultExtension;
+ return value;
}
}
<version>1.0-SNAPSHOT</version>
<versioning>
<snapshot>
- <timestamp>20100308.230825</timestamp>
- <buildNumber>1</buildNumber>
+ <timestamp>20100310.014828</timestamp>
+ <buildNumber>2</buildNumber>
</snapshot>
- <lastUpdated>20100308230825</lastUpdated>
+ <lastUpdated>20100310014828</lastUpdated>
</versioning>
</metadata>
-7210867ac16cd955db89cfca699e7c96
\ No newline at end of file
+aad6835e3e7a4a9de5318ce9183eab54
\ No newline at end of file
-271faeb2039d026ee6a3c937375b5ff7d4b1d605
\ No newline at end of file
+73669371dc2fdae2fa9a129932ed0932d62d9e6b
\ No newline at end of file
--- /dev/null
+e034e44b0d9f3968ebfbc66c71b41ba0
\ No newline at end of file
--- /dev/null
+ca8d1408b05d125d0307dbd23063e5aa04235d35
\ No newline at end of file
--- /dev/null
+a47f0edab0271fc55a3db38098f5f78a
\ No newline at end of file
--- /dev/null
+af4c914ef8f80be2a8241fb4d40cff11f4348c0f
\ No newline at end of file
--- /dev/null
+37786de9e272ed6db8541855e0e2d5dc
\ No newline at end of file
--- /dev/null
+bb1ca7834422926d0cb79ef303b715bc17f41661
\ No newline at end of file
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.example.test</groupId>
+ <artifactId>test-artifact</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>test-artifact</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <distributionManagement>
+ <repository>
+ <id>test</id>
+ <url>file:${basedir}/repository</url>
+ </repository>
+ </distributionManagement>
+</project>
--- /dev/null
+0612c49b1ac80983bfda08616330a4b8
\ No newline at end of file
--- /dev/null
+156d6062060743bf28df306e067914d3d692b571
\ No newline at end of file
<artifactId>test-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<versioning>
+ <release>1.0-SNAPSHOT</release>
<versions>
<version>1.0-SNAPSHOT</version>
</versions>
- <lastUpdated>20100308230825</lastUpdated>
+ <lastUpdated>20100310014828</lastUpdated>
</versioning>
</metadata>
-93afaac7340faadc7efd097952d79fa4
\ No newline at end of file
+4c0a7072d66cfe2deebd3eb998332ccb
\ No newline at end of file
-d59d588343d61fd7d838984a0daa4aaa2546bf9d
\ No newline at end of file
+64c28127c4923ff352021bdfdad448d2d881ef3b
\ No newline at end of file
--- /dev/null
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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.
+ */
+
+public interface ArtifactMappingProvider
+{
+ String mapClassifierAndExtensionToType( String classifier, String ext );
+}
--- /dev/null
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider" role-hint="default"
+ */
+public class DefaultArtifactMappingProvider
+ implements ArtifactMappingProvider
+{
+ private final Map<String,String> classifierAndExtensionToTypeMap;
+
+ public DefaultArtifactMappingProvider()
+ {
+ classifierAndExtensionToTypeMap = new HashMap<String,String>();
+
+ // Maven 2.2.1 supplied types (excluding defaults where extension == type and no classifier)
+ classifierAndExtensionToTypeMap.put( "client:jar", "ejb-client" );
+ classifierAndExtensionToTypeMap.put( "sources:jar", "java-source" );
+ classifierAndExtensionToTypeMap.put( "javadoc:jar", "javadoc" );
+ classifierAndExtensionToTypeMap.put( "tests:jar", "test-jar" );
+ }
+
+ public String mapClassifierAndExtensionToType( String classifier, String ext )
+ {
+ classifier = classifier != null ? classifier : "";
+ ext = ext != null ? ext : "";
+ return classifierAndExtensionToTypeMap.get( classifier + ":" + ext );
+ }
+}
package org.apache.archiva.metadata.repository.storage.maven2;
-import org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
-import org.apache.maven.archiva.common.utils.VersionUtil;
-
-import java.io.File;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* under the License.
*/
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.maven.archiva.common.utils.VersionUtil;
+
+import java.io.File;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* @plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator" role-hint="maven2"
*/
private static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "([0-9]{8}.[0-9]{6})-([0-9]+).*" );
+ /**
+ * @plexus.requirement role="org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider"
+ */
+ private List<ArtifactMappingProvider> artifactMappingProviders;
+
public File toFile( File basedir, String namespace, String projectId, String projectVersion, String filename )
{
return new File( basedir, toPath( namespace, projectId, projectVersion, filename ) );
m.matches();
String timestamp = m.group( 1 );
String buildNumber = m.group( 2 );
+ facet.setTimestamp( timestamp );
+ facet.setBuildNumber( Integer.valueOf( buildNumber ) );
version = idSubStrFromVersion.substring( 0, mainVersionLength ) + timestamp + "-" + buildNumber;
}
catch ( IllegalStateException e )
metadata.setVersion( version );
facet.setClassifier( classifier );
- // TODO: migrate here from ArtifactExtensionMapping and make extensible
-// facet.setType( );
+
+ // we use our own provider here instead of directly accessing Maven's artifact handlers as it has no way
+ // to select the correct order to apply multiple extensions mappings to a preferred type
+ // TODO: this won't allow the user to decide order to apply them if there are conflicts or desired changes -
+ // perhaps the plugins could register missing entries in configuration, then we just use configuration
+ // here?
+
+ String type = null;
+ for ( ArtifactMappingProvider mapping : artifactMappingProviders )
+ {
+ type = mapping.mapClassifierAndExtensionToType( classifier, ext );
+ if ( type != null )
+ {
+ break;
+ }
+ }
+
+ // use extension as default
+ facet.setType( type != null ? type : ext );
metadata.addFacet( facet );
return metadata;
assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
}
- // TODO: test snapshot, rest of artifacts
public void testGetArtifactMetadata()
throws Exception
{
assertEquals( 0, facet.getBuildNumber() );
assertNull( facet.getTimestamp() );
assertEquals( "sources", facet.getClassifier() );
- // TODO
-// assertEquals( "java-source", facet.getType() );
+ assertEquals( "java-source", facet.getType() );
artifactMetadata = artifacts.get( 1 );
assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
assertEquals( 0, facet.getBuildNumber() );
assertNull( facet.getTimestamp() );
assertNull( facet.getClassifier() );
- // TODO
-// assertEquals( "jar", facet.getType() );
+ assertEquals( "jar", facet.getType() );
artifactMetadata = artifacts.get( 2 );
assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
assertEquals( 0, facet.getBuildNumber() );
assertNull( facet.getTimestamp() );
assertNull( facet.getClassifier() );
- // TODO
-// assertEquals( "pom", facet.getType() );
+ assertEquals( "pom", facet.getType() );
+ }
+
+ public void testGetArtifactMetadataSnapshots()
+ throws Exception
+ {
+ Collection<ArtifactMetadata> testArtifacts = resolver.getArtifacts( TEST_REPO_ID, "com.example.test",
+ "test-artifact", "1.0-SNAPSHOT" );
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
+ Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
+ {
+ public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
+ {
+ return o1.getId().compareTo( o2.getId() );
+ }
+ } );
+
+ assertEquals( 6, artifacts.size() );
+
+ ArtifactMetadata artifactMetadata = artifacts.get( 0 );
+ assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
+ MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+ assertEquals( 1, facet.getBuildNumber() );
+ assertEquals( "20100308.230825", facet.getTimestamp() );
+ assertNull( facet.getClassifier() );
+ assertEquals( "jar", facet.getType() );
+
+ artifactMetadata = artifacts.get( 1 );
+ assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+ assertEquals( 1, facet.getBuildNumber() );
+ assertEquals( "20100308.230825", facet.getTimestamp() );
+ assertNull( facet.getClassifier() );
+ assertEquals( "pom", facet.getType() );
+
+ artifactMetadata = artifacts.get( 2 );
+ assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+ assertEquals( 2, facet.getBuildNumber() );
+ assertEquals( "20100310.014828", facet.getTimestamp() );
+ assertEquals( "javadoc", facet.getClassifier() );
+ assertEquals( "javadoc", facet.getType() );
+
+ artifactMetadata = artifacts.get( 3 );
+ assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+ assertEquals( 2, facet.getBuildNumber() );
+ assertEquals( "20100310.014828", facet.getTimestamp() );
+ assertEquals( "sources", facet.getClassifier() );
+ assertEquals( "java-source", facet.getType() );
+
+ artifactMetadata = artifacts.get( 4 );
+ assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+ assertEquals( 2, facet.getBuildNumber() );
+ assertEquals( "20100310.014828", facet.getTimestamp() );
+ assertNull( facet.getClassifier() );
+ assertEquals( "jar", facet.getType() );
+
+ artifactMetadata = artifacts.get( 5 );
+ assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
+ facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
+ assertEquals( 2, facet.getBuildNumber() );
+ assertEquals( "20100310.014828", facet.getTimestamp() );
+ assertNull( facet.getClassifier() );
+ assertEquals( "pom", facet.getType() );
}
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )