buildframework/helium/sf/java/sbs/src/com/nokia/helium/sbs/ant/taskdefs/SBSTask.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
 * All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
 * Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
 * Description:  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.helium.sbs.ant.taskdefs;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    20
import java.io.File;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    21
import java.util.ArrayList;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
import java.util.Collection;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    23
import java.util.Hashtable;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import java.util.List;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    25
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    26
import org.apache.log4j.Logger;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import org.apache.tools.ant.BuildException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import org.apache.tools.ant.Project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import org.apache.tools.ant.Task;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    30
import org.apache.tools.ant.types.PatternSet;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    31
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    32
import com.nokia.helium.core.ant.MappedVariable;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import com.nokia.helium.core.ant.types.VariableSet;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    34
import com.nokia.helium.core.plexus.AntStreamConsumer;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
import com.nokia.helium.sbs.SAXSysdefParser;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
import com.nokia.helium.sbs.SBSCommandBase;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
import com.nokia.helium.sbs.SBSException;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    38
import com.nokia.helium.sbs.ant.types.SBSInput;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    39
import com.nokia.helium.sbs.ant.types.SBSMakeOptions;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
import com.nokia.helium.sbs.plexus.SBSErrorStreamConsumer;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
/**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    43
 * This task is to execute the actual sbs commands with the list of sbs parameters using sbsinput
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    44
 * type. Based on the raptor input list of additional log file path used needs to be set, so that
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    45
 * the scanlog, additional log files are generated properly.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
 * <pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
 * Example 1:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
 * &lt;sbstask sbsinput=&quot;sbs.input&quot; sysdefFile=&quot;system.def.file&quot;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
 *      layerPatternSetRef=&quot;sbs.patternset&quot; errorOutput=&quot;sbs.log.file.error.log&quot;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
 *      workingDir=&quot;build.drive&quot; failOnError=&quot;false&quot; outputLog=&quot;sbs.log.file&quot;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
 *      cleanLog=&quot;sbs.log.file.clean.log&quot; statsLog=&quot;sbs.log.file.info.xml&quot; /&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
 * </pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
 * @ant.task name="sbstask" category="SBS"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
public class SBSTask extends Task {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    private Logger log = Logger.getLogger(SBSTask.class);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    private String sbsInputName;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
    private String layerPatternSetRef;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    private File sysDefFile;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    private File workingDir;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    private File errorFile;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    private String logSuffix;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    private File outputLogName;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    private boolean executeCmd = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    private boolean failOnError = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
    private boolean addMakeOptions = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
    private SBSCommandBase sbsCmd = new SBSCommandBase();;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    private String errorPattern;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    73
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    74
    public SBSCommandBase getSbsCmd() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    75
        return sbsCmd;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    76
    }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    79
     * Helper function to set the clean log file. The cleanlog file captures the clean output from
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    80
     * raptor and stores into a separate log. This is being used to backtrace the error information
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    81
     * to associate the components. The clean log contains the list of files has to be cleaned by
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    82
     * the raptor command for a specific components. An environment varialbe is set which is used by
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    83
     * filterMetadata plugin to store the clean log file in python.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    84
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
     * @param logPath, path of the clean log file.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
     * @deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    @Deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
    public void setCleanLog(String logPath) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    90
        // cleanLog = logPath;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        log("The usage of the cleanLog attribute is deprecated.");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    95
     * Helper function to set the what log file. The what log file captures the what output from
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    96
     * raptor and stores into a separate log. This is being used to backtrace the error information
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    97
     * to associate the components. The clean log contains the list of files has to be cleaned by
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    98
     * the raptor command for a specific components. An environment varialbe is set which is used by
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    99
     * filterMetadata plugin to store the clean log file in python.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   100
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
     * @param logPath, path of the clean log file.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
     * @deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    @Deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    public void setWhatLog(String logPath) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   106
        // whatLog = logPath;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        log("The usage of the whatLog attribute is deprecated.");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   111
     * Helper function to set the output log file name. Path of the output log where the raptor
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   112
     * command output to be stored. This would be obtained from sbsinput, if the raptor argument
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   113
     * --logfile set.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   114
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
     * @param logName, name of the logfile to store the raptor output.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
    public void setOutputLog(File logName) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        outputLogName = logName;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   120
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
     * To get the output log.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   123
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
    public File getOutputLog() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   127
        return outputLogName;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   131
     * Helper function to set the statistics info of the raptor command. The stats file contains how
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   132
     * long the build being executed, the log file for which the stats is obtained. Used during
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   133
     * scanlog generation from template file. Once ORM is working an additional table could be
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   134
     * created which stores the statistics information, in which case, there won't be the need for
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   135
     * the statistics file.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   136
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
     * @param log name of the logfile to store the raptor command statistics information.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
     * @deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
    @Deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
    public void setStatsLog(File log) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   142
//        statsLog = log;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   146
     * Helper function to set the sbsinput name for which the sbs to be executed. The sbsinput
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   147
     * contains the raptor parameter both the sbs options and sbs make options.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   148
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
     * @param inputName name of the sbs input which contains the list of sbs parameters.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
    public void setSBSInput(String inputName) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        sbsInputName = inputName;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   154
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
     * To get the sbs name.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   157
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
    public String getSBSInput() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   161
        return sbsInputName;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   165
     * Helper function to set the sbs error log file path. The error log file contains the errors
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   166
     * captured from the raptor error stream and processed separately.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   167
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
     * @param file path of the error output to be stored for the raptor command execution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
    public void setErrorOutput(File file) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
        errorFile = file;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   173
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
     * To get the error output file.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   176
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
    public File getErrorOutput() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   180
        return errorFile;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   184
     * Helper function to set the sysdef file path. System definition file contains the full list of
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   185
     * components to be build with the sbs input. For 1.4.0 schema the sysdef file should be already
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   186
     * filtered for the corresponding abld configuration and the sysdef file associated here
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   187
     * contains only layers for which the sbs command needs to be executed with sbsinput arguments.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   188
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
     * @param file sysdef file path.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
    public void setSysDefFile(File file) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
        sysDefFile = file;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   194
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
     * To get the sysdef file.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   197
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
    public File getSysDefFile() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   201
        return sysDefFile;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   205
     * Helper function to set the log suffix.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   206
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   207
     * @param suffix logfile suffix.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
    public void setLogSuffix(String suffix) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        logSuffix = suffix;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   212
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
     * To get the logsuffix.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   215
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
    public String getLogSuffix() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   219
        return logSuffix;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   223
     * Patternset is used to filter the layers from the sysdef file for which the sbs commands need
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   224
     * to be executed instead of all the layers in the system definition files. This is useful for
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   225
     * example in order to execute only the test layer, a patter set could contain test*, then all
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   226
     * the layers begining with test are matched and passed as raptor input.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   227
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   228
     * @param id patternset id, for which the patterns to be filtered.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
    public void setLayerPatternSetRef(String id) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
        layerPatternSetRef = id;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   233
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
     * 
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   236
     * To get the layer pattern set.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   237
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
    public String getLayerPatternSetRef() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   241
        return layerPatternSetRef;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   245
     * Helper function to set the current working directory. This would be mostly the root of the
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   246
     * build area.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   247
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   248
     * @param dir root of the build area location from which to execute the raptor commands.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
    public void setWorkingDir(File dir) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
        workingDir = dir;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   252
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   253
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
     * To get the working dir.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   256
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
    public File getWorkingDir() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   260
        return workingDir;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   264
     * Helper function to execute the actual commands or just print the commands and not execute the
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   265
     * actual commands.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   266
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   267
     * @param execute true / false if true print and execute the commands, otherwise just print the
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   268
     *        commands.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
    public void setExecute(boolean execute) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
        executeCmd = execute;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   273
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   274
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
     * To get execute value.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   276
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   279
    public boolean getExecute() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   280
        return executeCmd;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   281
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   282
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   283
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   284
     * Helper function to set whether to fail the build or not.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   285
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   286
     * @param failBuild true / false - true to fail the build otherwise false.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
    public void setFailOnError(boolean failBuild) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
        failOnError = failBuild;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   290
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   291
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   292
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   293
     * To get the failonError value.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   294
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   295
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   296
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   297
    public boolean getFailOnError() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   298
        return failOnError;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   299
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   300
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   301
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   302
     * @param addMakeOptions the addMakeOptions to set
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   303
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   304
    protected void setAddMakeOptions(boolean addMakeOptions) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   305
        this.addMakeOptions = addMakeOptions;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   306
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   307
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   308
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   309
     * To get the error Pattern.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   310
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   311
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   312
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   313
    protected String getErrorStreamPattern() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   314
        return this.errorPattern;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   315
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   316
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   317
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   318
     * Execute the sbs commands from sbsinput.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   319
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   320
     * @throws BuildException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   321
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   322
    public void execute() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   323
        SBSErrorStreamConsumer sbsErrorConsumer = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   324
        validateParameter();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   325
        sbsCmd.setWorkingDir(workingDir);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   326
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   327
            log.debug("error stream file : " + errorFile);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   328
            sbsCmd.addOutputLineHandler(new AntStreamConsumer(this));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   329
            if (errorFile == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   330
                log.debug("redirecting error to Antstream");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   331
                sbsCmd.addErrorLineHandler(new AntStreamConsumer(this));
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   332
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   333
            else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   334
                sbsErrorConsumer = new SBSErrorStreamConsumer(errorFile, getErrorStreamPattern());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   335
                log.debug("redirecting error to file stream");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   336
                sbsCmd.addErrorLineHandler(sbsErrorConsumer);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   337
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   338
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   339
        catch (java.io.FileNotFoundException ex) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   340
            log("file path: " + errorFile + "Not valid");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   341
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   342
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   343
        try {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   344
            String cmdLine = getSBSCmdLine();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   345
            if (cmdLine == null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   346
                // this happens in case there is nothing to be built, let's just run
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   347
                // sbs anyway so the output log is generated
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   348
                cmdLine = " --logfile " + getOutputLog().getAbsolutePath();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   349
            }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   350
            log(getSbsCmd().getExecutable() + " commands: " + cmdLine);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   351
            if (executeCmd) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   352
                sbsCmd.execute(cmdLine);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   353
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   354
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   355
        catch (SBSException sex) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   356
            log.debug("SBS exception occured during sbs execution", sex);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   357
            if (failOnError) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   358
                throw new BuildException("exception during SBS execution", sex);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   359
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   360
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   361
        finally {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   362
            // Called to update the error stream, better would be the commandbase
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   363
            // handling the closing of streams in case of exceptions.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   364
            if (sbsErrorConsumer != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   365
                sbsErrorConsumer.close();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   366
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   367
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   368
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   369
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   370
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   371
     * Internal function to get the filtered layers by processing the system definition file with
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   372
     * list of matched layers.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   373
     * 
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   374
     * @return list of filtered layers from the sysdef file for which the raptor commands to be
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   375
     *         executed.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   376
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   377
    private List<String> getFilteredLayers() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   378
        List<String> filteredLayers = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   379
        if (layerPatternSetRef != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   380
            Hashtable references = getProject().getReferences();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   381
            Object layerPatternSetObject = references.get(layerPatternSetRef);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   382
            if (layerPatternSetObject != null && !(layerPatternSetObject instanceof PatternSet)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   383
                throw new BuildException("Layer Pattern set is not of type PatternSet");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   384
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   385
            if (layerPatternSetObject != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   386
                PatternSet layerPatternSet = (PatternSet) layerPatternSetObject;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   387
                SAXSysdefParser sysDefParser = new SAXSysdefParser(sysDefFile);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   388
                List<String> fullLayerList = sysDefParser.getLayers();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   389
                filteredLayers = new ArrayList<String>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   390
                String[] includes = layerPatternSet.getIncludePatterns(getProject());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   391
                String[] excludes = layerPatternSet.getExcludePatterns(getProject());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   392
                if (includes == null && excludes == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   393
                    throw new BuildException("No patterns specified");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   394
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   395
                for (String layer : fullLayerList) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   396
                    if (isIncluded(layer, includes)) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   397
                        if (!isExcluded(layer, excludes)) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   398
                            filteredLayers.add(layer);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   399
                        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   400
                        continue;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   401
                    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   402
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   403
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   404
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   405
        return filteredLayers;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   406
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   407
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   408
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   409
     * Internal function to find the included layer patterns.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   410
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   411
     * @param text - layer name to be compared with
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   412
     * @param includes - compare the layer name with the includes list.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   413
     * @return true if the text containing layer name to be included.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   414
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   415
    private boolean isIncluded(String text, String[] includes) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   416
        if (includes == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   417
            return true;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   418
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   419
        else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   420
            for (String pattern : includes) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   421
                if (text.matches(pattern)) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   422
                    return true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   423
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   424
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   425
            return false;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   426
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   427
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   428
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   429
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   430
     * Internal function to find the excluded layer patterns.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   431
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   432
     * @param text - layer name to be compared with
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   433
     * @param excludes - compare the layer name with the excludes list.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   434
     * @return true if the text containing layer name to be excluded.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   435
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   436
    private boolean isExcluded(String text, String[] excludes) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   437
        if (excludes != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   438
            for (String pattern : excludes) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   439
                if (text.matches(pattern)) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   440
                    return true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   441
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   442
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   443
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   444
        return false;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   445
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   446
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   447
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   448
     * To Validate the parameters passed.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   449
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   450
    protected void validateParameter() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   451
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   452
        if (getSBSInput() == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   453
            throw new BuildException("'sbsInputName' is not defined");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   454
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   455
        if (getSysDefFile() == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   456
            throw new BuildException("'System Definition' file is missing");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   457
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   458
        if (getWorkingDir() == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   459
            throw new BuildException("'workingDir' must be set");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   460
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   461
        if (getOutputLog() == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   462
            throw new BuildException("'OutputLog' must be set");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   463
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   464
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   465
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   466
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   467
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   468
     * To get the SBS command line parameters.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   469
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   470
     * @return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   471
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   472
    protected String getSBSCmdLine() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   473
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   474
        List<String> filteredLayers = getFilteredLayers();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   475
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   476
        Object refObject = getProject().getReferences().get(sbsInputName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   477
        if (refObject == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   478
            throw new BuildException("invalid sbs input reference: " + sbsInputName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   479
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   480
        if (refObject != null && !(refObject instanceof SBSInput)) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   481
            throw new BuildException("sbs input name " + sbsInputName + "is not valid");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   482
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   483
        SBSInput sbsInput = (SBSInput) refObject;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   484
        StringBuffer cmdOptions = new StringBuffer();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   485
        VariableSet sbsOptions = sbsInput.getFullSBSOptions();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   486
        cmdOptions.append(" -s " + sysDefFile);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   487
        Collection<MappedVariable> variableList = sbsOptions.getVariables();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   488
        if (sbsOptions != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   489
            if (variableList.isEmpty()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   490
                throw new BuildException("sbsoptions cannot be empty for input: " + sbsInputName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   491
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   492
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   493
        cmdOptions.append(" --logfile " + getOutputLog().getAbsolutePath());
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   494
        for (MappedVariable variable : variableList) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   495
            if (variable.getParameter().startsWith("--logfile")) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   496
                this.log("The following command line argument will be ignored: "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   497
                    + variable.getParameter(), Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   498
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   499
            else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   500
                cmdOptions.append(" " + variable.getParameter());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   501
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   502
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   503
        SBSMakeOptions sbsMakeOptions = sbsInput.getFullSBSMakeOptions();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   504
        variableList = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   505
        if (sbsMakeOptions != null && addMakeOptions) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   506
            cmdOptions.append(" -e " + sbsMakeOptions.getEngine());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   507
            String ppThreads = sbsMakeOptions.getPPThreads();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   508
            if (ppThreads != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   509
                cmdOptions.append(" -j " + ppThreads);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   510
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   511
            variableList = sbsMakeOptions.getVariables();
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   512
            for (MappedVariable variable : variableList) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   513
                cmdOptions.append(" --mo=");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   514
                cmdOptions.append(variable.getParameter());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   515
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   516
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   517
        if (filteredLayers != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   518
            if (filteredLayers.isEmpty()) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   519
                log("Warning: No matching layers to build from system definition file, skipped");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   520
                return null;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   521
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   522
            else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   523
                for (String layer : filteredLayers) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   524
                    cmdOptions.append(" -l " + layer);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   525
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   526
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   527
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   528
        return cmdOptions.toString();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   529
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   530
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   531
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   532
}