buildframework/helium/sf/java/antlint/src/com/nokia/helium/antlint/ant/types/CheckAntCall.java
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    27 import org.dom4j.io.SAXReader;
    27 import org.dom4j.io.SAXReader;
    28 
    28 
    29 import com.nokia.helium.antlint.ant.AntlintException;
    29 import com.nokia.helium.antlint.ant.AntlintException;
    30 
    30 
    31 /**
    31 /**
    32  * <code>CheckAntCall</code> is used to check whether antcall is used with no
    32  * <code>CheckAntCall</code> is used to check whether antcall is used with no param elements and
    33  * param elements and calls the target with no dependencies
    33  * calls the target with no dependencies
    34  * 
    34  * 
    35  * <pre>
    35  * <pre>
    36  * Usage:
    36  * Usage:
    37  * 
    37  * 
    38  *  &lt;antlint&gt;
    38  *  &lt;antlint&gt;
    61     }
    61     }
    62 
    62 
    63     /**
    63     /**
    64      * Check against the given node.
    64      * Check against the given node.
    65      * 
    65      * 
    66      * @param node
    66      * @param node is the node to check.
    67      *            is the node to check.
       
    68      */
    67      */
    69     @SuppressWarnings("unchecked")
    68     @SuppressWarnings("unchecked")
    70     private void checkAntCalls(Element node) {
    69     private void checkAntCalls(Element node) {
    71         if (node.elements("antcall") != null) {
    70         if (node.elements("antcall") != null) {
    72             List<Element> antcallList = node.elements("antcall");
    71             List<Element> antcallList = node.elements("antcall");
    73             for (Element antcallElement : antcallList) {
    72             for (Element antcallElement : antcallList) {
    74                 String antcallName = antcallElement.attributeValue("target");
    73                 String antcallName = antcallElement.attributeValue("target");
    75                 if (((node.elements("param") == null) || (node
    74                 if (((node.elements("param") == null) || (node.elements("param") != null && node.elements("param").isEmpty()))
    76                         .elements("param") != null && node.elements("param")
    75                     && !checkTargetDependency(antcallName)) {
    77                         .isEmpty()))
    76                     this.getReporter().report(this.getSeverity(), "<antcall> is used with no param elements and calls the target "
    78                         && !checkTargetDependency(antcallName)) {
    77                         + antcallName
    79                     this
    78                         + " that has no dependencies! (<runtarget> could be used instead.)", this.getAntFile(), 0);
    80                             .getReporter()
       
    81                             .report(
       
    82                                     this.getSeverity(),
       
    83                                     "<antcall> is used with no param elements and calls the target "
       
    84                                             + antcallName
       
    85                                             + " that has no dependencies! (<runtarget> could be used instead.)",
       
    86                                     this.getAntFile(), 0);
       
    87                 }
    79                 }
    88             }
    80             }
    89         }
    81         }
    90     }
    82     }
    91 
    83 
   102         List<Element> targetNodes = new ArrayList<Element>();
    94         List<Element> targetNodes = new ArrayList<Element>();
   103 
    95 
   104         try {
    96         try {
   105             doc = saxReader.read(antFilename);
    97             doc = saxReader.read(antFilename);
   106             elementTreeWalk(doc.getRootElement(), "target", targetNodes);
    98             elementTreeWalk(doc.getRootElement(), "target", targetNodes);
   107         } catch (DocumentException e) {
    99         }
       
   100         catch (DocumentException e) {
   108             throw new AntlintException("Invalid XML file " + e.getMessage());
   101             throw new AntlintException("Invalid XML file " + e.getMessage());
   109         }
   102         }
   110 
   103 
   111         for (Element targetNode : targetNodes) {
   104         for (Element targetNode : targetNodes) {
   112             run(targetNode);
   105             run(targetNode);
   123     }
   116     }
   124 
   117 
   125     /**
   118     /**
   126      * Check the availability dependent targets of the given target.
   119      * Check the availability dependent targets of the given target.
   127      * 
   120      * 
   128      * @param targetName
   121      * @param targetName is the target for which dependent targets to be loked up.
   129      *            is the target for which dependent targets to be loked up.
       
   130      * @return true, if the dependant targets are available; otherwise false
   122      * @return true, if the dependant targets are available; otherwise false
   131      */
   123      */
   132     private boolean checkTargetDependency(String targetName) {
   124     private boolean checkTargetDependency(String targetName) {
   133         boolean dependencyCheck = false;
   125         boolean dependencyCheck = false;
   134         Target targetDependency = (Target) getProject().getTargets().get(
   126         Target targetDependency = (Target) getProject().getTargets().get(targetName);
   135                 targetName);
       
   136         dependencyCheck = targetDependency != null
   127         dependencyCheck = targetDependency != null
   137                 && targetDependency.getDependencies().hasMoreElements();
   128             && targetDependency.getDependencies().hasMoreElements();
   138         return dependencyCheck;
   129         return dependencyCheck;
   139     }
   130     }
   140 
   131 
   141     /*
   132     /*
   142      * (non-Javadoc)
   133      * (non-Javadoc)