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 |
package com.nokia.helium.sysdef.ant.taskdefs;
|
|
18 |
|
|
19 |
import java.io.File;
|
|
20 |
import java.io.IOException;
|
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.List;
|
|
23 |
|
|
24 |
import org.apache.tools.ant.BuildException;
|
|
25 |
import org.apache.tools.ant.util.FileUtils;
|
|
26 |
|
|
27 |
import com.nokia.helium.sysdef.ant.types.Filter;
|
|
28 |
import com.nokia.helium.sysdef.ant.types.FilterSet;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* <p>This task allows to do the filtering operation on system definition file v3.0.</p>
|
|
32 |
*
|
|
33 |
* <p>The following example shows how you can join the X:\layer.sysdef.xml under
|
|
34 |
* X:\filtered_layer.sysdef.xml.</p>
|
|
35 |
*
|
|
36 |
* E.g:
|
|
37 |
* <pre>
|
|
38 |
* <hlm:filterSysdef epocroot="X:\" srcfile="X:\layer.sysdef.xml"
|
|
39 |
* destfile="X:\filtered_layer.sysdef.xml">
|
|
40 |
* <filterset>
|
|
41 |
* <filter filter="test" type="has" />
|
|
42 |
* </filterset>
|
|
43 |
* </hlm:filterSysdef>
|
|
44 |
* </pre>
|
|
45 |
*
|
|
46 |
* For more information about system definition file v3.0 please check
|
|
47 |
* <a href="http://developer.symbian.org/wiki/index.php/System_Definition">http://developer.symbian.org/wiki/index.php/System_Definition</a>.
|
|
48 |
*
|
628
|
49 |
* <br>
|
|
50 |
* This task relies on externals tools. Their location can be configured the following ways:
|
|
51 |
* <li>by configuring the sysdef.tools.home property, fails if the location is incorrect.
|
|
52 |
* <li>The parent folder of the joinsysdef tool from the PATH, fallback on SDK location.
|
|
53 |
* <li>Default SDK location.
|
|
54 |
*
|
588
|
55 |
* @ant.task name="filterSysdef" category="Sysdef"
|
|
56 |
*/
|
|
57 |
public class FilterTask extends AbstractSydefTask {
|
628
|
58 |
private static final String XSLT = "filtering.xsl";
|
588
|
59 |
private List<FilterSet> filterSets = new ArrayList<FilterSet>();
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Create a FilterSet object to store filters.
|
|
63 |
* @return a new FilterSet object
|
|
64 |
*/
|
|
65 |
public FilterSet createFilterSet() {
|
|
66 |
FilterSet filterset = new FilterSet();
|
|
67 |
filterSets.add(filterset);
|
|
68 |
return filterset;
|
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Add a FilterSet object.
|
|
73 |
*/
|
|
74 |
public void add(FilterSet filterset) {
|
|
75 |
filterSets.add(filterset);
|
|
76 |
}
|
|
77 |
|
|
78 |
/**
|
|
79 |
* {@inheritDoc}
|
|
80 |
*/
|
|
81 |
public void execute() {
|
|
82 |
check();
|
|
83 |
if (filterSets.isEmpty()) {
|
|
84 |
throw new BuildException("You must define at least one nested filterset element.");
|
|
85 |
}
|
|
86 |
log("Filtering " + this.getSrcFile());
|
|
87 |
for (FilterSet filterSet : filterSets) {
|
|
88 |
if (filterSet.isReference()) {
|
628
|
89 |
try {
|
|
90 |
filterSet = (FilterSet)filterSet.getRefid().getReferencedObject();
|
|
91 |
} catch (ClassCastException ex) {
|
|
92 |
throw new BuildException("Object referenced by '" + filterSet.getRefid().getRefId() + "' is not a sysdefFilterSet.", ex);
|
|
93 |
}
|
588
|
94 |
}
|
|
95 |
List<File> toDelete = new ArrayList<File>();
|
|
96 |
try {
|
|
97 |
File src = this.getSrcFile();
|
|
98 |
File dst = null;
|
|
99 |
for (Filter filter : filterSet.getFilters()) {
|
628
|
100 |
|
|
101 |
// validating parameter first.
|
|
102 |
filter.validate();
|
|
103 |
|
|
104 |
// Then filter the file
|
588
|
105 |
dst = File.createTempFile("sysdef", ".xml", this.getEpocroot());
|
|
106 |
toDelete.add(dst);
|
628
|
107 |
filter.filter(this, src, dst);
|
|
108 |
|
588
|
109 |
// Dest is the input for next loop.
|
|
110 |
src = dst;
|
|
111 |
}
|
|
112 |
if (dst != null) {
|
|
113 |
log("Creating " + this.getDestFile());
|
|
114 |
FileUtils.getFileUtils().copyFile(dst, getDestFile());
|
|
115 |
} else {
|
|
116 |
// If nothing to do it is just identity,
|
|
117 |
// so copying the source file
|
|
118 |
log("Creating " + this.getDestFile());
|
|
119 |
FileUtils.getFileUtils().copyFile(getSrcFile(), getDestFile());
|
|
120 |
}
|
|
121 |
} catch (IOException e) {
|
|
122 |
throw new BuildException(e.getMessage(), e);
|
|
123 |
} finally {
|
|
124 |
for (File file : toDelete) {
|
|
125 |
file.delete();
|
|
126 |
}
|
|
127 |
}
|
|
128 |
}
|
|
129 |
}
|
|
130 |
|
|
131 |
/**
|
|
132 |
* {@inheritDoc}
|
|
133 |
*/
|
|
134 |
@Override
|
628
|
135 |
protected File getXsl() {
|
|
136 |
return new File(SysdefUtils.getSysdefHome(getProject(), this.getEpocroot()), XSLT);
|
588
|
137 |
}
|
|
138 |
} |