buildframework/helium/sf/java/sysdef/src/com/nokia/helium/sysdef/ant/taskdefs/FilterTask.java
changeset 628 7c4a911dc066
parent 588 c7c26511138f
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    17 package com.nokia.helium.sysdef.ant.taskdefs;
    17 package com.nokia.helium.sysdef.ant.taskdefs;
    18 
    18 
    19 import java.io.File;
    19 import java.io.File;
    20 import java.io.IOException;
    20 import java.io.IOException;
    21 import java.util.ArrayList;
    21 import java.util.ArrayList;
    22 import java.util.Hashtable;
       
    23 import java.util.List;
    22 import java.util.List;
    24 import java.util.Map;
       
    25 
    23 
    26 import org.apache.tools.ant.BuildException;
    24 import org.apache.tools.ant.BuildException;
    27 import org.apache.tools.ant.util.FileUtils;
    25 import org.apache.tools.ant.util.FileUtils;
    28 
    26 
    29 import com.nokia.helium.sysdef.ant.types.Filter;
    27 import com.nokia.helium.sysdef.ant.types.Filter;
    46  * </pre>
    44  * </pre>
    47  *
    45  *
    48  * For more information about system definition file v3.0 please check 
    46  * For more information about system definition file v3.0 please check 
    49  * <a href="http://developer.symbian.org/wiki/index.php/System_Definition">http://developer.symbian.org/wiki/index.php/System_Definition</a>.
    47  * <a href="http://developer.symbian.org/wiki/index.php/System_Definition">http://developer.symbian.org/wiki/index.php/System_Definition</a>.
    50  *
    48  *
       
    49  * <br>
       
    50  * This task relies on externals tools. Their location can be configured the following ways:
       
    51  *  <li>by configuring the sysdef.tools.home property, fails if the location is incorrect.
       
    52  *  <li>The parent folder of the joinsysdef tool from the PATH, fallback on SDK location.
       
    53  *  <li>Default SDK location.
       
    54  *
    51  * @ant.task name="filterSysdef" category="Sysdef"
    55  * @ant.task name="filterSysdef" category="Sysdef"
    52  */
    56  */
    53 public class FilterTask extends AbstractSydefTask {
    57 public class FilterTask extends AbstractSydefTask {
    54     private static final String XSLT = "sf/os/buildtools/bldsystemtools/sysdeftools/filtering.xsl";
    58     private static final String XSLT = "filtering.xsl";
    55     private List<FilterSet> filterSets = new ArrayList<FilterSet>();
    59     private List<FilterSet> filterSets = new ArrayList<FilterSet>();
    56     
    60     
    57     /**
       
    58      * Running the filtering operation on src file and put the result in dest file.
       
    59      * @param src the source file
       
    60      * @param dest the destination file
       
    61      * @param filter the filter to use
       
    62      * @param filterType the filter type to use (e.g has, only, with)
       
    63      */
       
    64     protected void filter(File src, File dest, String filter, String filterType) {
       
    65         Map<String, String> params = new Hashtable<String, String>();
       
    66         params.put("filter-type", filterType);
       
    67         params.put("filter", filter);
       
    68         transform(params);
       
    69     }
       
    70 
       
    71     /**
    61     /**
    72      * Create a FilterSet object to store filters.
    62      * Create a FilterSet object to store filters.
    73      * @return a new FilterSet object
    63      * @return a new FilterSet object
    74      */
    64      */
    75     public FilterSet createFilterSet() {
    65     public FilterSet createFilterSet() {
    94             throw new BuildException("You must define at least one nested filterset element.");
    84             throw new BuildException("You must define at least one nested filterset element.");
    95         }
    85         }
    96         log("Filtering " + this.getSrcFile());
    86         log("Filtering " + this.getSrcFile());
    97         for (FilterSet filterSet : filterSets) {
    87         for (FilterSet filterSet : filterSets) {
    98             if (filterSet.isReference()) {
    88             if (filterSet.isReference()) {
    99                 filterSet = (FilterSet)filterSet.getRefid().getReferencedObject();
    89                 try {
       
    90                     filterSet = (FilterSet)filterSet.getRefid().getReferencedObject();
       
    91                 } catch (ClassCastException ex) {
       
    92                     throw new BuildException("Object referenced by '" + filterSet.getRefid().getRefId() + "' is not a sysdefFilterSet.", ex);
       
    93                 }
   100             }
    94             }
   101             List<File> toDelete = new ArrayList<File>();
    95             List<File> toDelete = new ArrayList<File>();
   102             try {
    96             try {
   103                 File src = this.getSrcFile();
    97                 File src = this.getSrcFile();
   104                 File dst = null;
    98                 File dst = null;
   105                 for (Filter filter : filterSet.getFilters()) {
    99                 for (Filter filter : filterSet.getFilters()) {
   106                     if (filter.getFilter() == null) {
   100                     
   107                         throw new BuildException("'filter' attribute is not defined.");
   101                     // validating parameter first.
   108                     }
   102                     filter.validate();
       
   103                     
       
   104                     // Then filter the file
   109                     dst = File.createTempFile("sysdef", ".xml", this.getEpocroot());
   105                     dst = File.createTempFile("sysdef", ".xml", this.getEpocroot());
   110                     toDelete.add(dst);
   106                     toDelete.add(dst);
   111                     filter(src, dst, filter.getFilter(), filter.getType());
   107                     filter.filter(this, src, dst);
       
   108                     
   112                     // Dest is the input for next loop.
   109                     // Dest is the input for next loop.
   113                     src = dst;
   110                     src = dst;
   114                 }
   111                 }
   115                 if (dst != null) {
   112                 if (dst != null) {
   116                     log("Creating " + this.getDestFile());
   113                     log("Creating " + this.getDestFile());
   133 
   130 
   134     /**
   131     /**
   135      * {@inheritDoc}
   132      * {@inheritDoc}
   136      */
   133      */
   137     @Override
   134     @Override
   138     File getXsl() {
   135     protected File getXsl() {
   139         return new File(this.getEpocroot(), XSLT);
   136         return new File(SysdefUtils.getSysdefHome(getProject(), this.getEpocroot()), XSLT);
   140     }
   137     }
   141 }
   138 }