buildframework/helium/sf/java/logging/src/com/nokia/helium/logger/ant/listener/AntLoggingHandler.java
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    18 
    18 
    19 import java.io.File;
    19 import java.io.File;
    20 import java.text.DateFormat;
    20 import java.text.DateFormat;
    21 import java.text.SimpleDateFormat;
    21 import java.text.SimpleDateFormat;
    22 import java.util.Date;
    22 import java.util.Date;
    23 import java.util.Enumeration;
    23 import java.util.HashMap;
    24 import java.util.Hashtable;
    24 import java.util.Hashtable;
    25 import java.util.HashMap;
       
    26 import java.util.Map;
    25 import java.util.Map;
    27 import java.util.Vector;
    26 import java.util.Vector;
    28 
    27 import java.util.Map.Entry;
       
    28 
       
    29 import org.apache.log4j.Logger;
    29 import org.apache.tools.ant.BuildEvent;
    30 import org.apache.tools.ant.BuildEvent;
       
    31 import org.apache.tools.ant.BuildException;
    30 import org.apache.tools.ant.Project;
    32 import org.apache.tools.ant.Project;
    31 import org.apache.tools.ant.Target;
    33 import org.apache.tools.ant.Target;
    32 import org.apache.tools.ant.Task;
    34 import org.apache.tools.ant.Task;
    33 import org.apache.tools.ant.types.LogLevel;
    35 import org.apache.tools.ant.types.LogLevel;
    34 import org.apache.tools.ant.BuildException;
    36 
    35 import org.apache.log4j.Logger;
    37 import com.nokia.helium.core.ant.types.Stage;
    36 
       
    37 import com.nokia.helium.logger.ant.types.StageLogging;
    38 import com.nokia.helium.logger.ant.types.StageLogging;
    38 import com.nokia.helium.logger.ant.types.Stage;
       
    39 
    39 
    40 /**
    40 /**
    41  * Ant logging class for each Stage.
    41  * Ant logging class for each Stage.
    42  * 
    42  * 
    43  * 
    43  * 
    68         antLogLevel = new VerbosityLevelChoices();
    68         antLogLevel = new VerbosityLevelChoices();
    69         stagesMapping = new HashMap<String, Stage>();
    69         stagesMapping = new HashMap<String, Stage>();
    70         stageRecordMap = new HashMap<String, StageLogging>();
    70         stageRecordMap = new HashMap<String, StageLogging>();
    71         depStartTargetMap = new HashMap<String, Vector<Target>>();
    71         depStartTargetMap = new HashMap<String, Vector<Target>>();
    72         stageStartTargetMap = new HashMap<String, Target>();
    72         stageStartTargetMap = new HashMap<String, Target>();
    73         initStagesInformation(project);
    73         initialize(project);
    74     }
    74     }
    75 
    75 
    76     /**
    76     /**
    77      * Return the project associated to this Handler.
    77      * Return the project associated to this Handler.
    78      * 
    78      * 
    85     /**
    85     /**
    86      * {@inheritDoc}
    86      * {@inheritDoc}
    87      */
    87      */
    88     public void handleTargetFinished(BuildEvent event) {
    88     public void handleTargetFinished(BuildEvent event) {
    89         // log.debug("Finished target [" + event.getTarget().getName() + "]");
    89         // log.debug("Finished target [" + event.getTarget().getName() + "]");
    90         if (isEndTarget(event.getTarget().getName())
    90         if (isEndTarget(event.getTarget().getName()) && getIsStageRecordingHappening()
    91                 && getIsStageRecordingHappening() && (getLoggingStarted())) {
    91             && (getLoggingStarted())) {
    92             log.debug("Stopping stage logging for  [" + currentStageName
    92             log.debug("Stopping stage logging for  [" + currentStageName + "] for target ["
    93                     + "] for target [" + event.getTarget().getName() + "]");
    93                 + event.getTarget().getName() + "]");
    94             stopLog(currentStageName, "default");
    94             stopLog(currentStageName, "default");
    95             if (!isDefaultStageStarted)
    95             if (!isDefaultStageStarted) {
    96             {
       
    97                 startLog("default");
    96                 startLog("default");
    98                 isDefaultStageStarted = true;
    97                 isDefaultStageStarted = true;
    99             }
    98             }
   100             currentStageName = null;
    99             currentStageName = null;
   101         }
   100         }
   114         }
   113         }
   115 
   114 
   116         if (currentStageName == null && !getIsStageRecordingHappening() && getLoggingStarted()) {
   115         if (currentStageName == null && !getIsStageRecordingHappening() && getLoggingStarted()) {
   117             String stageName = isStageValid(event.getTarget(), event.getProject());
   116             String stageName = isStageValid(event.getTarget(), event.getProject());
   118             if (stageName != null) {
   117             if (stageName != null) {
   119                 log.debug("Started stage logging for  [" + stageName
   118                 log.debug("Started stage logging for  [" + stageName + "] for target ["
   120                         + "] for target [" + event.getTarget().getName() + "]");
   119                     + event.getTarget().getName() + "]");
   121 
   120 
   122                 if (isDefaultStageStarted)
   121                 if (isDefaultStageStarted) {
   123                 {
       
   124                     stopLog("default", stageName);
   122                     stopLog("default", stageName);
   125                     isDefaultStageStarted = false;
   123                     isDefaultStageStarted = false;
   126                 }
   124                 }
   127                 startLog(stageName);
   125                 startLog(stageName);
   128                 currentStageName = stageName;
   126                 currentStageName = stageName;
   141      * {@inheritDoc}
   139      * {@inheritDoc}
   142      */
   140      */
   143     public void handleBuildFinished(BuildEvent event) {
   141     public void handleBuildFinished(BuildEvent event) {
   144 
   142 
   145         /*
   143         /*
   146          * If any stage logging is happening stop logging into stage log file
   144          * If any stage logging is happening stop logging into stage log file and switch to
   147          * and switch to main/default ant log file.
   145          * main/default ant log file.
   148          */
   146          */
   149         if (getLoggingStarted() && getIsStageRecordingHappening()) {
   147         if (getLoggingStarted() && getIsStageRecordingHappening()) {
   150             stopLog(currentStageName, "default");
   148             stopLog(currentStageName, "default");
   151             if (!isDefaultStageStarted)
   149             if (!isDefaultStageStarted) {
   152             {
       
   153                 startLog("default");
   150                 startLog("default");
   154                 isDefaultStageStarted = true;
   151                 isDefaultStageStarted = true;
   155             }
   152             }
   156             currentStageName = null;
   153             currentStageName = null;
   157         }
   154         }
   158 
   155 
   159         /*
   156         /*
   160          * If default stage logging happening stop logging into default ant log
   157          * If default stage logging happening stop logging into default ant log file.
   161          * file.
       
   162          */
   158          */
   163         if (isDefaultStageStarted && getLoggingStarted()) {
   159         if (isDefaultStageStarted && getLoggingStarted()) {
   164             stopLog("default", null, event);
   160             stopLog("default", null, event);
   165             isDefaultStageStarted = false;
   161             isDefaultStageStarted = false;
   166         }
   162         }
   185     }
   181     }
   186 
   182 
   187     /**
   183     /**
   188      * Sets the level to which this recorder entry should log to.
   184      * Sets the level to which this recorder entry should log to.
   189      * 
   185      * 
   190      * @param level
   186      * @param level the level to set.
   191      *            the level to set.
       
   192      * @see VerbosityLevelChoices
   187      * @see VerbosityLevelChoices
   193      */
   188      */
   194     public void setLoglevel(VerbosityLevelChoices level) {
   189     public void setLoglevel(VerbosityLevelChoices level) {
   195         loglevel = level.getLevel();
   190         loglevel = level.getLevel();
   196     }
   191     }
   197 
   192 
   198     /**
   193     /**
   199      * A list of possible values for the <code>setLoglevel()</code> method.
   194      * A list of possible values for the <code>setLoglevel()</code> method. Possible values include:
   200      * Possible values include: error, warn, info, verbose, debug.
   195      * error, warn, info, verbose, debug.
   201      */
   196      */
   202     public static class VerbosityLevelChoices extends LogLevel {
   197     public static class VerbosityLevelChoices extends LogLevel {
   203     }
   198     }
   204 
   199 
   205     /**
   200     /**
   216      * To get current date and time.
   211      * To get current date and time.
   217      * 
   212      * 
   218      * @return
   213      * @return
   219      */
   214      */
   220     private String getDateTime() {
   215     private String getDateTime() {
   221         DateFormat dateFormat = new SimpleDateFormat(
   216         DateFormat dateFormat = new SimpleDateFormat("EE yyyy/MM/dd HH:mm:ss:SS aaa");
   222                 "EE yyyy/MM/dd HH:mm:ss:SS aaa");
       
   223         Date date = new Date();
   217         Date date = new Date();
   224         return dateFormat.format(date);
   218         return dateFormat.format(date);
   225     }
   219     }
   226 
   220 
   227     /**
   221     /**
   239      * @param stageName
   233      * @param stageName
   240      * @param action
   234      * @param action
   241      * @param message
   235      * @param message
   242      * @param task
   236      * @param task
   243      */
   237      */
   244     public void doLoggingAction(String stageName, boolean action,
   238     public void doLoggingAction(String stageName, boolean action, String message, Task task,
   245             String message, Task task, Target target) {
   239         Target target) {
   246         String time = getDateTime();
   240         String time = getDateTime();
   247         File fileName;
   241         File fileName;
   248         if (stageName.equalsIgnoreCase("default")) {
   242         if (stageName.equalsIgnoreCase("default")) {
   249             if (stageRecordMap.get("default") == null)
   243             if (stageRecordMap.get("default") == null) {
   250                 throw new BuildException("stageRecordMap.get('default') is null");
   244                 throw new BuildException("stageRecordMap.get('default') is null");
       
   245             }
   251             fileName = stageRecordMap.get("default").getDefaultOutput();
   246             fileName = stageRecordMap.get("default").getDefaultOutput();
   252         } else {
   247         } else {
   253             fileName = stageRecordMap.get(stageName).getOutput();
   248             fileName = stageRecordMap.get(stageName).getOutput();
   254         }
   249         }
   255 
   250 
   256         if (fileName.exists()) {
   251         if (fileName.exists()) {
   257             for (Map.Entry<File, RecorderEntry> entry : recorderEntries
   252             for (Map.Entry<File, RecorderEntry> entry : recorderEntries.entrySet()) {
   258                     .entrySet()) {
   253                 if (fileName.equals(entry.getKey()) && (getRecorderEntry(fileName) != null)
   259                 if (fileName.equals(entry.getKey())
   254                     && (fileCreatedMap.get(fileName))) {
   260                         && (getRecorderEntry(fileName) != null)
       
   261                         && (fileCreatedMap.get(fileName))) {
       
   262                     RecorderEntry recorderEntry = getRecorderEntry(fileName);
   255                     RecorderEntry recorderEntry = getRecorderEntry(fileName);
   263                     recorderEntry.addLogMessage(message + " logging into "
   256                     recorderEntry.addLogMessage(message + " logging into " + fileName + " from "
   264                             + fileName + " from " + task.getTaskName()
   257                         + task.getTaskName() + " task at " + time);
   265                             + " task at " + time);
   258                     log.debug(message + " logging into " + fileName + " from " + task.getTaskName()
   266                     log.debug(message + " logging into " + fileName + " from "
   259                         + " task at " + time);
   267                             + task.getTaskName() + " task at " + time);
       
   268                     recorderEntry.setRecordState(action);
   260                     recorderEntry.setRecordState(action);
   269                     break;
   261                     break;
   270                 }
   262                 }
   271             }
   263             }
   272         }
   264         }
   273     }
   265     }
   274 
   266 
   275     /**
   267     /**
   276      * Called by LogReplace task to find and replace any property values which
   268      * Called by LogReplace task to find and replace any property values which are not updated.
   277      * are not updated.
       
   278      * 
   269      * 
   279      * @param regExp
   270      * @param regExp
   280      */
   271      */
   281     public void addRegExp(String regExp) {
   272     public void addRegExp(String regExp) {
   282         if (!regExp.equals("")) {
   273         if (!regExp.equals("")) {
   283             for (Map.Entry<File, RecorderEntry> entry : recorderEntries
   274             for (Map.Entry<File, RecorderEntry> entry : recorderEntries.entrySet()) {
   284                     .entrySet()) {
       
   285                 RecorderEntry recorderEntry = entry.getValue();
   275                 RecorderEntry recorderEntry = entry.getValue();
   286                 recorderEntry.addRegexp(regExp);
   276                 recorderEntry.addRegexp(regExp);
   287             }
   277             }
   288         }
   278         }
   289     }
   279     }
   290 
   280 
   291     /**
   281     /**
   292      * To initialize stages information.
   282      * Initializing stage logging data.
   293      * 
   283      * Gathering all stagerecord.
   294      * @param proj
   284      * 
   295      */
   285      * @param project
   296 
   286      */
   297     @SuppressWarnings("unchecked")
   287     @SuppressWarnings("unchecked")
   298     private void initStagesInformation(Project proj) {
   288     private void initialize(Project project) {
   299         log.debug("initStagesInformation: project: " + proj.getName());
   289         Map<String, Object> references = (Hashtable<String, Object>)project.getReferences();
   300         Hashtable<String, Object> references = proj.getReferences();
   290         //matchStageName(references, stageKey);
   301         Enumeration<String> keyEnum = references.keys();
   291         for (Entry<String, Object> entry : references.entrySet()) {
   302         validateDefaultStage(references);
   292             if (entry.getValue() instanceof StageLogging) {
   303         while (keyEnum.hasMoreElements()) {
   293                 StageLogging tempStageLogging = (StageLogging)entry.getValue();
   304             String key = keyEnum.nextElement();
   294                 // Is the stagerecord having a defaultoutput attribute,
   305             if (references.get(key) instanceof Stage) {
   295                 // if yes, it is the default recorder.
   306                 Stage tempStage = (Stage) references.get(key);
   296                 if (tempStageLogging.getDefaultOutput() != null) {
   307                 validateStageInformation(key, tempStage);
   297                     stageRecordMap.put("default", tempStageLogging);                    
   308                 log.debug("Found  stage [" + key + "] for recording");
   298                     registerRecorderEntry(tempStageLogging.getDefaultOutput(), tempStageLogging, StatusAndLogListener.getStatusAndLogListener().getProject());
   309                 stagesMapping.put(key, (Stage) references.get(key));
   299                 } else if (tempStageLogging.getStageRefID() != null) {
   310                 getStageRecordInformation(proj, key);
   300                     if (references.containsKey(tempStageLogging.getStageRefID())) {
   311                 initDependentTargetMap(proj, key, tempStage.getStartTarget(),
   301                         if (references.get(tempStageLogging.getStageRefID()) instanceof Stage) {
   312                         tempStage.getEndTarget());
   302                             // Check the stage
   313             }
   303                             Stage stage = (Stage)references.get(tempStageLogging.getStageRefID());
   314         }
   304                             validateStageInformation(tempStageLogging.getStageRefID(), stage);
   315     }
   305                             log.debug("Found  stage [" + tempStageLogging.getStageRefID() + "] for recording");
   316 
   306                             stagesMapping.put(tempStageLogging.getStageRefID(), stage);
   317     /**
   307                             //  check the stage logging.
   318      * To initialize stage record information.
   308                             validateStageLogging(entry.getKey(), tempStageLogging);
   319      * 
   309                             stageRecordMap.put(tempStageLogging.getStageRefID(), tempStageLogging);
   320      * @param proj
   310                         } else {
   321      * @param stageKey
   311                             throw new BuildException("Invalid stagerecord stageRefId attribute value, " + 
   322      */
   312                                     "the '" + tempStageLogging.getStageRefID() + "' id doesn't refer to a stage type at " + 
   323     @SuppressWarnings("unchecked")
   313                                     tempStageLogging.getLocation().toString());
   324     private void getStageRecordInformation(Project proj, String stageKey) {
   314                             
   325         Hashtable<String, Object> references = proj.getReferences();
   315                         }
   326         matchStageName(references, stageKey);
   316                     } else {
   327         Enumeration<String> keyEnum = references.keys();
   317                         throw new BuildException("Invalid stagerecord stageRefId attribute value, " + 
   328         while (keyEnum.hasMoreElements()) {
   318                                 "the '" + tempStageLogging.getStageRefID() + "' id doesn't exist at " + 
   329             String key = keyEnum.nextElement();
   319                                 tempStageLogging.getLocation().toString());
   330             if (references.get(key) instanceof StageLogging) {
   320                     }
   331                 StageLogging tempStageLogging = (StageLogging) references
   321                 } else {
   332                         .get(key);
   322                     throw new BuildException("Invalid stagerecord configuration, " + 
   333                 if ((tempStageLogging.getStageRefID() != null)
   323                             "the stageRefId attribute is not defined at " +
   334                         && (tempStageLogging.getStageRefID().equals(stageKey))) {
   324                             tempStageLogging.getLocation().toString());
   335                     validateStageLogging(key, tempStageLogging);
       
   336                     stageRecordMap.put(stageKey, tempStageLogging);
       
   337                     return;
       
   338                 }
   325                 }
   339             }
   326             }
   340         }
   327         }
   341     }
   328         if (!stageRecordMap.containsKey("default")) {
   342 
   329             throw new BuildException("There must be one default stagerecord datatype.");
       
   330         }
       
   331     }
       
   332     
   343     /**
   333     /**
   344      * To start logging for respective stage.
   334      * To start logging for respective stage.
   345      * 
   335      * 
   346      * @param stageName
   336      * @param stageName
   347      */
   337      */
   353         log.debug("Starting logging for [" + stageName + "]");
   343         log.debug("Starting logging for [" + stageName + "]");
   354         if (stageName.equals("default")) {
   344         if (stageName.equals("default")) {
   355             fileName = stageRecordMap.get("default").getDefaultOutput();
   345             fileName = stageRecordMap.get("default").getDefaultOutput();
   356             stageLogging = stageRecordMap.get("default");
   346             stageLogging = stageRecordMap.get("default");
   357             message = "Starting logging into " + fileName + " at " + time;
   347             message = "Starting logging into " + fileName + " at " + time;
   358         } else {
   348         }
       
   349         else {
   359             fileName = stageRecordMap.get(stageName).getOutput();
   350             fileName = stageRecordMap.get(stageName).getOutput();
   360             stageLogging = stageRecordMap.get(stageName);
   351             stageLogging = stageRecordMap.get(stageName);
   361             this.isStageRecordingHappening = true;
   352             this.isStageRecordingHappening = true;
   362             message = "Starting logging for " + stageName + " into " + fileName
   353             message = "Starting logging for " + stageName + " into " + fileName + " at " + time;
   363                     + " at " + time;
       
   364         }
   354         }
   365         if (getRecorderEntry(fileName) != null) {
   355         if (getRecorderEntry(fileName) != null) {
   366             RecorderEntry recorderEntry = getRecorderEntry(fileName);
   356             RecorderEntry recorderEntry = getRecorderEntry(fileName);
   367             if (isFilePresent(recorderEntry, fileName, stageLogging)) {
   357             if (isFilePresent(recorderEntry, fileName, stageLogging)) {
   368                 recorderEntry.setRecordState(true);
   358                 recorderEntry.setRecordState(true);
   377      * @param recorderEntry
   367      * @param recorderEntry
   378      * @param fileName
   368      * @param fileName
   379      * @param stageLogging
   369      * @param stageLogging
   380      * @return
   370      * @return
   381      */
   371      */
   382     private boolean isFilePresent(RecorderEntry recorderEntry, File fileName, StageLogging stageLogging) {
   372     private boolean isFilePresent(RecorderEntry recorderEntry, File fileName,
       
   373         StageLogging stageLogging) {
   383         log.debug("isFilePresent? " + fileName);
   374         log.debug("isFilePresent? " + fileName);
   384         if (!fileCreatedMap.get(fileName)) {
   375         if (!fileCreatedMap.get(fileName)) {
   385             if (!fileName.getParentFile().exists()) {
   376             if (!fileName.getParentFile().exists()) {
   386                 log.debug("Creating dir: " + fileName.getParentFile());
   377                 log.debug("Creating dir: " + fileName.getParentFile());
   387                 fileName.getParentFile().mkdirs();
   378                 fileName.getParentFile().mkdirs();
   388             }
   379             }
   389             if (fileName.exists()) {
   380             if (fileName.exists()) {
   390                 long timestamp = System.currentTimeMillis();
   381                 long timestamp = System.currentTimeMillis();
   391                 getProject().log("Backing up of " + fileName + " into " + fileName + "." + timestamp);
   382                 getProject().log("Backing up of " + fileName + " into " + fileName + "."
       
   383                     + timestamp);
   392                 fileName.renameTo(new File(fileName.getAbsoluteFile() + "." + timestamp));
   384                 fileName.renameTo(new File(fileName.getAbsoluteFile() + "." + timestamp));
   393             }
   385             }
   394             recorderEntry.openFile(stageLogging.getAppend());
   386             recorderEntry.openFile(stageLogging.getAppend());
   395             fileCreatedMap.put(fileName, true);
   387             fileCreatedMap.put(fileName, true);
   396             return true;
   388             return true;
   397         } else {
   389         }
       
   390         else {
   398             return true;
   391             return true;
   399         }
   392         }
   400 
   393 
   401     }
   394     }
   402 
   395 
   415      * 
   408      * 
   416      * @param stopStageName
   409      * @param stopStageName
   417      * @param startStageName
   410      * @param startStageName
   418      * @param event
   411      * @param event
   419      */
   412      */
   420     private void stopLog(String stopStageName, String startStageName,
   413     private void stopLog(String stopStageName, String startStageName, BuildEvent event) {
   421             BuildEvent event) {
       
   422         File fileName;
   414         File fileName;
   423         String message;
   415         String message;
   424         String time = getDateTime();
   416         String time = getDateTime();
   425         log.debug("Stopping logging for [" + stopStageName + "]");
   417         log.debug("Stopping logging for [" + stopStageName + "]");
   426         if (stopStageName.equals("default")) {
   418         if (stopStageName.equals("default")) {
   427             fileName = stageRecordMap.get("default").getDefaultOutput();
   419             fileName = stageRecordMap.get("default").getDefaultOutput();
   428             message = "Stopping logging into " + fileName + " at " + time;
   420             message = "Stopping logging into " + fileName + " at " + time;
   429             if (startStageName != null)
   421             if (startStageName != null) {
   430                 message = message + "\nStarting logging into "
   422                 message = message + "\nStarting logging into "
   431                         + stageRecordMap.get(startStageName).getOutput();
   423                     + stageRecordMap.get(startStageName).getOutput();
   432         } else {
   424             }
       
   425         }
       
   426         else {
   433             fileName = stageRecordMap.get(stopStageName).getOutput();
   427             fileName = stageRecordMap.get(stopStageName).getOutput();
   434             this.isStageRecordingHappening = false;
   428             this.isStageRecordingHappening = false;
   435             message = "Stopping logging for " + stopStageName + " into "
   429             message = "Stopping logging for " + stopStageName + " into " + fileName + " at " + time;
   436                     + fileName + " at " + time;
   430             if (startStageName != null) {
   437             if (startStageName != null)
       
   438                 message = message + "\nResuming logging into "
   431                 message = message + "\nResuming logging into "
   439                         + stageRecordMap.get("default").getDefaultOutput();
   432                     + stageRecordMap.get("default").getDefaultOutput();
       
   433             }
   440         }
   434         }
   441         if (getRecorderEntry(fileName) != null) {
   435         if (getRecorderEntry(fileName) != null) {
   442             RecorderEntry recorderEntry = getRecorderEntry(fileName);
   436             RecorderEntry recorderEntry = getRecorderEntry(fileName);
   443             if (event != null) {
   437             if (event != null) {
   444                 recorderEntry.handleBuildFinished(event);
   438                 recorderEntry.handleBuildFinished(event);
   454      * 
   448      * 
   455      * @param fileName
   449      * @param fileName
   456      * @param stageLogging
   450      * @param stageLogging
   457      * @param proj
   451      * @param proj
   458      */
   452      */
   459     private void registerRecorderEntry(File fileName,
   453     private void registerRecorderEntry(File fileName, StageLogging stageLogging, Project proj) {
   460             StageLogging stageLogging, Project proj) {
       
   461         log.debug("Registering recorderentry for log file [" + fileName + "]");
   454         log.debug("Registering recorderentry for log file [" + fileName + "]");
   462         RecorderEntry recorderEntry = getRecorder(fileName);
   455         RecorderEntry recorderEntry = getRecorder(fileName);
   463         antLogLevel.setValue(stageLogging.getLogLevel());
   456         antLogLevel.setValue(stageLogging.getLogLevel());
   464         this.setLoglevel(antLogLevel);
   457         this.setLoglevel(antLogLevel);
   465         recorderEntry.setMessageOutputLevel(loglevel);
   458         recorderEntry.setMessageOutputLevel(loglevel);
   466         recorderEntry.setEmacsMode(false);
   459         recorderEntry.setEmacsMode(false);
   467         recorderEntry.setRecordState(false);
   460         recorderEntry.setRecordState(false);
   468         if (fileCreatedMap.get(fileName) == null)
   461         if (fileCreatedMap.get(fileName) == null) {
   469             fileCreatedMap.put(fileName, false);
   462             fileCreatedMap.put(fileName, false);
       
   463         }
   470     }
   464     }
   471 
   465 
   472     /**
   466     /**
   473      * To check is the stage valid for given start and end targets.
   467      * To check is the stage valid for given start and end targets.
   474      * 
   468      * 
   475      * @param target
   469      * @param target
   476      * @param proj
   470      * @param proj
   477      * @return
   471      * @return
   478      */
   472      */
   479     private String isStageValid(Target target, Project proj) {
   473     private String isStageValid(Target target, Project proj) {
   480         //if (!proj.getName().equals(StatusAndLogListener.getStatusAndLogListener().getProject().getName()) && (StatusAndLogListener.getStatusAndLogListener().getProject().getName() != null)) {
   474         // if
   481             initSubProjectDependentTarget(proj);
   475         // (!proj.getName().equals(StatusAndLogListener.getStatusAndLogListener().getProject().getName())
   482         //}
   476         // && (StatusAndLogListener.getStatusAndLogListener().getProject().getName() != null)) {
       
   477         initSubProjectDependentTarget(proj);
       
   478         // }
   483         for (Map.Entry<String, Stage> entry : stagesMapping.entrySet()) {
   479         for (Map.Entry<String, Stage> entry : stagesMapping.entrySet()) {
   484             Stage stage = entry.getValue();
   480             Stage stage = entry.getValue();
   485             if (stage.getStartTarget().equals(target.getName())
   481             if (stage.getStartTarget().equals(target.getName())
   486                     && validateStageTargets(proj, stage.getStartTarget(), stage
   482                 && validateStageTargets(proj, stage.getStartTarget(), stage.getEndTarget())) {
   487                             .getEndTarget())) {
   483                 log.debug("Found stage [" + entry.getKey() + "] for target [" + target.getName()
   488                 log.debug("Found stage [" + entry.getKey() + "] for target ["
   484                     + "]");
       
   485                 return entry.getKey();
       
   486             }
       
   487             if (stageStartTargetMap.get(entry.getKey()) != null) {
       
   488                 if (stageStartTargetMap.get(entry.getKey()).getName().equals(target.getName())) {
       
   489                     log.debug("Found stage [" + entry.getKey() + "] for dependent target ["
   489                         + target.getName() + "]");
   490                         + target.getName() + "]");
   490                 return entry.getKey();
       
   491             }
       
   492             if (stageStartTargetMap.get(entry.getKey()) != null) {
       
   493                 if (stageStartTargetMap.get(entry.getKey()).getName().equals(
       
   494                         target.getName())) {
       
   495                     log.debug("Found stage [" + entry.getKey()
       
   496                             + "] for dependent target [" + target.getName()
       
   497                             + "]");
       
   498                     return entry.getKey();
   491                     return entry.getKey();
   499                 }
   492                 }
   500             } else if (isDependentTarget(target, entry.getKey())) {
   493             }
   501                 log.debug("Found stage [" + entry.getKey()
   494             else if (isDependentTarget(target, entry.getKey())) {
   502                         + "] for dependent target [" + target.getName() + "]");
   495                 log.debug("Found stage [" + entry.getKey() + "] for dependent target ["
       
   496                     + target.getName() + "]");
   503                 return entry.getKey();
   497                 return entry.getKey();
   504             }
   498             }
   505         }
   499         }
   506         return null;
   500         return null;
   507     }
   501     }
   513      * @return
   507      * @return
   514      */
   508      */
   515 
   509 
   516     private boolean isEndTarget(String targetName) {
   510     private boolean isEndTarget(String targetName) {
   517         if (stagesMapping.get(currentStageName) != null) {
   511         if (stagesMapping.get(currentStageName) != null) {
   518             return stagesMapping.get(currentStageName).getEndTarget().equals(
   512             return stagesMapping.get(currentStageName).getEndTarget().equals(targetName);
   519                     targetName);
       
   520         }
   513         }
   521         return false;
   514         return false;
   522     }
   515     }
   523 
   516 
   524     /**
   517     /**
   525      * To validate is the endtarget and starttarget are present in the current
   518      * To validate is the endtarget and starttarget are present in the current project.
   526      * project.
       
   527      * 
   519      * 
   528      * @param proj
   520      * @param proj
   529      * @param startTarget
   521      * @param startTarget
   530      * @param endTarget
   522      * @param endTarget
   531      * @return
   523      * @return
   532      */
   524      */
   533 
   525 
   534     @SuppressWarnings("unchecked")
   526     @SuppressWarnings("unchecked")
   535     private boolean validateStageTargets(Project proj, String startTarget,
   527     private boolean validateStageTargets(Project proj, String startTarget, String endTarget) {
   536             String endTarget) {
       
   537 
   528 
   538         Hashtable<String, String> antTargets = proj.getTargets();
   529         Hashtable<String, String> antTargets = proj.getTargets();
   539         return antTargets.containsKey(startTarget)
   530         return antTargets.containsKey(startTarget) && antTargets.containsKey(endTarget);
   540                 && antTargets.containsKey(endTarget);
       
   541     }
   531     }
   542 
   532 
   543     /**
   533     /**
   544      * To check is recording is happening for any stages.
   534      * To check is recording is happening for any stages.
   545      * 
   535      * 
   578      * @param stageKey
   568      * @param stageKey
   579      * @param startTarget
   569      * @param startTarget
   580      * @param endTarget
   570      * @param endTarget
   581      */
   571      */
   582     @SuppressWarnings("unchecked")
   572     @SuppressWarnings("unchecked")
   583     private void initDependentTargetMap(Project proj, String stageKey,
   573     private void initDependentTargetMap(Project proj, String stageKey, String startTarget,
   584             String startTarget, String endTarget) {
   574         String endTarget) {
   585         Vector<Target> arrayList = null;
   575         Vector<Target> arrayList = null;
   586         if (validateStageTargets(proj, startTarget, endTarget)) {
   576         if (validateStageTargets(proj, startTarget, endTarget)) {
   587             arrayList = proj.topoSort(startTarget, proj.getTargets(), false);
   577             arrayList = proj.topoSort(startTarget, proj.getTargets(), false);
   588             log.debug("Target dependency for " + startTarget);
   578             log.debug("Target dependency for " + startTarget);
   589             for (Target target : arrayList) {
   579             for (Target target : arrayList) {
   603      */
   593      */
   604     private void initSubProjectDependentTarget(Project proj) {
   594     private void initSubProjectDependentTarget(Project proj) {
   605 
   595 
   606         for (Map.Entry<String, Stage> entry : stagesMapping.entrySet()) {
   596         for (Map.Entry<String, Stage> entry : stagesMapping.entrySet()) {
   607             if (depStartTargetMap.get(entry.getKey()) == null) {
   597             if (depStartTargetMap.get(entry.getKey()) == null) {
   608                 initDependentTargetMap(proj, entry.getKey(), entry.getValue()
   598                 initDependentTargetMap(proj, entry.getKey(), entry.getValue().getStartTarget(), entry.getValue().getEndTarget());
   609                         .getStartTarget(), entry.getValue().getEndTarget());
       
   610             }
   599             }
   611         }
   600         }
   612     }
   601     }
   613 
   602 
   614     /**
   603     /**
   619      */
   608      */
   620     private void validateStageInformation(String stageKey, Stage stage) {
   609     private void validateStageInformation(String stageKey, Stage stage) {
   621 
   610 
   622         if (stage.getStartTarget() == null) {
   611         if (stage.getStartTarget() == null) {
   623             throw new BuildException("'starttarget' for stage '" + stageKey
   612             throw new BuildException("'starttarget' for stage '" + stageKey
   624                     + "' should not be null.");
   613                 + "' should not be null.");
   625         }
   614         }
   626 
   615 
   627         if (stage.getEndTarget() == null) {
   616         if (stage.getEndTarget() == null) {
   628             throw new BuildException("'endtarget' for stage '" + stageKey
   617             throw new BuildException("'endtarget' for stage '" + stageKey + "' should not be null.");
   629                     + "' should not be null.");
       
   630         }
   618         }
   631     }
   619     }
   632 
   620 
   633     /**
   621     /**
   634      * To validate each stagelogging data type.
   622      * To validate each stagelogging data type.
   635      * 
   623      * 
   636      * @param stagerefid
   624      * @param stagerefid
   637      * @param stageLogging
   625      * @param stageLogging
   638      */
   626      */
   639     private void validateStageLogging(String stagerefid,
   627     private void validateStageLogging(String stagerefid, StageLogging stageLogging) {
   640             StageLogging stageLogging) {
       
   641 
   628 
   642         if (stageLogging.getOutput() == null) {
   629         if (stageLogging.getOutput() == null) {
   643             throw new BuildException("'output' attribute for stagelogging '"
   630             throw new BuildException("'output' attribute for stagelogging '" + stagerefid
   644                     + stagerefid + "' should not be null.");
   631                 + "' should not be null.");
   645         }
   632         }
   646         registerRecorderEntry(stageLogging.getOutput(), stageLogging,
   633         registerRecorderEntry(stageLogging.getOutput(), stageLogging, StatusAndLogListener.getStatusAndLogListener().getProject());
   647                 StatusAndLogListener.getStatusAndLogListener().getProject());
       
   648     }
       
   649 
       
   650     /**
       
   651      * To validate default stage.
       
   652      * 
       
   653      * @param stageRecord
       
   654      */
       
   655     private void validateDefaultStage(Hashtable<String, Object> stageRecord) {
       
   656 
       
   657         Enumeration<String> keyEnum = stageRecord.keys();
       
   658         while (keyEnum.hasMoreElements()) {
       
   659             String key = keyEnum.nextElement();
       
   660             if (stageRecord.get(key) instanceof StageLogging) {
       
   661                 StageLogging tempStageLogging = (StageLogging) stageRecord
       
   662                         .get(key);
       
   663                 if ((tempStageLogging.getStageRefID() == null)
       
   664                         && (tempStageLogging.getDefaultOutput() != null)) {
       
   665                     stageRecordMap.put("default", tempStageLogging);
       
   666                     registerRecorderEntry(tempStageLogging.getDefaultOutput(),
       
   667                             tempStageLogging, StatusAndLogListener
       
   668                                     .getStatusAndLogListener().getProject());
       
   669                     return;
       
   670                 }
       
   671             }
       
   672         }
       
   673         throw new BuildException("There should be one default stagerecord datatype.");
       
   674     }
       
   675 
       
   676     /**
       
   677      * To validate respective stagelogging for stage datatype.
       
   678      * 
       
   679      * @param stageRecord
       
   680      * @param stageKey
       
   681      */
       
   682     private void matchStageName(Hashtable<String, Object> stageRecord,
       
   683             String stageKey) {
       
   684 
       
   685         Enumeration<String> keyEnum = stageRecord.keys();
       
   686         while (keyEnum.hasMoreElements()) {
       
   687             String key = keyEnum.nextElement();
       
   688             if (stageRecord.get(key) instanceof StageLogging) {
       
   689                 StageLogging tempStageLogging = (StageLogging) stageRecord
       
   690                         .get(key);
       
   691                 if ((tempStageLogging.getStageRefID() != null)
       
   692                         && (tempStageLogging.getStageRefID().equals(stageKey))) {
       
   693                     return;
       
   694                 }
       
   695             }
       
   696         }
       
   697         throw new BuildException(
       
   698                 "there is no stagelogging datatype matching for stage '"
       
   699                         + stageKey + "'");
       
   700     }
   634     }
   701 
   635 
   702     /**
   636     /**
   703      * To retrun recorderEntry of respective file.
   637      * To retrun recorderEntry of respective file.
   704      * 
   638      *