Skip to content

Commit

Permalink
Merge pull request #118 from darxriggs/improvements
Browse files Browse the repository at this point in the history
Code Improvements
  • Loading branch information
batmat committed Feb 22, 2019
2 parents 6d9d823 + 90502d9 commit e72678d
Show file tree
Hide file tree
Showing 43 changed files with 86 additions and 250 deletions.
Expand Up @@ -63,6 +63,6 @@ public static <E> List<E> selectNodes(final DomNode domNode, final String xpathE
*/
public static <X> X selectSingleNode(final DomNode domNode, final String xpathExpr) {
WebClientUtil.waitForJSExec(domNode.getPage().getWebClient());
return domNode.<X>getFirstByXPath(xpathExpr);
return domNode.getFirstByXPath(xpathExpr);
}
}
5 changes: 0 additions & 5 deletions src/main/java/hudson/model/utils/AbortExceptionPublisher.java
Expand Up @@ -29,10 +29,5 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) { return true; }

@Override // Can be deleted after 1.635
public String getDisplayName() {
return clazz.getSimpleName();
}
}
}
5 changes: 0 additions & 5 deletions src/main/java/hudson/model/utils/IOExceptionPublisher.java
Expand Up @@ -29,10 +29,5 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) { return true; }

@Override // Can be deleted after 1.635
public String getDisplayName() {
return clazz.getSimpleName();
}
}
}
5 changes: 0 additions & 5 deletions src/main/java/hudson/model/utils/ResultWriterPublisher.java
Expand Up @@ -41,10 +41,5 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) { return true; }

@Override // Can be deleted after 1.635
public String getDisplayName() {
return clazz.getSimpleName();
}
}
}
5 changes: 0 additions & 5 deletions src/main/java/hudson/model/utils/TrueFalsePublisher.java
Expand Up @@ -36,10 +36,5 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) { return true; }

@Override // Can be deleted after 1.635
public String getDisplayName() {
return clazz.getSimpleName();
}
}
}
Expand Up @@ -35,7 +35,7 @@
import java.util.UUID;

/**
* Server-side logic that implements {@link HudsonTestCase#executeOnServer(Callable)}.
* Server-side logic that implements {@link HudsonTestCase#executeOnServer(java.util.concurrent.Callable)}.
*
* @author Kohsuke Kawaguchi
*/
Expand Down
Expand Up @@ -55,12 +55,7 @@ public void doConfigSubmit(StaplerRequest req) throws IOException, ServletExcept
public List getConnectorDescriptors() {
return ComputerConnectorDescriptor.all();
}

