File basedir = new File( repositoryConfiguration.getLocation() );
if ( VersionUtil.isSnapshot( projectVersion ) )
{
- // TODO: need much error handling here for incorrect metadata
File metadataFile =
pathTranslator.toFile( basedir, namespace, projectId, projectVersion, "maven-metadata.xml" );
try
{
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
- artifactVersion =
- artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end
+ // re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
- artifactVersion =
- artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
+ if ( snapshotVersion != null )
+ {
+ artifactVersion =
+ artifactVersion.substring( 0, artifactVersion.length() - 8 ); // remove SNAPSHOT from end
+ artifactVersion =
+ artifactVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
+ }
}
catch ( XMLException e )
{
File file = pathTranslator.toFile( basedir, namespace, projectId, projectVersion,
projectId + "-" + artifactVersion + ".pom" );
+ if ( !file.exists() )
+ {
+ // metadata could not be resolved
+ return null;
+ }
+
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setProcessPlugins( false );
req.setPomFile( file );
}
catch ( ModelBuildingException e )
{
- throw new MetadataResolverException( "Unable to build Maven POM to derive metadata from: " + e.getMessage(), e );
+ throw new MetadataResolverException( "Unable to build Maven POM to derive metadata from: " + e.getMessage(),
+ e );
}
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
{
return name;
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ Plugin plugin = (Plugin) o;
+
+ if ( !artifactId.equals( plugin.artifactId ) )
+ {
+ return false;
+ }
+ if ( name != null ? !name.equals( plugin.name ) : plugin.name != null )
+ {
+ return false;
+ }
+ if ( !prefix.equals( plugin.prefix ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = prefix.hashCode();
+ result = 31 * result + artifactId.hashCode();
+ result = 31 * result + ( name != null ? name.hashCode() : 0 );
+ return result;
+ }
}
}
checkOrganizationApache( metadata );
}
+ public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
+ throws MetadataResolverException
+ {
+ ProjectVersionMetadata metadata =
+ resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
+ assertNull( metadata );
+ }
+
+ public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
+ throws MetadataResolverException
+ {
+ ProjectVersionMetadata metadata =
+ resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" );
+ assertNull( metadata );
+ }
+
+ public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
+ throws MetadataResolverException
+ {
+ ProjectVersionMetadata metadata =
+ resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" );
+ assertNull( metadata );
+ }
+
+ public void testGetProjectVersionMetadataForInvalidPom()
+ {
+ try
+ {
+ ProjectVersionMetadata metadata =
+ resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
+
+ fail( "Expected failure, but received metadata: " + metadata );
+ }
+ catch ( MetadataResolverException e )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testGetProjectVersionMetadataForMissingPom()
+ throws MetadataResolverException
+ {
+ ProjectVersionMetadata metadata =
+ resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
+ assertNull( metadata );
+
+ }
+
private void checkApacheLicense( ProjectVersionMetadata metadata )
{
assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
public class MavenRepositoryMetadataReaderTest
extends PlexusInSpringTestCase
{
+ public void testGroupMetadata()
+ throws XMLException
+ {
+ File defaultRepoDir = new File( getBasedir(), "src/test/repositories/test" );
+ File metadataFile = new File( defaultRepoDir, "org/apache/maven/plugins/maven-metadata.xml" );
+
+ MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( metadataFile );
+
+ assertNotNull( metadata );
+ assertEquals( "org.apache.maven.plugins", metadata.getGroupId() );
+ assertNull( metadata.getArtifactId() );
+ assertNull( metadata.getReleasedVersion() );
+ assertNull( metadata.getLatestVersion() );
+ assertTrue( metadata.getAvailableVersions().isEmpty() );
+ assertNull( metadata.getSnapshotVersion() );
+ assertNull( metadata.getLastUpdated() );
+
+ MavenRepositoryMetadata.Plugin cleanPlugin = new MavenRepositoryMetadata.Plugin();
+ cleanPlugin.setPrefix( "clean" );
+ cleanPlugin.setArtifactId( "maven-clean-plugin" );
+ cleanPlugin.setName( "Maven Clean Plugin" );
+
+ MavenRepositoryMetadata.Plugin compilerPlugin = new MavenRepositoryMetadata.Plugin();
+ compilerPlugin.setPrefix( "compiler" );
+ compilerPlugin.setArtifactId( "maven-compiler-plugin" );
+ compilerPlugin.setName( "Maven Compiler Plugin" );
+
+ MavenRepositoryMetadata.Plugin surefirePlugin = new MavenRepositoryMetadata.Plugin();
+ surefirePlugin.setPrefix( "surefire" );
+ surefirePlugin.setArtifactId( "maven-surefire-plugin" );
+ surefirePlugin.setName( "Maven Surefire Plugin" );
+
+ assertEquals( Arrays.asList( cleanPlugin, compilerPlugin, surefirePlugin ), metadata.getPlugins() );
+ }
+
public void testProjectMetadata()
throws XMLException
{
--- /dev/null
+<!--
+ ~ 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.
+ -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.example.test</groupId>
+ <artifactId>incomplete-metadata</artifactId>
+ <version>1.0-SNAPSHOT</version>
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<metadata>
+ <groupId>com.example.test</groupId>
+ <artifactId>incomplete-metadata</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <versioning>
+ <!-- no snapshot element -->
+ <lastUpdated>20080801151215</lastUpdated>
+ </versioning>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<this-is-not-the-pom-you-are-looking-for>
+
+</this-is-not-the-pom-you-are-looking-for>
\ No newline at end of file
--- /dev/null
+<!--
+ ~ 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.
+ -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.example.test</groupId>
+ <artifactId>malformed-metadata</artifactId>
+ <version>1.0-SNAPSHOT</version>
+</project>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+ This is not the metadata you are looking for.
--- /dev/null
+<!--
+ ~ 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.
+ -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.example.test</groupId>
+ <artifactId>missing-metadata</artifactId>
+ <version>1.0-SNAPSHOT</version>
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<metadata>
+ <groupId>org.apache.maven.plugins</groupId>
+ <plugins>
+ <plugin>
+ <prefix>clean</prefix>
+ <artifactId>maven-clean-plugin</artifactId>
+ <name>Maven Clean Plugin</name>
+ </plugin>
+ <plugin>
+ <prefix>compiler</prefix>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <name>Maven Compiler Plugin</name>
+ </plugin>
+ <plugin>
+ <prefix>surefire</prefix>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <name>Maven Surefire Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>