588
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.metadata.ant.types;
|
|
19 |
|
628
|
20 |
import java.io.BufferedReader;
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FileNotFoundException;
|
|
23 |
import java.io.FileReader;
|
|
24 |
import java.io.IOException;
|
|
25 |
import java.util.ArrayList;
|
|
26 |
import java.util.List;
|
|
27 |
import java.util.Map;
|
|
28 |
import java.util.regex.Matcher;
|
|
29 |
import java.util.regex.Pattern;
|
588
|
30 |
|
628
|
31 |
import javax.persistence.EntityManager;
|
|
32 |
import javax.persistence.EntityManagerFactory;
|
|
33 |
|
|
34 |
import org.apache.tools.ant.Project;
|
|
35 |
|
|
36 |
import com.nokia.helium.metadata.MetadataException;
|
|
37 |
import com.nokia.helium.metadata.model.metadata.Component;
|
|
38 |
import com.nokia.helium.metadata.model.metadata.LogFile;
|
|
39 |
import com.nokia.helium.metadata.model.metadata.MetadataEntry;
|
|
40 |
import com.nokia.helium.metadata.model.metadata.Severity;
|
|
41 |
import com.nokia.helium.metadata.model.metadata.SeverityDAO;
|
|
42 |
|
588
|
43 |
|
|
44 |
/**
|
|
45 |
* This Type is to specify and use the abld logparser type to parse and store
|
|
46 |
* the data.
|
|
47 |
*
|
|
48 |
* <pre>
|
|
49 |
* <hlm:metadatafilterset id="abld.metadata.filter">
|
|
50 |
* <metadatafilterset filterfile="common.csv" />
|
|
51 |
* </hlm:metadatafilterset>
|
|
52 |
*
|
|
53 |
* <hlm:imakermetadatainput>
|
|
54 |
* <fileset dir="${project.dir}/../data/">
|
|
55 |
* <include name="*_compile*.log"/>
|
|
56 |
* </fileset>
|
|
57 |
* <metadatafilterset refid="abld.metadata.filter" />
|
|
58 |
* </hlm:imakermetadatainput>
|
|
59 |
* </pre>
|
|
60 |
*
|
|
61 |
* @ant.task name="imakermetadatainput" category="Metadata"
|
|
62 |
*/
|
628
|
63 |
public class IMakerLogMetaDataInput extends AbstractComponentBaseMetadataInput {
|
|
64 |
public static final String DEFAULT_COMPONENT_NAME = "General";
|
|
65 |
private Pattern iMakerFpsxPattern = Pattern.compile("/([^/]*?\\.fpsx)");
|
|
66 |
private EntityManager entityManager;
|
588
|
67 |
|
628
|
68 |
/**
|
|
69 |
* {@inheritDoc}
|
|
70 |
*/
|
|
71 |
@Override
|
|
72 |
public void extract(EntityManagerFactory factory, File file)
|
|
73 |
throws MetadataException {
|
|
74 |
entityManager = factory.createEntityManager();
|
|
75 |
List<MetadataEntry> entries = new ArrayList<MetadataEntry>();
|
|
76 |
String currentComponent = null;
|
|
77 |
try {
|
|
78 |
// Creating the filename
|
|
79 |
LogFile logFile = getLogFile(entityManager, file);
|
588
|
80 |
|
628
|
81 |
// Loading the available priorities
|
|
82 |
SeverityDAO severityDao = new SeverityDAO();
|
|
83 |
severityDao.setEntityManager(entityManager);
|
|
84 |
Map<String, Severity> priorities = severityDao.getSeverities();
|
|
85 |
|
|
86 |
// Parsing the log file
|
|
87 |
BufferedReader reader = new BufferedReader(new FileReader(file));
|
|
88 |
String line = null;
|
|
89 |
int lineNumber = 0;
|
|
90 |
while ((line = reader.readLine()) != null) {
|
|
91 |
lineNumber++;
|
|
92 |
Matcher matcher = iMakerFpsxPattern.matcher(line);
|
|
93 |
if (matcher.find()) {
|
|
94 |
currentComponent = matcher.group(1);
|
|
95 |
log("Matched component: " + currentComponent, Project.MSG_DEBUG);
|
|
96 |
}
|
|
97 |
if (line.startsWith("++ Started at")) {
|
|
98 |
currentComponent = null;
|
|
99 |
} else if (line.startsWith("++ Finished at")) {
|
|
100 |
if (currentComponent == null) {
|
|
101 |
currentComponent = DEFAULT_COMPONENT_NAME;
|
|
102 |
}
|
|
103 |
Component component = getComponent(currentComponent, logFile);
|
|
104 |
entityManager.getTransaction().begin();
|
|
105 |
for (MetadataEntry entry : entries) {
|
|
106 |
entry.setComponent(component);
|
|
107 |
entityManager.persist(entry);
|
|
108 |
}
|
|
109 |
entityManager.getTransaction().commit();
|
|
110 |
entityManager.clear();
|
|
111 |
entries.clear();
|
|
112 |
} else {
|
|
113 |
SeverityEnum.Severity severity = getSeverity(line);
|
|
114 |
if (severity != SeverityEnum.Severity.NONE) {
|
|
115 |
MetadataEntry entry = new MetadataEntry();
|
|
116 |
entry.setLogFile(logFile);
|
|
117 |
entry.setLineNumber(lineNumber);
|
|
118 |
entry.setSeverity(priorities.get(severity.toString()));
|
|
119 |
entry.setText(line);
|
|
120 |
entries.add(entry);
|
|
121 |
}
|
|
122 |
}
|
|
123 |
}
|
|
124 |
reader.close();
|
|
125 |
} catch (FileNotFoundException ex) {
|
|
126 |
throw new MetadataException(ex.getMessage(), ex);
|
|
127 |
} catch (IOException ex) {
|
|
128 |
throw new MetadataException(ex.getMessage(), ex);
|
|
129 |
} finally {
|
|
130 |
if (entityManager != null) {
|
|
131 |
entityManager.close();
|
|
132 |
}
|
|
133 |
clear();
|
588
|
134 |
}
|
628
|
135 |
|
588
|
136 |
}
|
|
137 |
|
|
138 |
/**
|
628
|
139 |
* {@inheritDoc}
|
588
|
140 |
*/
|
628
|
141 |
@Override
|
|
142 |
protected EntityManager getEntityManager() {
|
|
143 |
return entityManager;
|
|
144 |
}
|
588
|
145 |
|
|
146 |
}
|