@Extension
public static class DescriptorImpl extends Descriptor<ComputerConnectorTester> {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "ComputerConnectorTester";
}
}
public static class DescriptorImpl extends Descriptor<ComputerConnectorTester> {}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jvnet/hudson/test/CreateFileBuilder.java
Expand Up @@ -86,7 +86,7 @@ public static final class DescriptorImpl extends Descriptor<Builder> {

@Override
public Builder newInstance(StaplerRequest req, JSONObject data) {
throw new UnsupportedOperationException("This is a temporarytest class, "
throw new UnsupportedOperationException("This is a temporary test class, "
+ "which should not be configured from UI");
}

Expand Down
Expand Up @@ -87,19 +87,15 @@ public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath wo
workspace.unzipFrom(secondZip.openStream());

// Get list of files changed in secondZip.
ZipInputStream zip = new ZipInputStream(secondZip.openStream());
ZipEntry e;
ExtractChangeLogParser.ExtractChangeLogEntry changeLog = new ExtractChangeLogParser.ExtractChangeLogEntry(secondZip.toString());

try {
try (ZipInputStream zip = new ZipInputStream(secondZip.openStream())) {
ZipEntry e;
while ((e = zip.getNextEntry()) != null) {
if (!e.isDirectory())
changeLog.addFile(new ExtractChangeLogParser.FileInZip(e.getName()));
}
}
finally {
zip.close();
}
saveToChangeLog(changeLogFile, changeLog);

return true;
Expand Down Expand Up @@ -142,12 +138,6 @@ public void saveToChangeLog(File changeLogFile, ExtractChangeLogParser.ExtractCh
private Object writeReplace() { return new Object(); }

@Override public SCMDescriptor<?> getDescriptor() {
return new SCMDescriptor<ExtractResourceWithChangesSCM>(ExtractResourceWithChangesSCM.class, null) {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "ExtractResourceWithChangesSCM";
}
};
return new SCMDescriptor<ExtractResourceWithChangesSCM>(ExtractResourceWithChangesSCM.class, null) {};
}

}
5 changes: 0 additions & 5 deletions src/main/java/org/jvnet/hudson/test/FailureBuilder.java
Expand Up @@ -45,10 +45,5 @@ public static final class DescriptorImpl extends Descriptor<Builder> {
public FailureBuilder newInstance(StaplerRequest req, JSONObject data) {
return new FailureBuilder();
}

@Override // TODO 1.635+ delete
public String getDisplayName() {
return "FailureBuilder";
}
}
}
9 changes: 2 additions & 7 deletions src/main/java/org/jvnet/hudson/test/FakeChangeLogSCM.java
Expand Up @@ -79,12 +79,7 @@ public ChangeLogParser createChangeLogParser() {
}

@Override public SCMDescriptor<?> getDescriptor() {
return new SCMDescriptor<SCM>(null) {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "FakeChangeLogSCM";
}
};
return new SCMDescriptor<SCM>(null) {};
}

public static class ChangelogAction extends InvisibleAction {
Expand All @@ -106,7 +101,7 @@ public FakeChangeLogSet parse(Run build, RepositoryBrowser<?> browser, File chan
return new FakeChangeLogSet(build, action.entries);
}
}
return new FakeChangeLogSet(build, Collections.<EntryImpl>emptyList());
return new FakeChangeLogSet(build, Collections.emptyList());
}
}

Expand Down
Expand Up @@ -8,7 +8,6 @@
import hudson.tasks.Builder;
import hudson.Launcher;

import java.util.concurrent.Callable;
import java.io.IOException;

