Skip to content

Commit

Permalink
Merge pull request #140 from basil/guava
Browse files Browse the repository at this point in the history
[JENKINS-65988] Remove usages of Guava
  • Loading branch information
ikedam authored Aug 28, 2021
2 parents 9fedd7e + f740bc1 commit 772adda
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import com.thoughtworks.xstream.XStreamException;
import jenkins.model.Jenkins;
Expand All @@ -44,10 +45,6 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;

/**
* @author Alan Harder
*/
Expand Down Expand Up @@ -150,14 +147,9 @@ public List<Descriptor<BuildSelector>> getAvailableBuildSelectorList() {
if (jenkins == null) {
return Collections.emptyList();
}
return Lists.newArrayList(Collections2.filter(
jenkins.getDescriptorList(BuildSelector.class),
new Predicate<Descriptor<BuildSelector>>() {
public boolean apply(Descriptor<BuildSelector> input) {
return !"ParameterizedBuildSelector".equals(input.clazz.getSimpleName());
};
}
));
return jenkins.getDescriptorList(BuildSelector.class).stream()
.filter(input -> !"ParameterizedBuildSelector".equals(input.clazz.getSimpleName()))
.collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.annotation.CheckForNull;

Expand All @@ -42,9 +43,6 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

import hudson.Extension;
import hudson.model.AutoCompletionCandidates;
import hudson.model.Item;
Expand Down Expand Up @@ -127,11 +125,10 @@ public boolean canCopiedBy(Job<?,?> copier) {
}

List<String> literals = Arrays.asList(pattern.split("\\*", -1));
String regex = StringUtils.join(Lists.transform(literals, new Function<String, String>() {
public String apply(String input) {
return (input != null)?Pattern.quote(input):"";
}
}), ".*");
String regex =
literals.stream()
.map(input -> input != null ? Pattern.quote(input) : "")
.collect(Collectors.joining(".*"));
return name.matches(regex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package hudson.plugins.copyartifact.monitor;

import com.cloudbees.hudson.plugins.folder.computed.ComputedFolder;
import com.google.common.annotations.VisibleForTesting;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.BulkChange;
Expand Down Expand Up @@ -126,7 +125,8 @@ public boolean isActivated() {
/**
* @return data holding the list of jobs to warn.
*/
@VisibleForTesting LegacyMonitorData getData() {
@Restricted(NoExternalUse.class)
/* Visible for testing */ LegacyMonitorData getData() {
return data;
}

Expand Down Expand Up @@ -325,7 +325,7 @@ public HttpResponse doMigrateAllSelected(@JsonBody MigrateAllSelectedModel conte
}
}

@VisibleForTesting
/* Visible for testing */
@Restricted(NoExternalUse.class)
boolean applyAutoMigration(@Nonnull String jobFromName, @Nonnull String jobToName) throws IOException {
Jenkins jenkins = Jenkins.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package hudson.plugins.copyartifact.monitor;

import com.google.common.annotations.VisibleForTesting;
import hudson.model.Job;
import hudson.security.ACL;
import hudson.security.ACLContext;
Expand Down Expand Up @@ -156,7 +155,7 @@ public void onJobRename(@Nonnull String previousFullName, @Nonnull String newFul
* @return map map from the pair of jobs to the possible failure build.
*/
@Restricted(NoExternalUse.class)
@VisibleForTesting @Nonnull Map<JobKey, LegacyBuildStorage> getLegacyJobInfos() {
/* Visible for testing */ @Nonnull Map<JobKey, LegacyBuildStorage> getLegacyJobInfos() {
return new HashMap<>(legacyJobInfos);
}

Expand All @@ -166,7 +165,7 @@ public void onJobRename(@Nonnull String previousFullName, @Nonnull String newFul
* @return map map from the job name to all existing pair of jobs.
*/
@Restricted(NoExternalUse.class)
@VisibleForTesting @Nonnull Map<String, List<JobKey>> getFullNameToKey() {
/* Visible for testing */ @Nonnull Map<String, List<JobKey>> getFullNameToKey() {
Map<String, List<JobKey>> result = new HashMap<>();

fullNameToKey.forEach((key, value) -> result.put(key, new ArrayList<>(value)));
Expand All @@ -180,7 +179,7 @@ public void onJobRename(@Nonnull String previousFullName, @Nonnull String newFul
* Clear all.
*/
@Restricted(NoExternalUse.class)
@VisibleForTesting void clear() {
/* Visible for testing */ void clear() {
this.fullNameToKey.clear();
this.legacyJobInfos.clear();
}
Expand Down Expand Up @@ -327,7 +326,7 @@ private void removeEntryFromKeyMap(@Nonnull String fullName, @Nonnull JobKey key
*/
@Restricted(NoExternalUse.class)
@Nonnull
@VisibleForTesting static JobKey buildKey(@Nonnull String jobFrom, @Nonnull String jobTo) {
/* Visible for testing */ static JobKey buildKey(@Nonnull String jobFrom, @Nonnull String jobTo) {
return new JobKey(jobFrom, jobTo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import hudson.plugins.copyartifact.testutils.CopyArtifactJenkinsRule;
import hudson.plugins.copyartifact.testutils.FileWriteBuilder;
import hudson.tasks.ArtifactArchiver;
import java.util.Arrays;
import java.util.HashSet;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.security.QueueItemAuthenticator;
Expand All @@ -57,8 +59,6 @@
import org.jvnet.hudson.test.MockAuthorizationStrategy;
import org.jvnet.hudson.test.recipes.LocalData;

import com.google.common.collect.Sets;

import javax.annotation.CheckForNull;

import static org.hamcrest.Matchers.hasSize;
Expand Down Expand Up @@ -831,7 +831,7 @@ public void remove_succeeded() throws Exception {
LegacyJobConfigMigrationMonitor monitor = LegacyJobConfigMigrationMonitor.get();
assertThat(
monitor.getData().getFullNameToKey().keySet(),
Matchers.is(Sets.newHashSet("dest", "src"))
Matchers.is(new HashSet<>(Arrays.asList("dest", "src")))
);

src.addProperty(new CopyArtifactPermissionProperty("dest"));
Expand Down

0 comments on commit 772adda

Please sign in to comment.