/* Copyright 2004 * */ package org.apache.maven.repository; import java.io.File; import java.io.IOException; import java.util.List; import org.apache.maven.ArtifactListBuilder; import org.apache.maven.MavenUtils; import org.apache.maven.jelly.MavenJellyContext; import org.apache.maven.project.Project; import org.apache.maven.util.HttpUtils; import org.apache.commons.betwixt.io.BeanReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * ComponentArtifactTypeHandler handles globs of jars based * on the component dependency in the project. * * * @author Daniel Marchant * @version 1.0 9:01:00 AM * */ public class ComponentArtifactTypeHandler extends DefaultArtifactTypeHandler { private Log log = LogFactory.getLog(ComponentArtifactTypeHandler.class); public ComponentArtifactTypeHandler() { } /** * Look in the project file xml and get the appropriate jars specified in the list. * Should feed the DependencyVerifier and the BootstrapTask */ public List getDependentArtifacts(Artifact artifact, MavenJellyContext context) { List fetched = (List)context.getVariable(artifact.getName() + ".dependencies.fetched"); if(fetched != null) return fetched; String urlPath = artifact.getUrlPath(); int idx = urlPath.lastIndexOf('.'); urlPath = urlPath.substring(0,(idx)) + ".xml"; String filePath = artifact.getFile().toString(); idx = filePath.lastIndexOf('.'); filePath = filePath.substring(0,(idx)) + ".xml"; try { log.error(" getting file path " + filePath); File file = new File(filePath); if(!file.exists()) { HttpUtils.getFile(urlPath, file, false, true, true, context); } BeanReader reader = MavenUtils.createBeanReader(Project.class); Project project = (Project)reader.parse(file); project.setContext(context); List list = ArtifactListBuilder.build(project); context.setVariable(artifact.getName() + ".dependencies.fetched",list); return list; } catch(java.beans.IntrospectionException ie) { // @todo internationalize message... log.warn("Not able to get the dependent artifacts for " + artifact.getName() + " - " + ie.getMessage()); log.debug("Exception Stack for dependent artifacts retriveval for " + artifact.getName(),ie); } catch(org.xml.sax.SAXException saxe) { // @todo internationalize message... log.warn("Not able to get the dependent artifacts for " + artifact.getName() + " - " + saxe.getMessage()); log.debug("Exception Stack for dependent artifacts retriveval for " + artifact.getName(),saxe); } catch(javax.xml.parsers.ParserConfigurationException pce) { // @todo internationalize message... log.warn("Not able to get the dependent artifacts for " + artifact.getName() + " - " + pce.getMessage()); log.debug("Exception Stack for dependent artifacts retriveval for " + artifact.getName(),pce); } catch(IOException e) { // @todo internationalize message... log.warn("Not able to get the dependent artifacts for " + artifact.getName() + " - " + e.getMessage()); log.debug("Exception Stack for dependent artifacts retriveval for " + artifact.getName(),e); } return null; } }