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.taskdefs;
|
|
19 |
|
628
|
20 |
import java.io.File;
|
|
21 |
import java.util.Date;
|
|
22 |
import java.util.Vector;
|
|
23 |
|
|
24 |
import javax.persistence.EntityManagerFactory;
|
|
25 |
|
588
|
26 |
import org.apache.tools.ant.BuildException;
|
628
|
27 |
import org.apache.tools.ant.Project;
|
588
|
28 |
import org.apache.tools.ant.Task;
|
628
|
29 |
|
|
30 |
import com.nokia.helium.metadata.FactoryManager;
|
|
31 |
import com.nokia.helium.metadata.MetaDataInput;
|
|
32 |
import com.nokia.helium.metadata.MetadataException;
|
588
|
33 |
|
|
34 |
/**
|
|
35 |
* This task provide a way to record the data in the Database.
|
|
36 |
*
|
|
37 |
* <pre>
|
|
38 |
* Example 1:
|
|
39 |
* <metadatarecord database="compile_log.db">
|
|
40 |
* <sbsmetadatainput>
|
|
41 |
* <fileset casesensitive="false" file="sbs.log.file"/>
|
|
42 |
* <metadatafiltelistref refid="compilation"/>
|
|
43 |
* </sbsmetadatainput>
|
|
44 |
* </metadatarecord>
|
|
45 |
*
|
|
46 |
* Example 2:
|
|
47 |
*
|
|
48 |
* <metadatarecord database="metadata.db">
|
|
49 |
* <antmetadatainput>
|
|
50 |
* <fileset casesensitive="false" file="${build.id}_ant_build.log"/>
|
|
51 |
* <metadatafiltelistref refid="compilation"/>
|
|
52 |
* </antmetadatainput>
|
|
53 |
* </metadatarecord>
|
|
54 |
|
|
55 |
* </pre>
|
|
56 |
*
|
|
57 |
* @ant.task name="metadatarecord" category="Metadata"
|
|
58 |
*/
|
|
59 |
public class MetaDataRecordTask extends Task {
|
|
60 |
|
628
|
61 |
private File database;
|
588
|
62 |
|
|
63 |
private boolean failOnError = true;
|
|
64 |
|
628
|
65 |
private Vector<MetaDataInput> metaDataInputs = new Vector<MetaDataInput>();
|
588
|
66 |
|
|
67 |
/**
|
|
68 |
* Helper function to set the database parameter
|
|
69 |
*
|
|
70 |
* @ant.required
|
|
71 |
*/
|
628
|
72 |
public void setDatabase(File database) {
|
|
73 |
this.database = database;
|
588
|
74 |
}
|
|
75 |
|
628
|
76 |
/**
|
|
77 |
* Defines if the task should fail on error.
|
|
78 |
* @param failOnError
|
|
79 |
* @ant.not-required Default is true.
|
|
80 |
*/
|
|
81 |
public void setFailOnError(boolean failOnError) {
|
|
82 |
this.failOnError = failOnError;
|
588
|
83 |
}
|
628
|
84 |
|
588
|
85 |
/**
|
|
86 |
* Helper function to get the database
|
|
87 |
*
|
|
88 |
*/
|
628
|
89 |
public File getDatabase() {
|
588
|
90 |
return database;
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Helper function to return the metadatalist
|
|
95 |
* @return build metadata object
|
|
96 |
*
|
|
97 |
*/
|
628
|
98 |
public Vector<MetaDataInput> getMetaDataList() throws MetadataException {
|
|
99 |
if (metaDataInputs.isEmpty()) {
|
|
100 |
throw new MetadataException("metadata list is empty");
|
588
|
101 |
}
|
628
|
102 |
return metaDataInputs;
|
588
|
103 |
}
|
|
104 |
|
|
105 |
/**
|
|
106 |
* Helper function to add the metadatalist
|
|
107 |
* @param build metadata list to add
|
|
108 |
*
|
|
109 |
*/
|
628
|
110 |
public void add(MetaDataInput metaDataInput) {
|
|
111 |
metaDataInputs.add(metaDataInput);
|
588
|
112 |
}
|
|
113 |
|
628
|
114 |
/**
|
|
115 |
* {@inheritDoc}
|
|
116 |
*/
|
588
|
117 |
@Override
|
|
118 |
public void execute() {
|
628
|
119 |
if (database == null) {
|
|
120 |
throw new BuildException("'database' attribute is not defined.");
|
|
121 |
}
|
|
122 |
EntityManagerFactory factory = null;
|
588
|
123 |
try {
|
628
|
124 |
factory = FactoryManager.getFactoryManager().getEntityManagerFactory(database);
|
588
|
125 |
Date before = new Date();
|
|
126 |
log("Time before recording to db: " + before);
|
628
|
127 |
for (MetaDataInput metadataInput : metaDataInputs) {
|
|
128 |
metadataInput.extract(this, factory);
|
588
|
129 |
}
|
|
130 |
Date after = new Date();
|
|
131 |
log("Time after recording to db: " + after);
|
|
132 |
log("Elapsed time: " + (after.getTime() - before.getTime()) + " ms");
|
628
|
133 |
} catch (MetadataException ex) {
|
|
134 |
log(ex.getMessage(), Project.MSG_ERR);
|
588
|
135 |
if (failOnError) {
|
628
|
136 |
throw new BuildException(ex.getMessage(), ex);
|
588
|
137 |
}
|
|
138 |
} finally {
|
628
|
139 |
if (factory != null) {
|
|
140 |
factory.close();
|
588
|
141 |
}
|
628
|
142 |
factory = null;
|
588
|
143 |
}
|
|
144 |
}
|
|
145 |
} |