buildframework/helium/tools/preparation/preparation.antlib.xml
changeset 620 ad8ffc8e1982
parent 587 85df38eb4012
child 628 7c4a911dc066
equal deleted inserted replaced
585:238f4cb8391f 620:ad8ffc8e1982
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!-- 
       
     3 ============================================================================ 
       
     4 Name        : preparation.antlib.xml 
       
     5 Part of     : Helium 
       
     6 
       
     7 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 All rights reserved.
       
     9 This component and the accompanying materials are made available
       
    10 under the terms of the License "Eclipse Public License v1.0"
       
    11 which accompanies this distribution, and is available
       
    12 at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 
       
    14 Initial Contributors:
       
    15 Nokia Corporation - initial contribution.
       
    16 
       
    17 Contributors:
       
    18 
       
    19 Description:
       
    20 
       
    21 ============================================================================
       
    22 -->
       
    23 <!--* @package preparation -->
       
    24 <antlib xmlns:hlm="http://www.nokia.com/helium">
       
    25 
       
    26     <!--
       
    27        This task will copy the content of the its nested fileset in parallel. The todir attribute defines
       
    28        the output directory. 'threads' defines how many copy you would like in parallel, and verbose
       
    29        defines if you want the copying to be logged.
       
    30      -->
       
    31     <scriptdef language="beanshell" name="parallelCopy" uri="http://www.nokia.com/helium">
       
    32         <attribute name="todir" />
       
    33         <attribute name="threads" />
       
    34         <attribute name="verbose" />
       
    35         <attribute name="overwrite" />
       
    36         <element name="resourceset" type="http://www.nokia.com/helium:resourceSet"/>
       
    37         <![CDATA[
       
    38 import org.apache.tools.ant.taskdefs.Parallel;
       
    39 import org.apache.tools.ant.taskdefs.Copy;
       
    40 import org.apache.tools.ant.BuildException;
       
    41 import org.apache.tools.ant.taskdefs.Mkdir;
       
    42 import java.io.File;
       
    43         
       
    44 int threads = 4;
       
    45 String verbose = "false";
       
    46 String overwrite = "false";
       
    47 
       
    48 if (attributes.get("todir") == null) {
       
    49     throw new BuildException("'todir' attribute is not defined.");
       
    50 }
       
    51 
       
    52 if (attributes.get("threads") != null) {
       
    53     threads = Integer.parseInt(attributes.get("threads"));
       
    54     if (threads < 0) {
       
    55         throw new BuildException("Invalid thread number: " + threads);
       
    56     }
       
    57 }
       
    58 if (attributes.get("verbose") != null) {
       
    59         verbose = attributes.get("verbose");
       
    60 }
       
    61 if (attributes.get("overwrite") != null) {
       
    62         overwrite = attributes.get("overwrite");
       
    63 }
       
    64 // Creating the output dir
       
    65 Mkdir mkdir = new Mkdir();
       
    66 mkdir.setProject(project);
       
    67 mkdir.setTaskName(self.getTaskName());
       
    68 mkdir.setDir(new File(attributes.get("todir")));
       
    69 mkdir.execute();
       
    70 
       
    71 Parallel pt = new Parallel();
       
    72 pt.setProject(project);
       
    73 pt.setTaskName(self.getTaskName());
       
    74 pt.setThreadCount(threads);
       
    75 if (elements.get("resourceset") != null) {
       
    76     resourceSets = elements.get("resourceset");
       
    77     for (int rsi = 0 ; rsi < resourceSets.size() ; rsi++) {
       
    78         resourceCollections  = resourceSets.get(rsi).getData();
       
    79         for (int i = 0 ; i < resourceCollections.size() ; i++) {
       
    80             self.log("Creating copy task...");
       
    81             Copy copy = new Copy();
       
    82             copy.setProject(project);
       
    83             copy.setTaskName(self.getTaskName());
       
    84             copy.setTodir(new File(attributes.get("todir")));
       
    85             copy.add(resourceCollections.get(i));
       
    86             copy.setVerbose(new Boolean(verbose).booleanValue());
       
    87             copy.setOverwrite(new Boolean(overwrite).booleanValue());
       
    88             pt.addTask(copy);
       
    89     }
       
    90     }
       
    91 }
       
    92 self.log("Starting parallel copying...");
       
    93 pt.execute();
       
    94 self.log("Copying completed.");
       
    95 ]]>
       
    96     </scriptdef>
       
    97 
       
    98     <!--
       
    99         This task will unzip each group (represented as path element) in parallel. But the content of each
       
   100         group will be unzipped sequentially.
       
   101      -->
       
   102     <scriptdef language="beanshell" name="parallelUnzip" uri="http://www.nokia.com/helium">
       
   103         <attribute name="todir" />
       
   104         <attribute name="threads" />
       
   105         <attribute name="failonerror" />
       
   106         <attribute name="logdir" />
       
   107         <element name="resourceset" type="http://www.nokia.com/helium:resourceSet"/>
       
   108         <![CDATA[
       
   109 import org.apache.tools.ant.taskdefs.Sequential;
       
   110 import org.apache.tools.ant.taskdefs.Parallel;
       
   111 import org.apache.tools.ant.taskdefs.ExecTask;
       
   112 import org.apache.tools.ant.BuildException;
       
   113 import org.apache.tools.ant.taskdefs.Mkdir;
       
   114 import java.io.File;
       
   115 
       
   116 int threads = 4;
       
   117 String failonerror = "true";
       
   118 String logDir = attributes.get("logdir");
       
   119 
       
   120 if (attributes.get("todir") == null) {
       
   121     throw new BuildException("'todir' attribute is not defined.");
       
   122 }
       
   123 
       
   124 if (attributes.get("threads") != null) {
       
   125     threads = Integer.parseInt(attributes.get("threads"));
       
   126     if (threads < 0) {
       
   127         throw new BuildException("Invalid thread number: " + threads);
       
   128     }
       
   129 }
       
   130 if (attributes.get("failonerror") != null) {
       
   131     failonerror = attributes.get("failonerror");
       
   132 }
       
   133 
       
   134 // Creating the output dir
       
   135 Mkdir mkdir = new Mkdir();
       
   136 mkdir.setProject(project);
       
   137 mkdir.setTaskName(self.getTaskName());
       
   138 mkdir.setDir(new File(attributes.get("todir")));
       
   139 mkdir.execute();
       
   140 
       
   141 if (logDir != null) {
       
   142     Mkdir mkdir = new Mkdir();
       
   143     mkdir.setProject(project);
       
   144     mkdir.setTaskName(self.getTaskName());
       
   145     mkdir.setDir(new File(logDir));
       
   146     mkdir.execute();
       
   147 }
       
   148 
       
   149 // parallel
       
   150 Parallel pt = new Parallel();
       
   151 pt.setProject(project);
       
   152 pt.setTaskName(self.getTaskName());
       
   153 pt.setThreadCount(threads);
       
   154 
       
   155 if (elements.get("resourceset") != null) {
       
   156     resourceSets = elements.get("resourceset");
       
   157     for (int rsi = 0 ; rsi < resourceSets.size() ; rsi++) {
       
   158         resourceCollections  = resourceSets.get(rsi).getData();
       
   159         for (int i = 0 ; i < resourceCollections.size() ; i++) {
       
   160             Sequential seq = new Sequential();
       
   161             seq.setProject(project);
       
   162             seq.setTaskName(self.getTaskName());
       
   163             iterator = resourceCollections.get(i).iterator();
       
   164             while (iterator.hasNext()) {
       
   165                 resource = iterator.next();
       
   166                 self.log("Creating 7zip task...");
       
   167                 ExecTask exec = new ExecTask();
       
   168                 exec.setProject(project);
       
   169                 exec.setTaskName(self.getTaskName());
       
   170                 exec.setExecutable("7za");
       
   171                 if (logDir != null) {
       
   172                     exec.setOutput(new File(logDir, new File(resource.toString()).getName() + ".log"));
       
   173                 }
       
   174                 exec.setDir(new File(attributes.get("todir")));
       
   175                 exec.setFailonerror(new Boolean(failonerror).booleanValue());
       
   176                 exec.createArg().setValue("x");
       
   177                 exec.createArg().setFile(new File(resource.toString()));
       
   178                 exec.createArg().setValue("-y");
       
   179                 seq.addTask(exec);
       
   180             }
       
   181             pt.addTask(seq);
       
   182         }
       
   183     }
       
   184 }
       
   185 self.log("Starting parallel unzipping...");
       
   186 pt.execute();
       
   187 self.log("Unzipping completed.");
       
   188 ]]>
       
   189     </scriptdef>
       
   190 
       
   191 </antlib>