1 19 20 package org.apache.geronimo.mavenplugins.car; 21 22 import java.io.File ; 23 import java.util.SortedSet ; 24 import java.util.TreeSet ; 25 import java.util.Iterator ; 26 27 import org.apache.geronimo.system.repository.Maven2Repository; 28 import org.apache.geronimo.kernel.repository.Artifact; 29 import org.apache.geronimo.kernel.repository.Version; 30 import org.apache.geronimo.gbean.GBeanInfo; 31 import org.apache.geronimo.gbean.GBeanInfoBuilder; 32 import org.apache.geronimo.genesis.dependency.DependencyTree; 33 34 39 public class Maven2RepositoryAdapter 40 extends Maven2Repository 41 { 42 private ArtifactLookup lookup; 43 44 private DependencyTree dependencyTree; 45 46 public Maven2RepositoryAdapter(DependencyTree dependencyTree, final ArtifactLookup lookup) { 47 super(lookup.getBasedir()); 48 this.dependencyTree = dependencyTree; 49 this.lookup = lookup; 50 } 51 52 public File getLocation(final Artifact artifact) { 53 assert artifact != null; 54 55 return lookup.getLocation(artifact); 56 } 57 58 public SortedSet list() { 59 TreeSet list = new TreeSet (); 60 listInternal(list, dependencyTree.getRootNode(), null, null, null, null); 61 return list; 62 } 63 64 public SortedSet list(Artifact query) { 65 TreeSet list = new TreeSet (); 66 listInternal(list, dependencyTree.getRootNode(), query.getGroupId(), query.getArtifactId(), query.getVersion(), query.getType()); 67 return list; 68 } 69 70 private void listInternal(TreeSet list, DependencyTree.Node node, String groupId, String artifactId, Version version, String type) { 71 if (matches(node.getArtifact(), groupId, artifactId, version, type)) { 72 list.add(mavenToGeronimoArtifact(node.getArtifact())); 73 } 74 for (Iterator iterator = node.getChildren().iterator(); iterator.hasNext();) { 75 DependencyTree.Node childNode = (DependencyTree.Node) iterator.next(); 76 listInternal(list, childNode, groupId, artifactId, version, type); 77 } 78 } 79 80 private boolean matches(org.apache.maven.artifact.Artifact artifact, String groupId, String artifactId, Version version, String type) { 81 return (groupId == null || artifact.getGroupId().equals(groupId)) 82 && (artifactId == null || artifact.getArtifactId().equals(artifactId)) 83 && (version == null || artifact.getVersion().equals(version.toString())) 84 && (type == null || artifact.getType().equals(type)); 85 } 86 87 protected org.apache.geronimo.kernel.repository.Artifact mavenToGeronimoArtifact(final org.apache.maven.artifact.Artifact artifact) { 88 assert artifact != null; 89 90 return new org.apache.geronimo.kernel.repository.Artifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType()); 91 } 92 93 97 public static interface ArtifactLookup 98 { 99 File getLocation(Artifact artifact); 100 101 File getBasedir(); 102 } 103 104 108 public static final GBeanInfo GBEAN_INFO; 109 110 static { 111 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Maven2RepositoryAdapter.class, "Repository"); 112 infoFactory.addAttribute("lookup", ArtifactLookup.class, true); 113 infoFactory.addAttribute("dependencies", DependencyTree.class, true); 114 infoFactory.setConstructor(new String []{"dependencies", "lookup" }); 115 GBEAN_INFO = infoFactory.getBeanInfo(); 116 } 117 118 public static GBeanInfo getGBeanInfo() { 119 return GBEAN_INFO; 120 } 121 } 122 | Popular Tags |