-
Bug
-
Resolution: Fixed
-
Major
-
None
-
All
-
Powered by SuggestiMate
- Create New maven2 Job
- Choose No SCM
- Choose a Maven2 POM that is already available on disk. Specify it as absolute path in text box for pom.
- Build.
Hudson calculates the pom.xml w.r.t. the build workspace even when the pom is specified as an absolute path. The build then fails complaining it can't find the pom.xml.
[JENKINS-7261] Maven2 Project does not respect absolute path to the POM file (rootPOM)
Committed.
[FIXED-JENKINS-7162]
Hudson ignores Maven pom.xml path when it is specified as absolute path.
Provided utility methods for checking whether a path is absolute and
absolutizing a given path (w.r.t. a base).
Provided a unit test case for this scenario (@Bug 7261).
Modified: trunk/hudson/main/core/src/main/java/hudson/util/IOUtils.java
Url: https://hudson.dev.java.net/source/browse/hudson/trunk/hudson/main/core/src/main/java/hudson/util/IOUtils.java?view=diff&rev=34004&p1=trunk/hudson/main/core/src/main/java/hudson/util/IOUtils.java&p2=trunk/hudson/main/core/src/main/java/hudson/util/IOUtils.java&r1=34003&r2=34004
==============================================================================
— trunk/hudson/main/core/src/main/java/hudson/util/IOUtils.java (original)
+++ trunk/hudson/main/core/src/main/java/hudson/util/IOUtils.java 2010-08-21 02:13:15+0000
@@ -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 @@
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.
+ * <p>
+ * 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); + }+
{@link hudson.FilePath#isAbsolute(String)}
+ /**
+ * See.
{ + Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*"); + return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches(); + }
+ * @param path String representing <code> Platform Specific </code> (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)}
Modified: trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java
Url: https://hudson.dev.java.net/source/browse/hudson/trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java?view=diff&rev=34004&p1=trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java&p2=trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java&r1=34003&r2=34004
==============================================================================
— trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java (original)
+++ trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java 2010-08-21 02:13:15+0000
@@ -26,30 +26,30 @@
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 @@
protected void updateTransientActions() {
super.updateTransientActions();
// Fix for ISSUE-1149
- for (MavenModule module: modules.values()) {
- module.updateTransientActions();
+ if (modules!=null)Unknown macro: {+ for (MavenModule module}if(publishers!=null) // this method can be loaded from within the onLoad method, where this might be null
for (BuildStep step : publishers)
Modified: trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
Url: https://hudson.dev.java.net/source/browse/hudson/trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java?view=diff&rev=34004&p1=trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java&p2=trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java&r1=34003&r2=34004
==============================================================================
— trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java (original)
+++ trunk/hudson/main/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java 2010-08-21 02:13:15+0000
@@ -24,55 +24,22 @@
*/
package hudson.maven;
-import hudson.AbortException;
-import hudson.FilePath;
-import hudson.Launcher;
-import hudson.Util;
-import hudson.EnvVars;
-import hudson.scm.ChangeLogSet;
+import hudson.*;
import hudson.FilePath.FileCallable;
import hudson.maven.MavenBuild.ProxyImpl2;
import hudson.maven.reporters.MavenFingerprinter;
import hudson.maven.reporters.MavenMailer;
-import hudson.model.AbstractProject;
-import hudson.model.Action;
-import hudson.model.Build;
-import hudson.model.BuildListener;
-import hudson.model.Environment;
-import hudson.model.Fingerprint;
-import hudson.model.Hudson;
-import hudson.model.ParametersAction;
-import hudson.model.Result;
-import hudson.model.Computer;
-import hudson.model.Run;
-import hudson.model.TaskListener;
+import hudson.model.*;
import hudson.model.Cause.UpstreamCause;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
+import hudson.scm.ChangeLogSet;
import hudson.tasks.BuildWrapper;
import hudson.tasks.MailSender;
import hudson.tasks.Maven.MavenInstallation;
import hudson.util.ArgumentListBuilder;
+import hudson.util.IOUtils;
import hudson.util.StreamTaskListener;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.Serializable;
-import java.io.InterruptedIOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import org.apache.maven.BuildFailureException;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenSession;
@@ -84,6 +51,12 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
+import java.io.*;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import static hudson.model.Result.FAILURE;
/**
@@ -865,16 +838,21 @@
}
public List<PomInfo> invoke(File ws, VirtualChannel channel) throws IOException {
- File pom = new File(ws,rootPOM);
+ File pom;
PrintStream logger = listener.getLogger();
- // choice of module root ('ws' in this method) is somewhat arbitrary
- // when multiple CVS/SVN modules are checked out, so also check
- // the path against the workspace root if that seems like what the user meant (see issue #1293)
- File parentLoc = new File(ws.getParentFile(),rootPOM);
- if(!pom.exists() && parentLoc.exists())
- pom = parentLoc;
+ if (IOUtils.isAbsolute(rootPOM)) { + pom = new File(rootPOM); + }else
{ + // choice of module root ('ws' in this method) is somewhat arbitrary + // when multiple CVS/SVN modules are checked out, so also check + // the path against the workspace root if that seems like what the user meant (see issue #1293) + pom = new File(ws, rootPOM); + File parentLoc = new File(ws.getParentFile(),rootPOM); + if(!pom.exists() && parentLoc.exists()) + pom = parentLoc; + }
if(!pom.exists())
throw new AbortException(Messages.MavenModuleSetBuild_NoSuchPOMFile(pom));
Modified: trunk/hudson/main/test/src/test/java/hudson/maven/MavenProjectTest.java
Url: https://hudson.dev.java.net/source/browse/hudson/trunk/hudson/main/test/src/test/java/hudson/maven/MavenProjectTest.java?view=diff&rev=34004&p1=trunk/hudson/main/test/src/test/java/hudson/maven/MavenProjectTest.java&p2=trunk/hudson/main/test/src/test/java/hudson/maven/MavenProjectTest.java&r1=34003&r2=34004
==============================================================================
— trunk/hudson/main/test/src/test/java/hudson/maven/MavenProjectTest.java (original)
+++ trunk/hudson/main/test/src/test/java/hudson/maven/MavenProjectTest.java 2010-08-21 02:13:15+0000
@@ -25,11 +25,11 @@
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import hudson.tasks.Maven.MavenInstallation;
+import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
-import org.jvnet.hudson.test.Bug;
-import java.io.IOException;
+import java.io.File;
/**
- @author huybrechts
@@ -47,7 +47,7 @@
return createProject("/simple-projects.zip");
}
- private MavenModuleSet createProject(final String scmResource) throws IOException, Exception
Unknown macro: {+ private MavenModuleSet createProject(final String scmResource) throws Exception { MavenModuleSet project = createMavenProject(); MavenInstallation mi = configureDefaultMaven(); project.setScm(new ExtractResourceSCM(getClass().getResource( @@ -132,4 +132,14 @@ assertEquals(1, project.getModule("org.jvnet.hudson.main.test.multimod:moduleA").getBuilds().size()); assertEquals(1, project.getModule("org.jvnet.hudson.main.test.multimod:moduleB").getBuilds().size()); }+ @Bug(7261)+ public void testAbsolutePathPom() throws Exception { + File pom = new File(this.getClass().getResource("test-pom-7162.xml").toURI()); + MavenModuleSet project = createMavenProject(); + MavenInstallation mi = configureDefaultMaven(); + project.setMaven(mi.getName()); + project.setRootPOM(pom.getAbsolutePath()); + project.setGoals("install"); + buildAndAssertSuccess(project); + } }
Added: trunk/hudson/main/test/src/test/resources/hudson/maven/test-pom-7162.xml
Url: https://hudson.dev.java.net/source/browse/hudson/trunk/hudson/main/test/src/test/resources/hudson/maven/test-pom-7162.xml?view=auto&rev=34004
==============================================================================
— (empty file)
+++ trunk/hudson/main/test/src/test/resources/hudson/maven/test-pom-7162.xml 2010-08-21 02:13:15+0000
@@ -0,0 +1,26 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.infradna.support</groupId>
+ <artifactId>query</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>query</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <foo>bar</foo>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
The patch to maven-plugin that respects the rootPOM as absolute path.