8024414: javac, should facilitate the use of the bootstrap compiler for debugging

Tue, 10 Sep 2013 16:47:40 +0100

author
mcimadamore
date
Tue, 10 Sep 2013 16:47:40 +0100
changeset 2021
d87f017ec217
parent 2020
bb7271e64ef6
child 2022
65c218b25b61

8024414: javac, should facilitate the use of the bootstrap compiler for debugging
Reviewed-by: jjg

make/netbeans/langtools/build.xml file | annotate | diff | comparison | revisions
make/tools/anttasks/SelectToolTask.java file | annotate | diff | comparison | revisions
     1.1 --- a/make/netbeans/langtools/build.xml	Tue Sep 10 13:47:51 2013 +0200
     1.2 +++ b/make/netbeans/langtools/build.xml	Tue Sep 10 16:47:40 2013 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  <?xml version="1.0" encoding="UTF-8"?>
     1.5  <!--
     1.6 - Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
     1.7 + Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
     1.8  
     1.9   Redistribution and use in source and binary forms, with or without
    1.10   modification, are permitted provided that the following conditions
    1.11 @@ -55,10 +55,18 @@
    1.12          description="Build one or all langtools tools"
    1.13          />
    1.14  
    1.15 +    <condition property="bootstrap" value="bootstrap-" else="">
    1.16 +        <isset property="langtools.tool.bootstrap"/>
    1.17 +    </condition>
    1.18 +
    1.19 +    <condition property="bcp" value="${build.bootstrap.dir}/classes" else="${build.classes.dir}">
    1.20 +        <isset property="langtools.tool.bootstrap"/>
    1.21 +    </condition>
    1.22 +
    1.23      <target name="-build-tool" if="langtools.tool.name">
    1.24 -        <echo level="info" message="Building ${langtools.tool.name}"/>
    1.25 +        <echo level="info" message="Building ${bootstrap}${langtools.tool.name}"/>
    1.26          <echo level="verbose" message="(Unset langtools.tool.name to build all tools)"/>
    1.27 -        <antcall target="build-${langtools.tool.name}"/>
    1.28 +        <antcall target="build-${bootstrap}${langtools.tool.name}"/>
    1.29      </target>
    1.30  
    1.31      <target name="-build-all" unless="langtools.tool.name">
    1.32 @@ -89,8 +97,9 @@
    1.33  
    1.34      <target name="run" depends="-check-target.java.home,build,-def-run,-get-tool-and-args"
    1.35              description="run tool">
    1.36 -        <echo level="info" message="Run ${langtools.tool.name} with args ${langtools.tool.args}"/>
    1.37 -        <run mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}"/>
    1.38 +        <echo level="info" message="${bcp}"/>
    1.39 +        <echo level="info" message="Run ${bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
    1.40 +        <run bcp="${bcp}" mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}"/>
    1.41      </target>
    1.42  
    1.43      <!-- Run a selected class. (action: run.single;  shift-F6) -->
    1.44 @@ -136,9 +145,9 @@
    1.45      <!-- Debug tool in NetBeans. -->
    1.46  
    1.47      <target name="debug" depends="-check-target.java.home,-def-run,-def-start-debugger,-get-tool-and-args,build" if="netbeans.home">
    1.48 -        <echo level="info" message="Debug ${langtools.tool.name} with args ${langtools.tool.args}"/>
    1.49 +        <echo level="info" message="Debug ${boostrap}${langtools.tool.name} with args ${langtools.tool.args}"/>
    1.50          <start-debugger/>
    1.51 -        <run mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
    1.52 +        <run bcp="${bcp}" mainclass="com.sun.tools.${langtools.tool.name}.Main" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/>
    1.53      </target>
    1.54  
    1.55      <!-- Debug a selected class . -->
    1.56 @@ -207,6 +216,7 @@
    1.57      <target name="-get-tool-if-set" depends="-def-select-tool">
    1.58          <select-tool
    1.59              toolproperty="langtools.tool.name"
    1.60 +            bootstrapproperty="langtools.tool.bootstrap"
    1.61              propertyfile="${langtools.properties}"
    1.62              askIfUnset="false"
    1.63              />
    1.64 @@ -216,6 +226,7 @@
    1.65          <select-tool
    1.66              toolproperty="langtools.tool.name"
    1.67              argsproperty="langtools.tool.args"
    1.68 +            bootstrapproperty="langtools.tool.bootstrap"
    1.69              propertyfile="${langtools.properties}"
    1.70              askIfUnset="true"
    1.71              />
    1.72 @@ -226,10 +237,12 @@
    1.73          <macrodef name="run">
    1.74              <attribute name="mainclass"/>
    1.75              <attribute name="args" default=""/>
    1.76 +            <attribute name="bcp" default="${build.classes.dir}"/>
    1.77              <attribute name="jpda.jvmargs" default=""/>
    1.78 +
    1.79              <sequential>
    1.80                  <java fork="true" jvm="${target.java}" classname="@{mainclass}">
    1.81 -                    <jvmarg line="-Xbootclasspath/p:${build.classes.dir}"/>
    1.82 +                    <jvmarg line="-Xbootclasspath/p:${bcp}"/>
    1.83                      <jvmarg line="@{jpda.jvmargs}"/>
    1.84                      <arg line="@{args}"/>
    1.85                  </java>
     2.1 --- a/make/tools/anttasks/SelectToolTask.java	Tue Sep 10 13:47:51 2013 +0200
     2.2 +++ b/make/tools/anttasks/SelectToolTask.java	Tue Sep 10 16:47:40 2013 +0100
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -43,6 +43,7 @@
    2.11  import java.io.Writer;
    2.12  import java.util.ArrayList;
    2.13  import java.util.Arrays;
    2.14 +import java.util.EnumSet;
    2.15  import java.util.List;
    2.16  import java.util.Properties;
    2.17  import javax.swing.JButton;
    2.18 @@ -71,6 +72,31 @@
    2.19   * is invoked to allow the user to set or reset values for use in property mode.
    2.20   */
    2.21  public class SelectToolTask extends Task {
    2.22 +
    2.23 +    enum ToolChoices {
    2.24 +        NONE(""),
    2.25 +        JAVAC("javac"),
    2.26 +        JAVADOC("javadoc"),
    2.27 +        JAVAH("javah"),
    2.28 +        JAVAP("javap");
    2.29 +
    2.30 +        String toolName;
    2.31 +        boolean bootstrap;
    2.32 +
    2.33 +        ToolChoices(String toolName) {
    2.34 +            this(toolName, false);
    2.35 +        }
    2.36 +
    2.37 +        ToolChoices(String toolName, boolean boostrap) {
    2.38 +            this.toolName = toolName;
    2.39 +        }
    2.40 +
    2.41 +        @Override
    2.42 +        public String toString() {
    2.43 +            return toolName;
    2.44 +        }
    2.45 +    }
    2.46 +
    2.47      /**
    2.48       * Set the location of the private properties file used to keep the retain
    2.49       * user preferences for this repository.
    2.50 @@ -97,6 +123,14 @@
    2.51      }
    2.52  
    2.53      /**
    2.54 +     * Set the name of the property which will be set to the execution args of the
    2.55 +     * selected tool, if any. The args default to an empty string.
    2.56 +     */
    2.57 +    public void setBootstrapProperty(String bootstrapProperty) {
    2.58 +        this.bootstrapProperty = bootstrapProperty;
    2.59 +    }
    2.60 +
    2.61 +    /**
    2.62       * Specify whether or not to pop up a dialog if the user has not specified
    2.63       * a default value for a property.
    2.64       */
    2.65 @@ -110,6 +144,7 @@
    2.66  
    2.67          Properties props = readProperties(propertyFile);
    2.68          toolName = props.getProperty("tool.name");
    2.69 +        toolBootstrap = props.getProperty("tool.bootstrap") != null;
    2.70          if (toolName != null) {
    2.71              toolArgs = props.getProperty(toolName + ".args", "");
    2.72          }
    2.73 @@ -123,6 +158,8 @@
    2.74          // finally, return required values, if any
    2.75          if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
    2.76              p.setProperty(toolProperty, toolName);
    2.77 +            if (toolBootstrap)
    2.78 +                p.setProperty(bootstrapProperty, "true");
    2.79  
    2.80              if (argsProperty != null && toolArgs != null)
    2.81                  p.setProperty(argsProperty, toolArgs);
    2.82 @@ -134,14 +171,20 @@
    2.83          JOptionPane p = createPane(guiProps);
    2.84          p.createDialog("Select Tool").setVisible(true);
    2.85  
    2.86 -        toolName = (String) toolChoice.getSelectedItem();
    2.87 +        toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName;
    2.88          toolArgs = argsField.getText();
    2.89 -
    2.90 +        toolBootstrap = bootstrapCheckbox.isSelected();
    2.91          if (defaultCheck.isSelected()) {
    2.92              if (toolName.equals("")) {
    2.93                  fileProps.remove("tool.name");
    2.94 +                fileProps.remove("tool.bootstrap");
    2.95              } else {
    2.96                  fileProps.put("tool.name", toolName);
    2.97 +                if (toolBootstrap) {
    2.98 +                    fileProps.put("tool.bootstrap", "true");
    2.99 +                } else {
   2.100 +                    fileProps.remove("tool.bootstrap");
   2.101 +                }
   2.102                  fileProps.put(toolName + ".args", toolArgs);
   2.103              }
   2.104              writeProperties(propertyFile, fileProps);
   2.105 @@ -154,32 +197,38 @@
   2.106          lc.insets.right = 10;
   2.107          lc.insets.bottom = 3;
   2.108          GridBagConstraints fc = new GridBagConstraints();
   2.109 -        fc.anchor = GridBagConstraints.WEST;
   2.110          fc.gridx = 1;
   2.111 -        fc.gridwidth = GridBagConstraints.REMAINDER;
   2.112 +        fc.gridwidth = GridBagConstraints.NONE;
   2.113          fc.insets.bottom = 3;
   2.114  
   2.115 +        JPanel toolPane = new JPanel(new GridBagLayout());
   2.116 +
   2.117          JLabel toolLabel = new JLabel("Tool:");
   2.118          body.add(toolLabel, lc);
   2.119 -        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
   2.120 -        if (true || toolProperty == null) {
   2.121 -            // include empty value in setup mode
   2.122 -            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
   2.123 -            l.add(0, "");
   2.124 -            toolChoices = l.toArray(new String[l.size()]);
   2.125 -        }
   2.126 -        toolChoice = new JComboBox(toolChoices);
   2.127 +        EnumSet<ToolChoices> toolChoices = toolProperty == null ?
   2.128 +                EnumSet.allOf(ToolChoices.class) : EnumSet.range(ToolChoices.JAVAC, ToolChoices.JAVAP);
   2.129 +        toolChoice = new JComboBox(toolChoices.toArray());
   2.130          if (toolName != null)
   2.131 -            toolChoice.setSelectedItem(toolName);
   2.132 +            toolChoice.setSelectedItem(ToolChoices.valueOf(toolName.toUpperCase()));
   2.133          toolChoice.addItemListener(new ItemListener() {
   2.134              public void itemStateChanged(ItemEvent e) {
   2.135 -                String tn = (String) e.getItem();
   2.136 +                String tn = ((ToolChoices)e.getItem()).toolName;
   2.137                  argsField.setText(getDefaultArgsForTool(props, tn));
   2.138                  if (toolProperty != null)
   2.139                      okButton.setEnabled(!tn.equals(""));
   2.140              }
   2.141          });
   2.142 -        body.add(toolChoice, fc);
   2.143 +        GridBagConstraints checkConstraint = new GridBagConstraints();
   2.144 +        fc.anchor = GridBagConstraints.EAST;
   2.145 +
   2.146 +        GridBagConstraints toolConstraint = new GridBagConstraints();
   2.147 +        fc.anchor = GridBagConstraints.WEST;
   2.148 +
   2.149 +        toolPane.add(toolChoice, toolConstraint);
   2.150 +        bootstrapCheckbox = new JCheckBox("bootstrap", toolBootstrap);
   2.151 +        toolPane.add(bootstrapCheckbox, checkConstraint);
   2.152 +
   2.153 +        body.add(toolPane, fc);
   2.154  
   2.155          argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
   2.156          if (toolProperty == null || argsProperty != null) {
   2.157 @@ -190,7 +239,7 @@
   2.158                  public void focusGained(FocusEvent e) {
   2.159                  }
   2.160                  public void focusLost(FocusEvent e) {
   2.161 -                    String toolName = (String) toolChoice.getSelectedItem();
   2.162 +                    String toolName = ((ToolChoices)toolChoice.getSelectedItem()).toolName;
   2.163                      if (toolName.length() > 0)
   2.164                          props.put(toolName + ".args", argsField.getText());
   2.165                  }
   2.166 @@ -271,16 +320,19 @@
   2.167      // Ant task parameters
   2.168      private boolean askIfUnset;
   2.169      private String toolProperty;
   2.170 +    private String bootstrapProperty;
   2.171      private String argsProperty;
   2.172      private File propertyFile;
   2.173  
   2.174      // GUI components
   2.175      private JComboBox toolChoice;
   2.176 +    private JCheckBox bootstrapCheckbox;
   2.177      private JTextField argsField;
   2.178      private JCheckBox defaultCheck;
   2.179      private JButton okButton;
   2.180  
   2.181      // Result values for the client
   2.182      private String toolName;
   2.183 +    private boolean toolBootstrap;
   2.184      private String toolArgs;
   2.185  }

mercurial