summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMaria Odea B. Ching <oching@apache.org>2008-11-04 17:17:19 +0000
committerMaria Odea B. Ching <oching@apache.org>2008-11-04 17:17:19 +0000
commitf2ff86704d8973e7dc8e97a6681aadb5cfe42a52 (patch)
tree4d13c0558a580b8360b44f25be5331526c228905 /archiva-modules
parent9d345b6c945cbffa3ed35f3e0420ae9c661dcf6d (diff)
downloadarchiva-f2ff86704d8973e7dc8e97a6681aadb5cfe42a52.tar.gz
archiva-f2ff86704d8973e7dc8e97a6681aadb5cfe42a52.zip
[MRM-206]
- added getDependencies(..) and getDependees(..) implementation - added test cases git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@711320 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/SearchService.java4
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java111
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java40
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java152
4 files changed, 290 insertions, 17 deletions
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/SearchService.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/SearchService.java
index d820be458..1fa9fd155 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/SearchService.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/SearchService.java
@@ -23,6 +23,8 @@ import java.util.Date;
import java.util.List;
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
+import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
+
import com.atlassian.xmlrpc.ServiceObject;
@ServiceObject("Search")
@@ -48,7 +50,7 @@ public interface SearchService
public List<Artifact> getArtifactVersionsByDate( String groupId, String artifactId, String version, Date whenGathered )
throws Exception;
- public List<Artifact> getDirectDependencies( String repositoryId, String groupId, String artifactId, String version )
+ public List<Dependency> getDependencies( String groupId, String artifactId, String version )
throws Exception;
public List<Artifact> getDependencyTree( String groupId, String artifactId, String version ) throws Exception;
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java
new file mode 100644
index 000000000..7e12d76f0
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Dependency.java
@@ -0,0 +1,111 @@
+package org.apache.archiva.web.xmlrpc.api.beans;
+
+/*
+ * 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.Serializable;
+
+import com.atlassian.xmlrpc.ServiceBean;
+
+@ServiceBean
+public class Dependency
+ implements Serializable
+{
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
+
+ private String classifier;
+
+ private String type;
+
+ private String scope;
+
+ public Dependency( String groupId, String artifactId, String version, String classifier, String type, String scope )
+ {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ this.classifier = classifier;
+ this.type = type;
+ this.scope = scope;
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public void setClassifier( String classifier )
+ {
+ this.classifier = classifier;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ public String getScope()
+ {
+ return scope;
+ }
+
+ public void setScope( String scope )
+ {
+ this.scope = scope;
+ }
+}
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
index 407412466..914d2732c 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
@@ -26,9 +26,11 @@ import java.util.List;
import org.apache.archiva.indexer.util.SearchUtil;
import org.apache.archiva.web.xmlrpc.api.SearchService;
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
+import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.BrowsingResults;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
@@ -37,6 +39,7 @@ import org.apache.maven.archiva.indexer.search.SearchResultHit;
import org.apache.maven.archiva.indexer.search.SearchResultLimits;
import org.apache.maven.archiva.indexer.search.SearchResults;
import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
/**
* SearchServiceImpl
@@ -176,19 +179,36 @@ public class SearchServiceImpl
return artifacts;
}
- public List<Artifact> getDirectDependencies( String repositoryId, String groupId, String artifactId, String version )
+ public List<Dependency> getDependencies( String groupId, String artifactId, String version )
throws Exception
{
- List<Artifact> artifacts = new ArrayList<Artifact>();
+ List<Dependency> dependencies = new ArrayList<Dependency>();
+ List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
- return artifacts;
+ try
+ {
+ ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version );
+ List<org.apache.maven.archiva.model.Dependency> modelDeps = model.getDependencies();
+ for( org.apache.maven.archiva.model.Dependency dep : modelDeps )
+ {
+ Dependency dependency = new Dependency(
+ dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(), dep.getType(), dep.getScope() );
+ dependencies.add( dependency );
+ }
+ }
+ catch ( ObjectNotFoundException oe )
+ {
+ throw new Exception( "Artifact does not exist." );
+ }
+
+ return dependencies;
}
public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
throws Exception
{
List<Artifact> a = new ArrayList<Artifact>();
-
+
return a;
}
@@ -197,9 +217,15 @@ public class SearchServiceImpl
throws Exception
{
List<Artifact> artifacts = new ArrayList<Artifact>();
-
- // repo browsing usedBy?
-
+ List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
+
+ List<ArchivaProjectModel> dependees = repoBrowsing.getUsedBy( "", observableRepos, "org.apache.archiva", "archiva-test", "1.0" );
+ for( ArchivaProjectModel model : dependees )
+ {
+ Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "", model.getWhenIndexed() );
+ artifacts.add( artifact );
+ }
+
return artifacts;
}
} \ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java
index a03f2ace7..2deb6f1c2 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java
@@ -27,6 +27,7 @@ import java.util.List;
import org.apache.archiva.web.xmlrpc.api.SearchService;
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
+import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@@ -35,6 +36,7 @@ import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.BrowsingResults;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
@@ -45,6 +47,7 @@ import org.apache.maven.archiva.indexer.search.SearchResultLimits;
import org.apache.maven.archiva.indexer.search.SearchResults;
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.ArtifactReference;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
@@ -347,14 +350,73 @@ public class SearchServiceImplTest
public void testGetDependenciesArtifactExists()
throws Exception
- {
-
+ {
+ List<String> observableRepoIds = new ArrayList<String>();
+ observableRepoIds.add( "repo1.mirror" );
+ observableRepoIds.add( "public.releases" );
+
+ ArchivaProjectModel model = new ArchivaProjectModel();
+ model.setGroupId( "org.apache.archiva" );
+ model.setArtifactId( "archiva-test" );
+ model.setVersion( "1.0" );
+
+ org.apache.maven.archiva.model.Dependency dependency = new org.apache.maven.archiva.model.Dependency();
+ dependency.setGroupId( "commons-logging" );
+ dependency.setArtifactId( "commons-logging" );
+ dependency.setVersion( "2.0" );
+
+ model.addDependency( dependency );
+
+ dependency = new org.apache.maven.archiva.model.Dependency();
+ dependency.setGroupId( "junit" );
+ dependency.setArtifactId( "junit" );
+ dependency.setVersion( "2.4" );
+ dependency.setScope( "test" );
+
+ model.addDependency( dependency );
+
+ userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), model );
+
+ repoBrowsingControl.replay();
+ userReposControl.replay();
+
+ List<Dependency> dependencies = searchService.getDependencies( "org.apache.archiva", "archiva-test", "1.0" );
+
+ repoBrowsingControl.verify();
+ userReposControl.verify();
+
+ assertNotNull( dependencies );
+ assertEquals( 2, dependencies.size() );
}
public void testGetDependenciesArtifactDoesNotExist()
throws Exception
{
-
+ List<String> observableRepoIds = new ArrayList<String>();
+ observableRepoIds.add( "repo1.mirror" );
+ observableRepoIds.add( "public.releases" );
+
+ userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+ repoBrowsingControl.expectAndThrow(
+ repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), new ObjectNotFoundException( "Artifact does not exist." ) );
+
+ userReposControl.replay();
+ repoBrowsingControl.replay();
+
+ try
+ {
+ List<Dependency> dependencies = searchService.getDependencies( "org.apache.archiva", "archiva-test", "1.0" );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Artifact does not exist.", e.getMessage() );
+ }
+
+ userReposControl.verify();
+ repoBrowsingControl.verify();
}
/* get dependency tree */
@@ -362,7 +424,7 @@ public class SearchServiceImplTest
public void testGetDependencyTreeArtifactExists()
throws Exception
{
-
+
}
public void testGetDependencyTreeArtifactDoesNotExist()
@@ -373,15 +435,87 @@ public class SearchServiceImplTest
/* get dependees */
- public void testGetDependeneesArtifactExists()
+ public void testGetDependees()
throws Exception
{
-
+ Date date = new Date();
+ List<String> observableRepoIds = new ArrayList<String>();
+ observableRepoIds.add( "repo1.mirror" );
+ observableRepoIds.add( "public.releases" );
+
+ List dependeeModels = new ArrayList();
+ ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
+ dependeeModel.setGroupId( "org.apache.archiva" );
+ dependeeModel.setArtifactId( "archiva-dependee-one" );
+ dependeeModel.setVersion( "1.0" );
+ dependeeModel.setWhenIndexed( date );
+ dependeeModels.add( dependeeModel );
+
+ dependeeModel = new ArchivaProjectModel();
+ dependeeModel.setGroupId( "org.apache.archiva" );
+ dependeeModel.setArtifactId( "archiva-dependee-two" );
+ dependeeModel.setVersion( "1.0" );
+ dependeeModel.setWhenIndexed( date );
+ dependeeModels.add( dependeeModel );
+
+ userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+ repoBrowsingControl.expectAndReturn( repoBrowsing.getUsedBy( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), dependeeModels );
+
+ repoBrowsingControl.replay();
+ userReposControl.replay();
+
+ List<Artifact> dependees = searchService.getDependees( "org.apache.archiva", "archiva-test", "1.0" );
+
+ repoBrowsingControl.verify();
+ userReposControl.verify();
+
+ assertNotNull( dependees );
+ assertEquals( 2, dependees.size() );
}
- public void testGetDependeneesArtifactDoesNotExist()
+ /*public void testGetDependeesArtifactDoesNotExist()
throws Exception
{
-
- }
+ Date date = new Date();
+ List<String> observableRepoIds = new ArrayList<String>();
+ observableRepoIds.add( "repo1.mirror" );
+ observableRepoIds.add( "public.releases" );
+
+ List dependeeModels = new ArrayList();
+ ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
+ dependeeModel.setGroupId( "org.apache.archiva" );
+ dependeeModel.setArtifactId( "archiva-dependee-one" );
+ dependeeModel.setVersion( "1.0" );
+ dependeeModel.setWhenIndexed( date );
+ dependeeModels.add( dependeeModel );
+
+ dependeeModel = new ArchivaProjectModel();
+ dependeeModel.setGroupId( "org.apache.archiva" );
+ dependeeModel.setArtifactId( "archiva-dependee-two" );
+ dependeeModel.setVersion( "1.0" );
+ dependeeModel.setWhenIndexed( date );
+ dependeeModels.add( dependeeModel );
+
+ userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+ repoBrowsingControl.expectAndReturn( repoBrowsing.getUsedBy( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), dependeeModels );
+
+ repoBrowsingControl.replay();
+ userReposControl.replay();
+
+ try
+ {
+ List<Artifact> dependees = searchService.getDependees( "org.apache.archiva", "archiva-test", "1.0" );
+ fail( "An exception should have been thrown." );
+ }
+ catch ( Exception e )
+ {
+ assertEquals( "Artifact does not exist." )
+ }
+
+ repoBrowsingControl.verify();
+ userReposControl.verify();
+
+ assertNotNull( dependees );
+ assertEquals( 2, dependees.size() );
+ }*/
} \ No newline at end of file