From 676915056de4f491fb1f49c67fb43e8552a5e282 Mon Sep 17 00:00:00 2001 From: Stanislav Ochotnicky Date: Fri, 10 Jun 2011 09:29:46 +0200 Subject: Formatting cleanups only. Use spaces --- .../artifact/repository/MavenJPackageDepmap.java | 412 +++++++++++---------- .../artifact/resolver/JavadirWorkspaceReader.java | 52 +-- 2 files changed, 246 insertions(+), 218 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 035c9b4..6f2da41 100644 --- a/src/main/java/org/apache/maven/artifact/repository/MavenJPackageDepmap.java +++ b/src/main/java/org/apache/maven/artifact/repository/MavenJPackageDepmap.java @@ -1,5 +1,4 @@ -package org.fedoraproject.maven.artifact.repository; - +package org.apache.maven.artifact.repository; import java.io.FileNotFoundException; import java.io.IOException; @@ -10,204 +9,227 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - import org.xml.sax.SAXException; import org.w3c.dom.*; - public class MavenJPackageDepmap { - private static class ArtifactDefinition { - String groupId = null; - String artifactId = null; - String version = null; - } - - private static MavenJPackageDepmap instance; - private static Hashtable jppArtifactMap; + private static class ArtifactDefinition { + String groupId = null; + String artifactId = null; + String version = null; + } - private MavenJPackageDepmap() { - jppArtifactMap = new Hashtable(); - buildJppArtifactMap(); - } - - public static MavenJPackageDepmap getInstance() { - if (instance == null) { - instance = new MavenJPackageDepmap(); - } - - return instance; - } - - public Hashtable getMappedInfo(Hashtable mavenDep) { - return getMappedInfo((String) mavenDep.get("group"), - (String) mavenDep.get("artifact"), - (String) mavenDep.get("version")); - } - - public Hashtable getMappedInfo(String groupId, String artifactId, String version) { - - Hashtable jppDep; - String idToCheck, jppCombination; - - if (System.getProperty("maven2.ignore.versions") == null && System.getProperty("maven2.jpp.mode") == null) { - idToCheck = groupId+","+artifactId+","+version; - } else { - idToCheck = groupId+","+artifactId; - } - - jppCombination = (String) jppArtifactMap.get(idToCheck); - - //System.err.println("*** " + groupId+","+artifactId+","+version + " => " + jppCombination); - - jppDep = new Hashtable(); - if (jppCombination != null && jppCombination != "") { - - StringTokenizer st = new StringTokenizer(jppCombination, ","); - - jppDep.put("group", st.nextToken()); - jppDep.put("artifact",st.nextToken()); - jppDep.put("version",st.nextToken()); - - } else { - jppDep.put("group", groupId); - jppDep.put("artifact", artifactId); - jppDep.put("version", version); - } - - return jppDep; - } - - - /** - * Returns whether or not the given dependency should be dropped. - */ - public boolean shouldEliminate(String groupId, String artifactId, String version) { - String idToCheck; - - if (System.getProperty("maven2.ignore.versions") == null && System.getProperty("maven2.jpp.mode") == null) { - idToCheck = groupId+","+artifactId+","+version; - } else { - idToCheck = groupId+","+artifactId; - } - - return jppArtifactMap.get(idToCheck) != null && jppArtifactMap.get(idToCheck).equals(""); - - } - - private static void buildJppArtifactMap() { - - if (System.getProperty("maven2.ignore.versions") != null || System.getProperty("maven2.jpp.mode") != null) { - debug("Processing file: /usr/share/java-utils/xml/maven2-versionless-depmap.xml"); - processDepmapFile("/etc/maven/maven2-versionless-depmap.xml"); - } - - debug("Processing file: /usr/share/java-utils/xml/maven2-depmap.xml"); - processDepmapFile("/etc/maven/maven2-depmap.xml"); - - String customFileName = System.getProperty("maven2.jpp.depmap.file", null); - if (customFileName != null) { - debug("Processing file: " + customFileName); - processDepmapFile(customFileName); - } - } - - private static void processDepmapFile(String fileName) { - - Document mapDocument; - debug("Loading depmap file: " + fileName); - try { - DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); - fact.setNamespaceAware(true); - DocumentBuilder builder = fact.newDocumentBuilder(); - mapDocument = builder.parse(fileName); - } catch (FileNotFoundException fnfe) { - System.err.println("ERROR: Unable to find map file: " + fileName); - fnfe.printStackTrace(); - return; - } catch (IOException ioe) { - System.err.println("ERROR: I/O exception occured when opening map file"); - ioe.printStackTrace(); - return; - } catch (ParserConfigurationException pce) { - System.err.println("ERROR: Parsing of depmap file failed - configuration"); - pce.printStackTrace(); - return; - } catch (SAXException se) { - System.err.println("ERROR: Parsing of depmap file failed"); - se.printStackTrace(); - return; - } - - NodeList depNodes = (NodeList) mapDocument.getElementsByTagName("dependency"); - - for (int i = 0; i < depNodes.getLength(); i++) { - Element depNode = (Element) depNodes.item(i); - - NodeList mavenNodeList = (NodeList) depNode.getElementsByTagName("maven"); - if (mavenNodeList.getLength() != 1) { - debug("Number of maven sub-elements is not 1. Bailing from depmap generation"); - debug("Maven node: " + depNode.getTextContent()); - return; - } - ArtifactDefinition mavenAD = getArtifactDefinition((Element) mavenNodeList.item(0)); - - ArtifactDefinition jppAD = null; - NodeList jppNodeList = (NodeList) depNode.getElementsByTagName("jpp"); - - if (jppNodeList.getLength() == 1) { - jppAD = getArtifactDefinition((Element) jppNodeList.item(0)); - if (System.getProperty("maven2.ignore.versions") == null && System.getProperty("maven2.jpp.mode") == null) { - debug("*** Adding: " + mavenAD.groupId + "," + mavenAD.artifactId + "," + mavenAD.version + " => " - + jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map..."); - - jppArtifactMap.put(mavenAD.groupId + "," + mavenAD.artifactId + "," + mavenAD.version, - jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version); - } else { - debug("*** Adding: " + mavenAD.groupId+"," + mavenAD.artifactId + " => " - + jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map..."); - - jppArtifactMap.put(mavenAD.groupId+","+mavenAD.artifactId, - jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version); - } - } else { - debug("Number of jpp sub-elements is not 1. Dropping dependency"); - debug("*** Adding: " + mavenAD.groupId+","+mavenAD.artifactId+"," + " => " + "JPP/maven2,empty-dep,"+mavenAD.version + " to map..."); - jppArtifactMap.put(mavenAD.groupId+","+mavenAD.artifactId, "JPP/maven2,empty-dep,"+mavenAD.version); - } - } - } - - private static ArtifactDefinition getArtifactDefinition(Element element) { - ArtifactDefinition ad = new ArtifactDefinition(); - - NodeList nodes = element.getElementsByTagName("groupId"); - if (nodes.getLength() != 1) { - debug("groupId definition not found in depmap"); - return null; - } - ad.groupId = nodes.item(0).getTextContent(); - - nodes = element.getElementsByTagName("artifactId"); - if (nodes.getLength() != 1) { - debug("artifactId definition not found in depmap"); - return null; - } - ad.artifactId = nodes.item(0).getTextContent(); - - nodes = element.getElementsByTagName("version"); - if (nodes.getLength() != 1) { - ad.version = "DUMMY_VER"; - } else { - ad.version = nodes.item(0).getTextContent(); - } - return ad; - } - - - private static void debug(String msg) { - if (System.getProperty("maven2.jpp.debug") != null) - System.err.println(msg); - } + private static MavenJPackageDepmap instance; + private static Hashtable jppArtifactMap; + + private MavenJPackageDepmap() { + jppArtifactMap = new Hashtable(); + buildJppArtifactMap(); + } + + public static MavenJPackageDepmap getInstance() { + if (instance == null) { + instance = new MavenJPackageDepmap(); + } + + return instance; + } + + public Hashtable getMappedInfo( + Hashtable mavenDep) { + return getMappedInfo((String) mavenDep.get("group"), + (String) mavenDep.get("artifact"), + (String) mavenDep.get("version")); + } + + public Hashtable getMappedInfo(String groupId, + String artifactId, String version) { + + Hashtable jppDep; + String idToCheck, jppCombination; + + if (System.getProperty("maven2.ignore.versions") == null + && System.getProperty("maven2.jpp.mode") == null) { + idToCheck = groupId + "," + artifactId + "," + version; + } else { + idToCheck = groupId + "," + artifactId; + } + + jppCombination = (String) jppArtifactMap.get(idToCheck); + + // System.err.println("*** " + groupId+","+artifactId+","+version + + // " => " + jppCombination); + + jppDep = new Hashtable(); + if (jppCombination != null && jppCombination != "") { + + StringTokenizer st = new StringTokenizer(jppCombination, ","); + + jppDep.put("group", st.nextToken()); + jppDep.put("artifact", st.nextToken()); + jppDep.put("version", st.nextToken()); + + } else { + jppDep.put("group", groupId); + jppDep.put("artifact", artifactId); + jppDep.put("version", version); + } + + return jppDep; + } + + /** + * Returns whether or not the given dependency should be dropped. + */ + public boolean shouldEliminate(String groupId, String artifactId, + String version) { + String idToCheck; + + if (System.getProperty("maven2.ignore.versions") == null + && System.getProperty("maven2.jpp.mode") == null) { + idToCheck = groupId + "," + artifactId + "," + version; + } else { + idToCheck = groupId + "," + artifactId; + } + + return jppArtifactMap.get(idToCheck) != null + && jppArtifactMap.get(idToCheck).equals(""); + + } + + private static void buildJppArtifactMap() { + + if (System.getProperty("maven2.ignore.versions") != null + || System.getProperty("maven2.jpp.mode") != null) { + debug("Processing file: /usr/share/java-utils/xml/maven2-versionless-depmap.xml"); + processDepmapFile("/etc/maven/maven2-versionless-depmap.xml"); + } + + debug("Processing file: /usr/share/java-utils/xml/maven2-depmap.xml"); + processDepmapFile("/etc/maven/maven2-depmap.xml"); + + String customFileName = System.getProperty("maven2.jpp.depmap.file", + null); + if (customFileName != null) { + debug("Processing file: " + customFileName); + processDepmapFile(customFileName); + } + } + + private static void processDepmapFile(String fileName) { + + Document mapDocument; + debug("Loading depmap file: " + fileName); + try { + DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); + fact.setNamespaceAware(true); + DocumentBuilder builder = fact.newDocumentBuilder(); + mapDocument = builder.parse(fileName); + } catch (FileNotFoundException fnfe) { + System.err.println("ERROR: Unable to find map file: " + fileName); + fnfe.printStackTrace(); + return; + } catch (IOException ioe) { + System.err + .println("ERROR: I/O exception occured when opening map file"); + ioe.printStackTrace(); + return; + } catch (ParserConfigurationException pce) { + System.err + .println("ERROR: Parsing of depmap file failed - configuration"); + pce.printStackTrace(); + return; + } catch (SAXException se) { + System.err.println("ERROR: Parsing of depmap file failed"); + se.printStackTrace(); + return; + } + + NodeList depNodes = (NodeList) mapDocument + .getElementsByTagName("dependency"); + + for (int i = 0; i < depNodes.getLength(); i++) { + Element depNode = (Element) depNodes.item(i); + + NodeList mavenNodeList = (NodeList) depNode + .getElementsByTagName("maven"); + if (mavenNodeList.getLength() != 1) { + debug("Number of maven sub-elements is not 1. Bailing from depmap generation"); + debug("Maven node: " + depNode.getTextContent()); + return; + } + ArtifactDefinition mavenAD = getArtifactDefinition((Element) mavenNodeList + .item(0)); + + ArtifactDefinition jppAD = null; + NodeList jppNodeList = (NodeList) depNode + .getElementsByTagName("jpp"); + + if (jppNodeList.getLength() == 1) { + jppAD = getArtifactDefinition((Element) jppNodeList.item(0)); + if (System.getProperty("maven2.ignore.versions") == null + && System.getProperty("maven2.jpp.mode") == null) { + debug("*** Adding: " + mavenAD.groupId + "," + + mavenAD.artifactId + "," + mavenAD.version + + " => " + jppAD.groupId + "," + jppAD.artifactId + + "," + jppAD.version + " to map..."); + + jppArtifactMap.put(mavenAD.groupId + "," + + mavenAD.artifactId + "," + mavenAD.version, + jppAD.groupId + "," + jppAD.artifactId + "," + + jppAD.version); + } else { + debug("*** Adding: " + mavenAD.groupId + "," + + mavenAD.artifactId + " => " + jppAD.groupId + "," + + jppAD.artifactId + "," + jppAD.version + + " to map..."); + + jppArtifactMap.put(mavenAD.groupId + "," + + mavenAD.artifactId, jppAD.groupId + "," + + jppAD.artifactId + "," + jppAD.version); + } + } else { + debug("Number of jpp sub-elements is not 1. Dropping dependency"); + debug("*** Adding: " + mavenAD.groupId + "," + + mavenAD.artifactId + "," + " => " + + "JPP/maven2,empty-dep," + mavenAD.version + + " to map..."); + jppArtifactMap.put(mavenAD.groupId + "," + mavenAD.artifactId, + "JPP/maven2,empty-dep," + mavenAD.version); + } + } + } + + private static ArtifactDefinition getArtifactDefinition(Element element) { + ArtifactDefinition ad = new ArtifactDefinition(); + + NodeList nodes = element.getElementsByTagName("groupId"); + if (nodes.getLength() != 1) { + debug("groupId definition not found in depmap"); + return null; + } + ad.groupId = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("artifactId"); + if (nodes.getLength() != 1) { + debug("artifactId definition not found in depmap"); + return null; + } + ad.artifactId = nodes.item(0).getTextContent(); + + nodes = element.getElementsByTagName("version"); + if (nodes.getLength() != 1) { + ad.version = "DUMMY_VER"; + } else { + ad.version = nodes.item(0).getTextContent(); + } + return ad; + } + + public static void debug(String msg) { + if (System.getProperty("maven2.jpp.debug") != null) + System.err.println(msg); + } } diff --git a/src/main/java/org/apache/maven/artifact/resolver/JavadirWorkspaceReader.java b/src/main/java/org/apache/maven/artifact/resolver/JavadirWorkspaceReader.java index 81dc6b1..6e84735 100644 --- a/src/main/java/org/apache/maven/artifact/resolver/JavadirWorkspaceReader.java +++ b/src/main/java/org/apache/maven/artifact/resolver/JavadirWorkspaceReader.java @@ -11,16 +11,12 @@ import org.sonatype.aether.repository.WorkspaceReader; import org.sonatype.aether.repository.WorkspaceRepository; import org.sonatype.aether.artifact.Artifact; - -public class JavadirWorkspaceReader - implements WorkspaceReader -{ +public class JavadirWorkspaceReader implements WorkspaceReader { private WorkspaceRepository workspaceRepository; private static final char GROUP_SEPARATOR = '.'; private static final char PATH_SEPARATOR = '/'; - public JavadirWorkspaceReader() { workspaceRepository = new WorkspaceRepository("javadir-workspace"); } @@ -29,8 +25,9 @@ public class JavadirWorkspaceReader return workspaceRepository; } - public File findArtifact( Artifact artifact ) { - MavenJPackageDepmap.debug("=============JAVADIRREADER-FIND_ARTIFACT: " + artifact.getArtifactId()); + public File findArtifact(Artifact artifact) { + MavenJPackageDepmap.debug("=============JAVADIRREADER-FIND_ARTIFACT: " + + artifact.getArtifactId()); StringBuffer path = new StringBuffer(); String artifactId = artifact.getArtifactId(); @@ -39,10 +36,11 @@ public class JavadirWorkspaceReader MavenJPackageDepmap.debug("Wanted GROUPID=" + groupId); MavenJPackageDepmap.debug("Wanted ARTIFACTID=" + artifactId); - + if (!groupId.startsWith("JPP")) { MavenJPackageDepmap map = MavenJPackageDepmap.getInstance(); - Hashtable newInfo = map.getMappedInfo(groupId, artifactId, version); + Hashtable newInfo = map.getMappedInfo(groupId, + artifactId, version); groupId = (String) newInfo.get("group"); artifactId = (String) newInfo.get("artifact"); @@ -53,29 +51,30 @@ public class JavadirWorkspaceReader if (artifact.getExtension().equals("pom")) { path = getPOMPath(groupId, artifactId); } else if (artifact.getExtension().equals("signature")) { - path.append("/usr/share/maven/repository/"); - path.append( groupId ).append( '/' ); - path.append( artifactId ).append( ".signature" ); + path.append("/usr/share/maven/repository/"); + path.append(groupId).append('/'); + path.append(artifactId).append(".signature"); } else { - path.append("/usr/share/maven/repository/"); - path.append( groupId ).append( '/' ); - path.append( artifactId ).append( ".jar" ); + path.append("/usr/share/maven/repository/"); + path.append(groupId).append('/'); + path.append(artifactId).append(".jar"); } MavenJPackageDepmap.debug("Returning " + path.toString()); File ret = new File(path.toString()); // if file doesn't exist return null to delegate to other // resolvers (reactor/local repo) - if ( ret.isFile() ) { + if (ret.isFile()) { MavenJPackageDepmap.debug("Returning " + path.toString()); return ret; } else { - MavenJPackageDepmap.debug("Returning null for gid:aid" + groupId + ":" + artifactId); + MavenJPackageDepmap.debug("Returning null for gid:aid" + groupId + + ":" + artifactId); return null; } } - public List findVersions( Artifact artifact ) { + public List findVersions(Artifact artifact) { List ret = new LinkedList(); ret.add("latest"); return ret; @@ -84,19 +83,26 @@ public class JavadirWorkspaceReader private StringBuffer getPOMPath(String groupId, String artifactId) { StringBuffer path = new StringBuffer(); - String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-" + artifactId + ".pom"; - path.append(System.getProperty("maven.jpp.pom.path", "JPP/maven2/poms")).append("/").append(fName); + String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-" + + artifactId + ".pom"; + path.append(System.getProperty("maven.jpp.pom.path", "JPP/maven2/poms")) + .append("/").append(fName); java.io.File f; // NOTE: We are returning default_poms/ as the path for this pom // even though it may not exist there. This may cause an error, // but that is fine because if the pom is not there, there is // a serious problem anyways.. - f = new java.io.File(System.getProperty("maven.jpp.default.repo", "/usr/share/maven2/repository") + "/" + path.toString()); - //System.err.println("Checking path " + f.getAbsolutePath() + " for the pom"); + f = new java.io.File(System.getProperty("maven.jpp.default.repo", + "/usr/share/maven2/repository") + "/" + path.toString()); + // System.err.println("Checking path " + f.getAbsolutePath() + + // " for the pom"); if (!f.exists()) { path = new StringBuffer(); - path.append(System.getProperty("maven.jpp.default.pom.path", "JPP/maven2/default_poms")).append("/").append(fName); + path.append( + System.getProperty("maven.jpp.default.pom.path", + "JPP/maven2/default_poms")).append("/") + .append(fName); } path.insert(0, "/usr/share/maven2/repository/"); return path; -- cgit