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 |
|
|
19 |
package com.nokia.helium.signal.ant.types;
|
|
20 |
|
|
21 |
|
|
22 |
import java.io.File;
|
628
|
23 |
import java.util.ArrayList;
|
587
|
24 |
import java.util.List;
|
|
25 |
import java.util.Vector;
|
628
|
26 |
|
|
27 |
import org.apache.log4j.Logger;
|
|
28 |
import org.apache.tools.ant.DirectoryScanner;
|
587
|
29 |
import org.apache.tools.ant.types.DataType;
|
|
30 |
import org.apache.tools.ant.types.FileSet;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Helper class to store the signal notifier info.
|
|
34 |
*/
|
|
35 |
public class NotifierInput extends DataType
|
|
36 |
{
|
|
37 |
|
|
38 |
private File file;
|
|
39 |
|
|
40 |
//Different notifier could choose specific file
|
|
41 |
private String pattern = ".html";
|
|
42 |
|
|
43 |
private Vector<FileSet> fileSetList = new Vector<FileSet>();
|
|
44 |
|
|
45 |
private Logger log = Logger.getLogger(this.getClass());
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Adds the fileset (list of input log files to be processed).
|
|
49 |
* @param fileSet fileset to be added
|
|
50 |
*
|
|
51 |
*/
|
|
52 |
public void add(FileSet fileSet) {
|
|
53 |
fileSetList.add(fileSet);
|
|
54 |
}
|
|
55 |
|
|
56 |
public File getFile() {
|
|
57 |
return getFile(pattern);
|
|
58 |
}
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Return a file from the input fileset.
|
|
62 |
* @param pattern pattern to match from the input fileset
|
|
63 |
* @return the matched files including the base dir.
|
|
64 |
*/
|
|
65 |
public File getFile(String pattern) {
|
|
66 |
File fileToReturn = null;
|
|
67 |
if (file != null) {
|
|
68 |
if (file.toString().matches(pattern)) {
|
|
69 |
fileToReturn = file;
|
|
70 |
}
|
|
71 |
return fileToReturn;
|
|
72 |
}
|
|
73 |
for (FileSet fs : fileSetList) {
|
|
74 |
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
|
75 |
String[] includedFiles = ds.getIncludedFiles();
|
|
76 |
for ( String filePath : includedFiles ) {
|
|
77 |
if (filePath.matches(pattern)) {
|
|
78 |
fileToReturn = new File(ds.getBasedir(), filePath);
|
|
79 |
log.debug("matched file for pattern: " + pattern + ":" + fileToReturn);
|
|
80 |
break;
|
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
return fileToReturn;
|
|
85 |
}
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Returns the list of filelist from the input fileset.
|
|
89 |
* @param pattern pattern to match from the input fileset
|
|
90 |
* @return the matched files including the base dir.
|
|
91 |
*/
|
|
92 |
public List<File> getFileList(String pattern) {
|
|
93 |
List<File> fileList = new ArrayList<File>();
|
|
94 |
for (FileSet fs : fileSetList) {
|
|
95 |
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
|
96 |
String[] includedFiles = ds.getIncludedFiles();
|
|
97 |
for ( String filePath : includedFiles ) {
|
|
98 |
if (filePath.matches(pattern)) {
|
|
99 |
fileList.add(new File(ds.getBasedir(), filePath));
|
|
100 |
}
|
|
101 |
}
|
|
102 |
}
|
|
103 |
return fileList;
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Helper function called by ant to set the input file.
|
|
108 |
* @param inputFile input file for notifier
|
|
109 |
*/
|
|
110 |
public void setFile(File inputFile) {
|
|
111 |
file = inputFile;
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Helper function called by ant to get the file
|
|
116 |
* @return the input file for notifier.
|
|
117 |
*/
|
|
118 |
public String getPattern() {
|
|
119 |
return pattern ;
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* Helper function called by ant to get the file
|
|
124 |
* @return the input file for notifier.
|
|
125 |
*/
|
|
126 |
public void setPattern(String ptn) {
|
|
127 |
pattern = ptn;
|
|
128 |
}
|
|
129 |
} |