summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerkan Kaba <serkan@gentoo.org>2009-01-28 20:06:39 +0000
committerSerkan Kaba <serkan@gentoo.org>2009-01-28 20:06:39 +0000
commit0c14339c331c10b28652474312217275ff64b667 (patch)
tree08903b797ded122530f711e6332584641194fcbb /dev-java
parentAdd support for the upcoming java-dep-check. (diff)
downloadhistorical-0c14339c331c10b28652474312217275ff64b667.tar.gz
historical-0c14339c331c10b28652474312217275ff64b667.tar.bz2
historical-0c14339c331c10b28652474312217275ff64b667.zip
Version bump to report classes not found via DEPEND in package.env
Package-Manager: portage-2.2_rc23/cvs/Linux x86_64
Diffstat (limited to 'dev-java')
-rw-r--r--dev-java/java-dep-check/ChangeLog10
-rw-r--r--dev-java/java-dep-check/Manifest10
-rw-r--r--dev-java/java-dep-check/files/Main-0.3.java335
-rw-r--r--dev-java/java-dep-check/java-dep-check-0.3.ebuild40
4 files changed, 389 insertions, 6 deletions
diff --git a/dev-java/java-dep-check/ChangeLog b/dev-java/java-dep-check/ChangeLog
index 0843515450fd..28eadab2d0ca 100644
--- a/dev-java/java-dep-check/ChangeLog
+++ b/dev-java/java-dep-check/ChangeLog
@@ -1,6 +1,12 @@
# 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.3 2008/10/05 10:36:19 betelgeuse Exp $
+# Copyright 1999-2009 Gentoo Foundation; Distributed under the GPL v2
+# $Header: /var/cvsroot/gentoo-x86/dev-java/java-dep-check/ChangeLog,v 1.4 2009/01/28 20:06:39 serkan Exp $
+
+*java-dep-check-0.3 (28 Jan 2009)
+
+ 28 Jan 2009; Serkan Kaba <serkan@gentoo.org> +files/Main-0.3.java,
+ +java-dep-check-0.3.ebuild:
+ Version bump to report classes not found via DEPEND in package.env
*java-dep-check-0.2 (05 Oct 2008)
diff --git a/dev-java/java-dep-check/Manifest b/dev-java/java-dep-check/Manifest
index 8489122d45a5..c7297713fa7d 100644
--- a/dev-java/java-dep-check/Manifest
+++ b/dev-java/java-dep-check/Manifest
@@ -2,15 +2,17 @@
Hash: SHA1
AUX Main-0.2.java 9650 RMD160 b08e72be719dd996780eb26aeed70f659f91f7d5 SHA1 5b4a1a73a1716cc30aa11f4f36a4d4c06b833a0b SHA256 22d6cb62f53d0e009dbc1ae941994ffcd205c630ee26f5b8400619340f850d20
+AUX Main-0.3.java 11702 RMD160 755b8ce93edeef72ad03ce8582150f0e62b6dab9 SHA1 89b3411b4ced93946349fe916d2ee53e57728908 SHA256 c74c45307ef58b3575cdb58de83dd488d98b9229d03ff8276775d1e6e967072f
AUX Main.java 8393 RMD160 d4d43e3329f464c99aa233dfdb25e0567f21b83a SHA1 cc4e220f7ad4649f73e4767e2652fc3a08f2e10e SHA256 18da5060b23e74cb0abfa2561902b2c2c303150bcc28fda792dbcce3ec6ba043
EBUILD java-dep-check-0.1.ebuild 833 RMD160 26bde239381a28020c2ae0f3449ae8e21f07d7d8 SHA1 dbeb36d1824e0d2b9155b361416e4d1f10e58738 SHA256 af41b2e8b877c80a81bb9a5c469a24313e9599a7276ab8745d7912b241369110
EBUILD java-dep-check-0.2.ebuild 903 RMD160 4696bc2494e57f756bad853c5a49ae7564af2d68 SHA1 f236ac7118fae50a52e7f8c983d4be78c33ca191 SHA256 beda7e09268b0fea338819d7d074b541ded942b44b4f759040c3977fa846b648
-MISC ChangeLog 789 RMD160 ded8413a03c901a46f92af3942dfe9ddc9c9225a SHA1 a2e9f2df812b214302a5006b905e5d361b15b1db SHA256 851673206118a368cb1f9e6e63e2cd45cff33cc1f843d0672174a6b8c9e4330a
+EBUILD java-dep-check-0.3.ebuild 899 RMD160 5c9b55d6f7c4c23f091a39bb05ff9b5964447466 SHA1 682f8d98d7d4a4cc37ba9192fdef44f01cfa676e SHA256 62912be8cf5f9fe4cf0ad8f41673920a98d49bc40def17b25b693f6eb332aca5
+MISC ChangeLog 989 RMD160 f459201fa1fa53c6948b815c717a0fd63dd856bd SHA1 73081f3ea284c13839f17f2d249c4e5649d4ccbf SHA256 d7a7d95e7ebe558c1f9306f1f5c74fd41486c1a2d7ed5219fe008146ce3f9669
MISC metadata.xml 256 RMD160 dfdc09715c1faf5d0d0bfdc0d54f876cb18c2b36 SHA1 fc5c2378337d4748e0080ee9befda80ace8dd520 SHA256 e8300b6a21e079063340d3773537dbe70a8591a0033946f407b18d801b3cb953
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
-iEYEARECAAYFAkjomK0ACgkQcxLzpIGCsLQtvgCggEUGCaLmiUQCd69hnnM86qSD
-kKIAmwUSfWyiYVv+zo+iiWo/+n0S++9S
-=qxyE
+iEYEARECAAYFAkmAutUACgkQRh6X64ivZaLezwCfe6kEXIr9lsMl1JZYfWZEMGeG
+vSUAn1g+VUBm8gehbhCpQ5qgrHPqzHP1
+=NTrL
-----END PGP SIGNATURE-----
diff --git a/dev-java/java-dep-check/files/Main-0.3.java b/dev-java/java-dep-check/files/Main-0.3.java
new file mode 100644
index 000000000000..e1f02a024eef
--- /dev/null
+++ b/dev-java/java-dep-check/files/Main-0.3.java
@@ -0,0 +1,335 @@
+/*
+ * 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.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.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+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;
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.commons.EmptyVisitor;
+
+/**
+ *
+ * @author betelgeuse
+ * @author serkan
+ */
+public final class Main extends EmptyVisitor {
+
+ static private String image = "";
+ private Set<String> deps = new HashSet<String>();
+ private Set<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!=null/* package somehow missing*/ && !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);
+ new ClassReader(stream).accept(this, 0);
+ }
+ }
+ }
+
+ private static boolean depNeeded(String pkg, Collection<String> deps) throws IOException {
+ Collection<String> jars = getPackageJars(pkg);
+ // We have a virtual with VM provider here
+ if (jars.size() == 0) {
+ return true;
+ }
+ for (String jarName : jars) {
+ 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 depsFound(Collection<String> pkgs, Collection<String> deps) throws IOException {
+ boolean found = true;
+ Collection<String> jars = new ArrayList<String>();
+ String[] bootClassPathJars = System.getProperty("sun.boot.class.path").split(":");
+ // Do we need "java-config -r" here?
+ for (String jar : bootClassPathJars) {
+ File jarFile = new File(jar);
+ if (jarFile.exists()) {
+ jars.add(jar);
+ }
+ }
+ for (Iterator<String> pkg = pkgs.iterator(); pkg.hasNext();) {
+ jars.addAll(getPackageJars(pkg.next()));
+ }
+
+ if (jars.size() == 0) {
+ return false;
+ }
+ ArrayList<String> jarClasses = new ArrayList<String>();
+ for (String jarName : jars) {
+ JarFile jar = new JarFile(jarName);
+ for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
+ jarClasses.add(e.nextElement().getName());
+ }
+ }
+ for (String dep : deps) {
+ if (!jarClasses.contains(dep)) {
+ if (found) {
+ System.out.println("Class files not found via DEPEND in package.env");
+ }
+ System.out.println("\t" + dep);
+ found = false;
+ }
+ }
+ return found;
+ }
+
+ private static boolean checkPkg(File env) {
+ boolean needed = true;
+ boolean found = 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(":")) {
+ if (jar.endsWith(".jar")) {
+ classParser.processJar(new JarFile(image + jar));
+ }
+ }
+ deps = classParser.getDeps();
+ }
+ }
+
+ for (String pkg : pkgs) {
+ if (!depNeeded(pkg, deps)) {
+ if (needed) {
+ System.out.println("Possibly unneeded dependencies found");
+ }
+ System.out.println("\t" + pkg);
+ needed = false;
+ }
+ }
+ found = depsFound(pkgs, deps);
+
+ } 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 && found;
+ }
+
+ /**
+ * @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);
+ }
+
+ private void addDep(String dep) {
+ deps.add(dep + ".class");
+ }
+
+ private void addDep(Type dep) {
+ if (dep.getSort() == Type.ARRAY) {
+ addDep(dep.getElementType());
+ }
+ if (dep.getSort() == Type.OBJECT) {
+ addDep(dep.getInternalName());
+ }
+ }
+
+ private Collection<String> getDeps() {
+ ArrayList<String> result = new ArrayList<String>();
+ for (String s : deps) {
+ if (!current.contains(s)) {
+ result.add(s);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
+ if(superName != null) {
+ addDep(superName);
+ }
+ for (String iface : interfaces) {
+ addDep(iface);
+ }
+ }
+
+ @Override
+ public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
+ addDep(Type.getType(desc));
+ return null;
+ }
+
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
+ for (Type param : Type.getArgumentTypes(desc)) {
+ addDep(param);
+ }
+
+ if (exceptions != null) {
+ for (String exception : exceptions) {
+ addDep(exception);
+ }
+ }
+ addDep(Type.getReturnType(desc));
+ return new EmptyVisitor() {
+ @Override
+ public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
+ addDep(Type.getType(desc));
+ }
+
+ @Override
+ public void visitFieldInsn(int opcode, String owner, String name, String desc) {
+ addDep(Type.getObjectType(owner));
+ addDep(Type.getType(desc));
+ }
+
+ @Override
+ public void visitMethodInsn(int opcode, String owner, String name, String desc) {
+ addDep(Type.getObjectType(owner));
+ }
+
+ @Override
+ public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
+ return Main.this.visitAnnotation(desc, visible);
+ }
+ };
+ }
+
+ @Override
+ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+ addDep(Type.getType(desc));
+ return null;
+ }
+}
diff --git a/dev-java/java-dep-check/java-dep-check-0.3.ebuild b/dev-java/java-dep-check/java-dep-check-0.3.ebuild
new file mode 100644
index 000000000000..e18d2f56e62a
--- /dev/null
+++ b/dev-java/java-dep-check/java-dep-check-0.3.ebuild
@@ -0,0 +1,40 @@
+# Copyright 1999-2009 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.3.ebuild,v 1.1 2009/01/28 20:06:39 serkan 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="~amd64 ~x86"
+
+IUSE=""
+
+COMMON_DEP="
+ dev-java/commons-cli:1
+ dev-java/asm:3"
+RDEPEND=">=virtual/jre-1.5
+ ${COMMON_DEP}"
+DEPEND=">=virtual/jdk-1.5
+ ${COMMON_DEP}"
+
+S="${WORKDIR}"
+
+src_unpack() {
+ cp "${FILESDIR}/Main-${PV}.java" Main.java || die
+}
+src_compile() {
+ ejavac -cp $(java-pkg_getjars asm-3,commons-cli-1) -encoding UTF-8 -d . 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
+}