Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #16 from armfergom/JENKINS-34623
  • Loading branch information
armfergom committed May 9, 2016
2 parents 982e9cf + 9f6c00a commit 7dd836b
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 80 deletions.
40 changes: 33 additions & 7 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.532.1</version>
<version>2.7</version>
</parent>

<artifactId>ant</artifactId>
Expand All @@ -25,6 +25,32 @@
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
</scm>

<properties>
<jenkins.version>1.596.1</jenkins.version>
<java.level>6</java.level>
</properties>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness-tools</artifactId>
<version>2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
Expand All @@ -40,10 +66,10 @@
</license>
</licenses>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
47 changes: 29 additions & 18 deletions src/main/java/hudson/tasks/Ant.java
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.tasks;

import hudson.AbortException;
import hudson.CopyOnWrite;
import hudson.EnvVars;
import hudson.Extension;
Expand All @@ -36,9 +37,9 @@
import hudson.model.Computer;
import hudson.model.EnvironmentSpecific;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.slaves.NodeSpecific;
import hudson.tasks._ant.Messages;
import hudson.tasks._ant.AntConsoleAnnotator;
Expand All @@ -51,14 +52,16 @@
import hudson.util.VariableResolver;
import hudson.util.FormValidation;
import hudson.util.XStream2;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.QueryParameter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;
import java.util.List;
import java.util.Collections;
Expand Down Expand Up @@ -148,12 +151,15 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
if(ai==null) {
args.add(launcher.isUnix() ? "ant" : "ant.bat");
} else {
ai = ai.forNode(Computer.currentComputer().getNode(), listener);
Node node = Computer.currentComputer().getNode();
if (node == null) {
throw new AbortException(Messages.Ant_NodeOffline());
}
ai = ai.forNode(node, listener);
ai = ai.forEnvironment(env);
String exe = ai.getExecutable(launcher);
if (exe==null) {
listener.fatalError(Messages.Ant_ExecutableNotFound(ai.getName()));
return false;
throw new AbortException(Messages.Ant_ExecutableNotFound(ai.getName()));
}
args.add(exe);
}
Expand All @@ -171,14 +177,18 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
// and diagnosing it nicely. See HUDSON-1782

// first check if this appears to be a valid relative path from workspace root
FilePath buildFilePath2 = buildFilePath(build.getWorkspace(), buildFile, targets);
if(buildFilePath2.exists()) {
// This must be what the user meant. Let it continue.
buildFilePath = buildFilePath2;
FilePath workspaceFilePath = build.getWorkspace();
if (workspaceFilePath != null) {
FilePath buildFilePath2 = buildFilePath(workspaceFilePath, buildFile, targets);
if(buildFilePath2.exists()) {
// This must be what the user meant. Let it continue.
buildFilePath = buildFilePath2;
} else {
// neither file exists. So this now really does look like an error.
throw new AbortException("Unable to find build script at "+ buildFilePath);
}
} else {
// neither file exists. So this now really does look like an error.
listener.fatalError("Unable to find build script at "+buildFilePath);
return false;
throw new AbortException("Workspace is not available. Agent may be disconnected.");
}
}

Expand Down Expand Up @@ -231,8 +241,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
// There are Ant installations configured but the project didn't pick it
errorMessage += Messages.Ant_ProjectConfigNeeded();
}
e.printStackTrace( listener.fatalError(errorMessage) );
return false;
throw new AbortException(errorMessage);
}
}

Expand Down Expand Up @@ -283,7 +292,7 @@ public String getDisplayName() {
}

public AntInstallation[] getInstallations() {
return installations;
return Arrays.copyOf(installations, installations.length);
}

public void setInstallations(AntInstallation... antInstallations) {
Expand Down Expand Up @@ -341,7 +350,8 @@ public void buildEnvVars(EnvVars env) {
* Gets the executable path of this Ant on the given target system.
*/
public String getExecutable(Launcher launcher) throws IOException, InterruptedException {
return launcher.getChannel().call(new Callable<String,IOException>() {
return launcher.getChannel().call(new MasterToSlaveCallable<String,IOException>() {
private static final long serialVersionUID = 906341330603832653L;
public String call() throws IOException {
File exe = getExeFile();
if(exe.exists())
Expand Down Expand Up @@ -376,6 +386,7 @@ public AntInstallation forNode(Node node, TaskListener log) throws IOException,
}

@Extension
@SuppressFBWarnings(value="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification="https://github.com/jenkinsci/jenkins/pull/2094")
public static class DescriptorImpl extends ToolDescriptor<AntInstallation> {

@Override
Expand Down Expand Up @@ -445,7 +456,7 @@ public AntInstaller(String id) {
@Extension
public static final class DescriptorImpl extends DownloadFromUrlInstaller.DescriptorImpl<AntInstaller> {
public String getDisplayName() {
return Messages.InstallFromApache();
return Messages.Ant_InstallFromApache();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/tasks/_ant/AntConsoleAnnotator.java
Expand Up @@ -34,7 +34,7 @@
* Filter {@link OutputStream} that places an annotation that marks Ant target execution.
*
* @author Kohsuke Kawaguchi
* @sine 1.349
* @since 1.349
*/
public class AntConsoleAnnotator extends LineTransformationOutputStream {
private final OutputStream out;
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/hudson/tasks/_ant/AntTargetNote.java
Expand Up @@ -31,9 +31,13 @@

import java.util.regex.Pattern;

import com.google.common.annotations.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Marks the log line "TARGET:" that Ant uses to mark the beginning of the new target.
* @sine 1.349
* @since 1.349
*/
public final class AntTargetNote extends ConsoleNote {
public AntTargetNote() {
Expand All @@ -57,5 +61,7 @@ public String getDisplayName() {
}
}

@VisibleForTesting
@SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="Visible for testing")
public static boolean ENABLED = !Boolean.getBoolean(AntTargetNote.class.getName()+".disabled");
}
3 changes: 2 additions & 1 deletion src/main/resources/hudson/tasks/_ant/Messages.properties
Expand Up @@ -23,9 +23,10 @@
Ant.DisplayName=Invoke Ant
Ant.ExecFailed=command execution failed.
Ant.ExecutableNotFound=Cannot find executable from the chosen Ant installation "{0}"
Ant.NodeOffline=Cannot get installation for node, since it is not online
Ant.GlobalConfigNeeded= Maybe you need to configure where your Ant installations are?
Ant.NotADirectory={0} is not a directory
Ant.NotAntDirectory={0} doesn''t look like an Ant directory
Ant.ProjectConfigNeeded= Maybe you need to configure the job to choose one of your Ant installations?

InstallFromApache=Install from Apache
Ant.InstallFromApache=Install from Apache
Expand Up @@ -22,7 +22,7 @@

Ant.NotADirectory={0} er ikke et direktorie
Ant.GlobalConfigNeeded=M\u00e5ske mangler du at konfigurere hvor dine Ant installationer er?
InstallFromApache=Installer fra Apache
Ant.InstallFromApache=Installer fra Apache
Ant.ProjectConfigNeeded=M\u00e5ske mangler du at konfigurere jobbet til at v\u00e6lge en af dine Ant installationer?
Ant.NotAntDirectory={0} ligner ikke et Ant direktorie
Ant.ExecFailed=Kommandoeksekvering fejlede
Expand Down
Expand Up @@ -28,4 +28,4 @@ Ant.NotADirectory={0} ist kein Verzeichnis
Ant.NotAntDirectory={0} sieht nicht wie ein Ant-Verzeichnis aus.
Ant.ProjectConfigNeeded=Eventuell müssen Sie für den Job noch eine Ihrer Ant-Installationen auswählen.

InstallFromApache=Installiere von Apache
Ant.InstallFromApache=Installiere von Apache
3 changes: 2 additions & 1 deletion src/main/resources/hudson/tasks/_ant/Messages_es.properties
Expand Up @@ -23,9 +23,10 @@
Ant.DisplayName=Ejecutar Ant
Ant.ExecFailed=Falló la ejecución del comando
Ant.ExecutableNotFound=No se encuentra el archivo ejecutable para la instalación de ant seleccionada "{0}"
Ant.NodeOffline=No se puede generar la instalación de Ant para el nodo actual ya que este no se encuentra disponible.
Ant.GlobalConfigNeeded= Posiblemente tengas que configurar dónde se encuentra tu instalación de ''ant''
Ant.NotADirectory={0} no es un directorio
Ant.NotAntDirectory={0} no parece un directorio de ''ant''
Ant.ProjectConfigNeeded= Es posible que tengas que configurar la tarea para que utilice una de tus instalaciones de ''ant''

InstallFromApache=Instalar desde Apache
Ant.InstallFromApache=Instalar desde Apache
Expand Up @@ -28,4 +28,4 @@ Ant.NotADirectory={0}\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u306f\u304
Ant.NotAntDirectory={0}\u306b\u306fAnt\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u3088\u3046\u3067\u3059
Ant.ProjectConfigNeeded=\u3069\u306eAnt\u3092\u4f7f\u3046\u304b\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u306f\uff1f

InstallFromApache=Apache\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb
Ant.InstallFromApache=Apache\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb
Expand Up @@ -28,4 +28,4 @@ Ant.NotAntDirectory={0} n\u00e3o parece ser um diret\u00f3rio Ant
Ant.ProjectConfigNeeded= Talvez voc\u00ea precise configurar a tarefa para escolher uma de suas instala\u00e7\u00f5es do Ant.

# Install from Apache
InstallFromApache=Instalar a partir do Apache
Ant.InstallFromApache=Instalar a partir do Apache
Expand Up @@ -28,4 +28,4 @@ Ant.NotADirectory={0} \u4e0d\u662f\u76ee\u9304
Ant.NotAntDirectory={0} \u4e0d\u50cf\u662f Ant \u76ee\u9304
Ant.ProjectConfigNeeded= \u4e5f\u8a31\u60a8\u8a72\u8a2d\u5b9a\u4f5c\u696d\uff0c\u7531\u5b89\u88dd\u7684 Ant \u4e2d\u6311\u4e00\u500b?

InstallFromApache=\u5f9e Apache \u5b89\u88dd
Ant.InstallFromApache=\u5f9e Apache \u5b89\u88dd

0 comments on commit 7dd836b

Please sign in to comment.