summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Räty <betelgeuse@gentoo.org>2008-07-18 22:06:05 +0000
committerPetteri Räty <betelgeuse@gentoo.org>2008-07-18 22:06:05 +0000
commit8d3c0d96f9f22407ce55997d72edc7273d0743a6 (patch)
tree791cf582364871e832b02b81cc4f5af97bd07662 /dev-java/java-dep-check
parentzlib support wasn't being built so the jzlib dependency was useless. Now it's... (diff)
downloadgentoo-2-8d3c0d96f9f22407ce55997d72edc7273d0743a6.tar.gz
gentoo-2-8d3c0d96f9f22407ce55997d72edc7273d0743a6.tar.bz2
gentoo-2-8d3c0d96f9f22407ce55997d72edc7273d0743a6.zip
Initial addition. Ebuild and Java code written by me.
(Portage version: 2.2_rc1/cvs/Linux 2.6.25-gentoo-r5 i686)
Diffstat (limited to 'dev-java/java-dep-check')
-rw-r--r--dev-java/java-dep-check/ChangeLog10
-rw-r--r--dev-java/java-dep-check/Manifest4
-rw-r--r--dev-java/java-dep-check/files/Main.java233
-rw-r--r--dev-java/java-dep-check/java-dep-check-0.1.ebuild36
-rw-r--r--dev-java/java-dep-check/metadata.xml10
5 files changed, 293 insertions, 0 deletions
diff --git a/dev-java/java-dep-check/ChangeLog b/dev-java/java-dep-check/ChangeLog
new file mode 100644
index 000000000000..a432fdfa2bb4
--- /dev/null
+++ b/dev-java/java-dep-check/ChangeLog
@@ -0,0 +1,10 @@
+# ChangeLog for dev-java/java-dep-check
+# Copyright 1999-2008 Gentoo Foundation; Distributed under the GPL v2
+# $Header: /var/cvsroot/gentoo-x86/dev-java/java-dep-check/ChangeLog,v 1.1 2008/07/18 22:06:04 betelgeuse Exp $
+
+*java-dep-check-0.1 (18 Jul 2008)
+
+ 18 Jul 2008; Petteri Räty <betelgeuse@gentoo.org> +files/Main.java,
+ +metadata.xml, +java-dep-check-0.1.ebuild:
+ Initial addition. Ebuild and Java code written by me.
+
diff --git a/dev-java/java-dep-check/Manifest b/dev-java/java-dep-check/Manifest
new file mode 100644
index 000000000000..5ef42b041b1e
--- /dev/null
+++ b/dev-java/java-dep-check/Manifest
@@ -0,0 +1,4 @@
+AUX Main.java 8393 RMD160 d4d43e3329f464c99aa233dfdb25e0567f21b83a SHA1 cc4e220f7ad4649f73e4767e2652fc3a08f2e10e SHA256 18da5060b23e74cb0abfa2561902b2c2c303150bcc28fda792dbcce3ec6ba043
+EBUILD java-dep-check-0.1.ebuild 715 RMD160 9b5b846d1f77a5e3a12767d2be14d38958eef6f0 SHA1 ba95c4a5420354f77193d533318db4879f32feaa SHA256 d0264f11f1dac8ae282e316d242b957b0901c354922df8e067a4d132ce6fa920
+MISC ChangeLog 332 RMD160 6346fd061d602fb1d9ee04b0beda94418206458d SHA1 d07f373e63b8308260d96fc3ded662c64a277bea SHA256 9f3fa485c9957bb0a9d224a435384f0fe1e21422083daf4c5a38e32dd59b62ab
+MISC metadata.xml 256 RMD160 dfdc09715c1faf5d0d0bfdc0d54f876cb18c2b36 SHA1 fc5c2378337d4748e0080ee9befda80ace8dd520 SHA256 e8300b6a21e079063340d3773537dbe70a8591a0033946f407b18d801b3cb953
diff --git a/dev-java/java-dep-check/files/Main.java b/dev-java/java-dep-check/files/Main.java
new file mode 100644
index 000000000000..a057b3577ae5
--- /dev/null
+++ b/dev-java/java-dep-check/files/Main.java
@@ -0,0 +1,233 @@
+/*
+ * Main.java The main application class.
+ *
+ * Created on May 1, 2007, 6:32 PM
+ *
+ * Copyright (C) 2007,2008 Petteri Räty <betelgeuse@gentoo.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package javadepchecker;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.bcel.classfile.ClassParser;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.bcel.classfile.ConstantClass;
+import org.apache.bcel.classfile.ConstantPool;
+import org.apache.bcel.classfile.DescendingVisitor;
+import org.apache.bcel.classfile.EmptyVisitor;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+
+/**
+ *
+ * @author betelgeuse
+ */
+public final class Main extends EmptyVisitor {
+
+ static private String image = "";
+ private ConstantPool pool;
+ private TreeSet<String> deps = new TreeSet<String>();
+ private HashSet<String> current = new HashSet<String>();
+
+ /** Creates a new instance of Main */
+ public Main() {
+ }
+
+ private static Collection<String> getPackageJars(String pkg) {
+ ArrayList<String> jars = new ArrayList<String>();
+ try {
+ Process p = Runtime.getRuntime().exec("java-config -p " + pkg);
+ p.waitFor();
+ BufferedReader in;
+ in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String output = in.readLine();
+ if (!output.trim().equals("")) {
+ for (String jar : output.split(":")) {
+ jars.add(jar);
+ }
+ }
+ } catch (InterruptedException ex) {
+ Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return jars;
+ }
+
+ public void processJar(JarFile jar) throws IOException {
+ for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
+ JarEntry entry = e.nextElement();
+ String name = entry.getName();
+ if (!entry.isDirectory() && name.endsWith(".class")) {
+ this.current.add(name);
+ InputStream stream = jar.getInputStream(entry);
+ ClassParser parser = new ClassParser(stream, name);
+ JavaClass jclass = parser.parse();
+ this.pool = jclass.getConstantPool();
+ new DescendingVisitor(jclass, this).visitConstantPool(this.pool);
+ }
+ }
+ }
+
+ private static boolean depNeeded(String pkg, Collection<String> deps) throws IOException {
+ for (String jarName : getPackageJars(pkg)) {
+ JarFile jar = new JarFile(jarName);
+ for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
+ String name = e.nextElement().getName();
+ if (deps.contains(name)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean checkPkg(File env) {
+ boolean needed = true;
+ HashSet<String> pkgs = new HashSet<String>();
+ Collection<String> deps = null;
+
+ BufferedReader in = null;
+ try {
+ Pattern dep_re = Pattern.compile("^DEPEND=\"([^\"]*)\"$");
+ Pattern cp_re = Pattern.compile("^CLASSPATH=\"([^\"]*)\"$");
+
+ String line;
+ in = new BufferedReader(new FileReader(env));
+ while ((line = in.readLine()) != null) {
+ Matcher m = dep_re.matcher(line);
+ if (m.matches()) {
+ String atoms = m.group(1);
+ for (String atom : atoms.split(":")) {
+ String pkg = atom;
+ if (atom.contains("@")) {
+ pkg = atom.split("@")[1];
+ }
+ pkgs.add(pkg);
+ }
+ continue;
+ }
+ m = cp_re.matcher(line);
+ if (m.matches()) {
+ Main classParser = new Main();
+ for (String jar : m.group(1).split(":")) {
+ classParser.processJar(new JarFile(image + jar));
+ }
+ deps = classParser.getDeps();
+ }
+ }
+
+ for (String pkg : pkgs) {
+ if (!depNeeded(pkg, deps)) {
+ System.out.println(pkg);
+ needed = false;
+ }
+ }
+ } catch (IOException ex) {
+ Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ex) {
+ Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ return needed;
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) throws IOException {
+ int exit = 0;
+ try {
+ CommandLineParser parser = new PosixParser();
+ Options options = new Options();
+ options.addOption("h", "help", false, "print help");
+ options.addOption("i", "image", true, "image directory");
+ options.addOption("v","verbose", false, "print verbose output");
+ CommandLine line = parser.parse(options, args);
+ String[] files = line.getArgs();
+ if (line.hasOption("h") || files.length == 0) {
+ HelpFormatter h = new HelpFormatter();
+ h.printHelp("java-dep-check [-i <image] <package.env>+", options);
+ } else {
+ image = line.getOptionValue("i", "");
+
+ for (String arg : files) {
+ if(line.hasOption('v'))
+ System.out.println("Checking " + arg);
+ if (!checkPkg(new File(arg))) {
+ exit = 1;
+ }
+ }
+ }
+ } catch (ParseException ex) {
+ Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ System.exit(exit);
+ }
+
+ /**
+ * Find referenced class from signature if the signature is for a array
+ * type.
+ * @see http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html
+ */
+ private String stripArray(String signature) {
+ String[] result = signature.split("^\\[+L");
+ if (result.length == 2) {
+ return result[1].substring(0, result[1].length() - 1);
+ } else {
+ return signature;
+ }
+ }
+
+ @Override
+ public void visitConstantClass(ConstantClass obj) {
+ String className = obj.getBytes(pool);
+ deps.add(stripArray(className) + ".class");
+ }
+
+ private Collection<String> getDeps() {
+ ArrayList<String> result = new ArrayList<String>();
+ for (String s : deps) {
+ if (!current.contains(s)) {
+ result.add(s);
+ }
+ }
+ return result;
+ }
+}
diff --git a/dev-java/java-dep-check/java-dep-check-0.1.ebuild b/dev-java/java-dep-check/java-dep-check-0.1.ebuild
new file mode 100644
index 000000000000..e4b520eacdab
--- /dev/null
+++ b/dev-java/java-dep-check/java-dep-check-0.1.ebuild
@@ -0,0 +1,36 @@
+# Copyright 1999-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-java/java-dep-check/java-dep-check-0.1.ebuild,v 1.1 2008/07/18 22:06:04 betelgeuse Exp $
+
+EAPI=1
+
+inherit java-pkg-2
+
+DESCRIPTION="Java Dependency checker"
+HOMEPAGE="http://www.gentoo.org/proj/en/java"
+SRC_URI=""
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~x86"
+
+IUSE=""
+
+COMMON_DEP="
+ dev-java/bcel:0
+ dev-java/commons-cli:1"
+RDEPEND=">=virtual/jre-1.5
+ ${COMMON_DEP}"
+DEPEND=">=virtual/jdk-1.5
+ ${COMMON_DEP}"
+
+src_compile() {
+ ejavac -cp $(java-pkg_getjars bcel,commons-cli-1) -encoding UTF-8 -d . \
+ "${FILESDIR}/Main.java"
+ jar cf ${PN}.jar javadepchecker/*.class || die "jar failed"
+}
+
+src_install() {
+ java-pkg_dojar ${PN}.jar
+ java-pkg_dolauncher ${PN} --main javadepchecker.Main
+}
diff --git a/dev-java/java-dep-check/metadata.xml b/dev-java/java-dep-check/metadata.xml
new file mode 100644
index 000000000000..e8514d3973a6
--- /dev/null
+++ b/dev-java/java-dep-check/metadata.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <herd>java</herd>
+
+ <maintainer>
+ <email>betelgeuse@gentoo.org</email>
+ <name>Petteri Räty</name>
+ </maintainer>
+</pkgmetadata>