587
|
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.taskdefs;
|
|
19 |
|
|
20 |
import com.nokia.helium.metadata.CustomMetaDataProvider;
|
|
21 |
import com.nokia.helium.metadata.MetaDataInput;
|
|
22 |
import com.nokia.helium.jpa.entity.metadata.Metadata;
|
|
23 |
import org.apache.tools.ant.BuildException;
|
|
24 |
import org.apache.tools.ant.Task;
|
|
25 |
import java.util.Vector;
|
|
26 |
import java.util.Iterator;
|
|
27 |
import org.apache.log4j.Logger;
|
|
28 |
import com.nokia.helium.metadata.db.*;
|
|
29 |
import java.util.Date;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* This task provide a way to record the data in the Database.
|
|
33 |
*
|
|
34 |
* <pre>
|
|
35 |
* Example 1:
|
|
36 |
* <metadatarecord database="compile_log.db">
|
|
37 |
* <sbsmetadatainput>
|
|
38 |
* <fileset casesensitive="false" file="sbs.log.file"/>
|
|
39 |
* <metadatafiltelistref refid="compilation"/>
|
|
40 |
* </sbsmetadatainput>
|
|
41 |
* </metadatarecord>
|
|
42 |
*
|
|
43 |
* Example 2:
|
|
44 |
*
|
|
45 |
* <metadatarecord database="metadata.db">
|
|
46 |
* <antmetadatainput>
|
|
47 |
* <fileset casesensitive="false" file="${build.id}_ant_build.log"/>
|
|
48 |
* <metadatafiltelistref refid="compilation"/>
|
|
49 |
* </antmetadatainput>
|
|
50 |
* </metadatarecord>
|
|
51 |
|
|
52 |
* </pre>
|
|
53 |
*
|
|
54 |
* @ant.task name="metadatarecord" category="Metadata"
|
|
55 |
*/
|
|
56 |
public class MetaDataRecord extends Task {
|
|
57 |
|
|
58 |
private static Logger log = Logger.getLogger(MetaDataRecord.class);
|
|
59 |
|
|
60 |
private String database;
|
|
61 |
|
|
62 |
private boolean failOnError = true;
|
|
63 |
|
|
64 |
private Vector<MetaDataInput> metadataList = new Vector<MetaDataInput>();
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Helper function to set the database parameter
|
|
68 |
*
|
|
69 |
* @ant.required
|
|
70 |
*/
|
|
71 |
public void setDatabase(String dbFile) {
|
|
72 |
database = dbFile;
|
|
73 |
}
|
|
74 |
|
|
75 |
public void setFailOnError(String failNotify) {
|
|
76 |
if (failNotify.equals("false")) {
|
|
77 |
failOnError = false;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
/**
|
|
81 |
* Helper function to get the database
|
|
82 |
*
|
|
83 |
*/
|
|
84 |
public String getDatabase() {
|
|
85 |
return database;
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Helper function to return the metadatalist
|
|
90 |
* @return build metadata object
|
|
91 |
*
|
|
92 |
*/
|
|
93 |
public Vector<MetaDataInput> getMetaDataList() throws Exception {
|
|
94 |
if (metadataList.isEmpty()) {
|
|
95 |
throw new Exception("metadata list is empty");
|
|
96 |
}
|
|
97 |
return metadataList;
|
|
98 |
}
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Helper function to add the metadatalist
|
|
102 |
* @param build metadata list to add
|
|
103 |
*
|
|
104 |
*/
|
|
105 |
public void add(MetaDataInput interf) {
|
|
106 |
metadataList.add(interf);
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
@Override
|
|
111 |
public void execute() {
|
|
112 |
ORMMetadataDB ormDB = null;
|
|
113 |
try {
|
|
114 |
log.debug("Getting Contents to write to db: " + database);
|
|
115 |
log.debug("Initializing DB: " + database);
|
|
116 |
log.debug("initializing ORM db");
|
|
117 |
ormDB = new ORMMetadataDB(database);
|
|
118 |
log.debug("Parsing the input and writing to DB");
|
|
119 |
Date before = new Date();
|
|
120 |
log("Time before recording to db: " + before);
|
|
121 |
for (MetaDataInput metadataInput : metadataList) {
|
|
122 |
boolean removed = false;
|
|
123 |
String logPath = null;
|
618
|
124 |
String currentLogPath = null;
|
587
|
125 |
Iterator<Metadata.LogEntry> inputIterator = metadataInput.iterator();
|
|
126 |
while (inputIterator.hasNext()) {
|
618
|
127 |
//Todo: better way of log handling, with metadatainput
|
|
128 |
// metadata initialization for each logfile within
|
|
129 |
//metadatainput itself would be better. this is temporary.
|
587
|
130 |
Metadata.LogEntry logEntry = inputIterator.next();
|
618
|
131 |
logPath = logEntry.getLogPath();
|
|
132 |
if (currentLogPath == null) {
|
|
133 |
currentLogPath = logPath;
|
|
134 |
removed = false;
|
|
135 |
} else if (!currentLogPath.equals(logPath)) {
|
|
136 |
finalizeForLogPath(currentLogPath, metadataInput, ormDB);
|
|
137 |
currentLogPath = logPath;
|
|
138 |
removed = false;
|
|
139 |
}
|
|
140 |
if (!removed ) {
|
|
141 |
log.debug("processing for log: " + logPath);
|
587
|
142 |
ormDB.removeEntries(logPath);
|
|
143 |
removed = true;
|
|
144 |
}
|
|
145 |
//initializes the metadata if none exists
|
|
146 |
ormDB.addLogEntry(logEntry);
|
|
147 |
}
|
618
|
148 |
finalizeForLogPath(currentLogPath, metadataInput, ormDB);
|
587
|
149 |
}
|
|
150 |
Date after = new Date();
|
|
151 |
log("Time after recording to db: " + after);
|
|
152 |
log("Elapsed time: " + (after.getTime() - before.getTime()) + " ms");
|
|
153 |
log.debug("Successfully writen to DB");
|
|
154 |
} catch (BuildException ex1) {
|
|
155 |
log.debug("BuildException during writing to db: ", ex1);
|
|
156 |
if (failOnError) {
|
|
157 |
throw ex1;
|
|
158 |
}
|
|
159 |
} finally {
|
|
160 |
if (ormDB != null) {
|
|
161 |
ormDB.finalizeDB();
|
|
162 |
}
|
|
163 |
}
|
|
164 |
}
|
618
|
165 |
|
|
166 |
private void finalizeForLogPath(String currentLogPath,
|
|
167 |
MetaDataInput metadataInput, ORMMetadataDB ormDB) {
|
|
168 |
if (currentLogPath != null) {
|
|
169 |
if (metadataInput instanceof CustomMetaDataProvider) {
|
|
170 |
CustomMetaDataProvider provider =
|
|
171 |
(CustomMetaDataProvider)metadataInput;
|
|
172 |
provider.provide(ormDB, currentLogPath);
|
|
173 |
}
|
|
174 |
ormDB.finalizeMetadata(currentLogPath);
|
|
175 |
}
|
|
176 |
}
|
587
|
177 |
} |