8024414: javac, should facilitate the use of the bootstrap compiler for debugging
authormcimadamore
Tue, 10 Sep 2013 16:47:40 +0100
changeset 19935 8f2c828192c3
parent 19934 1d8232b1aa18
child 19936 41f7c3013d9b
8024414: javac, should facilitate the use of the bootstrap compiler for debugging Reviewed-by: jjg
langtools/make/netbeans/langtools/build.xml
langtools/make/tools/anttasks/SelectToolTask.java
--- a/langtools/make/netbeans/langtools/build.xml	Tue Sep 10 13:47:51 2013 +0200
+++ b/langtools/make/netbeans/langtools/build.xml	Tue Sep 10 16:47:40 2013 +0100
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
- Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
 
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
@@ -55,10 +55,18 @@
         description="Build one or all langtools tools"
         />
 
+    <condition property="bootstrap" value="bootstrap-" else="">
+        <isset property="langtools.tool.bootstrap"/>
+    </condition>
+
+    <condition property="bcp" value="${build.bootstrap.dir}/classes" else="${build.classes.dir}">
+        <isset property="langtools.tool.bootstrap"/>
+    </condition>
+
     <target name="-build-tool" if="langtools.tool.name">
-        <echo level="info" message="Building ${langtools.tool.name}"/>
+        <echo level="info" message="Building ${bootstrap}${langtools.tool.name}"/>
         <echo level="verbose" message="(Unset langtools.tool.name to build all tools)"/>
-        <antcall target="build-${langtools.tool.name}"/>
+        <antcall target="build-${bootstrap}${langtools.tool.name}"/>
     </target>
 
     <target name="-build-all" unless="langtools.tool.name">
@@ -89,8 +97,9 @@
 
     <target name="run" depends="-check-target.java.home,build,-def-run,-get-tool-and-args"
             description="run tool">
-        <echo level="info" message="Run ${langtools.tool.name} with args ${langtools.tool.args}"/>
-        <run mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}"/>
+        <echo level="info" message="${bcp}"/>
+        <echo level="info" message="Run ${bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
+        <run bcp="${bcp}" mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}"/>
     </target>
 
     <!-- Run a selected class. (action: run.single;  shift-F6) -->
@@ -136,9 +145,9 @@
     <!-- Debug tool in NetBeans. -->
 
     <target name="debug" depends="-check-target.java.home,-def-run,-def-start-debugger,-get-tool-and-args,build" if="netbeans.home">
-        <echo level="info" message="Debug ${langtools.tool.name} with args ${langtools.tool.args}"/>
+        <echo level="info" message="Debug ${boostrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
         <start-debugger/>
-        <run mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
+        <run bcp="${bcp}" mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
     </target>
 
     <!-- Debug a selected class . -->
@@ -207,6 +216,7 @@
     <target name="-get-tool-if-set" depends="-def-select-tool">
         <select-tool
             toolproperty="langtools.tool.name"
+            bootstrapproperty="langtools.tool.bootstrap"
             propertyfile="${langtools.properties}"
             askIfUnset="false"
             />
@@ -216,6 +226,7 @@
         <select-tool
             toolproperty="langtools.tool.name"
             argsproperty="langtools.tool.args"
+            bootstrapproperty="langtools.tool.bootstrap"
             propertyfile="${langtools.properties}"
             askIfUnset="true"
             />
@@ -226,10 +237,12 @@
         <macrodef name="run">
             <attribute name="mainclass"/>
             <attribute name="args" default=""/>
+            <attribute name="bcp" default="${build.classes.dir}"/>
             <attribute name="jpda.jvmargs" default=""/>
+
             <sequential>
                 <java fork="true" jvm="${target.java}" classname="@{mainclass}">
-                    <jvmarg line="-Xbootclasspath/p:${build.classes.dir}"/>
+                    <jvmarg line="-Xbootclasspath/p:${bcp}"/>
                     <jvmarg line="@{jpda.jvmargs}"/>
                     <arg line="@{args}"/>
                 </java>
--- a/langtools/make/tools/anttasks/SelectToolTask.java	Tue Sep 10 13:47:51 2013 +0200
+++ b/langtools/make/tools/anttasks/SelectToolTask.java	Tue Sep 10 16:47:40 2013 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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
@@ -43,6 +43,7 @@
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Properties;
 import javax.swing.JButton;
