Author: pawelz Date: Thu Apr 29 13:31:43 2010 GMT Module: packages Tag: JPACKAGE ---- Log message: - raw files from JPP
---- Files affected: packages/maven: maven-JPackageRepositoryLayout.java (NONE -> 1.1.2.1) (NEW), maven-MavenJPackageDepmap.java (NONE -> 1.1.2.1) (NEW), maven-jpp-script (NONE -> 1.1.2.1) (NEW) ---- Diffs: ================================================================ Index: packages/maven/maven-JPackageRepositoryLayout.java diff -u /dev/null packages/maven/maven-JPackageRepositoryLayout.java:1.1.2.1 --- /dev/null Thu Apr 29 15:31:43 2010 +++ packages/maven/maven-JPackageRepositoryLayout.java Thu Apr 29 15:31:38 2010 @@ -0,0 +1,140 @@ +package org.apache.maven.artifact.repository.layout; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.xml.sax.InputSource; + +/** + * Repository layout for jpackage based repositories. + * This class resolves items for jpp style repos (i.e things located in + * /usr/share/java). + */ + +public class JPackageRepositoryLayout + implements ArtifactRepositoryLayout +{ + private static Hashtable jppArtifactMap; + + private static final char GROUP_SEPARATOR = '.'; + private static final char PATH_SEPARATOR = '/'; + + public String pathOf( Artifact artifact ) + { + + ArtifactHandler artifactHandler = artifact.getArtifactHandler(); + StringBuffer path = new StringBuffer(); + + String artifactId = artifact.getArtifactId(); + String groupId = artifact.getGroupId(); + String version = artifact.getVersion(); + String classifierSuffix = (artifact.getClassifier() == null || artifact.getClassifier() == "") ? + "" : "-" + artifact.getClassifier(); + + if (!groupId.startsWith("JPP")) { + MavenJPackageDepmap map = MavenJPackageDepmap.getInstance(); + Hashtable newInfo = map.getMappedInfo(groupId, artifactId, version); + + groupId = (String) newInfo.get("group"); + artifactId = (String) newInfo.get("artifact"); + } + + if (groupId.startsWith("JPP")) { + if (artifactHandler.getPackaging().equals("pom")) { + path = getPOMPath(groupId, artifactId); + + } else { // Assume if it is not pom it is jar + // as "maven-plugin" type is a JAR + path.append( groupId ).append( '/' ); + path.append( artifactId ).append(classifierSuffix).append( "." + artifactHandler.getExtension()); + } + } else { + path.append( groupId.replace(GROUP_SEPARATOR, PATH_SEPARATOR) ).append( '/' ).append( artifactId ).append( '/' ).append( version ).append( '/' ); + path.append( artifactId ).append( '-' ).append( version ).append( "." ); + // Parent poms may come with type "xml" + if (artifactHandler.getPackaging().equals("xml")) { + path.append( "pom" ); + } else { + path.append( artifactHandler.getPackaging() ); + } + } + + return path.toString(); + } + + 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("maven2.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("maven2.jpp.default.repo", "/usr/share/maven2/repository") + "/" + path.toString()); + System.err.println("Checking path " + f.getAbsolutePath() + " for the pom"); + if (!f.exists()) { + System.err.println(f.getAbsolutePath() + " not found"); + path = new StringBuffer(); + path.append(System.getProperty("maven2.jpp.default.pom.path", "JPP/maven2/default_poms")).append("/").append(fName); + } + + return path; + } + + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) + { + return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) ); + } + + private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename ) + { + + StringBuffer path = new StringBuffer(); + + if (filename.substring(filename.length()-4).equals(".pom")) { + path = getPOMPath(metadata.getGroupId(), metadata.getArtifactId()); + } else { + + // FIXME: If it gets here, something other than a pom was requested.. where are those things located? + path.append(System.getProperty("maven2.jpp.pom.path", "maven2/poms")).append("/").append(filename); + } + + return path.toString(); + } + + public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) + { + return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() ); + } +} ================================================================ Index: packages/maven/maven-MavenJPackageDepmap.java diff -u /dev/null packages/maven/maven-MavenJPackageDepmap.java:1.1.2.1 --- /dev/null Thu Apr 29 15:31:43 2010 +++ packages/maven/maven-MavenJPackageDepmap.java Thu Apr 29 15:31:38 2010 @@ -0,0 +1,162 @@ +package org.apache.maven.artifact.repository.layout; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.xml.sax.InputSource; + +public class MavenJPackageDepmap { + + 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) { + //System.err.println("Processing file: /usr/share/java-utils/xml/maven2-versionless-depmap.xml"); + processDepmapFile("/etc/maven/maven2-versionless-depmap.xml"); + } + + //System.err.println("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) { + //System.err.println("Processing file: " + customFileName); + processDepmapFile(customFileName); + } + } + + private static void processDepmapFile(String fileName) { + + Document mapDocument; + + try { + mapDocument = (new SAXBuilder()).build(new InputSource(new FileInputStream(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 (JDOMException jde) { + System.err.println("ERROR: Unable to instantiate parser"); + jde.printStackTrace(); + return; + } + + List l = mapDocument.getRootElement().getChildren("dependency"); + + Iterator i = l.iterator(); + while (i.hasNext()) { + Element depElement = (Element) i.next(); + + Element mElem = depElement.getChild("maven"); + Element jppElem = depElement.getChild("jpp"); + + String mG = mElem.getChildText("groupId"); + String mA = mElem.getChildText("artifactId"); + String mV = mElem.getChildText("version"); + + // jppElem == null => drop this dependency + if (jppElem != null) { + + String jppG = jppElem.getChildText("groupId"); + String jppA = jppElem.getChildText("artifactId"); + String jppV = jppElem.getChildText("version"); + jppV = jppV != null && jppV.length() > 0 ? jppV : mV; + + if (System.getProperty("maven2.ignore.versions") == null && System.getProperty("maven2.jpp.mode") == null) { + //System.err.println("*** Adding: " + mG+","+mA+","+mV + " => " + jppG+","+jppA+","+jppV + " to map..."); + jppArtifactMap.put(mG+","+mA+","+mV, jppG+","+jppA+","+jppV); + } else { + //System.err.println("*** Adding: " + mG+","+mA + " => " + jppG+","+jppA+","+jppV + " to map..."); + jppArtifactMap.put(mG+","+mA, jppG+","+jppA+","+jppV); + } + } else { + //System.err.println("*** Adding: " + mG+","+mA+"," + " => " + "JPP/maven2,empty-dep,"+mV + " to map..."); + jppArtifactMap.put(mG+","+mA, "JPP/maven2,empty-dep,"+mV); + } + } + } +} ================================================================ Index: packages/maven/maven-jpp-script diff -u /dev/null packages/maven/maven-jpp-script:1.1.2.1 --- /dev/null Thu Apr 29 15:31:43 2010 +++ packages/maven/maven-jpp-script Thu Apr 29 15:31:38 2010 @@ -0,0 +1,10 @@ +#!/bin/sh +if [ -f /usr/share/java-utils/java-functions ] ; then + . /usr/share/java-utils/java-functions + set_jvm + set_javacmd +fi + +export M2_HOME=/usr/share/maven2 +echo $JAVA_HOME +export JAVA_HOME; $M2_HOME/bin/mvn -Dmaven2.offline.mode -Dmaven2.ignore.versions -Dmaven2.usejppjars $@ ================================================================ _______________________________________________ pld-cvs-commit mailing list [email protected] http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit
