[MRM-1283] migrate dependencies() method to metadata repository

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-26 11:49:56 +00:00
parent a9d2d71164
commit cd4c3cb104
7 changed files with 282 additions and 29 deletions

View File

@ -228,6 +228,22 @@ public class ShowArtifactAction
model.addMailingList( mailingList );
}
}
if ( versionMetadata.getDependencies() != null )
{
for ( org.apache.archiva.metadata.model.Dependency d : versionMetadata.getDependencies() )
{
Dependency dependency = new Dependency();
dependency.setScope( d.getScope() );
dependency.setSystemPath( d.getSystemPath() );
dependency.setType( d.getType() );
dependency.setVersion( d.getVersion() );
dependency.setArtifactId( d.getArtifactId() );
dependency.setClassifier( d.getClassifier() );
dependency.setGroupId( d.getGroupId() );
dependency.setOptional( d.isOptional() );
model.addDependency( dependency );
}
}
}
/**
@ -236,7 +252,29 @@ public class ShowArtifactAction
public String dependencies()
throws ObjectNotFoundException, ArchivaDatabaseException
{
this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
ProjectVersionMetadata versionMetadata = null;
for ( String repoId : getObservableRepos() )
{
if ( versionMetadata == null )
{
try
{
versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
}
catch ( MetadataResolverException e )
{
addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
return ERROR;
}
}
}
if ( versionMetadata == null )
{
addActionError( "Artifact not found" );
return ERROR;
}
populateLegacyModel( versionMetadata );
this.dependencies = model.getDependencies();
@ -249,8 +287,6 @@ public class ShowArtifactAction
public String mailingLists()
throws ObjectNotFoundException, ArchivaDatabaseException
{
// In the future, this should be replaced by the repository grouping mechanism, so that we are only making
// simple resource requests here and letting the resolver take care of it
ProjectVersionMetadata versionMetadata = null;
for ( String repoId : getObservableRepos() )
{

View File

@ -25,6 +25,7 @@ import java.util.List;
import com.opensymphony.xwork2.Action;
import org.apache.archiva.metadata.model.CiManagement;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.IssueManagement;
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.MailingList;
@ -43,7 +44,6 @@ import org.apache.maven.archiva.database.constraints.ProjectsByArtifactUsageCons
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.security.UserRepositories;
import org.apache.maven.archiva.security.UserRepositoriesStub;
@ -386,22 +386,16 @@ public class ShowArtifactActionTest
public void testGetDependencies()
throws ArchivaDatabaseException
{
List<ArchivaArtifact> artifacts =
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
ArchivaProjectModel legacyModel = createLegacyProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
Dependency dependency1 = createDependencyBasic( "artifactId1" );
Dependency dependency2 = createDependencyExtended( "artifactId2" );
legacyModel.setDependencies( Arrays.asList( dependency1, dependency2 ) );
MockControl projectDaoMockControl = createProjectDaoMock( legacyModel );
versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
setActionParameters();
String result = action.dependencies();
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionSuccess( action, result );
assertActionParameters( action );
@ -472,14 +466,14 @@ public class ShowArtifactActionTest
assertEquals( "version", dependee.getVersion() );
}
private void assertDependencyBasic( Dependency dependency, String artifactId )
private void assertDependencyBasic( org.apache.maven.archiva.model.Dependency dependency, String artifactId )
{
assertEquals( artifactId, dependency.getArtifactId() );
assertEquals( "groupId", dependency.getGroupId() );
assertEquals( "version", dependency.getVersion() );
}
private void assertDependencyExtended( Dependency dependency, String artifactId )
private void assertDependencyExtended( org.apache.maven.archiva.model.Dependency dependency, String artifactId )
{
assertDependencyBasic( dependency, artifactId );
assertEquals( true, dependency.isOptional() );
@ -729,20 +723,6 @@ public class ShowArtifactActionTest
return control;
}
private MockControl createProjectDaoMock( ArchivaProjectModel project )
throws ArchivaDatabaseException
{
MockControl control = MockControl.createNiceControl( ProjectModelDAO.class );
ProjectModelDAO dao = (ProjectModelDAO) control.getMock();
archivaDao.setProjectDao( dao );
control.expectAndReturn(
dao.getProjectModel( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
control.replay();
return control;
}
private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
{
return createArtifact( groupId, artifactId, version, TEST_REPO );

View File

@ -0,0 +1,122 @@
package org.apache.archiva.metadata.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.
*/
/**
* TODO: review what is appropriate for the base here - rest should be in a maven dependency facet
*/
public class Dependency
{
private String classifier;
private boolean optional;
private String scope;
private String systemPath;
private String type;
private String artifactId;
private String groupId;
private String version;
public void setClassifier( String classifier )
{
this.classifier = classifier;
}
public String getClassifier()
{
return classifier;
}
public void setOptional( boolean optional )
{
this.optional = optional;
}
public boolean isOptional()
{
return optional;
}
public void setScope( String scope )
{
this.scope = scope;
}
public String getScope()
{
return scope;
}
public void setSystemPath( String systemPath )
{
this.systemPath = systemPath;
}
public String getSystemPath()
{
return systemPath;
}
public void setType( String type )
{
this.type = type;
}
public String getType()
{
return type;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public void setVersion( String version )
{
this.version = version;
}
public String getVersion()
{
return version;
}
public String getArtifactId()
{
return artifactId;
}
public String getGroupId()
{
return groupId;
}
}

View File

@ -49,6 +49,8 @@ public class ProjectVersionMetadata
private List<MailingList> mailingLists;
private List<Dependency> dependencies;
public String getId()
{
return id;
@ -186,4 +188,23 @@ public class ProjectVersionMetadata
}
this.mailingLists.add( mailingList );
}
public void setDependencies( List<Dependency> dependencies )
{
this.dependencies = dependencies;
}
public List<Dependency> getDependencies()
{
return dependencies;
}
public void addDependency( Dependency dependency )
{
if ( this.dependencies == null )
{
this.dependencies = new ArrayList<Dependency>();
}
this.dependencies.add( dependency );
}
}

