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.ant.data.taskdefs;
|
|
19 |
|
|
20 |
import java.io.File;
|
|
21 |
import java.io.FileWriter;
|
|
22 |
import java.io.IOException;
|
|
23 |
import java.util.ArrayList;
|
|
24 |
import java.util.List;
|
|
25 |
|
|
26 |
import org.apache.tools.ant.BuildException;
|
|
27 |
import org.apache.tools.ant.DirectoryScanner;
|
|
28 |
import org.apache.tools.ant.Project;
|
|
29 |
import org.apache.tools.ant.Task;
|
|
30 |
import org.apache.tools.ant.types.FileSet;
|
|
31 |
import org.apache.tools.ant.types.ResourceCollection;
|
628
|
32 |
|
587
|
33 |
import com.nokia.helium.ant.data.Database;
|
|
34 |
|
|
35 |
/**
|
628
|
36 |
* Reads the current Ant project and/or Ant files and generates a XML file with a summary
|
|
37 |
* of targets, macros and properties.
|
587
|
38 |
*
|
628
|
39 |
* @ant.task name="database" category="Database"
|
587
|
40 |
*/
|
|
41 |
public class DatabaseTask extends Task {
|
628
|
42 |
private static final String DEFAULT_SCOPE = "public";
|
|
43 |
|
587
|
44 |
private File outputFile;
|
628
|
45 |
private String scope = DEFAULT_SCOPE;
|
587
|
46 |
private boolean filesetonly;
|
|
47 |
private List<ResourceCollection> rcs = new ArrayList<ResourceCollection>();
|
|
48 |
|
|
49 |
public DatabaseTask() {
|
|
50 |
setTaskName("database");
|
|
51 |
}
|
|
52 |
|
|
53 |
/**
|
|
54 |
* Add a set of files to copy.
|
|
55 |
*
|
|
56 |
* @param set a set of files to copy.
|
|
57 |
*/
|
|
58 |
public void addFileset(FileSet set) {
|
|
59 |
add(set);
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Add a collection of files to copy.
|
|
64 |
*
|
|
65 |
* @param res a resource collection to copy.
|
|
66 |
* @since Ant 1.7
|
|
67 |
*/
|
|
68 |
public void add(ResourceCollection res) {
|
|
69 |
rcs.add(res);
|
|
70 |
}
|
|
71 |
|
|
72 |
public void setOutput(File outputFile) {
|
|
73 |
this.outputFile = outputFile;
|
|
74 |
}
|
628
|
75 |
|
|
76 |
public void setFilesetOnly(boolean filesetonly) {
|
|
77 |
this.filesetonly = filesetonly;
|
587
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
628
|
81 |
* Defines what level of visibility to display Ant objects at. Default value is "public".
|
587
|
82 |
*
|
|
83 |
* @param scope The visibility level, either public, protected or private.
|
|
84 |
*/
|
|
85 |
public void setScope(String scope) {
|
|
86 |
this.scope = scope;
|
|
87 |
}
|
|
88 |
|
|
89 |
public void execute() {
|
|
90 |
if (outputFile == null) {
|
|
91 |
throw new BuildException("'output' must be defined.");
|
|
92 |
}
|
|
93 |
log("Building Ant project database", Project.MSG_DEBUG);
|
|
94 |
|
|
95 |
// Get additional Ant file paths
|
|
96 |
try {
|
|
97 |
List<String> antFilePaths = new ArrayList<String>();
|
|
98 |
// Only filesets are supported currently
|
|
99 |
for (ResourceCollection rc : rcs) {
|
|
100 |
if (rc instanceof FileSet) {
|
|
101 |
FileSet fs = (FileSet) rc;
|
|
102 |
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
|
103 |
String[] srcFiles = ds.getIncludedFiles();
|
|
104 |
String basedir = ds.getBasedir().getPath();
|
|
105 |
for (int i = 0; i < srcFiles.length; i++) {
|
|
106 |
String fileName = basedir + File.separator + srcFiles[i];
|
|
107 |
antFilePaths.add(fileName);
|
|
108 |
}
|
|
109 |
}
|
|
110 |
}
|
|
111 |
|
|
112 |
// Output the database file
|
|
113 |
Database db;
|
628
|
114 |
if (filesetonly) {
|
587
|
115 |
db = new Database(null);
|
628
|
116 |
}
|
|
117 |
else {
|
587
|
118 |
db = new Database(getProject());
|
628
|
119 |
}
|
587
|
120 |
db.setScopeFilter(scope);
|
|
121 |
db.addAntFilePaths(antFilePaths);
|
|
122 |
FileWriter out = new FileWriter(outputFile);
|
|
123 |
db.toXML(out);
|
|
124 |
out.close();
|
|
125 |
}
|
|
126 |
catch (IOException e) {
|
|
127 |
e.printStackTrace();
|
|
128 |
throw new BuildException("Not able to build the ANT project Database " + e.getMessage());
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|