Skip to content

Commit

Permalink
Minor code cleanup (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSpieker committed Jan 20, 2021
1 parent b8a14f0 commit 9ab9ae0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package hudson.scm;

import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;

import jenkins.scm.impl.subversion.RemotableSVNErrorMessage;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/hudson/scm/SubversionChangeLogSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import jenkins.triggers.SCMTriggerItem;

import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -373,13 +375,13 @@ public boolean equals(Object o) {
if (revision != that.revision) {
return false;
}
if (author != null ? !author.equals(that.author) : that.author != null) {
if (!Objects.equals(author, that.author)) {
return false;
}
if (date != null ? !date.equals(that.date) : that.date != null) {
if (!Objects.equals(date, that.date)) {
return false;
}
if (msg != null ? !msg.equals(that.msg) : that.msg != null) {
if (!Objects.equals(msg, that.msg)) {
return false;
}

Expand Down
33 changes: 24 additions & 9 deletions src/main/java/hudson/scm/SubversionSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,30 @@
import hudson.Launcher;
import hudson.Util;
import hudson.init.InitMilestone;
import hudson.model.*;

import java.io.ByteArrayOutputStream;
import java.nio.charset.UnsupportedCharsetException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.WeakHashMap;

import hudson.model.AbstractBuild;
import hudson.model.AbstractDescribableImpl;
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Item;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.ModelObject;
import hudson.model.Node;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.util.ListBoxModel;
Expand Down Expand Up @@ -112,18 +123,23 @@
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -917,8 +933,7 @@ private Map<String, List<External>> checkout(Run build, FilePath workspace, Task
for (ModuleLocation location : getLocations(env, build)) {
CheckOutTask checkOutTask =
new CheckOutTask(build, this, location, build.getTimestamp().getTime(), listener, env, quietOperation);
List<External> externals = new ArrayList<>();
externals.addAll(workspace.act(checkOutTask));
List<External> externals = new ArrayList<>(workspace.act(checkOutTask));
// save location <---> externals maps
externalsMap.put(location.remote, externals);
unauthenticatedRealms.addAll(checkOutTask.getUnauthenticatedRealms());
Expand Down Expand Up @@ -1475,7 +1490,7 @@ static final class SVNLogHandler implements ISVNLogEntryHandler, Serializable {
private SVNLogFilter filter;

SVNLogHandler(SVNLogFilter svnLogFilter, TaskListener listener) {
this.filter = svnLogFilter;;
this.filter = svnLogFilter;
this.filter.setTaskListener(listener);
}

Expand Down Expand Up @@ -3368,7 +3383,7 @@ public boolean equals(Object o) {
if (!realm.equals(that.realm)) {
return false;
}
if (credentialsId != null ? !credentialsId.equals(that.credentialsId) : that.credentialsId != null) {
if (!Objects.equals(credentialsId, that.credentialsId)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;

import java.util.Objects;

/**
* This class represents the actual {@link ParameterValue} for the
* {@link ListSubversionTagsParameterDefinition} parameter.
Expand Down Expand Up @@ -73,10 +75,8 @@ public boolean equals(Object o) {

ListSubversionTagsParameterValue that = (ListSubversionTagsParameterValue) o;

if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false;
if (tagsDir != null ? !tagsDir.equals(that.tagsDir) : that.tagsDir != null) return false;

return true;
if (!Objects.equals(tag, that.tag)) return false;
return Objects.equals(tagsDir, that.tagsDir);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/scm/DefaultSVNLogFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static boolean containsRevs(List<SVNLogEntry> logs, long ... revs) {
public void noExcludes() throws Exception {

DefaultSVNLogFilter filter = new DefaultSVNLogFilter(noPatterns, noPatterns, noUsers, null, noPatterns, false);
assertTrue(!filter.hasExclusionRule());
assertFalse(filter.hasExclusionRule());

List<SVNLogEntry> entries = doFilter(filter);
assertTrue(containsRevs(entries, 1, 2, 3, 4, 5));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/scm/SubversionSCMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ public void ignoreExternals() throws Exception {
assertTrue(ws.child("with_externals").child("externals").child("projb").exists());

// Check that the external doesn't exist
assertTrue(!(ws.child("no_externals").child("externals").child("projb").exists()));
assertFalse(ws.child("no_externals").child("externals").child("projb").exists());
} finally {
p.kill();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void lastModified_Smokes() throws Exception {
long oneMinute = 60*1000;
sampleRepo.write("file", "modified");
sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc());
try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"), revision);) {
try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"), revision)) {
long lastModified = fs.lastModified();
//ensure the timestamp is from after we started but not in the distant future
assertThat(lastModified, greaterThanOrEqualTo(currentTime));
Expand Down Expand Up @@ -156,7 +156,7 @@ public void mixedContent() throws Exception {
sampleRepo.svnkit("add", sampleRepo.wc() + "/dir");
sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc());
SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl());
try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"));) {
try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"))) {
assertThat(fs, notNullValue());
assertThat(fs.getRoot(), notNullValue());
Iterable<SCMFile> children = fs.getRoot().children();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package jenkins.scm.impl.subversion;

import jenkins.scm.impl.subversion.SubversionSCMSource;
import org.junit.Test;

import java.util.Arrays;
Expand All @@ -20,7 +19,7 @@
public class SubversionSCMSourceTest {

@Test
public void isMatch() throws Exception {
public void isMatch() {
assertThat(SubversionSCMSource.isMatch("trunk", "trunk"), is(true));
assertThat(SubversionSCMSource.isMatch("trunk", "trunk*"), is(true));
assertThat(SubversionSCMSource.isMatch("trunk", "*trunk"), is(true));
Expand All @@ -32,17 +31,17 @@ public void isMatch() throws Exception {
}

@Test
public void splitCludes() throws Exception {
public void splitCludes() {
assertThat(SubversionSCMSource.splitCludes("trunk"),
is((SortedSet) new TreeSet<>(Arrays.asList("trunk"))));
is(new TreeSet<>(Collections.singletonList("trunk"))));
assertThat(SubversionSCMSource.splitCludes("trunk,branches/*"),
is((SortedSet) new TreeSet<>(Arrays.asList("trunk", "branches/*"))));
is(new TreeSet<>(Arrays.asList("trunk", "branches/*"))));
assertThat(SubversionSCMSource.splitCludes("trunk, branches/*"),
is((SortedSet) new TreeSet<>(Arrays.asList("trunk", "branches/*"))));
is(new TreeSet<>(Arrays.asList("trunk", "branches/*"))));
assertThat(SubversionSCMSource.splitCludes("trunk , , branches/*"),
is((SortedSet) new TreeSet<>(Arrays.asList("trunk", "branches/*"))));
is(new TreeSet<>(Arrays.asList("trunk", "branches/*"))));
assertThat(SubversionSCMSource.splitCludes("trunk , , branches/* , tags/* "),
is((SortedSet) new TreeSet<>(Arrays.asList("trunk", "branches/*", "tags/*"))));
is(new TreeSet<>(Arrays.asList("trunk", "branches/*", "tags/*"))));
}

private static List<String> list(String... values) {
Expand All @@ -56,7 +55,7 @@ private static SortedSet<List<String>> pathSet(List<String>... paths) {
}

@Test
public void toPaths() throws Exception {
public void toPaths() {
assertThat(SubversionSCMSource.toPaths(SubversionSCMSource.splitCludes("trunk")), is(pathSet(list("trunk"))));
assertThat(SubversionSCMSource.toPaths(SubversionSCMSource.splitCludes("trunk,branches/*")), is(pathSet(
list("trunk"), list("branches", "*")
Expand All @@ -69,7 +68,7 @@ public void toPaths() throws Exception {
}

@Test
public void filterPaths() throws Exception {
public void filterPaths() {
assertThat(SubversionSCMSource
.filterPaths(pathSet(list("trunk"), list("branches", "foo"), list("branches", "bar")),
list("trunk")),
Expand All @@ -81,7 +80,7 @@ public void filterPaths() throws Exception {
}

@Test
public void groupPaths() throws Exception {
public void groupPaths() {
SortedMap<List<String>, SortedSet<List<String>>> result;
SortedSet<List<String>> data = pathSet(
list("trunk"),
Expand Down Expand Up @@ -135,7 +134,7 @@ public void groupPaths() throws Exception {
}

@Test
public void startsWith() throws Exception {
public void startsWith() {
assertThat(SubversionSCMSource.startsWith(list(), list()), is(true));
assertThat(SubversionSCMSource.startsWith(list("a", "b", "c"), list()), is(true));
assertThat(SubversionSCMSource.startsWith(list("a", "b", "c"), list("a")), is(true));
Expand All @@ -148,7 +147,7 @@ public void startsWith() throws Exception {
}

@Test
public void wildcardStartsWith() throws Exception {
public void wildcardStartsWith() {
assertThat(SubversionSCMSource.wildcardStartsWith(list(), list()), is(true));
assertThat(SubversionSCMSource.wildcardStartsWith(list("a", "b", "c"), list()), is(true));
assertThat(SubversionSCMSource.wildcardStartsWith(list("a", "b", "c"), list("a")), is(true));
Expand Down

0 comments on commit 9ab9ae0

Please sign in to comment.