/**
Expand All @@ -22,16 +21,11 @@ public abstract class GroovyHudsonTestCase extends HudsonTestCase {
/**
* Executes the given closure on the server, in the context of an HTTP request.
* This is useful for testing some methods that require {@link StaplerRequest} and {@link StaplerResponse}.
*
* <p>
* The closure will get the request and response as parameters.
*/
public Object executeOnServer(final Closure c) throws Exception {
return executeOnServer(new Callable<Object>() {
public Object call() throws Exception {
return c.call();
}
});
return executeOnServer(c::call);
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java
Expand Up @@ -30,7 +30,6 @@
import hudson.model.BuildListener;
import hudson.tasks.Builder;
import java.io.IOException;
import java.util.concurrent.Callable;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

Expand All @@ -43,16 +42,11 @@ public class GroovyJenkinsRule extends JenkinsRule {
/**
* Executes the given closure on the server, in the context of an HTTP request.
* This is useful for testing some methods that require {@link StaplerRequest} and {@link StaplerResponse}.
*
* <p>
* The closure will get the request and response as parameters.
*/
public Object executeOnServer(final Closure c) throws Exception {
return executeOnServer(new Callable<Object>() {
@Override public Object call() throws Exception {
return c.call();
}
});
return executeOnServer(c::call);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jvnet/hudson/test/HudsonPageCreator.java
Expand Up @@ -28,10 +28,8 @@
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.PageCreator;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;

/**
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
Expand Up @@ -66,7 +66,6 @@
import hudson.slaves.ComputerLauncher;
import hudson.slaves.ComputerListener;
import hudson.slaves.DumbSlave;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
Expand Down Expand Up @@ -118,7 +117,6 @@
import net.sf.json.JSONObject;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory.Listener;

import org.acegisecurity.AuthenticationException;
import org.acegisecurity.BadCredentialsException;
Expand Down Expand Up @@ -649,7 +647,7 @@ public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws
synchronized (jenkins) {
DumbSlave slave = new DumbSlave(nodeName, "dummy",
createTmpDir().getPath(), "1", Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env),
RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList());
RetentionStrategy.NOOP, Collections.emptyList());
jenkins.addNode(slave);
return slave;
}
Expand Down Expand Up @@ -682,15 +680,15 @@ public ComputerLauncher createComputerLauncher(EnvVars env) throws URISyntaxExce
}

/**
* Create a new slave on the local host and wait for it to come onilne
* Create a new slave on the local host and wait for it to come online
* before returning.
*/
public DumbSlave createOnlineSlave() throws Exception {
return createOnlineSlave(null);
}

/**
* Create a new slave on the local host and wait for it to come onilne
* Create a new slave on the local host and wait for it to come online
* before returning.
*/
public DumbSlave createOnlineSlave(Label l) throws Exception {
Expand Down Expand Up @@ -1006,8 +1004,8 @@ public Object call() throws Exception {
* a cancellation.
*/
private List<String> listProperties(String properties) {
List<String> props = new ArrayList<String>(Arrays.asList(properties.split(",")));
for (String p : props.toArray(new String[props.size()])) {
List<String> props = new CopyOnWriteArrayList<>(properties.split(","));
for (String p : props) {
if (p.startsWith("-")) {
props.remove(p);
props.remove(p.substring(1));
Expand All @@ -1026,7 +1024,7 @@ public HtmlPage submit(HtmlForm form) throws Exception {
}

/**
* Submits the form by clikcing the submit button of the given name.
* Submits the form by clicking the submit button of the given name.
*
* @param name
* This corresponds to the @name of {@code <f:submit />}
Expand Down Expand Up @@ -1446,7 +1444,7 @@ public void contextReleased(Context cx) {

setAlertHandler(new AlertHandler() {
public void handleAlert(Page page, String message) {
throw new AssertionError("Alert dialog poped up: "+message);
throw new AssertionError("Alert dialog popped up: "+message);
}
});

Expand Down Expand Up @@ -1762,7 +1760,7 @@ public boolean isLoggable(LogRecord record) {

private static final Logger LOGGER = Logger.getLogger(HudsonTestCase.class.getName());

protected static final List<ToolProperty<?>> NO_PROPERTIES = Collections.<ToolProperty<?>>emptyList();
protected static final List<ToolProperty<?>> NO_PROPERTIES = Collections.emptyList();

/**
* Specify this to a TCP/IP port number to have slaves started with the debugger.
Expand Down Expand Up @@ -1817,11 +1815,6 @@ public boolean isApplicable(AbstractProject<?, ?> project) {
public BuildWrapper newInstance(StaplerRequest req, JSONObject formData) {
throw new UnsupportedOperationException();
}

@Override // TODO 1.635+ delete
public String getDisplayName() {
return "TestBuildWrapper";
}
}
}
}
Expand Up @@ -56,12 +56,7 @@ public void doConfigSubmit(StaplerRequest req) throws IOException, ServletExcept
public List getConnectorDescriptors() {
return ComputerConnectorDescriptor.all();
}

@Extension
public static class DescriptorImpl extends Descriptor<JenkinsComputerConnectorTester> {
@Override // TODO 1.635+ delete
public String getDisplayName() {
return "JenkinsComputerConnectorTester";
}
}
public static class DescriptorImpl extends Descriptor<JenkinsComputerConnectorTester> {}
}
4 changes: 1 addition & 3 deletions src/main/java/org/jvnet/hudson/test/JenkinsMatchers.java
Expand Up @@ -56,9 +56,7 @@ public boolean matches(Object o) {
}
t = t.getCause();
}
} catch (InstantiationException e) {
// ignore
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException e) {
// ignore
} finally {
c.setAccessible(accessible);
Expand Down

0 comments on commit e72678d

Please sign in to comment.