buildframework/helium/sf/java/metadata/src/com/nokia/helium/metadata/ant/conditions/MetaDataLogCondition.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
 * All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
 * Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
 * Description:  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.helium.metadata.ant.conditions;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
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.Date;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    23
import java.util.Iterator;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    24
import java.util.List;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    25
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    26
import javax.persistence.EntityManager;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    27
import javax.persistence.EntityManagerFactory;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    28
import javax.persistence.Query;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    29
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import org.apache.tools.ant.BuildException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import org.apache.tools.ant.Project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
import org.apache.tools.ant.taskdefs.condition.Condition;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import org.apache.tools.ant.types.DataType;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    34
import org.apache.tools.ant.types.Resource;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    35
import org.apache.tools.ant.types.ResourceCollection;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    36
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    37
import com.nokia.helium.metadata.FactoryManager;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    38
import com.nokia.helium.metadata.MetadataException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    39
import com.nokia.helium.metadata.ant.types.SeverityEnum;
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
 * This class implements a Ant Condition which report true if it finds any
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
 * matching severity inside a database for an XML log.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
 * Example:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
 * <pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
 * &lt;target name=&quot;fail-on-build-error&quot;&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
 *   &lt;fail message=&quot;The build contains errors&quot;&gt;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    49
 *     &lt;hlm:metadataHasSeverity log=&quot;my.log&quot; database=&quot;my.db&quot; severity=&quot;error&quot;/&gt;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
 *   &lt;/fail&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
 * &lt;/target&gt;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
 * </pre>
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
 * The condition will eval as true if the my.db contains error stored for my.log file.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
 * @ant.type name="metadataHasSeverity" category="Metadata"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
public class MetaDataLogCondition extends DataType implements Condition {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    // The severity to count
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    61
    private SeverityEnum severity;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    62
    private File log;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    63
    private File database;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    64
    private List<ResourceCollection> resourceCollections = new ArrayList<ResourceCollection>();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    67
     * Defines which severity will be counted.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
     * @param severity
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
     * @ant.required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    72
    public void setSeverity(SeverityEnum severity) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        this.severity = severity;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    76
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    77
     * Defines the database to use.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    78
     * @param database
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    79
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    80
    @Deprecated
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    81
    public void setDb(File database) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    82
        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
    83
        setDatabase(database);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    84
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    85
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    86
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    87
     * Defines the database to use.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    88
     * @param database
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    89
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    90
    public void setDatabase(File database) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    91
        this.database = database;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
    
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    94
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    95
     * The log file to look severity for in the metadata. 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    96
     * @param log the actual real log file.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    97
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    98
    public void setLog(File log) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    99
        this.log = log;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   102
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   103
     * Defines if missing file shall be counted (Deprecated attribute is ignored).
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   104
     * @param countMissing
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   105
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   106
    @Deprecated
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
    public void setCountMissing(boolean countMissing) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   108
        log("The usage of the 'countMissing' attribute is deprecated.", Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   109
        //this.countMissing = countMissing;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   110
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   111
    
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   112
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   113
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   114
     * @param resourceCollection
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   115
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   116
    public void add(ResourceCollection resourceCollection) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   117
        resourceCollections.add(resourceCollection);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   118
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   119
    
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   120
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   121
     * Get the severity for a specific log file.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   122
     * @param file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   123
     * @return
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   124
     * @throws MetadataException
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   125
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   126
    public int getSeverity(EntityManager em, File file) throws MetadataException {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   127
        // log file under the DB is always represented with / and not \.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   128
        String queryString = "select Count(m.id) from MetadataEntry m JOIN  m.logFile as l " +
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   129
                        "JOIN m.severity as p where l.path='" +
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   130
                        file.getAbsolutePath().replace('\\', '/') +
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   131
                        "' and p.severity='" + severity.getSeverity() + "'";
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   132
        log("Query: " + queryString, Project.MSG_DEBUG);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   133
        Query query = em.createQuery(queryString);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   134
        Number number = (Number)query.getSingleResult();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   135
        log("Result: " + number, Project.MSG_DEBUG);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   136
        return number.intValue();        
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
     * Get the number of a particular severity.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
     * @return the number of a particular severity.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   144
    @SuppressWarnings("unchecked")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   145
    public int getSeverity() throws MetadataException {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   146
        if (log == null && resourceCollections.isEmpty()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   147
            throw new BuildException("'log' attribute not defined.");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   149
        if (database == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   150
            throw new BuildException("'database' attribute not defined.");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   151
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   152
        if (log != null && !log.exists()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   153
            log("Could not find " + log + ".", Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   154
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   155
        if (severity == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   156
            throw new BuildException("'severity' attribute is not defined.");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   157
        }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   159
        EntityManagerFactory factory = null;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   160
        EntityManager em = null;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   161
        int result = 0;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   162
        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   163
            factory = FactoryManager.getFactoryManager().getEntityManagerFactory(database);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   164
            em = factory.createEntityManager();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   165
            Date before = new Date();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   166
            if (!resourceCollections.isEmpty()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   167
                for (ResourceCollection rc : resourceCollections) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   168
                    Iterator<Resource> ri = rc.iterator();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   169
                    while (ri.hasNext()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   170
                        Resource resource = ri.next();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   171
                        log("Looking for severity '" + severity.getValue() + "' under '" + resource + "'");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   172
                        result += getSeverity(em, new File(resource.toString()));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   173
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   174
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   175
            } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   176
                log("Looking for severity '" + severity.getValue() + "' under '" + log.getAbsolutePath() + "'");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   177
                result = getSeverity(em, log);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   178
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   179
            Date after = new Date();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   180
            log("Elapsed time: " + (after.getTime() - before.getTime()) + " ms");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   181
        } finally {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   182
            if (em != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   183
                em.close();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   184
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   185
            if (factory != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   186
                factory.close();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   187
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
        }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   189
        return result;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
     * This method open the defined file and count the number of message tags
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
     * with their severity attribute matching the configured one.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
     * @return if true if message with the defined severity have been found.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
    public boolean eval() {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   199
        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   200
            int severity = getSeverity();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   201
            if (severity < 0) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   202
                return false;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   203
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   204
            return severity > 0;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   205
        } catch (MetadataException ex) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   206
            throw new BuildException(ex.getMessage(), ex);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
}