001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.client.builder;
021:
022: import java.io.IOException;
023: import java.util.Collection;
024: import java.util.LinkedHashSet;
025:
026: import org.apache.geronimo.kernel.repository.ArtifactManager;
027: import org.apache.geronimo.kernel.repository.Repository;
028: import org.apache.geronimo.kernel.repository.ListableRepository;
029: import org.apache.geronimo.kernel.repository.ArtifactResolver;
030: import org.apache.geronimo.kernel.repository.Artifact;
031: import org.apache.geronimo.kernel.repository.MissingDependencyException;
032: import org.apache.geronimo.kernel.repository.MultipleMatchesException;
033: import org.apache.geronimo.system.resolver.ExplicitDefaultArtifactResolver;
034: import org.apache.geronimo.system.serverinfo.ServerInfo;
035: import org.apache.geronimo.gbean.GBeanInfo;
036: import org.apache.geronimo.gbean.GBeanInfoBuilder;
037:
038: /**
039: * This class is intended to get around some problems using the normal ExplicitDefaultArtifactResolver for client building.
040: * We really want it to refer to the server's client_artifact_aliases.properties file, but that isn't available when run
041: * from the car-maven-plugin. Also the ServerInfo is missing and the ArtifactManager is not in a parent configuration
042: * (the car-maven-plugin starts a configuration that isn't a parent of anything. We might be able to fix that by a
043: * use of artifact_aliases.properties itself, but that might be for later).
044: *
045: * @version $Rev: 567892 $ $Date: 2007-08-20 18:01:16 -0700 (Mon, 20 Aug 2007) $
046: */
047: public class OptionalExplicitDefaultArtifactResolver implements
048: ArtifactResolver {
049:
050: private final ArtifactResolver delegate;
051:
052: public OptionalExplicitDefaultArtifactResolver(
053: String versionMapLocation,
054: Collection<ArtifactManager> artifactManagers,
055: Collection<ListableRepository> repositories,
056: Collection<ServerInfo> serverInfos,
057: Collection<ArtifactResolver> fallbackResolver)
058: throws IOException {
059: ServerInfo serverInfo = getServerInfo(serverInfos);
060: if (serverInfo != null) {
061: delegate = new ExplicitDefaultArtifactResolver(
062: versionMapLocation,
063: getArtifactManager(artifactManagers), repositories,
064: serverInfo);
065: } else {
066: if (fallbackResolver == null || fallbackResolver.isEmpty()) {
067: throw new IllegalStateException(
068: "No ServerInfo and no delegate ArtifactResolver supplied");
069: }
070: delegate = fallbackResolver.iterator().next();
071: }
072: }
073:
074: private static ServerInfo getServerInfo(
075: Collection<ServerInfo> serverInfo) {
076: if (serverInfo == null || serverInfo.isEmpty()) {
077: return null;
078: } else {
079: return serverInfo.iterator().next();
080: }
081: }
082:
083: private static ArtifactManager getArtifactManager(
084: Collection<ArtifactManager> artifactManagers) {
085: if (artifactManagers == null || artifactManagers.isEmpty()) {
086: throw new IllegalStateException("No ArtifactManager found");
087: }
088: return artifactManagers.iterator().next();
089: }
090:
091: public Artifact generateArtifact(Artifact source, String defaultType) {
092: return delegate.generateArtifact(source, defaultType);
093: }
094:
095: public Artifact resolveInClassLoader(Artifact source)
096: throws MissingDependencyException {
097: return delegate.resolveInClassLoader(source);
098: }
099:
100: public Artifact resolveInClassLoader(Artifact source,
101: Collection parentConfigurations)
102: throws MissingDependencyException {
103: return delegate.resolveInClassLoader(source,
104: parentConfigurations);
105: }
106:
107: public LinkedHashSet resolveInClassLoader(Collection artifacts)
108: throws MissingDependencyException {
109: return delegate.resolveInClassLoader(artifacts);
110: }
111:
112: public LinkedHashSet resolveInClassLoader(Collection artifacts,
113: Collection parentConfigurations)
114: throws MissingDependencyException {
115: return delegate.resolveInClassLoader(artifacts,
116: parentConfigurations);
117: }
118:
119: public Artifact queryArtifact(Artifact artifact)
120: throws MultipleMatchesException {
121: return delegate.queryArtifact(artifact);
122: }
123:
124: public Artifact[] queryArtifacts(Artifact artifact) {
125: return delegate.queryArtifacts(artifact);
126: }
127:
128: public static final GBeanInfo GBEAN_INFO;
129:
130: static {
131: GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(
132: OptionalExplicitDefaultArtifactResolver.class,
133: "ArtifactResolver");
134: infoFactory.addAttribute("versionMapLocation", String.class,
135: true, true);
136: infoFactory.addReference("ArtifactManager",
137: ArtifactManager.class, "ArtifactManager");
138: infoFactory.addReference("Repositories",
139: ListableRepository.class, "Repository");
140: infoFactory.addReference("ServerInfo", ServerInfo.class,
141: "GBean");
142: infoFactory.addReference("FallbackArtifactResolver",
143: ArtifactResolver.class, "ArtifactResolver");
144: infoFactory.addInterface(ArtifactResolver.class);
145:
146: infoFactory.setConstructor(new String[] { "versionMapLocation",
147: "ArtifactManager", "Repositories", "ServerInfo",
148: "FallbackArtifactResolver" });
149:
150: GBEAN_INFO = infoFactory.getBeanInfo();
151:
152: }
153:
154: public static GBeanInfo getGBeanInfo() {
155: return GBEAN_INFO;
156: }
157:
158: }
|