Stab at model.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@512468 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-02-27 22:48:37 +00:00
parent 5f263af251
commit 6d3a2dca4c
7 changed files with 366 additions and 472 deletions

View File

@ -19,24 +19,11 @@ package org.apache.maven.archiva.model;
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidArtifactRTException;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
/**
* ArchivaArtifact
@ -47,84 +34,23 @@ import java.util.regex.Matcher;
* @plexus.component role="org.apache.maven.archiva.model.ArchivaArtifact"
*/
public class ArchivaArtifact
implements Artifact
implements RepositoryContent
{
private ArtifactHandler artifactHandler;
private String artifactId;
private Map attached;
private List availableVersions;
/**
* The resolved version for the artifact after conflict resolution, that has not been transformed.
*
* @todo should be final
*/
private String baseVersion;
private String classifier;
private ArtifactFilter dependencyFilter;
private List dependencyTrail;
private String downloadUrl;
private File file;
private String groupId;
private Map metadataMap;
private boolean optional;
private boolean release;
private ArtifactRepository repository;
private boolean resolved;
private String scope;
private RepositoryContentKey key;
private String type;
private String version;
private VersionRange versionRange;
public ArchivaArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type,
String classifier, ArtifactHandler artifactHandler )
public ArchivaArtifact( ArtifactRepository repository, String groupId, String artifactId, String version, String classifier, String type )
{
this( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler, false );
}
public ArchivaArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type,
String classifier, ArtifactHandler artifactHandler, boolean optional )
{
this.groupId = groupId;
this.artifactId = artifactId;
this.versionRange = versionRange;
selectVersionFromNewRangeIfAvailable();
this.artifactHandler = artifactHandler;
this.scope = scope;
this.type = type;
if ( classifier == null )
{
classifier = artifactHandler.getClassifier();
}
this.key = new RepositoryContentKey( repository, groupId, artifactId, version );
this.classifier = classifier;
this.optional = optional;
this.type = type;
validateIdentity();
}
@ -136,216 +62,24 @@ public class ArchivaArtifact
attachedArtifact.clearAttached();
}
public void addMetadata( ArtifactMetadata metadata )
{
if ( metadataMap == null )
{
metadataMap = new HashMap();
}
ArtifactMetadata m = (ArtifactMetadata) metadataMap.get( metadata.getKey() );
if ( m != null )
{
m.merge( metadata );
}
else
{
metadataMap.put( metadata.getKey(), metadata );
}
}
public void clearAttached()
{
attached.clear();
}
public int compareTo( Object o )
{
Artifact a = (Artifact) o;
int result = groupId.compareTo( a.getGroupId() );
if ( result == 0 )
{
result = artifactId.compareTo( a.getArtifactId() );
if ( result == 0 )
{
result = type.compareTo( a.getType() );
if ( result == 0 )
{
if ( classifier == null )
{
if ( a.getClassifier() != null )
{
result = 1;
}
}
else
{
if ( a.getClassifier() != null )
{
result = classifier.compareTo( a.getClassifier() );
}
else
{
result = -1;
}
}
if ( result == 0 )
{
// We don't consider the version range in the comparison, just the resolved version
result = version.compareTo( a.getVersion() );
}
}
}
}
return result;
}
public boolean equals( Object o )
{
if ( o == this )
{
return true;
}
if ( !( o instanceof Artifact ) )
{
return false;
}
Artifact a = (Artifact) o;
if ( !a.getGroupId().equals( groupId ) )
{
return false;
}
else if ( !a.getArtifactId().equals( artifactId ) )
{
return false;
}
else if ( !a.getVersion().equals( version ) )
{
return false;
}
else if ( !a.getType().equals( type ) )
{
return false;
}
else if ( a.getClassifier() == null ? classifier != null : !a.getClassifier().equals( classifier ) )
{
return false;
}
// We don't consider the version range in the comparison, just the resolved version
return true;
}
public ArtifactHandler getArtifactHandler()
{
return artifactHandler;
}
public String getArtifactId()
{
return artifactId;
}
public Map getAttached()
{
return attached;
}
public List getAvailableVersions()
{
return availableVersions;
}
public String getBaseVersion()
{
if ( baseVersion == null )
{
baseVersion = version;
if ( version == null )
{
throw new NullPointerException( "version was null for " + groupId + ":" + artifactId );
}
}
return baseVersion;
}
public String getClassifier()
{
return classifier;
}
public String getDependencyConflictId()
public RepositoryContentKey getRepositoryContentKey()
{
StringBuffer sb = new StringBuffer();
sb.append( getGroupId() );
sb.append( ":" );
appendArtifactTypeClassifierString( sb );
return sb.toString();
}
public ArtifactFilter getDependencyFilter()
{
return dependencyFilter;
}
public List getDependencyTrail()
{
return dependencyTrail;
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public String getDownloadUrl()
{
return downloadUrl;
}
public File getFile()
{
return file;
}
public String getGroupId()
{
return groupId;
}
public String getId()
{
return getDependencyConflictId() + ":" + getBaseVersion();
}
public Collection getMetadataList()
{
return metadataMap == null ? Collections.EMPTY_LIST : metadataMap.values();
}
// ----------------------------------------------------------------------
// Object overrides
// ----------------------------------------------------------------------
public ArtifactRepository getRepository()
{
return repository;
}
public String getScope()
{
return scope;
}
public ArtifactVersion getSelectedVersion()
throws OverConstrainedVersionException
{
return versionRange.getSelectedVersion( this );
return key;
}
public String getType()
@ -353,213 +87,42 @@ public class ArchivaArtifact
return type;
}
public String getVersion()
{
return version;
}
public VersionRange getVersionRange()
{
return versionRange;
}
public boolean hasClassifier()
{
return StringUtils.isNotEmpty( classifier );
}
public int hashCode()
{
int result = 17;
result = 37 * result + groupId.hashCode();
result = 37 * result + artifactId.hashCode();
result = 37 * result + type.hashCode();
if ( version != null )
{
result = 37 * result + version.hashCode();
}
result = 37 * result + ( classifier != null ? classifier.hashCode() : 0 );
return result;
}
public boolean isOptional()
{
return optional;
}
public boolean isRelease()
{
return release;
}
public boolean isResolved()
{
return resolved;
}
public boolean isSelectedVersionKnown()
throws OverConstrainedVersionException
{
return versionRange.isSelectedVersionKnown( this );
}
public boolean isSnapshot()
{
if ( version != null || baseVersion != null )
{
Matcher m = VERSION_FILE_PATTERN.matcher( getBaseVersion() );
if ( m.matches() )
{
setBaseVersion( m.group( 1 ) + "-" + SNAPSHOT_VERSION );
return true;
}
else
{
return getBaseVersion().endsWith( SNAPSHOT_VERSION ) || getBaseVersion().equals( LATEST_VERSION );
}
}
else
{
return false;
}
}
public void selectVersion( String version )
{
this.version = version;
this.baseVersion = version;
}
public void setArtifactHandler( ArtifactHandler artifactHandler )
{
this.artifactHandler = artifactHandler;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public void setAttached( Map attached )
{
this.attached = attached;
}
public void setAvailableVersions( List availableVersions )
public void setRepositoryContentKey( RepositoryContentKey key )
{
this.availableVersions = availableVersions;
}
public void setBaseVersion( String baseVersion )
{
this.baseVersion = baseVersion;
}
public void setDependencyFilter( ArtifactFilter artifactFilter )
{
this.dependencyFilter = artifactFilter;
}
public void setDependencyTrail( List dependencyTrail )
{
this.dependencyTrail = dependencyTrail;
}
public void setDownloadUrl( String downloadUrl )
{
this.downloadUrl = downloadUrl;
}
public void setFile( File file )
{
this.file = file;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public void setOptional( boolean optional )
{
this.optional = optional;
}
public void setRelease( boolean release )
{
this.release = release;
}
public void setRepository( ArtifactRepository repository )
{
this.repository = repository;
}
public void setResolved( boolean resolved )
{
this.resolved = resolved;
}
public void setResolvedVersion( String version )
{
this.version = version;
// retain baseVersion
}
public void setScope( String scope )
{
this.scope = scope;
}
public void setVersion( String version )
{
this.version = version;
this.baseVersion = version;
this.versionRange = null;
}
public void setVersionRange( VersionRange versionRange )
{
this.versionRange = versionRange;
selectVersionFromNewRangeIfAvailable();
this.key = key;
}
public String toString()
{
StringBuffer sb = new StringBuffer();
if ( getGroupId() != null )
if ( key.getGroupId() != null )
{
sb.append( getGroupId() );
sb.append( key.getGroupId() );
sb.append( ":" );
}
appendArtifactTypeClassifierString( sb );
sb.append( ":" );
if ( version != null || baseVersion != null )
if ( key.getVersion() != null )
{
sb.append( getBaseVersion() );
sb.append( key.getVersion() );
}
else
{
sb.append( versionRange.toString() );
}
if ( scope != null )
{
sb.append( ":" );
sb.append( scope );
}
return sb.toString();
}
public void updateVersion( String version, ArtifactRepository localRepository )
{
setResolvedVersion( version );
setFile( new File( localRepository.getBasedir(), localRepository.pathOf( this ) ) );
return sb.toString();
}
private void appendArtifactTypeClassifierString( StringBuffer sb )
{
sb.append( getArtifactId() );
sb.append( key.getArtifactId() );
sb.append( ":" );
sb.append( getType() );
if ( hasClassifier() )
@ -574,41 +137,29 @@ public class ArchivaArtifact
return value == null || value.trim().length() < 1;
}
private void selectVersionFromNewRangeIfAvailable()
{
if ( versionRange != null && versionRange.getRecommendedVersion() != null )
{
selectVersion( versionRange.getRecommendedVersion().toString() );
}
else
{
this.version = null;
this.baseVersion = null;
}
}
private void validateIdentity()
{
if ( empty( groupId ) )
if ( empty( key.getGroupId() ) )
{
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
"The groupId cannot be empty." );
}
if ( artifactId == null )
if ( key.getArtifactId() == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
"The artifactId cannot be empty." );
}
if ( type == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type, "The type cannot be empty." );
throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
"The type cannot be empty." );
}
if ( version == null && versionRange == null )
if ( key.getVersion() == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
"The version cannot be empty." );
}
}

