buildframework/helium/sf/java/sysdef/src/com/nokia/helium/sysdef/ant/types/SysdefConfig.java
changeset 628 7c4a911dc066
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 package com.nokia.helium.sysdef.ant.types;
       
    18 
       
    19 import java.io.File;
       
    20 import java.util.ArrayList;
       
    21 import java.util.List;
       
    22 
       
    23 import org.apache.tools.ant.BuildException;
       
    24 import org.apache.tools.ant.ProjectComponent;
       
    25 import org.apache.tools.ant.taskdefs.ExecTask;
       
    26 
       
    27 import com.nokia.helium.core.FileUtils;
       
    28 import com.nokia.helium.sysdef.ant.taskdefs.FilterTask;
       
    29 import com.nokia.helium.sysdef.ant.taskdefs.SysdefUtils;
       
    30 
       
    31 /**
       
    32  * This type configure the Feature based filtering, by accepting 
       
    33  * a HRH file parameter and a set of include path as input. 
       
    34  *
       
    35  */
       
    36 public class SysdefConfig extends ProjectComponent implements Filter {
       
    37     private File file;
       
    38     private String includes;
       
    39   
       
    40     /**
       
    41      * The configuration file. (e.g bldvariant.hrh)
       
    42      * @param file
       
    43      * @ant.required
       
    44      */
       
    45     public void setFile(File file) {
       
    46         this.file = file;
       
    47     }
       
    48         
       
    49     /**
       
    50      * Set a list of include path separated by current os separator character (; or :)
       
    51      * @param includes
       
    52      * @ant.not-required
       
    53      */
       
    54     public void setIncludes(String includes) {
       
    55         this.includes = includes;
       
    56     }
       
    57     
       
    58     /**
       
    59      * Get the list of include path as a list of File objet.
       
    60      * Include will be considered as relative to basedir if they
       
    61      * are not absolute.
       
    62      * @return a list of directories.
       
    63      */
       
    64     protected List<File> getIncludes() {
       
    65         List<File> includeFiles = new ArrayList<File>();
       
    66         if (includes != null) {
       
    67             for (String include : includes.split(File.pathSeparator)) {
       
    68                 includeFiles.add(getProject().resolveFile(include));
       
    69             }
       
    70         }
       
    71         return includeFiles;
       
    72     }
       
    73 
       
    74     /**
       
    75      * {@inheritDoc}
       
    76      */
       
    77     @Override
       
    78     public void filter(FilterTask task, File src, File dest) {
       
    79         String[] pathDirs = {SysdefUtils.getSysdefHome(task.getProject(), task.getEpocroot()).toString()};
       
    80         File script = FileUtils.findExecutableOnPath("joinsysdef", pathDirs);
       
    81         if (script == null) {
       
    82             throw new BuildException("Could not find the joinsysdef tool.");           
       
    83         }
       
    84         ExecTask exec = new ExecTask();
       
    85         exec.bindToOwner(task);
       
    86         exec.setDir(task.getEpocroot());
       
    87         exec.setExecutable(script.toString());
       
    88         exec.createArg().setValue("-config");
       
    89         exec.createArg().setFile(file);
       
    90         exec.createArg().setValue("-output");
       
    91         exec.createArg().setFile(dest);
       
    92         for (File include : getIncludes()) {
       
    93             exec.createArg().setValue("-I" + include.toString());            
       
    94         }
       
    95         exec.createArg().setFile(src);
       
    96         exec.execute();
       
    97     }
       
    98 
       
    99     /**
       
   100      * {@inheritDoc}
       
   101      */
       
   102     @Override
       
   103     public void validate() {
       
   104         if (file == null) {
       
   105             throw new BuildException("'file' attribute is not defined.");
       
   106         }
       
   107         if (!file.exists()) {
       
   108             throw new BuildException("Could not find file: " + file.getAbsolutePath());
       
   109         }
       
   110     }
       
   111     
       
   112 }