diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java index a084977abe..4cea6c1b3b 100644 --- a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java +++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java @@ -21,7 +21,6 @@ package org.apache.maven.repository.internal; import java.io.File; import java.util.ArrayList; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; @@ -35,66 +34,38 @@ import org.sonatype.aether.artifact.Artifact; * @author Benjamin Bentmann */ final class LocalSnapshotMetadata - extends MavenMetadata + extends MavenSnapshotMetadata { - private final Collection artifacts = new ArrayList(); - - private final boolean legacyFormat; - public LocalSnapshotMetadata( Artifact artifact, boolean legacyFormat ) { - super( createMetadata( artifact, legacyFormat ), null ); - this.legacyFormat = legacyFormat; + super( createLocalMetadata( artifact, legacyFormat ), null, legacyFormat ); } public LocalSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) { - super( metadata, file ); - this.legacyFormat = legacyFormat; + super( metadata, file, legacyFormat ); } - private static Metadata createMetadata( Artifact artifact, boolean legacyFormat ) + private static Metadata createLocalMetadata( Artifact artifact, boolean legacyFormat ) { + Metadata metadata = createRepositoryMetadata( artifact, legacyFormat ); + Snapshot snapshot = new Snapshot(); snapshot.setLocalCopy( true ); Versioning versioning = new Versioning(); versioning.setSnapshot( snapshot ); - Metadata metadata = new Metadata(); metadata.setVersioning( versioning ); - metadata.setGroupId( artifact.getGroupId() ); - metadata.setArtifactId( artifact.getArtifactId() ); - metadata.setVersion( artifact.getBaseVersion() ); - - if ( !legacyFormat ) - { - metadata.setModelVersion( "1.1.0" ); - } return metadata; } - public void bind( Artifact artifact ) - { - artifacts.add( artifact ); - } - public MavenMetadata setFile( File file ) { return new LocalSnapshotMetadata( metadata, file, legacyFormat ); } - public Object getKey() - { - return getGroupId() + ':' + getArtifactId() + ':' + getVersion(); - } - - public static Object getKey( Artifact artifact ) - { - return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion(); - } - @Override protected void merge( Metadata recessive ) { @@ -135,29 +106,4 @@ final class LocalSnapshotMetadata artifacts.clear(); } - private String getKey( String classifier, String extension ) - { - return classifier + ':' + extension; - } - - public String getGroupId() - { - return metadata.getGroupId(); - } - - public String getArtifactId() - { - return metadata.getArtifactId(); - } - - public String getVersion() - { - return metadata.getVersion(); - } - - public Nature getNature() - { - return Nature.SNAPSHOT; - } - } diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java new file mode 100644 index 0000000000..0f88cdc1d4 --- /dev/null +++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenSnapshotMetadata.java @@ -0,0 +1,100 @@ +package org.apache.maven.repository.internal; + +/* + * 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.io.File; +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.sonatype.aether.artifact.Artifact; + +/** + * @author Hervé Boutemy + */ +abstract class MavenSnapshotMetadata + extends MavenMetadata +{ + static final String SNAPSHOT = "SNAPSHOT"; + + protected final Collection artifacts = new ArrayList(); + + protected final boolean legacyFormat; + + protected MavenSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) + { + super( metadata, file ); + this.legacyFormat = legacyFormat; + } + + protected static Metadata createRepositoryMetadata( Artifact artifact, boolean legacyFormat ) + { + Metadata metadata = new Metadata(); + if ( !legacyFormat ) + { + metadata.setModelVersion( "1.1.0" ); + } + metadata.setGroupId( artifact.getGroupId() ); + metadata.setArtifactId( artifact.getArtifactId() ); + metadata.setVersion( artifact.getBaseVersion() ); + + return metadata; + } + + public void bind( Artifact artifact ) + { + artifacts.add( artifact ); + } + + public Object getKey() + { + return getGroupId() + ':' + getArtifactId() + ':' + getVersion(); + } + + public static Object getKey( Artifact artifact ) + { + return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion(); + } + + protected String getKey( String classifier, String extension ) + { + return classifier + ':' + extension; + } + + public String getGroupId() + { + return metadata.getGroupId(); + } + + public String getArtifactId() + { + return metadata.getArtifactId(); + } + + public String getVersion() + { + return metadata.getVersion(); + } + + public Nature getNature() + { + return Nature.SNAPSHOT; + } +} diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java index 4ce43938ac..246c786e0b 100644 --- a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java +++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java @@ -23,7 +23,6 @@ import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; @@ -39,46 +38,19 @@ import org.sonatype.aether.artifact.Artifact; * @author Benjamin Bentmann */ final class RemoteSnapshotMetadata - extends MavenMetadata + extends MavenSnapshotMetadata { - private static final String SNAPSHOT = "SNAPSHOT"; - - private final Collection artifacts = new ArrayList(); - private final Map versions = new LinkedHashMap(); - private final boolean legacyFormat; - public RemoteSnapshotMetadata( Artifact artifact, boolean legacyFormat ) { - super( createMetadata( artifact, legacyFormat ), null ); - this.legacyFormat = legacyFormat; + super( createRepositoryMetadata( artifact, legacyFormat ), null, legacyFormat ); } private RemoteSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat ) { - super( metadata, file ); - this.legacyFormat = legacyFormat; - } - - private static Metadata createMetadata( Artifact artifact, boolean legacyFormat ) - { - Metadata metadata = new Metadata(); - if ( !legacyFormat ) - { - metadata.setModelVersion( "1.1.0" ); - } - metadata.setGroupId( artifact.getGroupId() ); - metadata.setArtifactId( artifact.getArtifactId() ); - metadata.setVersion( artifact.getBaseVersion() ); - - return metadata; - } - - public void bind( Artifact artifact ) - { - artifacts.add( artifact ); + super( metadata, file, legacyFormat ); } public MavenMetadata setFile( File file ) @@ -86,16 +58,6 @@ final class RemoteSnapshotMetadata return new RemoteSnapshotMetadata( metadata, file, legacyFormat ); } - public Object getKey() - { - return getGroupId() + ':' + getArtifactId() + ':' + getVersion(); - } - - public static Object getKey( Artifact artifact ) - { - return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion(); - } - public String getExpandedVersion( Artifact artifact ) { String key = getKey( artifact.getClassifier(), artifact.getExtension() ); @@ -136,7 +98,7 @@ final class RemoteSnapshotMetadata if ( version.endsWith( SNAPSHOT ) ) { - String qualifier = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber(); + String qualifier = snapshot.getTimestamp() + '-' + snapshot.getBuildNumber(); version = version.substring( 0, version.length() - SNAPSHOT.length() ) + qualifier; } @@ -145,6 +107,7 @@ final class RemoteSnapshotMetadata sv.setExtension( artifact.getExtension() ); sv.setVersion( version ); sv.setUpdated( lastUpdated ); + versions.put( getKey( sv.getClassifier(), sv.getExtension() ), sv ); } @@ -169,11 +132,6 @@ final class RemoteSnapshotMetadata } } - private String getKey( String classifier, String extension ) - { - return classifier + ':' + extension; - } - private static int getBuildNumber( Metadata metadata ) { int number = 0; @@ -191,24 +149,4 @@ final class RemoteSnapshotMetadata return number; } - public String getGroupId() - { - return metadata.getGroupId(); - } - - public String getArtifactId() - { - return metadata.getArtifactId(); - } - - public String getVersion() - { - return metadata.getVersion(); - } - - public Nature getNature() - { - return Nature.SNAPSHOT; - } - } diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java index 139e5f8c9c..2fefe02e1d 100644 --- a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java +++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java @@ -40,18 +40,22 @@ final class VersionsMetadata public VersionsMetadata( Artifact artifact ) { - super( createMetadata( artifact ), null ); + super( createRepositoryMetadata( artifact ), null ); this.artifact = artifact; } public VersionsMetadata( Artifact artifact, File file ) { - super( createMetadata( artifact ), file ); + super( createRepositoryMetadata( artifact ), file ); this.artifact = artifact; } - private static Metadata createMetadata( Artifact artifact ) + private static Metadata createRepositoryMetadata( Artifact artifact ) { + Metadata metadata = new Metadata(); + metadata.setGroupId( artifact.getGroupId() ); + metadata.setArtifactId( artifact.getArtifactId() ); + Versioning versioning = new Versioning(); versioning.addVersion( artifact.getBaseVersion() ); if ( !artifact.isSnapshot() ) @@ -63,10 +67,7 @@ final class VersionsMetadata versioning.setLatest( artifact.getBaseVersion() ); } - Metadata metadata = new Metadata(); metadata.setVersioning( versioning ); - metadata.setGroupId( artifact.getGroupId() ); - metadata.setArtifactId( artifact.getArtifactId() ); return metadata; }