Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java diff -u /dev/null maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java:1.1 --- /dev/null Sat Jan 5 13:02:27 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/core/SourceEntry.java Sat Jan 5 13:02:22 2008 @@ -0,0 +1,119 @@ +/* +* \#\#% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* \#\#% */ +package org.codelutin.i18n.plugin.core; + +import org.codehaus.plexus.util.DirectoryScanner; + +import java.io.File; +import java.util.Arrays; + +/** + * A simple model for a sourceEntry represents by a basedir and includes and/or exlucdes pattern. + *
+ * The class offers the usefull method : + * {@link #getIncludedFiles(File, String[])} + * + * to obtain the list of files from + * the {@link #basedir} directory which respects the {@link #includes} and/or + * {@link #excludes} patterns using an internal {@link DirectoryScanner} object. + * + * Note : The class does not extendsDirectoryScanner since we DO not want
+ * to expose his methods.
+ *
+ * @author tony
+ */
+public class SourceEntry {
+
+ protected File basedir;
+
+ protected String[] includes;
+
+ protected String[] excludes;
+
+ public String[] getExcludes() {
+ return excludes;
+ }
+
+ public void setExcludes(String[] excludes) {
+ this.excludes = excludes;
+ }
+
+ public String[] getIncludes() {
+ return includes;
+ }
+
+ public void setIncludes(String[] includes) {
+ this.includes = includes;
+ }
+
+ public File getBasedir() {
+ return basedir;
+ }
+
+ public void setBasedir(File basedir) {
+ this.basedir = basedir;
+ }
+
+ public boolean hasSrc() {
+ return basedir != null;
+ }
+
+ public boolean hasIncludes() {
+ return includes != null && includes.length > 0;
+ }
+
+ public boolean hasExcludes() {
+ return excludes != null && excludes.length > 0;
+ }
+
+ public String[] getIncludedFiles(File defaultBasedir, String[] defaultIncludes) {
+ // normalized entry
+ if (!hasSrc()) {
+ setBasedir(defaultBasedir);
+ }
+ if (!hasIncludes()) {
+ setIncludes(defaultIncludes);
+ }
+ // init directory scanner
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir(getBasedir());
+ ds.setIncludes(getIncludes());
+ if (hasExcludes()) {
+ ds.setExcludes(getExcludes());
+ }
+ // scan
+ ds.scan();
+ // get found files
+ String[] foundFiles;
+ foundFiles = ds.getIncludedFiles();
+ return foundFiles;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("basedir:").append(basedir);
+ if (includes != null) {
+ sb.append(", includes:").append(Arrays.toString(includes));
+ }
+ if (excludes != null) {
+ sb.append(", excludes:").append(Arrays.toString(excludes));
+ }
+ return sb.toString();
+ }
+}