String.java, [...]: Merge from GNU Classpath HEAD.

2006-06-09  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* java/lang/String.java, classpath/native/jni/classpath/jcl.h,
	classpath/native/jni/qt-peer/eventmethods.h,
	classpath/native/jni/qt-peer/qtmenupeer.cpp,
	classpath/native/jni/qt-peer/.cvsignore,
	classpath/native/jni/gtk-peer/gdkdisplay.h,
	classpath/native/jni/gtk-peer/cairographics2d.h,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,
	classpath/native/jni/gtk-peer/.cvsignore,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c,
	classpath/native/jni/gtk-peer/gtkpeer.h,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c,
	classpath/native/jni/gtk-peer/Makefile.am,
	classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c,
	classpath/native/jawt/Makefile.am,
	classpath/native/jawt/.cvsignore,
	classpath/native/target/Linux/Makefile.in,
	classpath/native/plugin/gcjwebplugin.cc,
	classpath/native/plugin/Makefile.am,
	classpath/native/plugin/.cvsignore,
	classpath/resource/Makefile.in,
	classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java,
	classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,
	classpath/gnu/java/awt/peer/gtk/CairoSurface.java,
	classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,
	classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java,
	classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,
	classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java,
	classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java,
	classpath/gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java,
	classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java,
	classpath/gnu/java/awt/peer/gtk/GdkGraphics.java,
	classpath/gnu/java/awt/peer/gtk/GtkToolkit.java,
	classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java,
	classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,
	classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java,
	classpath/gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java,
	classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,
	classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java,
	classpath/gnu/java/awt/peer/gtk/GtkImage.java,
	classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java,
	classpath/gnu/java/awt/peer/gtk/GdkGlyphVector.java,
	classpath/gnu/java/awt/peer/gtk/GtkCanvasPeer.java,
	classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java,
	classpath/gnu/java/awt/peer/swing/SwingComponent.java,
	classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java,
	classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java,
	classpath/gnu/java/awt/peer/swing/SwingFramePeer.java,
	classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java,
	classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java,
	classpath/gnu/java/awt/print/JavaPrinterJob.java,
	classpath/gnu/java/awt/print/PostScriptGraphics2D.java,
	classpath/gnu/java/awt/print/SpooledDocument.java,
	classpath/gnu/java/awt/print/JavaPrinterGraphics.java,
	classpath/gnu/java/awt/BitwiseXORComposite.java,
	classpath/gnu/java/awt/font/GNUGlyphVector.java,
	classpath/gnu/java/awt/font/opentype/NameDecoder.java,
	classpath/gnu/java/awt/java2d/RasterGraphics.java,
	classpath/gnu/java/awt/java2d/TexturePaintContext.java,
	classpath/gnu/java/awt/java2d/PolyEdge.java,
	classpath/gnu/java/awt/java2d/AbstractGraphics2D.java,
	classpath/gnu/java/awt/java2d/AlphaCompositeContext.java,
	classpath/gnu/java/awt/java2d/ImagePaint.java,
	classpath/gnu/java/awt/Buffers.java,
	classpath/gnu/classpath/Configuration.java.in,
	classpath/gnu/javax/swing/text/html/CombinedAttributes.java,
	classpath/gnu/javax/swing/text/html/CharacterAttributeTranslator.java,
	classpath/gnu/javax/swing/text/html/parser/htmlAttributeSet.java,
	classpath/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java,
	classpath/gnu/javax/swing/text/html/ImageViewIconFactory.java,
	classpath/tools/toolwrapper.c,
	classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java,
	classpath/tools/gnu/classpath/tools/native2ascii/Messages.java,
	classpath/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java,
	classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java,
	classpath/tools/gnu/classpath/tools/getopt/OptionException.java,
	classpath/tools/gnu/classpath/tools/getopt/Messages.java,
	classpath/tools/gnu/classpath/tools/getopt/Option.java,
	classpath/tools/gnu/classpath/tools/getopt/Parser.java,
	classpath/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java,
	classpath/tools/gnu/classpath/tools/jarsigner/JarSigner.java,
	classpath/tools/gnu/classpath/tools/jarsigner/Main.java,
	classpath/tools/gnu/classpath/tools/jarsigner/Messages.java,
	classpath/tools/gnu/classpath/tools/jarsigner/package.html,
	classpath/tools/gnu/classpath/tools/keytool/ListCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/Messages.java,
	classpath/tools/gnu/classpath/tools/keytool/package.html,
	classpath/tools/gnu/classpath/tools/keytool/Command.java,
	classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/Main.java,
	classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java,
	classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java,
	classpath/tools/gnu/classpath/tools/rmi/registry/package.html,
	classpath/tools/gnu/classpath/tools/rmi/RMIC.txt,
	classpath/tools/gnu/classpath/tools/rmi/RMIC.java,
	classpath/tools/gnu/classpath/tools/appletviewer/ErrorApplet.java,
	classpath/tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java,
	classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java,
	classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java,
	classpath/tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java,
	classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java,
	classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java,
	classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java,
	classpath/tools/gnu/classpath/tools/appletviewer/AppletTag.java,
	classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java,
	classpath/tools/gnu/classpath/tools/appletviewer/Main.java,
	classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java,
	classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java,
	classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java,
	classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java,
	classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java,
	classpath/tools/gnu/classpath/tools/serialver/Messages.java,
	classpath/tools/gnu/classpath/tools/serialver/SerialVer.java,
	classpath/tools/gnu/classpath/tools/jar/Creator.java,
	classpath/tools/gnu/classpath/tools/jar/Entry.java,
	classpath/tools/gnu/classpath/tools/jar/Lister.java,
	classpath/tools/gnu/classpath/tools/jar/Main.java,
	classpath/tools/gnu/classpath/tools/jar/Updater.java,
	classpath/tools/gnu/classpath/tools/jar/Messages.java,
	classpath/tools/gnu/classpath/tools/jar/Extractor.java,
	classpath/tools/gnu/classpath/tools/jar/Action.java,
	classpath/tools/gnu/classpath/tools/jar/Indexer.java,
	classpath/tools/gnu/classpath/tools/jar/WorkSet.java,
	classpath/tools/gnu/classpath/tools/giop/GRMIC.txt,
	classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java,
	classpath/tools/gnu/classpath/tools/giop/GRMIC.java,
	classpath/tools/Makefile.am, classpath/tools/jarsigner.in,
	classpath/tools/keytool.in, classpath/tools/appletviewer.in,
	classpath/tools/.cvsignore, classpath/configure.ac,
	classpath/javax/swing/JTabbedPane.java,
	classpath/javax/swing/AbstractButton.java,
	classpath/javax/swing/JViewport.java,
	classpath/javax/swing/KeyboardManager.java,
	classpath/javax/swing/JMenuItem.java,
	classpath/javax/swing/JMenuBar.java,
	classpath/javax/swing/MenuSelectionManager.java,
	classpath/javax/swing/JOptionPane.java,
	classpath/javax/swing/JSpinner.java,
	classpath/javax/swing/JCheckBoxMenuItem.java,
	classpath/javax/swing/JEditorPane.java,
	classpath/javax/swing/JFormattedTextField.java,
	classpath/javax/swing/JTree.java,
	classpath/javax/swing/CellRendererPane.java,
	classpath/javax/swing/JScrollPane.java,
	classpath/javax/swing/tree/VariableHeightLayoutCache.java,
	classpath/javax/swing/tree/TreeNode.java,
	classpath/javax/swing/tree/FixedHeightLayoutCache.java,
	classpath/javax/swing/tree/DefaultTreeCellEditor.java,
	classpath/javax/swing/tree/TreePath.java,
	classpath/javax/swing/tree/RowMapper.java,
	classpath/javax/swing/tree/DefaultMutableTreeNode.java,
	classpath/javax/swing/tree/DefaultTreeModel.java,
	classpath/javax/swing/tree/AbstractLayoutCache.java,
	classpath/javax/swing/tree/TreeSelectionModel.java,
	classpath/javax/swing/tree/DefaultTreeSelectionModel.java,
	classpath/javax/swing/tree/DefaultTreeCellRenderer.java,
	classpath/javax/swing/tree/ExpandVetoException.java,
	classpath/javax/swing/JList.java,
	classpath/javax/swing/table/JTableHeader.java,
	classpath/javax/swing/table/AbstractTableModel.java,
	classpath/javax/swing/table/DefaultTableModel.java,
	classpath/javax/swing/table/TableCellEditor.java,
	classpath/javax/swing/table/TableCellRenderer.java,
	classpath/javax/swing/ProgressMonitor.java,
	classpath/javax/swing/JToolBar.java,
	classpath/javax/swing/TransferHandler.java,
	classpath/javax/swing/DefaultCellEditor.java,
	classpath/javax/swing/DefaultButtonModel.java,
	classpath/javax/swing/JLayeredPane.java,
	classpath/javax/swing/text/DefaultEditorKit.java,
	classpath/javax/swing/text/DefaultCaret.java,
	classpath/javax/swing/text/FieldView.java,
	classpath/javax/swing/text/JTextComponent.java,
	classpath/javax/swing/text/TextAction.java,
	classpath/javax/swing/text/StyleContext.java,
	classpath/javax/swing/text/html/HTMLDocument.java,
	classpath/javax/swing/text/html/MinimalHTMLWriter.java,
	classpath/javax/swing/text/html/ImageView.java,
	classpath/javax/swing/text/html/HTMLEditorKit.java,
	classpath/javax/swing/text/AbstractWriter.java,
	classpath/javax/swing/text/GapContent.java,
	classpath/javax/swing/text/Utilities.java,
	classpath/javax/swing/text/PlainView.java,
	classpath/javax/swing/UIManager.java,
	classpath/javax/swing/JSplitPane.java,
	classpath/javax/swing/JComponent.java,
	classpath/javax/swing/SwingUtilities.java,
	classpath/javax/swing/border/AbstractBorder.java,
	classpath/javax/swing/border/CompoundBorder.java,
	classpath/javax/swing/border/TitledBorder.java,
	classpath/javax/swing/border/MatteBorder.java,
	classpath/javax/swing/border/BevelBorder.java,
	classpath/javax/swing/RepaintManager.java,
	classpath/javax/swing/JTable.java,
	classpath/javax/swing/UIDefaults.java,
	classpath/javax/swing/DefaultDesktopManager.java,
	classpath/javax/swing/JMenu.java,
	classpath/javax/swing/JLabel.java,
	classpath/javax/swing/JSlider.java,
	classpath/javax/swing/plaf/basic/BasicToolBarUI.java,
	classpath/javax/swing/plaf/basic/BasicButtonUI.java,
	classpath/javax/swing/plaf/basic/BasicOptionPaneUI.java,
	classpath/javax/swing/plaf/basic/BasicTextAreaUI.java,
	classpath/javax/swing/plaf/basic/BasicToggleButtonUI.java,
	classpath/javax/swing/plaf/basic/BasicSpinnerUI.java,
	classpath/javax/swing/plaf/basic/BasicSliderUI.java,
	classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java,
	classpath/javax/swing/plaf/basic/BasicComboPopup.java,
	classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java,
	classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java,
	classpath/javax/swing/plaf/basic/BasicProgressBarUI.java,
	classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java,
	classpath/javax/swing/plaf/basic/BasicPanelUI.java,
	classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java,
	classpath/javax/swing/plaf/basic/BasicTreeUI.java,
	classpath/javax/swing/plaf/basic/BasicTableHeaderUI.java,
	classpath/javax/swing/plaf/basic/BasicFileChooserUI.java,
	classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java,
	classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,
	classpath/javax/swing/plaf/basic/BasicListUI.java,
	classpath/javax/swing/plaf/basic/BasicIconFactory.java,
	classpath/javax/swing/plaf/basic/BasicTextUI.java,
	classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,
	classpath/javax/swing/plaf/basic/BasicDirectoryModel.java,
	classpath/javax/swing/plaf/basic/BasicRootPaneUI.java,
	classpath/javax/swing/plaf/basic/BasicTableUI.java,
	classpath/javax/swing/plaf/basic/SharedUIDefaults.java,
	classpath/javax/swing/plaf/multi/MultiComboBoxUI.java,
	classpath/javax/swing/plaf/multi/MultiListUI.java,
	classpath/javax/swing/plaf/multi/MultiSplitPaneUI.java,
	classpath/javax/swing/plaf/multi/MultiFileChooserUI.java,
	classpath/javax/swing/plaf/multi/MultiOptionPaneUI.java,
	classpath/javax/swing/plaf/multi/MultiTabbedPaneUI.java,
	classpath/javax/swing/plaf/multi/MultiLookAndFeel.java,
	classpath/javax/swing/plaf/metal/MetalSliderUI.java,
	classpath/javax/swing/plaf/metal/MetalIconFactory.java,
	classpath/javax/swing/plaf/metal/MetalComboBoxIcon.java,
	classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java,
	classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,
	classpath/javax/swing/plaf/metal/MetalCheckBoxUI.java,
	classpath/javax/swing/plaf/metal/MetalSeparatorUI.java,
	classpath/javax/swing/plaf/metal/MetalBorders.java,
	classpath/javax/swing/plaf/metal/MetalSplitPaneDivider.java,
	classpath/javax/swing/plaf/metal/MetalScrollBarUI.java,
	classpath/javax/swing/plaf/metal/MetalRootPaneUI.java,
	classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java,
	classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java,
	classpath/javax/swing/plaf/metal/MetalToolTipUI.java,
	classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java,
	classpath/javax/swing/plaf/metal/MetalFileChooserUI.java,
	classpath/javax/swing/plaf/metal/MetalUtils.java,
	classpath/javax/swing/plaf/metal/MetalComboBoxButton.java,
	classpath/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java,
	classpath/javax/swing/plaf/metal/MetalButtonUI.java,
	classpath/javax/swing/JPopupMenu.java,
	classpath/javax/swing/JProgressBar.java,
	classpath/javax/swing/WindowConstants.java,
	classpath/javax/swing/JFrame.java,
	classpath/javax/swing/JFileChooser.java,
	classpath/javax/swing/JComboBox.java,
	classpath/javax/swing/event/EventListenerList.java,
	classpath/javax/swing/ListSelectionModel.java,
	classpath/javax/swing/JScrollBar.java,
	classpath/java/text/SimpleDateFormat.java,
	classpath/java/text/NumberFormat.java,
	classpath/java/text/class-dependencies.conf,
	classpath/java/awt/image/ColorModel.java,
	classpath/java/awt/image/BufferedImage.java,
	classpath/java/awt/Window.java,
	classpath/java/awt/ContainerOrderFocusTraversalPolicy.java,
	classpath/java/awt/LightweightDispatcher.java,
	classpath/java/awt/EventDispatchThread.java,
	classpath/java/awt/BasicStroke.java,
	classpath/java/awt/ColorPaintContext.java,
	classpath/java/awt/Container.java,
	classpath/java/awt/TexturePaint.java,
	classpath/java/awt/Component.java, classpath/java/awt/Font.java,
	classpath/java/awt/GraphicsConfiguration.java,
	classpath/java/awt/DefaultKeyboardFocusManager.java,
	classpath/java/awt/print/PrinterJob.java,
	classpath/java/awt/im/InputContext.java,
	classpath/java/awt/dnd/DragGestureRecognizer.java,
	classpath/java/awt/Toolkit.java,
	classpath/java/awt/font/GraphicAttribute.java,
	classpath/java/awt/font/ImageGraphicAttribute.java,
	classpath/java/awt/font/GlyphVector.java,
	classpath/java/awt/font/GlyphMetrics.java,
	classpath/java/awt/font/ShapeGraphicAttribute.java,
	classpath/java/awt/Graphics2D.java,
	classpath/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h,
	classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h,
	classpath/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h,
	classpath/include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h,
	classpath/include/gnu_java_awt_peer_gtk_GtkCanvasPeer.h,
	classpath/include/config.h.in,
	classpath/include/gnu_java_awt_peer_gtk_GdkTextLayout.h,
	classpath/include/gnu_java_awt_peer_gtk_GtkComponentPeer.h,
	classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h,
	classpath/include/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h,
	classpath/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h,
	classpath/include/gnu_java_awt_peer_gtk_GtkImage.h,
	classpath/include/gnu_java_awt_peer_gtk_CairoSurface.h,
	classpath/include/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h:
	Merge from GNU Classpath HEAD.

From-SVN: r114510
This commit is contained in:
Thomas Fitzsimmons
2006-06-09 16:07:07 +00:00
committed by Thomas Fitzsimmons
parent 6c65d7577c
commit 02440ca432
360 changed files with 34743 additions and 9337 deletions
+6
View File
@@ -0,0 +1,6 @@
jarsigner
keytool
Makefile.in
Makefile
tools.zip
appletviewer
+51 -3
View File
@@ -21,6 +21,47 @@ endif
endif
endif
if CREATE_WRAPPERS
bin_SCRIPTS =
bin_PROGRAMS = appletviewer jarsigner keytool
if FOUND_GCJ
LIBJVM = -lgcj
else
if FOUND_CACAO
LIBJVM = -ljvm
else
LIBJVM =
endif
endif
appletviewer_SOURCES = toolwrapper.c
appletviewer_CFLAGS = -Wall \
-DDATA_DIR="\"$(datadir)\"" \
-DPACKAGE="\"$(PACKAGE)\"" \
-DTOOLNAME="\"appletviewer\""
appletviewer_LDFLAGS = -L$(libdir) $(LIBJVM)
jarsigner_SOURCES = toolwrapper.c
jarsigner_CFLAGS = -Wall \
-DDATA_DIR="\"$(datadir)\"" \
-DPACKAGE="\"$(PACKAGE)\"" \
-DTOOLNAME="\"jarsigner\""
jarsigner_LDFLAGS = -L$(libdir) $(LIBJVM)
keytool_SOURCES = toolwrapper.c
keytool_CFLAGS = -Wall \
-DDATA_DIR="\"$(datadir)\"" \
-DPACKAGE="\"$(PACKAGE)\"" \
-DTOOLNAME="\"keytool\""
keytool_LDFLAGS = -L$(libdir) $(LIBJVM)
else
bin_SCRIPTS = appletviewer jarsigner keytool
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
@@ -32,7 +73,7 @@ TOOLS_ZIP = tools.zip
BUILT_SOURCES = $(TOOLS_ZIP)
# The templates that must be included into the generated zip file.
GRMIC_TEMPLATES = $(srcdir)/gnu/classpath/tools/giop/grmic/templates/*.jav
GRMIC_TEMPLATES = $(srcdir)/gnu/classpath/tools/giop/grmic/templates/*.jav
RMIC_TEMPLATES = $(srcdir)/gnu/classpath/tools/rmi/rmic/templates/*.jav
TOOLS_TEMPLATES = $(GRMIC_TEMPLATES) $(RMIC_TEMPLATES)
@@ -76,11 +117,14 @@ dist-hook:
$(TOOLS_ZIP): $(TOOLS_JAVA_FILES)
mkdir -p classes/gnu/classpath/tools/giop/grmic/templates
mkdir -p classes/gnu/classpath/tools/rmi/rmic/templates
mkdir -p classes/gnu/classpath/tools/appletviewer
mkdir -p classes/gnu/classpath/tools/jarsigner
mkdir -p classes/gnu/classpath/tools/keytool
cp $(RMIC_TEMPLATES) classes/gnu/classpath/tools/rmi/rmic/templates
cp $(GRMIC_TEMPLATES) classes/gnu/classpath/tools/giop/grmic/templates
cp $(GRMIC_TEMPLATES) classes/gnu/classpath/tools/giop/grmic/templates
cp $(RMI_HELPS) classes/gnu/classpath/tools/rmi/
cp $(GIOP_HELPS) classes/gnu/classpath/tools/giop/
$(JCOMPILER) -d classes $(TOOLS_JAVA_FILES)
$(JCOMPILER) -d classes $(TOOLS_JAVA_FILES)
(cd classes; \
if test "$(ZIP)" != ""; then $(ZIP) -r ../$(TOOLS_ZIP) .; fi; \
if test "$(FASTJAR)" != ""; then $(FASTJAR) cf ../$(TOOLS_ZIP) .; fi; \
@@ -90,3 +134,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:
:
+316 -33
View File
@@ -14,6 +14,8 @@
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@@ -37,9 +39,12 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
@CREATE_WRAPPERS_TRUE@bin_PROGRAMS = appletviewer$(EXEEXT) \
@CREATE_WRAPPERS_TRUE@ jarsigner$(EXEEXT) keytool$(EXEEXT)
subdir = tools
DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/jarsigner.sh.in $(srcdir)/keytool.sh.in
$(srcdir)/appletviewer.in $(srcdir)/jarsigner.in \
$(srcdir)/keytool.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../../libtool.m4 \
$(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \
@@ -52,18 +57,53 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES = jarsigner.sh keytool.sh
SOURCES =
DIST_SOURCES =
CONFIG_CLEAN_FILES = appletviewer jarsigner keytool
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" \
"$(DESTDIR)$(TOOLSdir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS)
am__appletviewer_SOURCES_DIST = toolwrapper.c
@CREATE_WRAPPERS_TRUE@am_appletviewer_OBJECTS = \
@CREATE_WRAPPERS_TRUE@ appletviewer-toolwrapper.$(OBJEXT)
appletviewer_OBJECTS = $(am_appletviewer_OBJECTS)
appletviewer_LDADD = $(LDADD)
am__jarsigner_SOURCES_DIST = toolwrapper.c
@CREATE_WRAPPERS_TRUE@am_jarsigner_OBJECTS = \
@CREATE_WRAPPERS_TRUE@ jarsigner-toolwrapper.$(OBJEXT)
jarsigner_OBJECTS = $(am_jarsigner_OBJECTS)
jarsigner_LDADD = $(LDADD)
am__keytool_SOURCES_DIST = toolwrapper.c
@CREATE_WRAPPERS_TRUE@am_keytool_OBJECTS = \
@CREATE_WRAPPERS_TRUE@ keytool-toolwrapper.$(OBJEXT)
keytool_OBJECTS = $(am_keytool_OBJECTS)
keytool_LDADD = $(LDADD)
binSCRIPT_INSTALL = $(INSTALL_SCRIPT)
SCRIPTS = $(bin_SCRIPTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(appletviewer_SOURCES) $(jarsigner_SOURCES) \
$(keytool_SOURCES)
DIST_SOURCES = $(am__appletviewer_SOURCES_DIST) \
$(am__jarsigner_SOURCES_DIST) $(am__keytool_SOURCES_DIST)
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(TOOLSdir)"
TOOLSDATA_INSTALL = $(INSTALL_DATA)
DATA = $(TOOLS_DATA)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
@@ -75,8 +115,6 @@ AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BUILD_CLASS_FILES_FALSE = @BUILD_CLASS_FILES_FALSE@
BUILD_CLASS_FILES_TRUE = @BUILD_CLASS_FILES_TRUE@
CAIRO_CFLAGS = @CAIRO_CFLAGS@
CAIRO_LIBS = @CAIRO_LIBS@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
@@ -103,8 +141,12 @@ CREATE_JNI_HEADERS_FALSE = @CREATE_JNI_HEADERS_FALSE@
CREATE_JNI_HEADERS_TRUE = @CREATE_JNI_HEADERS_TRUE@
CREATE_JNI_LIBRARIES_FALSE = @CREATE_JNI_LIBRARIES_FALSE@
CREATE_JNI_LIBRARIES_TRUE = @CREATE_JNI_LIBRARIES_TRUE@
CREATE_PLUGIN_FALSE = @CREATE_PLUGIN_FALSE@
CREATE_PLUGIN_TRUE = @CREATE_PLUGIN_TRUE@
CREATE_QT_PEER_LIBRARIES_FALSE = @CREATE_QT_PEER_LIBRARIES_FALSE@
CREATE_QT_PEER_LIBRARIES_TRUE = @CREATE_QT_PEER_LIBRARIES_TRUE@
CREATE_WRAPPERS_FALSE = @CREATE_WRAPPERS_FALSE@
CREATE_WRAPPERS_TRUE = @CREATE_WRAPPERS_TRUE@
CREATE_XMLJ_LIBRARY_FALSE = @CREATE_XMLJ_LIBRARY_FALSE@
CREATE_XMLJ_LIBRARY_TRUE = @CREATE_XMLJ_LIBRARY_TRUE@
CXX = @CXX@
@@ -127,6 +169,8 @@ EXAMPLESDIR = @EXAMPLESDIR@
EXEEXT = @EXEEXT@
FASTJAR = @FASTJAR@
FIND = @FIND@
FOUND_CACAO_FALSE = @FOUND_CACAO_FALSE@
FOUND_CACAO_TRUE = @FOUND_CACAO_TRUE@
FOUND_ECJ_FALSE = @FOUND_ECJ_FALSE@
FOUND_ECJ_TRUE = @FOUND_ECJ_TRUE@
FOUND_GCJX_FALSE = @FOUND_GCJX_FALSE@
@@ -142,9 +186,8 @@ FREETYPE2_LIBS = @FREETYPE2_LIBS@
GCJ = @GCJ@
GCJX = @GCJX@
GJDOC = @GJDOC@
GTK_CAIRO_ENABLED = @GTK_CAIRO_ENABLED@
GTK_CAIRO_FALSE = @GTK_CAIRO_FALSE@
GTK_CAIRO_TRUE = @GTK_CAIRO_TRUE@
GLIB_CFLAGS = @GLIB_CFLAGS@
GLIB_LIBS = @GLIB_LIBS@
GTK_CFLAGS = @GTK_CFLAGS@
GTK_LIBS = @GTK_LIBS@
INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@
@@ -166,6 +209,7 @@ KJC = @KJC@
LDFLAGS = @LDFLAGS@
LIBDEBUG = @LIBDEBUG@
LIBICONV = @LIBICONV@
LIBMAGIC = @LIBMAGIC@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
@@ -179,6 +223,8 @@ MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
MKDIR = @MKDIR@
MOC = @MOC@
MOZILLA_CFLAGS = @MOZILLA_CFLAGS@
MOZILLA_LIBS = @MOZILLA_LIBS@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
@@ -192,6 +238,7 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@
PERL = @PERL@
PKG_CONFIG = @PKG_CONFIG@
PLUGIN_DIR = @PLUGIN_DIR@
QT_CFLAGS = @QT_CFLAGS@
QT_LIBS = @QT_LIBS@
RANLIB = @RANLIB@
@@ -211,11 +258,13 @@ USER_SPECIFIED_JAVAH_TRUE = @USER_SPECIFIED_JAVAH_TRUE@
USE_PREBUILT_GLIBJ_ZIP_FALSE = @USE_PREBUILT_GLIBJ_ZIP_FALSE@
USE_PREBUILT_GLIBJ_ZIP_TRUE = @USE_PREBUILT_GLIBJ_ZIP_TRUE@
VERSION = @VERSION@
VM_BINARY = @VM_BINARY@
WARNING_CFLAGS = @WARNING_CFLAGS@
XML_CFLAGS = @XML_CFLAGS@
XML_LIBS = @XML_LIBS@
XSLT_CFLAGS = @XSLT_CFLAGS@
XSLT_LIBS = @XSLT_LIBS@
XTEST_LIBS = @XTEST_LIBS@
X_CFLAGS = @X_CFLAGS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_LIBS = @X_LIBS@
@@ -277,6 +326,33 @@ GLIBJ_CLASSPATH = '$(top_builddir)/lib':'$(top_builddir)/lib/glibj.zip'
# Setup the compiler to use the GNU Classpath library we just build
@FOUND_GCJ_TRUE@JCOMPILER = $(GCJ) -encoding UTF-8 --bootclasspath $(GLIBJ_CLASSPATH) --classpath . -C
@CREATE_WRAPPERS_FALSE@bin_SCRIPTS = appletviewer jarsigner keytool
@CREATE_WRAPPERS_TRUE@bin_SCRIPTS =
@CREATE_WRAPPERS_TRUE@@FOUND_CACAO_FALSE@@FOUND_GCJ_FALSE@LIBJVM =
@CREATE_WRAPPERS_TRUE@@FOUND_CACAO_TRUE@@FOUND_GCJ_FALSE@LIBJVM = -ljvm
@CREATE_WRAPPERS_TRUE@@FOUND_GCJ_TRUE@LIBJVM = -lgcj
@CREATE_WRAPPERS_TRUE@appletviewer_SOURCES = toolwrapper.c
@CREATE_WRAPPERS_TRUE@appletviewer_CFLAGS = -Wall \
@CREATE_WRAPPERS_TRUE@ -DDATA_DIR="\"$(datadir)\"" \
@CREATE_WRAPPERS_TRUE@ -DPACKAGE="\"$(PACKAGE)\"" \
@CREATE_WRAPPERS_TRUE@ -DTOOLNAME="\"appletviewer\""
@CREATE_WRAPPERS_TRUE@appletviewer_LDFLAGS = -L$(libdir) $(LIBJVM)
@CREATE_WRAPPERS_TRUE@jarsigner_SOURCES = toolwrapper.c
@CREATE_WRAPPERS_TRUE@jarsigner_CFLAGS = -Wall \
@CREATE_WRAPPERS_TRUE@ -DDATA_DIR="\"$(datadir)\"" \
@CREATE_WRAPPERS_TRUE@ -DPACKAGE="\"$(PACKAGE)\"" \
@CREATE_WRAPPERS_TRUE@ -DTOOLNAME="\"jarsigner\""
@CREATE_WRAPPERS_TRUE@jarsigner_LDFLAGS = -L$(libdir) $(LIBJVM)
@CREATE_WRAPPERS_TRUE@keytool_SOURCES = toolwrapper.c
@CREATE_WRAPPERS_TRUE@keytool_CFLAGS = -Wall \
@CREATE_WRAPPERS_TRUE@ -DDATA_DIR="\"$(datadir)\"" \
@CREATE_WRAPPERS_TRUE@ -DPACKAGE="\"$(PACKAGE)\"" \
@CREATE_WRAPPERS_TRUE@ -DTOOLNAME="\"keytool\""
@CREATE_WRAPPERS_TRUE@keytool_LDFLAGS = -L$(libdir) $(LIBJVM)
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
@@ -288,7 +364,7 @@ TOOLS_ZIP = tools.zip
BUILT_SOURCES = $(TOOLS_ZIP)
# The templates that must be included into the generated zip file.
GRMIC_TEMPLATES = $(srcdir)/gnu/classpath/tools/giop/grmic/templates/*.jav
GRMIC_TEMPLATES = $(srcdir)/gnu/classpath/tools/giop/grmic/templates/*.jav
RMIC_TEMPLATES = $(srcdir)/gnu/classpath/tools/rmi/rmic/templates/*.jav
TOOLS_TEMPLATES = $(GRMIC_TEMPLATES) $(RMIC_TEMPLATES)
@@ -312,6 +388,7 @@ all: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
@@ -341,10 +418,157 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
jarsigner.sh: $(top_builddir)/config.status $(srcdir)/jarsigner.sh.in
appletviewer: $(top_builddir)/config.status $(srcdir)/appletviewer.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
keytool.sh: $(top_builddir)/config.status $(srcdir)/keytool.sh.in
jarsigner: $(top_builddir)/config.status $(srcdir)/jarsigner.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
keytool: $(top_builddir)/config.status $(srcdir)/keytool.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
|| test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
installcheck-binPROGRAMS: $(bin_PROGRAMS)
bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \
case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \
*" $$p "* | *" $(srcdir)/$$p "*) continue;; \
esac; \
f=`echo "$$p" | \
sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
for opt in --help --version; do \
if "$(DESTDIR)$(bindir)/$$f" $$opt >c$${pid}_.out \
2>c$${pid}_.err </dev/null \
&& test -n "`cat c$${pid}_.out`" \
&& test -z "`cat c$${pid}_.err`"; then :; \
else echo "$$f does not support $$opt" 1>&2; bad=1; fi; \
done; \
done; rm -f c$${pid}_.???; exit $$bad
appletviewer$(EXEEXT): $(appletviewer_OBJECTS) $(appletviewer_DEPENDENCIES)
@rm -f appletviewer$(EXEEXT)
$(LINK) $(appletviewer_LDFLAGS) $(appletviewer_OBJECTS) $(appletviewer_LDADD) $(LIBS)
jarsigner$(EXEEXT): $(jarsigner_OBJECTS) $(jarsigner_DEPENDENCIES)
@rm -f jarsigner$(EXEEXT)
$(LINK) $(jarsigner_LDFLAGS) $(jarsigner_OBJECTS) $(jarsigner_LDADD) $(LIBS)
keytool$(EXEEXT): $(keytool_OBJECTS) $(keytool_DEPENDENCIES)
@rm -f keytool$(EXEEXT)
$(LINK) $(keytool_LDFLAGS) $(keytool_OBJECTS) $(keytool_LDADD) $(LIBS)
install-binSCRIPTS: $(bin_SCRIPTS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_SCRIPTS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
if test -f $$d$$p; then \
f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
echo " $(binSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(bindir)/$$f'"; \
$(binSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(bindir)/$$f"; \
else :; fi; \
done
uninstall-binSCRIPTS:
@$(NORMAL_UNINSTALL)
@list='$(bin_SCRIPTS)'; for p in $$list; do \
f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/appletviewer-toolwrapper.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jarsigner-toolwrapper.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keytool-toolwrapper.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
appletviewer-toolwrapper.o: toolwrapper.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(appletviewer_CFLAGS) $(CFLAGS) -MT appletviewer-toolwrapper.o -MD -MP -MF "$(DEPDIR)/appletviewer-toolwrapper.Tpo" -c -o appletviewer-toolwrapper.o `test -f 'toolwrapper.c' || echo '$(srcdir)/'`toolwrapper.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/appletviewer-toolwrapper.Tpo" "$(DEPDIR)/appletviewer-toolwrapper.Po"; else rm -f "$(DEPDIR)/appletviewer-toolwrapper.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='toolwrapper.c' object='appletviewer-toolwrapper.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(appletviewer_CFLAGS) $(CFLAGS) -c -o appletviewer-toolwrapper.o `test -f 'toolwrapper.c' || echo '$(srcdir)/'`toolwrapper.c
appletviewer-toolwrapper.obj: toolwrapper.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(appletviewer_CFLAGS) $(CFLAGS) -MT appletviewer-toolwrapper.obj -MD -MP -MF "$(DEPDIR)/appletviewer-toolwrapper.Tpo" -c -o appletviewer-toolwrapper.obj `if test -f 'toolwrapper.c'; then $(CYGPATH_W) 'toolwrapper.c'; else $(CYGPATH_W) '$(srcdir)/toolwrapper.c'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/appletviewer-toolwrapper.Tpo" "$(DEPDIR)/appletviewer-toolwrapper.Po"; else rm -f "$(DEPDIR)/appletviewer-toolwrapper.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='toolwrapper.c' object='appletviewer-toolwrapper.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(appletviewer_CFLAGS) $(CFLAGS) -c -o appletviewer-toolwrapper.obj `if test -f 'toolwrapper.c'; then $(CYGPATH_W) 'toolwrapper.c'; else $(CYGPATH_W) '$(srcdir)/toolwrapper.c'; fi`
jarsigner-toolwrapper.o: toolwrapper.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(jarsigner_CFLAGS) $(CFLAGS) -MT jarsigner-toolwrapper.o -MD -MP -MF "$(DEPDIR)/jarsigner-toolwrapper.Tpo" -c -o jarsigner-toolwrapper.o `test -f 'toolwrapper.c' || echo '$(srcdir)/'`toolwrapper.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/jarsigner-toolwrapper.Tpo" "$(DEPDIR)/jarsigner-toolwrapper.Po"; else rm -f "$(DEPDIR)/jarsigner-toolwrapper.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='toolwrapper.c' object='jarsigner-toolwrapper.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(jarsigner_CFLAGS) $(CFLAGS) -c -o jarsigner-toolwrapper.o `test -f 'toolwrapper.c' || echo '$(srcdir)/'`toolwrapper.c
jarsigner-toolwrapper.obj: toolwrapper.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(jarsigner_CFLAGS) $(CFLAGS) -MT jarsigner-toolwrapper.obj -MD -MP -MF "$(DEPDIR)/jarsigner-toolwrapper.Tpo" -c -o jarsigner-toolwrapper.obj `if test -f 'toolwrapper.c'; then $(CYGPATH_W) 'toolwrapper.c'; else $(CYGPATH_W) '$(srcdir)/toolwrapper.c'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/jarsigner-toolwrapper.Tpo" "$(DEPDIR)/jarsigner-toolwrapper.Po"; else rm -f "$(DEPDIR)/jarsigner-toolwrapper.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='toolwrapper.c' object='jarsigner-toolwrapper.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(jarsigner_CFLAGS) $(CFLAGS) -c -o jarsigner-toolwrapper.obj `if test -f 'toolwrapper.c'; then $(CYGPATH_W) 'toolwrapper.c'; else $(CYGPATH_W) '$(srcdir)/toolwrapper.c'; fi`
keytool-toolwrapper.o: toolwrapper.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(keytool_CFLAGS) $(CFLAGS) -MT keytool-toolwrapper.o -MD -MP -MF "$(DEPDIR)/keytool-toolwrapper.Tpo" -c -o keytool-toolwrapper.o `test -f 'toolwrapper.c' || echo '$(srcdir)/'`toolwrapper.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/keytool-toolwrapper.Tpo" "$(DEPDIR)/keytool-toolwrapper.Po"; else rm -f "$(DEPDIR)/keytool-toolwrapper.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='toolwrapper.c' object='keytool-toolwrapper.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(keytool_CFLAGS) $(CFLAGS) -c -o keytool-toolwrapper.o `test -f 'toolwrapper.c' || echo '$(srcdir)/'`toolwrapper.c
keytool-toolwrapper.obj: toolwrapper.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(keytool_CFLAGS) $(CFLAGS) -MT keytool-toolwrapper.obj -MD -MP -MF "$(DEPDIR)/keytool-toolwrapper.Tpo" -c -o keytool-toolwrapper.obj `if test -f 'toolwrapper.c'; then $(CYGPATH_W) 'toolwrapper.c'; else $(CYGPATH_W) '$(srcdir)/toolwrapper.c'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/keytool-toolwrapper.Tpo" "$(DEPDIR)/keytool-toolwrapper.Po"; else rm -f "$(DEPDIR)/keytool-toolwrapper.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='toolwrapper.c' object='keytool-toolwrapper.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(keytool_CFLAGS) $(CFLAGS) -c -o keytool-toolwrapper.obj `if test -f 'toolwrapper.c'; then $(CYGPATH_W) 'toolwrapper.c'; else $(CYGPATH_W) '$(srcdir)/toolwrapper.c'; fi`
mostlyclean-libtool:
-rm -f *.lo
@@ -372,12 +596,54 @@ uninstall-TOOLSDATA:
echo " rm -f '$(DESTDIR)$(TOOLSdir)/$$f'"; \
rm -f "$(DESTDIR)$(TOOLSdir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS:
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS:
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
@@ -412,9 +678,9 @@ distdir: $(DISTFILES)
check-am: all-am
check: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) check-am
all-am: Makefile $(DATA)
all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(DATA)
installdirs:
for dir in "$(DESTDIR)$(TOOLSdir)"; do \
for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(TOOLSdir)"; do \
test -z "$$dir" || $(mkdir_p) "$$dir"; \
done
install: $(BUILT_SOURCES)
@@ -445,11 +711,14 @@ maintainer-clean-generic:
-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
clean: clean-am
clean-am: clean-generic clean-libtool clean-local mostlyclean-am
clean-am: clean-binPROGRAMS clean-generic clean-libtool clean-local \
mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-libtool
distclean-am: clean-am distclean-compile distclean-generic \
distclean-libtool distclean-tags
dvi: dvi-am
@@ -463,21 +732,23 @@ info-am:
install-data-am: install-TOOLSDATA
install-exec-am:
install-exec-am: install-binPROGRAMS install-binSCRIPTS
install-info: install-info-am
install-man:
installcheck-am:
installcheck-am: installcheck-binPROGRAMS installcheck-binSCRIPTS
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
@@ -487,18 +758,23 @@ ps: ps-am
ps-am:
uninstall-am: uninstall-TOOLSDATA uninstall-info-am
uninstall-am: uninstall-TOOLSDATA uninstall-binPROGRAMS \
uninstall-binSCRIPTS uninstall-info-am
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
clean-local dist-hook distclean distclean-generic \
distclean-libtool distdir dvi dvi-am html html-am info info-am \
install install-TOOLSDATA install-am install-data \
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libtool clean-local ctags dist-hook \
distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-TOOLSDATA install-am \
install-binPROGRAMS install-binSCRIPTS install-data \
install-data-am install-exec install-exec-am install-info \
install-info-am install-man install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-generic \
mostlyclean-libtool pdf pdf-am ps ps-am uninstall \
uninstall-TOOLSDATA uninstall-am uninstall-info-am
installcheck-am installcheck-binPROGRAMS \
installcheck-binSCRIPTS installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-TOOLSDATA uninstall-am \
uninstall-binPROGRAMS uninstall-binSCRIPTS uninstall-info-am
@FOUND_ECJ_FALSE@@FOUND_GCJX_FALSE@@FOUND_GCJ_FALSE@@FOUND_JIKES_FALSE@error dunno how to setup the JCOMPILER and compile
@@ -523,11 +799,14 @@ dist-hook:
$(TOOLS_ZIP): $(TOOLS_JAVA_FILES)
mkdir -p classes/gnu/classpath/tools/giop/grmic/templates
mkdir -p classes/gnu/classpath/tools/rmi/rmic/templates
mkdir -p classes/gnu/classpath/tools/appletviewer
mkdir -p classes/gnu/classpath/tools/jarsigner
mkdir -p classes/gnu/classpath/tools/keytool
cp $(RMIC_TEMPLATES) classes/gnu/classpath/tools/rmi/rmic/templates
cp $(GRMIC_TEMPLATES) classes/gnu/classpath/tools/giop/grmic/templates
cp $(GRMIC_TEMPLATES) classes/gnu/classpath/tools/giop/grmic/templates
cp $(RMI_HELPS) classes/gnu/classpath/tools/rmi/
cp $(GIOP_HELPS) classes/gnu/classpath/tools/giop/
$(JCOMPILER) -d classes $(TOOLS_JAVA_FILES)
$(JCOMPILER) -d classes $(TOOLS_JAVA_FILES)
(cd classes; \
if test "$(ZIP)" != ""; then $(ZIP) -r ../$(TOOLS_ZIP) .; fi; \
if test "$(FASTJAR)" != ""; then $(FASTJAR) cf ../$(TOOLS_ZIP) .; fi; \
@@ -537,6 +816,10 @@ $(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:
:
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
+46
View File
@@ -0,0 +1,46 @@
#!/bin/sh
## Copyright (C) 2006 Free Software Foundation, Inc.
##
## This file is a 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 of the License, 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; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, 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.
##
## A simple shell script to launch the GNU Classpath appletviewer tool.
##
prefix=@prefix@
tools_dir=@datadir@/@PACKAGE@
tools_cp=${tools_dir}/tools.zip
exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" gnu.classpath.tools.appletviewer.Main $@
@@ -0,0 +1,81 @@
/* AppletClassLoader -- a loader for applet classes
Copyright (C) 2004, 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.appletviewer;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
public class AppletClassLoader extends URLClassLoader
{
/**
* Constructs a new <code>AppletLoader</code> object.
*
* @param codebase the codebase of the applet
* @param archives the urls to add to the search path
*/
public AppletClassLoader(URL codebase, ArrayList archives)
{
super(new URL[0]);
for (int count = 0; count < archives.size(); count++)
addURL((URL) archives.get(count));
addURL(codebase);
}
/**
* Finds the specified class. This method should be overridden by
* class loader implementations that follow the delegation model for
* loading classes, and will be invoked by the loadClass method after
* checking the parent class loader for the requested class. The default
* implementation throws a ClassNotFoundException.
*
* (description copied from java.lang.ClassLoader.findClass(String))
*
* @param name The name of the class.
*
* @return the resulting <code>Class</code> object.
*
* @exception ClassNotFoundException if the class is not found.
*/
protected Class findClass(String name) throws ClassNotFoundException
{
return super.findClass(name);
}
}
@@ -0,0 +1,95 @@
/* AppletSecurityManager.java -- an applet security manager
Copyright (C) 2004, 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.appletviewer;
import java.io.FilePermission;
import java.net.SocketPermission;
import java.security.Permission;
import java.security.SecurityPermission;
import java.util.PropertyPermission;
class AppletSecurityManager extends SecurityManager
{
private boolean plugin;
AppletSecurityManager(boolean plugin)
{
this.plugin = plugin;
}
public void checkPermission(Permission permission)
{
if (permission == null)
throw new NullPointerException();
// FIXME: we need to restrict this.
//
// libgcj asks for "java.io.FilePermission <<ALL FILES>> execute"
// to be able to execute "addr2line" to get proper stack traces.
if (permission instanceof FilePermission)
return;
// FIXME: we need to restrict this.
if (permission instanceof SecurityPermission)
return;
// FIXME: is this really needed ?
if (permission instanceof PropertyPermission)
return;
// Needed to allow to access AWT event queue.
if (permission.getName().equals("accessEventQueue"))
return;
// Needed to create a class loader for each codebase.
if (permission.getName().equals("createClassLoader"))
return;
// FIXME: we need to allow access to codebase here.
if (permission instanceof SocketPermission // for net access
|| permission instanceof RuntimePermission) // for checkWrite(FileDescriptor)
return;
if (! plugin && permission.getName().equals("exitVM"))
return;
// Reject all other permissions.
throw new SecurityException();
}
}
@@ -0,0 +1,489 @@
/* AppletTag.java -- a representation of an HTML APPLET tag
Copyright (C) 2003, 2004, 2005, 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.appletviewer;
import gnu.xml.dom.html2.DomHTMLAppletElement;
import gnu.xml.dom.html2.DomHTMLEmbedElement;
import gnu.xml.dom.html2.DomHTMLObjectElement;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
/**
* @author Lillian Angel (langel@redhat.com)
* @author Thomas Fitzsimmons (fitzsim@redhat.com)
*/
class AppletTag
{
/**
* The document base of this applet.
*/
URL documentbase;
/**
* name of applet tag.
*/
String name = "";
/**
* code of applet tag.
*/
String code = "";
/**
* codebase of applet tag.
*/
String codebase = "";
/**
* The archives.
*/
ArrayList archives = new ArrayList();
/**
* The parameters.
*/
HashMap parameters = new HashMap();
/**
* The screen size.
*/
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
/**
* Default constructor.
*/
AppletTag()
{
// Do nothing.
}
/**
* Constructs an AppletTag and parses the given applet element.
*
* @param appElement - the Applet element to parse.
*/
AppletTag(DomHTMLAppletElement appElement)
{
name = appElement.getName();
parameters.put("name", name);
parameters.put("object", appElement.getObject());
parameters.put("align", appElement.getAlign());
parameters.put("alt", appElement.getAlt());
parameters.put("height", appElement.getHeight());
parameters.put("hspace", Integer.toString(appElement.getHspace()));
parameters.put("vspace", Integer.toString(appElement.getVspace()));
parameters.put("width", appElement.getWidth());
TagParser.parseParams(appElement, this);
if (code.equals(""))
{
code = appElement.getCode();
if (code.equals(""))
code = appElement.getCls();
}
// Must initialize codebase before archives
if (codebase.equals(""))
{
codebase = appElement.getCodeBase();
if (codebase.equals(""))
codebase = appElement.getSrc();
}
if (archives.size() == 0)
{
String arcs = "";
String arch = appElement.getArchive();
if (code.indexOf(".") < 0)
arcs = code + ".jar";
if (!arch.equals(""))
arcs += "," + arch;
if (!arcs.equals(""))
archives = TagParser.parseArchives(arcs, this);
}
}
/**
* Constructs an AppletTag and parses the given embed element.
*
* @param embElement - the Embed element to parse.
*/
AppletTag(DomHTMLEmbedElement embElement)
{
// In an EMBED tag, a parameter is any non-standard attribute. This
// is a problem for applets that take parameters named "code",
// "codebase", "archive", "object", or "type". The solution is to
// allow the same attributes, prefixed by "java_". The presence of
// a "java_" attribute indicates that the non-prefixed attribute
// should be interpreted as a parameter. For example if "java_code"
// and "code" attributes are present in the EMBED tag then the
// "code" attribute is interpreted as a parameter.
name = embElement.getName();
parameters.put("name", name);
String jobj = embElement.getJavaObject();
if (!jobj.equals(""))
parameters.put("java_object", jobj);
else
parameters.put("object", embElement.getObject());
parameters.put("width", embElement.getWidth());
parameters.put("height", embElement.getHeight());
parameters.put("align", embElement.getAlign());
parameters.put("alt", embElement.getAlt());
parameters.put("hspace", Integer.toString(embElement.getHspace()));
parameters.put("mayscript", embElement.getMayscript());
parameters.put("pluginspage", embElement.getPluginsPage());
parameters.put("title", embElement.getTitle());
parameters.put("type", embElement.getType());
parameters.put("java_type", embElement.getJavaType());
parameters.put("vspace", Integer.toString(embElement.getVspace()));
TagParser.parseParams(embElement, this);
// Must initialize codebase before archives
if (codebase.equals(""))
{
String javacb = embElement.getJavaCodeBase();
if (!javacb.equals(""))
codebase = javacb;
else
codebase = embElement.getCodeBase();
}
if (code.equals(""))
{
String jcode = embElement.getJavaCode();
if (!jcode.equals(""))
code = jcode;
else
code = embElement.getCode();
}
if (archives.size() == 0)
{
String arcs = "";
String jarch = embElement.getJavaArchive();
String arch = embElement.getArchive();
if (code.indexOf(".") < 0)
arcs = code + ".jar";
if (!jarch.equals(""))
arcs += "," + jarch;
else if (!arch.equals(""))
arcs += "," + arch;
if (!arcs.equals(""))
archives = TagParser.parseArchives(arcs, this);
}
}
/**
* Constructs an AppletTag and parses the given object element.
*
* @param objElement - the Object element to parse.
*/
AppletTag(DomHTMLObjectElement objElement)
{
// In an OBJECT tag, a parameter is any non-standard attribute. This
// is a problem for applets that take parameters named "code",
// "codebase", "archive", "object", or "type". The solution is to
// allow the same attributes, prefixed by "java_". The presence of
// a "java_" attribute indicates that the non-prefixed attribute
// should be interpreted as a parameter. For example if "java_code"
// and "code" attributes are present in the OBJECT tag then the
// "code" attribute is interpreted as a parameter.
name = objElement.getName();
parameters.put("name", name);
String jobj = objElement.getJavaObject();
if (!jobj.equals(""))
parameters.put("java_object", jobj);
else
parameters.put("object", objElement.getObject());
parameters.put("type", objElement.getType());
parameters.put("java_type", objElement.getJavaType());
parameters.put("align", objElement.getAlign());
parameters.put("codetype", objElement.getCodeType());
parameters.put("data", objElement.getData());
parameters.put("declare", Boolean.toString(objElement.getDeclare()));
parameters.put("height", objElement.getHeight());
parameters.put("hspace", Integer.toString(objElement.getHspace()));
parameters.put("border", objElement.getBorder());
parameters.put("standby", objElement.getStandby());
parameters.put("tabindex", Integer.toString(objElement.getTabIndex()));
parameters.put("usemap", objElement.getUseMap());
parameters.put("vspace", Integer.toString(objElement.getVspace()));
parameters.put("width", objElement.getWidth());
parameters.put("mayscript", objElement.getMayscript());
parameters.put("scriptable", objElement.getScriptable());
TagParser.parseParams(objElement, this);
// Must initialize codebase before archives
if (codebase.equals(""))
{
String javacb = objElement.getJavaCodeBase();
if (! javacb.equals(""))
codebase = javacb;
else
codebase = objElement.getCodeBase();
}
if (code.equals(""))
{
String jcode = objElement.getJavaCode();
if (!jcode.equals(""))
code = jcode;
else
code = objElement.getCode();
}
if (archives.size() == 0)
{
String arcs = "";
String jarch = objElement.getJavaArchive();
String arch = objElement.getArchive();
if (code.indexOf(".") < 0)
arcs = code + ".jar";
if (!jarch.equals(""))
arcs += "," + jarch;
else if (!arch.equals(""))
arcs += "," + arch;
if (!arcs.equals(""))
archives = TagParser.parseArchives(arcs, this);
}
}
/**
* String representation of the tag.
*
* @return the string representation.
*/
public String toString()
{
return (" name=" + name + "\n" + " code=" + code + "\n" + " codebase="
+ codebase + "\n" + " archive=" + archives + "\n" + " parameters="
+ parameters + "\n" + " documentbase=" + documentbase + "\n");
}
/**
* Returns the size of the applet.
*
* @return the size.
*/
Dimension getSize()
{
Dimension size = new Dimension(320, 200);
try
{
String widthStr = (String) parameters.get("width");
if (widthStr != null && ! widthStr.equals(""))
{
if (widthStr.charAt(widthStr.length() - 1) == '%')
{
double p = NumberFormat.getPercentInstance(Locale.US).parse(widthStr).intValue() / 100.0;
size.width = (int)(p * screenSize.width);
}
else
size.width = NumberFormat.getInstance(Locale.US).parse(widthStr).intValue();
}
}
catch (ParseException e)
{
// Use default.
}
try
{
String heightStr = (String) parameters.get("height");
if (heightStr != null && !heightStr.equals(""))
{
if (heightStr.charAt(heightStr.length() - 1) == '%')
{
double p = NumberFormat.getPercentInstance(Locale.US).parse(heightStr).intValue() / 100.0;
size.height = (int) (p * screenSize.height);
}
else
size.height = NumberFormat.getInstance(Locale.US).parse(heightStr).intValue();
}
}
catch (ParseException e)
{
// Use default.
}
return size;
}
/**
* Gets the code base.
*
* @return the codebase.
*/
String getCodeBase()
{
return codebase;
}
/**
* Gets the archive list.
*
* @return the archive list.
*/
ArrayList getArchives()
{
return archives;
}
/**
* Gets the code.
*
* @return the code.
*/
String getCode()
{
return code;
}
/**
* Gets the document base.
*
* @return the document base.
*/
URL getDocumentBase()
{
return documentbase;
}
/**
* Gets the specified parameter.
*
* @param name - the specified parameter.
* @return the parameter.
*/
String getParameter(String name)
{
return (String) parameters.get(name.toLowerCase());
}
/**
* Prepends the base to the codebase.
*
* @return the new URL.
*/
URL prependCodeBase(String base) throws MalformedURLException
{
if (documentbase == null)
documentbase = TagParser.db;
URL fullcodebase;
//If no codebase was specified, default to documentbase.
if (codebase.equals(""))
{
if (documentbase.getFile().endsWith(File.separator))
fullcodebase = documentbase;
else
{
String dirname = documentbase.getFile();
if (dirname.indexOf(".") < 0)
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
{
// codebase was specified.
URL codebaseURL = new URL(documentbase, codebase);
if ("file".equals(codebaseURL.getProtocol()))
{
if (new File(codebaseURL.getFile()).isDirectory() && !codebase.endsWith(File.separator))
fullcodebase = new URL(documentbase, codebase + File.separator);
else
fullcodebase = new URL(documentbase, codebase);
}
else if (codebase.endsWith(File.separator))
fullcodebase = new URL(documentbase, codebase);
else
fullcodebase = new URL(documentbase, codebase + File.separator);
}
return new URL(fullcodebase, base);
}
}
@@ -0,0 +1,66 @@
/* AppletWarning -- a security warning message display dialog
Copyright (C) 2003, 2004, 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.appletviewer;
import javax.swing.JOptionPane;
/**
* @author Michael Koch (konqueror@gmx.de)
*/
public class AppletWarning
{
private static String TITLE = "WARNING";
private static boolean showWarning = false;
private static String MESSAGE =
"The current version of this applet plugin does not provide\n" +
"a security manager capable of handling Java (tm) applets. Applets\n" +
"have UNRESTRICTED access to your computer. This means they can do\n" +
"anything you can do, like deleting all your important data.\n\n" +
"Continue ?";
public static int show()
{
if (showWarning)
return JOptionPane.showConfirmDialog(null, MESSAGE, TITLE,
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
else
return JOptionPane.YES_OPTION;
}
}
@@ -0,0 +1,133 @@
/* CommonAppletContext.java -- a common applet's context
Copyright (C) 2004, 2005, 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.appletviewer;
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AudioClip;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/*
* CommonAppletContext represents the common context stuff for both
* types, plugins and standalone.
*/
abstract class CommonAppletContext
implements AppletContext
{
// FIXME: this needs to be static, and we need one AppletContext per
// Applet.
List applets = new ArrayList();
HashMap streams = new HashMap();
void addApplet(Applet applet)
{
applets.add(applet);
}
///////////////////////////////
//// AppletContext methods ////
///////////////////////////////
public AudioClip getAudioClip(URL url)
{
return Applet.newAudioClip(url);
}
public Image getImage(URL url)
{
return Toolkit.getDefaultToolkit().getImage(url);
}
public Applet getApplet(String name)
{
Applet a;
String appletName;
Iterator i = applets.iterator();
while (i.hasNext())
{
a = (Applet) i.next();
appletName = a.getParameter("name");
if (a != null && appletName != null && appletName.equals(name))
return a;
}
return null;
}
public Enumeration getApplets()
{
return Collections.enumeration(applets);
}
public void showDocument(URL url)
{
showDocument(url, "_self");
}
/*
// FIXME: implement.
public abstract void showDocument (URL url, String target);
// FIXME: implement.
public abstract void showStatus (String status);
*/
public void setStream(String key, InputStream stream)
{
streams.put(key, stream);
}
public InputStream getStream(String key)
{
return (InputStream) streams.get(key);
}
public Iterator getStreamKeys()
{
return streams.keySet().iterator();
}
}
@@ -0,0 +1,138 @@
/* CommonAppletStub.java -- an applet-browser interface class
Copyright (C) 2003, 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.appletviewer;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.applet.Applet;
import java.net.MalformedURLException;
import java.net.URL;
class CommonAppletStub
implements AppletStub
{
private AppletTag tag;
private AppletContext context;
private Applet applet;
CommonAppletStub(AppletTag tag, AppletContext context, Applet applet)
{
this.tag = tag;
this.context = context;
this.applet = applet;
}
////////////////////////////////
////// AppletStub Methods //////
////////////////////////////////
/**
* Tests whether or not this applet is currently active. An applet
* becomes active just before the browser invokes start (), and
* becomes inactive just before the browser invokes stop ().
*
* @return true if applet is active, false otherwise
*/
public boolean isActive()
{
return true;
}
/**
* Returns the basename URL of the document in which this applet is
* embedded.
*
* @return the document base url.
*/
public URL getDocumentBase()
{
return tag.getDocumentBase();
}
/**
* Returns the URL of the code base for this applet.
*
* @return the codebase url
*/
public URL getCodeBase()
{
try
{
return tag.prependCodeBase("");
}
catch (MalformedURLException e)
{
throw new RuntimeException("unknown codebase");
}
}
/**
* Returns the value of the specified parameter that was specified
* in the <code>APPLET</code> tag for this applet.
*
* @param name the key name
*
* @return the key value
*/
public String getParameter(String name)
{
return (String) tag.getParameter(name.toLowerCase());
}
/**
* Returns the applet context for this applet.
*
* @return the context
*/
public AppletContext getAppletContext()
{
return context;
}
/**
* Requests that the applet window for this applet be resized.
*
* @param width the new witdh
* @param height the new height
*/
public void appletResize(int width, int height)
{
applet.setBounds (0, 0, width, height);
}
}
@@ -0,0 +1,175 @@
/* ConsoleDialog -- a console dialog for applets
Copyright (C) 2003, 2004, 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.appletviewer;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* This class is a little dialog showing standard output and standard error output.
*
* @author Michael Koch (konqueror@gmx.de)
*/
public class ConsoleDialog extends Frame
implements ActionListener
{
static class InternalOutputStream extends OutputStream
{
private ConsoleDialog console;
public InternalOutputStream(ConsoleDialog console)
{
super();
this.console = console;
}
public void write(int data) throws IOException
{
console.print(String.valueOf((char) data));
}
}
private TextArea textArea;
private Button buttonClear;
private Button buttonHide;
private PrintStream printStream;
/**
* Creates a console dialog object.
*/
public ConsoleDialog()
{
super(Main.messages.getString("gcjwebplugin.console_title"));
setSize(400, 200);
setLayout(new BorderLayout());
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
hide();
}
});
textArea = new TextArea();
textArea.setEditable(false);
add(textArea);
Panel panel = new Panel();
panel.setLayout(new FlowLayout());
add(panel, BorderLayout.SOUTH);
buttonClear = new Button(Main.messages.getString("gcjwebplugin.console_clear"));
buttonClear.addActionListener(this);
panel.add(buttonClear);
buttonHide = new Button(Main.messages.getString("gcjwebplugin.console_hide"));
buttonHide.addActionListener(this);
panel.add(buttonHide);
printStream = new PrintStream(new InternalOutputStream(this));
clearTextArea();
}
/**
* Clears the content of the textarea and inserts the initial text.
*/
public void clearTextArea()
{
textArea.setText("");
println("java.vm.version: " + System.getProperty("java.vm.version"));
println("java.vm.vendor: " + System.getProperty("java.vm.vendor"));
}
/**
* Print a message into the console dialog.
*
* @param message the message to print.
*/
public void print(String message)
{
textArea.append(message);
}
/**
* Print a line into the console dialog.
*
* @param message the line to print.
*/
public void println(String message)
{
print(message + "\n");
}
/**
* Perform actions on button clicks inside the console dialog.
*
* @param event the event.
*/
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == buttonHide)
hide(); // Hide console window.
else if (event.getSource() == buttonClear)
clearTextArea(); // Clear text area and insert standard messages.
}
/**
* Returns a <code>PrintStream</code> object that prints into the
* console dialog.
*
* @return the <code>PrintStream</code> object.
*/
public PrintStream getPrintStream()
{
return printStream;
}
}
@@ -0,0 +1,53 @@
/* ErrorApplet.java -- an applet to load in case of an error
Copyright (C) 2004, 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.appletviewer;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
public class ErrorApplet extends Applet
{
public ErrorApplet(String message)
{
setLayout(new BorderLayout());
Button button = new Button(message);
add(button);
}
}
@@ -0,0 +1,293 @@
/* Main.java -- a standalone viewer for Java applets
Copyright (C) 2003, 2004, 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.appletviewer;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.applet.Applet;
import java.awt.Dimension;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
class Main
{
/**
* The localized strings are kept in a separate file.
*/
public static final ResourceBundle messages = ResourceBundle.getBundle
("gnu.classpath.tools.appletviewer.MessagesBundle");
private static HashMap classLoaderCache = new HashMap();
private static ClassLoader getClassLoader(URL codebase, ArrayList archives)
{
// Should load class loader each time. It is possible that there
// are more than one applet to be loaded with different archives.
AppletClassLoader loader = new AppletClassLoader(codebase, archives);
classLoaderCache.put(codebase, loader);
return loader;
}
private static String code = null;
private static String codebase = null;
private static String archive = null;
private static List parameters = new ArrayList();
private static Dimension dimensions = new Dimension(-1, -1);
private static String pipeInName = null;
private static String pipeOutName = null;
private static boolean pluginMode = false;
private static Parser parser = null;
static Applet createApplet(AppletTag tag)
{
Applet applet = null;
try
{
ClassLoader loader = getClassLoader(tag.prependCodeBase(""),
tag.getArchives());
String code = tag.getCode();
if (code.endsWith(".class"))
code = code.substring(0, code.length() - 6).replace('/', '.');
Class c = loader.loadClass(code);
applet = (Applet) c.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
if (applet == null)
applet = new ErrorApplet("Error loading applet");
return applet;
}
protected static boolean verbose;
/**
* The main method starting the applet viewer.
*
* @param args the arguments given on the command line.
*
* @exception IOException if an error occurs.
*/
public static void main(String[] args) throws IOException
{
parser = new ClasspathToolParser("appletviewer", true);
parser.setHeader("usage: appletviewer [OPTION] -code CODE | URL...");
OptionGroup attributeGroup = new OptionGroup("Applet tag options");
attributeGroup.add(new Option("code", Main.messages.getString
("gcjwebplugin.code_description"),
"CODE")
{
public void parsed(String argument) throws OptionException
{
code = argument;
}
});
attributeGroup.add(new Option("codebase", Main.messages.getString
("gcjwebplugin.codebase_description"),
"CODEBASE")
{
public void parsed(String argument) throws OptionException
{
codebase = argument;
}
});
attributeGroup.add(new Option("archive", Main.messages.getString
("gcjwebplugin.archive_description"),
"ARCHIVE")
{
public void parsed(String argument) throws OptionException
{
archive = argument;
}
});
attributeGroup.add(new Option("width", Main.messages.getString
("gcjwebplugin.width_description"),
"WIDTH")
{
public void parsed(String argument) throws OptionException
{
dimensions.width = Integer.parseInt(argument);
}
});
attributeGroup.add(new Option("height", Main.messages.getString
("gcjwebplugin.height_description"),
"HEIGHT")
{
public void parsed(String argument) throws OptionException
{
dimensions.height = Integer.parseInt(argument);
}
});
attributeGroup.add(new Option("param", Main.messages.getString
("gcjwebplugin.param_description"),
"NAME,VALUE")
{
public void parsed(String argument) throws OptionException
{
parameters.add(argument);
}
});
OptionGroup pluginGroup = new OptionGroup("Plugin option");
pluginGroup.add(new Option("plugin", Main.messages.getString
("gcjwebplugin.plugin_description"),
"INPUT,OUTPUT")
{
public void parsed(String argument) throws OptionException
{
pluginMode = true;
int comma = argument.indexOf(',');
pipeInName = argument.substring(0, comma);
pipeOutName = argument.substring(comma + 1);
}
});
OptionGroup debuggingGroup = new OptionGroup("Debugging option");
debuggingGroup.add(new Option("verbose", Main.messages.getString
("gcjwebplugin.verbose_description"),
(String) null)
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
OptionGroup compatibilityGroup = new OptionGroup("Compatibility options");
compatibilityGroup.add(new Option("debug", Main.messages.getString
("gcjwebplugin.debug_description"),
(String) null)
{
public void parsed(String argument) throws OptionException
{
// Currently ignored.
}
});
compatibilityGroup.add(new Option("encoding", Main.messages.getString
("gcjwebplugin.encoding_description"),
"CHARSET")
{
public void parsed(String argument) throws OptionException
{
// FIXME: We should probably be using
// java.nio.charset.CharsetDecoder to handle the encoding. What
// is the status of Classpath's implementation?
}
});
parser.add(attributeGroup);
parser.add(pluginGroup);
parser.add(debuggingGroup);
parser.add(compatibilityGroup);
String[] urls = parser.parse(args);
// Print arguments.
printArguments(args);
args = urls;
if (dimensions.height < 0)
dimensions.height = 200;
if (dimensions.width < 0)
dimensions.width = (int) (1.6 * dimensions.height);
//System.setSecurityManager(new AppletSecurityManager(pluginMode));
if (pluginMode)
{
InputStream in;
OutputStream out;
in = new FileInputStream(pipeInName);
out = new FileOutputStream(pipeOutName);
PluginAppletViewer.start(in, out);
}
else
{
if (code == null)
{
// The --code option wasn't given and there are no URL
// arguments so we have nothing to work with.
if (args.length == 0)
{
System.err.println(Main.messages.getString("gcjwebplugin.no_input_files"));
System.exit(1);
}
// Create a standalone appletviewer from a list of URLs.
new StandaloneAppletViewer(args);
}
else
{
// Create a standalone appletviewer from the --code
// option.
new StandaloneAppletViewer(code, codebase, archive, parameters, dimensions);
}
}
}
static void printArguments(String[] args)
{
if (verbose)
{
System.out.println("raw arguments:");
for (int i = 0; i < args.length; i++)
System.out.println(" " + args[i]);
}
}
}
@@ -0,0 +1,72 @@
/* PluginAppletContext.java -- an applet's context within a web browser
Copyright (C) 2003, 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.appletviewer;
import java.net.URL;
import java.io.IOException;
/*
* PluginAppletContext represents the context within a webpage of a
* group of applets that all share the same codebase.
*/
class PluginAppletContext extends CommonAppletContext
{
public void showDocument(URL url, String target)
{
try
{
PluginAppletViewer.write("url " + url + " " + target);
}
catch(IOException e)
{
System.err.println("showDocument failed: " + e);
}
}
public void showStatus(String status)
{
try
{
PluginAppletViewer.write("status " + status);
}
catch(IOException e)
{
System.err.println("showDocument failed: " + e);
}
}
}
@@ -0,0 +1,172 @@
/* PluginAppletViewer.java -- manages embeddable applet windows
Copyright (C) 2003, 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.appletviewer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.util.HashMap;
/**
* PluginAppletViewer communicates through pipes with a web browser
* plugin. A PluginAppletViewer manages applet windows that may be
* embedded into web pages.
*/
class PluginAppletViewer
{
// A mapping of instance IDs to PluginAppletWindows.
static HashMap appletWindows = new HashMap ();
private static BufferedReader pluginInputStream;
private static BufferedWriter pluginOutputStream;
static void start(InputStream inputStream, OutputStream outputStream)
throws MalformedURLException, IOException
{
// Set up input and output pipes. Use UTF-8 encoding.
pluginInputStream =
new BufferedReader(new InputStreamReader(inputStream,
Charset.forName("UTF-8")));
pluginOutputStream =
new BufferedWriter(new OutputStreamWriter(outputStream,
Charset.forName("UTF-8")));
write("running");
// Read first message.
String message = read();
PluginAppletWindow currentWindow = null;
while (true)
{
if (message.startsWith("instance"))
{
// Read applet instance identifier.
String key = message.substring(9);
if (appletWindows.get(key) == null)
appletWindows.put(key, new PluginAppletWindow());
currentWindow = (PluginAppletWindow) appletWindows.get(key);
}
else if (message.startsWith("tag"))
{
int pos = message.indexOf(' ', 4);
String documentbase = message.substring(4, pos);
String tag = message.substring(pos + 1);
currentWindow.setParser(tag, documentbase);
}
else if (message.startsWith("handle"))
{
long handle = Long.parseLong(message.substring(7));
currentWindow.setHandle(handle);
}
else if (message.startsWith("width"))
{
int width = Integer.parseInt(message.substring(6));
currentWindow.setSize(width, currentWindow.getHeight());
}
else if (message.startsWith("height"))
{
int height = Integer.parseInt(message.substring(7));
currentWindow.setSize(currentWindow.getWidth(), height);
}
else if (message.startsWith("destroy"))
{
appletWindows.remove(currentWindow);
currentWindow.dispose();
}
// Read next message.
message = read();
}
}
/**
* Write string to plugin.
*
* @param message the message to write
*
* @exception IOException if an error occurs
*/
static void write(String message) throws IOException
{
pluginOutputStream.write(message, 0, message.length());
pluginOutputStream.newLine();
pluginOutputStream.flush();
System.err.println(" PIPE: applet viewer wrote: " + message);
}
/**
* Read string from plugin.
*
* @return the read string
*
* @exception IOException if an error occurs
*/
static String read() throws IOException
{
String message = pluginInputStream.readLine();
System.err.println(" PIPE: applet viewer read: " + message);
if (message == null || message.equals("shutdown"))
{
// Close input/output channels to plugin.
pluginInputStream.close();
pluginOutputStream.close();
System.err.println("appletviewer: exiting plugin applet viewer");
System.exit(0);
}
return message;
}
}
@@ -0,0 +1,454 @@
/* PluginAppletWindow.java -- an embeddable applet window
Copyright (C) 2003, 2004, 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.appletviewer;
import gnu.java.awt.EmbeddedWindow;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JOptionPane;
class PluginAppletWindow
extends EmbeddedWindow
implements ContainerListener, ComponentListener, MouseListener,
MouseMotionListener, InputMethodListener, HierarchyListener,
HierarchyBoundsListener
{
// This class implements various listeners because the author of an applet
// may attach listeners to it, unaware of the applet's parent (this class).
// So, we must pass all listener events on this plugin applet window to the
// actual applet.
private static HashMap contexts = new HashMap();
private Applet applet;
private TagParser parser;
private AppletTag tag;
PluginAppletWindow()
{
super();
addContainerListener(this);
addComponentListener(this);
addMouseListener(this);
addMouseMotionListener(this);
addInputMethodListener(this);
addHierarchyListener(this);
addHierarchyBoundsListener(this);
}
///////////////////////////////////
/// ContainerListener Methods /////
///////////////////////////////////
/**
* This method is called when a component is added to the container.
*
* @param event the <code>ContainerEvent</code> indicating component
* addition
*/
public void componentAdded(ContainerEvent event)
{
if (applet != null)
{
ContainerListener[] l = applet.getContainerListeners();
for (int i = 0; i < l.length; i++)
l[i].componentAdded(event);
}
}
/**
* This method is called when a component is removed from the container.
*
* @param event the <code>ContainerEvent</code> indicating component removal
*/
public void componentRemoved(ContainerEvent event)
{
if (applet != null)
{
ContainerListener[] l = applet.getContainerListeners();
for (int i = 0; i < l.length; i++)
l[i].componentRemoved(event);
}
}
///////////////////////////////////
/// ComponentListener Methods /////
///////////////////////////////////
/**
* This method is called when the component is resized.
*
* @param event the <code>ComponentEvent</code> indicating the resize
*/
public void componentResized(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentResized(event);
}
}
/**
* This method is called when the component is moved.
*
* @param event the <code>ComponentEvent</code> indicating the move
*/
public void componentMoved(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentMoved(event);
}
}
/**
* This method is called when the component is made visible.
*
* @param event the <code>ComponentEvent</code> indicating the visibility
*/
public void componentShown(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentShown(event);
}
}
/**
* This method is called when the component is hidden.
*
* @param event the <code>ComponentEvent</code> indicating the visibility
*/
public void componentHidden(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentHidden(event);
}
}
///////////////////////////////////
////// MouseListener Methods //////
///////////////////////////////////
/**
* This method is called when the mouse is clicked (pressed and released
* in short succession) on a component.
*
* @param event the <code>MouseEvent</code> indicating the click
*/
public void mouseClicked(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseClicked(event);
}
}
/**
* This method is called when the mouse is pressed over a component.
*
* @param event the <code>MouseEvent</code> for the press
*/
public void mousePressed(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mousePressed(event);
}
}
/**
* This method is called when the mouse is released over a component.
*
* @param event the <code>MouseEvent</code> for the release
*/
public void mouseReleased(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseReleased(event);
}
}
/**
* This method is called when the mouse enters a component.
*
* @param event the <code>MouseEvent</code> for the entry
*/
public void mouseEntered(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseEntered(event);
}
}
/**
* This method is called when the mouse exits a component.
*
* @param event the <code>MouseEvent</code> for the exit
*/
public void mouseExited(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseExited(event);
}
}
///////////////////////////////////
/// MouseMotionListener Methods ///
///////////////////////////////////
/**
* This method is called when the mouse is moved over a component
* while a button has been pressed.
*
* @param event the <code>MouseEvent</code> indicating the motion
*/
public void mouseDragged(MouseEvent event)
{
if (applet != null)
{
MouseMotionListener[] l = applet.getMouseMotionListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseDragged(event);
}
}
/**
* This method is called when the mouse is moved over a component
* while no button is pressed.
*
* @param event the <code>MouseEvent</code> indicating the motion
*/
public void mouseMoved(MouseEvent event)
{
if (applet != null)
{
MouseMotionListener[] l = applet.getMouseMotionListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseMoved(event);
}
}
///////////////////////////////////
/// InputMethodListener Methods ///
///////////////////////////////////
/**
* This method is called when the text is changed.
*
* @param event the <code>InputMethodEvent</code> indicating the text change
*/
public void inputMethodTextChanged(InputMethodEvent event)
{
if (applet != null)
{
InputMethodListener[] l = applet.getInputMethodListeners();
for (int i = 0; i < l.length; i++)
l[i].inputMethodTextChanged(event);
}
}
/**
* This method is called when the cursor position within the text is changed.
*
* @param event the <code>InputMethodEvent</code> indicating the change
*/
public void caretPositionChanged(InputMethodEvent event)
{
if (applet != null)
{
InputMethodListener[] l = applet.getInputMethodListeners();
for (int i = 0; i < l.length; i++)
l[i].caretPositionChanged(event);
}
}
///////////////////////////////////
//// HierarchyListener Methods ////
///////////////////////////////////
/**
* Called when the hierarchy of this component changes. Use
* <code>getChangeFlags()</code> on the event to see what exactly changed.
*
* @param e the event describing the change
*/
public void hierarchyChanged(HierarchyEvent event)
{
if (applet != null)
{
HierarchyListener[] l = applet.getHierarchyListeners();
for (int i = 0; i < l.length; i++)
l[i].hierarchyChanged(event);
}
}
/////////////////////////////////////////
//// HierarchyBoundsListener Methods ////
/////////////////////////////////////////
/**
* Called when an ancestor component of the source is moved.
*
* @param e the event describing the ancestor's motion
*/
public void ancestorMoved(HierarchyEvent e)
{
if (applet != null)
{
HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
for (int i = 0; i < l.length; i++)
l[i].ancestorMoved(e);
}
}
/**
* Called when an ancestor component is resized.
*
* @param e the event describing the ancestor's resizing
*/
public void ancestorResized(HierarchyEvent e)
{
if (applet != null)
{
HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
for (int i = 0; i < l.length; i++)
l[i].ancestorResized(e);
}
}
void setParser(String tag, String documentbase) throws MalformedURLException, IOException
{
URL documentbaseURL = TagParser.getLocationToURL(documentbase);
StringReader in = new StringReader(tag);
this.parser = new TagParser(in, documentbaseURL);
}
// /////////////////////////////////
// //// EmbeddedWindow Method //////
// /////////////////////////////////
/**
* Set the native handle of the window system to embed the window in.
*
* @param handle the native handle.
*/
public void setHandle(long handle)
{
super.setHandle(handle);
addNotify();
ArrayList l = parser.parseAppletTags();
int s = l.size();
for (int i = 0; i < s; i++)
{
tag = (AppletTag) l.get(i);
applet = Main.createApplet(tag);
if (contexts.get(tag.getCodeBase()) == null)
contexts.put(tag.getCodeBase(), new PluginAppletContext());
int result = AppletWarning.show();
if (result == JOptionPane.NO_OPTION)
return;
add(applet);
AppletContext context = (AppletContext) contexts.get(tag.getCodeBase());
((PluginAppletContext) context).addApplet(applet);
applet.setStub(new CommonAppletStub(tag, context, applet));
Dimension size = getSize();
if (size.width == 0 || size.height == 0)
size = tag.getSize();
applet.setSize(size);
// Initialize the applet before showing this window so that
// the applet doesn't receive events before it has been
// initialized.
applet.init();
applet.start();
setVisible(true);
}
}
}
@@ -0,0 +1,75 @@
/* StandaloneAppletContext.java -- an applet's context within the
standalone viewer
Copyright (C) 2003, 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.appletviewer;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
/**
* StandaloneAppletContext represents the context within a webpage of a
* group of applets that all share the same codebase.
*/
class StandaloneAppletContext extends CommonAppletContext
{
private List appletWindows;
StandaloneAppletContext(List appletWindows)
{
this.appletWindows = appletWindows;
}
public void showDocument(URL url, String target)
{
System.err.println("showDocument is not implemented in standalone mode");
}
// In standalone mode, there are potentially several windows, each
// with its own status bar. In plugin mode, all the applets in the
// same context (on the same page) share the browser's status bar.
// The best way to simulate the plugin mode behaviour in standalone
// mode is to show the same status on each window's status bar.
public void showStatus(String status)
{
Iterator window = appletWindows.iterator();
while (window.hasNext())
((StandaloneAppletWindow) window.next()).showStatus(status);
}
}
@@ -0,0 +1,144 @@
/* StandaloneAppletViewer.java -- a standalone viewer for Java applets
Copyright (C) 2003, 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.appletviewer;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
/**
* StandaloneAppletViewer displays an applet in its own Frame. Most
* of the context that is available to an applet within a webpage is
* available to it in StandaloneAppletViewer.
*/
class StandaloneAppletViewer extends Main
{
static ArrayList appletTags = new ArrayList();
static ArrayList appletWindows = new ArrayList();
StandaloneAppletViewer(String[] urls)
throws MalformedURLException, IOException
{
// Handle each file specified on the command line.
for (int i = 0; i < urls.length; i++)
{
TagParser parser = new TagParser(urls[i]);
appletTags.addAll(parser.parseAppletTags());
}
printTags();
createWindows();
}
StandaloneAppletViewer(String code, String codebase, String archives,
List parameters, Dimension dimensions)
throws IOException
{
if (!(code.equals("") || code.endsWith(".class")))
{
System.err.println("appletviewer: option '--code' requires a class filename");
System.exit(1);
}
String tagString =
"<EMBED"
+ " CODE=\"" + code + "\""
+ " WIDTH=" + dimensions.width
+ " HEIGHT=" + dimensions.height
+ " CODEBASE=\"" + codebase + "\""
+ " ARCHIVE=\"" + archives + "\">";
// Handle parameters.
Iterator pairs = parameters.iterator();
while (pairs.hasNext())
{
StringTokenizer paramTokenizer =
new StringTokenizer((String) pairs.next(), ",");
tagString +=
"<PARAM NAME=" + paramTokenizer.nextToken().trim() + " VALUE="
+ paramTokenizer.nextToken().trim() + ">";
}
tagString += "</EMBED>";
StringReader reader = new StringReader(tagString);
String path = System.getProperty("user.dir") + File.separator;
TagParser parser = new TagParser(reader,
new URL("file", "", path));
appletTags.addAll(parser.parseAppletTags());
printTags();
createWindows();
}
void printTags()
{
if (verbose)
{
System.out.println("parsed applet tags:");
for (int i = 0; i < appletTags.size(); i++)
{
AppletTag tag = (AppletTag) appletTags.get(i);
System.out.println(" tag " + i + ":");
System.out.println(tag);
}
}
}
void createWindows()
{
for (int i = 0; i < appletTags.size(); i++)
{
AppletTag tag = (AppletTag) appletTags.get(i);
// Create a StandaloneAppletWindow and add it to the
// appletWindows list.
new StandaloneAppletWindow(tag, appletWindows);
}
}
}
@@ -0,0 +1,559 @@
/* StandaloneAppletWindow.java -- an applet frame
Copyright (C) 2003, 2004, 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.appletviewer;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashMap;
import java.util.List;
class StandaloneAppletWindow
extends Frame
implements ActionListener, ContainerListener, ComponentListener,
MouseListener, MouseMotionListener, InputMethodListener, HierarchyListener,
HierarchyBoundsListener
{
// This class implements various listeners because the author of an applet
// may attach listeners to it, unaware of the applet's parent (this class).
// So, we must pass all listener events on this plugin applet window to the
// actual applet.
private static int testWindowCount;
private static HashMap contexts = new HashMap();
private Applet applet;
private Label status = new Label();
private MenuItem restartItem;
private MenuItem reloadItem;
private MenuItem cancelItem;
private MenuItem saveItem;
private MenuItem startItem;
private MenuItem cloneItem;
private MenuItem tagItem;
private MenuItem infoItem;
private MenuItem editItem;
private MenuItem encodingItem;
private MenuItem printItem;
private MenuItem propertiesItem;
private MenuItem closeItem;
private MenuItem quitItem;
StandaloneAppletWindow(AppletTag tag, List appletWindows)
{
appletWindows.add(this);
applet = Main.createApplet(tag);
if (contexts.get(tag.codebase) == null)
contexts.put(tag.codebase, new StandaloneAppletContext(appletWindows));
setLayout(new BorderLayout());
add(applet, BorderLayout.CENTER);
add(status, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
applet.stop();
StandaloneAppletWindow.this.hide();
System.exit(0);
}
});
addContainerListener(this);
addComponentListener(this);
addMouseListener(this);
addMouseMotionListener(this);
addInputMethodListener(this);
addHierarchyListener(this);
addHierarchyBoundsListener(this);
restartItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_restart"));
restartItem.setEnabled(false);
restartItem.addActionListener(this);
reloadItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_reload"));
reloadItem.setEnabled(false);
reloadItem.addActionListener(this);
cancelItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_cancel"));
cancelItem.setEnabled(false);
cancelItem.addActionListener(this);
saveItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_save"));
saveItem.setEnabled(false);
saveItem.addActionListener(this);
startItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_start"));
startItem.setEnabled(false);
startItem.addActionListener(this);
cloneItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_clone"));
cloneItem.setEnabled(false);
cloneItem.addActionListener(this);
closeItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_close"));
closeItem.setEnabled(false);
closeItem.addActionListener(this);
tagItem =
new MenuItem(Main.messages.getString("gcjwebplugin.menu_tag"));
tagItem.setEnabled(false);
tagItem.addActionListener(this);
infoItem =
new MenuItem(Main.messages.getString("gcjwebplugin.menu_info"));
infoItem.setEnabled(false);
infoItem.addActionListener(this);
editItem =
new MenuItem(Main.messages.getString("gcjwebplugin.menu_edit"));
editItem.setEnabled(false);
editItem.addActionListener(this);
editItem.setEnabled(false);
encodingItem =
new MenuItem(Main.messages.getString("gcjwebplugin.menu_encoding"));
encodingItem.setEnabled(false);
encodingItem.addActionListener(this);
printItem =
new MenuItem(Main.messages.getString("gcjwebplugin.menu_print"));
printItem.setEnabled(false);
printItem.addActionListener(this);
propertiesItem =
new MenuItem(Main.messages.getString("gcjwebplugin.menu_properties"));
propertiesItem.setEnabled(false);
propertiesItem.addActionListener(this);
quitItem = new MenuItem(Main.messages.getString("gcjwebplugin.menu_quit"));
quitItem.addActionListener(this);
MenuBar menuBar = new MenuBar();
Menu menuApplet = new Menu(Main.messages.getString("gcjwebplugin.menu_title"));
menuBar.add(menuApplet);
menuApplet.add(restartItem);
menuApplet.add(reloadItem);
menuApplet.add(cancelItem);
menuApplet.add(saveItem);
menuApplet.add(startItem);
menuApplet.add(cloneItem);
menuApplet.addSeparator();
menuApplet.add(tagItem);
menuApplet.add(infoItem);
menuApplet.add(editItem);
menuApplet.add(encodingItem);
menuApplet.addSeparator();
menuApplet.add(printItem);
menuApplet.addSeparator();
menuApplet.add(propertiesItem);
menuApplet.addSeparator();
menuApplet.add(closeItem);
menuApplet.add(quitItem);
setMenuBar(menuBar);
setTitle("GCJ Applet Viewer: " + tag.code);
AppletContext context = (AppletContext) contexts.get(tag.codebase);
((StandaloneAppletContext) context).addApplet(applet);
applet.setStub(new CommonAppletStub(tag, context, applet));
// Create the frame's peer. Otherwise getPreferredSize will read
// its insets as 0.
addNotify();
Insets i = getInsets();
Dimension size = tag.getSize();
setSize(i.left + size.width + i.right,
i.top + size.height + status.getPreferredSize().height
+ i.bottom);
applet.setSize(size);
// Initialize the applet before showing this window so that the
// applet doesn't receive events before it has been initialized.
applet.init();
applet.start();
setVisible(true);
}
private void closeWindow()
{
applet.stop();
StandaloneAppletViewer.appletWindows.remove(this);
StandaloneAppletWindow.this.hide();
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == quitItem)
{
closeWindow();
System.exit(0);
}
else if (e.getSource() == closeItem)
{
// Close current window.
closeWindow();
// Exit if there are other windows left.
if (StandaloneAppletViewer.appletWindows.isEmpty())
System.exit(0);
}
}
void showStatus(String status)
{
this.status.setText(status);
}
///////////////////////////////////
/// ContainerListener Methods /////
///////////////////////////////////
/**
* This method is called when a component is added to the container.
*
* @param event the <code>ContainerEvent</code> indicating component
* addition
*/
public void componentAdded(ContainerEvent event)
{
if (applet != null)
{
ContainerListener[] l = applet.getContainerListeners();
for (int i = 0; i < l.length; i++)
l[i].componentAdded(event);
}
}
/**
* This method is called when a component is removed from the container.
*
* @param event the <code>ContainerEvent</code> indicating component removal
*/
public void componentRemoved(ContainerEvent event)
{
if (applet != null)
{
ContainerListener[] l = applet.getContainerListeners();
for (int i = 0; i < l.length; i++)
l[i].componentRemoved(event);
}
}
///////////////////////////////////
/// ComponentListener Methods /////
///////////////////////////////////
/**
* This method is called when the component is resized.
*
* @param event the <code>ComponentEvent</code> indicating the resize
*/
public void componentResized(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentResized(event);
}
}
/**
* This method is called when the component is moved.
*
* @param event the <code>ComponentEvent</code> indicating the move
*/
public void componentMoved(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentMoved(event);
}
}
/**
* This method is called when the component is made visible.
*
* @param event the <code>ComponentEvent</code> indicating the visibility
*/
public void componentShown(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentShown(event);
}
}
/**
* This method is called when the component is hidden.
*
* @param event the <code>ComponentEvent</code> indicating the visibility
*/
public void componentHidden(ComponentEvent event)
{
if (applet != null)
{
ComponentListener[] l = applet.getComponentListeners();
for (int i = 0; i < l.length; i++)
l[i].componentHidden(event);
}
}
///////////////////////////////////
////// MouseListener Methods //////
///////////////////////////////////
/**
* This method is called when the mouse is clicked (pressed and released
* in short succession) on a component.
*
* @param event the <code>MouseEvent</code> indicating the click
*/
public void mouseClicked(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseClicked(event);
}
}
/**
* This method is called when the mouse is pressed over a component.
*
* @param event the <code>MouseEvent</code> for the press
*/
public void mousePressed(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mousePressed(event);
}
}
/**
* This method is called when the mouse is released over a component.
*
* @param event the <code>MouseEvent</code> for the release
*/
public void mouseReleased(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseReleased(event);
}
}
/**
* This method is called when the mouse enters a component.
*
* @param event the <code>MouseEvent</code> for the entry
*/
public void mouseEntered(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseEntered(event);
}
}
/**
* This method is called when the mouse exits a component.
*
* @param event the <code>MouseEvent</code> for the exit
*/
public void mouseExited(MouseEvent event)
{
if (applet != null)
{
MouseListener[] l = applet.getMouseListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseExited(event);
}
}
///////////////////////////////////
/// MouseMotionListener Methods ///
///////////////////////////////////
/**
* This method is called when the mouse is moved over a component
* while a button has been pressed.
*
* @param event the <code>MouseEvent</code> indicating the motion
*/
public void mouseDragged(MouseEvent event)
{
if (applet != null)
{
MouseMotionListener[] l = applet.getMouseMotionListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseDragged(event);
}
}
/**
* This method is called when the mouse is moved over a component
* while no button is pressed.
*
* @param event the <code>MouseEvent</code> indicating the motion
*/
public void mouseMoved(MouseEvent event)
{
if (applet != null)
{
MouseMotionListener[] l = applet.getMouseMotionListeners();
for (int i = 0; i < l.length; i++)
l[i].mouseMoved(event);
}
}
///////////////////////////////////
/// InputMethodListener Methods ///
///////////////////////////////////
/**
* This method is called when the text is changed.
*
* @param event the <code>InputMethodEvent</code> indicating the text change
*/
public void inputMethodTextChanged(InputMethodEvent event)
{
if (applet != null)
{
InputMethodListener[] l = applet.getInputMethodListeners();
for (int i = 0; i < l.length; i++)
l[i].inputMethodTextChanged(event);
}
}
/**
* This method is called when the cursor position within the text is changed.
*
* @param event the <code>InputMethodEvent</code> indicating the change
*/
public void caretPositionChanged(InputMethodEvent event)
{
if (applet != null)
{
InputMethodListener[] l = applet.getInputMethodListeners();
for (int i = 0; i < l.length; i++)
l[i].caretPositionChanged(event);
}
}
///////////////////////////////////
//// HierarchyListener Methods ////
///////////////////////////////////
/**
* Called when the hierarchy of this component changes. Use
* <code>getChangeFlags()</code> on the event to see what exactly changed.
*
* @param e the event describing the change
*/
public void hierarchyChanged(HierarchyEvent event)
{
if (applet != null)
{
HierarchyListener[] l = applet.getHierarchyListeners();
for (int i = 0; i < l.length; i++)
l[i].hierarchyChanged(event);
}
}
/////////////////////////////////////////
//// HierarchyBoundsListener Methods ////
/////////////////////////////////////////
/**
* Called when an ancestor component of the source is moved.
*
* @param e the event describing the ancestor's motion
*/
public void ancestorMoved(HierarchyEvent e)
{
if (applet != null)
{
HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
for (int i = 0; i < l.length; i++)
l[i].ancestorMoved(e);
}
}
/**
* Called when an ancestor component is resized.
*
* @param e the event describing the ancestor's resizing
*/
public void ancestorResized(HierarchyEvent e)
{
if (applet != null)
{
HierarchyBoundsListener[] l = applet.getHierarchyBoundsListeners();
for (int i = 0; i < l.length; i++)
l[i].ancestorResized(e);
}
}
}
@@ -0,0 +1,302 @@
/* TagParser.java -- a parser for applet tags
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.appletviewer;
import gnu.javax.swing.text.html.parser.HTML_401F;
import gnu.xml.dom.DomNode;
import gnu.xml.dom.html2.DomHTMLAppletElement;
import gnu.xml.dom.html2.DomHTMLDocument;
import gnu.xml.dom.html2.DomHTMLEmbedElement;
import gnu.xml.dom.html2.DomHTMLObjectElement;
import gnu.xml.dom.html2.DomHTMLParamElement;
import gnu.xml.dom.html2.DomHTMLParser;
import java.io.File;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Vector;
import org.w3c.dom.NodeList;
public class TagParser
{
/**
* Parsed document.
*/
DomHTMLDocument document;
/**
* The document base of this applet.
*/
URL documentbase;
/**
* The document base of all the applets.
*/
static URL db;
/**
* The tags in the document.
*/
Vector tags = new Vector();
/**
* Default constructor.
*/
TagParser()
{
// Do nothing.
}
/**
* Constructs and parses document using the given location.
*
* @param location - location of applet
*/
TagParser(String location) throws IOException
{
documentbase = getLocationToURL(location);
db = documentbase;
InputStreamReader in = new InputStreamReader(documentbase.openStream());
document = (DomHTMLDocument) (new DomHTMLParser(HTML_401F.getInstance()).parseDocument(in));
}
/**
* Constructs and parses document.
*
* @param in - Reader to parse document from.
* @param documentBase - the URL of the applet
* @throws IOException - is thrown if any IO error occurs.
*/
TagParser(Reader in, URL documentBase) throws IOException
{
documentbase = documentBase;
db = documentbase;
document = (DomHTMLDocument) (new DomHTMLParser(HTML_401F.getInstance()).parseDocument(in));
}
/**
* Parses all applet tags in document.
*
* @return a list of AppletTag objects representing the applet tags
* in document
*/
ArrayList parseAppletTags()
{
ArrayList allTags = new ArrayList();
if (document == null)
return null;;
recurseDocument(document.getChildNodes());
int sz = tags.size();
for (int j = 0; j < sz; j++)
{
Object curr = tags.get(j);
// Order of checking is important here.
// Must check embed element before applet element
// because DomHTMLEmbedElement extends DomHTMLAppletElement
AppletTag a = null;
if (curr instanceof DomHTMLEmbedElement)
a = new AppletTag((DomHTMLEmbedElement) curr);
else if (curr instanceof DomHTMLAppletElement)
a = new AppletTag((DomHTMLAppletElement) curr);
else if (curr instanceof DomHTMLObjectElement)
a = new AppletTag((DomHTMLObjectElement) curr);
a.documentbase = documentbase;
allTags.add(a);
}
return allTags;
}
/**
* Recurses the document in search for the appropriate tags.
*
* @param list - the Node list.
*/
private void recurseDocument(NodeList list)
{
// Recurse and store all APPLET, OBJECT and EMBED tags.
int length = list.getLength();
for (int i = 0; i < length; i++)
{
DomNode curr = (DomNode) list.item(i);
if ((curr instanceof DomHTMLEmbedElement) ||
(curr instanceof DomHTMLAppletElement) ||
(curr instanceof DomHTMLObjectElement))
tags.add(curr);
recurseDocument(curr.getChildNodes());
}
}
/**
* Parses the param elements for a given node.
*
* @param node - the node element to parse.
*/
static void parseParams(DomNode node, AppletTag t)
{
boolean ja = false;
boolean jb = false;
boolean jc = false;
NodeList l = node.getChildNodes();
int size = l.getLength();
if (size != 0)
for (int i = 0; i < size; i++)
{
Object c = l.item(i);
if (! (c instanceof DomHTMLParamElement))
continue;
DomHTMLParamElement curr = (DomHTMLParamElement) c;
String key = curr.getName();
String val = curr.getValue();
if (key.equals("java_code"))
{
jc = true;
t.code = val;
}
else if (key.equals("java_codebase"))
{
jb = true;
t.codebase = val;
}
else if (!jc && key.equals("code"))
t.code = val;
else if (!jc && key.equals("classid"))
{
int x = val.indexOf(":");
if (x != -1)
val = val.substring(x + 1);
t.code = val;
}
else if (!jb && key.equals("codebase"))
t.codebase = val;
else if (key.equals("java_archive"))
{
ja = true;
t.archives = parseArchives(val, t);
val = t.archives.toString();
}
else if (!ja && key.equals("archive"))
{
t.archives = parseArchives(val, t);
val = t.archives.toString();
}
t.parameters.put(key.toLowerCase(), val);
}
}
/**
* Parses the archive string and returns a list.
*
* @param the list of archives (comma-separated) in a String.
*/
static ArrayList parseArchives(String arcs, AppletTag t)
{
try
{
ArrayList list = new ArrayList();
StringTokenizer tagTokenizer = new StringTokenizer(arcs, ",");
while (tagTokenizer.hasMoreTokens())
list.add(t.prependCodeBase(tagTokenizer.nextToken().trim()));
return list;
}
catch (MalformedURLException e)
{
}
return null;
}
/**
* Gets the location to the URL, given a location.
*
* @param location - the given location.
* @return the URL.
*/
static URL getLocationToURL(String location) throws IOException
{
URL tmpDocumentBase = null;
try
{
// Try parsing location as a URL.
tmpDocumentBase = new URL(location);
// If no file was specified in the URL the assume the user
// meant the root page.
String f = tmpDocumentBase.getFile();
if (f.indexOf(".") == -1 && !f.endsWith(File.separator))
if (new File(tmpDocumentBase.getFile()).isDirectory())
tmpDocumentBase = new URL(location.concat(File.separator));
}
catch (MalformedURLException e)
{
// location is not a URL. See if it is an HTML file.
String path;
if (location.startsWith(File.separator))
path = new File(location).getCanonicalPath();
else
path = new File(System.getProperty("user.dir") + File.separator
+ location).getCanonicalPath();
tmpDocumentBase = new URL("file", "", path);
if (new File(tmpDocumentBase.getFile()).isDirectory())
tmpDocumentBase = new URL("file", "", path + File.separator);
}
return tmpDocumentBase;
}
}
@@ -0,0 +1,73 @@
/* ClasspathToolParser.java -- Parser subclass for classpath tools
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.getopt;
import java.text.MessageFormat;
import gnu.classpath.Configuration;
/**
* This is like the Parser class, but is specialized for use by
* tools distributed with GNU Classpath. In particular it automatically
* computes the version string using the program's name.
*/
public class ClasspathToolParser
extends Parser
{
private static String getVersionString(String programName)
{
String fmt = (Messages.getString("ClasspathToolParser.VersionFormat")); //$NON-NLS-1$
return MessageFormat.format(fmt,
new Object[]
{
programName,
Configuration.CLASSPATH_VERSION
});
}
public ClasspathToolParser(String programName)
{
super(programName, getVersionString(programName));
}
public ClasspathToolParser(String programName, boolean longOnly)
{
super(programName, getVersionString(programName), longOnly);
}
}
@@ -0,0 +1,62 @@
/* FileArgumentCallback.java - handle non-option command line arguments
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.getopt;
/**
* This is a callback class which is used when a "file name" is found by the
* command-line parser. A file name is any command-line argument which does not
* start with a dash and which is not the argument of some preceding option.
*/
public abstract class FileArgumentCallback
{
/**
* Create a new instance.
*/
protected FileArgumentCallback()
{
}
/**
* This is called when a file argument is seen.
*
* @param fileArgument the file name
*/
public abstract void notifyFile(String fileArgument)
throws OptionException;
}
@@ -0,0 +1,67 @@
/* Messages.java -- i18n support for getopt
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.getopt;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages
{
private static final String BUNDLE_NAME
= "gnu.classpath.tools.getopt.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 + '!';
}
}
}
@@ -0,0 +1,200 @@
/* Option.java - represent a command-line option
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.getopt;
/**
* This is the base class representing an option. An option can have a short
* form. This is a single character, like '-x'. An option can have a long form,
* like '--verbose'; if the parser is working in "long option only" mode, then a
* long flag has a single dash, like '-verbose'. Both a long and a short form
* may be specified; it is not valid to have neither. A description is mandatory
* for options; this is used to automatically generate '--help' output.
*/
public abstract class Option
{
private char shortName;
private String longName;
private String description;
private String argumentName;
/**
* Create a new option with the given short name and description.
*
* @param shortName the short name
* @param description the description
*/
protected Option(char shortName, String description)
{
this.shortName = shortName;
this.description = description;
}
/**
* Create a new option with the given short name and description.
*
* @param shortName the short name
* @param description the description
* @param argumentName the descriptive name of the argument, if this option
* takes an argument; otherwise null
*/
protected Option(char shortName, String description, String argumentName)
{
this.shortName = shortName;
this.description = description;
this.argumentName = argumentName;
}
/**
* Create a new option with the given long name and description. The long name
* should be specified without any leading dashes.
*
* @param longName the long name
* @param description the description
*/
protected Option(String longName, String description)
{
this.longName = longName;
this.description = description;
}
/**
* Create a new option with the given long name and description. The long name
* should be specified without any leading dashes.
*
* @param longName the long name
* @param description the description
* @param argumentName the descriptive name of the argument, if this option
* takes an argument; otherwise null
*/
protected Option(String longName, String description, String argumentName)
{
this.longName = longName;
this.description = description;
this.argumentName = argumentName;
}
/**
* Create a new option with the given short and long names and description.
* The long name should be specified without any leading dashes.
*
* @param longName the long name
* @param shortName the short name
* @param description the description
*/
protected Option(String longName, char shortName, String description)
{
this.shortName = shortName;
this.longName = longName;
this.description = description;
}
/**
* Create a new option with the given short and long names and description.
* The long name should be specified without any leading dashes.
*
* @param longName the long name
* @param shortName the short name
* @param description the description
* @param argumentName the descriptive name of the argument, if this option
* takes an argument; otherwise null
*/
protected Option(String longName, char shortName, String description,
String argumentName)
{
this.shortName = shortName;
this.longName = longName;
this.argumentName = argumentName;
this.description = description;
}
/**
* Return the short name of the option, or \0 if none.
*/
public char getShortName()
{
return shortName;
}
/**
* Return the long name of the option, or null if none.
*/
public String getLongName()
{
return longName;
}
/**
* Return true if the argument takes an option.
*/
public boolean getTakesArgument()
{
return argumentName != null;
}
/**
* Return the name of the argument. If the option does not take an argument,
* returns null.
*/
public String getArgumentName()
{
return argumentName;
}
/**
* Return the description of the option.
*/
public String getDescription()
{
return description;
}
/**
* This is called by the parser when this option is recognized. It may be
* called multiple times during a single parse. If this option takes an
* argument, the argument will be passed in. Otherwise the argument will be
* null.
*
* @param argument the argument
* @throws OptionException if the option or its argument is somehow invalid
*/
public abstract void parsed(String argument) throws OptionException;
}
@@ -0,0 +1,52 @@
/* OptionException.java - when command-line processing fails
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.getopt;
/**
* An OptionException is thrown internally when an error is seen when parsing a
* command line.
*/
public class OptionException
extends Exception
{
public OptionException(String message)
{
super(message);
}
}
@@ -0,0 +1,271 @@
/* OptionGroup.java - a group of related command-line options
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.getopt;
import java.io.PrintStream;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
/**
* An option group holds a collection of Options. It also has a name. Option
* groups are primarily useful for grouping help output.
*/
public class OptionGroup
{
/** An 80-character string of whitespaces to use as a source for padding. */
private static final String FILLER = " "
+ " ";
private String name;
ArrayList options = new ArrayList();
/**
* Create a new nameless option group. This can only be used by Parser.
*/
OptionGroup()
{
}
/**
* Create a new option group with the indicated name.
*
* @param name the name
*/
public OptionGroup(String name)
{
this.name = name;
}
/**
* Print a designated text to a {@link PrintStream}, eventually wrapping the
* lines of text so as to ensure that the width of each line does not overflow
* {@link Parser#MAX_LINE_LENGTH} columns. The line-wrapping is done with a
* {@link BreakIterator} using the default {@link Locale}.
* <p>
* The text to print may contain <code>\n</code> characters. This method will
* force a line-break for each such character.
*
* @param out the {@link PrintStream} destination of the formatted text.
* @param text the text to print.
* @param leftMargin a positive value indicating the column position of the
* start of the first line. Continuation lines, if they exist, are
* printed starting at <code>leftMargin + 2</code> as per GNU
* convention.
* @see Parser#MAX_LINE_LENGTH
*/
protected static void formatText(PrintStream out, String text, int leftMargin)
{
formatText(out, text, leftMargin, Locale.getDefault());
}
/**
* Similar to the method with the same name and three arguments, except that
* the caller MUST specify a non-null {@link Locale} instance.
* <p>
* Print a designated text to a {@link PrintStream}, eventually wrapping the
* lines of text so as to ensure that the width of each line does not overflow
* {@link Parser#MAX_LINE_LENGTH} columns. The line-wrapping is done with a
* {@link BreakIterator} using the designated {@link Locale}.
* <p>
* The text to print may contain <code>\n</code> characters. This method will
* force a line-break for each such character.
*
* @param out the {@link PrintStream} destination of the formatted text.
* @param text the text to print.
* @param leftMargin a positive value indicating the column position of the
* start of the first line. Continuation lines, if they exist, are
* printed starting at <code>leftMargin + 2</code> as per GNU
* convention.
* @param aLocale the {@link Locale} instance to use when constructing the
* {@link BreakIterator}.
* @see Parser#MAX_LINE_LENGTH
*/
protected static void formatText(PrintStream out, String text, int leftMargin,
Locale aLocale)
{
BreakIterator bit = BreakIterator.getLineInstance(aLocale);
String[] lines = text.split("\n");
int length = leftMargin;
String leftPadding = FILLER.substring(0, leftMargin + 2);
for (int i = 0; i < lines.length; i++)
{
text = lines[i];
bit.setText(text);
int start = bit.first();
int finish;
while ((finish = bit.next()) != BreakIterator.DONE)
{
String word = text.substring(start, finish);
length += word.length();
if (length >= Parser.MAX_LINE_LENGTH)
{
out.println();
out.print(leftPadding);
length = word.length() + leftMargin + 2;
}
out.print(word);
start = finish;
}
out.println();
if (i != lines.length - 1)
{
length = leftMargin + 2;
out.print(leftPadding);
}
}
}
/**
* Add an option to this option group.
*
* @param opt the option to add
*/
public void add(Option opt)
{
options.add(opt);
}
/**
* Print the help output for this option group.
*
* @param out the stream to which to print
*/
public void printHelp(PrintStream out, boolean longOnly)
{
// Compute maximum lengths.
int maxArgLen = 0;
boolean shortOptionSeen = false;
Iterator it;
// The first pass only looks to see if we have a short option.
it = options.iterator();
while (it.hasNext())
{
Option option = (Option) it.next();
if (option.getShortName() != '\0')
{
shortOptionSeen = true;
break;
}
}
it = options.iterator();
while (it.hasNext())
{
Option option = (Option) it.next();
String argName = option.getArgumentName();
// First compute the width required for the short
// option. "2" is the initial indentation. In the
// GNU style we don't print an argument name for
// a short option if there is also a long name for
// the option.
int thisArgLen = 2;
if (shortOptionSeen)
thisArgLen += 4;
if (option.getLongName() != null)
{
// Handle either '-' or '--'.
thisArgLen += 1 + option.getLongName().length();
if (! longOnly)
++thisArgLen;
}
// Add in the width of the argument name.
if (argName != null)
thisArgLen += 1 + argName.length();
maxArgLen = Math.max(maxArgLen, thisArgLen);
}
// Print the help.
if (name != null)
out.println(name + ":");
it = options.iterator();
while (it.hasNext())
{
Option option = (Option) it.next();
String argName = option.getArgumentName();
int column = 0;
if (option.getShortName() != '\0')
{
out.print(" -");
out.print(option.getShortName());
column += 4;
if (option.getLongName() == null)
{
if (argName != null)
{
// This is a silly hack just for '-J'. We don't
// support joined options in general, but this option
// is filtered out before argument processing can see it.
if (option.getShortName() != 'J')
{
out.print(' ');
++column;
}
out.print(argName);
column += argName.length();
}
out.print(" ");
}
else
out.print(", ");
column += 2;
}
// Indent the long option past the short options, if one
// was seen.
for (; column < (shortOptionSeen ? 6 : 2); ++column)
out.print(' ');
if (option.getLongName() != null)
{
out.print(longOnly ? "-" : "--");
out.print(option.getLongName());
column += (longOnly ? 1 : 2) + option.getLongName().length();
if (argName != null)
{
out.print(" " + argName);
column += 1 + argName.length();
}
}
// FIXME: should have a better heuristic for padding.
out.print(FILLER.substring(0, maxArgLen + 4 - column));
formatText(out, option.getDescription(), maxArgLen + 4);
}
}
}
@@ -0,0 +1,454 @@
/* Parser.java - parse command line options
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.getopt;
import java.io.PrintStream;
import java.text.BreakIterator;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
/**
* An instance of this class is used to parse command-line options. It does "GNU
* style" argument recognition and also automatically handles "--help" and
* "--version" processing. It can also be put in "long option only" mode. In
* this mode long options are recognized with a single dash (as well as a double
* dash) and strings of options like "-abc" are never parsed as a collection of
* short options.
*/
public class Parser
{
/** The maximum right column position. */
public static final int MAX_LINE_LENGTH = 80;
private String programName;
private String headerText;
private String footerText;
private boolean longOnly;
private ArrayList options = new ArrayList();
private ArrayList optionGroups = new ArrayList();
private OptionGroup defaultGroup = new OptionGroup();
// These are used while parsing.
private int currentIndex;
private String[] args;
/**
* Create a new parser. The program name is used when printing error messages.
* The version string is printed verbatim in response to "--version".
*
* @param programName the name of the program
* @param versionString the program's version information
*/
public Parser(String programName, String versionString)
{
this(programName, versionString, false);
}
/**
* Print a designated text to a {@link PrintStream}, eventually wrapping the
* lines of text so as to ensure that the width of each line does not overflow
* {@link #MAX_LINE_LENGTH} columns. The line-wrapping is done with a
* {@link BreakIterator} using the default {@link Locale}.
* <p>
* The text to print may contain <code>\n</code> characters. This method will
* force a line-break for each such character.
*
* @param out the {@link PrintStream} destination of the formatted text.
* @param text the text to print.
* @see Parser#MAX_LINE_LENGTH
*/
protected static void formatText(PrintStream out, String text)
{
formatText(out, text, Locale.getDefault());
}
/**
* Similar to the method with the same name and two arguments, except that the
* caller MUST specify a non-null {@link Locale} instance.
* <p>
* Print a designated text to a {@link PrintStream}, eventually wrapping the
* lines of text so as to ensure that the width of each line does not overflow
* {@link #MAX_LINE_LENGTH} columns. The line-wrapping is done with a
* {@link BreakIterator} using the designated {@link Locale}.
* <p>
* The text to print may contain <code>\n</code> characters. This method will
* force a line-break for each such character.
*
* @param out the {@link PrintStream} destination of the formatted text.
* @param text the text to print.
* @param aLocale the {@link Locale} instance to use when constructing the
* {@link BreakIterator}.
* @see Parser#MAX_LINE_LENGTH
*/
protected static void formatText(PrintStream out, String text, Locale aLocale)
{
BreakIterator bit = BreakIterator.getLineInstance(aLocale);
String[] lines = text.split("\n"); //$NON-NLS-1$
for (int i = 0; i < lines.length; i++)
{
text = lines[i];
bit.setText(text);
int length = 0;
int finish;
int start = bit.first();
while ((finish = bit.next()) != BreakIterator.DONE)
{
String word = text.substring(start, finish);
length += word.length();
if (length >= MAX_LINE_LENGTH)
{
out.println();
length = word.length();
}
out.print(word);
start = finish;
}
out.println();
}
}
/**
* Create a new parser. The program name is used when printing error messages.
* The version string is printed verbatim in response to "--version".
*
* @param programName the name of the program
* @param versionString the program's version information
* @param longOnly true if the parser should work in long-option-only mode
*/
public Parser(String programName, final String versionString, boolean longOnly)
{
this.programName = programName;
this.longOnly = longOnly;
// Put standard options in their own section near the end.
OptionGroup finalGroup = new OptionGroup(Messages.getString("Parser.StdOptions")); //$NON-NLS-1$
finalGroup.add(new Option("help", Messages.getString("Parser.PrintHelp")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
printHelp(System.out);
System.exit(0);
}
});
finalGroup.add(new Option("version", Messages.getString("Parser.PrintVersion")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
System.out.println(versionString);
System.exit(0);
}
});
finalGroup.add(new Option('J', Messages.getString("Parser.JArgument"), Messages.getString("Parser.JName")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
// -J should be handled by the appletviewer wrapper binary.
// We add it here so that it shows up in the --help output.
// Note that there is a special case for this in OptionGroup.
}
});
add(finalGroup);
add(defaultGroup);
}
/**
* Set the header text that is printed by --help.
*
* @param headerText the header text
*/
public void setHeader(String headerText)
{
this.headerText = headerText;
}
/**
* Set the footer text that is printed by --help.
*
* @param footerText the footer text
*/
public void setFooter(String footerText)
{
this.footerText = footerText;
}
/**
* Add an option to this parser. The option is added to the default option
* group; this affects where it is placed in the help output.
*
* @param opt the option
*/
public synchronized void add(Option opt)
{
options.add(opt);
defaultGroup.add(opt);
}
/**
* Add an option group to this parser. All the options in this group will be
* recognized by the parser.
*
* @param group the option group
*/
public synchronized void add(OptionGroup group)
{
options.addAll(group.options);
// This ensures that the final group always appears at the end
// of the options.
if (optionGroups.isEmpty())
optionGroups.add(group);
else
optionGroups.add(optionGroups.size() - 1, group);
}
public void printHelp()
{
this.printHelp(System.out);
}
void printHelp(PrintStream out)
{
if (headerText != null)
{
formatText(out, headerText);
out.println();
}
Iterator it = optionGroups.iterator();
while (it.hasNext())
{
OptionGroup group = (OptionGroup) it.next();
// An option group might be empty, in which case we don't
// want to print it..
if (! group.options.isEmpty())
{
group.printHelp(out, longOnly);
out.println();
}
}
if (footerText != null)
formatText(out, footerText);
}
/**
* This method can be overridden by subclassses to provide some option
* validation. It is called by the parser after all options have been
* parsed. If an option validation problem is encountered, this should
* throw an {@link OptionException} whose message should be shown to
* the user.
* <p>
* It is better to do validation here than after {@link #parse(String[])}
* returns, because the parser will print a message referring the
* user to the <code>--help</code> option.
* <p>
* The base implementation does nothing.
*
* @throws OptionException the error encountered
*/
protected void validate() throws OptionException
{
// Base implementation does nothing.
}
private String getArgument(String request) throws OptionException
{
++currentIndex;
if (currentIndex >= args.length)
{
String message
= MessageFormat.format(Messages.getString("Parser.ArgReqd"), //$NON-NLS-1$
new Object[] { request });
throw new OptionException(request);
}
return args[currentIndex];
}
private void handleLongOption(String real, int index) throws OptionException
{
String option = real.substring(index);
String justName = option;
int eq = option.indexOf('=');
if (eq != - 1)
justName = option.substring(0, eq);
Option found = null;
for (int i = options.size() - 1; i >= 0; --i)
{
Option opt = (Option) options.get(i);
if (justName.equals(opt.getLongName()))
{
found = opt;
break;
}
}
if (found == null)
{
String msg = MessageFormat.format(Messages.getString("Parser.Unrecognized"), //$NON-NLS-1$
new Object[] { real });
throw new OptionException(msg);
}
String argument = null;
if (found.getTakesArgument())
{
if (eq == - 1)
argument = getArgument(real);
else
argument = option.substring(eq + 1);
}
else if (eq != - 1)
{
String msg
= MessageFormat.format(Messages.getString("Parser.NoArg"), //$NON-NLS-1$
new Object[] { real.substring(0, eq + index) });
throw new OptionException(msg);
}
found.parsed(argument);
}
private void handleShortOption(char option) throws OptionException
{
Option found = null;
for (int i = options.size() - 1; i >= 0; --i)
{
Option opt = (Option) options.get(i);
if (option == opt.getShortName())
{
found = opt;
break;
}
}
if (found == null)
{
String msg = MessageFormat.format(Messages.getString("Parser.UnrecDash"), //$NON-NLS-1$
new Object[] { "" + option }); //$NON-NLS-1$
throw new OptionException(msg);
}
String argument = null;
if (found.getTakesArgument())
argument = getArgument("-" + option); //$NON-NLS-1$
found.parsed(argument);
}
private void handleShortOptions(String option) throws OptionException
{
for (int i = 1; i < option.length(); ++i)
{
handleShortOption(option.charAt(i));
}
}
/**
* Parse a command line. Any files which are found will be passed to the file
* argument callback. This method will exit on error or when --help or
* --version is specified.
*
* @param inArgs the command-line arguments
* @param files the file argument callback
*/
public synchronized void parse(String[] inArgs, FileArgumentCallback files)
{
try
{
args = inArgs;
for (currentIndex = 0; currentIndex < args.length; ++currentIndex)
{
if (args[currentIndex].length() == 0
|| args[currentIndex].charAt(0) != '-'
|| "-".equals(args[currentIndex])) //$NON-NLS-1$
{
files.notifyFile(args[currentIndex]);
continue;
}
if ("--".equals(args[currentIndex])) //$NON-NLS-1$
break;
if (args[currentIndex].charAt(1) == '-')
handleLongOption(args[currentIndex], 2);
else if (longOnly)
handleLongOption(args[currentIndex], 1);
else
handleShortOptions(args[currentIndex]);
}
// Add remaining arguments to leftovers.
for (++currentIndex; currentIndex < args.length; ++currentIndex)
files.notifyFile(args[currentIndex]);
// See if something went wrong.
validate();
}
catch (OptionException err)
{
System.err.println(programName + ": " + err.getMessage()); //$NON-NLS-1$
String fmt;
if (longOnly)
fmt = Messages.getString("Parser.TryHelpShort"); //$NON-NLS-1$
else
fmt = Messages.getString("Parser.TryHelpLong"); //$NON-NLS-1$
String msg = MessageFormat.format(fmt, new Object[] { programName });
System.err.println(programName + ": " + msg); //$NON-NLS-1$
System.exit(1);
}
}
/**
* Parse a command line. Any files which are found will be returned. This
* method will exit on error or when --help or --version is specified.
*
* @param inArgs the command-line arguments
*/
public String[] parse(String[] inArgs)
{
final ArrayList fileResult = new ArrayList();
parse(inArgs, new FileArgumentCallback()
{
public void notifyFile(String fileArgument)
{
fileResult.add(fileArgument);
}
});
return (String[]) fileResult.toArray(new String[0]);
}
}
@@ -104,6 +104,17 @@ public class GRMIC
else
HelpPrinter.printHelpAndExit(HelpPath);
}
else if (c.equals("-classpath"))
{
int f = i + 1;
if (f < args.length)
{
compiler.setClassPath(args[f]);
i++;
}
else
HelpPrinter.printHelpAndExit(HelpPath);
}
else if (c.charAt(0) != '-')
// No more options - start of class list.
{
@@ -124,17 +135,7 @@ public class GRMIC
if (args[i].charAt(0) != '-')
{
compiler.reset();
Class c = null;
try
{
c = Thread.currentThread().getContextClassLoader().loadClass(
args[i]);
}
catch (ClassNotFoundException e)
{
System.err.println(args[i] + " class not found.");
System.exit(1);
}
Class c = compiler.loadClass(args[i]);
compiler.compile(c);
String packag = compiler.getPackageName().replace('.', '/');
@@ -9,18 +9,20 @@ Please report bugs at http://www.gnu.org/software/classpath/bugs.html
Usage: grmic <options> <class names>
where <options> includes:
-poa Generate the Servant based ties (default)
-impl Generate the obsoleted ObjectImpl based ties
(for backward compatibility)
-nowarn Show no warnings
-nowrite Do not write any files (check for errors only)
-d <folder> Place generated files into the given folder
-poa Generate the Servant based ties (default)
-impl Generate the obsoleted ObjectImpl based ties
(for backward compatibility)
-nowarn Show no warnings
-nowrite Do not write any files (check for errors only)
-d <folder> Place generated files into the given folder
-classpath <path> Specifies the path, where to find the classes being
compiled
-help Print this help text
-v Print version
-verbose Verbose output
-force Try to generate code even if the input classes seem not
consistent with RMI specification.
-help Print this help text
-v Print version
-verbose Verbose output
-force Try to generate code even if the input classes seem not
consistent with RMI specification.
and <class names> can include one or more non abstract classes that implement
@@ -23,7 +23,11 @@ package gnu.classpath.tools.giop.grmic;
import gnu.classpath.tools.AbstractMethodGenerator;
import java.io.File;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
@@ -33,6 +37,7 @@ import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.TreeSet;
/**
@@ -104,6 +109,11 @@ public class GiopRmicCompiler
* Force mode - do not check the exceptions
*/
protected boolean force = false;
/**
* The class loader to load the class being compiled.
*/
ClassLoader classLoader;
/**
* Clear data, preparing for the next compilation.
@@ -116,6 +126,78 @@ public class GiopRmicCompiler
methods.clear();
vars.clear();
}
/**
* Set the class path (handle the -classpath key)
*
* @param classPath the class path to set.
*/
public void setClassPath(String classPath)
{
classLoader = Thread.currentThread().getContextClassLoader();
StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator,
true);
ArrayList urls = new ArrayList(tok.countTokens());
String s = null;
try
{
while (tok.hasMoreTokens())
{
s = tok.nextToken();
if (s.equals(File.pathSeparator))
urls.add(new File(".").toURL());
else
{
urls.add(new File(s).toURL());
if (tok.hasMoreTokens())
{
// Skip the separator.
tok.nextToken();
// If the classpath ended with a separator,
// append the current directory.
if (! tok.hasMoreTokens())
urls.add(new File(".").toURL());
}
}
}
}
catch (MalformedURLException ex)
{
System.err.println("Malformed path '" + s + "' in classpath '"
+ classPath + "'");
System.exit(1);
}
URL[] u = new URL[urls.size()];
for (int i = 0; i < u.length; i++)
{
u[i] = (URL) urls.get(i);
}
classLoader = new URLClassLoader(u, classLoader);
}
/**
* Loads the class with the given name (uses class path, if applicable)
*
* @param name the name of the class.
*/
public Class loadClass(String name)
{
ClassLoader loader = classLoader;
if (loader == null)
loader = Thread.currentThread().getContextClassLoader();
try
{
return loader.loadClass(name);
}
catch (ClassNotFoundException e)
{
System.err.println(name+" not found on "+loader);
System.exit(1);
// Unreacheable code.
return null;
}
}
/**
* Compile the given class (the instance of Remote), generating the stub and
@@ -193,12 +275,12 @@ public class GiopRmicCompiler
remEx = true;
break;
}
if (! remEx && !force)
throw new CompilationError(m[i].getName() + ", defined in "
+ c.getName()
+ ", does not throw "
+ RemoteException.class.getName());
}
}
if (! remEx && !force)
throw new CompilationError(m[i].getName() + ", defined in "
+ c.getName()
+ ", does not throw "
+ RemoteException.class.getName());
AbstractMethodGenerator mm = createMethodGenerator(m[i]);
methods.add(mm);
}
@@ -0,0 +1,51 @@
/* Action.java - an action taken by the jar driver
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.io.IOException;
public abstract class Action
{
protected Action()
{
}
public abstract void run(Main parameters)
throws IOException;
}
@@ -0,0 +1,247 @@
/* Creator.java - create a new jar file
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.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
public class Creator
extends Action
{
JarOutputStream outputStream;
HashSet writtenItems = new HashSet();
// The manifest to use, or null if we don't want a manifest.
Manifest manifest;
private long copyFile(CRC32 crc, InputStream is, OutputStream output)
throws IOException
{
byte[] buffer = new byte[1024];
long size = 0;
while (true)
{
int len = is.read(buffer);
if (len == - 1)
break;
size += len;
output.write(buffer, 0, len);
crc.update(buffer, 0, len);
}
output.close();
return size;
}
protected void writeFile(boolean isDirectory, InputStream inputFile,
String filename, boolean verbose)
throws IOException
{
if (writtenItems.contains(filename))
{
if (verbose)
{
String msg = MessageFormat.format(Messages.getString("Creator.Ignoring"), //$NON-NLS-1$
new Object[] { filename });
System.err.println(msg);
}
return;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
CRC32 crc = new CRC32();
long size;
if (isDirectory)
{
size = 0;
}
else
{
size = copyFile(crc, inputFile, out);
}
ZipEntry entry = new ZipEntry(filename);
entry.setCrc(crc.getValue());
entry.setSize(size);
outputStream.putNextEntry(entry);
out.writeTo(outputStream);
outputStream.closeEntry();
writtenItems.add(filename);
if (verbose)
{
long csize = entry.getCompressedSize();
long perc;
if (size == 0)
perc = 0;
else
perc = 100 - (100 * csize) / size;
String msg = MessageFormat.format(Messages.getString("Creator.Adding"), //$NON-NLS-1$
new Object[]
{
filename,
Long.valueOf(size),
Long.valueOf(entry.getSize()),
Long.valueOf(perc)
});
System.err.println(msg);
}
}
protected void writeFile(File file, String filename, boolean verbose)
throws IOException
{
boolean isDirectory = file.isDirectory();
InputStream inputStream = null;
if (isDirectory)
{
if (filename.charAt(filename.length() - 1) != '/')
filename += '/';
}
else
inputStream = new FileInputStream(file);
writeFile(isDirectory, inputStream, filename, verbose);
}
private void addEntries(ArrayList result, Entry entry)
{
if (entry.file.isDirectory())
{
String name = entry.name;
if (name.charAt(name.length() - 1) != '/')
{
name += '/';
entry = new Entry(entry.file, name);
}
result.add(entry);
String[] files = entry.file.list();
for (int i = 0; i < files.length; ++i)
addEntries(result, new Entry(new File(entry.file, files[i]),
entry.name + files[i]));
}
else
result.add(entry);
}
private ArrayList getAllEntries(Main parameters)
{
Iterator it = parameters.entries.iterator();
ArrayList allEntries = new ArrayList();
while (it.hasNext())
{
Entry entry = (Entry) it.next();
addEntries(allEntries, entry);
}
return allEntries;
}
private void writeCommandLineEntries(Main parameters)
throws IOException
{
// We've already written the manifest, make sure to mark it.
writtenItems.add("META-INF/"); //$NON-NLS-1$
writtenItems.add(JarFile.MANIFEST_NAME);
ArrayList allEntries = getAllEntries(parameters);
Iterator it = allEntries.iterator();
while (it.hasNext())
{
Entry entry = (Entry) it.next();
writeFile(entry.file, entry.name, parameters.verbose);
}
}
protected Manifest createManifest(Main parameters)
throws IOException
{
if (! parameters.wantManifest)
return null;
if (parameters.manifestFile != null)
{
// User specified a manifest file.
InputStream contents = new FileInputStream(parameters.manifestFile);
return new Manifest(contents);
}
return new Manifest();
}
protected void writeCommandLineEntries(Main parameters, OutputStream os)
throws IOException
{
manifest = createManifest(parameters);
outputStream = new JarOutputStream(os, manifest);
// FIXME: in Classpath this sets the method too late for the
// manifest file.
outputStream.setMethod(parameters.storageMode);
writeCommandLineEntries(parameters);
}
protected void close() throws IOException
{
outputStream.finish();
outputStream.close();
}
public void run(Main parameters) throws IOException
{
if (parameters.archiveFile == null || parameters.archiveFile.equals("-")) //$NON-NLS-1$
writeCommandLineEntries(parameters, System.out);
else
{
OutputStream os
= new BufferedOutputStream(new FileOutputStream(parameters.archiveFile));
writeCommandLineEntries(parameters, os);
}
close();
}
}
@@ -0,0 +1,60 @@
/* Entry.java - represent a single file to write to a jar
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.io.File;
public class Entry
{
public File file;
public String name;
public Entry(File file, String name)
{
this.file = file;
this.name = name;
}
public Entry(File file)
{
this.file = file;
this.name = file.toString();
}
}
@@ -0,0 +1,127 @@
/* Extractor.java - action to extract from a jar file
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.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Extractor
extends Action
{
// This is a set of all the items specified on the command line.
private WorkSet allItems;
private void copyFile(InputStream input, File output) throws IOException
{
FileOutputStream os = new FileOutputStream(output);
byte[] buffer = new byte[1024];
while (true)
{
int len = input.read(buffer);
if (len == - 1)
break;
os.write(buffer, 0, len);
}
os.close();
}
public void run(Main parameters) throws IOException
{
// Figure out what we want to extract.
allItems = new WorkSet(parameters.entries);
// Open the input file.
ZipInputStream zis;
File zfile = parameters.archiveFile;
if (zfile == null || "-".equals(zfile.getName())) //$NON-NLS-1$
zis = new ZipInputStream(System.in);
else
{
InputStream ins = new BufferedInputStream(new FileInputStream(zfile));
zis = new ZipInputStream(ins);
}
// Extract stuff.
while (true)
{
ZipEntry entry = zis.getNextEntry();
if (entry == null)
break;
if (! allItems.contains(entry.getName()))
continue;
File file = new File(entry.getName());
if (entry.isDirectory())
{
if (file.mkdirs())
{
if (parameters.verbose)
{
String msg
= MessageFormat.format(Messages.getString("Extractor.Created"), //$NON-NLS-1$
new Object[] { file });
System.err.println(msg);
}
}
continue;
}
File parent = file.getParentFile();
if (parent != null)
parent.mkdirs();
copyFile(zis, file);
if (parameters.verbose)
{
String fmt;
if (entry.getMethod() == ZipEntry.STORED)
fmt = Messages.getString("Extractor.Extracted"); //$NON-NLS-1$
else
fmt = Messages.getString("Extractor.Inflated"); //$NON-NLS-1$
String msg = MessageFormat.format(fmt, new Object[] { file });
System.err.println(msg);
}
}
}
}
@@ -0,0 +1,144 @@
/* Indexer.java -- add index.list file to jar
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 gnu.java.net.IndexListParser;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
public class Indexer
extends Updater
{
private void indexJarFile(StringBuffer result, File fileName,
boolean verbose)
throws IOException
{
if (verbose)
{
String msg = MessageFormat.format(Messages.getString("Indexer.Indexing"), //$NON-NLS-1$
new Object[] { fileName });
System.err.println(msg);
}
JarFile jf = new JarFile(fileName);
// Index the files in this jar.
// The results look a little better if we keep them
// in insertion order.
LinkedHashSet entries = new LinkedHashSet();
Enumeration e = jf.entries();
while (e.hasMoreElements())
{
JarEntry entry = (JarEntry) e.nextElement();
String name = entry.getName();
if (name.startsWith("META-INF/")) //$NON-NLS-1$
continue;
int index = name.lastIndexOf('/');
if (index != -1)
name = name.substring(0, index);
entries.add(name);
}
if (! entries.isEmpty())
{
result.append(fileName);
// Any line ending will do.
result.append('\n');
Iterator i = entries.iterator();
while (i.hasNext())
{
result.append(i.next());
result.append('\n');
}
// Paragraph break.
result.append('\n');
}
// Now read pointed-to jars.
Manifest m = jf.getManifest();
if (m != null)
{
File parent = fileName.getParentFile();
Attributes attrs = m.getMainAttributes();
String jars = attrs.getValue(Attributes.Name.CLASS_PATH);
if (jars != null)
{
StringTokenizer st = new StringTokenizer(jars, " "); //$NON-NLS-1$
while (st.hasMoreTokens())
{
String name = st.nextToken();
indexJarFile(result, new File(parent, name), verbose);
}
}
}
jf.close();
}
protected void writeCommandLineEntries(Main parameters, OutputStream os)
throws IOException
{
// This is a pretty lame design. We know the super call will
// only have side effects and won't actually write anything important.
super.writeCommandLineEntries(parameters, os);
// Now compute our index file and write it.
StringBuffer contents = new StringBuffer();
indexJarFile(contents, parameters.archiveFile, parameters.verbose);
if (contents.length() != 0)
{
// Insert in reverse order to avoid computing anything.
contents.insert(0, "1.0\n\n"); //$NON-NLS-1$
contents.insert(0, IndexListParser.JAR_INDEX_VERSION_KEY);
ByteArrayInputStream in
= new ByteArrayInputStream(contents.toString().getBytes());
writeFile(false, in, IndexListParser.JAR_INDEX_FILE, parameters.verbose);
}
}
}
@@ -0,0 +1,112 @@
/* Lister.java - action to list contents of a jar file
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.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;
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;
if (verbose)
format = new MessageFormat(" {0,date,E M dd HH:mm:ss z yyyy} {1}");
while (true)
{
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.
String s = " " + size;
int index = Math.min(s.length() - 5, 5);
System.out.print(s.substring(index));
Object[] values = new Object[] { new Date(entry.getTime()),
entry.getName() };
System.out.println(format.format(values));
}
else
System.out.println(entry.getName());
}
}
public void run(Main parameters) throws IOException
{
allItems = new WorkSet(parameters.entries);
File file = parameters.archiveFile;
ZipInputStream zis;
if (file == null || "-".equals(file.getName()))
zis = new ZipInputStream(System.in);
else
zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)));
listJar(zis, parameters.verbose);
}
}
@@ -0,0 +1,266 @@
/* Main.java - jar program main()
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 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.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.zip.ZipOutputStream;
public class Main
{
/** The mode of operation. This is the class representing
* the action; we make a new instance before using it. It
* must be a subclass of Action. 'null' means the mode
* has not yet been set. */
Class operationMode;
/** The archive file name. */
File archiveFile;
/** The zip storage mode. */
int storageMode = ZipOutputStream.DEFLATED;
/** True if we should read file names from stdin. */
boolean readNamesFromStdin = false;
/** True for verbose mode. */
boolean verbose = false;
/** True if we want a manifest file. */
boolean wantManifest = true;
/** Name of manifest file to use. */
File manifestFile;
/** A list of Entry objects, each describing a file to write. */
ArrayList entries = new ArrayList();
/** Used only while parsing, holds the first argument for -C. */
String changedDirectory;
void setArchiveFile(String filename) throws OptionException
{
if (archiveFile != null)
{
String fmt = MessageFormat.format(Messages.getString("Main.ArchiveAlreadySet"), //$NON-NLS-1$
new Object[] { archiveFile });
throw new OptionException(fmt);
}
archiveFile = new File(filename);
}
class HandleFile
extends FileArgumentCallback
{
public void notifyFile(String fileArgument)
{
Entry entry;
if (changedDirectory != null)
{
entry = new Entry(new File(changedDirectory, fileArgument),
fileArgument);
changedDirectory = null;
}
else
entry = new Entry(new File(fileArgument));
entries.add(entry);
}
}
// An option that knows how to set the operation mode.
private class ModeOption
extends Option
{
private Class mode;
public ModeOption(char shortName, String description, Class mode)
{
super(shortName, description);
this.mode = mode;
}
public ModeOption(char shortName, String description, String argName,
Class mode)
{
super(shortName, description, argName);
this.mode = mode;
}
public void parsed(String argument) throws OptionException
{
if (operationMode != null)
throw new OptionException(Messages.getString("Main.ModeAlreaySet")); //$NON-NLS-1$
operationMode = mode;
// We know this is only the case for -i.
if (argument != null)
setArchiveFile(argument);
}
}
private class JarParser extends ClasspathToolParser
{
public JarParser(String name)
{
super(name);
}
protected void validate() throws OptionException
{
if (operationMode == null)
throw new OptionException(Messages.getString("Main.MustSpecify")); //$NON-NLS-1$
if (changedDirectory != null)
throw new OptionException(Messages.getString("Main.TwoArgsReqd")); //$NON-NLS-1$
if (! wantManifest && manifestFile != null)
throw new OptionException(Messages.getString("Main.CantHaveBoth")); //$NON-NLS-1$
if (operationMode == Indexer.class)
{
// Some extra validation for -i.
if (! entries.isEmpty())
throw new OptionException(Messages.getString("Main.NoFilesWithi")); //$NON-NLS-1$
if (! wantManifest)
throw new OptionException(Messages.getString("Main.NoMAndi")); //$NON-NLS-1$
if (manifestFile != null)
throw new OptionException(Messages.getString("Main.AnotherNomAndi")); //$NON-NLS-1$
}
}
}
private Parser initializeParser()
{
Parser p = new JarParser("jar"); //$NON-NLS-1$
p.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
OptionGroup grp = new OptionGroup(Messages.getString("Main.OpMode")); //$NON-NLS-1$
grp.add(new ModeOption('c', Messages.getString("Main.Create"), Creator.class)); //$NON-NLS-1$
grp.add(new ModeOption('x', Messages.getString("Main.Extract"), Extractor.class)); //$NON-NLS-1$
grp.add(new ModeOption('t', Messages.getString("Main.List"), Lister.class)); //$NON-NLS-1$
grp.add(new ModeOption('u', Messages.getString("Main.Update"), Updater.class)); //$NON-NLS-1$
// Note that -i works in-place and explicitly requires a file name.
grp.add(new ModeOption('i', Messages.getString("Main.Index"), Messages.getString("Main.FileArg"), Indexer.class)); //$NON-NLS-1$ //$NON-NLS-2$
p.add(grp);
grp = new OptionGroup(Messages.getString("Main.OpMods")); //$NON-NLS-1$
grp.add(new Option('f', Messages.getString("Main.ArchiveName"), Messages.getString("Main.FileArg2")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
setArchiveFile(argument);
}
});
grp.add(new Option('0', Messages.getString("Main.NoZip")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
storageMode = ZipOutputStream.STORED;
}
});
grp.add(new Option('v', Messages.getString("Main.Verbose")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
grp.add(new Option('M', Messages.getString("Main.NoManifest")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
wantManifest = false;
}
});
grp.add(new Option('m', Messages.getString("Main.ManifestName"), Messages.getString("Main.ManifestArgName")) //$NON-NLS-1$ //$NON-NLS-2$
{
public void parsed(String argument) throws OptionException
{
manifestFile = new File(argument);
}
});
// -@
p.add(grp);
grp = new OptionGroup(Messages.getString("Main.FileNameGroup")); //$NON-NLS-1$
grp.add(new Option('C', Messages.getString("Main.ChangeDir"), //$NON-NLS-1$
Messages.getString("Main.ChangeDirArg")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
changedDirectory = argument;
}
});
p.add(grp);
return p;
}
private void run(String[] args)
throws InstantiationException, IllegalAccessException, IOException
{
Parser p = initializeParser();
// Special hack to emulate old tar-style commands.
if (args.length > 0 && args[0].charAt(0) != '-')
args[0] = '-' + args[0];
p.parse(args, new HandleFile());
Action t = (Action) operationMode.newInstance();
t.run(this);
}
public static void main(String[] args)
{
Main jarprogram = new Main();
try
{
jarprogram.run(args);
}
catch (Exception e)
{
System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
e.printStackTrace(System.err);
System.exit(1);
}
}
}
@@ -0,0 +1,67 @@
/* Messages.java -- localization support for jar
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.MissingResourceException;
import java.util.ResourceBundle;
public class Messages
{
private static final String BUNDLE_NAME
= "gnu.classpath.tools.jar.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 + '!';
}
}
}
@@ -0,0 +1,91 @@
/* Updater.java - action to update a jar file
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.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
public class Updater
extends Creator
{
JarFile inputJar;
protected Manifest createManifest(Main parameters) throws IOException
{
Manifest result = inputJar.getManifest();
if (result == null)
return super.createManifest(parameters);
if (parameters.manifestFile != null)
result.read(new FileInputStream(parameters.manifestFile));
return result;
}
public void run(Main parameters) throws IOException
{
// Set this early so that createManifest can use it.
inputJar = new JarFile(parameters.archiveFile);
// Write all the new entries to a temporary file.
File tmpFile = File.createTempFile("jarcopy", null);
OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile));
writeCommandLineEntries(parameters, os);
// Now read the old file and copy extra entries to the new file.
Enumeration e = inputJar.entries();
while (e.hasMoreElements())
{
ZipEntry entry = (ZipEntry) e.nextElement();
if (writtenItems.contains(entry.getName()))
continue;
writeFile(entry.isDirectory(), inputJar.getInputStream(entry),
entry.getName(), parameters.verbose);
}
close();
tmpFile.renameTo(parameters.archiveFile);
}
}
@@ -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;
}
}
@@ -141,7 +141,7 @@ public class JarSigner
main.isInternalSF());
log.finer("Created .DSA file"); //$NON-NLS-1$
if (main.isVerbose())
System.out.println(Messages.getString("JarSigner.11") + dsaFileName); //$NON-NLS-1$
System.out.println(Messages.getString("JarSigner.8") + dsaFileName); //$NON-NLS-1$
// cleanup
outSignedJarFile.close();
@@ -39,9 +39,13 @@ exception statement from your version. */
package gnu.classpath.tools.jarsigner;
import gnu.classpath.SystemProperties;
import gnu.classpath.tools.HelpPrinter;
import gnu.classpath.tools.common.CallbackUtil;
import gnu.classpath.tools.common.ProviderUtil;
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.OptionGroup;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.javax.security.auth.callback.ConsoleCallbackHandler;
@@ -61,6 +65,7 @@ import java.security.Security;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.jar.Attributes.Name;
import java.util.logging.Logger;
@@ -81,8 +86,8 @@ import javax.security.auth.callback.UnsupportedCallbackException;
*/
public class Main
{
private static final Logger log = Logger.getLogger(Main.class.getName());
private static final String HELP_PATH = "jarsigner/jarsigner.txt"; //$NON-NLS-1$
protected static final Logger log = Logger.getLogger(Main.class.getName());
static final String KEYTOOL_TOOL = "jarsigner"; //$NON-NLS-1$
private static final Locale EN_US_LOCALE = new Locale("en", "US"); //$NON-NLS-1$ //$NON-NLS-2$
static final String DIGEST = "SHA1-Digest"; //$NON-NLS-1$
static final String DIGEST_MANIFEST = "SHA1-Digest-Manifest"; //$NON-NLS-1$
@@ -91,20 +96,20 @@ public class Main
static final OID DSA_SIGNATURE_OID = new OID(Registry.DSA_OID_STRING);
static final OID RSA_SIGNATURE_OID = new OID(Registry.RSA_OID_STRING);
private boolean verify;
private String ksURL;
private String ksType;
private String password;
private String ksPassword;
private String sigFileName;
private String signedJarFileName;
private boolean verbose;
private boolean certs;
private boolean internalSF;
private boolean sectionsOnly;
private String providerClassName;
private String jarFileName;
private String alias;
protected boolean verify;
protected String ksURL;
protected String ksType;
protected String password;
protected String ksPassword;
protected String sigFileName;
protected String signedJarFileName;
protected boolean verbose;
protected boolean certs;
protected boolean internalSF;
protected boolean sectionsOnly;
protected String providerClassName;
protected String jarFileName;
protected String alias;
protected Provider provider;
private boolean providerInstalled;
@@ -115,6 +120,9 @@ public class Main
private Certificate[] signerCertificateChain;
/** The callback handler to use when needing to interact with user. */
private CallbackHandler handler;
/** The command line parser. */
private ToolParser cmdLineParser;
protected ArrayList fileAndAlias = new ArrayList();;
private Main()
{
@@ -126,10 +134,12 @@ public class Main
log.entering(Main.class.getName(), "main", args); //$NON-NLS-1$
Main tool = new Main();
int result = 1;
try
{
tool.processArgs(args);
tool.start();
result = 0;
}
catch (SecurityException x)
{
@@ -141,11 +151,13 @@ public class Main
log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$
System.err.println(Messages.getString("Main.9") + x); //$NON-NLS-1$
}
finally
{
tool.teardown();
}
tool.teardown();
log.exiting(Main.class.getName(), "main"); //$NON-NLS-1$
// System.exit(0);
log.exiting(Main.class.getName(), "main", Integer.valueOf(result)); //$NON-NLS-1$
System.exit(result);
}
// helper methods -----------------------------------------------------------
@@ -155,65 +167,15 @@ public class Main
* preparation for the user desired action.
*
* @param args an array of options (strings).
* @throws Exception if an exceptio occurs during the process.
* @throws Exception if an exception occurs during the process.
*/
private void processArgs(String[] args) throws Exception
{
log.entering(this.getClass().getName(), "processArgs", args); //$NON-NLS-1$
HelpPrinter.checkHelpKey(args, HELP_PATH);
if (args == null || args.length == 0)
HelpPrinter.printHelpAndExit(HELP_PATH);
int limit = args.length;
log.finest("args.length=" + limit); //$NON-NLS-1$
int i = 0;
String opt;
while (i < limit)
{
opt = args[i++];
log.finest("args[" + (i - 1) + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-verify".equals(opt)) // -verify //$NON-NLS-1$
verify = true;
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
ksURL = args[i++];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
ksType = args[i++];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
ksPassword = args[i++];
else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
password = args[i++];
else if ("-sigfile".equals(opt)) // -sigfile NAME //$NON-NLS-1$
sigFileName = args[i++];
else if ("-signedjar".equals(opt)) // -signedjar FILE_NAME //$NON-NLS-1$
signedJarFileName = args[i++];
else if ("-verbose".equals(opt)) // -verbose //$NON-NLS-1$
verbose = true;
else if ("-certs".equals(opt)) // -certs //$NON-NLS-1$
certs = true;
else if ("-internalsf".equals(opt)) // -internalsf //$NON-NLS-1$
internalSF = true;
else if ("-sectionsonly".equals(opt)) // -sectionsonly //$NON-NLS-1$
sectionsOnly = true;
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
providerClassName = args[i++];
else
{
jarFileName = opt;
if (! verify)
alias = args[i++];
break;
}
}
if (i < limit) // more options than needed
log.fine("Last argument is assumed at index #" + (i - 1) //$NON-NLS-1$
+ ". Remaining arguments (" + args[i] //$NON-NLS-1$
+ "...) will be ignored"); //$NON-NLS-1$
cmdLineParser = new ToolParser();
cmdLineParser.initializeParser();
cmdLineParser.parse(args, new ToolParserCallback());
setupCommonParams();
if (verify)
@@ -319,9 +281,6 @@ public class Main
{
log.entering(this.getClass().getName(), "setupCommonParams"); //$NON-NLS-1$
if (jarFileName == null)
HelpPrinter.printHelpAndExit(HELP_PATH);
File jar = new File(jarFileName);
if (! jar.exists())
throw new FileNotFoundException(jarFileName);
@@ -429,9 +388,6 @@ public class Main
InputStream stream = url.openStream();
store.load(stream, ksPasswordChars);
if (alias == null)
HelpPrinter.printHelpAndExit(HELP_PATH);
if (! store.containsAlias(alias))
throw new SecurityException(Messages.getFormattedString("Main.6", alias)); //$NON-NLS-1$
@@ -564,4 +520,155 @@ public class Main
return handler;
}
private class ToolParserCallback
extends FileArgumentCallback
{
public void notifyFile(String fileArgument)
{
fileAndAlias.add(fileArgument);
}
}
private class ToolParser
extends ClasspathToolParser
{
public ToolParser()
{
super(KEYTOOL_TOOL, true);
}
protected void validate() throws OptionException
{
if (fileAndAlias.size() < 1)
throw new OptionException(Messages.getString("Main.133")); //$NON-NLS-1$
jarFileName = (String) fileAndAlias.get(0);
if (! verify) // must have an ALIAS. use "mykey" if undefined
if (fileAndAlias.size() < 2)
{
log.finer("Missing ALIAS argument. Will use [mykey] instead"); //$NON-NLS-1$
alias = "mykey"; //$NON-NLS-1$
}
else
alias = (String) fileAndAlias.get(1);
}
public void initializeParser()
{
setHeader(Messages.getString("Main.2")); //$NON-NLS-1$
setFooter(Messages.getString("Main.1")); //$NON-NLS-1$
OptionGroup signGroup = new OptionGroup(Messages.getString("Main.0")); //$NON-NLS-1$
signGroup.add(new Option("keystore", //$NON-NLS-1$
Messages.getString("Main.101"), //$NON-NLS-1$
Messages.getString("Main.102")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
ksURL = argument;
}
});
signGroup.add(new Option("storetype", //$NON-NLS-1$
Messages.getString("Main.104"), //$NON-NLS-1$
Messages.getString("Main.105")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
ksType = argument;
}
});
signGroup.add(new Option("storepass", //$NON-NLS-1$
Messages.getString("Main.107"), //$NON-NLS-1$
Messages.getString("Main.108")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
ksPassword = argument;
}
});
signGroup.add(new Option("keypass", //$NON-NLS-1$
Messages.getString("Main.110"), //$NON-NLS-1$
Messages.getString("Main.111")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
password = argument;
}
});
signGroup.add(new Option("sigfile", //$NON-NLS-1$
Messages.getString("Main.113"), //$NON-NLS-1$
Messages.getString("Main.114")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
sigFileName = argument;
}
});
signGroup.add(new Option("signedjar", //$NON-NLS-1$
Messages.getString("Main.116"), //$NON-NLS-1$
Messages.getString("Main.117")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
signedJarFileName = argument;
}
});
add(signGroup);
OptionGroup verifyGroup = new OptionGroup(Messages.getString("Main.118")); //$NON-NLS-1$
verifyGroup.add(new Option("verify", //$NON-NLS-1$
Messages.getString("Main.120")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verify = true;
}
});
verifyGroup.add(new Option("certs", //$NON-NLS-1$
Messages.getString("Main.122")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
certs = true;
}
});
add(verifyGroup);
OptionGroup commonGroup = new OptionGroup(Messages.getString("Main.123")); //$NON-NLS-1$
commonGroup.add(new Option("verbose", //$NON-NLS-1$
Messages.getString("Main.125")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
commonGroup.add(new Option("internalsf", //$NON-NLS-1$
Messages.getString("Main.127")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
internalSF = true;
}
});
commonGroup.add(new Option("sectionsonly", //$NON-NLS-1$
Messages.getString("Main.129")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
sectionsOnly = true;
}
});
commonGroup.add(new Option("provider", //$NON-NLS-1$
Messages.getString("Main.131"), //$NON-NLS-1$
Messages.getString("Main.132")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
providerClassName = argument;
}
});
add(commonGroup);
}
}
}
@@ -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
{
@@ -0,0 +1,60 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- package.html - describes classes in gnu.classpath.tools.jarsigner
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. -->
<html>
<head>
<title>GNU Classpath - gnu.classpath.tools.jarsigner</title>
</head>
<body>
This package contains the classes that provide an implementation of the
Security Tool: <code>jarsigner</code>. The behaviour of these classes should
match that of the same tool provided in the RI version 1.4.2, except for the
following:
<ul>
<li>The RI tool accepts -J<i>javaoption</i> options which it then passes to
the underlying JVM. This is because the RI tool acts as a <i>wrapper</i>
around the JVM launcher.
<p>
This implementation DOES NOT support these options.
</li>
</ul>
</body>
</html>
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.OID;
import gnu.java.security.der.BitString;
import gnu.java.security.der.DER;
@@ -123,7 +128,7 @@ import javax.security.auth.x500.X500Principal;
*
* <dt>-keypass PASSWORD</dt>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -170,15 +175,16 @@ import javax.security.auth.x500.X500Principal;
class CertReqCmd extends Command
{
private static final Logger log = Logger.getLogger(CertReqCmd.class.getName());
private String _alias;
private String _sigAlgorithm;
private String _certReqFileName;
private String _password;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
private boolean nullAttributes;
private static final String ATTRIBUTES_OPT = "attributes"; //$NON-NLS-1$
protected String _alias;
protected String _sigAlgorithm;
protected String _certReqFileName;
protected String _password;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
protected boolean nullAttributes;
// default 0-arguments constructor
@@ -246,60 +252,19 @@ class CertReqCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM //$NON-NLS-1$
_sigAlgorithm = args[++i];
else if ("-file".equals(opt)) // -file FILE_NAME //$NON-NLS-1$
_certReqFileName = args[++i];
else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
_password = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else if ("-attributes".equals(opt)) //$NON-NLS-1$
nullAttributes = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setOutputStreamParam(_certReqFileName);
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
// setSignatureAlgorithm(_sigAlgorithm);
log.finer("-certreq handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -sigalg=" + _sigAlgorithm); //$NON-NLS-1$
log.finer(" -file=" + _certReqFileName); //$NON-NLS-1$
log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
log.finer(" -attributes=" + nullAttributes); //$NON-NLS-1$
@@ -346,6 +311,108 @@ class CertReqCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.CERTREQ_CMD, true);
result.setHeader(Messages.getString("CertReqCmd.25")); //$NON-NLS-1$
result.setFooter(Messages.getString("CertReqCmd.24")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("CertReqCmd.23")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("CertReqCmd.22"), //$NON-NLS-1$
Messages.getString("CertReqCmd.21")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.SIGALG_OPT,
Messages.getString("CertReqCmd.20"), //$NON-NLS-1$
Messages.getString("CertReqCmd.19")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_sigAlgorithm = argument;
}
});
options.add(new Option(Main.FILE_OPT,
Messages.getString("CertReqCmd.18"), //$NON-NLS-1$
Messages.getString("CertReqCmd.17")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_certReqFileName = argument;
}
});
options.add(new Option(Main.KEYPASS_OPT,
Messages.getString("CertReqCmd.16"), //$NON-NLS-1$
Messages.getString("CertReqCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_password = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("CertReqCmd.14"), //$NON-NLS-1$
Messages.getString("CertReqCmd.13")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("CertReqCmd.12"), //$NON-NLS-1$
Messages.getString("CertReqCmd.11")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("CertReqCmd.10"), //$NON-NLS-1$
Messages.getString("CertReqCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("CertReqCmd.8"), //$NON-NLS-1$
Messages.getString("CertReqCmd.7")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("CertReqCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
options.add(new Option(ATTRIBUTES_OPT,
Messages.getString("CertReqCmd.5")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
nullAttributes = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
/**
* @param aliasName
* @param publicKey
@@ -42,6 +42,7 @@ import gnu.classpath.SystemProperties;
import gnu.classpath.tools.common.CallbackUtil;
import gnu.classpath.tools.common.ProviderUtil;
import gnu.classpath.tools.common.SecurityProviderInfo;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.OID;
import gnu.java.security.Registry;
import gnu.java.security.der.BitString;
@@ -167,10 +168,17 @@ abstract class Command
private int providerNdx = -2;
/** The callback handler to use when needing to interact with user. */
private CallbackHandler handler;
/** The shutdown hook. */
private ShutdownHook shutdownThread;
// Constructor(s) -----------------------------------------------------------
// default 0-arguments constructor
protected Command()
{
super();
shutdownThread = new ShutdownHook();
Runtime.getRuntime().addShutdownHook(shutdownThread);
}
// Methods ------------------------------------------------------------------
@@ -193,14 +201,16 @@ abstract class Command
public void doCommand() throws Exception
{
try
{
setup();
start();
}
{
setup();
start();
}
finally
{
teardown();
}
{
teardown();
if (shutdownThread != null)
Runtime.getRuntime().removeShutdownHook(shutdownThread);
}
}
/**
@@ -228,11 +238,18 @@ abstract class Command
*
* @param args an array of options for this handler and possibly other
* commands and their options.
* @param startIndex the index of the first argument in <code>args</code> to
* process.
* @return the index of the first unprocessed argument in <code>args</code>.
* @return the remaining un-processed <code>args</code>.
*/
abstract int processArgs(String[] args, int startIndex);
String[] processArgs(String[] args)
{
log.entering(this.getClass().getName(), "processArgs", args); //$NON-NLS-1$
Parser cmdOptionsParser = getParser();
String[] result = cmdOptionsParser.parse(args);
log.exiting(this.getClass().getName(), "processArgs", result); //$NON-NLS-1$
return result;
}
/**
* Initialize this concrete command handler for later invocation of the
@@ -345,6 +362,12 @@ abstract class Command
// parameter setup and validation methods -----------------------------------
/**
* @return a {@link Parser} that knows how to parse the concrete command's
* options.
*/
abstract Parser getParser();
/**
* Convenience method to setup the key store given its type, its password, its
* location and portentially a specialized security provider.
@@ -486,7 +509,6 @@ abstract class Command
storePasswordChars = pcb.getPassword();
pcb.clearPassword();
}
log.finest("storePasswordChars = [" + String.valueOf(storePasswordChars)+ "]"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -575,7 +597,7 @@ abstract class Command
catch (IOException x)
{
log.fine("Exception while closing the key store input stream: " + x //$NON-NLS-1$
+ ". Ignore"); //$NON-NLS-1$
+ ". Ignore"); //$NON-NLS-1$
}
}
@@ -970,7 +992,7 @@ abstract class Command
protected void saveKeyStore(char[] password) throws IOException,
KeyStoreException, NoSuchAlgorithmException, CertificateException
{
log.entering(this.getClass().getName(), "saveKeyStore", String.valueOf(password)); //$NON-NLS-1$
log.entering(this.getClass().getName(), "saveKeyStore"); //$NON-NLS-1$
URLConnection con = storeURL.openConnection();
con.setDoOutput(true);
@@ -1144,4 +1166,15 @@ abstract class Command
return handler;
}
// Inner class(es) ==========================================================
private class ShutdownHook
extends Thread
{
public void run()
{
teardown();
}
}
}
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
@@ -64,7 +70,7 @@ import javax.security.auth.callback.UnsupportedCallbackException;
* omitted from the command line.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -106,11 +112,11 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class DeleteCmd extends Command
{
private static final Logger log = Logger.getLogger(DeleteCmd.class.getName());
private String _alias;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _alias;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
// default 0-arguments constructor
@@ -148,36 +154,6 @@ class DeleteCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
@@ -187,7 +163,6 @@ class DeleteCmd extends Command
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -206,6 +181,73 @@ class DeleteCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.DELETE_CMD, true);
result.setHeader(Messages.getString("DeleteCmd.18")); //$NON-NLS-1$
result.setFooter(Messages.getString("DeleteCmd.17")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("DeleteCmd.16")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("DeleteCmd.15"), //$NON-NLS-1$
Messages.getString("DeleteCmd.14")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("DeleteCmd.13"), //$NON-NLS-1$
Messages.getString("DeleteCmd.12")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("DeleteCmd.11"), //$NON-NLS-1$
Messages.getString("DeleteCmd.10")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("DeleteCmd.9"), //$NON-NLS-1$
Messages.getString("DeleteCmd.8")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("DeleteCmd.7"), //$NON-NLS-1$
Messages.getString("DeleteCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("DeleteCmd.5")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
/**
* Set the alias to delete from the key store.
* <p>
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.util.Base64;
import java.io.IOException;
@@ -69,7 +74,7 @@ import java.util.logging.Logger;
* exported to. If omitted, STDOUT will be used instead.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -119,13 +124,13 @@ import java.util.logging.Logger;
class ExportCmd extends Command
{
private static final Logger log = Logger.getLogger(ExportCmd.class.getName());
private String _alias;
private String _certFileName;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
private boolean rfc;
protected String _alias;
protected String _certFileName;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
protected boolean rfc;
// default 0-arguments constructor
@@ -178,72 +183,37 @@ class ExportCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt);
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS
_alias = args[++i];
else if ("-file".equals(opt)) // -file FILE_NAME
_certFileName = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME
_providerClassName = args[++i];
else if ("-rfc".equals(opt))
rfc = true;
else if ("-v".equals(opt))
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setOutputStreamParam(_certFileName);
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
log.finer("-export handler will use the following options:");
log.finer(" -alias=" + alias);
log.finer(" -file=" + _certFileName);
log.finer(" -storetype=" + storeType);
log.finer(" -keystore=" + storeURL);
log.finer(" -storepass=" + String.valueOf(storePasswordChars));
log.finer(" -provider=" + provider);
log.finer(" -rfc=" + rfc);
log.finer(" -v=" + verbose);
log.finer("-export handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -file=" + _certFileName); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -rfc=" + rfc); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
void start() throws KeyStoreException, CertificateEncodingException,
IOException
{
log.entering(this.getClass().getName(), "start");
log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
ensureStoreContainsAlias();
Certificate certificate;
if (store.isCertificateEntry(alias))
{
log.fine("Alias [" + alias + "] is a trusted certificate");
log.finer("Alias [" + alias + "] is a trusted certificate"); //$NON-NLS-1$ //$NON-NLS-2$
certificate = store.getCertificate(alias);
}
else
{
log.fine("Alias [" + alias + "] is a key entry");
log.finer("Alias [" + alias + "] is a key entry"); //$NON-NLS-1$ //$NON-NLS-2$
Certificate[] chain = store.getCertificateChain(alias);
certificate = chain[0];
}
@@ -253,14 +223,100 @@ class ExportCmd extends Command
{
String encoded = Base64.encode(derBytes, 0, derBytes.length, true);
PrintWriter pw = new PrintWriter(outStream, true);
pw.println("-----BEGIN CERTIFICATE-----");
pw.println("-----BEGIN CERTIFICATE-----"); //$NON-NLS-1$
pw.println(encoded);
pw.println("-----END CERTIFICATE-----");
pw.println("-----END CERTIFICATE-----"); //$NON-NLS-1$
}
else
outStream.write(derBytes);
// stream is closed in Command.teardown()
log.exiting(this.getClass().getName(), "start");
log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$
}
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.EXPORT_CMD, true);
result.setHeader(Messages.getString("ExportCmd.17")); //$NON-NLS-1$
result.setFooter(Messages.getString("ExportCmd.18")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("ExportCmd.19")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("ExportCmd.20"), //$NON-NLS-1$
Messages.getString("ExportCmd.21")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.FILE_OPT,
Messages.getString("ExportCmd.22"), //$NON-NLS-1$
Messages.getString("ExportCmd.23")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_certFileName = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("ExportCmd.24"), //$NON-NLS-1$
Messages.getString("ExportCmd.25")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("ExportCmd.26"), //$NON-NLS-1$
Messages.getString("ExportCmd.27")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("ExportCmd.28"), //$NON-NLS-1$
Messages.getString("ExportCmd.29")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("ExportCmd.30"), //$NON-NLS-1$
Messages.getString("ExportCmd.31")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.RFC_OPT,
Messages.getString("ExportCmd.32")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
rfc = true;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("ExportCmd.33")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
}
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.util.Util;
import gnu.java.security.x509.X500DistinguishedName;
@@ -153,7 +158,7 @@ import javax.security.auth.callback.UnsupportedCallbackException;
*
* <dt>-validity DAY_COUNT</dt>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -198,19 +203,20 @@ class GenKeyCmd extends Command
/** Default key size in bits. */
private static final int DEFAULT_KEY_SIZE = 1024;
private String _alias;
private String _keyAlgorithm;
private String _keySizeStr;
private String _sigAlgorithm;
private String _dName;
private String _password;
private String _validityStr;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _alias;
protected String _keyAlgorithm;
protected String _keySizeStr;
protected String _sigAlgorithm;
protected String _dName;
protected String _password;
protected String _validityStr;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
private int keySize;
private X500DistinguishedName distinguishedName;
private Parser cmdOptionsParser;
// default 0-arguments constructor
@@ -294,48 +300,6 @@ class GenKeyCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-keyalg".equals(opt)) // -keyalg ALGORITHM //$NON-NLS-1$
_keyAlgorithm = args[++i];
else if ("-keysize".equals(opt)) // -keysize KEY_SIZE //$NON-NLS-1$
_keySizeStr = args[++i];
else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM //$NON-NLS-1$
_sigAlgorithm = args[++i];
else if ("-dname".equals(opt)) // -dname NAME //$NON-NLS-1$
_dName = args[++i];
else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
_password = args[++i];
else if ("-validity".equals(opt)) // -validity DAY_COUNT //$NON-NLS-1$
_validityStr = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
@@ -352,11 +316,9 @@ class GenKeyCmd extends Command
log.finer(" -keysize=" + keySize); //$NON-NLS-1$
log.finer(" -sigalg=" + signatureAlgorithm.getAlgorithm()); //$NON-NLS-1$
log.finer(" -dname=" + distinguishedName); //$NON-NLS-1$
log.finer(" -keypass=" + String.valueOf(keyPasswordChars)); //$NON-NLS-1$
log.finer(" -validity=" + validityInDays); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -368,14 +330,14 @@ class GenKeyCmd extends Command
log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
// 1. generate a new key-pair
log.fine("About to generate key-pair...");
log.finer("About to generate key-pair..."); //$NON-NLS-1$
keyPairGenerator.initialize(keySize);
KeyPair kp = keyPairGenerator.generateKeyPair();
PublicKey publicKey = kp.getPublic();
PrivateKey privateKey = kp.getPrivate();
// 2. generate a self-signed certificate
log.fine("About to generate a self-signed certificate...");
log.finer("About to generate a self-signed certificate..."); //$NON-NLS-1$
byte[] derBytes = getSelfSignedCertificate(distinguishedName,
publicKey,
privateKey);
@@ -398,6 +360,127 @@ class GenKeyCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.GENKEY_CMD, true);
result.setHeader(Messages.getString("GenKeyCmd.57")); //$NON-NLS-1$
result.setFooter(Messages.getString("GenKeyCmd.58")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("GenKeyCmd.59")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("GenKeyCmd.60"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.61")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.KEYALG_OPT,
Messages.getString("GenKeyCmd.62"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.63")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_keyAlgorithm = argument;
}
});
options.add(new Option(Main.KEYSIZE_OPT,
Messages.getString("GenKeyCmd.64"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.65")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_keySizeStr = argument;
}
});
options.add(new Option(Main.SIGALG_OPT,
Messages.getString("GenKeyCmd.66"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.63")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_sigAlgorithm = argument;
}
});
options.add(new Option(Main.DNAME_OPT,
Messages.getString("GenKeyCmd.68"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.69")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_dName = argument;
}
});
options.add(new Option(Main.KEYPASS_OPT,
Messages.getString("GenKeyCmd.70"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.71")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_password = argument;
}
});
options.add(new Option(Main.VALIDITY_OPT,
Messages.getString("GenKeyCmd.72"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.73")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_validityStr = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("GenKeyCmd.74"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.75")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("GenKeyCmd.76"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.77")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("GenKeyCmd.78"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.71")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("GenKeyCmd.80"), //$NON-NLS-1$
Messages.getString("GenKeyCmd.81")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("GenKeyCmd.82")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
/**
* @param size the desired key size as a string.
* @throws NumberFormatException if the string does not represent a valid
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.util.logging.Logger;
/**
@@ -55,7 +61,7 @@ import java.util.logging.Logger;
* option is omitted, the tool will process STDIN.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -97,11 +103,11 @@ import java.util.logging.Logger;
class IdentityDBCmd extends Command
{
private static final Logger log = Logger.getLogger(IdentityDBCmd.class.getName());
private String _idbFileName;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _idbFileName;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
// default 0-arguments constructor
@@ -139,47 +145,85 @@ class IdentityDBCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt);
if (opt == null || opt.length() == 0)
continue;
if ("-file".equals(opt)) // -file FILE_NAME
_idbFileName = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME
_providerClassName = args[++i];
else if ("-v".equals(opt))
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setInputStreamParam(_idbFileName);
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
log.finer("-identitydb handler will use the following options:");
log.finer(" -file=" + _idbFileName);
log.finer(" -storetype=" + storeType);
log.finer(" -keystore=" + storeURL);
log.finer(" -storepass=" + new String(storePasswordChars));
log.finer(" -provider=" + provider);
log.finer(" -v=" + verbose);
log.finer("-identitydb handler will use the following options:"); //$NON-NLS-1$
log.finer(" -file=" + _idbFileName); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.IDENTITYDB_CMD, true);
result.setHeader(Messages.getString("IdentityDBCmd.7")); //$NON-NLS-1$
result.setFooter(Messages.getString("IdentityDBCmd.8")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("IdentityDBCmd.9")); //$NON-NLS-1$
options.add(new Option(Main.FILE_OPT,
Messages.getString("IdentityDBCmd.10"), //$NON-NLS-1$
Messages.getString("IdentityDBCmd.11")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_idbFileName = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("IdentityDBCmd.12"), //$NON-NLS-1$
Messages.getString("IdentityDBCmd.13")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("IdentityDBCmd.14"), //$NON-NLS-1$
Messages.getString("IdentityDBCmd.15")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("IdentityDBCmd.16"), //$NON-NLS-1$
Messages.getString("IdentityDBCmd.17")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("IdentityDBCmd.18"), //$NON-NLS-1$
Messages.getString("IdentityDBCmd.19")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("IdentityDBCmd.20")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
}
@@ -39,6 +39,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.SystemProperties;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.x509.X509CertPath;
import java.io.FileInputStream;
@@ -47,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;
@@ -57,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;
@@ -139,7 +148,7 @@ import javax.security.auth.callback.UnsupportedCallbackException;
* should be considered when trying to establish chain-of-trusts.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -181,17 +190,37 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class ImportCmd extends Command
{
private static final Logger log = Logger.getLogger(ImportCmd.class.getName());
private String _alias;
private String _certFileName;
private String _password;
private boolean noPrompt;
private boolean trustCACerts;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
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;
protected boolean noPrompt;
protected boolean trustCACerts;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
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
@@ -259,44 +288,6 @@ class ImportCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-file".equals(opt)) // -file FILE_NAME //$NON-NLS-1$
_certFileName = args[++i];
else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
_password = args[++i];
else if ("-noprompt".equals(opt)) //$NON-NLS-1$
noPrompt = true;
else if ("-trustcacerts".equals(opt)) //$NON-NLS-1$
trustCACerts = true;
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setInputStreamParam(_certFileName);
@@ -307,12 +298,10 @@ class ImportCmd extends Command
log.finer("-import handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -file=" + _certFileName); //$NON-NLS-1$
log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -noprompt=" + noPrompt); //$NON-NLS-1$
log.finer(" -trustcacerts=" + trustCACerts); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -323,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
@@ -339,6 +342,107 @@ class ImportCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.IMPORT_CMD, true);
result.setHeader(Messages.getString("ImportCmd.27")); //$NON-NLS-1$
result.setFooter(Messages.getString("ImportCmd.26")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("ImportCmd.25")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("ImportCmd.24"), //$NON-NLS-1$
Messages.getString("ImportCmd.23")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.FILE_OPT,
Messages.getString("ImportCmd.22"), //$NON-NLS-1$
Messages.getString("ImportCmd.21")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_certFileName = argument;
}
});
options.add(new Option(Main.KEYPASS_OPT,
Messages.getString("ImportCmd.20"), //$NON-NLS-1$
Messages.getString("ImportCmd.19")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_password = argument;
}
});
options.add(new Option("noprompt", //$NON-NLS-1$
Messages.getString("ImportCmd.18")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
noPrompt = true;
}
});
options.add(new Option("trustcacerts", //$NON-NLS-1$
Messages.getString("ImportCmd.17")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
trustCACerts = true;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("ImportCmd.16"), //$NON-NLS-1$
Messages.getString("ImportCmd.15")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("ImportCmd.14"), //$NON-NLS-1$
Messages.getString("ImportCmd.13")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("ImportCmd.12"), //$NON-NLS-1$
Messages.getString("ImportCmd.11")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("ImportCmd.10"), //$NON-NLS-1$
Messages.getString("ImportCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("ImportCmd.8")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
/**
* When importing a new trusted certificate, <i>alias</i> MUST NOT yet exist
* in the key store.
@@ -542,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)
@@ -598,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();
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;
}
@@ -646,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)
{
@@ -671,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;
@@ -705,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");
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
{
@@ -744,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;
}
}
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.io.IOException;
import java.security.Key;
import java.security.KeyStoreException;
@@ -90,7 +96,7 @@ import javax.security.auth.callback.UnsupportedCallbackException;
* material of the newly cloned copy of the <i>Key Entry</i>.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -132,14 +138,14 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class KeyCloneCmd extends Command
{
private static final Logger log = Logger.getLogger(KeyCloneCmd.class.getName());
private String _alias;
private String _destAlias;
private String _password;
private String _newPassword;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _alias;
protected String _destAlias;
protected String _password;
protected String _newPassword;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
private String destinationAlias;
private char[] newKeyPasswordChars;
@@ -197,58 +203,18 @@ class KeyCloneCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-dest".equals(opt)) // -dest ALIAS //$NON-NLS-1$
_destAlias = args[++i];
else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
_password = args[++i];
else if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$
_newPassword = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
setDestinationAlias(_destAlias);
// setNewKeyPassword(_newPassword);
log.finer("-keyclone handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -dest=" + destinationAlias); //$NON-NLS-1$
log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -new=" + _newPassword); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -276,6 +242,100 @@ class KeyCloneCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.KEYCLONE_CMD, true);
result.setHeader(Messages.getString("KeyCloneCmd.22")); //$NON-NLS-1$
result.setFooter(Messages.getString("KeyCloneCmd.21")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("KeyCloneCmd.20")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("KeyCloneCmd.19"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.16")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.DEST_OPT,
Messages.getString("KeyCloneCmd.17"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.16")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_destAlias = argument;
}
});
options.add(new Option(Main.KEYPASS_OPT,
Messages.getString("KeyCloneCmd.15"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_password = argument;
}
});
options.add(new Option(Main.NEW_OPT,
Messages.getString("KeyCloneCmd.13"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_newPassword = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("KeyCloneCmd.11"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.10")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("KeyCloneCmd.9"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.8")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("KeyCloneCmd.7"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("KeyCloneCmd.5"), //$NON-NLS-1$
Messages.getString("KeyCloneCmd.4")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("KeyCloneCmd.3")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
private void setDestinationAlias(String name) throws IOException,
UnsupportedCallbackException
{
@@ -294,9 +354,9 @@ class KeyCloneCmd extends Command
private void setNewKeyPassword(String password) throws IOException,
UnsupportedCallbackException
{
if (password != null) // ask user to provide one
if (password != null)
newKeyPasswordChars = password.toCharArray();
else
else // ask user to provide one
{
boolean ok = false;
Callback[] prompts = new Callback[1];
@@ -39,6 +39,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.SystemProperties;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.io.IOException;
import java.security.Key;
@@ -86,7 +91,7 @@ import javax.security.auth.callback.UnsupportedCallbackException;
* private key material of the designated Key Entry.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -128,13 +133,13 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class KeyPasswdCmd extends Command
{
private static final Logger log = Logger.getLogger(KeyPasswdCmd.class.getName());
private String _alias;
private String _password;
private String _newPassword;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _alias;
protected String _password;
protected String _newPassword;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
private char[] newPasswordChars;
// default 0-arguments constructor
@@ -185,54 +190,17 @@ class KeyPasswdCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-keypass".equals(opt)) // -keypass PASSWORD //$NON-NLS-1$
_password = args[++i];
else if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$
_newPassword = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
// setNewKeyPassword(_newPassword);
log.finer("-keypasswd handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -keypass=" + _password); //$NON-NLS-1$
log.finer(" -new=" + _newPassword); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -259,6 +227,91 @@ class KeyPasswdCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.KEYPASSWD_CMD, true);
result.setHeader(Messages.getString("KeyPasswdCmd.23")); //$NON-NLS-1$
result.setFooter(Messages.getString("KeyPasswdCmd.22")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("KeyPasswdCmd.21")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("KeyPasswdCmd.20"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.19")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.KEYPASS_OPT,
Messages.getString("KeyPasswdCmd.18"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_password = argument;
}
});
options.add(new Option(Main.NEW_OPT,
Messages.getString("KeyPasswdCmd.16"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_newPassword = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("KeyPasswdCmd.14"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.13")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("KeyPasswdCmd.12"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.11")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("KeyPasswdCmd.10"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("KeyPasswdCmd.8"), //$NON-NLS-1$
Messages.getString("KeyPasswdCmd.7")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("KeyPasswdCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
/**
* Set the new password to use for protecting Alias's private key.
*
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.util.Base64;
import java.io.IOException;
@@ -64,7 +69,7 @@ import java.util.logging.Logger;
* omitted from the command line.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -113,12 +118,12 @@ import java.util.logging.Logger;
class ListCmd extends Command
{
private static final Logger log = Logger.getLogger(ListCmd.class.getName());
private String _alias;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
private boolean rfc;
protected String _alias;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
protected boolean rfc;
private boolean all;
// default 0-arguments constructor
@@ -166,44 +171,11 @@ class ListCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS //$NON-NLS-1$
_alias = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else if ("-rfc".equals(opt)) //$NON-NLS-1$
rfc = true;
else
break;
}
all = _alias == null;
return i;
}
void setup() throws Exception
{
setOutputStreamParam(null); // use stdout
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
all = _alias == null;
if (! all)
setAliasParam(_alias);
@@ -218,7 +190,6 @@ class ListCmd extends Command
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
log.finer(" -rfc=" + rfc); //$NON-NLS-1$
@@ -254,6 +225,81 @@ class ListCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.LIST_CMD, true);
result.setHeader(Messages.getString("ListCmd.20")); //$NON-NLS-1$
result.setFooter(Messages.getString("ListCmd.19")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("ListCmd.18")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("ListCmd.17"), //$NON-NLS-1$
Messages.getString("ListCmd.16")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("ListCmd.15"), //$NON-NLS-1$
Messages.getString("ListCmd.14")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("ListCmd.13"), //$NON-NLS-1$
Messages.getString("ListCmd.12")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("ListCmd.11"), //$NON-NLS-1$
Messages.getString("ListCmd.10")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("ListCmd.9"), //$NON-NLS-1$
Messages.getString("ListCmd.8")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("ListCmd.7")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
options.add(new Option(Main.RFC_OPT,
Messages.getString("ListCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
rfc = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
/**
* Prints the certificate(s) associated with the designated alias.
*
@@ -312,7 +358,7 @@ class ListCmd extends Command
private void print1Chain(Certificate[] chain, PrintWriter writer)
throws CertificateEncodingException
{
if (!verbose && !rfc)
if (! verbose && ! rfc)
fingerprint(chain[0], writer);
else
{
@@ -38,8 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.HelpPrinter;
import gnu.classpath.tools.common.ProviderUtil;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.Registry;
import gnu.javax.crypto.jce.GnuCrypto;
import gnu.javax.security.auth.callback.GnuCallbacks;
@@ -57,8 +61,51 @@ import java.util.logging.Logger;
public class Main
{
private static final Logger log = Logger.getLogger(Main.class.getName());
/** The relative file path to the command tool's help text. */
private static final String HELP_PATH = "keytool/keytool.txt"; //$NON-NLS-1$
static final String KEYTOOL_TOOL = "keytool"; //$NON-NLS-1$
static final String GENKEY_CMD = "genkey"; //$NON-NLS-1$
static final String IMPORT_CMD = "import"; //$NON-NLS-1$
static final String SELFCERT_CMD = "selfcert"; //$NON-NLS-1$
static final String IDENTITYDB_CMD = "identitydb"; //$NON-NLS-1$
static final String CERTREQ_CMD = "certreq"; //$NON-NLS-1$
static final String EXPORT_CMD = "export"; //$NON-NLS-1$
static final String LIST_CMD = "list"; //$NON-NLS-1$
static final String PRINTCERT_CMD = "printcert"; //$NON-NLS-1$
static final String KEYCLONE_CMD = "keyclone"; //$NON-NLS-1$
static final String STOREPASSWD_CMD = "storepasswd"; //$NON-NLS-1$
static final String KEYPASSWD_CMD = "keypasswd"; //$NON-NLS-1$
static final String DELETE_CMD = "delete"; //$NON-NLS-1$
static final String _GENKEY = "-" + GENKEY_CMD; //$NON-NLS-1$
static final String _IMPORT = "-" + IMPORT_CMD; //$NON-NLS-1$
static final String _SELFCERT = "-" + SELFCERT_CMD; //$NON-NLS-1$
static final String _IDENTITYDB = "-" + IDENTITYDB_CMD; //$NON-NLS-1$
static final String _CERTREQ = "-" + CERTREQ_CMD; //$NON-NLS-1$
static final String _EXPORT = "-" + EXPORT_CMD; //$NON-NLS-1$
static final String _LIST = "-" + LIST_CMD; //$NON-NLS-1$
static final String _PRINTCERT = "-" + PRINTCERT_CMD; //$NON-NLS-1$
static final String _KEYCLONE = "-" + KEYCLONE_CMD; //$NON-NLS-1$
static final String _STOREPASSWD = "-" + STOREPASSWD_CMD; //$NON-NLS-1$
static final String _KEYPASSWD = "-" + KEYPASSWD_CMD; //$NON-NLS-1$
static final String _DELETE = "-" + DELETE_CMD; //$NON-NLS-1$
static final String _HELP = "-help"; //$NON-NLS-1$
static final String ALIAS_OPT = "alias"; //$NON-NLS-1$
static final String SIGALG_OPT = "sigalg"; //$NON-NLS-1$
static final String KEYALG_OPT = "keyalg"; //$NON-NLS-1$
static final String KEYSIZE_OPT = "keysize"; //$NON-NLS-1$
static final String KEYPASS_OPT = "keypass"; //$NON-NLS-1$
static final String VALIDITY_OPT = "validity"; //$NON-NLS-1$
static final String STORETYPE_OPT = "storetype"; //$NON-NLS-1$
static final String STOREPASS_OPT = "storepass"; //$NON-NLS-1$
static final String KEYSTORE_OPT = "keystore"; //$NON-NLS-1$
static final String PROVIDER_OPT = "provider"; //$NON-NLS-1$
static final String FILE_OPT = "file"; //$NON-NLS-1$
static final String VERBOSE_OPT = "v"; //$NON-NLS-1$
static final String DEST_OPT = "dest"; //$NON-NLS-1$
static final String NEW_OPT = "new"; //$NON-NLS-1$
static final String RFC_OPT = "rfc"; //$NON-NLS-1$
static final String DNAME_OPT = "dname"; //$NON-NLS-1$
/** The Preferences key name for the last issued certificate serial nbr. */
static final String LAST_SERIAL_NUMBER = "lastSerialNumber"; //$NON-NLS-1$
/** Constant denoting the X.509 certificate type. */
@@ -70,6 +117,8 @@ public class Main
private int gnuCryptoProviderNdx = -2;
/** The new position of GNU Callbacks provider if it is not already installed. */
private int gnuCallbacksNdx = -2;
/** The command line parser. */
private Parser cmdLineParser;
private Main()
{
@@ -81,119 +130,142 @@ public class Main
log.entering(Main.class.getName(), "main", args); //$NON-NLS-1$
Main tool = new Main();
int result = 1;
try
{
tool.setup();
tool.start(args);
result = 0;
}
catch (OptionException x)
{
System.err.println(x.getMessage());
if (tool.cmdLineParser != null)
tool.cmdLineParser.printHelp();
}
catch (SecurityException x)
{
log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$
System.err.println(Messages.getString("Main.6") + x.getMessage()); //$NON-NLS-1$
System.err.println(Messages.getFormattedString("Main.6", //$NON-NLS-1$
x.getMessage()));
}
catch (Exception x)
{
log.throwing(Main.class.getName(), "main", x); //$NON-NLS-1$
System.err.println(Messages.getString("Main.8") + x); //$NON-NLS-1$
System.err.println(Messages.getFormattedString("Main.8", x)); //$NON-NLS-1$
}
finally
{
tool.teardown();
}
{
tool.teardown();
}
log.exiting(Main.class.getName(), "main"); //$NON-NLS-1$
// System.exit(0);
log.exiting(Main.class.getName(), "main", Integer.valueOf(result)); //$NON-NLS-1$
System.exit(result);
}
// helper methods -----------------------------------------------------------
private void start(String[] args) throws Exception
{
log.entering(this.getClass().getName(), "start", args); //$NON-NLS-1$
if (args == null)
args = new String[0];
int limit = args.length;
log.finest("args.length=" + limit); //$NON-NLS-1$
int i = 0;
String opt;
Command cmd;
while (i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
cmd = null;
if ("-genkey".equals(opt)) //$NON-NLS-1$
cmd = new GenKeyCmd();
else if ("-import".equals(opt)) //$NON-NLS-1$
cmd = new ImportCmd();
else if ("-selfcert".equals(opt)) //$NON-NLS-1$
cmd = new SelfCertCmd();
else if ("-identitydb".equals(opt)) //$NON-NLS-1$
cmd = new IdentityDBCmd();
else if ("-certreq".equals(opt)) //$NON-NLS-1$
cmd = new CertReqCmd();
else if ("-export".equals(opt)) //$NON-NLS-1$
cmd = new ExportCmd();
else if ("-list".equals(opt)) //$NON-NLS-1$
cmd = new ListCmd();
else if ("-printcert".equals(opt)) //$NON-NLS-1$
cmd = new PrintCertCmd();
else if ("-keyclone".equals(opt)) //$NON-NLS-1$
cmd = new KeyCloneCmd();
else if ("-storepasswd".equals(opt)) //$NON-NLS-1$
cmd = new StorePasswdCmd();
else if ("-keypasswd".equals(opt)) //$NON-NLS-1$
cmd = new KeyPasswdCmd();
else if ("-delete".equals(opt)) //$NON-NLS-1$
cmd = new DeleteCmd();
else if ("-help".equals(opt)) //$NON-NLS-1$
{
printHelp();
i++;
}
else
{
log.fine("Unknown command [" + opt + "] at index #" + i //$NON-NLS-1$ //$NON-NLS-2$
+ ". Arguments from that token onward will be ignored"); //$NON-NLS-1$
break;
}
if (cmd != null)
{
i = cmd.processArgs(args, i);
cmd.doCommand();
}
}
// the -help command is the default; i.e.
// keytool
// is equivalent to:
// keytool -help
if (i == 0)
printHelp();
if (i < limit) // more options than needed
log.fine("Last recognized argument is assumed at index #" + (i - 1) //$NON-NLS-1$
+ ". Remaining arguments (" + args[i] + "...) will be ignored"); //$NON-NLS-1$ //$NON-NLS-2$
log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$
}
private void setup()
{
log.entering(this.getClass().getName(), "setup"); //$NON-NLS-1$
cmdLineParser = getParser();
gnuCryptoProviderNdx = ProviderUtil.addProvider(new GnuCrypto());
gnuCallbacksNdx = ProviderUtil.addProvider(new GnuCallbacks());
log.exiting(this.getClass().getName(), "setup"); //$NON-NLS-1$
}
private void start(String[] args) throws Exception
{
log.entering(this.getClass().getName(), "start"); //$NON-NLS-1$
if (args == null || args.length == 0)
throw new OptionException(""); //$NON-NLS-1$
String opt;
Command cmd;
while (args.length > 0)
{
opt = args[0];
cmd = null;
if (_GENKEY.equals(opt))
cmd = new GenKeyCmd();
else if (_IMPORT.equals(opt))
cmd = new ImportCmd();
else if (_SELFCERT.equals(opt))
cmd = new SelfCertCmd();
else if (_IDENTITYDB.equals(opt))
cmd = new IdentityDBCmd();
else if (_CERTREQ.equals(opt))
cmd = new CertReqCmd();
else if (_EXPORT.equals(opt))
cmd = new ExportCmd();
else if (_LIST.equals(opt))
cmd = new ListCmd();
else if (_PRINTCERT.equals(opt))
cmd = new PrintCertCmd();
else if (_KEYCLONE.equals(opt))
cmd = new KeyCloneCmd();
else if (_STOREPASSWD.equals(opt))
cmd = new StorePasswdCmd();
else if (_KEYPASSWD.equals(opt))
cmd = new KeyPasswdCmd();
else if (_DELETE.equals(opt))
cmd = new DeleteCmd();
else if (_HELP.equals(opt))
throw new OptionException(""); //$NON-NLS-1$
else
throw new OptionException(Messages.getFormattedString("Main.18", //$NON-NLS-1$
opt));
String[] cmdArgs = new String[args.length - 1];
System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length);
args = cmd.processArgs(cmdArgs);
cmd.doCommand();
}
log.exiting(this.getClass().getName(), "start"); //$NON-NLS-1$
}
private Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(KEYTOOL_TOOL, true);
result.setHeader(Messages.getString("Main.19")); //$NON-NLS-1$
result.setFooter(Messages.getString("Main.20")); //$NON-NLS-1$
OptionGroup cmdGroup = new OptionGroup(Messages.getString("Main.21")); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(GENKEY_CMD,
Messages.getString("Main.22"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(IMPORT_CMD,
Messages.getString("Main.23"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(SELFCERT_CMD,
Messages.getString("Main.24"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(IDENTITYDB_CMD,
Messages.getString("Main.25"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(CERTREQ_CMD,
Messages.getString("Main.26"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(EXPORT_CMD,
Messages.getString("Main.27"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(LIST_CMD,
Messages.getString("Main.28"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(PRINTCERT_CMD,
Messages.getString("Main.29"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(KEYCLONE_CMD,
Messages.getString("Main.30"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(STOREPASSWD_CMD,
Messages.getString("Main.31"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(KEYPASSWD_CMD,
Messages.getString("Main.32"))); //$NON-NLS-1$
cmdGroup.add(new NoParseOption(DELETE_CMD,
Messages.getString("Main.33"))); //$NON-NLS-1$
result.add(cmdGroup);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
private void teardown()
{
log.entering(this.getClass().getName(), "teardown"); //$NON-NLS-1$
@@ -213,7 +285,28 @@ public class Main
if (helpPrinted)
return;
HelpPrinter.printHelp(HELP_PATH);
helpPrinted = true;
}
// Inner class(es)
// ==========================================================================
private class NoParseOption
extends Option
{
public NoParseOption(String name, String description)
{
super(name, description);
}
public NoParseOption(String name, String description, String param)
{
super(name, description, param);
}
public void parsed(String argument) throws OptionException
{
// do nothing
}
}
}
@@ -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
{
@@ -38,6 +38,12 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.io.PrintWriter;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
@@ -63,7 +69,7 @@ import java.util.logging.Logger;
class PrintCertCmd extends Command
{
private static final Logger log = Logger.getLogger(PrintCertCmd.class.getName());
private String _certFileName;
protected String _certFileName;
// default 0-arguments constructor
@@ -77,40 +83,18 @@ class PrintCertCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt);
if (opt == null || opt.length() == 0)
continue;
if ("-file".equals(opt)) // -file FILE_NAME
_certFileName = args[++i];
else if ("-v".equals(opt))
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setInputStreamParam(_certFileName);
log.finer("-printcert handler will use the following options:");
log.finer(" -file=" + _certFileName);
log.finer(" -v=" + verbose);
log.finer("-printcert handler will use the following options:"); //$NON-NLS-1$
log.finer(" -file=" + _certFileName); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
void start() throws CertificateException
{
log.entering(getClass().getName(), "start");
log.entering(getClass().getName(), "start"); //$NON-NLS-1$
CertificateFactory x509Factory = CertificateFactory.getInstance(Main.X_509);
Certificate certificate = x509Factory.generateCertificate(inStream);
@@ -118,6 +102,39 @@ class PrintCertCmd extends Command
writer.println();
printVerbose(certificate, writer);
log.exiting(getClass().getName(), "start");
log.exiting(getClass().getName(), "start"); //$NON-NLS-1$
}
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.PRINTCERT_CMD, true);
result.setHeader(Messages.getString("PrintCertCmd.5")); //$NON-NLS-1$
result.setFooter(Messages.getString("PrintCertCmd.6")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("PrintCertCmd.7")); //$NON-NLS-1$
options.add(new Option(Main.FILE_OPT,
Messages.getString("PrintCertCmd.8"), //$NON-NLS-1$
Messages.getString("PrintCertCmd.9")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_certFileName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("PrintCertCmd.10")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
}
@@ -38,6 +38,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import gnu.java.security.x509.X500DistinguishedName;
import java.io.ByteArrayInputStream;
@@ -129,7 +134,7 @@ import javax.security.auth.x500.X500Principal;
*
* <dt>-keypass PASSWORD</dt>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -171,15 +176,15 @@ import javax.security.auth.x500.X500Principal;
class SelfCertCmd extends Command
{
private static final Logger log = Logger.getLogger(SelfCertCmd.class.getName());
private String _alias;
private String _sigAlgorithm;
private String _dName;
private String _password;
private String _validityStr;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _alias;
protected String _sigAlgorithm;
protected String _dName;
protected String _password;
protected String _validityStr;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
private X500DistinguishedName distinguishedName;
private int validityInDays;
@@ -253,71 +258,29 @@ class SelfCertCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt);
if (opt == null || opt.length() == 0)
continue;
if ("-alias".equals(opt)) // -alias ALIAS
_alias = args[++i];
else if ("-sigalg".equals(opt)) // -sigalg ALGORITHM
_sigAlgorithm = args[++i];
else if ("-dname".equals(opt)) // -dname NAME
_dName = args[++i];
else if ("-keypass".equals(opt)) // -keypass PASSWORD
_password = args[++i];
else if ("-validity".equals(opt)) // -validity DAY_COUNT
_validityStr = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME
_providerClassName = args[++i];
else if ("-v".equals(opt))
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setAliasParam(_alias);
setKeyPasswordNoPrompt(_password);
// setDName(_dName);
setValidityParam(_validityStr);
// setSignatureAlgorithm(_sigAlgorithm);
log.finer("-selfcert handler will use the following options:");
log.finer(" -alias=" + alias);
log.finer(" -sigalg=" + _sigAlgorithm);
log.finer(" -dname=" + _dName);
log.finer(" -keypass=" + _password);
log.finer(" -validity=" + validityInDays);
log.finer(" -storetype=" + storeType);
log.finer(" -keystore=" + storeURL);
log.finer(" -storepass=" + String.valueOf(storePasswordChars));
log.finer(" -provider=" + provider);
log.finer(" -v=" + verbose);
log.finer("-selfcert handler will use the following options:"); //$NON-NLS-1$
log.finer(" -alias=" + alias); //$NON-NLS-1$
log.finer(" -sigalg=" + _sigAlgorithm); //$NON-NLS-1$
log.finer(" -dname=" + _dName); //$NON-NLS-1$
log.finer(" -validity=" + validityInDays); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
void start() throws KeyStoreException, NoSuchAlgorithmException,
UnrecoverableKeyException, IOException, UnsupportedCallbackException,
InvalidKeyException, SignatureException, CertificateException
{
log.entering(getClass().getName(), "start");
log.entering(getClass().getName(), "start"); //$NON-NLS-1$
// 1. get the key entry and certificate chain associated to alias
Key privateKey = getAliasPrivateKey();
@@ -337,7 +300,7 @@ class SelfCertCmd extends Command
byte[] derBytes = getSelfSignedCertificate(distinguishedName,
publicKey,
(PrivateKey) privateKey);
CertificateFactory x509Factory = CertificateFactory.getInstance("X.509");
CertificateFactory x509Factory = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
ByteArrayInputStream bais = new ByteArrayInputStream(derBytes);
Certificate certificate = x509Factory.generateCertificate(bais);
@@ -348,11 +311,114 @@ class SelfCertCmd extends Command
// 7. persist the key store
saveKeyStore();
log.exiting(getClass().getName(), "start");
log.exiting(getClass().getName(), "start"); //$NON-NLS-1$
}
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.SELFCERT_CMD, true);
result.setHeader(Messages.getString("SelfCertCmd.14")); //$NON-NLS-1$
result.setFooter(Messages.getString("SelfCertCmd.15")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("SelfCertCmd.16")); //$NON-NLS-1$
options.add(new Option(Main.ALIAS_OPT,
Messages.getString("SelfCertCmd.17"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.18")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_alias = argument;
}
});
options.add(new Option(Main.SIGALG_OPT,
Messages.getString("SelfCertCmd.19"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.20")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_sigAlgorithm = argument;
}
});
options.add(new Option(Main.DNAME_OPT,
Messages.getString("SelfCertCmd.21"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.22")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_dName = argument;
}
});
options.add(new Option(Main.KEYPASS_OPT,
Messages.getString("SelfCertCmd.23"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.24")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_password = argument;
}
});
options.add(new Option(Main.VALIDITY_OPT,
Messages.getString("SelfCertCmd.25"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.26")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_validityStr = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("SelfCertCmd.27"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.28")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("SelfCertCmd.29"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.30")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("SelfCertCmd.31"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.32")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("SelfCertCmd.33"), //$NON-NLS-1$
Messages.getString("SelfCertCmd.34")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("SelfCertCmd.35")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
private void setDName(String name, X500Principal defaultName)
{
if (name != null && name.trim().length() > 0)
@@ -39,6 +39,11 @@ exception statement from your version. */
package gnu.classpath.tools.keytool;
import gnu.classpath.SystemProperties;
import gnu.classpath.tools.getopt.ClasspathToolParser;
import gnu.classpath.tools.getopt.Option;
import gnu.classpath.tools.getopt.OptionException;
import gnu.classpath.tools.getopt.OptionGroup;
import gnu.classpath.tools.getopt.Parser;
import java.io.IOException;
import java.security.KeyStoreException;
@@ -65,7 +70,7 @@ import javax.security.auth.callback.UnsupportedCallbackException;
* designated key store.
* <p></dd>
*
* <dt>-storetype STORE_TYP}</dt>
* <dt>-storetype STORE_TYPE</dt>
* <dd>Use this option to specify the type of the key store to use. The
* default value, if this option is omitted, is that of the property
* <code>keystore.type</code> in the security properties file, which is
@@ -107,11 +112,11 @@ import javax.security.auth.callback.UnsupportedCallbackException;
class StorePasswdCmd extends Command
{
private static final Logger log = Logger.getLogger(StorePasswdCmd.class.getName());
private String _newPassword;
private String _ksType;
private String _ksURL;
private String _ksPassword;
private String _providerClassName;
protected String _newPassword;
protected String _ksType;
protected String _ksURL;
protected String _ksPassword;
protected String _providerClassName;
private char[] newStorePasswordChars;
// default 0-arguments constructor
@@ -150,46 +155,14 @@ class StorePasswdCmd extends Command
// life-cycle methods -------------------------------------------------------
int processArgs(String[] args, int i)
{
int limit = args.length;
String opt;
while (++i < limit)
{
opt = args[i];
log.finest("args[" + i + "]=" + opt); //$NON-NLS-1$ //$NON-NLS-2$
if (opt == null || opt.length() == 0)
continue;
if ("-new".equals(opt)) // -new PASSWORD //$NON-NLS-1$
_newPassword = args[++i];
else if ("-storetype".equals(opt)) // -storetype STORE_TYPE //$NON-NLS-1$
_ksType = args[++i];
else if ("-keystore".equals(opt)) // -keystore URL //$NON-NLS-1$
_ksURL = args[++i];
else if ("-storepass".equals(opt)) // -storepass PASSWORD //$NON-NLS-1$
_ksPassword = args[++i];
else if ("-provider".equals(opt)) // -provider PROVIDER_CLASS_NAME //$NON-NLS-1$
_providerClassName = args[++i];
else if ("-v".equals(opt)) //$NON-NLS-1$
verbose = true;
else
break;
}
return i;
}
void setup() throws Exception
{
setKeyStoreParams(_providerClassName, _ksType, _ksPassword, _ksURL);
setNewKeystorePassword(_newPassword);
log.finer("-storepasswd handler will use the following options:"); //$NON-NLS-1$
log.finer(" -new=" + String.valueOf(newStorePasswordChars)); //$NON-NLS-1$
log.finer(" -storetype=" + storeType); //$NON-NLS-1$
log.finer(" -keystore=" + storeURL); //$NON-NLS-1$
log.finer(" -storepass=" + String.valueOf(storePasswordChars)); //$NON-NLS-1$
log.finer(" -provider=" + provider); //$NON-NLS-1$
log.finer(" -v=" + verbose); //$NON-NLS-1$
}
@@ -206,6 +179,73 @@ class StorePasswdCmd extends Command
// own methods --------------------------------------------------------------
Parser getParser()
{
log.entering(this.getClass().getName(), "getParser"); //$NON-NLS-1$
Parser result = new ClasspathToolParser(Main.STOREPASSWD_CMD, true);
result.setHeader(Messages.getString("StorePasswdCmd.18")); //$NON-NLS-1$
result.setFooter(Messages.getString("StorePasswdCmd.17")); //$NON-NLS-1$
OptionGroup options = new OptionGroup(Messages.getString("StorePasswdCmd.16")); //$NON-NLS-1$
options.add(new Option(Main.NEW_OPT,
Messages.getString("StorePasswdCmd.15"), //$NON-NLS-1$
Messages.getString("StorePasswdCmd.8")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_newPassword = argument;
}
});
options.add(new Option(Main.STORETYPE_OPT,
Messages.getString("StorePasswdCmd.13"), //$NON-NLS-1$
Messages.getString("StorePasswdCmd.12")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksType = argument;
}
});
options.add(new Option(Main.KEYSTORE_OPT,
Messages.getString("StorePasswdCmd.11"), //$NON-NLS-1$
Messages.getString("StorePasswdCmd.10")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksURL = argument;
}
});
options.add(new Option(Main.STOREPASS_OPT,
Messages.getString("StorePasswdCmd.9"), //$NON-NLS-1$
Messages.getString("StorePasswdCmd.8")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_ksPassword = argument;
}
});
options.add(new Option(Main.PROVIDER_OPT,
Messages.getString("StorePasswdCmd.7"), //$NON-NLS-1$
Messages.getString("StorePasswdCmd.6")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
_providerClassName = argument;
}
});
options.add(new Option(Main.VERBOSE_OPT,
Messages.getString("StorePasswdCmd.5")) //$NON-NLS-1$
{
public void parsed(String argument) throws OptionException
{
verbose = true;
}
});
result.add(options);
log.exiting(this.getClass().getName(), "getParser", result); //$NON-NLS-1$
return result;
}
protected void setNewKeystorePassword(String password) throws IOException,
UnsupportedCallbackException
{
@@ -0,0 +1,65 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- package.html - describes classes in gnu.classpath.tools.keytool
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. -->
<html>
<head>
<title>GNU Classpath - gnu.classpath.tools.keytool</title>
</head>
<body>
This package contains the classes that provide an implementation of the
Security Tool: <code>keytool</code>. The behaviour of these classes should
match that of the same tool provided in the RI version 1.4.2, except for the
following:
<ul>
<li>The RI tool accepts -J<i>javaoption</i> options which it then passes to
the underlying JVM. This is because the RI tool acts as a <i>wrapper</i>
around the JVM launcher.
<p>
This implementation DOES NOT support these options.
</li>
<li>The RI tool is capable of importing JDK-1.1 style <i>identities</i>.
<p>
This implementation does not offer this feature.
</li>
</ul>
</body>
</html>
@@ -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 + '!';
}
}
}
@@ -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$
}
}
@@ -41,7 +41,7 @@ public class RMIC
/**
* The version of the compiler.
*/
public static String VERSION = "0.0 alpha pre";
public static String VERSION = "0.01 alpha pre";
/**
* The GRMIC compiler methods
@@ -112,6 +112,17 @@ public class RMIC
else
HelpPrinter.printHelpAndExit(HelpPath);
}
else if (c.equals("-classpath"))
{
int f = i + 1;
if (f < args.length)
{
compiler.setClassPath(args[f]);
i++;
}
else
HelpPrinter.printHelpAndExit(HelpPath);
}
else if (c.charAt(0) != '-')
// No more options - start of class list.
{
@@ -132,17 +143,7 @@ public class RMIC
if (args[i].charAt(0) != '-')
{
compiler.reset();
Class c = null;
try
{
c = Thread.currentThread().getContextClassLoader().loadClass(
args[i]);
}
catch (ClassNotFoundException e)
{
System.err.println(args[i] + " class not found.");
System.exit(1);
}
Class c = compiler.loadClass(args[i]);
compiler.compile(c);
String packag = compiler.getPackageName().replace('.', '/');
@@ -9,25 +9,29 @@ Please report bugs at http://www.gnu.org/software/classpath/bugs.html
Usage: rmic <options> <class names>
where <options> includes:
-nowarn Show no warnings
-nowrite Do not write any files (check for errors only)
-d <folder> Place generated files into the given folder
-nowarn Show no warnings
-nowrite Do not write any files (check for errors only)
-d <folder> Place generated files into the given folder
-classpath <path> Specifies the path, where to find the classes being
compiled
-help Print this help text
-v Print version
-verbose Verbose output
-force Try to generate code even if the input classes seem not
consistent with RMI specification.
-help Print this help text
-v Print version
-verbose Verbose output
-force Try to generate code even if the input classes seem not
consistent with RMI specification.
-1.2 Generate v 1.2 stubs (default)*
-1.2 Generate v 1.2 stubs (default)*
-iiop Generate stubs and ties for the GIOP based RMI package extension,
javax.rmi. With this key, the two additional keys are accepted:
-poa Generate the Servant based ties (default)
-impl Generate the obsoleted ObjectImpl based ties
(for backward compatibility)
-help Show more details on the giop stub and tie generator options.
-giop Same as -iiop*
-iiop Generate stubs and ties for the GIOP based RMI package
extension, javax.rmi. With this key, the two additional
keys are accepted:
-poa Generate the Servant based ties (default)
-impl Generate the obsoleted ObjectImpl based ties
(for backward compatibility)
-help Show more details on the giop stub and tie generator
options.
-giop Same as -iiop*
and <class names> can include one or more non abstract classes that implement
@@ -0,0 +1,46 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- package.html - describes classes in gnu.java.rmi.registry package.
Copyright (C) 2005 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. -->
<html>
<head><title>GNU Classpath - gnu.classpath.tools.rmi.registry</title></head>
<body>
<p></p>
</body>
</html>
@@ -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 + '!';
}
}
}
@@ -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);
}
}
+47
View File
@@ -0,0 +1,47 @@
#!/bin/sh
## Copyright (C) 2006 Free Software Foundation, Inc.
##
## This file is a 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 of the License, 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; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, 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.
##
##
## A simple shell script to launch the GNU Classpath jarsigner tool.
##
prefix=@prefix@
tools_dir=@datadir@/@PACKAGE@
tools_cp=${tools_dir}/tools.zip
exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" gnu.classpath.tools.jarsigner.Main $@
+47
View File
@@ -0,0 +1,47 @@
#!/bin/sh
## Copyright (C) 2006 Free Software Foundation, Inc.
##
## This file is a 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 of the License, 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; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, 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.
##
##
## A simple shell script to launch the GNU Classpath keytool tool.
##
prefix=@prefix@
tools_dir=@datadir@/@PACKAGE@
tools_cp=${tools_dir}/tools.zip
exec @VM_BINARY@ -Xbootclasspath/p:"${tools_cp}" gnu.classpath.tools.keytool.Main $@
+220
View File
@@ -0,0 +1,220 @@
/* 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.
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. */
#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include "config.h"
#ifndef JNI_VERSION_1_2
# error JNI version 1.2 or greater required
#endif
union env_union
{
void *void_env;
JNIEnv *jni_env;
};
int
main (int argc, const char** argv)
{
union env_union tmp;
JNIEnv* env;
JavaVM* jvm;
JavaVMInitArgs vm_args;
jint result;
jclass class_id;
jmethodID method_id;
jstring str;
jclass string_class_id;
jobjectArray args_array;
char** non_vm_argv;
int non_vm_argc;
int i;
int classpath_found = 0;
env = NULL;
jvm = NULL;
vm_args.nOptions = 0;
vm_args.options = NULL;
non_vm_argc = 0;
non_vm_argv = NULL;
if (argc > 1)
{
for (i = 1; i < argc; i++)
{
if (!strncmp (argv[i], "-J", 2))
{
if (!strncmp (argv[i], "-J-Djava.class.path=", 20))
classpath_found = 1;
/* A virtual machine option. */
vm_args.options = (JavaVMOption*) realloc (vm_args.options, (vm_args.nOptions + 1) * sizeof (JavaVMOption));
if (vm_args.options == NULL)
{
fprintf (stderr, TOOLNAME ": realloc failed.\n");
goto destroy;
}
if (strlen (argv[i]) == 2)
{
fprintf (stderr, TOOLNAME ": the -J option must not be followed by a space.\n");
goto destroy;
}
else
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)
{
fprintf (stderr, TOOLNAME ": realloc failed.\n");
goto destroy;
}
non_vm_argv[non_vm_argc++] = strdup (argv[i]);
}
}
}
if (!classpath_found)
{
/* Set the invocation classpath. */
vm_args.options = (JavaVMOption*) realloc (vm_args.options, (vm_args.nOptions + 1) * sizeof (JavaVMOption));
if (vm_args.options == NULL)
{
fprintf (stderr, TOOLNAME ": realloc failed.\n");
goto destroy;
}
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)
{
fprintf (stderr, TOOLNAME ": realloc failed.\n");
goto destroy;
}
vm_args.options[vm_args.nOptions].optionString = NULL;
/* Terminate non_vm_argv with a NULL element. */
non_vm_argv = (char**) realloc (non_vm_argv, (non_vm_argc + 1) * sizeof (char*));
if (non_vm_argv == NULL)
{
fprintf (stderr, TOOLNAME ": realloc failed.\n");
goto destroy;
}
non_vm_argv[non_vm_argc] = NULL;
vm_args.version = JNI_VERSION_1_2;
vm_args.ignoreUnrecognized = JNI_TRUE;
result = JNI_CreateJavaVM (&jvm, &tmp.void_env, &vm_args);
if (result < 0)
{
fprintf (stderr, TOOLNAME ": couldn't create virtual machine\n");
goto destroy;
}
env = tmp.jni_env;
string_class_id = (*env)->FindClass (env, "java/lang/String");
if (string_class_id == NULL)
{
fprintf (stderr, TOOLNAME ": FindClass failed.\n");
goto destroy;
}
args_array = (*env)->NewObjectArray (env, non_vm_argc, string_class_id, NULL);
if (args_array == NULL)
{
fprintf (stderr, TOOLNAME ": NewObjectArray failed.\n");
goto destroy;
}
for (i = 0; i < non_vm_argc; i++)
{
str = (*env)->NewStringUTF (env, non_vm_argv[i]);
if (str == NULL)
{
fprintf (stderr, TOOLNAME ": NewStringUTF failed.\n");
goto destroy;
}
(*env)->SetObjectArrayElement (env, args_array, i, str);
}
class_id = (*env)->FindClass (env, "gnu/classpath/tools/" TOOLNAME "/Main");
if (class_id == NULL)
{
fprintf (stderr, TOOLNAME ": FindClass failed.\n");
goto destroy;
}
method_id = (*env)->GetStaticMethodID (env, class_id, "main", "([Ljava/lang/String;)V");
if (method_id == NULL)
{
fprintf (stderr, TOOLNAME ": GetStaticMethodID failed.\n");
goto destroy;
}
(*env)->CallStaticVoidMethod (env, class_id, method_id, args_array);
destroy:
if (env != NULL)
{
if ((*env)->ExceptionOccurred (env))
(*env)->ExceptionDescribe (env);
if (jvm != NULL)
(*jvm)->DestroyJavaVM (jvm);
}
return 1;
}