View File

@ -0,0 +1,77 @@
package org.apache.maven.archiva.model;
/*
* 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.maven.artifact.repository.ArtifactRepository;
import java.util.ArrayList;
import java.util.List;
/**
* ArchivaRepositoryMetadata
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class ArchivaRepositoryMetadata
implements RepositoryContent
{
private List availableVersions = new ArrayList();
private RepositoryContentKey key;
private String releasedVersion;
public ArchivaRepositoryMetadata( ArtifactRepository repository, String groupId, String artifactId, String version )
{
this.key = new RepositoryContentKey( repository, groupId, artifactId, version );
}
public List getAvailableVersions()
{
return availableVersions;
}
public String getReleasedVersion()
{
return releasedVersion;
}
public RepositoryContentKey getRepositoryContentKey()
{
return this.key;
}
public void setAvailableVersions( List availableVersions )
{
this.availableVersions = availableVersions;
}
public void setReleasedVersion( String releasedVersion )
{
this.releasedVersion = releasedVersion;
}
public void setRepositoryContentKey( RepositoryContentKey key )
{
this.key = key;
}
}

View File

@ -0,0 +1,33 @@
package org.apache.maven.archiva.model;
/*
* 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.
*/
/**
* RepositoryContent
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public interface RepositoryContent
{
public RepositoryContentKey getRepositoryContentKey();
public void setRepositoryContentKey( RepositoryContentKey key );
}

View File

@ -0,0 +1,87 @@
package org.apache.maven.archiva.model;
/*
* 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.maven.artifact.repository.ArtifactRepository;
/**
* RepositoryContentKey - the golden key for all content within the repository.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class RepositoryContentKey
{
private String artifactId;
private String groupId;
private ArtifactRepository repository;
private String version;
public RepositoryContentKey( ArtifactRepository repository, String groupId, String artifactId, String version )
{
this.repository = repository;
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}
public String getArtifactId()
{
return artifactId;
}
public String getGroupId()
{
return groupId;
}
public ArtifactRepository getRepository()
{
return repository;
}
public String getVersion()
{
return version;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public void setRepository( ArtifactRepository repository )
{
this.repository = repository;
}
public void setVersion( String version )
{
this.version = version;
}
}

View File

@ -0,0 +1,6 @@
package org.apache.maven.archiva.model.health;
public class ArtifactHealth
{
}

View File

@ -0,0 +1,77 @@
package org.apache.maven.archiva.model.health;
/*
* 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.
*/
/**
* HealthProblem
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class HealthProblem
{
private String type;
private String origin;
private String message;
public HealthProblem()
{
}
public HealthProblem( String type, String origin, String message )
{
this.type = type;
this.origin = origin;
this.message = message;
}
public String getMessage()
{
return message;
}
public void setMessage( String message )
{
this.message = message;
}
public String getOrigin()
{
return origin;
}
public void setOrigin( String origin )
{
this.origin = origin;
}
public String getType()
{
return type;
}
public void setType( String type )
{
this.type = type;
}
}

View File

@ -0,0 +1,63 @@
package org.apache.maven.archiva.model.health;
/*
* 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.maven.archiva.model.ArchivaRepositoryMetadata;
import java.util.ArrayList;
import java.util.List;
/**
* RepositoryMetadataHealth
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class RepositoryMetadataHealth
{
private ArchivaRepositoryMetadata repositoryMetadata;
private List problems = new ArrayList();
public void addProblem( HealthProblem problem )
{
this.problems.add( problem );
}
public List getProblems()
{
return problems;
}
public void setProblems( List problems )
{
this.problems = problems;
}
public ArchivaRepositoryMetadata getRepositoryMetadata()
{
return repositoryMetadata;
}
public void setRepositoryMetadata( ArchivaRepositoryMetadata repositoryMetadata )
{
this.repositoryMetadata = repositoryMetadata;
}
}