buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/ant/taskdefs/MetaDataLogCountTask.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:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     1
/*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     3
 * All rights reserved.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     8
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    11
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    12
 * Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    13
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    14
 * Description:  
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    15
 *
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    16
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    17
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    18
package com.nokia.helium.metadata.ant.taskdefs;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    19
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    20
import java.io.File;
628
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.List;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    23
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    24
import org.apache.tools.ant.BuildException;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    25
import org.apache.tools.ant.Project;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    26
import org.apache.tools.ant.Task;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    27
import org.apache.tools.ant.types.ResourceCollection;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    28
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    29
import com.nokia.helium.metadata.MetadataException;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    30
import com.nokia.helium.metadata.ant.conditions.MetaDataLogCondition;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    31
import com.nokia.helium.metadata.ant.types.SeverityEnum;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    32
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    33
/**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    34
 * This class sets a property to the number of matching severity inside a Metadata db for a log.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    35
 * Example:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    36
 * <pre>
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    37
 *     &lt;hlm:metadataCountSeverity severity=&quot;error&quot; 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    38
 *                                   log=&quot;${compile.log.dir}/${build.id}_fixslashes_raptor.log&quot; 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    39
 *                                   database=&quot;${build.log.dir}/metadata_db&quot; 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    40
 *                                   property=&quot;fixslashes.error&quot; /&gt;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    41
 * </pre>
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    42
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    43
 * @ant.task name="metadataCountSeverity" category="Metadata"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    44
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    45
public class MetaDataLogCountTask extends Task {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    46
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    47
    private File database;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    48
    private File log;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    49
    private SeverityEnum severity;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    50
    private String property;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    51
    private List<ResourceCollection> resourceCollections = new ArrayList<ResourceCollection>();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    52
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    53
    public void add(ResourceCollection resourceCollection) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    54
        resourceCollections.add(resourceCollection);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    55
    }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    56
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    57
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    58
     * Location of the database.
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    59
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    60
     * @param filename
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    61
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    62
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    63
    @Deprecated
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    64
    public void setDb(File database) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    65
        log("The usage of the db attribute is deprecated, please use the database attribute instead.", Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    66
        this.database = database;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    67
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    68
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    69
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    70
     * Location of the database.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    71
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    72
     * @param filename
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    73
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    74
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    75
    public void setDatabase(File database) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    76
        this.database = database;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    77
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    78
    
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    79
    public void setLog(File log) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    80
        this.log = log;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    81
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    82
    
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    83
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    84
     * Defines the severity name to be counted.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    85
     * 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    86
     * @param severity
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    87
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    88
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    89
    public void setSeverity(SeverityEnum severity) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    90
        this.severity = severity;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    91
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    92
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    93
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    94
     * Name of the property to be set.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    95
     * @param property the property name
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    96
     * @ant.required
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    97
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    98
    public void setProperty(String property) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    99
        this.property = property;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   100
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   101
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   102
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   103
     * Should the count of missing files for error severity.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   104
     * @param countMissing enable the count of missing files 
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   105
     *                     for error severity
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   106
     * @ant.not-required Default is true
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   107
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   108
    @Deprecated
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   109
    public void setCountMissing(boolean countMissing) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   110
        // not active anymore
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   111
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   112
    
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   113
    /**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   114
     *  Execute the task. Set the property with number of severities.  
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   115
     * @throws BuildException
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   116
     */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   117
    public void execute() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   118
        if (property == null) {
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   119
            throw new BuildException("'property' attribute is not defined");
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   120
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   121
        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   122
            MetaDataLogCondition cond = new MetaDataLogCondition();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   123
            cond.setProject(getProject());
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   124
            cond.setDatabase(database);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   125
            cond.setLog(log);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   126
            cond.setSeverity(severity);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   127
            for (ResourceCollection rc : resourceCollections) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   128
                cond.add(rc);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   129
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   130
            getProject().setNewProperty(property, "" + cond.getSeverity());
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   131
        } catch (MetadataException ex) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   132
            throw new BuildException(ex.getMessage(), ex);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   133
        }
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   134
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
   135
}