From c854fd309d746647b546cd24d70b323e4daf9798 Mon Sep 17 00:00:00 2001 From: Stanislav Ochotnicky Date: Fri, 10 Jun 2011 10:31:51 +0200 Subject: Direct fragment processing instead of use of generated depmap We had to create wrapper around fragment data because they are not proper xml document (they lack root element). --- .../artifact/repository/MavenJPackageDepmap.java | 77 +++++++++++++++++++--- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/artifact/repository/MavenJPackageDepmap.java b/src/main/java/org/apache/maven/artifact/repository/MavenJPackageDepmap.java index 14fcac5..9b48a07 100644 --- a/src/main/java/org/apache/maven/artifact/repository/MavenJPackageDepmap.java +++ b/src/main/java/org/apache/maven/artifact/repository/MavenJPackageDepmap.java @@ -1,7 +1,10 @@ package org.apache.maven.artifact.repository; +import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.util.Hashtable; import java.util.StringTokenizer; @@ -9,10 +12,11 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import org.w3c.dom.*; - public class MavenJPackageDepmap { private static class ArtifactDefinition { @@ -21,6 +25,50 @@ public class MavenJPackageDepmap { String version = null; } + /** + * + * @author Stanislav Ochotnicky + * + * This class is used to wrap around fragments that are mapping + * artifacts to jar files in our _javadir. These used to be + * processed in a macro after every package installation. Fragments + * themselves are not proper xml files (they have no root element) + * so we have to fix them by wrapping them in one root element. + */ + private static class WrapFragmentStream extends InputStream { + String startTag = ""; + String endTag = ""; + byte fragmentContent[]; + int position; + + WrapFragmentStream(String fragmentPath) throws IOException { + FileInputStream fin = new FileInputStream(fragmentPath); + int nBytes = fin.available(); + byte tmpContent[] = new byte[nBytes]; + fin.read(tmpContent); + fin.close(); + byte startBytes[] = startTag.getBytes(); + byte endBytes[] = endTag.getBytes(); + fragmentContent = new byte[nBytes + startBytes.length + + endBytes.length]; + System.arraycopy(startBytes, 0, fragmentContent, 0, + startBytes.length); + System.arraycopy(tmpContent, 0, fragmentContent, startBytes.length, + tmpContent.length); + System.arraycopy(endBytes, 0, fragmentContent, startBytes.length + + tmpContent.length, endBytes.length); + position = 0; + } + + public int read() throws IOException { + if (position < fragmentContent.length) { + return fragmentContent[position++]; + } else { + return -1; + } + } + } + private static MavenJPackageDepmap instance; private static Hashtable jppArtifactMap; @@ -59,9 +107,6 @@ public class MavenJPackageDepmap { jppCombination = (String) jppArtifactMap.get(idToCheck); - // System.err.println("*** " + groupId+","+artifactId+","+version + - // " => " + jppCombination); - jppDep = new Hashtable(); if (jppCombination != null && jppCombination != "") { @@ -107,8 +152,20 @@ public class MavenJPackageDepmap { processDepmapFile("/etc/maven/maven2-versionless-depmap.xml"); } - debug("Processing file: /usr/share/java-utils/xml/maven2-depmap.xml"); - processDepmapFile("/etc/maven/maven2-depmap.xml"); + // process fragments in etc + File fragmentDir = new File("/etc/maven/fragments"); + String flist[] = fragmentDir.list(); + if (flist != null) + for (String fragFilename : flist) + processDepmapFile("/etc/maven/fragments/" + fragFilename); + + // process fragments is usr. Once packages are rebuilt, we can skip + // fragments in /etc + fragmentDir = new File("/usr/share/maven-fragments"); + flist = fragmentDir.list(); + if (flist != null) + for (String fragFilename : flist) + processDepmapFile("/usr/share/maven-fragments/" + fragFilename); String customFileName = System.getProperty("maven.local.depmap.file", null); @@ -116,6 +173,7 @@ public class MavenJPackageDepmap { debug("Processing file: " + customFileName); processDepmapFile(customFileName); } + } private static void processDepmapFile(String fileName) { @@ -126,7 +184,10 @@ public class MavenJPackageDepmap { DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); fact.setNamespaceAware(true); DocumentBuilder builder = fact.newDocumentBuilder(); - mapDocument = builder.parse(fileName); + // we can wrap even old depmaps, no harm done + WrapFragmentStream wfs = new WrapFragmentStream(fileName); + mapDocument = builder.parse(wfs); + wfs.close(); } catch (FileNotFoundException fnfe) { System.err.println("ERROR: Unable to find map file: " + fileName); fnfe.printStackTrace(); -- cgit