@@ -71,6 +72,31 @@
  * is invoked to allow the user to set or reset values for use in property mode.
  */
 public class SelectToolTask extends Task {
+
+    enum ToolChoices {
+        NONE(""),
+        JAVAC("javac"),
+        JAVADOC("javadoc"),
+        JAVAH("javah"),
+        JAVAP("javap");
+
+        String toolName;
+        boolean bootstrap;
+
+        ToolChoices(String toolName) {
+            this(toolName, false);
+        }
+
+        ToolChoices(String toolName, boolean boostrap) {
+            this.toolName = toolName;
+        }
+
+        @Override
+        public String toString() {
+            return toolName;
+        }
+    }
+
     /**
      * Set the location of the private properties file used to keep the retain
      * user preferences for this repository.
@@ -97,6 +123,14 @@
     }
 
     /**
+     * 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 setBootstrapProperty(String bootstrapProperty) {
+        this.bootstrapProperty = bootstrapProperty;
+    }
+
+    /**
      * Specify whether or not to pop up a dialog if the user has not specified
      * a default value for a property.
      */
@@ -110,6 +144,7 @@
 
         Properties props = readProperties(propertyFile);
         toolName = props.getProperty("tool.name");
+        toolBootstrap = props.getProperty("tool.bootstrap") != null;
         if (toolName != null) {
             toolArgs = props.getProperty(toolName + ".args", "");
         }
@@ -123,6 +158,8 @@
         // finally, return required values, if any
         if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
             p.setProperty(toolProperty, toolName);
+            if (toolBootstrap)
+                p.setProperty(bootstrapProperty, "true");
 
             if (argsProperty != null && toolArgs != null)
                 p.setProperty(argsProperty, toolArgs);
@@ -134,14 +171,20 @@
         JOptionPane p = createPane(guiProps);
         p.createDialog("Select Tool").setVisible(true);
 
-        toolName = (String) toolChoice.getSelectedItem();
+        toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName;
         toolArgs = argsField.getText();
-
+        toolBootstrap = bootstrapCheckbox.isSelected();
         if (defaultCheck.isSelected()) {
             if (toolName.equals("")) {
                 fileProps.remove("tool.name");
+                fileProps.remove("tool.bootstrap");
             } else {
                 fileProps.put("tool.name", toolName);
+                if (toolBootstrap) {
+                    fileProps.put("tool.bootstrap", "true");
+                } else {
+                    fileProps.remove("tool.bootstrap");
+                }
                 fileProps.put(toolName + ".args", toolArgs);
             }
             writeProperties(propertyFile, fileProps);
@@ -154,32 +197,38 @@
         lc.insets.right = 10;
         lc.insets.bottom = 3;
         GridBagConstraints fc = new GridBagConstraints();
-        fc.anchor = GridBagConstraints.WEST;
         fc.gridx = 1;
-        fc.gridwidth = GridBagConstraints.REMAINDER;
+        fc.gridwidth = GridBagConstraints.NONE;
         fc.insets.bottom = 3;
 
+        JPanel toolPane = new JPanel(new GridBagLayout());
+
         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<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
-            l.add(0, "");
-            toolChoices = l.toArray(new String[l.size()]);
-        }
-        toolChoice = new JComboBox(toolChoices);
+        EnumSet<ToolChoices> toolChoices = toolProperty == null ?
+                EnumSet.allOf(ToolChoices.class) : EnumSet.range(ToolChoices.JAVAC, ToolChoices.JAVAP);
+        toolChoice = new JComboBox(toolChoices.toArray());
         if (toolName != null)
-            toolChoice.setSelectedItem(toolName);
+            toolChoice.setSelectedItem(ToolChoices.valueOf(toolName.toUpperCase()));
         toolChoice.addItemListener(new ItemListener() {
             public void itemStateChanged(ItemEvent e) {
-                String tn = (String) e.getItem();
+                String tn = ((ToolChoices)e.getItem()).toolName;
                 argsField.setText(getDefaultArgsForTool(props, tn));
                 if (toolProperty != null)
                     okButton.setEnabled(!tn.equals(""));
             }
         });
-        body.add(toolChoice, fc);
+        GridBagConstraints checkConstraint = new GridBagConstraints();
+        fc.anchor = GridBagConstraints.EAST;
+
+        GridBagConstraints toolConstraint = new GridBagConstraints();
+        fc.anchor = GridBagConstraints.WEST;
+
+        toolPane.add(toolChoice, toolConstraint);
+        bootstrapCheckbox = new JCheckBox("bootstrap", toolBootstrap);
+        toolPane.add(bootstrapCheckbox, checkConstraint);
+
+        body.add(toolPane, fc);
 
         argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
         if (toolProperty == null || argsProperty != null) {
@@ -190,7 +239,7 @@
                 public void focusGained(FocusEvent e) {
                 }
                 public void focusLost(FocusEvent e) {
-                    String toolName = (String) toolChoice.getSelectedItem();
+                    String toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName;
                     if (toolName.length() > 0)
                         props.put(toolName + ".args", argsField.getText());
                 }
@@ -271,16 +320,19 @@
     // Ant task parameters
     private boolean askIfUnset;
     private String toolProperty;
+    private String bootstrapProperty;
     private String argsProperty;
     private File propertyFile;
 
     // GUI components
     private JComboBox toolChoice;
+    private JCheckBox bootstrapCheckbox;
     private JTextField argsField;
     private JCheckBox defaultCheck;
     private JButton okButton;
 
     // Result values for the client
     private String toolName;
+    private boolean toolBootstrap;
     private String toolArgs;
 }