001: package org.andromda.maven.plugin.distribution;
002:
003: import java.io.File;
004: import java.util.ArrayList;
005: import java.util.List;
006:
007: import org.apache.maven.plugin.MojoExecutionException;
008: import org.codehaus.plexus.util.DirectoryScanner;
009:
010: /**
011: * Represents a location which represents a location that can have
012: * values included/excluded.
013: *
014: * @author Chad Brandon
015: */
016: public class Location {
017: /**
018: * The patterns to exclude.
019: */
020: private String[] excludes;
021:
022: /**
023: * @param excludes The excludes to set.
024: */
025: public void setExcludes(String[] excludes) {
026: this .excludes = excludes;
027: }
028:
029: /**
030: * The patterns to include.
031: */
032: private String[] includes;
033:
034: /**
035: * @param includes The includes to set.
036: */
037: public void setIncludes(String[] includes) {
038: this .includes = includes;
039: }
040:
041: /**
042: * The path to which output should be generated.
043: */
044: private String outputPath;
045:
046: /**
047: * Sets the output path.
048: *
049: * @param outputPath The outputPath to set.
050: */
051: public void setOutputPath(String outputPath) {
052: this .outputPath = outputPath;
053: }
054:
055: /**
056: * Retrieves the path to which output of this location should be written.
057: *
058: * @return the output path.
059: */
060: public String getOuputPath() {
061: return this .outputPath;
062: }
063:
064: /**
065: * The path to the location.
066: */
067: private String path;
068:
069: /**
070: * Sets the path of the location.
071: *
072: * @param path The path to set.
073: */
074: public void setPath(String path) {
075: this .path = path;
076: }
077:
078: /**
079: * Retrieves the complete file given the <code>relativePath</code>.
080: *
081: * @return the location's path.
082: */
083: public File getFile(final String relativePath) {
084: File file;
085: final File filePath = new File(this .path);
086: if (filePath.isFile()) {
087: file = filePath;
088: } else {
089: file = new File(this .path, relativePath);
090: }
091: return file;
092: }
093:
094: /**
095: * Retrieves all the paths found in this location.
096: *
097: * @return all poms found.
098: * @throws MojoExecutionException
099: */
100: public List getPaths() {
101: final DirectoryScanner scanner = new DirectoryScanner();
102: final File filePath = new File(this .path);
103: final List paths = new ArrayList();
104: if (filePath.isDirectory()) {
105: scanner.setBasedir(this .path);
106: scanner.setIncludes(this .includes);
107: scanner.setExcludes(this .excludes);
108: scanner.scan();
109:
110: final String[] files = scanner.getIncludedFiles();
111: for (int ctr = 0; ctr < files.length; ctr++) {
112: paths.add(files[ctr]);
113: }
114: } else if (filePath.isFile()) {
115: paths.add(this.path);
116: }
117: return paths;
118: }
119: }
|