# HG changeset patch # User jjg # Date 1232738590 28800 # Node ID 65838583499800beb0e63b448cd6575d2d0f67ea # Parent 9820a8bee1e5246b8c202f5381c18bc60c98b632 6795365: NetBeans projects in langtools repository are not NB6.5-friendly Reviewed-by: mcimadamore diff -r 9820a8bee1e5 -r 658385834998 langtools/make/README --- a/langtools/make/README Thu Jan 22 15:45:44 2009 -0800 +++ b/langtools/make/README Fri Jan 23 11:23:10 2009 -0800 @@ -15,7 +15,7 @@ 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 -r 9820a8bee1e5 -r 658385834998 langtools/make/build.xml --- a/langtools/make/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ b/langtools/make/build.xml Fri Jan 23 11:23:10 2009 -0800 @@ -660,7 +660,7 @@ - + diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/README --- a/langtools/make/netbeans/README Thu Jan 22 15:45:44 2009 -0800 +++ b/langtools/make/netbeans/README Fri Jan 23 11:23:10 2009 -0800 @@ -1,28 +1,39 @@ -Working on the "langtools" workspace using NetBeans. +Using NetBeans to work on the langtools repository. + +Netbeans 6.0 or later is recommended. -This directory (make/netbeans) contains NetBeans projects that -allow you to work on the various tools using the NetBeans IDE. +The "langtools" project in this directory allows you to +edit, run, test and debug the tools in the OpenJDK langtools +repository. -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 repository contains a number of tools: + apt, javac, javadoc and its doclets, javah and javap. + +Build Properties. -The following projects are provided: +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. -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. +- 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". -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. +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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/apt/README --- a/langtools/make/netbeans/apt/README Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/apt/build.xml --- a/langtools/make/netbeans/apt/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/apt/nbproject/project.xml --- a/langtools/make/netbeans/apt/nbproject/project.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/common/shared.xml --- a/langtools/make/netbeans/common/shared.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/common/standard-context-menu-items-no-javadoc.ent --- a/langtools/make/netbeans/common/standard-context-menu-items-no-javadoc.ent Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/common/standard-context-menu-items.ent --- a/langtools/make/netbeans/common/standard-context-menu-items.ent Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/common/standard-ide-actions-no-javadoc.ent --- a/langtools/make/netbeans/common/standard-ide-actions-no-javadoc.ent Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/common/standard-ide-actions.ent --- a/langtools/make/netbeans/common/standard-ide-actions.ent Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/compiler/README --- a/langtools/make/netbeans/compiler/README Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/compiler/build.xml --- a/langtools/make/netbeans/compiler/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/compiler/nbproject/project.xml --- a/langtools/make/netbeans/compiler/nbproject/project.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/doclets/README --- a/langtools/make/netbeans/doclets/README Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/doclets/build.xml --- a/langtools/make/netbeans/doclets/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/doclets/nbproject/project.xml --- a/langtools/make/netbeans/doclets/nbproject/project.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javadoc/README --- a/langtools/make/netbeans/javadoc/README Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javadoc/build.xml --- a/langtools/make/netbeans/javadoc/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javadoc/nbproject/project.xml --- a/langtools/make/netbeans/javadoc/nbproject/project.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ - - - - - -]> - - org.netbeans.modules.ant.freeform - - - - javadoc - - ../../.. - - - - - ${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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javah/README --- a/langtools/make/netbeans/javah/README Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javah/build.xml --- a/langtools/make/netbeans/javah/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javah/nbproject/project.xml --- a/langtools/make/netbeans/javah/nbproject/project.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javap/README --- a/langtools/make/netbeans/javap/README Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javap/build.xml --- a/langtools/make/netbeans/javap/build.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/javap/nbproject/project.xml --- a/langtools/make/netbeans/javap/nbproject/project.xml Thu Jan 22 15:45:44 2009 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/langtools/build.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/make/netbeans/langtools/build.xml Fri Jan 23 11:23:10 2009 -0800 @@ -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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/langtools/nbproject/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/make/netbeans/langtools/nbproject/project.xml Fri Jan 23 11:23:10 2009 -0800 @@ -0,0 +1,108 @@ + + + + + +]> + + org.netbeans.modules.ant.freeform + + + + langtools + + ../../.. + + + + + ${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 -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/langtools/nbproject/standard-context-menu-items.ent --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/make/netbeans/langtools/nbproject/standard-context-menu-items.ent Fri Jan 23 11:23:10 2009 -0800 @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + diff -r 9820a8bee1e5 -r 658385834998 langtools/make/netbeans/langtools/nbproject/standard-ide-actions.ent --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/make/netbeans/langtools/nbproject/standard-ide-actions.ent Fri Jan 23 11:23:10 2009 -0800 @@ -0,0 +1,173 @@ + + + + + + + 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 + + + + debug-single + + debug.classname + ${root}/src/share/classes + \.java$ + java-name + + + + + + + + + + debug-jtreg + + jtreg.tests + ${root}/test + \.(java|sh)$ + relative-path + + + + + + + + debug-fix + ${root}/src/share/classes + + class + ${root}/src/share/classes + \.java$ + relative-path-noext + + + + + + + + javadoc + + + + select-tool + + + + test-select-tool-1 + + + + test-select-tool-2 + diff -r 9820a8bee1e5 -r 658385834998 langtools/make/tools/SelectTool/SelectToolTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/make/tools/SelectTool/SelectToolTask.java Fri Jan 23 11:23:10 2009 -0800 @@ -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; +}