mirror of https://github.com/apache/maven.git
refactoring: extracted MavenSnapshotMetadata from
(Local+Remote)SnapshotMetadata
This commit is contained in:
parent
37d3166d00
commit
ff370850cd
|
@ -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<Artifact> artifacts = new ArrayList<Artifact>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Artifact> artifacts = new ArrayList<Artifact>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<Artifact> artifacts = new ArrayList<Artifact>();
|
||||
|
||||
private final Map<String, SnapshotVersion> versions = new LinkedHashMap<String, SnapshotVersion>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue