diff --git a/langtools/make/README b/langtools/make/README index 466426d8ad6..bc8873178ef 100644 --- a/langtools/make/README +++ b/langtools/make/README @@ -15,7 +15,7 @@ that expect to be able to build this workspace with GNU Make. System Requirements: Ant: version 1.6.5 or later - NetBeans: version 5.0 or later (optional) + NetBeans: version 6.0 or later (optional) JDK: currently version 1.5.0, although 1.6.0 is recommended OS: any system supporting the above tools diff --git a/langtools/make/build.xml b/langtools/make/build.xml index 7b9e1457bf0..770f3dd040c 100644 --- a/langtools/make/build.xml +++ b/langtools/make/build.xml @@ -660,7 +660,7 @@ - + diff --git a/langtools/make/netbeans/README b/langtools/make/netbeans/README index 7208e598e6a..58cfec07cee 100644 --- a/langtools/make/netbeans/README +++ b/langtools/make/netbeans/README @@ -1,28 +1,39 @@ -Working on the "langtools" workspace using NetBeans. +Using NetBeans to work on the langtools repository. -This directory (make/netbeans) contains NetBeans projects that -allow you to work on the various tools using the NetBeans IDE. +Netbeans 6.0 or later is recommended. -NetBeans 5.0 or later is required and sufficient to use these -projects. This is different from other projects in OpenJDK, -which requires version 6.0 or later. +The "langtools" project in this directory allows you to +edit, run, test and debug the tools in the OpenJDK langtools +repository. -The following projects are provided: +The repository contains a number of tools: + apt, javac, javadoc and its doclets, javah and javap. -compiler: for working on the compiler, javac -javadoc: for working on the documentation tool, javadoc -doclets: for working on the standard doclets used by the - documentation tool, javadoc -javah: for working on the C header tool, javah -javap: for working on the disassembler, javap -apt: for working on the annotation processing tool, apt. - Note that this is just provided for completeness; - the tool has been superceded by new features in javac, - and work on apt itself is discouraged. +Build Properties. -However, any tool can be worked on from any project; the only difference -between these projects is the behavior of the standard NetBeans actions, -so that "Build" in the compiler project will build the compiler, etc. +To build this repository, you must set some properties for Ant. +You can set these properties in a number of ways: +- Set the properties in the Properties panel under Tool> Options> Ant. + Properties set this way will apply globally to all the langtools + repositories you may be working on. +- Create a file build.properties in the root directory of a + langtools repository, and set the properties in that file. + These properties will be specific to that repository. +To build the repository, at a minimum you must set the "boot.java.home" +property. To run the tools, you must also set "target.java.home". To +run the regression tests, you must set "jtreg.home". + +By default, the build and test targets will build and test all +of these tools. The run and debug targets will prompt you for the +name of a tool to execute. + +As an alternative, you can focus on a single tool. When you do +this, you will still see all the source code for all the tools, +but the various Ant targets will now be focussed on the selected tool. +To focus on a tool, bring up the context menu on the "langtools" +project (i.e. right-click on the project) and select "Select Tool". +This brings up a dialog which allows you to specify which tool you +wish to work on, and the arguments to use if and when you run it. diff --git a/langtools/make/netbeans/apt/README b/langtools/make/netbeans/apt/README deleted file mode 100644 index 6fa70ee080e..00000000000 --- a/langtools/make/netbeans/apt/README +++ /dev/null @@ -1,15 +0,0 @@ -"apt" project README. - -This project is for working on the annotation processing tool (apt) -in the OpenJDK langtools component. - -The tool was provided in Java 1.5, but has been superceded by new -features in the compiler (javac) in Java 6. apt itself is now -deprecated, and any further devlopment on it is strongly discouraged. - -The main class for the tool is com.sun.tools.apt.Main. - -NetBeans 5.0 or later is required and sufficient to use this -project, and others in the OpenJDK langtools component. -This is different from other projects in OpenJDK, which -require version 6.0 or later. diff --git a/langtools/make/netbeans/apt/build.xml b/langtools/make/netbeans/apt/build.xml deleted file mode 100644 index 6b4a72e3a4a..00000000000 --- a/langtools/make/netbeans/apt/build.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/apt/nbproject/project.xml b/langtools/make/netbeans/apt/nbproject/project.xml deleted file mode 100644 index 6987228768f..00000000000 --- a/langtools/make/netbeans/apt/nbproject/project.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - -]> - - org.netbeans.modules.ant.freeform - - - - apt - - ../../.. - - - - - ${root} - - - - java - ${root}/src/share/classes - - - - tests - ${root}/test - - - - build - ${root}/make - - - - &standard-ide-actions-no-javadoc; - - - folder - ${root}/build/classes - build - - - - - - ${root}/src/share/classes - - - - ${root}/test - - - - ${root}/make - - - - README - - - - &standard-context-menu-items-no-javadoc; - - - - - - - ${root}/src/share/classes - ${root}/build/classes - 1.5 - - - - diff --git a/langtools/make/netbeans/common/shared.xml b/langtools/make/netbeans/common/shared.xml deleted file mode 100644 index 015a08c8b77..00000000000 --- a/langtools/make/netbeans/common/shared.xml +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - - - - - - - - - - Must set property 'includes' - - - - - - - - - - - - - Must set property 'run.classname' - - - - - - - - Some tests failed; see report for details. - - - - - - - - - - - - - Must set property 'debug.classname' - - - - - - - - Must set property 'jtreg.tests' - - - - - - - - Must set property 'class' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/common/standard-context-menu-items-no-javadoc.ent b/langtools/make/netbeans/common/standard-context-menu-items-no-javadoc.ent deleted file mode 100644 index c40ee69c213..00000000000 --- a/langtools/make/netbeans/common/standard-context-menu-items-no-javadoc.ent +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/common/standard-ide-actions-no-javadoc.ent b/langtools/make/netbeans/common/standard-ide-actions-no-javadoc.ent deleted file mode 100644 index 912daf729a8..00000000000 --- a/langtools/make/netbeans/common/standard-ide-actions-no-javadoc.ent +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - build - - - - clean - - - - clean - build - - - - compile-single - ${root}/src/share/classes - - includes - ${root}/src/share/classes - \.java$ - relative-path - - , - - - - - - run - - - - run-single - - run.classname - ${root}/src/share/classes - \.java$ - java-name - - - - - - - - - - jtreg - - jtreg.tests - ${root}/test - \.(java|sh)$ - relative-path - - , - - - - - - jtreg - - - - debug-nb - - - - debug-single-nb - - debug.classname - ${root}/src/share/classes - \.java$ - java-name - - - - - - - - - - debug-jtreg-nb - - jtreg.tests - ${root}/test - \.(java|sh)$ - relative-path - - - - - - - - debug-fix - ${root}/src/share/classes - - class - ${root}/src/share/classes - \.java$ - relative-path-noext - - - - - - - - -javadoc-nb - diff --git a/langtools/make/netbeans/compiler/README b/langtools/make/netbeans/compiler/README deleted file mode 100644 index 9dc7ff11888..00000000000 --- a/langtools/make/netbeans/compiler/README +++ /dev/null @@ -1,11 +0,0 @@ -"compiler" project README. - -This project is for working on the compiler tool (javac) -in the OpenJDK langtools component. - -The main class for the tool is com.sun.tools.javac.Main. - -NetBeans 5.0 or later is required and sufficient to use this -project, and others in the OpenJDK langtools component. -This is different from other projects in OpenJDK, which -require version 6.0 or later. diff --git a/langtools/make/netbeans/compiler/build.xml b/langtools/make/netbeans/compiler/build.xml deleted file mode 100644 index 1c1df801a52..00000000000 --- a/langtools/make/netbeans/compiler/build.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/compiler/nbproject/project.xml b/langtools/make/netbeans/compiler/nbproject/project.xml deleted file mode 100644 index ac52705ef99..00000000000 --- a/langtools/make/netbeans/compiler/nbproject/project.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - -]> - - org.netbeans.modules.ant.freeform - - - - compiler - - ../../.. - - - - - ${root} - - - - java - ${root}/src/share/classes - - - - tests - ${root}/test - - - - build - ${root}/make - - - - &standard-ide-actions; - - - folder - ${root}/build/classes - build - - - - - - ${root}/src/share/classes - - - - ${root}/test - - - - ${root}/make - - - - README - - - - &standard-context-menu-items; - - - - - - - ${root}/src/share/classes - ${root}/build/classes - 1.5 - - - - diff --git a/langtools/make/netbeans/doclets/README b/langtools/make/netbeans/doclets/README deleted file mode 100644 index eb7e61b6524..00000000000 --- a/langtools/make/netbeans/doclets/README +++ /dev/null @@ -1,16 +0,0 @@ -"doclets" project README. - -This project is for working on the standard doclets used by -the documentation tool (javadoc) in the OpenJDK langtools component. - -The doclets are invoked as part of the documentation tool (javadoc). -Using this project, you can also browse javadoc and any tools in langtools. -If you build the doclets, javadoc will be built automatically as well, -if necessary. - -The doclets are found in com.sun.tools.doclets. - -NetBeans 5.0 or later is required and sufficient to use this -project, and others in the OpenJDK langtools component. -This is different from other projects in OpenJDK, which -require version 6.0 or later. diff --git a/langtools/make/netbeans/doclets/build.xml b/langtools/make/netbeans/doclets/build.xml deleted file mode 100644 index a390161c14d..00000000000 --- a/langtools/make/netbeans/doclets/build.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/doclets/nbproject/project.xml b/langtools/make/netbeans/doclets/nbproject/project.xml deleted file mode 100644 index f0fa2f45d74..00000000000 --- a/langtools/make/netbeans/doclets/nbproject/project.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - -]> - - org.netbeans.modules.ant.freeform - - - - doclets - - ../../.. - - - - - ${root} - - - - java - ${root}/src/share/classes - - - - tests - ${root}/test - - - - build - ${root}/make - - - - &standard-ide-actions-no-javadoc; - - - folder - ${root}/build/classes - build - - - - - - ${root}/src/share/classes - - - - ${root}/test - - - - ${root}/make - - - - README - - - - &standard-context-menu-items-no-javadoc; - - - - - - - ${root}/src/share/classes - ${root}/build/classes - 1.5 - - - - diff --git a/langtools/make/netbeans/javadoc/README b/langtools/make/netbeans/javadoc/README deleted file mode 100644 index e0027ccb397..00000000000 --- a/langtools/make/netbeans/javadoc/README +++ /dev/null @@ -1,16 +0,0 @@ -"javadoc" project README. - -This project is for working on the documentation tool (javadoc) -in the OpenJDK langtools component. - -javadoc is built on top of the compiler (javac). Using this -project, you can also browse javac and any tools in langtools. -If you build javadoc, javac will be built automatically as well, -if necessary. - -The main class for the tool is com.sun.tools.javadoc.Main. - -NetBeans 5.0 or later is required and sufficient to use this -project, and others in the OpenJDK langtools component. -This is different from other projects in OpenJDK, which -require version 6.0 or later. diff --git a/langtools/make/netbeans/javadoc/build.xml b/langtools/make/netbeans/javadoc/build.xml deleted file mode 100644 index ba565a6bc58..00000000000 --- a/langtools/make/netbeans/javadoc/build.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/javah/README b/langtools/make/netbeans/javah/README deleted file mode 100644 index 6e94fb1f68d..00000000000 --- a/langtools/make/netbeans/javah/README +++ /dev/null @@ -1,21 +0,0 @@ -"javah" project README. - -This project is for working on the native header tool (javah) -in the OpenJDK langtools component. - -javah is built on top of the documentation tool (javadoc). Using this -project, you can also browse javadoc and any other tools in langtools. -If you build javah, javadoc will be built automatically as well, -if necessary. - -javah is in the process of being converted so that it runs directly on -top of the compiler, javac, using the annotation processing API, -instead of on top of the documentation tool, javadoc, using the -Doclet API. - -The main class for the tool is com.sun.tools.javah.Main. - -NetBeans 5.0 or later is required and sufficient to use this -project, and others in the OpenJDK langtools component. -This is different from other projects in OpenJDK, which -require version 6.0 or later. diff --git a/langtools/make/netbeans/javah/build.xml b/langtools/make/netbeans/javah/build.xml deleted file mode 100644 index 578cd1458a9..00000000000 --- a/langtools/make/netbeans/javah/build.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/javah/nbproject/project.xml b/langtools/make/netbeans/javah/nbproject/project.xml deleted file mode 100644 index d4db76f39be..00000000000 --- a/langtools/make/netbeans/javah/nbproject/project.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - -]> - - org.netbeans.modules.ant.freeform - - - - javah - - ../../.. - - - - - ${root} - - - - java - ${root}/src/share/classes - - - - tests - ${root}/test - - - - build - ${root}/make - - - - &standard-ide-actions-no-javadoc; - - - folder - ${root}/build/classes - build - - - - - - ${root}/src/share/classes - - - - ${root}/test - - - - ${root}/make - - - - README - - - - &standard-context-menu-items-no-javadoc; - - - - - - - ${root}/src/share/classes - ${root}/build/classes - 1.5 - - - - diff --git a/langtools/make/netbeans/javap/README b/langtools/make/netbeans/javap/README deleted file mode 100644 index fb08ece3ee7..00000000000 --- a/langtools/make/netbeans/javap/README +++ /dev/null @@ -1,11 +0,0 @@ -"javap" project README. - -This project is for working on the disassembler tool (javap) -in the OpenJDK langtools component. - -The main class for the tool is sun.tools.javap.Main. - -NetBeans 5.0 or later is required and sufficient to use this -project, and others in the OpenJDK langtools component. -This is different from other projects in OpenJDK, which -require version 6.0 or later. diff --git a/langtools/make/netbeans/javap/build.xml b/langtools/make/netbeans/javap/build.xml deleted file mode 100644 index 818a933d5e4..00000000000 --- a/langtools/make/netbeans/javap/build.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/langtools/make/netbeans/javap/nbproject/project.xml b/langtools/make/netbeans/javap/nbproject/project.xml deleted file mode 100644 index 692e6726cf8..00000000000 --- a/langtools/make/netbeans/javap/nbproject/project.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - -]> - - org.netbeans.modules.ant.freeform - - - - javap - - ../../.. - - - - - ${root} - - - - java - ${root}/src/share/classes - - - - tests - ${root}/test - - - - build - ${root}/make - - - - &standard-ide-actions-no-javadoc; - - - folder - ${root}/build/classes - build - - - - - - ${root}/src/share/classes - - - - ${root}/test - - - - ${root}/make - - - - README - - - - &standard-context-menu-items-no-javadoc; - - - - - - - ${root}/src/share/classes - ${root}/build/classes - 1.5 - - - - diff --git a/langtools/make/netbeans/langtools/build.xml b/langtools/make/netbeans/langtools/build.xml new file mode 100644 index 00000000000..8f2b95f3031 --- /dev/null +++ b/langtools/make/netbeans/langtools/build.xml @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set property 'includes' + + + + + + + + + + + + + + Must set property 'run.classname' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see report for details. + + + + + + + + + + + + + Must set property 'debug.classname' + + + + + + + Must set property 'jtreg.tests' + + + + + + + + Must set property 'class' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/langtools/make/netbeans/javadoc/nbproject/project.xml b/langtools/make/netbeans/langtools/nbproject/project.xml similarity index 94% rename from langtools/make/netbeans/javadoc/nbproject/project.xml rename to langtools/make/netbeans/langtools/nbproject/project.xml index 61ebeb3b7af..e7509600556 100644 --- a/langtools/make/netbeans/javadoc/nbproject/project.xml +++ b/langtools/make/netbeans/langtools/nbproject/project.xml @@ -1,6 +1,6 @@ - + + ]> org.netbeans.modules.ant.freeform - javadoc + langtools ../../.. diff --git a/langtools/make/netbeans/common/standard-context-menu-items.ent b/langtools/make/netbeans/langtools/nbproject/standard-context-menu-items.ent similarity index 95% rename from langtools/make/netbeans/common/standard-context-menu-items.ent rename to langtools/make/netbeans/langtools/nbproject/standard-context-menu-items.ent index f6e1a96bb84..ab0568a009d 100644 --- a/langtools/make/netbeans/common/standard-context-menu-items.ent +++ b/langtools/make/netbeans/langtools/nbproject/standard-context-menu-items.ent @@ -1,6 +1,6 @@ + + + + diff --git a/langtools/make/netbeans/common/standard-ide-actions.ent b/langtools/make/netbeans/langtools/nbproject/standard-ide-actions.ent similarity index 92% rename from langtools/make/netbeans/common/standard-ide-actions.ent rename to langtools/make/netbeans/langtools/nbproject/standard-ide-actions.ent index 912daf729a8..3081fdfcdf0 100644 --- a/langtools/make/netbeans/common/standard-ide-actions.ent +++ b/langtools/make/netbeans/langtools/nbproject/standard-ide-actions.ent @@ -108,11 +108,11 @@ - debug-nb + debug - debug-single-nb + debug-single debug.classname ${root}/src/share/classes @@ -130,7 +130,7 @@ --> - debug-jtreg-nb + debug-jtreg jtreg.tests ${root}/test @@ -157,5 +157,17 @@ - -javadoc-nb + javadoc + + + + select-tool + + + + test-select-tool-1 + + + + test-select-tool-2 diff --git a/langtools/make/tools/SelectTool/SelectToolTask.java b/langtools/make/tools/SelectTool/SelectToolTask.java new file mode 100644 index 00000000000..0646c306e8a --- /dev/null +++ b/langtools/make/tools/SelectTool/SelectToolTask.java @@ -0,0 +1,284 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import javax.swing.SwingUtilities; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; + +/** + * Task to allow the user to control langtools tools built when using NetBeans. + * + * There are two primary modes. + * 1) Property mode. In this mode, property names are provided to get values + * that may be specified by the user, either directly in a GUI dialog, or + * read from a properties file. If the GUI dialog is invoked, values may + * optionally be set for future use. + * 2) Setup mode. In this mode, no property names are provided, and the GUI + * is invoked to allow the user to set or reset values for use in property mode. + */ +public class SelectToolTask extends Task { + /** + * Set the location of the private properties file used to keep the retain + * user preferences for this repository. + */ + public void setPropertyFile(File propertyFile) { + this.propertyFile = propertyFile; + } + + /** + * Set the name of the property which will be set to the name of the + * selected tool, if any. If no tool is selected, the property will + * remain unset. + */ + public void setToolProperty(String toolProperty) { + this.toolProperty = toolProperty; + } + + /** + * Set the name of the property which will be set to the execution args of the + * selected tool, if any. The args default to an empty string. + */ + public void setArgsProperty(String argsProperty) { + this.argsProperty = argsProperty; + } + + /** + * Specify whether or not to pop up a dialog if the user has not specified + * a default value for a property. + */ + public void setAskIfUnset(boolean askIfUnset) { + this.askIfUnset = askIfUnset; + } + + @Override + public void execute() { + Project p = getProject(); + + Properties props = readProperties(propertyFile); + toolName = props.getProperty("tool.name"); + if (toolName != null) { + toolArgs = props.getProperty(toolName + ".args", ""); + } + + if (toolProperty == null || + askIfUnset && (toolName == null + || (argsProperty != null && toolArgs == null))) { + showGUI(props); + } + + // finally, return required values, if any + if (toolProperty != null && !(toolName == null || toolName.equals(""))) { + p.setProperty(toolProperty, toolName); + + if (argsProperty != null && toolArgs != null) + p.setProperty(argsProperty, toolArgs); + } + } + + void showGUI(Properties fileProps) { + Properties guiProps = new Properties(fileProps); + JOptionPane p = createPane(guiProps); + p.createDialog("Select Tool").setVisible(true); + + toolName = (String) toolChoice.getSelectedItem(); + toolArgs = argsField.getText(); + + if (defaultCheck.isSelected()) { + if (toolName.equals("")) { + fileProps.remove("tool.name"); + } else { + fileProps.put("tool.name", toolName); + fileProps.put(toolName + ".args", toolArgs); + } + writeProperties(propertyFile, fileProps); + } + } + + JOptionPane createPane(final Properties props) { + JPanel body = new JPanel(new GridBagLayout()); + GridBagConstraints lc = new GridBagConstraints(); + lc.insets.right = 10; + lc.insets.bottom = 3; + GridBagConstraints fc = new GridBagConstraints(); + fc.anchor = GridBagConstraints.WEST; + fc.gridx = 1; + fc.gridwidth = GridBagConstraints.REMAINDER; + fc.insets.bottom = 3; + + JLabel toolLabel = new JLabel("Tool:"); + body.add(toolLabel, lc); + String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" }; + if (true || toolProperty == null) { + // include empty value in setup mode + List l = new ArrayList(Arrays.asList(toolChoices)); + l.add(0, ""); + toolChoices = l.toArray(new String[l.size()]); + } + toolChoice = new JComboBox(toolChoices); + if (toolName != null) + toolChoice.setSelectedItem(toolName); + toolChoice.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + String tn = (String) e.getItem(); + argsField.setText(getDefaultArgsForTool(props, tn)); + if (toolProperty != null) + okButton.setEnabled(!tn.equals("")); + } + }); + body.add(toolChoice, fc); + + argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40); + if (toolProperty == null || argsProperty != null) { + JLabel argsLabel = new JLabel("Args:"); + body.add(argsLabel, lc); + body.add(argsField, fc); + argsField.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent e) { + } + public void focusLost(FocusEvent e) { + String toolName = (String) toolChoice.getSelectedItem(); + if (toolName.length() > 0) + props.put(toolName + ".args", argsField.getText()); + } + }); + } + + defaultCheck = new JCheckBox("Set as default"); + if (toolProperty == null) + defaultCheck.setSelected(true); + else + body.add(defaultCheck, fc); + + final JOptionPane p = new JOptionPane(body); + okButton = new JButton("OK"); + okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals(""))); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p); + d.setVisible(false); + } + }); + p.setOptions(new Object[] { okButton }); + + return p; + } + + Properties readProperties(File file) { + Properties p = new Properties(); + if (file != null && file.exists()) { + Reader in = null; + try { + in = new BufferedReader(new FileReader(file)); + p.load(in); + in.close(); + } catch (IOException e) { + throw new BuildException("error reading property file", e); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + throw new BuildException("cannot close property file", e); + } + } + } + } + return p; + } + + void writeProperties(File file, Properties p) { + if (file != null) { + Writer out = null; + try { + File dir = file.getParentFile(); + if (dir != null && !dir.exists()) + dir.mkdirs(); + out = new BufferedWriter(new FileWriter(file)); + p.store(out, "langtools properties"); + out.close(); + } catch (IOException e) { + throw new BuildException("error writing property file", e); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + throw new BuildException("cannot close property file", e); + } + } + } + } + } + + String getDefaultArgsForTool(Properties props, String tn) { + return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", ""); + } + + // Ant task parameters + private boolean askIfUnset; + private String toolProperty; + private String argsProperty; + private File propertyFile; + + // GUI components + private JComboBox toolChoice; + private JTextField argsField; + private JCheckBox defaultCheck; + private JButton okButton; + + // Result values for the client + private String toolName; + private String toolArgs; +}