Skip to content

Commit

Permalink
Remove all the formatting
Browse files Browse the repository at this point in the history
- keep convert groovy view to jelly
- keep use Jenkins.get()
  • Loading branch information
Wadeck committed Oct 31, 2018
1 parent a3bb68f commit 31f0491
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 109 deletions.
105 changes: 45 additions & 60 deletions src/main/java/hudson/tasks/Ant.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class Ant extends Builder {
private final String properties;

@DataBoundConstructor
public Ant(String targets, String antName, String antOpts, String buildFile, String properties) {
public Ant(String targets,String antName, String antOpts, String buildFile, String properties) {
this.targets = targets;
this.antName = antName;
this.antOpts = Util.fixEmptyAndTrim(antOpts);
Expand All @@ -129,10 +129,9 @@ public String getTargets() {
* or null to invoke the default one.
*/
public AntInstallation getAnt() {
for (AntInstallation i : getDescriptor().getInstallations()) {
if (antName != null && antName.equals(i.getName())) {
for( AntInstallation i : getDescriptor().getInstallations() ) {
if(antName!=null && antName.equals(i.getName()))
return i;
}
}
return null;
}
Expand All @@ -145,7 +144,7 @@ public String getAntOpts() {
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
ArgumentListBuilder args = new ArgumentListBuilder();

EnvVars env = build.getEnvironment(listener);
Expand All @@ -161,7 +160,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}

AntInstallation ai = getAnt();
if (ai == null) {
if(ai==null) {
args.add(launcher.isUnix() ? "ant" : "ant.bat");
} else {
Node node = Computer.currentComputer().getNode();
Expand All @@ -171,7 +170,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
ai = ai.forNode(node, listener);
ai = ai.forEnvironment(env);
String exe = ai.getExecutable(launcher);
if (exe == null) {
if (exe==null) {
throw new AbortException(Messages.Ant_ExecutableNotFound(ai.getName()));
}
args.add(exe);
Expand All @@ -183,7 +182,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

FilePath buildFilePath = buildFilePath(build.getModuleRoot(), buildFile, targets);

if (!buildFilePath.exists()) {
if(!buildFilePath.exists()) {
// because of the poor choice of getModuleRoot() with CVS/Subversion, people often get confused
// with where the build file path is relative to. Now it's too late to change this behavior
// due to compatibility issue, but at least we can make this less painful by looking for errors
Expand All @@ -193,62 +192,60 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
FilePath workspaceFilePath = build.getWorkspace();
if (workspaceFilePath != null) {
FilePath buildFilePath2 = buildFilePath(workspaceFilePath, buildFile, targets);
if (buildFilePath2.exists()) {
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);
throw new AbortException("Unable to find build script at "+ buildFilePath);
}
} else {
throw new AbortException("Workspace is not available. Agent may be disconnected.");
}
}

if (buildFile != null) {
if(buildFile!=null) {
args.add("-file", buildFilePath.getName());
}

Set<String> sensitiveVars = build.getSensitiveBuildVariables();

args.addKeyValuePairs("-D", build.getBuildVariables(), sensitiveVars);
args.addKeyValuePairs("-D",build.getBuildVariables(),sensitiveVars);

args.addKeyValuePairsFromPropertyString("-D", properties, vr, sensitiveVars);
args.addKeyValuePairsFromPropertyString("-D",properties,vr,sensitiveVars);

args.addTokenized(targets.replaceAll("[\t\r\n]+", " "));
args.addTokenized(targets.replaceAll("[\t\r\n]+"," "));

if (ai != null) {
if(ai!=null)
ai.buildEnvVars(env);
}
if (antOpts != null) {
env.put("ANT_OPTS", env.expand(antOpts));
}
if (!launcher.isUnix()) {
if(antOpts!=null)
env.put("ANT_OPTS",env.expand(antOpts));

if(!launcher.isUnix()) {
args = toWindowsCommand(args.toWindowsCommand());
}

long startTime = System.currentTimeMillis();
try {
AntConsoleAnnotator aca = new AntConsoleAnnotator(listener.getLogger(), build.getCharset());
AntConsoleAnnotator aca = new AntConsoleAnnotator(listener.getLogger(),build.getCharset());
int r;
try {
r = launcher.launch().cmds(args).envs(env).stdout(aca).pwd(buildFilePath.getParent()).join();
} finally {
aca.forceEol();
}
return r == 0;
return r==0;
} catch (IOException e) {
Util.displayIOException(e, listener);
Util.displayIOException(e,listener);

String errorMessage = Messages.Ant_ExecFailed();
if (ai == null && (System.currentTimeMillis() - startTime) < 1000) {
if (getDescriptor().getInstallations() == null) {
if(ai==null && (System.currentTimeMillis()-startTime)<1000) {
if(getDescriptor().getInstallations()==null)
// looks like the user didn't configure any Ant installation
errorMessage += Messages.Ant_GlobalConfigNeeded();
} else {
else
// There are Ant installations configured but the project didn't pick it
errorMessage += Messages.Ant_ProjectConfigNeeded();
}
}
throw new AbortException(errorMessage);
}
Expand Down Expand Up @@ -293,24 +290,21 @@ protected static ArgumentListBuilder toWindowsCommand(ArgumentListBuilder args)
}

private static FilePath buildFilePath(FilePath base, String buildFile, String targets) {
if (buildFile != null) {
return base.child(buildFile);
}
if(buildFile!=null) return base.child(buildFile);
// some users specify the -f option in the targets field, so take that into account as well.
// see
String[] tokens = Util.tokenize(targets);
for (int i = 0; i < tokens.length - 1; i++) {
for (int i = 0; i<tokens.length-1; i++) {
String a = tokens[i];
if (a.equals("-f") || a.equals("-file") || a.equals("-buildfile")) {
return base.child(tokens[i + 1]);
}
if(a.equals("-f") || a.equals("-file") || a.equals("-buildfile"))
return base.child(tokens[i+1]);
}
return base.child("build.xml");
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
return (DescriptorImpl)super.getDescriptor();
}

@Extension @Symbol("ant")
Expand Down Expand Up @@ -371,14 +365,14 @@ public AntInstallation(String name, String home, List<? extends ToolProperty<?>>
*/
@Deprecated
public AntInstallation(String name, String home) {
this(name, home, Collections.emptyList());
this(name,home,Collections.<ToolProperty<?>>emptyList());
}

private static String launderHome(String home) {
if (home.endsWith("/") || home.endsWith("\\")) {
if(home.endsWith("/") || home.endsWith("\\")) {
// see https://issues.apache.org/bugzilla/show_bug.cgi?id=26947
// Ant doesn't like the trailing slash, especially on Windows
return home.substring(0, home.length() - 1);
return home.substring(0,home.length()-1);
} else {
return home;
}
Expand All @@ -395,7 +389,7 @@ public String getAntHome() {

@Override
public void buildEnvVars(EnvVars env) {
env.put("ANT_HOME", getHome());
env.put("ANT_HOME",getHome());
env.put("PATH+ANT", getHome() + "/bin");
}

Expand Down Expand Up @@ -430,7 +424,7 @@ private static class GetExecutable extends MasterToSlaveCallable<String, IOExcep
* Returns true if the executable exists.
*/
public boolean getExists() throws IOException, InterruptedException {
return getExecutable(new Launcher.LocalLauncher(TaskListener.NULL)) != null;
return getExecutable(new Launcher.LocalLauncher(TaskListener.NULL))!=null;
}

private static final long serialVersionUID = 1L;
Expand All @@ -443,9 +437,8 @@ public AntInstallation forNode(Node node, TaskListener log) throws IOException,
return new AntInstallation(getName(), translateFor(node, log), getProperties().toList());
}

@Extension
@Symbol("ant")
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "https://github.com/jenkinsci/jenkins/pull/2094")
@Extension @Symbol("ant")
@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 @@ -474,22 +467,18 @@ public List<? extends ToolInstaller> getDefaultInstallers() {
*/
public FormValidation doCheckHome(@QueryParameter File value) {
// this can be used to check the existence of a file on the server, so needs to be protected
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER))
return FormValidation.ok();
}

if (value.getPath().equals("")) {
if(value.getPath().equals(""))
return FormValidation.ok();
}

if (!value.isDirectory()) {
if(!value.isDirectory())
return FormValidation.error(Messages.Ant_NotADirectory(value));
}

File antJar = new File(value, "lib/ant.jar");
if (!antJar.exists()) {
File antJar = new File(value,"lib/ant.jar");
if(!antJar.exists())
return FormValidation.error(Messages.Ant_NotAntDirectory(value));
}

return FormValidation.ok();
}
Expand All @@ -500,13 +489,9 @@ public FormValidation doCheckName(@QueryParameter String value) {
}

public static class ConverterImpl extends ToolConverter {
public ConverterImpl(XStream2 xstream) {
super(xstream);
}

@Override
protected String oldHomeField(ToolInstallation obj) {
return ((AntInstallation) obj).antHome;
public ConverterImpl(XStream2 xstream) { super(xstream); }
@Override protected String oldHomeField(ToolInstallation obj) {
return ((AntInstallation)obj).antHome;
}
}
}
Expand All @@ -528,7 +513,7 @@ public String getDisplayName() {

@Override
public boolean isApplicable(Class<? extends ToolInstallation> toolType) {
return toolType == AntInstallation.class;
return toolType==AntInstallation.class;
}
}
}
Expand Down

0 comments on commit 31f0491

Please sign in to comment.