View File

@ -34,6 +34,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.xml.XMLException;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
@ -143,6 +144,7 @@ public class Maven2RepositoryMetadataResolver
metadata.setIssueManagement( convertIssueManagement( model.getIssueManagement() ) );
metadata.setLicenses( convertLicenses( model.getLicenses() ) );
metadata.setMailingLists( convertMailingLists( model.getMailingLists() ) );
metadata.setDependencies( convertDependencies( model.getDependencies() ) );
metadata.setName( model.getName() );
metadata.setOrganization( convertOrganization( model.getOrganization() ) );
metadata.setScm( convertScm( model.getScm() ) );
@ -165,6 +167,27 @@ public class Maven2RepositoryMetadataResolver
return metadata;
}
private List<org.apache.archiva.metadata.model.Dependency> convertDependencies( List<Dependency> dependencies )
{
List<org.apache.archiva.metadata.model.Dependency> l =
new ArrayList<org.apache.archiva.metadata.model.Dependency>();
for ( Dependency dependency : dependencies )
{
org.apache.archiva.metadata.model.Dependency newDependency =
new org.apache.archiva.metadata.model.Dependency();
newDependency.setArtifactId( dependency.getArtifactId() );
newDependency.setClassifier( dependency.getClassifier() );
newDependency.setGroupId( dependency.getGroupId() );
newDependency.setOptional( dependency.isOptional() );
newDependency.setScope( dependency.getScope() );
newDependency.setSystemPath( dependency.getSystemPath() );
newDependency.setType( dependency.getType() );
newDependency.setVersion( dependency.getVersion() );
l.add( newDependency );
}
return l;
}
private org.apache.archiva.metadata.model.Scm convertScm( Scm scm )
{
org.apache.archiva.metadata.model.Scm newScm = null;

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
@ -102,6 +103,36 @@ public class Maven2RepositoryMetadataResolverTest
assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
"http://www.nabble.com/Archiva---Issues-f29617.html" );
List<Dependency> dependencies = metadata.getDependencies();
assertEquals( 10, dependencies.size() );
assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
}
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
{
assertDependency( dependency, groupId, artifactId, version, "compile" );
}
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
String scope )
{
assertEquals( artifactId, dependency.getArtifactId() );
assertEquals( "jar", dependency.getType() );
assertEquals( version, dependency.getVersion() );
assertEquals( groupId, dependency.getGroupId() );
assertEquals( scope, dependency.getScope() );
assertNull( dependency.getClassifier() );
assertNull( dependency.getSystemPath() );
}
public void testGetProjectVersionMetadataForTimestampedSnapshot()
@ -138,6 +169,7 @@ public class Maven2RepositoryMetadataResolverTest
"http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
"announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
Collections.<String>emptyList(), true );
assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
}
public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()

View File

@ -34,6 +34,7 @@ import java.util.Properties;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.IssueManagement;
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.MailingList;
@ -136,6 +137,18 @@ public class FileMetadataRepository
setProperty( properties, "mailingList." + i + ".otherArchives", join( mailingList.getOtherArchives() ) );
i++;
}
i = 0;
for ( Dependency dependency : versionMetadata.getDependencies() )
{
setProperty( properties, "dependency." + i + ".classifier", dependency.getClassifier() );
setProperty( properties, "dependency." + i + ".scope", dependency.getScope() );
setProperty( properties, "dependency." + i + ".systemPath", dependency.getSystemPath() );
setProperty( properties, "dependency." + i + ".artifactId", dependency.getArtifactId() );
setProperty( properties, "dependency." + i + ".groupId", dependency.getGroupId() );
setProperty( properties, "dependency." + i + ".version", dependency.getVersion() );
setProperty( properties, "dependency." + i + ".type", dependency.getType() );
i++;
}
properties.setProperty( "facetIds", join( versionMetadata.getAllFacetIds() ) );
for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )
{
@ -333,6 +346,32 @@ public class FileMetadataRepository
i++;
}
done = false;
i = 0;
while ( !done )
{
String dependencyArtifactId = properties.getProperty( "dependency." + i + ".artifactId" );
if ( dependencyArtifactId != null )
{
Dependency dependency = new Dependency();
dependency.setArtifactId( dependencyArtifactId );
dependency.setGroupId( properties.getProperty( "dependency." + i + ".groupId" ) );
dependency.setClassifier( properties.getProperty( "dependency." + i + ".classifier" ) );
dependency.setOptional(
Boolean.valueOf( properties.getProperty( "dependency." + i + ".optional" ) ) );
dependency.setScope( properties.getProperty( "dependency." + i + ".scope" ) );
dependency.setSystemPath( properties.getProperty( "dependency." + i + ".systemPath" ) );
dependency.setType( properties.getProperty( "dependency." + i + ".type" ) );
dependency.setVersion( properties.getProperty( "dependency." + i + ".version" ) );
versionMetadata.addDependency( dependency );
}
else
{
done = true;
}
i++;
}
for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
{
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );