geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hogst...@apache.org
Subject svn commit: r409174 - in /geronimo/sandbox/contrib/releasetools: ./ trunk/ trunk/src/ trunk/src/i-p/ trunk/src/java/ trunk/src/java/org/ trunk/src/java/org/apache/ trunk/src/java/org/apache/geroinimo/ trunk/src/java/org/apache/geroinimo/releasetools/ t...
Date Wed, 24 May 2006 14:22:02 GMT
Author: hogstrom
Date: Wed May 24 07:22:02 2006
New Revision: 409174

URL: http://svn.apache.org/viewvc?rev=409174&view=rev
Log:
Version Verifier searches Geronimo Tree and extracts package dependencies

Added:
    geronimo/sandbox/contrib/releasetools/
    geronimo/sandbox/contrib/releasetools/trunk/
    geronimo/sandbox/contrib/releasetools/trunk/src/
    geronimo/sandbox/contrib/releasetools/trunk/src/i-p/
    geronimo/sandbox/contrib/releasetools/trunk/src/java/
    geronimo/sandbox/contrib/releasetools/trunk/src/java/org/
    geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/
    geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/
    geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/releasetools/
    geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/releasetools/VersionVerifier.java
    geronimo/sandbox/contrib/releasetools/trunk/target/
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier$Dependency.class
  (with props)
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier$MavenXMLHandler.class
  (with props)
    geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier.class
  (with props)

Added: geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/releasetools/VersionVerifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/releasetools/VersionVerifier.java?rev=409174&view=auto
==============================================================================
--- geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/releasetools/VersionVerifier.java
(added)
+++ geronimo/sandbox/contrib/releasetools/trunk/src/java/org/apache/geroinimo/releasetools/VersionVerifier.java
Wed May 24 07:22:02 2006
@@ -0,0 +1,346 @@
+/**
+ *
+ * Copyright 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.
+ */
+
+package org.apache.geronimo.releasetools;
+
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class VersionVerifier {
+
+	File geronimoRoot = null;
+	static Properties p = null;
+	ArrayList projectXmls = null;
+	Dependency currentDependency = null;
+	ArrayList dependencyList = null;
+	boolean processingGroup = false;
+	boolean processingArtifact = false;
+	boolean processingVersion = false;
+	String currentXML = null;
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		VersionVerifier v = null;
+		v = new VersionVerifier();
+
+		v.init(args);
+		v.processProjectXMLs();
+		for (int x = 0; x < v.dependencyList.size(); x++) {
+			v.getJarInfo((Dependency)v.dependencyList.get(x));
+		}
+	}
+
+	private void processProjectXMLs() {
+		File cFile = null;
+		for (int x = 0; x < projectXmls.size(); x++) {
+			InputSource in = null;
+			try {
+				cFile = (File) projectXmls.get(x);
+				in = new InputSource(new FileInputStream(cFile));
+			} catch (FileNotFoundException e1) {
+				e1.printStackTrace();
+			}
+			DocumentBuilderFactory dfactory = DocumentBuilderFactory
+					.newInstance();
+			try {
+				Document doc = dfactory.newDocumentBuilder().parse(in);
+				Element root = doc.getDocumentElement();
+				NodeList configs = root.getElementsByTagName("dependency");
+				for (int i = 0; i < configs.getLength(); i++) {
+					Element dependencyElement = (Element) configs.item(i);
+					String project = cFile.getCanonicalPath();
+					String groupId = getString(dependencyElement, "groupId");
+					String artifactId = getString(dependencyElement, "artifactId");
+					String version = resolveVersion(getString( dependencyElement, "version"));
+					String type = getString(dependencyElement, "type");
+					if (type == null) {
+						type = "jar";
+					}
+					dependencyList.add(new Dependency(project,
+							groupId, artifactId, version, type));
+				}
+			} catch (IOException e) {
+				throw (IllegalStateException) new IllegalStateException(
+						"Unable to parse  file in "+cFile.getAbsoluteFile());
+			} catch (ParserConfigurationException e) {
+				throw (IllegalStateException) new IllegalStateException(
+						"Unable to parse  file in "+cFile.getAbsoluteFile());
+			} catch (SAXException e) {
+				throw (IllegalStateException) new IllegalStateException(
+						"Unable to parse  file in "+cFile.getAbsoluteFile());
+			}
+
+		}
+	}
+
+	/*
+	 * Resolves versions. I took the naive view that I took was that
+	 * ${pom.currentVersion} resolves to the Geronimo current version. This
+	 * should be fixed.
+	 */
+	private String resolveVersion(String version) {
+		if (!version.startsWith("${"))
+			return version;
+		if (version.startsWith("${pom.currentVersion}"))
+			return (String) p.get("geronimo_version");
+		String v = (String) p.get(version.substring(2, version.length() - 1));
+		if (v == null)
+			return version;
+		else
+			return v;
+	}
+
+	private String getString(Element dependencyElement, String childName) {
+		NodeList children = dependencyElement.getElementsByTagName(childName);
+		if (children == null || children.getLength() == 0) {
+			return null;
+		}
+		String value = "";
+		NodeList text = children.item(0).getChildNodes();
+		for (int t = 0; t < text.getLength(); t++) {
+			Node n = text.item(t);
+			if (n.getNodeType() == Node.TEXT_NODE) {
+				value += n.getNodeValue();
+			}
+		}
+		return value.trim();
+	}
+
+	/*
+	 * Argument 0 is the Geronimo Tree name to check versions on.
+	 */
+	private boolean init(String[] args) {
+		geronimoRoot = new File(args[0]);
+		projectXmls = new ArrayList(500);
+		dependencyList = new ArrayList(500);
+
+		// Get our properties
+		if (geronimoRoot.exists()) {
+			File etcProperties = new File(geronimoRoot.getAbsolutePath()
+					+ "/etc/project.properties");
+			p = new Properties();
+			try {
+				p.load(new FileInputStream(etcProperties));
+			} catch (Exception e) {
+				System.err.println("Unable to open file.  Message is "
+						+ e.getMessage());
+			}
+			getProjectXmlFiles(geronimoRoot);
+		}
+		return true;
+	}
+
+	// After this routeine returns we have a list of all project.xml files in
+	// the
+	// Geronimo Tree in the ArrayList projectXmls.
+	private void getProjectXmlFiles(File geronimoRoot) {
+		// get Module list
+		searchDirs(geronimoRoot);
+		// searchDirs(new File(geronimoRoot.getAbsoluteFile() + "/configs"));
+		for (int x = 0; x < projectXmls.size(); x++) {
+			System.out.println(((File) projectXmls.get(x)).getAbsolutePath());
+		}
+	}
+
+	private void searchDirs(File dirName) {
+		if (dirName.isDirectory()) {
+			// So far so good
+			File[] modList = dirName.listFiles();
+			for (int x = 0; x < modList.length; x++) {
+				File pFile = new File(modList[x].getAbsoluteFile()
+						+ "/project.xml");
+				if (pFile.exists() && pFile.isFile()) {
+					projectXmls.add(pFile);
+				} else {
+					if (modList[x].isDirectory())
+						searchDirs(modList[x]);
+				}
+			}
+		}
+	}
+
+	// Lifted this from org.apache.geronimo.system.repository.Maven1Repository (originally from
Brett Porter)
+	private static final Pattern MAVEN_1_PATTERN = Pattern.compile("(.+)-([0-9].+)\\.*");
+	
+	private String[] getJarInfo(Dependency dependency) {
+		String mavenSiteUrl = "http://www.ibiblio.com/maven/";
+		URL compositeUrl = null;
+		String url = mavenSiteUrl;
+		Pattern aRefPattern = Pattern.compile("<A HREF=\".*\">", 	Pattern.CASE_INSENSITIVE);
+		Pattern artifactPattern = Pattern.compile("</A>.*", 	Pattern.CASE_INSENSITIVE);
+
+		try {
+			url += dependency.groupId + "/" + dependency.type + "s";
+			compositeUrl = new URL(url);
+		} catch (MalformedURLException e) {
+			System.out.println("Maven Site URL of: " + url);
+		}
+		URLConnection conn = null;
+		DataInputStream data = null;
+		String line;
+		StringBuffer buf = new StringBuffer();
+		try {
+			conn = compositeUrl.openConnection();
+			conn.connect();
+			System.out.println("Connection opened...");
+			data = new DataInputStream(new BufferedInputStream(conn
+					.getInputStream()));
+			
+			System.out.println("Reading data...");
+			while ((line = data.readLine()) != null) {
+				buf.append(line + "\n");
+			}
+		
+			String [] arefMatch = aRefPattern.split(buf);
+			
+			Matcher matcher = MAVEN_1_PATTERN.matcher("");
+			
+			for (int y=0; y< arefMatch.length; y++) {
+				if (arefMatch[y].startsWith(dependency.artifactId)) {
+					String [] t = artifactPattern.split(arefMatch[y]);
+					if (t[0].endsWith("sha1") || t[0].endsWith("md5") || t[0].endsWith("asc")) continue;
+					System.out.println(t[0]);
+					matcher.reset(t[0]);
+		             if (matcher.matches() && matcher.group(1).equals(dependency.artifactId))
{
+		            	     String m = matcher.group(2);
+		            	     for (int z=m.length()-1; z>0; z--) {
+		            	    	   if (m.charAt(z) == '.') { 
+		            	    		   m = m.substring(0,z);
+		            	    		   break;
+		            	    	   }
+		            	     }
+		            	     System.out.println(m);
+		             }
+				}
+			}
+			System.out.println();
+			data.close();
+		} catch (IOException e) {
+			System.out.println("IO Error:" + e.getMessage());
+		}
+		return new String[3];
+	}
+
+
+	class MavenXMLHandler extends DefaultHandler {
+		public void startDocument() throws SAXException {
+		}
+
+		public void startElement(String namespaceURI, String sName,
+				String qName, Attributes attrs) throws SAXException {
+			String eName = sName; // element name
+
+			if ("".equals(eName))
+				eName = qName; // namespaceAware = false
+
+			if (eName.equals("dependency")) {
+				if (currentDependency != null) {
+					dependencyList.add(currentDependency);
+				}
+				currentDependency = new Dependency();
+			}
+
+			if (eName.equals("groupId")) {
+				processingGroup = true;
+				return;
+			}
+			if (eName.equals("artifactId")) {
+				processingArtifact = true;
+				return;
+			}
+			if (eName.equals("version")) {
+				processingVersion = true;
+				return;
+			}
+		}
+
+		public void characters(char buf[], int offset, int len)
+				throws SAXException {
+			String s = new String(buf, offset, len);
+			if (processingGroup)
+				currentDependency.groupId = s;
+			if (processingArtifact)
+				currentDependency.artifactId = s;
+			if (processingVersion) {
+				if (s != null && s.startsWith("${") && s.length() > 3) {
+					if (s.equals("${pom.currentVersion}"))
+						s = "${geronimo_version}";
+					// System.out.println(currentXML+"
+					// "+s+"="+s.substring(2,s.length()-1)+"="+p.getProperty(s.substring(2,s.length()-1)));
+					currentDependency.version = p.getProperty(s.substring(2, s
+							.length() - 1));
+					// if (currentDependency.version == null)
+					// System.out.println("Version = \""+s+"\"");
+				} else {
+					currentDependency.version = s;
+				}
+			}
+			processingGroup = false;
+			processingArtifact = false;
+			processingVersion = false;
+		}
+
+		public void endDocument() throws SAXException {
+		}
+	}
+
+	class Dependency {
+		String groupId = null;
+		String artifactId = null;
+		String version = null;
+		String type = null;
+		String project = null;
+
+		Dependency() {
+		}
+
+		Dependency(String project, String groupId,
+				String artifactId, String version, String type) {
+			this.project = project;
+			this.groupId = groupId;
+			this.artifactId = artifactId;
+			this.version = version;
+			this.type = type;
+		}
+	}
+
+}

Added: geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier$Dependency.class
URL: http://svn.apache.org/viewvc/geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier%24Dependency.class?rev=409174&view=auto
==============================================================================
Binary file - no diff available.

Propchange: geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier$Dependency.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier$MavenXMLHandler.class
URL: http://svn.apache.org/viewvc/geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier%24MavenXMLHandler.class?rev=409174&view=auto
==============================================================================
Binary file - no diff available.

Propchange: geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier$MavenXMLHandler.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier.class
URL: http://svn.apache.org/viewvc/geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier.class?rev=409174&view=auto
==============================================================================
Binary file - no diff available.

Propchange: geronimo/sandbox/contrib/releasetools/trunk/target/classes/org/apache/geronimo/releasetools/VersionVerifier.class
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message