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 );
+ }
+ }
}
/**
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();
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() )
{
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;
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;
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 );
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() );
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 );
--- /dev/null
+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;
+ }
+}
private List<MailingList> mailingLists;
+ private List<Dependency> dependencies;
+
public String getId()
{
return id;
}
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 );
+ }
}
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;
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() ) );
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;
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;
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()
"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()
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;
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() )
{
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 );