提交 b228c24d 编写于 作者: K km

[FIXED-HUDSON-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).



git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34004 71c3de6d-444a-0410-be80-ed276b4c234a
上级 e31629b1
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.
* <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);
}
/**
* See {@link hudson.FilePath#isAbsolute(String)}.
* @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) {
Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*");
return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches();
}
}
......@@ -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<MavenModuleSet,Ma
protected void updateTransientActions() {
super.updateTransientActions();
// Fix for ISSUE-1149
for (MavenModule module: modules.values()) {
module.updateTransientActions();
if (modules!=null) {
for (MavenModule module: modules.values()) {
module.updateTransientActions();
}
}
if(publishers!=null) // this method can be loaded from within the onLoad method, where this might be null
for (BuildStep step : publishers)
......
......@@ -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.apache.maven.project.ProjectBuildingException;
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 class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
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));
......
......@@ -25,11 +25,11 @@ package hudson.maven;
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 @@ public class MavenProjectTest extends HudsonTestCase {
return createProject("/simple-projects.zip");
}
private MavenModuleSet createProject(final String scmResource) throws IOException, Exception {
private MavenModuleSet createProject(final String scmResource) throws Exception {
MavenModuleSet project = createMavenProject();
MavenInstallation mi = configureDefaultMaven();
project.setScm(new ExtractResourceSCM(getClass().getResource(
......@@ -132,4 +132,14 @@ public class MavenProjectTest extends HudsonTestCase {
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);
}
}
<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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册