buildframework/helium/sf/java/diamonds/src/com/nokia/helium/diamonds/DiamondsPostBuildStatusUpdate.java
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
     1 /*
     1 /*
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5  * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description: To update the build status to Diamonds with signals in case of build exceptions.
    14  * Description: To update the build status to Diamonds with signals in case of build exceptions.
    15 *
    15  *
    16 */
    16  */
    17  
    17 
    18 package com.nokia.helium.diamonds;
    18 package com.nokia.helium.diamonds;
    19 
    19 
       
    20 import org.apache.log4j.Logger;
       
    21 import org.apache.tools.ant.types.DataType;
    20 import org.apache.tools.ant.Project;
    22 import org.apache.tools.ant.Project;
    21 import com.nokia.helium.core.ant.types.*;
    23 import com.nokia.helium.core.ant.PostBuildAction;
    22 import com.nokia.helium.core.PropertiesSource;
       
    23 import com.nokia.helium.core.TemplateInputSource;
       
    24 import com.nokia.helium.core.TemplateProcessor;
       
    25 
       
    26 import org.apache.log4j.Logger;
       
    27 
       
    28 import java.util.List;
       
    29 import java.io.File;
       
    30 import java.util.ArrayList;
       
    31 import java.util.Properties;
       
    32 
       
    33 
    24 
    34 /**
    25 /**
    35  * Class to store the builds status and send the generated XML file to diamonds client class
    26  * Class to store the builds status and send the generated XML file to diamonds client class to
    36  * to update the build status into diamonds
    27  * update the build status into diamonds
    37  */
    28  */
    38 public class DiamondsPostBuildStatusUpdate extends HlmPostDefImpl {
    29 public class DiamondsPostBuildStatusUpdate extends DataType implements PostBuildAction {
    39     private Logger log;
    30     private Logger log;
    40 
    31 
    41     /* Initiate build status to failed as this method will be invoked in case of exceptions only */
    32     /* Initiate build status to failed as this method will be invoked in case of exceptions only */
    42     private String buildStatus = "succeeded";
    33     private String buildStatus = "succeeded";
    43 
    34 
    44     private TemplateProcessor templateProcessor;
    35     private String outputFile, templateFile;
    45 
    36 
    46     private String outputFile,templateFile;
       
    47 
       
    48     private List<TemplateInputSource> sourceList = new ArrayList<TemplateInputSource>();
       
    49 
    37 
    50     public DiamondsPostBuildStatusUpdate() {
    38     public DiamondsPostBuildStatusUpdate() {
    51         log = Logger.getLogger(DiamondsPostBuildStatusUpdate.class);    
    39         log = Logger.getLogger(DiamondsPostBuildStatusUpdate.class);
    52     }
    40     }
    53 
    41 
    54     /**
    42     /**
    55      * Override execute method to update build status to diamonds.
    43      * Override execute method to update build status to diamonds.
       
    44      * 
    56      * @param prj
    45      * @param prj
    57      * @param module
    46      * @param module
    58      * @param targetNames
    47      * @param targetNames
    59      */
    48      */
    60     @SuppressWarnings("unchecked")
    49     @SuppressWarnings("unchecked")
    61     public void execute(Project prj, String module, String[] targetNames) {
    50     public void executeOnPostBuild(Project project, String[] targetNames) {
    62         templateProcessor = new TemplateProcessor();
    51         try {
    63         Properties tempProperties = new Properties();
    52             if (DiamondsListenerImpl.isInitialized()) {
    64 
    53                 Project prj = DiamondsListenerImpl.getProject(); 
    65         /* Intialiaze the diamond properties class to access the diamonds properties */
    54                 prj.setProperty("build.status", buildStatus);
    66         DiamondsProperties diamondsProperties = DiamondsConfig.getDiamondsProperties();
    55                 DiamondsListenerImpl.sendMessage("diamonds-status");
    67 
       
    68         //Check, Is the diamonds listener is initialized?
       
    69         if (DiamondsListenerImpl.isInitialized()) {
       
    70             /* Initialize the diamond client class required to update the information into diamonds. */
       
    71             DiamondsClient diamondsClient = new DiamondsClient(getProject()
       
    72                     .getProperty(diamondsProperties.getProperty("host")),
       
    73                     getProject().getProperty(diamondsProperties
       
    74                             .getProperty("port")), getProject()
       
    75                             .getProperty(diamondsProperties
       
    76                                     .getProperty("path")), getProject()
       
    77                                     .getProperty(diamondsProperties
       
    78                                             .getProperty("mail")));
       
    79             /* Generate the build status XML file required for diamonds to update the build status information,
       
    80              * using templateprocessor class. 
       
    81              */
       
    82             tempProperties.put("build.status", buildStatus);
       
    83             sourceList.add(new PropertiesSource("ant", getProject().getProperties()));
       
    84             sourceList.add(new PropertiesSource("diamonds", tempProperties));
       
    85             outputFile = DiamondsConfig.getOutputDir() + File.separator + "diamonds-status.xml";
       
    86             templateFile = "diamonds_status.xml.ftl";
       
    87             templateProcessor.convertTemplate(DiamondsConfig.getTemplateDir(), templateFile, outputFile, sourceList);
       
    88 
       
    89             /* send the generated XML file for diamonds client to update the build status into Diamonds */
       
    90             log.debug("[DiamondsPostBuildStatusUpdate] => sending data to diamonds ..." + outputFile);
       
    91             diamondsClient.sendData(outputFile, DiamondsConfig.getDiamondsProperties().getDiamondsBuildID());
       
    92             try {
       
    93                 DiamondsListenerImpl.mergeToFullResults(new File(outputFile));
       
    94             } catch (DiamondsException de) {
       
    95                 log.error("Not able to merge into full results XML file " + de.getMessage(), de);
       
    96             }
    56             }
       
    57         } catch (DiamondsException de) {
       
    58             log.error("Not able to merge into full results XML file " + de.getMessage(), de);
    97         }
    59         }
    98     }
    60     }
    99 
    61 
   100 }
    62 }