buildframework/helium/sf/java/diamonds/src/com/nokia/helium/diamonds/StageDiamondsListener.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
/*
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     3
 * All rights reserved.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     4
 * This component and the accompanying materials are made available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     6
 * which accompanies this distribution, and is available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     8
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
     9
 * Initial Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    10
 * Nokia Corporation - initial contribution.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    11
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    12
 * Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    13
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    14
 * Description:  
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    15
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    16
 */
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.helium.diamonds;
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.util.ArrayList;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import java.util.Date;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
import java.util.Enumeration;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    23
import java.util.HashMap;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    24
import java.util.Iterator;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    25
import java.util.LinkedHashMap;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import java.util.List;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import java.util.Map;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    28
import java.util.Set;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import java.util.Vector;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    30
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import org.apache.log4j.Logger;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    32
import org.apache.tools.ant.BuildEvent;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    33
import org.apache.tools.ant.BuildException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    34
import org.apache.tools.ant.Project;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    35
import org.apache.tools.ant.Target;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    36
import com.nokia.helium.core.ant.types.Stage;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
/**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    39
 * Diamonds client used to connect to get build id and also to send the build results
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
public class StageDiamondsListener extends DiamondsListenerImpl {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    private static final Date INVALID_DATE = new Date(-1);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    46
    private static Object mutexObject = new Object();;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    47
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    private Logger log = Logger.getLogger(StageDiamondsListener.class);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    49
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    private List<Map<String, Date>> stageTargetBeginList = new ArrayList<Map<String, Date>>();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    52
    private Map<String, List<Stage>> stageTargetEndMap = new HashMap<String, List<Stage>>();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    54
    private Map<String, String> stageStartTargetMap = new HashMap<String, String>();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    55
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    56
    private Map<String, Date> stageStartTargetTimeMap = new HashMap<String, Date>();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    57
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    private boolean isTargetMapInitialized;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    60
    private Map<String, Stage> stages;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    public StageDiamondsListener() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        stages = DiamondsConfig.getStages();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    public void targetBegin(BuildEvent buildEvent) throws DiamondsException {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    68
        initDiamondsClient();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    69
        Project projectInStage = buildEvent.getProject();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    70
        int hashCode = projectInStage.hashCode();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        String targetName = buildEvent.getTarget().getName();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        if (!isTargetMapInitialized && stages != null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    73
            log.debug("diamonds:StageDiamondsListener: initializing for all stages.");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    74
            initStageTargetsMap(projectInStage);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
            isTargetMapInitialized = true;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    77
        String targetNameWithHashCode = targetName + "-" + hashCode;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    78
        log.debug("targetBegin: targetNameWithHashCode: " + targetNameWithHashCode);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    79
        log.debug("targetBegin targetName: " + targetName + " - currentStartTargetName:"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    80
            + stageStartTargetMap.get(targetNameWithHashCode));
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    81
        if (stageStartTargetMap.get(targetNameWithHashCode) == null) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    82
            log.debug("looking for start target match and associating time to it");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    83
            findAndSetStartTimeForTargetInStageList(targetName, targetNameWithHashCode);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    86
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    87
    private Date getStartTime(Stage stage) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    88
        String startTargetName = stage.getStartTarget();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    89
        for (Iterator<Map<String, Date>> listIter = stageTargetBeginList.iterator(); listIter.hasNext();) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    90
            Map<String, Date> stageMap = listIter.next();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    91
            if (stageMap.get(startTargetName) != null) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    92
                Set<String> targetSet = stageMap.keySet();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    93
                for (String key : targetSet) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    94
                    log.debug("key: " + key);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    95
                    Date time = stageMap.get(key);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    96
                    log.debug("time: " + time);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    97
                    if (time != INVALID_DATE) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    98
                        return time;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    99
                    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   100
                }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   101
            }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   102
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   103
        throw new BuildException("No time recorded " + "for stage:" + stage.getStageName());
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   104
    }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   106
    private void sendStageInfo(String targetName, int hashCode) throws DiamondsException {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   107
        List<Stage> stageList = stageTargetEndMap.get(targetName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   108
        synchronized (mutexObject) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   109
            if (stageList != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   110
                for (Stage stage : stageList) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   111
                    if (stage != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   112
                        log.debug("stage.name: " + stage.getStageName());
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   113
                        log.debug("stage.start target name: " + stage.getStartTarget());
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   114
                        String currentStageTargetName = stageStartTargetMap.get(stage.getStartTarget()
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   115
                            + "-" + hashCode);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   116
                        log.debug("getStageBasedOnEndTarget: currentStargetTargetName" + currentStageTargetName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   117
                        if (currentStageTargetName != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   118
                            log.debug("stage in targetend: " + stage);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   119
                            if (stage != null && getIsInitialized()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   120
                                //initDiamondsClient();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   121
                                String stageName = stage.getStageName();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   122
                                log.debug("stageName in targetend: " + stageName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   123
                                String stageMessage =  stageName + ".id";
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   124
                                sendMessage(stageMessage);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   125
                                Date startTime = getStartTime(stage);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   126
                                getProject().setProperty("logical.stage", stageName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   127
                                getProject().setProperty("stage.start.time", getTimeFormat().format(startTime));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   128
                                getProject().setProperty("stage.end.time", getTimeFormat().format(new Date()));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   129
                                sendMessage("stage.time.message");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   130
                            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   131
                        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   132
                    }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   138
    @SuppressWarnings("unchecked")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   139
    public void targetEnd(BuildEvent buildEvent) throws DiamondsException {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   140
        String targetName = buildEvent.getTarget().getName();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   141
        Project prj = buildEvent.getProject();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   142
        int hashCode = prj.hashCode();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   143
        String targetNameWithHashCode = targetName + "-" + hashCode;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   144
        log.debug("targetEnd: targetNamewith-hashcode: " + targetNameWithHashCode);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   145
        sendStageInfo(targetName, hashCode);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   146
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   147
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   148
    private void findAndSetStartTimeForTargetInStageList(String targetName,
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   149
        String targetNameWithHashCode) throws DiamondsException {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   150
        for (Iterator<Map<String, Date>> listIter = stageTargetBeginList.iterator(); listIter.hasNext();) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
            Map<String, Date> stageMap = listIter.next();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
            Date targetTime = stageMap.get(targetName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
            if (targetTime != null && targetTime.equals(INVALID_DATE)) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   154
                log.debug("diamonds:StageDiamondsListener: started recording for stage-target-----: "
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   155
                    + targetName);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   156
                log.debug("findtime: targetNamewith-hashcode: " + targetNameWithHashCode);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   157
                log.debug("findtime: time: " + new Date());
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
                stageMap.put(targetName, new Date());
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   159
                stageStartTargetMap.put(targetNameWithHashCode, targetName);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   160
                stageStartTargetTimeMap.put(targetNameWithHashCode, new Date());
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
            }
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
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
    @SuppressWarnings("unchecked")
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   166
    private void initStageTargetsMap(Project projectInStage) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   167
        for (String key : stages.keySet()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   168
            Stage stage = stages.get(key);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   169
            String startTargetName = stage.getStartTarget();
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   170
            Map<String, Date> stageMap = new LinkedHashMap<String, Date>();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
            Vector<Target> arrayList = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
            try {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   173
                arrayList = projectInStage.topoSort(startTargetName, projectInStage.getTargets(), false);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   174
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   175
            catch (BuildException be) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
                log.debug("Diamonds target missing: ", be);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
            if (arrayList != null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
                log.debug(" + Stage definition: " + stage.getStageName());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
                Enumeration<Target> targetEnum = arrayList.elements();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
                while (targetEnum.hasMoreElements()) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
                    // fast lookup
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
                    Target target = targetEnum.nextElement();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
                    stageMap.put(target.getName(), INVALID_DATE);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
                    log.debug("   - Start target: " + target.getName());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
                }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
                stageTargetBeginList.add(stageMap);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
                // stage end process
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   190
                String endTargetName = stage.getEndTarget();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
                // fast lookup
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   192
                List<Stage> existingStageList = stageTargetEndMap.get(endTargetName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   193
                if (existingStageList == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   194
                    existingStageList = new ArrayList<Stage>();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   195
                    stageTargetEndMap.put(endTargetName, existingStageList);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   196
                }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   197
                existingStageList.add(stage);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
                log.debug("   - End target: " + endTargetName);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
}