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 021 package org.apache.geronimo.system.plugin; 022 023 import java.io.File; 024 import java.io.FileInputStream; 025 import java.io.IOException; 026 027 import javax.security.auth.login.FailedLoginException; 028 029 import org.apache.geronimo.kernel.repository.Artifact; 030 import org.apache.geronimo.kernel.repository.ArtifactResolver; 031 import org.apache.geronimo.kernel.repository.DefaultArtifactManager; 032 import org.apache.geronimo.kernel.repository.DefaultArtifactResolver; 033 import org.apache.geronimo.kernel.repository.FileWriteMonitor; 034 import org.apache.geronimo.kernel.repository.Maven2Repository; 035 import org.apache.geronimo.kernel.repository.MissingDependencyException; 036 import org.apache.geronimo.system.plugin.model.PluginListType; 037 038 /** 039 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 040 */ 041 public class LocalSourceRepository extends Maven2Repository implements SourceRepository { 042 043 private final ArtifactResolver artifactResolver; 044 045 public LocalSourceRepository(File base) { 046 super(base); 047 artifactResolver = new DefaultArtifactResolver(new DefaultArtifactManager(), this); 048 } 049 050 public PluginListType getPluginList() { 051 try { 052 FileInputStream in = new FileInputStream(new File(rootFile, "geronimo-plugins.xml")); 053 try { 054 return PluginXmlUtil.loadPluginList(in); 055 } finally { 056 in.close(); 057 } 058 } catch (Exception e) { 059 return null; 060 } 061 } 062 063 public OpenResult open(Artifact artifact, FileWriteMonitor monitor) throws IOException, FailedLoginException { 064 if (!artifact.isResolved()) { 065 try { 066 artifact = artifactResolver.resolveInClassLoader(artifact); 067 } catch (MissingDependencyException e) { 068 throw (IOException)new IOException("Could not resolve artifact " + artifact + " in repo " + rootFile).initCause(e); 069 } 070 } 071 File location = getLocation(artifact); 072 return new LocalOpenResult(artifact, location); 073 } 074 }