diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-05-29 16:19:43 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-05-29 16:19:43 +0000 |
commit | edd2a15cd1b0c0771bde794ca558397414515e7f (patch) | |
tree | 7a03d9df49a3eafa27a831ff321ce65168bfa16b /tools | |
parent | 5418bfcd1dcd18878b4d0910610513c6247632ec (diff) | |
download | classpath-edd2a15cd1b0c0771bde794ca558397414515e7f.tar.gz |
2006-05-29 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD to generics-branch (2006-05-20 to 2006-05-29)
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/Makefile.am | 44 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/appletviewer/AppletTag.java | 22 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/getopt/FileArgumentCallback.java | 3 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jar/Extractor.java | 43 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jar/Lister.java | 24 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jar/WorkSet.java | 86 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/jarsigner/Messages.java | 4 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/ImportCmd.java | 167 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/keytool/Messages.java | 4 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/native2ascii/Messages.java | 67 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/native2ascii/Native2ASCII.java | 185 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/serialver/Messages.java | 68 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/serialver/SerialVer.java | 163 | ||||
-rw-r--r-- | tools/toolwrapper.c (renamed from tools/appletviewer.c) | 51 |
14 files changed, 808 insertions, 123 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index cd69bc04f..713c5827a 100755 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -13,8 +13,46 @@ error dunno how to setup the JCOMPILER and compile endif endif +if CREATE_WRAPPERS +bin_SCRIPTS = +bin_PROGRAMS = appletviewer jarsigner keytool + +#if FOUND_GCJ +#LIBJVM = -lgcj +#else +if FOUND_CACAO +LIBJVM = -lcacaovm +else +LIBJVM = +endif +#endif + +appletviewer_SOURCES = toolwrapper.c +appletviewer_CFLAGS = -Wall \ + -DDATA_DIR="\"$(datadir)\"" \ + -DPACKAGE="\"$(PACKAGE)\"" \ + -DTOOLNAME="\"appletviewer\"" +appletviewer_LDFLAGS = $(LIBJVM) + +jarsigner_SOURCES = toolwrapper.c +jarsigner_CFLAGS = -Wall \ + -DDATA_DIR="\"$(datadir)\"" \ + -DPACKAGE="\"$(PACKAGE)\"" \ + -DTOOLNAME="\"jarsigner\"" +jarsigner_LDFLAGS = $(LIBJVM) + +keytool_SOURCES = toolwrapper.c +keytool_CFLAGS = -Wall \ + -DDATA_DIR="\"$(datadir)\"" \ + -DPACKAGE="\"$(PACKAGE)\"" \ + -DTOOLNAME="\"keytool\"" +keytool_LDFLAGS = $(LIBJVM) + +else bin_SCRIPTS = appletviewer jarsigner keytool -EXTRA_DIST = appletviewer.in appletviewer.c jarsigner.in keytool.in +bin_PROGRAMS = +endif +EXTRA_DIST = toolwrapper.c appletviewer.in jarsigner.in keytool.in # All our example java source files TOOLS_JAVA_FILES = $(srcdir)/gnu/classpath/tools/*.java $(srcdir)/gnu/classpath/tools/*/*.java $(srcdir)/gnu/classpath/tools/*/*/*.java @@ -88,3 +126,7 @@ $(TOOLS_ZIP): $(TOOLS_JAVA_FILES) # Zip file be gone! (and make sure the classes are gone too) clean-local: rm -rf $(TOOLS_ZIP) classes + +# FIXME: remove this when GNU Classpath includes a bootstrap VM. +installcheck-binSCRIPTS: + : diff --git a/tools/gnu/classpath/tools/appletviewer/AppletTag.java b/tools/gnu/classpath/tools/appletviewer/AppletTag.java index b2d7ccb2b..4c3d01edb 100644 --- a/tools/gnu/classpath/tools/appletviewer/AppletTag.java +++ b/tools/gnu/classpath/tools/appletviewer/AppletTag.java @@ -451,15 +451,19 @@ class AppletTag else { String dirname = documentbase.getFile(); - - // Determine dirname for file by stripping everything - // past the last file separator. - dirname = dirname.substring(0, - dirname.lastIndexOf(File.separatorChar) + 1); - - fullcodebase = new URL(documentbase.getProtocol(), - documentbase.getHost(), - documentbase.getPort(), dirname); + if (!new File(dirname).isFile()) + fullcodebase = new URL(documentbase + File.separator); + else + { + // Determine dirname for file by stripping everything + // past the last file separator. + dirname = dirname.substring(0, + dirname.lastIndexOf(File.separatorChar) + 1); + + fullcodebase = new URL(documentbase.getProtocol(), + documentbase.getHost(), + documentbase.getPort(), dirname); + } } } else diff --git a/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java b/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java index 0c44745c9..455389127 100644 --- a/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java +++ b/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java @@ -57,5 +57,6 @@ public abstract class FileArgumentCallback * * @param fileArgument the file name */ - public abstract void notifyFile(String fileArgument); + public abstract void notifyFile(String fileArgument) + throws OptionException; } diff --git a/tools/gnu/classpath/tools/jar/Extractor.java b/tools/gnu/classpath/tools/jar/Extractor.java index ed647cbfe..203ff0566 100644 --- a/tools/gnu/classpath/tools/jar/Extractor.java +++ b/tools/gnu/classpath/tools/jar/Extractor.java @@ -45,9 +45,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -55,8 +52,7 @@ public class Extractor extends Action { // This is a set of all the items specified on the command line. - // It is null if none were specified. - private HashSet allItems; + private WorkSet allItems; private void copyFile(InputStream input, File output) throws IOException { @@ -72,43 +68,10 @@ public class Extractor os.close(); } - private void initSet(ArrayList entries) - { - if (entries == null || entries.isEmpty()) - return; - allItems = new HashSet(); - Iterator it = entries.iterator(); - while (it.hasNext()) - { - Entry entry = (Entry) it.next(); - int len = entry.name.length(); - while (len > 0 && entry.name.charAt(len - 1) == '/') - --len; - String name = entry.name.substring(0, len); - allItems.add(name); - } - } - - private boolean shouldExtract(String filename) - { - if (allItems == null) - return true; - while (filename.length() > 0) - { - if (allItems.contains(filename)) - return true; - int index = filename.lastIndexOf('/'); - if (index == -1) - break; - filename = filename.substring(0, index); - } - return false; - } - public void run(Main parameters) throws IOException { // Figure out what we want to extract. - initSet(parameters.entries); + allItems = new WorkSet(parameters.entries); // Open the input file. ZipInputStream zis; File zfile = parameters.archiveFile; @@ -125,7 +88,7 @@ public class Extractor ZipEntry entry = zis.getNextEntry(); if (entry == null) break; - if (! shouldExtract(entry.getName())) + if (! allItems.contains(entry.getName())) continue; File file = new File(entry.getName()); if (entry.isDirectory()) diff --git a/tools/gnu/classpath/tools/jar/Lister.java b/tools/gnu/classpath/tools/jar/Lister.java index ee4fb725e..98275f789 100644 --- a/tools/gnu/classpath/tools/jar/Lister.java +++ b/tools/gnu/classpath/tools/jar/Lister.java @@ -42,6 +42,7 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.text.MessageFormat; import java.util.Date; import java.util.zip.ZipEntry; @@ -50,6 +51,22 @@ import java.util.zip.ZipInputStream; public class Lister extends Action { + private WorkSet allItems; + + private long readUntilEnd(InputStream is) throws IOException + { + byte[] buffer = new byte[5 * 1024]; + long result = 0; + while (true) + { + int r = is.read(buffer); + if (r == -1) + break; + result += r; + } + return result; + } + private void listJar(ZipInputStream zis, boolean verbose) throws IOException { MessageFormat format = null; @@ -60,11 +77,15 @@ public class Lister ZipEntry entry = zis.getNextEntry(); if (entry == null) break; + if (! allItems.contains(entry.getName())) + continue; if (verbose) { + // Read the stream; entry.getSize() is unreliable. + // (Also, we're just going to read it anyway.) + long size = readUntilEnd(zis); // No easy way to right-justify the size using // MessageFormat -- how odd. - long size = entry.getSize(); String s = " " + size; int index = Math.min(s.length() - 5, 5); System.out.print(s.substring(index)); @@ -79,6 +100,7 @@ public class Lister public void run(Main parameters) throws IOException { + allItems = new WorkSet(parameters.entries); File file = parameters.archiveFile; ZipInputStream zis; if (file == null || "-".equals(file.getName())) diff --git a/tools/gnu/classpath/tools/jar/WorkSet.java b/tools/gnu/classpath/tools/jar/WorkSet.java new file mode 100644 index 000000000..ff0b48786 --- /dev/null +++ b/tools/gnu/classpath/tools/jar/WorkSet.java @@ -0,0 +1,86 @@ +/* WorkSet.java -- Helper to track what files to work on + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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, or (at your option) +any later version. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.tools.jar; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; + +public class WorkSet +{ + private HashSet allItems; + + private void initSet(ArrayList entries) + { + if (entries == null || entries.isEmpty()) + return; + allItems = new HashSet(); + Iterator it = entries.iterator(); + while (it.hasNext()) + { + Entry entry = (Entry) it.next(); + int len = entry.name.length(); + while (len > 0 && entry.name.charAt(len - 1) == '/') + --len; + String name = entry.name.substring(0, len); + allItems.add(name); + } + } + + public WorkSet(ArrayList entries) + { + initSet(entries); + } + + public boolean contains(String filename) + { + if (allItems == null) + return true; + while (filename.length() > 0) + { + if (allItems.contains(filename)) + return true; + int index = filename.lastIndexOf('/'); + if (index == -1) + break; + filename = filename.substring(0, index); + } + return false; + } +} diff --git a/tools/gnu/classpath/tools/jarsigner/Messages.java b/tools/gnu/classpath/tools/jarsigner/Messages.java index 284639115..35f461669 100644 --- a/tools/gnu/classpath/tools/jarsigner/Messages.java +++ b/tools/gnu/classpath/tools/jarsigner/Messages.java @@ -54,7 +54,7 @@ import java.util.logging.Logger; class Messages { private static final Logger log = Logger.getLogger(Messages.class.getName()); - private static final String BUNDLE_NAME = "gnu.classpath.tools.jarsigner.MessageBundle"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "gnu.classpath.tools.jarsigner.messages"; private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); private static final Map CACHED_FORMATS = new HashMap(5); @@ -88,7 +88,7 @@ class Messages CACHED_FORMATS.put(key, mf); } - // if the argument is not an array, then build one consisiting of the + // if the argument is not an array, then build one consisting of the // sole argument before passing it to the format() method try { diff --git a/tools/gnu/classpath/tools/keytool/ImportCmd.java b/tools/gnu/classpath/tools/keytool/ImportCmd.java index 2d587be08..7a4b6dfb6 100644 --- a/tools/gnu/classpath/tools/keytool/ImportCmd.java +++ b/tools/gnu/classpath/tools/keytool/ImportCmd.java @@ -52,6 +52,7 @@ import java.security.Key; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.security.Principal; import java.security.PublicKey; import java.security.UnrecoverableKeyException; import java.security.cert.CertPathValidator; @@ -62,11 +63,14 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.PKIXCertPathValidatorResult; import java.security.cert.PKIXParameters; +import java.security.cert.TrustAnchor; +import java.security.cert.X509Certificate; import java.security.interfaces.DSAParams; import java.security.interfaces.DSAPublicKey; import java.security.interfaces.RSAPublicKey; import java.util.Collection; import java.util.LinkedList; +import java.util.ListIterator; import java.util.logging.Level; import java.util.logging.Logger; @@ -186,6 +190,12 @@ import javax.security.auth.callback.UnsupportedCallbackException; class ImportCmd extends Command { private static final Logger log = Logger.getLogger(ImportCmd.class.getName()); + private static final String GKR = "gkr"; //$NON-NLS-1$ + private static final String JKS = "jks"; //$NON-NLS-1$ + private static final String LIB = "lib"; //$NON-NLS-1$ + private static final String SECURITY = "security"; //$NON-NLS-1$ + private static final String CACERTS = "cacerts"; //$NON-NLS-1$ + private static final String CACERTS_GKR = CACERTS + "." + GKR; //$NON-NLS-1$ protected String _alias; protected String _certFileName; protected String _password; @@ -197,6 +207,20 @@ class ImportCmd extends Command protected String _providerClassName; private CertificateFactory x509Factory; private boolean imported; + /** + * Pathname to a GKR-type cacerts file to use when trustCACerts is true. This + * is usually a file named "cacerts.gkr" located in lib/security in the folder + * specified by the system-property "gnu.classpath.home". + */ + private String gkrCaCertsPathName; + /** + * Pathname to a JKS-type cacerts file to use when trustCACerts is true. This + * is usually a file named "cacerts" located in lib/security in the folder + * specified by the system-property "java.home". + */ + private String jksCaCertsPathName; + /** Alias self-signed certificate. used when importing certificate replies. */ + private X509Certificate selfSignedCertificate; // default 0-arguments constructor @@ -288,6 +312,20 @@ class ImportCmd extends Command { log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$ + if (trustCACerts) + { + String fs = SystemProperties.getProperty("file.separator"); //$NON-NLS-1$ + String classpathHome = SystemProperties.getProperty("gnu.classpath.home"); //$NON-NLS-1$ + gkrCaCertsPathName = new StringBuilder(classpathHome).append(fs) + .append(LIB).append(fs) + .append(SECURITY).append(fs) + .append(CACERTS_GKR).toString(); + String javaHome = SystemProperties.getProperty("java.home"); //$NON-NLS-1$ + jksCaCertsPathName = new StringBuilder(javaHome).append(fs) + .append(LIB).append(fs) + .append(SECURITY).append(fs) + .append(CACERTS).toString(); + } x509Factory = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$ // the alias will tell us whether we're dealing with // a new trusted certificate or a certificate reply @@ -608,8 +646,8 @@ class ImportCmd extends Command if (chain == null) throw new IllegalArgumentException(Messages.getFormattedString("ImportCmd.37", //$NON-NLS-1$ alias)); - Certificate anchor = chain[0]; - PublicKey anchorPublicKey = anchor.getPublicKey(); + selfSignedCertificate = (X509Certificate) chain[0]; + PublicKey anchorPublicKey = selfSignedCertificate.getPublicKey(); PublicKey certPublicKey = certificate.getPublicKey(); boolean sameKey; if (anchorPublicKey instanceof DSAPublicKey) @@ -664,17 +702,54 @@ class ImportCmd extends Command } /** - * @param chain + * Given a collection of certificates returned as a certificate-reply, this + * method sorts the certificates in the collection so that the <i>Issuer</i> + * of the certificate at position <code>i</code> is the <i>Subject</i> of + * the certificate at position <code>i + 1</code>. + * <p> + * This method uses <code>selfSignedCertificate</code> to discover the first + * certificate in the chain. The <i>Trust Anchor</i> of the chain; i.e. the + * self-signed CA certificate, if it exsits, will be discovered/established + * later by an appropriate <i>Certificate Path Validator</i>. + * <p> + * An exception is thrown if (a) no initial certificate is found in the + * designated collection which can be used as the start of the chain, or (b) + * if a chain can not be constructed using all the certificates in the + * designated collection. + * + * @param chain a collection of certificates, not necessarily ordered, but + * assumed to include a CA certificate authenticating our alias + * public key, which is the subject of the alias self-signed + * certificate. * @return the input collection, ordered with own certificate first, and CA's * self-signed certificate last. */ private LinkedList orderChain(Collection chain) { log.entering(this.getClass().getName(), "orderChain"); //$NON-NLS-1$ - + LinkedList in = new LinkedList(chain); + int initialCount = in.size(); LinkedList result = new LinkedList(); - // FIXME: really order it! - + Principal issuer = selfSignedCertificate.getIssuerDN(); + ListIterator it; + outer: while (in.size() > 0) + { + for (it = in.listIterator(); it.hasNext();) + { + X509Certificate certificate = (X509Certificate) it.next(); + if (issuer.equals(certificate.getSubjectDN())) + { + it.remove(); + result.addLast(certificate); + issuer = certificate.getIssuerDN(); + continue outer; + } + } + throw new IllegalArgumentException( + Messages.getFormattedString(Messages.getString("ImportCmd.7"), //$NON-NLS-1$ + new Object[] { Integer.valueOf(result.size()), + Integer.valueOf(initialCount) })); + } log.entering(this.getClass().getName(), "orderChain", result); //$NON-NLS-1$ return result; } @@ -712,13 +787,19 @@ class ImportCmd extends Command CertificateEncodingException { log.entering(this.getClass().getName(), "findTrustAndUpdate"); //$NON-NLS-1$ - - X509CertPath certPath = new X509CertPath(reply); CertPathValidator validator = CertPathValidator.getInstance("PKIX"); //$NON-NLS-1$ + X509CertPath certPath = new X509CertPath(reply); PKIXCertPathValidatorResult cpvr = findTrustInStore(certPath, validator); - if (cpvr == null && trustCACerts) - cpvr = findTrustInCACerts(certPath, validator); - + if (cpvr == null && trustCACerts) // try cacerts.gkr - a GKR key store + { + PKIXParameters params = getCertPathParameters(GKR, gkrCaCertsPathName); + cpvr = validate(validator, certPath, params); + if (cpvr == null) // try cacerts - a JKS key store + { + params = getCertPathParameters(JKS, jksCaCertsPathName); + cpvr = validate(validator, certPath, params); + } + } boolean result = false; if (cpvr == null) { @@ -737,12 +818,12 @@ class ImportCmd extends Command } else { - log.fine("Found a chain-of-trust anchored by " + cpvr.getTrustAnchor()); //$NON-NLS-1$ - Certificate trustedCert = cpvr.getTrustAnchor().getTrustedCert(); + TrustAnchor anchor = cpvr.getTrustAnchor(); + log.fine("Found a chain-of-trust anchored by " + anchor); //$NON-NLS-1$ + Certificate trustedCert = anchor.getTrustedCert(); reply.addLast(trustedCert); result = true; } - log.entering(this.getClass().getName(), "findTrustAndUpdate", //$NON-NLS-1$ Boolean.valueOf(result)); return result; @@ -771,33 +852,32 @@ class ImportCmd extends Command return result; } - private PKIXCertPathValidatorResult findTrustInCACerts(X509CertPath certPath, - CertPathValidator validator) + /** + * Return an instance of {@link PKIXParameters} constructed using a key store + * of the designated type and located at the designated path. + * + * @param type the type of the key-store to load. + * @param pathName the local File System fully qualified path name to the key + * store. + * @return an instance of <code>CertPathParameters</code> to use for + * validating certificates and certificate replies. + */ + private PKIXParameters getCertPathParameters(String type, String pathName) { - log.entering(this.getClass().getName(), "findTrustInCACerts"); //$NON-NLS-1$ - + log.entering(this.getClass().getName(), "getCertPathParameters", //$NON-NLS-1$ + new Object[] { type, pathName }); FileInputStream stream = null; - PKIXCertPathValidatorResult result = null; + PKIXParameters result = null; try { - KeyStore cacerts = KeyStore.getInstance("jks"); //$NON-NLS-1$ - String cacertsPath = SystemProperties.getProperty("java.home"); //$NON-NLS-1$ - String fs = SystemProperties.getProperty("file.separator"); //$NON-NLS-1$ - cacertsPath = new StringBuilder(cacertsPath).append(fs) - .append("lib").append(fs) //$NON-NLS-1$ - .append("security").append(fs) //$NON-NLS-1$ - .append("cacerts").toString(); //$NON-NLS-1$ - stream = new FileInputStream(cacertsPath); + KeyStore cacerts = KeyStore.getInstance(type); + stream = new FileInputStream(pathName); cacerts.load(stream, "changeit".toCharArray()); //$NON-NLS-1$ - PKIXParameters params = new PKIXParameters(cacerts); - result = (PKIXCertPathValidatorResult) validator.validate(certPath, - params); + result = new PKIXParameters(cacerts); } catch (Exception x) { - log.log(Level.FINE, - "Exception in findTrustInCACerts(). Ignore + Return NULL", //$NON-NLS-1$ - x); + log.log(Level.FINE, "Exception in getCertPathParameters(). Ignore", x); //$NON-NLS-1$ } finally { @@ -810,8 +890,27 @@ class ImportCmd extends Command { } } + log.exiting(this.getClass().getName(), "getCertPathParameters", result); //$NON-NLS-1$ + return result; + } - log.exiting(this.getClass().getName(), "findTrustInCACerts", result); //$NON-NLS-1$ + private PKIXCertPathValidatorResult validate(CertPathValidator validator, + X509CertPath certPath, + PKIXParameters params) + { + log.entering(this.getClass().getName(), "validate"); //$NON-NLS-1$ + PKIXCertPathValidatorResult result = null; + if (params != null) + try + { + result = (PKIXCertPathValidatorResult) validator.validate(certPath, + params); + } + catch (Exception x) + { + log.log(Level.FINE, "Exception in validate(). Ignore", x); //$NON-NLS-1$ + } + log.exiting(this.getClass().getName(), "validate", result); //$NON-NLS-1$ return result; } } diff --git a/tools/gnu/classpath/tools/keytool/Messages.java b/tools/gnu/classpath/tools/keytool/Messages.java index e3308e021..7ecaa1c37 100644 --- a/tools/gnu/classpath/tools/keytool/Messages.java +++ b/tools/gnu/classpath/tools/keytool/Messages.java @@ -54,7 +54,7 @@ import java.util.logging.Logger; class Messages { private static final Logger log = Logger.getLogger(Messages.class.getName()); - private static final String BUNDLE_NAME = "gnu.classpath.tools.keytool.MessageBundle"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "gnu.classpath.tools.keytool.messages"; private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); private static final Map CACHED_FORMATS = new HashMap(5); @@ -88,7 +88,7 @@ class Messages CACHED_FORMATS.put(key, mf); } - // if the argument is not an array, then build one consisiting of the + // if the argument is not an array, then build one consisting of the // sole argument before passing it to the format() method try { diff --git a/tools/gnu/classpath/tools/native2ascii/Messages.java b/tools/gnu/classpath/tools/native2ascii/Messages.java new file mode 100644 index 000000000..4c6bae4dc --- /dev/null +++ b/tools/gnu/classpath/tools/native2ascii/Messages.java @@ -0,0 +1,67 @@ +/* Messages.java -- translation support for native2ascii + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath 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, or (at your option) + any later version. + + GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.tools.native2ascii; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages +{ + private static final String BUNDLE_NAME + = "gnu.classpath.tools.native2ascii.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE + = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() + { + } + + public static String getString(String key) + { + try + { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) + { + return '!' + key + '!'; + } + } +} diff --git a/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java b/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java new file mode 100644 index 000000000..9508c103e --- /dev/null +++ b/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java @@ -0,0 +1,185 @@ +/* Native2ASCII.java - native2ascii program + Copyright (C) 2003 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath 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, or (at your option) + any later version. + + GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.tools.native2ascii; + +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.FileArgumentCallback; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.Parser; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; + +/** + * Native2ASCII main program. + * @author Ito Kazumitsu <kaz@maczuka.gcd.org> + */ +public class Native2ASCII +{ + // Input file. + String input; + // Output file. + String output; + // Encoding to use. + String encoding; + // True for reverse operation. + boolean reversed; + + private class HandleFile extends FileArgumentCallback + { + public HandleFile() + { + } + + public void notifyFile(String fileArgument) + throws OptionException + { + if (input == null) + input = fileArgument; + else if (output == null) + output = fileArgument; + else + throw new OptionException(Messages.getString("Native2ASCII.TooManyFiles")); //$NON-NLS-1$ + } + } + + private Parser createParser() + { + Parser result = new ClasspathToolParser("native2ascii", true); //$NON-NLS-1$ + result.setHeader(Messages.getString("Native2ASCII.Usage")); //$NON-NLS-1$ + + result.add(new Option("encoding", Messages.getString("Native2ASCII.EncodingHelp"), Messages.getString("Native2ASCII.EncodingArgName")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + { + public void parsed(String argument) throws OptionException + { + if (encoding != null) + throw new OptionException(Messages.getString("Native2ASCII.EncodingSpecified")); //$NON-NLS-1$ + encoding = argument; + } + }); + result.add(new Option("reversed", Messages.getString("Native2ASCII.ReversedHelp")) //$NON-NLS-1$ //$NON-NLS-2$ + { + public void parsed(String argument) throws OptionException + { + reversed = true; + } + }); + + return result; + } + + private void run(String[] args) + { + Parser argParser = createParser(); + argParser.parse(args, new HandleFile()); + + if (encoding == null) + encoding = System.getProperty("file.encoding"); //$NON-NLS-1$ + try + { + InputStream is = (input == null ? System.in + : new FileInputStream(input)); + OutputStream os = (output == null ? (OutputStream) System.out + : new FileOutputStream(output)); + + BufferedReader rdr = new BufferedReader(new InputStreamReader(is, + encoding)); + PrintWriter wtr = new PrintWriter( + new BufferedWriter( + new OutputStreamWriter( + os, + encoding))); + while (true) + { + String s = rdr.readLine(); + if (s == null) + break; + StringBuffer sb = new StringBuffer(s.length() + 80); + for (int i = 0; i < s.length(); i++) + { + char c = s.charAt(i); + if (reversed + && i + 6 < s.length() + && s.charAt(i) == '\\' + && s.charAt(i + 1) == 'u') + { + int num = Integer.parseInt(s.substring(i + 2, i + 6), 16); + sb.append((char) num); + i += 5; + } + else if ((int)c <= 127 || reversed) + { + sb.append(c); + } + else + { + sb.append("\\u"); //$NON-NLS-1$ + if ((int)c <= 0xff) + sb.append("00"); //$NON-NLS-1$ + else if ((int)c <= 0xfff) + sb.append("0"); //$NON-NLS-1$ + sb.append(Integer.toHexString((int) c)); + } + } + wtr.println(sb.toString()); + } + rdr.close(); + wtr.flush(); + wtr.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void main(String[] args) + { + new Native2ASCII().run(args); + String encoding = System.getProperty("file.encoding"); //$NON-NLS-1$ + } +} diff --git a/tools/gnu/classpath/tools/serialver/Messages.java b/tools/gnu/classpath/tools/serialver/Messages.java new file mode 100644 index 000000000..a6ab67add --- /dev/null +++ b/tools/gnu/classpath/tools/serialver/Messages.java @@ -0,0 +1,68 @@ +/* Messages.java -- translations for serialver tool + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath 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, or (at your option) + any later version. + + GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.tools.serialver; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages +{ + private static final String BUNDLE_NAME + = "gnu.classpath.tools.serialver.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE + = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() + { + } + + public static String getString(String key) + { + // TODO Auto-generated method stub + try + { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) + { + return '!' + key + '!'; + } + } +} diff --git a/tools/gnu/classpath/tools/serialver/SerialVer.java b/tools/gnu/classpath/tools/serialver/SerialVer.java new file mode 100644 index 000000000..b5a12ec92 --- /dev/null +++ b/tools/gnu/classpath/tools/serialver/SerialVer.java @@ -0,0 +1,163 @@ +/* gnu.classpath.tools.SerialVer + Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath 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, or (at your option) + any later version. + + GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + + +package gnu.classpath.tools.serialver; + +import gnu.classpath.tools.getopt.ClasspathToolParser; +import gnu.classpath.tools.getopt.FileArgumentCallback; +import gnu.classpath.tools.getopt.Option; +import gnu.classpath.tools.getopt.OptionException; +import gnu.classpath.tools.getopt.Parser; + +import java.io.File; +import java.io.ObjectStreamClass; +import java.net.URL; +import java.net.URLClassLoader; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.StringTokenizer; + +/** + * This class is an implementation of the `serialver' program. Any number of + * class names can be passed as arguments, and the serial version unique + * identitfier for each class will be printed in a manner suitable for cuting + * and pasting into a Java source file. + */ +public class SerialVer +{ + // List of classes to load. + ArrayList classes = new ArrayList(); + // The class path to use. + String classpath; + + // FIXME: taken from ClassLoader, should share it. + private static void addFileURL(ArrayList list, String file) + { + try + { + list.add(new File(file).toURL()); + } + catch(java.net.MalformedURLException x) + { + } + } + + private ClassLoader getClassLoader() + { + // FIXME: this code is taken from ClassLoader. + // We should share it somewhere. + URL[] urls; + if (classpath == null) + urls = new URL[0]; + else + { + StringTokenizer tok = new StringTokenizer(classpath, + File.pathSeparator, true); + ArrayList list = new ArrayList(); + while (tok.hasMoreTokens()) + { + String s = tok.nextToken(); + if (s.equals(File.pathSeparator)) + addFileURL(list, "."); //$NON-NLS-1$ + else + { + addFileURL(list, s); + if (tok.hasMoreTokens()) + { + // Skip the separator. + tok.nextToken(); + // If the classpath ended with a separator, + // append the current directory. + if (!tok.hasMoreTokens()) + addFileURL(list, "."); //$NON-NLS-1$ + } + } + } + urls = new URL[list.size()]; + urls = (URL[]) list.toArray(urls); + } + return new URLClassLoader(urls); + } + + private void printMessage(String format, String klass) + { + System.err.println(MessageFormat.format(format, new Object[] { klass })); + } + + public void run(String[] args) + { + Parser p = new ClasspathToolParser("serialver", true) //$NON-NLS-1$ + { + protected void validate() throws OptionException + { + if (classes.isEmpty()) + throw new OptionException(Messages.getString("SerialVer.NoClassesSpecd")); //$NON-NLS-1$ + } + }; + p.setHeader(Messages.getString("SerialVer.HelpHeader")); //$NON-NLS-1$ + + p.add(new Option(Messages.getString("SerialVer.5"), Messages.getString("SerialVer.ClasspathHelp"), "PATH") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + { + public void parsed(String argument) throws OptionException + { + if (classpath != null) + throw new OptionException(Messages.getString("SerialVer.DupClasspath")); //$NON-NLS-1$ + classpath = argument; + } + }); + + p.parse(args, new FileArgumentCallback() + { + public void notifyFile(String fileArgument) throws OptionException + { + classes.add(fileArgument); + } + }); + + ClassLoader loader = getClassLoader(); + Iterator it = classes.iterator(); + while (it.hasNext()) + { + String name = (String) it.next(); + try + { + Class clazz = loader.loadClass(name); + ObjectStreamClass osc = ObjectStreamClass.lookup(clazz); + if (osc != null) + System.out.println(clazz.getName() + ": " //$NON-NLS-1$ + + "static final long serialVersionUID = " //$NON-NLS-1$ + + osc.getSerialVersionUID() + "L;"); //$NON-NLS-1$ + else + printMessage(Messages.getString("SerialVer.ClassNotSerial"), name); //$NON-NLS-1$ + } + catch (ClassNotFoundException e) + { + printMessage(Messages.getString("SerialVer.ClassNotFound"), name); //$NON-NLS-1$ + } + } + } + + public static void main(String[] args) + { + new SerialVer().run(args); + } +}
\ No newline at end of file diff --git a/tools/appletviewer.c b/tools/toolwrapper.c index 2609ccaf6..de6556c63 100644 --- a/tools/appletviewer.c +++ b/tools/toolwrapper.c @@ -1,5 +1,5 @@ -/* appletviewer.c -- a native appletviewer wrapper for VMs that - support the JNI invocation interface +/* toolwrapper.c -- a native tool wrapper for VMs that support the JNI + invocation interface Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,7 +37,6 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include <jni.h> -#include <glib.h> #include <string.h> #include <stdlib.h> #include "config.h" @@ -93,41 +92,27 @@ main (int argc, const char** argv) if (vm_args.options == NULL) { - g_printerr ("appletviewer: realloc failed.\n"); + fprintf (stderr, TOOLNAME ": realloc failed.\n"); goto destroy; } if (strlen (argv[i]) == 2) { - g_printerr ("appletviewer: the -J option must not be followed by a space.\n"); + fprintf (stderr, TOOLNAME ": the -J option must not be followed by a space.\n"); goto destroy; } else - vm_args.options[vm_args.nOptions++].optionString = g_strdup (argv[i] + 2); - } - else if (!strncmp (argv[i], "--version", 9) - && argv[i][9] == '\0') - { - g_print ("appletviewer (GCJ Applet Viewer) " PACKAGE_VERSION "\n"); - exit (0); - } - else if (!strncmp (argv[i], "-debug", 6) - && argv[i][6] == '\0') - { - /* FIXME: Ignore for now. The debug option will be - unsupported until we have the ability to debug - bytecode. For now, just strip it out of the argument - list. */ + vm_args.options[vm_args.nOptions++].optionString = strdup (argv[i] + 2); } else { non_vm_argv = (char**) realloc (non_vm_argv, (non_vm_argc + 1) * sizeof (char*)); if (non_vm_argv == NULL) { - g_printerr ("appletviewer: realloc failed.\n"); + fprintf (stderr, TOOLNAME ": realloc failed.\n"); goto destroy; } - non_vm_argv[non_vm_argc++] = g_strdup (argv[i]); + non_vm_argv[non_vm_argc++] = strdup (argv[i]); } } } @@ -139,18 +124,18 @@ main (int argc, const char** argv) if (vm_args.options == NULL) { - g_printerr ("appletviewer: realloc failed.\n"); + fprintf (stderr, TOOLNAME ": realloc failed.\n"); goto destroy; } - vm_args.options[vm_args.nOptions++].optionString = "-Djava.class.path=" "@datadir@/@PACKAGE@/tools.zip"; + vm_args.options[vm_args.nOptions++].optionString = "-Djava.class.path=" DATA_DIR "/" PACKAGE "/tools.zip"; } /* Terminate vm_args.options with a NULL element. */ vm_args.options = (JavaVMOption*) realloc (vm_args.options, (vm_args.nOptions + 1) * sizeof (JavaVMOption)); if (vm_args.options == NULL) { - g_printerr ("appletviewer: realloc failed.\n"); + fprintf (stderr, TOOLNAME ": realloc failed.\n"); goto destroy; } vm_args.options[vm_args.nOptions].optionString = NULL; @@ -159,7 +144,7 @@ main (int argc, const char** argv) non_vm_argv = (char**) realloc (non_vm_argv, (non_vm_argc + 1) * sizeof (char*)); if (non_vm_argv == NULL) { - g_printerr ("appletviewer: realloc failed.\n"); + fprintf (stderr, TOOLNAME ": realloc failed.\n"); goto destroy; } non_vm_argv[non_vm_argc] = NULL; @@ -171,7 +156,7 @@ main (int argc, const char** argv) if (result < 0) { - g_printerr ("appletviewer: couldn't create virtual machine\n"); + fprintf (stderr, TOOLNAME ": couldn't create virtual machine\n"); goto destroy; } @@ -180,14 +165,14 @@ main (int argc, const char** argv) string_class_id = (*env)->FindClass (env, "java/lang/String"); if (string_class_id == NULL) { - g_printerr ("appletviewer: FindClass failed.\n"); + fprintf (stderr, TOOLNAME ": FindClass failed.\n"); goto destroy; } args_array = (*env)->NewObjectArray (env, non_vm_argc, string_class_id, NULL); if (args_array == NULL) { - g_printerr ("appletviewer: NewObjectArray failed.\n"); + fprintf (stderr, TOOLNAME ": NewObjectArray failed.\n"); goto destroy; } @@ -196,17 +181,17 @@ main (int argc, const char** argv) str = (*env)->NewStringUTF (env, non_vm_argv[i]); if (str == NULL) { - g_printerr ("appletviewer: NewStringUTF failed.\n"); + fprintf (stderr, TOOLNAME ": NewStringUTF failed.\n"); goto destroy; } (*env)->SetObjectArrayElement (env, args_array, i, str); } - class_id = (*env)->FindClass (env, "gnu/classpath/tools/appletviewer/Main"); + class_id = (*env)->FindClass (env, "gnu/classpath/tools/" TOOLNAME "/Main"); if (class_id == NULL) { - g_printerr ("appletviewer: FindClass failed.\n"); + fprintf (stderr, TOOLNAME ": FindClass failed.\n"); goto destroy; } @@ -214,7 +199,7 @@ main (int argc, const char** argv) if (method_id == NULL) { - g_printerr ("appletviewer: GetStaticMethodID failed.\n"); + fprintf (stderr, TOOLNAME ": GetStaticMethodID failed.\n"); goto destroy; } |