You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@apache.org on 2005/06/13 01:15:57 UTC

cvs commit: ant/src/main/org/apache/tools/ant Diagnostics.java

stevel      2005/06/12 16:15:57

  Modified:    src/main/org/apache/tools/ant/taskdefs defaults.properties
               src/main/org/apache/tools/ant Diagnostics.java
  Added:       src/main/org/apache/tools/ant/taskdefs DiagnosticsTask.java
  Log:
  Little something to make IDE debugging easier; <diagnostics/> prints the diagnostics out as per -diagnostics.
  1. Why does Netbeans4.1 keep javax.xml.parsers.SAXParserFactory a secret? SecurityException handling to Diagnostics to compensate.
  2. could add output file support, maybe?
  3. could add task="junit" for detailed task diags instead...
  
  Revision  Changes    Path
  1.171     +1 -0      ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.170
  retrieving revision 1.171
  diff -u -r1.170 -r1.171
  --- defaults.properties	24 May 2005 20:49:55 -0000	1.170
  +++ defaults.properties	12 Jun 2005 23:15:57 -0000	1.171
  @@ -83,6 +83,7 @@
   length=org.apache.tools.ant.taskdefs.Length
   clone=org.apache.tools.ant.taskdefs.Clone
   copypath=org.apache.tools.ant.taskdefs.CopyPath
  +diagnostics=org.apache.tools.ant.taskdefs.DiagnosticsTask
   
   # optional tasks
   image=org.apache.tools.ant.taskdefs.optional.image.Image
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/DiagnosticsTask.java
  
  Index: DiagnosticsTask.java
  ===================================================================
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Diagnostics;
  
  /*
   * Copyright  2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  /**
   * This is a task that hands off work to the Diagnostics module.
   * It lets you run diagnostics in an IDE.
   */
  public class DiagnosticsTask extends Task {
  
      private static final String[] args=new String[0];
      
      public void execute() throws BuildException {
          Diagnostics.main(args);
      }
  
  
  }
  
  
  
  1.30      +15 -2     ant/src/main/org/apache/tools/ant/Diagnostics.java
  
  Index: Diagnostics.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Diagnostics.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- Diagnostics.java	6 Jun 2005 19:45:32 -0000	1.29
  +++ Diagnostics.java	12 Jun 2005 23:15:57 -0000	1.30
  @@ -259,10 +259,23 @@
        * @param out the stream to print the properties to.
        */
       private static void doReportSystemProperties(PrintStream out) {
  -        for (Enumeration keys = System.getProperties().propertyNames();
  +        Properties sysprops = null;
  +        try {
  +            sysprops = System.getProperties();
  +        } catch (SecurityException  e) {
  +            out.println("Access to System.getProperties() blocked " +
  +                    "by a security manager");
  +        }
  +        for (Enumeration keys = sysprops.propertyNames();
               keys.hasMoreElements();) {
               String key = (String) keys.nextElement();
  -            out.println(key + " : " + System.getProperty(key));
  +            String value;
  +            try {
  +                value = System.getProperty(key);
  +            } catch (SecurityException e) {
  +                value = "Access to this property blocked by a security manager";
  +            }
  +            out.println(key + " : " + value);
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: cvs commit: ant/src/main/org/apache/tools/ant Diagnostics.java

Posted by Steve Loughran <st...@apache.org>.
stevel@apache.org wrote:
> stevel      2005/06/12 16:15:57
> 
>   Modified:    src/main/org/apache/tools/ant/taskdefs defaults.properties
>                src/main/org/apache/tools/ant Diagnostics.java
>   Added:       src/main/org/apache/tools/ant/taskdefs DiagnosticsTask.java
>   Log:
>   Little something to make IDE debugging easier; <diagnostics/> prints the diagnostics out as per -diagnostics.
>   1. Why does Netbeans4.1 keep javax.xml.parsers.SAXParserFactory a secret? SecurityException handling to Diagnostics to compensate.
>   2. could add output file support, maybe?
>   3. could add task="junit" for detailed task diags instead...
>   


For the curious, this now lets you do targets like


<diagnostics/>

and get the ant -diagnostics output printed to the log. Its an 
interesting way to find out what is going on inside an IDE, such as what 
tasks are there, the classpath, etc.

I had to put some security handling in there as netbeans4.1 doesnt let 
me find out the value of javax.xml.parsers.SAXParserFactory, which is, 
well, surprising. Jesse -is there a particular reason that this is a 
secret?

One thing I might like to add is the ability to save to a file (on both 
command line and task)

ant -diagnostics -file something.txt

<diagnostics destFile="something.txt" />

And the component helper diagnostics for individual tasks


ant -diagnostics -task junit


<diagnostics task="junit" />

In this mode, only the task diags are run, and the command fails if the 
task wont instantiate. So you could do

<diagnostics task="junit" failuremessage="fetch junit from 
http://junit.org/" />

which I think would be kind of cool for self-diagnosing build files.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org