diff --git a/core/src/main/java/hudson/util/IOUtils.java b/core/src/main/java/hudson/util/IOUtils.java index a5275232c8b60f64d204666a950ebae91662875e..475b20f7bc52ae4ed1c20bd82513b7070a758388 100644 --- a/core/src/main/java/hudson/util/IOUtils.java +++ b/core/src/main/java/hudson/util/IOUtils.java @@ -1,11 +1,7 @@ package hudson.util; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; +import java.util.regex.Pattern; /** * Adds more to commons-io. @@ -72,4 +68,30 @@ public class IOUtils extends org.apache.commons.io.IOUtils { size -= in.skip(size); return in; } + + /** + * Resolves the given path with respect to given base. If the path represents an absolute path, a file representing + * it is returned, otherwise a file representing a path relative to base is returned. + *
+ * It would be nice if File#File(File, String) were doing this.
+ * @param base File that represents the parent, may be null if path is absolute
+ * @param path Path of the file, may not be null
+ * @return new File(name) if name represents an absolute path, new File(base, name) otherwise
+ * @see hudson.FilePath#absolutize()
+ */
+ public static File absolutize(File base, String path) {
+ if (isAbsolute(path))
+ return new File(path);
+ return new File(base, path);
+ }
+
+ /**
+ * See {@link hudson.FilePath#isAbsolute(String)}.
+ * @param path String representing Platform Specific
(unlike FilePath, which may get Platform agnostic paths), may not be null
+ * @return true if String represents absolute path on this platform, false otherwise
+ */
+ public static boolean isAbsolute(String path) {
+ Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*");
+ return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches();
+ }
}
diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java
index 46881fb3abe3dfdfa051ed4408d60567a8547a82..2d03edcbab626e11b6a82f11fbd9655efc28250d 100644
--- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java
+++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java
@@ -26,30 +26,30 @@ package hudson.maven;
import hudson.*;
import hudson.model.*;
import hudson.model.Descriptor.FormException;
-import static hudson.model.ItemGroupMixIn.loadChildren;
import hudson.model.Queue;
import hudson.model.Queue.Task;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndexBuilder;
-import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.*;
+import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.junit.JUnitResultArchiver;
-import static hudson.Util.fixEmpty;
import hudson.util.CopyOnWriteMap;
import hudson.util.DescribableList;
-import hudson.util.Function1;
import hudson.util.FormValidation;
+import hudson.util.Function1;
+import net.sf.json.JSONObject;
+import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
-import org.kohsuke.stapler.QueryParameter;
+import org.kohsuke.stapler.export.Exported;
import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.util.*;
-import net.sf.json.JSONObject;
-import org.kohsuke.stapler.export.Exported;
+import static hudson.Util.fixEmpty;
+import static hudson.model.ItemGroupMixIn.loadChildren;
/**
* Group of {@link MavenModule}s.
@@ -198,8 +198,10 @@ public final class MavenModuleSet extends AbstractMavenProject