Mercurial > hg > mercurial
changeset 1027:10dc26b32c35
Update code according to new Java
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleaner.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleaner.java Wed Aug 05 13:19:53 2020 +0300 @@ -63,7 +63,7 @@ } private Set<String> getRunningBuildRepositories(@NotNull DirectoryCleanersProviderContext context) { - Set<String> repositories = new HashSet<String>(); + Set<String> repositories = new HashSet<>(); for (VcsRootEntry entry : context.getRunningBuild().getVcsRootEntries()) { VcsRoot root = entry.getVcsRoot(); if (!isHgRoot(root))
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfigImpl.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentPluginConfigImpl.java Wed Aug 05 13:19:53 2020 +0300 @@ -89,11 +89,11 @@ } public boolean runWithTraceback(@NotNull AgentRunningBuild build) { - return Boolean.valueOf(build.getSharedConfigParameters().get("teamcity.hg.run.commands.with.traceback")); + return Boolean.parseBoolean(build.getSharedConfigParameters().get("teamcity.hg.run.commands.with.traceback")); } public boolean runWithProfile(@NotNull AgentRunningBuild build) { - return Boolean.valueOf(build.getSharedConfigParameters().get("teamcity.hg.runCommandsWithProfile")); + return Boolean.parseBoolean(build.getSharedConfigParameters().get("teamcity.hg.runCommandsWithProfile")); } @Nullable
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgDetector.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgDetector.java Wed Aug 05 13:19:53 2020 +0300 @@ -134,7 +134,7 @@ } - private class HgExec { + private static class HgExec { private final String myPath; private final HgVersion myVersion;
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Wed Aug 05 13:19:53 2020 +0300 @@ -65,7 +65,7 @@ return AgentCheckoutAbility.noVcsClientOnAgent(e.getMessage()); } - Set<String> targetDirs = new HashSet<String>(); + Set<String> targetDirs = new HashSet<>(); try { for (IncludeRule rule : checkoutRules.getRootIncludeRules()) { MercurialIncludeRuleUpdater.checkRuleIsValid(rule); @@ -94,7 +94,7 @@ @NotNull private List<VcsRootEntry> getMercurialEntries(@NotNull AgentRunningBuild build) { - List<VcsRootEntry> result = new ArrayList<VcsRootEntry>(); + List<VcsRootEntry> result = new ArrayList<>(); for (VcsRootEntry entry : build.getVcsRootEntries()) { if (Constants.VCS_NAME.equals(entry.getVcsRoot().getVcsName())) result.add(entry); @@ -105,7 +105,7 @@ @NotNull private List<IncludeRule> getOtherRootRules(@NotNull List<IncludeRule> rules) { - List<IncludeRule> result = new ArrayList<IncludeRule>(); + List<IncludeRule> result = new ArrayList<>(); for (IncludeRule rule : rules) { try { MercurialIncludeRuleUpdater.checkRuleIsValid(rule);
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Wed Aug 05 13:19:53 2020 +0300 @@ -57,7 +57,7 @@ private int myPullTimeout; private final boolean myUseTraceback; private final boolean myProfile; - private final List<MercurialExtension> myExtensions = new ArrayList<MercurialExtension>(); + private final List<MercurialExtension> myExtensions = new ArrayList<>(); protected final MercurialProgress myProgress; public MercurialIncludeRuleUpdater(@NotNull AgentPluginConfig pluginConfig, @@ -104,7 +104,7 @@ @NotNull protected <T extends MercurialExtension> List<T> getExtensions(@NotNull Class<T> extensionClass) { - List<T> extentions = new ArrayList<T>(); + List<T> extentions = new ArrayList<>(); for (MercurialExtension e : myExtensions) { if (extensionClass.isInstance(e)) extentions.add(extensionClass.cast(e)); @@ -176,7 +176,7 @@ private void updateWorkingDir(@NotNull File workingDir, @NotNull String toVersion, @NotNull String repositoryUrl) throws VcsException, IOException { HgRepo repo = myRepoFactory.createRepo(myRoot, workingDir, myProgress); - List<File> repos = new ArrayList<File>(); + List<File> repos = new ArrayList<>(); updateSubrepositories(repo, toVersion, repositoryUrl, repos); doUpdateWorkingDir(repo, toVersion); purge(repos);
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SharingMercurialUpdater.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SharingMercurialUpdater.java Wed Aug 05 13:19:53 2020 +0300 @@ -25,6 +25,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * Updater which uses local mirrors and hg share extension (available in hg 1.3+) @@ -87,7 +88,7 @@ } private void writeSharedPath(@NotNull File mirrorHg, @NotNull File workingDir) throws IOException { - FileUtil.writeToFile(getSharedPath(workingDir), mirrorHg.getCanonicalPath().getBytes("UTF-8")); + FileUtil.writeToFile(getSharedPath(workingDir), mirrorHg.getCanonicalPath().getBytes(StandardCharsets.UTF_8)); } private void writeRequires(@NotNull File mirrorHg, @NotNull File workingDir) throws IOException {
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/BeforeWorkingDirUpdateExtension.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/BeforeWorkingDirUpdateExtension.java Wed Aug 05 13:19:53 2020 +0300 @@ -21,5 +21,5 @@ import org.jetbrains.annotations.NotNull; public interface BeforeWorkingDirUpdateExtension extends MercurialExtension { - public void call(@NotNull HgRepo repo, @NotNull String revision) throws VcsException; + void call(@NotNull HgRepo repo, @NotNull String revision) throws VcsException; }
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/MercurialExtensionManager.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/MercurialExtensionManager.java Wed Aug 05 13:19:53 2020 +0300 @@ -23,7 +23,7 @@ public class MercurialExtensionManager { - private final List<MercurialExtensionProvider> myProviders = new ArrayList<MercurialExtensionProvider>(); + private final List<MercurialExtensionProvider> myProviders = new ArrayList<>(); public void registerExtentionFactory(@NotNull MercurialExtensionProvider provider) { myProviders.add(provider); @@ -31,7 +31,7 @@ @NotNull public List<MercurialExtension> getExtensionsForCheckout(@NotNull CheckoutInfo info) { - List<MercurialExtension> extensions = new ArrayList<MercurialExtension>(); + List<MercurialExtension> extensions = new ArrayList<>(); for (MercurialExtensionProvider provider : myProviders) { MercurialExtension ext = provider.getExtentionForCheckout(info); if (ext != null)
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/impl/SparseCheckoutProvider.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ext/impl/SparseCheckoutProvider.java Wed Aug 05 13:19:53 2020 +0300 @@ -31,6 +31,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; public class SparseCheckoutProvider implements MercurialExtensionProvider { @@ -105,7 +106,7 @@ private void writeSparseConfig(@NotNull File workingDir, @NotNull String sparseContent) throws VcsException { try { - FileUtil.writeToFile(getSparseConfig(workingDir), sparseContent.getBytes("UTF-8"), false); + FileUtil.writeToFile(getSparseConfig(workingDir), sparseContent.getBytes(StandardCharsets.UTF_8), false); } catch (IOException e) { Loggers.VCS.warn("Error while writing .hg/sparse, will not do a sparse checkout", e); } @@ -115,7 +116,7 @@ private String getSparseContentFromRules() { StringBuilder sparse = new StringBuilder(); sparse.append("[exclude]\n"); - for (FileRule rule : myRules.getExcludeRules()) { + for (FileRule<?> rule : myRules.getExcludeRules()) { sparse.append(rule.getFrom()).append("\n"); } return sparse.toString();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Wed Aug 05 13:19:53 2020 +0300 @@ -44,7 +44,7 @@ protected final File myWorkingDir; protected final String myHgPath; protected final AuthSettings myAuthSettings; - protected final Map<String, Map<String, SubRepo>> mySubreposCache = new HashMap<String, Map<String, SubRepo>>(); + protected final Map<String, Map<String, SubRepo>> mySubreposCache = new HashMap<>(); public HgRepo(@NotNull CommandSettingsFactory commandSettingsFactory, @NotNull File workingDir, @@ -110,7 +110,7 @@ } public Map<String, String> getBranchRevisions(boolean includeBookmarks, boolean includeTags) throws VcsException { - Map<String, String> revisions = new HashMap<String, String>(); + Map<String, String> revisions = new HashMap<>(); if (includeTags) revisions.putAll(tags().call()); if (includeBookmarks && version().call().isEqualsOrGreaterThan(BookmarksCommand.REQUIRED_HG_VERSION)) @@ -208,7 +208,7 @@ .hideStatus() .showAllFiles() .call(); - List<String> files = new ArrayList<String>(fileStatuses.size()); + List<String> files = new ArrayList<>(fileStatuses.size()); for (FileStatus fileStatus : fileStatuses) files.add(fileStatus.getPath()); return files; @@ -284,7 +284,7 @@ public List<HgSubrepoConfigChange> getSubrepoConfigChanges(@NotNull ChangeSet cset) { if (containsSubrepoConfigChange(cset)) { - List<String> parents = new ArrayList<String>(); + List<String> parents = new ArrayList<>(); for (ChangeSetRevision p : cset.getParents()) { parents.add(p.getId()); } @@ -299,7 +299,7 @@ public List<HgSubrepoConfigChange> getSubrepoConfigChanges(@NotNull String revision, @NotNull List<String> parentRevisions) { Map<String, SubRepo> curSubrepos = getSubrepositories(revision); - List<Map<String, SubRepo>> prevSubrepos = new ArrayList<Map<String, SubRepo>>(); + List<Map<String, SubRepo>> prevSubrepos = new ArrayList<>(); for (String parentRevision : parentRevisions) { prevSubrepos.add(getSubrepositories(parentRevision)); } @@ -310,11 +310,11 @@ private List<HgSubrepoConfigChange> getSubrepoConfigChanges(@NotNull String mainRepoRevision, @NotNull List<Map<String, SubRepo>> prevSubrepos, @NotNull Map<String, SubRepo> curSubrepos) { - List<HgSubrepoConfigChange> configChanges = new ArrayList<HgSubrepoConfigChange>(); + List<HgSubrepoConfigChange> configChanges = new ArrayList<>(); for (Map.Entry<String, SubRepo> e : curSubrepos.entrySet()) { String path = e.getKey(); SubRepo curSubrepo = e.getValue(); - List<SubRepo> prevs = new ArrayList<SubRepo>(); + List<SubRepo> prevs = new ArrayList<>(); for (Map<String, SubRepo> prev : prevSubrepos) { SubRepo prevSubrepo = prev.remove(path); if (prevSubrepo == null) //no subrepo at this path in previous revision @@ -365,7 +365,7 @@ Map<String, SubRepo> subrepos = mySubreposCache.get(revId); if (subrepos != null) { - return new HashMap<String, SubRepo>(subrepos); + return new HashMap<>(subrepos); } File catDir = null; @@ -374,7 +374,7 @@ catDir = cc.call(); subrepos = HgSubs.readSubrepositories(new File(catDir, ".hgsub"), new File(catDir, ".hgsubstate")); mySubreposCache.put(revId, subrepos); - return new HashMap<String, SubRepo>(subrepos); + return new HashMap<>(subrepos); } catch (VcsException e) { return emptyMap(); } finally {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubrepoConfigChange.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubrepoConfigChange.java Wed Aug 05 13:19:53 2020 +0300 @@ -38,7 +38,7 @@ @NotNull String path, @Nullable SubRepo previous, @Nullable SubRepo current) { - this(mainRepoRevision, path, previous != null ? asList(previous) : new ArrayList<SubRepo>(), current); + this(mainRepoRevision, path, previous != null ? asList(previous) : new ArrayList<>(), current); } public HgSubrepoConfigChange(@NotNull String mainRepoRevision,
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubs.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgSubs.java Wed Aug 05 13:19:53 2020 +0300 @@ -68,7 +68,7 @@ @NotNull private static Map<String, SubRepo> readSubrepositories(@NotNull final Map<String, String> path2repo, @NotNull final Map<String, String> path2revision) { - final Map<String, SubRepo> result = new HashMap<String, SubRepo>(); + final Map<String, SubRepo> result = new HashMap<>(); for (Map.Entry<String, String> entry : path2repo.entrySet()) { final String path = entry.getKey(); final String url = entry.getValue(); @@ -88,7 +88,7 @@ @NotNull /*returns map: relative path -> repository url */ private static Map<String, String> readHgsub(@NotNull final Collection<String> lines) { - Map<String, String> result = new HashMap<String, String>(); + Map<String, String> result = new HashMap<>(); for (String line : lines) { String[] parts = line.split(" = "); if (parts.length == 2) @@ -107,7 +107,7 @@ @NotNull /*returns map: relative path -> revision */ private static Map<String, String> readHgsubstate(@NotNull final Collection<String> lines) { - final Map<String, String> result = new HashMap<String, String>(); + final Map<String, String> result = new HashMap<>(); for (String line : lines) { String[] parts = line.split(" "); if (parts.length == 2)
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialProgress.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialProgress.java Wed Aug 05 13:19:53 2020 +0300 @@ -28,7 +28,7 @@ void reportProgress(float percentage, @NotNull String stage); - static MercurialProgress NO_OP = new MercurialProgress() { + MercurialProgress NO_OP = new MercurialProgress() { public void progressStarted(@NotNull String progressMessage) { } public void progressFinished(@NotNull String progressMessage) {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MirrorManager.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MirrorManager.java Wed Aug 05 13:19:53 2020 +0300 @@ -33,16 +33,16 @@ * @return see above */ @NotNull - public File getMirrorDir(@NotNull final String url); + File getMirrorDir(@NotNull final String url); /** * Get all local mirror repository dirs * @return see above */ @NotNull - public List<File> getMirrors(); + List<File> getMirrors(); - public long getLastUsedTime(@NotNull final File mirrorDir); + long getLastUsedTime(@NotNull final File mirrorDir); /** * Forget specified dir. After call to this method with non-empty dir, @@ -52,12 +52,12 @@ * * @param dir dir of interest */ - public void forgetDir(@NotNull final File dir); + void forgetDir(@NotNull final File dir); @NotNull - public Map<String, File> getMappings(); + Map<String, File> getMappings(); - public void lockDir(@NotNull File dir); + void lockDir(@NotNull File dir); - public void unlockDir(@NotNull File dir); + void unlockDir(@NotNull File dir); }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MirrorManagerImpl.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MirrorManagerImpl.java Wed Aug 05 13:19:53 2020 +0300 @@ -49,10 +49,10 @@ /*Only one thread read or write to this file, it is protected by myLock.writeLock()*/ private final File myMappingFile; /*Protected by myLock*/ - private final Map<String, File> myMirrors = new HashMap<String, File>(); + private final Map<String, File> myMirrors = new HashMap<>(); private HashCalculator myHash = new StandartHash(); - private final ConcurrentMap<String, Lock> myDirLocks = new ConcurrentHashMap<String, Lock>(); + private final ConcurrentMap<String, Lock> myDirLocks = new ConcurrentHashMap<>(); public MirrorManagerImpl(@NotNull PluginConfig config) { myRootDir = config.getCachesDir(); @@ -85,7 +85,7 @@ public List<File> getMirrors() { myLock.readLock().lock(); try { - return new ArrayList<File>(myMirrors.values()); + return new ArrayList<>(myMirrors.values()); } finally { myLock.readLock().unlock(); } @@ -96,7 +96,7 @@ public Map<String, File> getMappings() { myLock.readLock().lock(); try { - return new HashMap<String, File>(myMirrors); + return new HashMap<>(myMirrors); } finally { myLock.readLock().unlock(); } @@ -148,7 +148,7 @@ } private Set<String> getUrlsMappedToDir(@NotNull final File dir) { - Set<String> urlsMappedToDir = new HashSet<String>(); + Set<String> urlsMappedToDir = new HashSet<>(); for (Map.Entry<String, File> entry : myMirrors.entrySet()) { File f = entry.getValue(); if (f.equals(dir)) @@ -282,7 +282,7 @@ return FileUtil.readFile(myMappingFile); } catch (IOException e) { LOG.error("Error while reading a mapping file at " + myMappingFile.getAbsolutePath() + " starting with empty mapping", e); - return new ArrayList<String>(); + return new ArrayList<>(); } } else { LOG.debug("No mapping file found at " + myMappingFile.getAbsolutePath() + " starting with empty mapping"); @@ -297,7 +297,7 @@ LOG.error("Cannot create a mapping file at " + myMappingFile.getAbsolutePath(), e); } } - return new ArrayList<String>(); + return new ArrayList<>(); } } @@ -345,7 +345,7 @@ if (lines.isEmpty()) return mirrorDir.lastModified(); else - return Long.valueOf(lines.get(0)); + return Long.parseLong(lines.get(0)); } catch (IOException e) { return mirrorDir.lastModified(); } @@ -380,7 +380,7 @@ } } - public static interface HashCalculator { + public interface HashCalculator { long calc(String value); } }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubRepo.java Wed Aug 05 13:19:53 2020 +0300 @@ -123,7 +123,7 @@ return myPath + " = " + myUrl + "#" + myRevision; } - public static enum VcsType { + public enum VcsType { hg(Constants.VCS_NAME), git("jetbrains.git"), svn("svn") ;
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -41,7 +41,7 @@ private File myDestination; private String myToId; private String myType = "files"; - private List<String> myIncludeRules = new ArrayList<String>(); + private List<String> myIncludeRules = new ArrayList<>(); public ArchiveCommand(@NotNull CommandSettings commandSettings, @NotNull String hgPath,
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/AuthSettings.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/AuthSettings.java Wed Aug 05 13:19:53 2020 +0300 @@ -18,7 +18,6 @@ import jetbrains.buildServer.log.Loggers; import jetbrains.buildServer.serverSide.TeamCityProperties; -import jetbrains.buildServer.util.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,7 +34,7 @@ */ public class AuthSettings { - private final static Set<String> AUTH_PROTOS = new HashSet<String>(asList("http", "https", "ssh")); + private final static Set<String> AUTH_PROTOS = new HashSet<>(asList("http", "https", "ssh")); private final String myUsername; private final String myPassword; @@ -174,7 +173,7 @@ return escaped.substring(5); } - private class FakeStreamHandler extends URLStreamHandler { + private static class FakeStreamHandler extends URLStreamHandler { @Override protected URLConnection openConnection(URL u) throws IOException { throw new UnsupportedOperationException();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BranchesCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BranchesCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -47,7 +47,7 @@ cli.addParameter(getBranchesCommand()); CommandResult res = runCommand(cli); String stdout = res.getRawStdout(); - Map<String, String> result = new HashMap<String, String>(); + Map<String, String> result = new HashMap<>(); Pattern branchPattern = Pattern.compile("(.*)[\\s]+([0-9]+:[A-Za-z0-9]+).*"); for (String line: stdout.split("[\r\n]+")) { Matcher matcher = branchPattern.matcher(line);
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -33,7 +33,7 @@ public class CatCommand extends AuthCommand { private String myRevId; - private List<String> myRelativePaths = new ArrayList<String>(); + private List<String> myRelativePaths = new ArrayList<>(); private boolean myCheckForFailure = true; public CatCommand(@NotNull CommandSettings commandSettings, @@ -107,12 +107,12 @@ private void catFiles(@NotNull final List<String> relPaths, final boolean checkFailure, @NotNull final File tempDir) throws VcsException { - final Queue<String> paths = new LinkedList<String>(relPaths); + final Queue<String> paths = new LinkedList<>(relPaths); while (!paths.isEmpty()) { MercurialCommandLine cli = createCommandLine(tempDir); int cmdSize = cli.getCommandLineLength() + 42; - List<String> pathsForDescription = new ArrayList<String>(2); + List<String> pathsForDescription = new ArrayList<>(2); do { String path = paths.poll(); if (pathsForDescription.size() < 2)
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java Wed Aug 05 13:19:53 2020 +0300 @@ -32,8 +32,8 @@ @NotNull private Date myTimestamp; private String myDescription; private String myBranch = DEFAULT_BRANCH_NAME; - private List<ChangeSetRevision> myParents = new ArrayList<ChangeSetRevision>(); - private List<FileStatus> myModifiedFiles = new ArrayList<FileStatus>(); + private List<ChangeSetRevision> myParents = new ArrayList<>(); + private List<FileStatus> myModifiedFiles = new ArrayList<>(); public ChangeSet(final int revNumber, @NotNull final String id) { super(revNumber, id);
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java Wed Aug 05 13:19:53 2020 +0300 @@ -299,6 +299,6 @@ } private static Set<Integer> setOf(Integer... ints) { - return new HashSet<Integer>(asList(ints)); + return new HashSet<>(asList(ints)); } }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java Wed Aug 05 13:19:53 2020 +0300 @@ -31,14 +31,14 @@ private final int myReadBytesLimit = TeamCityProperties.getInteger("teamcity.hg.command.readBytesLimit", Integer.MAX_VALUE); private int myTimeout = TeamCityProperties.getInteger("teamcity.hg.command.defaultExecutionTimeout", 3600); - private final Set<String> myPrivateData = new HashSet<String>(); + private final Set<String> myPrivateData = new HashSet<>(); private boolean myCheckForFailure = true; private boolean myFailWhenStderrNotEmpty = false; private String myLogLevel = "debug"; - private Map<String, String> myHgEnv = new HashMap<String, String>(); + private Map<String, String> myHgEnv = new HashMap<>(); private int myLogOutputLimit = -1; private int myExceptionOutputLimit = 5000; - private List<String> myGlobalArguments = new ArrayList<String>(0); + private List<String> myGlobalArguments = new ArrayList<>(0); private boolean myUseCommandlineViaFileWrapper = false; private MercurialProgress myProgress = MercurialProgress.NO_OP; @@ -147,11 +147,7 @@ public ProgressParser.ProgressConsumer getProgressConsumer() { if (myProgress == MercurialProgress.NO_OP) return null; - return new ProgressParser.ProgressConsumer() { - public void consume(float progress, @NotNull String stage) { - myProgress.reportProgress(progress, stage); - } - }; + return (progress, stage) -> myProgress.reportProgress(progress, stage); } @NotNull
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettingsForRootImpl.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettingsForRootImpl.java Wed Aug 05 13:19:53 2020 +0300 @@ -35,15 +35,12 @@ @NotNull public CommandSettingsFactory forRoot(@NotNull final HgVcsRoot root) { - return new CommandSettingsFactory() { - @NotNull - public CommandSettings create() { - CommandSettings settings = myFactory.create(); - for (CommandSettingsWeaver weaver : myWeavers) { - settings = weaver.update(root, settings); - } - return settings; + return () -> { + CommandSettings settings = myFactory.create(); + for (CommandSettingsWeaver weaver : myWeavers) { + settings = weaver.update(root, settings); } + return settings; }; } }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Wed Aug 05 13:19:53 2020 +0300 @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Set; public class CommandUtil { @@ -123,7 +124,7 @@ ProgressParser.ProgressConsumer progressConsumer = settings.getProgressConsumer(); ByteArrayOutputStream stderrBuffer; if (progressConsumer != null && cli.hasProgress()) { - stderrBuffer = new LineAwareByteArrayOutputStream(Charset.forName("UTF-8"), new ProgressParser(progressConsumer)); + stderrBuffer = new LineAwareByteArrayOutputStream(StandardCharsets.UTF_8, new ProgressParser(progressConsumer)); ((LineAwareByteArrayOutputStream) stderrBuffer).setCREndsLine(true); } else { stderrBuffer = new ByteArrayOutputStream();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -111,31 +111,10 @@ if (!rawOutput.contains("##Completed##")) throw new VcsException("Command failed: " + res.getSecureStdout()); try { - parseFileLog(new File(root, "result.hgsub"), new CommitsAndMountPointsParser.ContentsConsumer() { - public void onCommit(@NotNull final String fileNodeId, @NotNull final String content) { - consumer.processHGSubFile(fileNodeId, content); - } - }); - parseFileLog(new File(root, "result.hgsubstate"), new CommitsAndMountPointsParser.ContentsConsumer() { - public void onCommit(@NotNull final String fileNodeId, @NotNull final String content) { - consumer.processHGSubStateFile(fileNodeId, content); - } - }); + parseFileLog(new File(root, "result.hgsub"), consumer::processHGSubFile); + parseFileLog(new File(root, "result.hgsubstate"), consumer::processHGSubStateFile); - parseCommits(new File(root, "result.commits"), new CommitsAndMountPointsParser.CommitsConsumer() { - public void onCommit(@NotNull String commitNum, - @NotNull String commitId, - @NotNull String[] parents, - @NotNull String branch, - @NotNull String[] tags, - @NotNull String author, - @NotNull String message, - @NotNull Date timestamp, - @Nullable String hgsubNodeId, - @Nullable String hgsubstateNodeId) { - consumer.onCommit(commitNum, commitId, parents, branch, tags, author, message, timestamp, hgsubNodeId, hgsubstateNodeId); - } - }); + parseCommits(new File(root, "result.commits"), consumer::onCommit); } catch (IOException e) { throw new VcsException("Failed to parse response files for 'load-substates' command. " + e.getMessage(), e); }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsParser.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsParser.java Wed Aug 05 13:19:53 2020 +0300 @@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable; import java.io.*; +import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -35,7 +36,7 @@ public static void parseFileLog(@NotNull final File dump, @NotNull final ContentsConsumer consumer) throws IOException { - final BufferedReader st = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(dump)), "utf-8")); + final BufferedReader st = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(dump)), StandardCharsets.UTF_8)); try { final Decoder fileDecoder = new Decoder(5); @@ -84,7 +85,7 @@ final Decoder authorDecoder = new Decoder(200); final Decoder messageDecoder = new Decoder(210); - final BufferedReader st = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(dump)), "utf-8")); + final BufferedReader st = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(dump)), StandardCharsets.UTF_8)); try { String line; while((line = st.readLine()) != null) { @@ -165,7 +166,7 @@ final String result = myCache.get(base64); if (result != null) return result; - final String value = new String(Base64.decodeBase64(base64), "utf-8"); + final String value = new String(Base64.decodeBase64(base64), StandardCharsets.UTF_8); //noinspection RedundantStringConstructorCall myCache.put(new String(base64), value); return value;
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Wed Aug 05 13:19:53 2020 +0300 @@ -68,7 +68,7 @@ myIncludeSubreposInPatch = Boolean.parseBoolean(getProperty(Constants.INCLUDE_SUBREPOS_IN_PATCH, "true")); myUseArchiveForPatch = Boolean.parseBoolean(getProperty(Constants.USE_ARCHIVE_FOR_PATCH)); myPurgePolicy = readPurgePolicy(vcsRootProperties); - myIgnoreMissingDefaultBranch = Boolean.valueOf(getProperty(Constants.IGNORE_MISSING_DEFAULT_BRANCH, "false")); + myIgnoreMissingDefaultBranch = Boolean.parseBoolean(getProperty(Constants.IGNORE_MISSING_DEFAULT_BRANCH, "false")); myCustomHgConfig = getProperty(Constants.CUSTOM_HG_CONFIG_PROP, ""); myUseAgentMirrors = readUseSharedMirrors(); } @@ -90,7 +90,7 @@ } public HgVcsRoot withUrl(@NotNull String repositoryUrl) { - Map<String, String> customUrlProperties = new HashMap<String, String>(getProperties()); + Map<String, String> customUrlProperties = new HashMap<>(getProperties()); customUrlProperties.put(Constants.REPOSITORY_PROP, repositoryUrl); return new HgVcsRoot(customUrlProperties); } @@ -169,7 +169,7 @@ } public boolean isSubrepo() { - return Boolean.valueOf(getProperty("teamcity.internal.subrepo")); + return Boolean.parseBoolean(getProperty("teamcity.internal.subrepo")); } public String getSubrepoPath() { @@ -237,7 +237,7 @@ return myUseAgentMirrors; } - public static enum PurgePolicy { + public enum PurgePolicy { DONT_RUN, PURGE_UNKNOWN, PURGE_ALL
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LoadDagCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LoadDagCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -46,42 +46,39 @@ @NotNull public List<Pair<String, String>> call() throws VcsException { - return myDagLogTemplate.withTemplate(new MercurialTemplate.WithTemplate<List<Pair<String, String>>>() { - @NotNull - public List<Pair<String, String>> action(@NotNull File template) throws VcsException { - final List<Pair<String, String>> edges = new ArrayList<Pair<String, String>>(); - final MercurialCommandLine cli = createCommandLine(); - cli.addParameter("log"); - cli.addParameter("--style=" + template.getAbsolutePath()); - if (myMaxDagNodesCount > 0) { - cli.addParameters("--limit", String.valueOf(myMaxDagNodesCount)); - } + return myDagLogTemplate.withTemplate(template -> { + final List<Pair<String, String>> edges = new ArrayList<>(); + final MercurialCommandLine cli = createCommandLine(); + cli.addParameter("log"); + cli.addParameter("--style=" + template.getAbsolutePath()); + if (myMaxDagNodesCount > 0) { + cli.addParameters("--limit", String.valueOf(myMaxDagNodesCount)); + } - final CommandResult res = runCommand(cli); + final CommandResult res = runCommand(cli); - final String output = res.getRawStdout(); - String fromNode = null; - for (String line : StringUtil.splitByLines(output)) { - final String[] revs = line.split(" "); - if (revs.length == 0) continue; + final String output = res.getRawStdout(); + String fromNode = null; + for (String line : StringUtil.splitByLines(output)) { + final String[] revs = line.split(" "); + if (revs.length == 0) continue; - if (fromNode != null) { - edges.add(Pair.create(fromNode, revs[0])); - fromNode = null; - } + if (fromNode != null) { + edges.add(Pair.create(fromNode, revs[0])); + fromNode = null; + } - if (revs.length == 1) { - fromNode = revs[0]; - } else { - edges.add(Pair.create(revs[0], revs[1])); - if (revs.length == 3) { - edges.add(Pair.create(revs[0], revs[2])); - } + if (revs.length == 1) { + fromNode = revs[0]; + } else { + edges.add(Pair.create(revs[0], revs[1])); + if (revs.length == 3) { + edges.add(Pair.create(revs[0], revs[2])); } } - return edges; } + return edges; }); }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -29,7 +29,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.*; public class LogCommand extends VcsRootCommand { @@ -46,7 +46,7 @@ private boolean myCalculateParents = true; private String myRevsets; private MercurialTemplate myTemplate; - private List<String> myFiles = new ArrayList<String>(); + private List<String> myFiles = new ArrayList<>(); public LogCommand(@NotNull CommandSettings commandSettings, @NotNull String hgPath, @@ -107,53 +107,50 @@ @NotNull public List<ChangeSet> call() throws VcsException { - return myTemplate.withTemplate(new MercurialTemplate.WithTemplate<List<ChangeSet>>() { - @NotNull - public List<ChangeSet> action(@NotNull File template) throws VcsException { - final MercurialCommandLine cli = createCommandLine(); - cli.setCharset(Charset.forName("UTF-8")); - cli.addParameters("--encoding", "UTF-8"); - cli.addParameter("log"); - cli.addParameter("-v"); - if (myTemplate != null) { - cli.addParameter("--style=" + template.getAbsolutePath()); - } + return myTemplate.withTemplate(template -> { + final MercurialCommandLine cli = createCommandLine(); + cli.setCharset(StandardCharsets.UTF_8); + cli.addParameters("--encoding", "UTF-8"); + cli.addParameter("log"); + cli.addParameter("-v"); + if (myTemplate != null) { + cli.addParameter("--style=" + template.getAbsolutePath()); + } - if (myBranchName != null) { - cli.addParameter("-b"); - cli.addParameter(myBranchName); - } - cli.addParameter("-r"); - if (myRevsets != null) { - cli.addParameter(myRevsets); + if (myBranchName != null) { + cli.addParameter("-b"); + cli.addParameter(myBranchName); + } + cli.addParameter("-r"); + if (myRevsets != null) { + cli.addParameter(myRevsets); + } else { + String from = myFromId != null ? myFromId : "0"; + String to = myToId != null ? myToId : "tip"; + cli.addParameter(from + ":" + to); + } + if (myLimit != null) { + cli.addParameter("--limit"); + cli.addParameter(myLimit.toString()); + } + + cli.addParameters(myFiles); + + final CommandResult res = runCommand(cli); + final String output = res.getRawStdout(); + try { + List<ChangeSet> changes = parseChangeSetsXml(output); + if (myCalculateParents) + assignTrivialParents(changes); + return changes; + } catch (Exception e) { + int limit = myCommandSettings.getLogOutputLimit(); + if (limit == -1) { + LOG.error("Error while parsing log output:\n" + res.getSecureStdout(), e); } else { - String from = myFromId != null ? myFromId : "0"; - String to = myToId != null ? myToId : "tip"; - cli.addParameter(from + ":" + to); + LOG.error("Error while parsing log output:\n" + StringUtil.truncateStringValueWithDotsAtEnd(res.getSecureStdout(), limit), e); } - if (myLimit != null) { - cli.addParameter("--limit"); - cli.addParameter(myLimit.toString()); - } - - cli.addParameters(myFiles); - - final CommandResult res = runCommand(cli); - final String output = res.getRawStdout(); - try { - List<ChangeSet> changes = parseChangeSetsXml(output); - if (myCalculateParents) - assignTrivialParents(changes); - return changes; - } catch (Exception e) { - int limit = myCommandSettings.getLogOutputLimit(); - if (limit == -1) { - LOG.error("Error while parsing log output:\n" + res.getSecureStdout(), e); - } else { - LOG.error("Error while parsing log output:\n" + StringUtil.truncateStringValueWithDotsAtEnd(res.getSecureStdout(), limit), e); - } - throw new VcsException("Error while parsing log output, see teamcity-vcs.log for details", e); - } + throw new VcsException("Error while parsing log output, see teamcity-vcs.log for details", e); } }); } @@ -165,7 +162,7 @@ String validXml = makeValidXml(xml); MercurialXmlLogParser parser = new MercurialXmlLogParser(); SAXParser saxParser = ourSAXFactory.newSAXParser(); - saxParser.parse(new ByteArrayInputStream(validXml.getBytes("UTF-8")), parser); + saxParser.parse(new ByteArrayInputStream(validXml.getBytes(StandardCharsets.UTF_8)), parser); return parser.getChangeSets(); } @@ -194,7 +191,7 @@ } private Map<Integer, ChangeSet> makeMapByRevNumber(@NotNull List<ChangeSet> csets) throws VcsException { - Map<Integer, ChangeSet> csetMap = new HashMap<Integer, ChangeSet>(); + Map<Integer, ChangeSet> csetMap = new HashMap<>(); for (ChangeSet cset : csets) { csetMap.put(cset.getRevNumber(), cset); }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java Wed Aug 05 13:19:53 2020 +0300 @@ -29,8 +29,8 @@ public class MercurialCommandLine { private String myExePath; - private final List<String> myArguments = new ArrayList<String>(); - private final Map<String, String> myEnvPatch = new TreeMap<String, String>(); + private final List<String> myArguments = new ArrayList<>(); + private final Map<String, String> myEnvPatch = new TreeMap<>(); private String myWorkingDirectory; private final Set<String> myPrivateData; @@ -75,7 +75,7 @@ @NotNull public List<String> getArguments() { - return new ArrayList<String>(myArguments); + return new ArrayList<>(myArguments); } public void addParameter(@NotNull final String parameter) { @@ -160,7 +160,7 @@ if (!myEnvPatch.isEmpty()) { cmd.setPassParentEnvs(true); - cmd.setEnvParams(new TreeMap<String, String>(myEnvPatch)); + cmd.setEnvParams(new TreeMap<>(myEnvPatch)); } return cmd;
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialXmlLogParser.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialXmlLogParser.java Wed Aug 05 13:19:53 2020 +0300 @@ -35,7 +35,7 @@ private static final String DATE_FORMAT = "EEE MMM d HH:mm:ss yyyy Z"; private final SimpleDateFormat mySimpleDateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); - private List<ChangeSet> myChangeSets = new ArrayList<ChangeSet>(); + private List<ChangeSet> myChangeSets = new ArrayList<>(); private ChangeSet myCset = null; private StringBuilder myText = new StringBuilder(); private List<FileStatus> myFiles; @@ -57,7 +57,7 @@ } else if ("author".equals(qName)) { myCset.setUser(attrs.getValue("original")); } else if ("paths".equals(qName)) { - myFiles = new ArrayList<FileStatus>(); + myFiles = new ArrayList<>(); } else if ("path".equals(qName)) { myFileAction = attrs.getValue("action"); resetText();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ParentsCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ParentsCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -46,7 +46,7 @@ if (myRevision != null) cli.addParameters("-r", myRevision); CommandResult res = runCommand(cli); - List<String> parentRevisions = new ArrayList<String>(); + List<String> parentRevisions = new ArrayList<>(); for (String line : res.getRawStdout().split("\n")) { if (StringUtil.isEmpty(line)) continue;
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ResolveCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ResolveCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -21,6 +21,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static java.util.Collections.emptyList; @@ -40,11 +41,7 @@ String stdout = result.getRawStdout(); if (stdout.length() == 0) return emptyList(); - List<String> unresolvedFiles = new ArrayList<String>(); - for (String line: stdout.split("[\r\n]+")) { - unresolvedFiles.add(line); - } - return unresolvedFiles; + return new ArrayList<>(Arrays.asList(stdout.split("[\r\n]+"))); } @NotNull
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommand.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommand.java Wed Aug 05 13:19:53 2020 +0300 @@ -111,7 +111,7 @@ @NotNull private List<FileStatus> parseFiles(@NotNull final String stdout) { - final List<FileStatus> result = new ArrayList<FileStatus>(); + final List<FileStatus> result = new ArrayList<>(); String[] lines = stdout.split("\n"); for (String line : lines) { if (isEmpty(line))
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Cleanup.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Cleanup.java Wed Aug 05 13:19:53 2020 +0300 @@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull; import java.io.File; -import java.io.FileFilter; import java.util.*; import static java.util.Arrays.asList; @@ -56,22 +55,18 @@ private List<File> existingDirs() { File[] files = listDirs(); if (files != null) - return new ArrayList<File>(asList(files)); + return new ArrayList<>(asList(files)); if (myConfig.getCachesDir().isDirectory()) LOG.warn("Cannot list files in " + myConfig.getCachesDir()); return Collections.emptyList(); } private File[] listDirs() { - return myConfig.getCachesDir().listFiles(new FileFilter() { - public boolean accept(File f) { - return f.isDirectory(); - } - }); + return myConfig.getCachesDir().listFiles(File::isDirectory); } private List<File> mirrorDirsOfRootsInUse(@NotNull List<File> mirrors) { - List<File> result = new ArrayList<File>(); + List<File> result = new ArrayList<>(); long now = new Date().getTime(); for (File mirror : mirrors) { File dotHg = new File(mirror, ".hg");
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CollectChangesContext.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CollectChangesContext.java Wed Aug 05 13:19:53 2020 +0300 @@ -39,20 +39,20 @@ private final ServerPluginConfig myConfig; private final Set<String> myUninterestingRevisions; - private final Map<VcsRootKey, DAG<String>> myDags = new HashMap<VcsRootKey, DAG<String>>(); - private Set<File> mySyncedDirs = new HashSet<File>(); - private Map<String, Set<SubrepoChangesInterval>> myProcessedSubrepoChanges = new HashMap<String, Set<SubrepoChangesInterval>>();//subrepo url -> processed changes intervals - private Map<VcsRootKey, Set<String>> myRevisionsPerRoot = new HashMap<VcsRootKey, Set<String>>(); - private Map<File, ServerHgRepo> myRepos = new HashMap<File, ServerHgRepo>(); + private final Map<VcsRootKey, DAG<String>> myDags = new HashMap<>(); + private Set<File> mySyncedDirs = new HashSet<>(); + private Map<String, Set<SubrepoChangesInterval>> myProcessedSubrepoChanges = new HashMap<>();//subrepo url -> processed changes intervals + private Map<VcsRootKey, Set<String>> myRevisionsPerRoot = new HashMap<>(); + private Map<File, ServerHgRepo> myRepos = new HashMap<>(); private boolean myIncludeFromRevisions = false;//by default don't include them, they should be included only for subrepos - private TLongObjectHashMap<String> myStringPool = new TLongObjectHashMap<String>(); + private TLongObjectHashMap<String> myStringPool = new TLongObjectHashMap<>(); public CollectChangesContext(@NotNull ServerPluginConfig config, @NotNull MercurialVcsSupport vcs, @NotNull RepoFactory repoFactory, @NotNull MercurialProgress progress, @NotNull RepositoryStateData fromState) { - this(config, vcs, repoFactory, progress, new HashSet<String>(fromState.getBranchRevisions().values())); + this(config, vcs, repoFactory, progress, new HashSet<>(fromState.getBranchRevisions().values())); } public CollectChangesContext(@NotNull ServerPluginConfig config, @@ -70,7 +70,7 @@ @NotNull Collection<String> fromVersions) { super(vcs, repoFactory, progress); myConfig = config; - myUninterestingRevisions = new HashSet<String>(fromVersions); + myUninterestingRevisions = new HashSet<>(fromVersions); } public void syncRepository(@NotNull HgVcsRoot root) throws VcsException { @@ -83,11 +83,7 @@ public void markProcessedSubrepoChanges(@NotNull VcsRoot subrepo, @NotNull List<String> previousSubrepoRevisions, @NotNull String currentSubrepoRevision) { String subrepoUrl = subrepo.getProperty(Constants.REPOSITORY_PROP); - Set<SubrepoChangesInterval> processedSubrepoChanges = myProcessedSubrepoChanges.get(subrepoUrl); - if (processedSubrepoChanges == null) { - processedSubrepoChanges = new HashSet<SubrepoChangesInterval>(); - myProcessedSubrepoChanges.put(subrepoUrl, processedSubrepoChanges); - } + Set<SubrepoChangesInterval> processedSubrepoChanges = myProcessedSubrepoChanges.computeIfAbsent(subrepoUrl, k -> new HashSet<>()); processedSubrepoChanges.add(new SubrepoChangesInterval(previousSubrepoRevisions, currentSubrepoRevision)); } @@ -132,12 +128,7 @@ @NotNull private Set<String> getReportedRootRevisions(@NotNull ModificationData m) { VcsRootKey key = VcsRootKey.create(m.getVcsRoot()); - Set<String> revisions = myRevisionsPerRoot.get(key); - if (revisions == null) { - revisions = new HashSet<String>(); - myRevisionsPerRoot.put(key, revisions); - } - return revisions; + return myRevisionsPerRoot.computeIfAbsent(key, k -> new HashSet<>()); } @@ -206,7 +197,7 @@ if (!repo.supportRevsets() || !myConfig.computeFromRevisions()) return singleton(fromRevision); - Set<String> fromRevisions = new HashSet<String>(); + Set<String> fromRevisions = new HashSet<>(); if (toState.getBranchRevisions().size() > 1) { VcsRootKey rootKey = VcsRootKey.create(root); DAG<String> dag = myDags.get(rootKey); @@ -257,10 +248,10 @@ private final DAG<String> myDag; private final Collection<String> myUninterestingRevisions;//from state revisions - private final Set<String> myAllUninteresting = new HashSet<String>();//myUninterestingRevisions + all revisions reachable from them + private final Set<String> myAllUninteresting = new HashSet<>();//myUninterestingRevisions + all revisions reachable from them private boolean myUninterestingInitialized = false;//become true when myAllUninteresting is computed - private final Set<String> myCoveredUninteresting = new HashSet<String>();//all revisions reachable from computed endpoints - private final Set<String> myEndpoints = new HashSet<String>(); + private final Set<String> myCoveredUninteresting = new HashSet<>();//all revisions reachable from computed endpoints + private final Set<String> myEndpoints = new HashSet<>(); private FindIntervalVisitor(@NotNull DAG<String> dag, @NotNull Collection<String> uninteresting) { myDag = dag; @@ -303,7 +294,7 @@ return myEndpoints; } - private class MarkUninterestingRevisions extends BFSVisitorAdapter<String> { + private static class MarkUninterestingRevisions extends BFSVisitorAdapter<String> { private final Set<String> myAccumulator; public MarkUninterestingRevisions(@NotNull Set<String> accumulator) {
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ListFilesSupport.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ListFilesSupport.java Wed Aug 05 13:19:53 2020 +0300 @@ -65,7 +65,7 @@ @NotNull private List<VcsFileData> listFilesIn(@NotNull HgVcsRoot root, @NotNull String dir) throws VcsException { HgRepo repo = myVcs.createRepo(root); - List<VcsFileData> result = new ArrayList<VcsFileData>(); + List<VcsFileData> result = new ArrayList<>(); Pattern p = compile(quote(File.separator)); for (String file : repo.listFiles(root.getBranchName())) { String canonicalFile = p.matcher(file).replaceAll("/");
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java Wed Aug 05 13:19:53 2020 +0300 @@ -62,11 +62,7 @@ @NotNull public RepositoryStateData getCurrentState(@NotNull final HgVcsRoot hgRoot) throws VcsException { final OperationContext context = new OperationContext(myVcs, myRepoFactory, createMercurialProgess()); - VcsCallable<Map<String, String>> cmd = new VcsCallable<Map<String, String>>() { - public Map<String, String> call() throws VcsException { - return getHeads(hgRoot, context); - } - }; + VcsCallable<Map<String, String>> cmd = () -> getHeads(hgRoot, context); Map<String, String> revisions = context.syncRepository(hgRoot, cmd); String defaultBranchName = hgRoot.getBranchName(); if (revisions.get(defaultBranchName) == null && !hgRoot.isIgnoreMissingDefaultBranch()) { @@ -103,7 +99,7 @@ @NotNull RepositoryStateData fromState, @NotNull RepositoryStateData toState, @NotNull CheckoutRules rules) throws VcsException { - List<ModificationData> changes = new ArrayList<ModificationData>(); + List<ModificationData> changes = new ArrayList<>(); HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); CollectChangesContext ctx = new CollectChangesContext(myConfig, myVcs, myRepoFactory, createMercurialProgess(), fromState); for (Map.Entry<String, String> entry : toState.getBranchRevisions().entrySet()) { @@ -205,12 +201,12 @@ @NotNull CheckoutRules checkoutRules) throws VcsException { HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); ctx.syncRepository(hgRoot); - List<ModificationData> result = new ArrayList<ModificationData>(); + List<ModificationData> result = new ArrayList<>(); List<ChangeSet> csets = getChangesets(ctx, hgRoot, fromVersion, currentVersion); //When commit has no changes in subrepo configuration we can reuse //subrepo revision table calculated for its parent commit(s). To do //that parents should be processed before children: - Collections.sort(csets, ASCENDING_REV_NUMS); + csets.sort(ASCENDING_REV_NUMS); for (ChangeSet cset : csets) { result.add(createModificationData(ctx, cset, root, hgRoot, checkoutRules)); } @@ -225,7 +221,7 @@ @Nullable final String toVersion) throws VcsException { if (toVersion == null) return emptyList(); - List<String> fromCommits = new ArrayList<String>(); + List<String> fromCommits = new ArrayList<>(); for (String fromVersion : fromVersions) { fromCommits.add(new ChangeSetRevision(fromVersion).getId()); } @@ -238,12 +234,7 @@ .includeFromRevision(ctx.includeFromRevisions()) .call(); if (!ctx.includeFromRevisions()) { - Iterator<ChangeSet> iter = csets.iterator(); - while (iter.hasNext()) { - ChangeSet cset = iter.next(); - if (fromVersions.contains(cset.getId())) - iter.remove(); - } + csets.removeIf(cset -> fromVersions.contains(cset.getId())); } return csets; } catch (UnknownRevisionException e) { @@ -274,7 +265,7 @@ return emptyList(); List<HgSubrepoConfigChange> subrepoConfigChanges = getSubrepoConfigChanges(ctx, changes); - List<ModificationData> subrepoChanges = new ArrayList<ModificationData>(); + List<ModificationData> subrepoChanges = new ArrayList<>(); for (HgSubrepoConfigChange configChange : subrepoConfigChanges) { SubRepo current = configChange.getCurrent(); @@ -282,13 +273,13 @@ String subrepoUrl = current.url(); String curRevision = current.revision(); - List<String> prevRevisions = new ArrayList<String>(0); + List<String> prevRevisions = new ArrayList<>(0); for (SubRepo prevSubrepo : configChange.getPrevious()) { prevRevisions.add(prevSubrepo.revision()); } String path = configChange.getPath(); - Map<String, String> subrepoParams = new HashMap<String, String>(hgRoot.getProperties()); + Map<String, String> subrepoParams = new HashMap<>(hgRoot.getProperties()); subrepoParams.put(Constants.REPOSITORY_PROP, subrepoUrl); subrepoParams.put("teamcity.internal.subrepo", "true"); subrepoParams.put("teamcity.internal.subrepo.path", path); @@ -326,7 +317,7 @@ private List<HgSubrepoConfigChange> getSubrepoConfigChanges(@NotNull CollectChangesContext ctx, @NotNull List<ModificationData> mainRootChanges) throws VcsException { - List<HgSubrepoConfigChange> subrepoConfigChanges = new ArrayList<HgSubrepoConfigChange>(); + List<HgSubrepoConfigChange> subrepoConfigChanges = new ArrayList<>(); for (ModificationData m : mainRootChanges) { subrepoConfigChanges.addAll(getSubrepoConfigChanges(ctx, m)); } @@ -336,7 +327,7 @@ @NotNull private List<HgSubrepoConfigChange> getSubrepoConfigChanges(@NotNull CollectChangesContext ctx, @NotNull ModificationData m) throws VcsException { - List<HgSubrepoConfigChange> configChanges = new ArrayList<HgSubrepoConfigChange>(); + List<HgSubrepoConfigChange> configChanges = new ArrayList<>(); HgVcsRoot mainRoot = myHgVcsRootFactory.createHgRoot(m.getVcsRoot()); ServerHgRepo repo = ctx.createRepo(mainRoot); @@ -348,7 +339,7 @@ assert currentSubrepo != null; String subrepoUrl = ctx.getStringFromPool(currentSubrepo.resolveUrl(mainRoot.getRepository())); String curRevision = ctx.getStringFromPool(currentSubrepo.revision()); - List<SubRepo> prevSubrepos = new ArrayList<SubRepo>(0); + List<SubRepo> prevSubrepos = new ArrayList<>(0); String path = ctx.getStringFromPool(mainRoot.expandSubrepoPath(c.getPath())); for (SubRepo prevSubrepo : c.getPrevious()) { prevSubrepos.add(new SubRepo(path, subrepoUrl, ctx.getStringFromPool(prevSubrepo.revision()))); @@ -369,7 +360,7 @@ @NotNull VcsRoot mainRoot, @NotNull HgVcsRoot mainHgRoot, @NotNull ModificationData m) throws VcsException { - Map<String, String> attributes = new HashMap<String, String>(); + Map<String, String> attributes = new HashMap<>(); if (detectSubrepoChanges(mainHgRoot)) { try { ServerHgRepo repo = ctx.createRepo(mainHgRoot); @@ -397,13 +388,7 @@ private final static class AscendingRevNums implements Comparator<ChangeSet> { public int compare(ChangeSet o1, ChangeSet o2) { - int revnum1 = o1.getRevNumber(); - int revnum2 = o2.getRevNumber(); - if (revnum1 < revnum2) - return -1; - if (revnum1 > revnum2) - return 1; - return 0; + return Integer.compare(o1.getRevNumber(), o2.getRevNumber()); } }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupport.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupport.java Wed Aug 05 13:19:53 2020 +0300 @@ -79,9 +79,9 @@ private final HgVcsRoot myHgRoot; private final File myPatchDir; private final File myCheckoutDir; - private final Set<String> myCreatedFiles = new HashSet<String>(); - private final Set<String> myDeletedFiles = new HashSet<String>(); - private final Set<String> myDeletedDirs = new HashSet<String>(); + private final Set<String> myCreatedFiles = new HashSet<>(); + private final Set<String> myDeletedFiles = new HashSet<>(); + private final Set<String> myDeletedDirs = new HashSet<>(); public MercurialCommitPatchBuilder(@NotNull VcsRoot root, @NotNull HgVcsRoot hgRoot, @NotNull File patchDir, @NotNull File checkoutDir) { myRoot = root; @@ -179,7 +179,7 @@ @NotNull private RepositoryStateData getCurrentState() throws VcsException { - Map<String, String> props = new HashMap<String, String>(myHgRoot.getProperties()); + Map<String, String> props = new HashMap<>(myHgRoot.getProperties()); props.put(Constants.IGNORE_MISSING_DEFAULT_BRANCH, "true"); return myVcs.getCollectChangesPolicy().getCurrentState(new HgVcsRoot(props)); }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderStates.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderStates.java Wed Aug 05 13:19:53 2020 +0300 @@ -29,8 +29,8 @@ * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) */ public class MercurialCommitsInfoBuilderStates { - private final Map<String, String> myHgStateNodes = new HashMap<String, String>(); - private final Map<String, String> myHgSubNodes = new HashMap<String, String>(); + private final Map<String, String> myHgStateNodes = new HashMap<>(); + private final Map<String, String> myHgSubNodes = new HashMap<>(); public void addSubNode(@NotNull final String hash, @NotNull final String text) { myHgSubNodes.put(hash, text);
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java Wed Aug 05 13:19:53 2020 +0300 @@ -46,7 +46,7 @@ @NotNull private static MultiMapToList<String, String> commitToBranchs(@NotNull final Map<String, String> branchToCommit) { - final MultiMapToList<String, String> map = new MultiMapToList<String, String>(); + final MultiMapToList<String, String> map = new MultiMapToList<>(); for (Map.Entry<String, String> e : branchToCommit.entrySet()) { map.add(e.getValue(), e.getKey()); } @@ -59,12 +59,8 @@ final HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); final ServerHgRepo repo = mySupport.createRepo(hgRoot); - VcsCallable<MultiMapToList<String, String>> cmd = new VcsCallable<MultiMapToList<String, String>>() { - public MultiMapToList<String, String> call() throws VcsException { - return commitToBranchs(mySupport.getCollectChangesPolicy().getHeads(hgRoot)); - } - }; - final MultiMapToList<String, String> heads = mySupport.syncRepository(hgRoot, new SyncSettings<MultiMapToList<String, String>>(cmd)); + VcsCallable<MultiMapToList<String, String>> cmd = () -> commitToBranchs(mySupport.getCollectChangesPolicy().getHeads(hgRoot)); + final MultiMapToList<String, String> heads = mySupport.syncRepository(hgRoot, new SyncSettings<>(cmd)); repo.logSubstates().call(new CommitsAndMountPointsCommand.Callback() { private final MercurialCommitsInfoBuilderStates subs = new MercurialCommitsInfoBuilderStates();
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java Wed Aug 05 13:19:53 2020 +0300 @@ -61,7 +61,7 @@ tmpDir = HgFileUtil.createTempDir(); HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); HgRepo repo = myHgRepoFactory.createRepo(hgRoot, tmpDir); - Map<MergeTask, MergeResult> results = new HashMap<MergeTask, MergeResult>(); + Map<MergeTask, MergeResult> results = new HashMap<>(); for (MergeTask task : tasks) { try { new CheckoutRepository(myMirrorManager, myHgRepoFactory, myConfig.getPullTimeout(), myConfig.useTagsAsBranches(), hgRoot, tmpDir) @@ -163,7 +163,7 @@ private List<String> detectConflicts(@NotNull HgVcsRoot root, @NotNull String prefix, @NotNull HgRepo repo) throws VcsException { - List<String> conflicts = new ArrayList<String>(); + List<String> conflicts = new ArrayList<>(); for (String conflict : repo.resolve().call()) { conflicts.add(prefix + conflict); }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Wed Aug 05 13:19:53 2020 +0300 @@ -61,7 +61,7 @@ private final FileFilter myAcceptAllFilter = new AcceptAllFilter(); private final HgTestConnectionSupport myTestConnection; private final SubrepoCheckoutRulesProvider mySubrepoCheckoutRulesProvider; - private final Collection<MercurialServerExtension> myExtensions = new ArrayList<MercurialServerExtension>(); + private final Collection<MercurialServerExtension> myExtensions = new ArrayList<>(); public MercurialVcsSupport(@NotNull final VcsOperationProgressProvider progressProvider, @NotNull final EventDispatcher<ServerListener> dispatcher, @@ -151,7 +151,7 @@ public PropertiesProcessor getVcsPropertiesProcessor() { return new AbstractVcsPropertiesProcessor() { public Collection<InvalidProperty> process(final Map<String, String> properties) { - List<InvalidProperty> result = new ArrayList<InvalidProperty>(); + List<InvalidProperty> result = new ArrayList<>(); if (isEmpty(properties.get(Constants.HG_COMMAND_PATH_PROP))) { result.add(new InvalidProperty(Constants.HG_COMMAND_PATH_PROP, "Path to 'hg' command must be specified")); } @@ -190,7 +190,7 @@ @Nullable public Map<String, String> getDefaultVcsProperties() { - Map<String, String> defaults = new HashMap<String, String>(); + Map<String, String> defaults = new HashMap<>(); defaults.put(Constants.BRANCH_NAME_PROP, "default"); defaults.put(Constants.HG_COMMAND_PATH_PROP, "hg"); return defaults; @@ -205,13 +205,11 @@ // comparator is called when TeamCity needs to sort modifications in the order of their appearance, // currently we sort changes by revision number, not sure however that this is a good idea, // probably it would be better to sort them by timestamp (and to add timestamp into the version). - return new Comparator<String>() { - public int compare(final String o1, final String o2) { - try { - return new ChangeSet(o1).getRevNumber() - new ChangeSet(o2).getRevNumber(); - } catch (Exception e) { - return 1; - } + return (o1, o2) -> { + try { + return new ChangeSet(o1).getRevNumber() - new ChangeSet(o2).getRevNumber(); + } catch (Exception e) { + return 1; } }; } @@ -224,7 +222,7 @@ @NotNull final CheckoutRules checkoutRules) throws VcsException, IOException { final HgRepo repo = createRepo(root); final List<FileStatus> modifiedFiles = repo.status().fromRevision(fromVer).toRevision(toVer).call(); - final List<String> notDeletedFiles = new ArrayList<String>(); + final List<String> notDeletedFiles = new ArrayList<>(); for (FileStatus f: modifiedFiles) { if (f.getStatus() != Status.REMOVED) { notDeletedFiles.add(f.getPath()); @@ -517,11 +515,8 @@ builder.createDirectory(virtualFile); buildPatchFromDirectory(realFile, builder, repRoot, checkoutRules, filter); } else { - final FileInputStream is = new FileInputStream(realFile); - try { + try (FileInputStream is = new FileInputStream(realFile)) { builder.createBinaryFile(virtualFile, null, is, realFile.length()); - } finally { - is.close(); } } } else { @@ -565,7 +560,7 @@ } public void syncRepository(@NotNull final HgVcsRoot root) throws VcsException { - syncRepository(root, new SyncSettings<Void>(VcsCallable.NO_OP)); + syncRepository(root, new SyncSettings<>(VcsCallable.NO_OP)); } public <T> T syncRepository(@NotNull HgVcsRoot root, @NotNull SyncSettings<T> settings) throws VcsException { @@ -818,7 +813,7 @@ @Override public Map<String, String> getCheckoutProperties(@NotNull VcsRoot root) { Map<String, String> rootProperties = root.getProperties(); - Map<String, String> repositoryProperties = new HashMap<String, String>(); + Map<String, String> repositoryProperties = new HashMap<>(); repositoryProperties.put(Constants.REPOSITORY_PROP, rootProperties.get(Constants.REPOSITORY_PROP)); repositoryProperties.put(Constants.INCLUDE_SUBREPOS_IN_PATCH, rootProperties.get(Constants.INCLUDE_SUBREPOS_IN_PATCH)); String customHgConfig = rootProperties.get(Constants.CUSTOM_HG_CONFIG_PROP);
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataFactory.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataFactory.java Wed Aug 05 13:19:53 2020 +0300 @@ -75,7 +75,7 @@ @NotNull String prevVer, @NotNull String curVer, @NotNull CheckoutRules rules) { - final List<VcsChange> files = new ArrayList<VcsChange>(0); + final List<VcsChange> files = new ArrayList<>(0); for (FileStatus mf : modifiedFiles) { if (rules.map(mf.getPath()) == null) continue;
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/OperationContext.java Wed Aug 05 13:19:53 2020 +0300 @@ -29,7 +29,7 @@ protected final MercurialVcsSupport myVcs; protected final RepoFactory myRepoFactory; protected final MercurialProgress myProgress; - private final Map<String, HgVersion> myHgVersions = new HashMap<String, HgVersion>(); + private final Map<String, HgVersion> myHgVersions = new HashMap<>(); public OperationContext(@NotNull MercurialVcsSupport vcs, @NotNull RepoFactory repoFactory, @@ -63,7 +63,7 @@ } public <T> T syncRepository(@NotNull HgVcsRoot root, @NotNull VcsCallable<T> cmd) throws VcsException { - SyncSettings<T> settings = new SyncSettings<T>(cmd); + SyncSettings<T> settings = new SyncSettings<>(cmd); return myVcs.syncRepository(root, settings, this); }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfig.java Wed Aug 05 13:19:53 2020 +0300 @@ -29,36 +29,36 @@ @Nullable String getHgPath(); - public boolean isUsePullProtocol(); + boolean isUsePullProtocol(); int getPullTimeout(); - public boolean dontUseRevsets(); + boolean dontUseRevsets(); - public boolean detectSubrepoChanges(); + boolean detectSubrepoChanges(); - public boolean bookmarksEnabled(); + boolean bookmarksEnabled(); - public boolean useTagsAsBranches(); + boolean useTagsAsBranches(); - public int getMaxDagNodesCount(); + int getMaxDagNodesCount(); - public int getLogOutputLimit(); + int getLogOutputLimit(); - public long getMirrorExpirationTimeoutMillis(); + long getMirrorExpirationTimeoutMillis(); @Nullable - public CronExpression getCleanupCronExpression(); + CronExpression getCleanupCronExpression(); - public boolean reportSubrepoChangesFileStatus(); + boolean reportSubrepoChangesFileStatus(); - public boolean allowSourceCaching(); + boolean allowSourceCaching(); - public int listFilesTTLSeconds(); + int listFilesTTLSeconds(); - public String getMergeTool(); + String getMergeTool(); - public boolean runWithProfile(@NotNull HgVcsRoot root); + boolean runWithProfile(@NotNull HgVcsRoot root); boolean computeFromRevisions(); }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsCallable.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsCallable.java Wed Aug 05 13:19:53 2020 +0300 @@ -21,11 +21,7 @@ import java.util.concurrent.Callable; public interface VcsCallable<T> extends Callable<T> { - VcsCallable<Void> NO_OP = new VcsCallable<Void>() { - public Void call() throws VcsException { - return null; - } - }; + VcsCallable<Void> NO_OP = () -> null; - public T call() throws VcsException; + T call() throws VcsException; }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CollectChangesNoRevsets.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CollectChangesNoRevsets.java Wed Aug 05 13:19:53 2020 +0300 @@ -61,8 +61,8 @@ DAG<String> revisionIntervalDag = DAGs.createFromEdges(revisionIntervalEdges); DAGIterator<String> iter = revisionIntervalDag.iterator(toCommit); iter.markUninteresting(fromCommit); - List<ChangeSet> revisionIntervalReachableChangesets = new ArrayList<ChangeSet>(); - Set<String> missingParents = new HashSet<String>(); + List<ChangeSet> revisionIntervalReachableChangesets = new ArrayList<>(); + Set<String> missingParents = new HashSet<>(); while (iter.hasNext()) { String csetId = iter.next(); ChangeSet cset = revisionIntervalMap.get(csetId); @@ -86,7 +86,7 @@ List<ChangeSet> commitsWithFiles = getRevisionsBetween(minRevNum, fromCommit); Map<String, ChangeSet> csetMap = getChangesetMap(commitsWithFiles); csetMap.putAll(revisionIntervalMap); - List<ChangeSet> result = new ArrayList<ChangeSet>(); + List<ChangeSet> result = new ArrayList<>(); for (ChangeSet cset : csetsWithoutFiles) { ChangeSet csetWithFiles = csetMap.get(cset.getId()); if (csetWithFiles != null) @@ -104,7 +104,7 @@ DAG<String> dag = DAGs.createFromEdges(getEdges(csets)); DAGIterator<String> iter = dag.iterator(toCommit); iter.markUninteresting(fromCommit); - List<ChangeSet> result = new ArrayList<ChangeSet>(); + List<ChangeSet> result = new ArrayList<>(); int minRevNum = Integer.MAX_VALUE; while (iter.hasNext()) { String commit = iter.next(); @@ -119,14 +119,14 @@ Collections.reverse(result); return Pair.create(result, minRevNum); } else { - return new Pair<List<ChangeSet>, Integer>(Collections.<ChangeSet>emptyList(), Integer.MAX_VALUE); + return new Pair<>(Collections.<ChangeSet>emptyList(), Integer.MAX_VALUE); } } //csetId -> cset private Map<String, ChangeSet> getChangesetMap(@NotNull final List<ChangeSet> csets) { - Map<String, ChangeSet> result = new HashMap<String, ChangeSet>(csets.size()); + Map<String, ChangeSet> result = new HashMap<>(csets.size()); for (ChangeSet cset : csets) { result.put(cset.getId(), cset); } @@ -162,7 +162,7 @@ private List<Pair<String, String>> getEdges(List<ChangeSet> csets) { - List<Pair<String, String>> result = new ArrayList<Pair<String, String>>(); + List<Pair<String, String>> result = new ArrayList<>(); for (ChangeSet cset : csets) { for (ChangeSetRevision parent : cset.getParents()) { result.add(Pair.create(cset.getId(), parent.getId()));
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MergeBaseNoRevsets.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MergeBaseNoRevsets.java Wed Aug 05 13:19:53 2020 +0300 @@ -40,7 +40,7 @@ if (myRevision1.equals(myRevision2)) return myRevision1; try { - List<Pair<String, String>> edges = new ArrayList<Pair<String, String>>(); + List<Pair<String, String>> edges = new ArrayList<>(); fillEdges(edges, getRevisionsReachableFrom(myRevision1)); fillEdges(edges, getRevisionsReachableFrom(myRevision2)); DAG<String> dag = DAGs.createFromEdges(edges);
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -232,11 +232,7 @@ private File doUpdate(@NotNull final VcsRoot root, @NotNull final String version, int timeoutSeconds) throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(); - Future<File> future = executor.submit(new Callable<File>() { - public File call() throws Exception { - return doUpdate(root, version); - } - }); + Future<File> future = executor.submit(() -> doUpdate(root, version)); executor.shutdown(); executor.awaitTermination(timeoutSeconds, TimeUnit.SECONDS); if (!future.isDone()) @@ -254,7 +250,7 @@ private File doUpdate(final VcsRoot vcsRoot, final String version, final IncludeRule includeRule, boolean useLocalMirrors) throws VcsException { File actualWorkDir = new File(myWorkDir, includeRule.getTo()); - final Map<String, String> sharedConfigParameters = new HashMap<String, String>(); + final Map<String, String> sharedConfigParameters = new HashMap<>(); sharedConfigParameters.put("teamcity.hg.use.local.mirrors", String.valueOf(useLocalMirrors)); final AgentRunningBuild build = myContext.mock(AgentRunningBuild.class, "build" + myBuildCounter++); myContext.checking(new Expectations() {{
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -136,7 +136,7 @@ @TestFor(issues = "TW-39482") @RequiredHgVersion(min = "2.4") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void should_recover_from_abandoned_transaction(@NotNull HgVersion _) throws Exception { + public void should_recover_from_abandoned_transaction(@NotNull HgVersion version) throws Exception { File remoteRepo = myTempFiles.createTempDir(); Util.copyRepository(new File("mercurial-tests/testData/bookmarks/1"), remoteRepo); VcsRootImpl root = vcsRoot().withUrl(remoteRepo).build();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -68,7 +68,7 @@ @BeforeMethod public void setUp() throws Exception { super.setUp(); - myProcesses = new ArrayList<Process>(); + myProcesses = new ArrayList<>(); myOriginalRepositoriesParentDir = myTempFiles.createTempDir(); myDefaultWorkDir = new File(myOriginalRepositoriesParentDir, "agentWorkDir"); myWorkDir = myDefaultWorkDir;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BookmarksTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BookmarksTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -59,7 +59,7 @@ } - public void current_state_should_include_bookmarks(@NotNull HgVersion _) throws Exception { + public void current_state_should_include_bookmarks(@NotNull HgVersion version) throws Exception { setupRemoteRepositoryWithTwoBookmarks(); RepositoryStateData state = myVcs.getCollectChangesPolicy().getCurrentState(myRoot); assertThat(state, hasBranch("bookmark1").withRevision("15b4a116520d")); @@ -67,7 +67,7 @@ } - public void remove_bookmark_when_it_is_removed_from_remote_repo(@NotNull HgVersion _) throws Exception { + public void remove_bookmark_when_it_is_removed_from_remote_repo(@NotNull HgVersion version) throws Exception { cloneRepositoryWithTwoBookmarks(); allBookmarksRemoved(); @@ -78,7 +78,7 @@ } - public void update_bookmark_when_it_is_updated_in_remote_repo(@NotNull HgVersion _) throws Exception { + public void update_bookmark_when_it_is_updated_in_remote_repo(@NotNull HgVersion version) throws Exception { cloneRepositoryWithTwoBookmarks(); bookmark1Updated(); @@ -88,7 +88,7 @@ } - public void update_bookmark_when_it_is_deverged_in_remote_repo(@NotNull HgVersion _) throws Exception { + public void update_bookmark_when_it_is_deverged_in_remote_repo(@NotNull HgVersion version) throws Exception { cloneRepositoryWithTwoBookmarks(); bookmark1Diverged(); @@ -98,7 +98,7 @@ } - public void prefer_branch_to_bookmark_when_their_names_collide(@NotNull HgVersion _) throws Exception { + public void prefer_branch_to_bookmark_when_their_names_collide(@NotNull HgVersion version) throws Exception { cloneRepositoryWithTwoBookmarks(); branchWithNameBookmark2Created();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CleanupTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CleanupTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -16,17 +16,14 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; -import jetbrains.buildServer.TempFiles; import jetbrains.buildServer.util.FileUtil; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; import org.jetbrains.annotations.NotNull; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; -import java.io.FileFilter; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -104,16 +101,12 @@ private List<File> directoriesInside(@NotNull File dir) { - return asList(dir.listFiles(new FileFilter() { - public boolean accept(File f) { - return f.isDirectory(); - } - })); + return asList(dir.listFiles(File::isDirectory)); } private List<File> mappingsFile() throws IOException { File mappingFile = new File(myCachesDir, "map"); - List<File> files = new ArrayList<File>(); + List<File> files = new ArrayList<>(); for (String line : FileUtil.readFile(mappingFile)) { String[] fields = line.split("="); files.add(new File(mappingFile.getParentFile(), fields[1].trim())); @@ -149,7 +142,7 @@ private static <T> ContainsOnly<T> containsOnly(Collection<T> expected) { - return new ContainsOnly<T>(expected); + return new ContainsOnly<>(expected); } static class ContainsOnly<T> extends TypeSafeMatcher<Collection<T>> {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CollectChangesContextTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CollectChangesContextTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -55,7 +55,7 @@ @TestFor(issues = "TW-46340") - public void test_many_from_revisions(@NotNull HgVersion _) throws Exception { + public void test_many_from_revisions(@NotNull HgVersion version) throws Exception { //default // | branch1 // V |
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -71,28 +71,24 @@ myTestLogger.disableDebug(); } - public void simpleTest(@NotNull HgVersion _) throws IOException, VcsException { + public void simpleTest(@NotNull HgVersion version) throws IOException, VcsException { myTestLogger.enableDebug(); VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); - final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { - public void consumeCommit(@NotNull CommitInfo commit) { - commitInfos.add(commit); - } - }); + final List<CommitInfo> commitInfos = new ArrayList<>(); + mySupport.collectCommits(root, CheckoutRules.DEFAULT, commitInfos::add); Assert.assertFalse(commitInfos.isEmpty()); for (CommitInfo commitInfo : commitInfos) { System.out.println(commitInfo); } - final Set<String> branches = new TreeSet<String>(); - final Set<String> tags = new TreeSet<String>(); - final Set<String> commits = new TreeSet<String>(); - final Set<String> parents = new TreeSet<String>(); + final Set<String> branches = new TreeSet<>(); + final Set<String> tags = new TreeSet<>(); + final Set<String> commits = new TreeSet<>(); + final Set<String> parents = new TreeSet<>(); for (CommitInfo commitInfo : commitInfos) { branches.addAll(commitInfo.getBranches()); tags.addAll(commitInfo.getTags()); @@ -103,8 +99,8 @@ parents.addAll(commitInfo.getParentRevisions()); } - Assert.assertEquals(branches, new TreeSet<String>(Arrays.asList("default", "personal-branch", "test", "topic", "<TEST> Branch with exitics)(*&^%$#@!", "NULL"))); - Assert.assertEquals(tags, new TreeSet<String>(Arrays.asList("t1"))); + Assert.assertEquals(branches, new TreeSet<>(Arrays.asList("default", "personal-branch", "test", "topic", "<TEST> Branch with exitics)(*&^%$#@!", "NULL"))); + Assert.assertEquals(tags, new TreeSet<>(Arrays.asList("t1"))); //check all parent commits are included into the set Assert.assertTrue(commits.containsAll(parents), "Unknown commits: " + new TreeSet<String>(parents){{removeAll(commits);}}); @@ -113,17 +109,13 @@ Assert.assertFalse(parents.contains(v)); } - public void should_not_have_parse_errors(@NotNull HgVersion _) throws IOException, VcsException { + public void should_not_have_parse_errors(@NotNull HgVersion version) throws IOException, VcsException { myTestLogger.enableDebug(); VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); - final List<CommitInfo> commitInfos = new ArrayList<CommitInfo>(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { - public void consumeCommit(@NotNull CommitInfo commit) { - commitInfos.add(commit); - } - }); + final List<CommitInfo> commitInfos = new ArrayList<>(); + mySupport.collectCommits(root, CheckoutRules.DEFAULT, commitInfos::add); Assert.assertFalse(commitInfos.isEmpty()); for (CommitInfo commitInfo : commitInfos) { @@ -131,7 +123,7 @@ } } - private void should_return_subrepos_graphcommits(@NotNull HgVersion _) throws Exception { + private void should_return_subrepos_graphcommits(@NotNull HgVersion version) throws Exception { myRemoteRepo = myTempFiles.createTempDir(); copyRepository(new File("mercurial-tests/testData/subrepos/r1"), myRemoteRepo); @@ -139,10 +131,8 @@ final AtomicBoolean hasSubRepo = new AtomicBoolean(false); final long start = System.currentTimeMillis(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { - public void consumeCommit(@NotNull CommitInfo commit) { - if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); - } + mySupport.collectCommits(root, CheckoutRules.DEFAULT, commit -> { + if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); }); final long actual = System.currentTimeMillis() - start; @@ -152,15 +142,13 @@ } @Test(enabled = false) - public void should_return_graphcommits(@NotNull HgVersion _) throws Exception { + public void should_return_graphcommits(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withLocalRepository(new File("F:\\Work\\ReSharper")).build(); final AtomicBoolean hasSubRepo = new AtomicBoolean(false); final long start = System.currentTimeMillis(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, new CommitsInfoBuilder.CommitsConsumer() { - public void consumeCommit(@NotNull CommitInfo commit) { - if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); - } + mySupport.collectCommits(root, CheckoutRules.DEFAULT, commit -> { + if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); }); final long actual = System.currentTimeMillis() - start;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ExtensionsTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ExtensionsTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -38,7 +38,7 @@ public class ExtensionsTest extends BaseMercurialTestCase { @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void test_no_extension(HgVersion _) throws IOException, VcsException { + public void test_no_extension(HgVersion version) throws IOException, VcsException { String extension = "HGExtensionThatDoesNotExits"; try { @@ -50,7 +50,7 @@ } @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void test_extension(HgVersion _) throws IOException, VcsException { + public void test_extension(HgVersion version) throws IOException, VcsException { runWithExtensions("mq", "largefiles"); }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtilTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgFileUtilTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -44,19 +44,17 @@ @TestFor(issues = "TW-30589") public void createTempFile_should_always_return_unique_dir() throws Exception { final CountDownLatch allThreadsInitialized = new CountDownLatch(1); - final Set<File> tmpFiles = new HashSet<File>(); - Runnable createTmpFile = new Runnable() { - public void run() { - try { - allThreadsInitialized.await(); - tmpFiles.add(HgFileUtil.createTempDir()); - } catch (Exception e) { - e.printStackTrace(); - } + final Set<File> tmpFiles = new HashSet<>(); + Runnable createTmpFile = () -> { + try { + allThreadsInitialized.await(); + tmpFiles.add(HgFileUtil.createTempDir()); + } catch (Exception e) { + e.printStackTrace(); } }; - List<Thread> threads = new ArrayList<Thread>(); + List<Thread> threads = new ArrayList<>(); for (int i = 0; i < 50; i++) { Thread t = new Thread(createTmpFile); t.start();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupportTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupportTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -64,7 +64,7 @@ } - public void test_commit(@NotNull HgVersion _) throws Exception { + public void test_commit(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRepo).build(); RepositoryStateData beforeCommit = myVcs.getCollectChangesPolicy().getCurrentState(root); @@ -95,7 +95,7 @@ @TestFor(issues = "TW-39095") - public void commit_with_non_ascii_commit_message(@NotNull HgVersion _) throws Exception { + public void commit_with_non_ascii_commit_message(@NotNull HgVersion version) throws Exception { for (String msg : new String[] {"Комит месадж", "Über Alles"}) { commit(msg); } @@ -103,7 +103,7 @@ @TestFor(issues = "TW-39321") - public void should_throw_meaningful_error_if_destination_branch_doesnt_exist(@NotNull HgVersion _) throws Exception { + public void should_throw_meaningful_error_if_destination_branch_doesnt_exist(@NotNull HgVersion version) throws Exception { String nonExistingBranch = "nonExisting"; VcsRoot root = vcsRoot().withUrl(myRepo).withBranch(nonExistingBranch).build(); String description = "msg"; @@ -120,7 +120,7 @@ @TestFor(issues = "TW-39321") - public void should_create_branch_if_repository_has_no_branches(@NotNull HgVersion _) throws Exception { + public void should_create_branch_if_repository_has_no_branches(@NotNull HgVersion version) throws Exception { File emptyRemoteRepo = myTempFiles.createTempDir(); ServerHgRepo repo = new ServerHgRepo(new TestCommandSettingsFactory(), myPluginConfig, emptyRemoteRepo, getHgPath(), new AuthSettings()); repo.init().call(); @@ -144,7 +144,7 @@ return new ByteArrayInputStream(content.getBytes()); } - private class CommitSettingsImpl implements CommitSettings { + private static class CommitSettingsImpl implements CommitSettings { private final String myUserName; private final String myDescription;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java Wed Aug 05 13:19:53 2020 +0300 @@ -38,7 +38,7 @@ private Mockery myContext; private ServerPluginConfig myConfig; - private List<MercurialServerExtension> myExtensions = new ArrayList<MercurialServerExtension>(); + private List<MercurialServerExtension> myExtensions = new ArrayList<>(); private HgVcsRootFactory myHgRootFactory; private RepoFactory myRepoFactory; private ServerHgPathProvider myHgPathProvider;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -28,7 +28,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.util.*; @@ -141,11 +140,7 @@ File clonedReposParentDir = myPluginConfig.getCachesDir(); assertTrue(clonedReposParentDir.isDirectory()); - assertTrue(1 == clonedReposParentDir.list(new FilenameFilter() { - public boolean accept(final File dir, final String name) { - return name.startsWith("hg_"); - } - }).length); + assertTrue(1 == clonedReposParentDir.list((dir, name) -> name.startsWith("hg_")).length); } public void test_build_incremental_patch() throws IOException, VcsException { @@ -391,7 +386,7 @@ @RequiredHgVersion(min = "2.7") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion", enabled = false) - public void unicode_in_filename(@NotNull HgVersion _) throws Exception { + public void unicode_in_filename(@NotNull HgVersion version) throws Exception { File repo = copyRepository(myTempFiles, new File("mercurial-tests/testData/unicodeFileName").getAbsolutePath()); VcsRoot root = vcsRoot().withUrl(repo.getAbsolutePath()) .withSubrepoChanges(false) @@ -758,7 +753,7 @@ @RequiredHgVersion(min = "1.7.0") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void should_not_report_redundant_changes_after_merge(@NotNull HgVersion _) throws Exception { + public void should_not_report_redundant_changes_after_merge(@NotNull HgVersion version) throws Exception { VcsRootImpl root = createVcsRoot(myRep2Path); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, RepositoryStateData.createVersionState("default", map("default", "505c5b9d01e6", "personal-branch", "9ec402c74298")), @@ -770,7 +765,7 @@ @RequiredHgVersion(min = "1.7.0") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void should_not_report_duplicate_changes(@NotNull HgVersion _) throws Exception { + public void should_not_report_duplicate_changes(@NotNull HgVersion version) throws Exception { VcsRootImpl root = createVcsRoot(myRep2Path); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, RepositoryStateData.createVersionState("default", map("default", "505c5b9d01e6", "personal-branch", "96b78d73081d")), @@ -782,7 +777,7 @@ @RequiredHgVersion(min = "1.7.0") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void should_not_report_duplicate_changes2(@NotNull HgVersion _) throws Exception { + public void should_not_report_duplicate_changes2(@NotNull HgVersion version) throws Exception { VcsRootImpl root = createVcsRoot(myRep2Path); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, RepositoryStateData.createVersionState("default", map("default", "528572bbf77b", "personal-branch", "27184c50d7ef")), @@ -794,7 +789,7 @@ @RequiredHgVersion(min = "1.7.0") @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") - public void should_not_report_all_changes_in_repository_if_default_branch_is_unrelated(@NotNull HgVersion _) throws Exception { + public void should_not_report_all_changes_in_repository_if_default_branch_is_unrelated(@NotNull HgVersion version) throws Exception { VcsRootImpl root = createVcsRoot(myRep2Path); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, RepositoryStateData.createVersionState("NULL", map("NULL", "1f355761350e")), @@ -816,11 +811,11 @@ private void assertFiles(final List<String> expectedFiles, final ModificationData modificationData) { - Set<String> actualFiles = new HashSet<String>(); + Set<String> actualFiles = new HashSet<>(); for (VcsChange vc: modificationData.getChanges()) { actualFiles.add(toFileStatus(vc.getType()) + " " + vc.getRelativeFileName()); } - Assert.assertEquals("Actual files: " + actualFiles.toString(), new HashSet<String>(expectedFiles), actualFiles); + Assert.assertEquals("Actual files: " + actualFiles.toString(), new HashSet<>(expectedFiles), actualFiles); } private String toFileStatus(VcsChange.Type type) {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialXmlLogParserTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialXmlLogParserTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -23,6 +23,7 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.*; @@ -33,32 +34,30 @@ @TestFor(issues = {"TW-24864", "TW-24214"}) public void parse_date() throws Exception { final SAXParserFactory saxFactory = SAXParserFactory.newInstance(); - final List<Exception> errors = new ArrayList<Exception>(); + final List<Exception> errors = new ArrayList<>(); final CountDownLatch countDown = new CountDownLatch(1); - Runnable parseLog = new Runnable() { - public void run() { - try { - countDown.await(); - MercurialXmlLogParser parser = new MercurialXmlLogParser(); - SAXParser saxParser = saxFactory.newSAXParser(); - String logOutput = - "<?xml version=\"1.0\"?>" + - "<log>" + - "<logentry revision=\"11774\" shortnode=\"b1b6ed3cd705\">" + - "<parent revision=\"11770\" shortnode=\"7e30fc4a3cda\"/>" + - "<author original=\"Mikhail.Pilin\"/>" + - "<date>Fri Dec 14 12:22:31 2012 +0100</date>" + - "<msg xml:space=\"preserve\">Fix SDK installer.</msg>" + - "<paths>" + - "<path action=\"M\">.hgsubstate</path>" + - "</paths>" + - "</logentry>" + - "</log>"; - saxParser.parse(new ByteArrayInputStream(logOutput.getBytes("UTF-8")), parser); - parser.getChangeSets(); - } catch (Exception e) { - errors.add(e); - } + Runnable parseLog = () -> { + try { + countDown.await(); + MercurialXmlLogParser parser = new MercurialXmlLogParser(); + SAXParser saxParser = saxFactory.newSAXParser(); + String logOutput = + "<?xml version=\"1.0\"?>" + + "<log>" + + "<logentry revision=\"11774\" shortnode=\"b1b6ed3cd705\">" + + "<parent revision=\"11770\" shortnode=\"7e30fc4a3cda\"/>" + + "<author original=\"Mikhail.Pilin\"/>" + + "<date>Fri Dec 14 12:22:31 2012 +0100</date>" + + "<msg xml:space=\"preserve\">Fix SDK installer.</msg>" + + "<paths>" + + "<path action=\"M\">.hgsubstate</path>" + + "</paths>" + + "</logentry>" + + "</log>"; + saxParser.parse(new ByteArrayInputStream(logOutput.getBytes(StandardCharsets.UTF_8)), parser); + parser.getChangeSets(); + } catch (Exception e) { + errors.add(e); } };
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MergeSupportTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MergeSupportTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -59,14 +59,14 @@ } - public void should_return_succesful_result_when_merge_succeeds(@NotNull HgVersion _) throws Exception { + public void should_return_succesful_result_when_merge_succeeds(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); MergeResult mergeResult = myMergeSupport.merge(root, "2742914d19b2", "default", "merge topic1 into default", new MergeOptions()); assertTrue(mergeResult.isSuccess()); } - public void result_of_succesful_merge_should_appear_in_remote_repository(@NotNull HgVersion _) throws Exception { + public void result_of_succesful_merge_should_appear_in_remote_repository(@NotNull HgVersion version) throws Exception { final String mergeDestinationBranch = "default"; final String mergeCommitMessage = "merge topic1 into default"; @@ -85,7 +85,7 @@ } - public void should_return_unsuccesful_result_when_merge_fails(@NotNull HgVersion _) throws Exception { + public void should_return_unsuccesful_result_when_merge_fails(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); MergeResult mergeResult = myMergeSupport.merge(root, "79d836707416", "default", "merge topic2 into default", new MergeOptions()); assertFalse(mergeResult.isSuccess()); @@ -93,7 +93,7 @@ } - public void result_of_failed_merge_should_not_appear_in_remote_repository(@NotNull HgVersion _) throws Exception { + public void result_of_failed_merge_should_not_appear_in_remote_repository(@NotNull HgVersion version) throws Exception { final String mergeDestinationBranch = "default"; VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); @@ -108,7 +108,7 @@ } - public void try_merge_returns_correct_result_for_every_task(@NotNull HgVersion _) throws Exception { + public void try_merge_returns_correct_result_for_every_task(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); final MergeTask topic1ToDefault = new MergeTask("2742914d19b2", "09dd527b77ec"); @@ -123,7 +123,7 @@ } - public void merge_into_same_branch(@NotNull HgVersion _) throws Exception { + public void merge_into_same_branch(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); MergeResult result = myMergeSupport.merge(root, "6370ce18689a", "default", "merge into same branch", new MergeOptions()); assertTrue(result.isSuccess());
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MirrorManagerTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MirrorManagerTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -17,7 +17,6 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.util.Hash; -import org.jetbrains.annotations.NotNull; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -43,12 +42,7 @@ public void setUp() throws Exception { super.setUp(); myRootDir = myTempFiles.createTempDir(); - myManager = new MirrorManagerImpl(new PluginConfig() { - @NotNull - public File getCachesDir() { - return myRootDir; - } - }); + myManager = new MirrorManagerImpl(() -> myRootDir); } @@ -84,34 +78,22 @@ final String url1 = "hg://some.com/repository.hg"; final String url2 = "hg://other.com/repository.hg"; - MirrorManagerImpl.HashCalculator hashWithCollision = new MirrorManagerImpl.HashCalculator() { - public long calc(String value) { - if (value.equals(url1) || value.equals(url2)) { - return 0;//emulate collision - } else { - return Hash.calc(value); - } + MirrorManagerImpl.HashCalculator hashWithCollision = value -> { + if (value.equals(url1) || value.equals(url2)) { + return 0;//emulate collision + } else { + return Hash.calc(value); } }; //alone they get dir with the same name: final File dir1 = myTempFiles.createTempDir(); - MirrorManagerImpl mm1 = new MirrorManagerImpl(new PluginConfig() { - @NotNull - public File getCachesDir() { - return dir1; - } - }); + MirrorManagerImpl mm1 = new MirrorManagerImpl(() -> dir1); mm1.setHashCalculator(hashWithCollision); File separateMirrorDir1 = mm1.getMirrorDir(url1); final File dir2 = myTempFiles.createTempDir(); - MirrorManagerImpl mm2 = new MirrorManagerImpl(new PluginConfig() { - @NotNull - public File getCachesDir() { - return dir2; - } - }); + MirrorManagerImpl mm2 = new MirrorManagerImpl(() -> dir2); mm2.setHashCalculator(hashWithCollision); File separateMirrorDir2 = mm2.getMirrorDir(url2); @@ -131,12 +113,7 @@ File mirrorDir2 = myManager.getMirrorDir(url2); //emulate restart by creating a new manager for the same rootDir - MirrorManagerImpl manager = new MirrorManagerImpl(new PluginConfig() { - @NotNull - public File getCachesDir() { - return myRootDir; - } - }); + MirrorManagerImpl manager = new MirrorManagerImpl(() -> myRootDir); assertEquals(2, manager.getMirrors().size()); assertTrue(manager.getMirrors().contains(mirrorDir1));
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataMatcher.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ModificationDataMatcher.java Wed Aug 05 13:19:53 2020 +0300 @@ -31,8 +31,8 @@ private String myVersion; private String myDescription; - private Map<String, String> myVcsRootProperties = new HashMap<String, String>(); - private Map<String, String> myAttributes = new HashMap<String, String>(); + private Map<String, String> myVcsRootProperties = new HashMap<>(); + private Map<String, String> myAttributes = new HashMap<>(); private List<String> myParentRevisions; @Override
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -69,14 +69,14 @@ } - public void should_report_changes_from_subrepos(@NotNull HgVersion _) throws Exception { + public void should_report_changes_from_subrepos(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo1.getAbsolutePath()).withSubrepoChanges(true).build(); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, "d350e7209906", "09c256b6163e", CheckoutRules.DEFAULT); assertEquals(4, changes.size()); } - public void should_include_from_revisions_into_changes_from_subrepos(@NotNull HgVersion _) throws Exception { + public void should_include_from_revisions_into_changes_from_subrepos(@NotNull HgVersion version) throws Exception { //otherwise TeamCity won't show changes from subrepos in UI VcsRoot root = vcsRoot().withUrl(myRemoteRepo1.getAbsolutePath()).withSubrepoChanges(true).build(); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, "d350e7209906", "09c256b6163e", CheckoutRules.DEFAULT); @@ -84,35 +84,35 @@ } - public void should_not_report_any_changes_when_subrepo_removed(@NotNull HgVersion _) throws Exception { + public void should_not_report_any_changes_when_subrepo_removed(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo1.getAbsolutePath()).withSubrepoChanges(true).build(); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, "34017377d9c3", "4d7b3db8779f", CheckoutRules.DEFAULT); assertEquals(1, changes.size()); } - public void should_not_report_any_changes_when_subrepo_added(@NotNull HgVersion _) throws Exception { + public void should_not_report_any_changes_when_subrepo_added(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo1.getAbsolutePath()).withSubrepoChanges(true).build(); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, "4d7b3db8779f", "d350e7209906", CheckoutRules.DEFAULT); assertEquals(1, changes.size()); } - public void should_report_subrepo_changes_recursevly(@NotNull HgVersion _) throws Exception { + public void should_report_subrepo_changes_recursevly(@NotNull HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepo1.getAbsolutePath()).withSubrepoChanges(true).build(); List<ModificationData> changes = myVcs.getCollectChangesPolicy().collectChanges(root, "09c256b6163e", "d64d9799c143", CheckoutRules.DEFAULT); assertEquals(7, changes.size()); assertThat(changes, hasItem(modificationData().withVersion("d64d9799c143").withVcsRootProperties(root.getProperties()))); - Map<String, String> s1props = new HashMap<String, String>(root.getProperties()); + Map<String, String> s1props = new HashMap<>(root.getProperties()); s1props.put("teamcity.internal.subrepo.path", "r2"); s1props.put(Constants.REPOSITORY_PROP, myRemoteRepo3.getCanonicalPath()); s1props.put("teamcity.internal.subrepo", "true"); assertThat(changes, hasItem(modificationData().withVersion("514c3e09cddf").withVcsRootProperties(s1props))); assertThat(changes, hasItem(modificationData().withVersion("1f9eb39a3921").withVcsRootProperties(s1props))); - Map<String, String> s2props = new HashMap<String, String>(root.getProperties()); + Map<String, String> s2props = new HashMap<>(root.getProperties()); s2props.put("teamcity.internal.subrepo.path", "r2/r2"); s2props.put(Constants.REPOSITORY_PROP, myRemoteRepo2.getCanonicalPath()); s2props.put("teamcity.internal.subrepo", "true"); @@ -121,7 +121,7 @@ } - public void report_subrepo_changes_without_revsets(@NotNull HgVersion _) throws Exception { + public void report_subrepo_changes_without_revsets(@NotNull HgVersion version) throws Exception { ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() .cachesDir(myTempFiles.createTempDir()) .detectSubrepoChanges(true) @@ -134,7 +134,7 @@ } - public void report_subrepo_changes(@NotNull HgVersion _) throws Exception { + public void report_subrepo_changes(@NotNull HgVersion version) throws Exception { ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() .cachesDir(myTempFiles.createTempDir()) .detectSubrepoChanges(true) @@ -147,7 +147,7 @@ assertThat(changes, hasItem(modificationData().withVersion("d64d9799c143").withVcsRootProperties(root.getProperties()))); - Map<String, String> subrepoRootProperties = new HashMap<String, String>(root.getProperties()); + Map<String, String> subrepoRootProperties = new HashMap<>(root.getProperties()); subrepoRootProperties.put("teamcity.internal.subrepo.path", "r2"); subrepoRootProperties.put(Constants.REPOSITORY_PROP, myRemoteRepo3.getCanonicalPath()); subrepoRootProperties.put("teamcity.internal.subrepo", "true"); @@ -156,7 +156,7 @@ } - public void report_subrepo_revision_in_each_main_root_commit(@NotNull HgVersion _) throws Exception { + public void report_subrepo_revision_in_each_main_root_commit(@NotNull HgVersion version) throws Exception { ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() .cachesDir(myTempFiles.createTempDir()) .detectSubrepoChanges(true) @@ -212,7 +212,7 @@ assertThat(changes, hasItem(modificationData().withVersion("514c3e09cddf").withAttributes(builder.buildAttributes()))); } - public void should_retrieve_subrepo_config_only_when_necessary(@NotNull HgVersion _) throws Exception { + public void should_retrieve_subrepo_config_only_when_necessary(@NotNull HgVersion version) throws Exception { //Every commit from a main repository has a table of subrepo revisions. //To build this table we call hg cat .hgsub .hgsubstate. -r <main root revision> //When main repository has a lot of new changes (thousands) calling 'hg cat'
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/TagsTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/TagsTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -50,27 +50,27 @@ Util.copyRepository(new File("mercurial-tests/testData/tags"), myRemoteRepository); } - public void no_tags_reported_by_default(HgVersion _) throws Exception { + public void no_tags_reported_by_default(HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).build(); RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); assertThat(state, not(hasBranch("v1").withRevision("fa7ad5b80a88"))); assertThat(state, not(hasBranch("v4").withRevision("f7fbcc489e40"))); } - public void should_report_tag_revisions(HgVersion _) throws Exception { + public void should_report_tag_revisions(HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); assertThat(state, hasBranch("v1").withRevision("fa7ad5b80a88")); assertThat(state, hasBranch("v4").withRevision("f7fbcc489e40")); } - public void branch_has_higher_precedence_over_tag(HgVersion _) throws Exception { + public void branch_has_higher_precedence_over_tag(HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); assertThat(state, hasBranch("topic").withRevision("efde33cd0b66")); } - public void tags_can_be_turned_off_globally(HgVersion _) throws Exception { + public void tags_can_be_turned_off_globally(HgVersion version) throws Exception { myConfig.withTagsAsBranches(false); VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); @@ -78,7 +78,7 @@ assertThat(state, not(hasBranch("v4").withRevision("f7fbcc489e40"))); } - public void tags_should_not_include_tip(HgVersion _) throws Exception { + public void tags_should_not_include_tip(HgVersion version) throws Exception { VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withTagsEnabled(true).build(); RepositoryStateData state = getVcs().getCollectChangesPolicy().getCurrentState(root); assertThat(state, hasNoBranch("tip"));
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Wed Aug 05 13:19:53 2020 +0300 @@ -62,7 +62,7 @@ vcsRoot.addProperty(Constants.USE_ARCHIVE_FOR_PATCH, String.valueOf(myUseArchiveForPatch)); vcsRoot.addProperty(Constants.HG_EXTENSIONS, myExtensions); if (myCloneRepositoryTo != null) - vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, String.valueOf(myCloneRepositoryTo.getAbsolutePath())); + vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, myCloneRepositoryTo.getAbsolutePath()); vcsRoot.addProperty(Constants.USE_TAGS_AS_BRANCHES, String.valueOf(myTagsAsBranches)); if (myPurgePolicy != null) vcsRoot.addProperty(Constants.PURGE_POLICY, myPurgePolicy.name());
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTestCase.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTestCase.java Wed Aug 05 13:19:53 2020 +0300 @@ -54,7 +54,7 @@ } protected <T> T runCommand(CommandExecutor<T> executor) throws IOException, VcsException { - Map<String, String> vcsRootProps = new HashMap<String, String>(); + Map<String, String> vcsRootProps = new HashMap<>(); vcsRootProps.put(Constants.REPOSITORY_PROP, myRepository);
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommandTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CatCommandTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -16,7 +16,6 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgPathProvider; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.UnknownFileException; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.vcs.VcsException; @@ -24,7 +23,6 @@ import org.testng.annotations.Test; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.util.List; @@ -54,11 +52,9 @@ public void should_not_throw_exception_if_not_asked_to() throws IOException, VcsException { cleanCatResultDirs(); setRepository("mercurial-tests/testData/rep1", true); - runCommand(new CommandExecutor<File>() { - public File execute(@NotNull HgVcsRoot root, @NotNull HgPathProvider hgPathProvider, @NotNull File workingDir) throws VcsException { - return new CatCommand(new CommandSettings(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()).files("/non/existing/path").checkForFailure(false).call(); - } - }); + runCommand((root, hgPathProvider, workingDir) -> + new CatCommand(new CommandSettings(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) + .files("/non/existing/path").checkForFailure(false).call()); } private void cleanCatResultDirs() { @@ -73,20 +69,14 @@ private File[] getCatResultDirs() { String tempDirPath = FileUtil.getTempDirectory(); - return new File(tempDirPath).listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.startsWith("mercurial") && name.endsWith("catresult"); - } - }); + return new File(tempDirPath).listFiles((dir, name) -> name.startsWith("mercurial") && name.endsWith("catresult")); } @NotNull private File runCat(@NotNull final List<String> paths) throws IOException, VcsException { - return runCommand(new CommandExecutor<File>() { - public File execute(@NotNull HgVcsRoot root, @NotNull HgPathProvider hgPathProvider, @NotNull File workingDir) throws VcsException { - final CatCommand cat = new CatCommand(new CommandSettings(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()); - return cat.files(paths).checkForFailure(true).call(); - } + return runCommand((root, hgPathProvider, workingDir) -> { + CatCommand cat = new CatCommand(new CommandSettings(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()); + return cat.files(paths).checkForFailure(true).call(); }); } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -181,15 +181,15 @@ @NotNull CommandResult commandResultFor(@NotNull String command, @NotNull ExecResultBuilder builder, String... privateData) { - return new CommandResult(myLogger, command, builder.build(), new HashSet<String>(Arrays.asList(privateData)), new CommandSettings(), "/path/to/command/dir"); + return new CommandResult(myLogger, command, builder.build(), new HashSet<>(Arrays.asList(privateData)), new CommandSettings(), "/path/to/command/dir"); } @NotNull CommandResult commandResultFor(@NotNull ExecResultBuilder builder, CommandSettings settings) { - return new CommandResult(myLogger, "", builder.build(), new HashSet<String>(), settings, "/path/to/command/dir"); + return new CommandResult(myLogger, "", builder.build(), new HashSet<>(), settings, "/path/to/command/dir"); } - private class ExecResultBuilder { + private static class ExecResultBuilder { private String myStdout = ""; private String myStderr = ""; private Throwable myException = null; @@ -235,9 +235,9 @@ } } - private class RecordingLogger extends Logger { + private static class RecordingLogger extends Logger { - private List<String> myMessages = new ArrayList<String>(); + private List<String> myMessages = new ArrayList<>(); public boolean contains(@NotNull String entry) { for (String message : myMessages) {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommandParserTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommandParserTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -22,8 +22,6 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; @@ -39,7 +37,7 @@ @Test public void test_parse_commits_a() throws IOException { - final List<String> log = new ArrayList<String>(); + final List<String> log = new ArrayList<>(); CommitsAndMountPointsParser.parseCommits(new File("./mercurial-tests/testData/subst/a.commits"), proxy(CommitsAndMountPointsParser.CommitsConsumer.class, log)); for (String s : log) { @@ -59,7 +57,7 @@ @Test public void test_parse_files_a() throws IOException { - final List<String> log = new ArrayList<String>(); + final List<String> log = new ArrayList<>(); CommitsAndMountPointsParser.parseFileLog(new File("./mercurial-tests/testData/subst/a.files"), proxy(CommitsAndMountPointsParser.ContentsConsumer.class, log)); for (String s : log) { @@ -74,15 +72,13 @@ @NotNull private <T> T proxy(@NotNull final Class<T> clazz, @NotNull final List<String> log) { - return clazz.cast(Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{clazz}, new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - for (int i = 0; i < args.length; i++) { - Object arg = args[i]; - if (arg instanceof Date) args[i] = ((Date) arg).getTime(); - } - log.add(method.getName() + " " + Arrays.deepToString(args)); - return null; + return clazz.cast(Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{clazz}, (proxy, method, args) -> { + for (int i = 0; i < args.length; i++) { + Object arg = args[i]; + if (arg instanceof Date) args[i] = ((Date) arg).getTime(); } + log.add(method.getName() + " " + Arrays.deepToString(args)); + return null; })); } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommandTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommandTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -16,7 +16,6 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; import jetbrains.buildServer.TempFiles; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgPathProvider; import jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialClasspathTemplate; import jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialTemplate; import jetbrains.buildServer.vcs.VcsException; @@ -25,7 +24,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.List; @@ -153,7 +151,7 @@ private Map<String, ChangeSet> createChangeSetMap(@NotNull List<ChangeSet> csets) { - Map<String, ChangeSet> result = new HashMap<String, ChangeSet>(); + Map<String, ChangeSet> result = new HashMap<>(); for (ChangeSet cset : csets) { result.put(cset.getId(), cset); } @@ -172,15 +170,12 @@ private List<ChangeSet> runLog(final String fromId, final String toId) throws IOException, VcsException { - return runCommand(new CommandExecutor<List<ChangeSet>>() { - public List<ChangeSet> execute(@NotNull HgVcsRoot root, @NotNull HgPathProvider hgPathProvider, @NotNull File workingDir) throws VcsException { - return new LogCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) - .inBranch(root.getBranchName()) - .withTemplate(myTemplateFile) - .fromRevision(fromId) - .toRevision(toId) - .call(); - } - }); + return runCommand((root, hgPathProvider, workingDir) -> + new LogCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) + .inBranch(root.getBranchName()) + .withTemplate(myTemplateFile) + .fromRevision(fromId) + .toRevision(toId) + .call()); } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommandTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommandTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -15,12 +15,9 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgPathProvider; import jetbrains.buildServer.vcs.VcsException; -import org.jetbrains.annotations.NotNull; import org.testng.annotations.Test; -import java.io.File; import java.io.IOException; /** @@ -35,11 +32,10 @@ setPassword(password); try { - runCommand(new CommandExecutor<Boolean>() { - public Boolean execute(@NotNull HgVcsRoot root, @NotNull HgPathProvider hgPathProvider, @NotNull File workingDir) throws VcsException { - new PushCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()).toRepository(root.getRepository()).call(); - return null; - } + runCommand((CommandExecutor<Boolean>) (root, hgPathProvider, workingDir) -> { + new PushCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) + .toRepository(root.getRepository()).call(); + return null; }); } catch (VcsException e) { assertFalse(e.getMessage().contains(password));
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommandTest.java Mon Jun 15 13:07:12 2020 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommandTest.java Wed Aug 05 13:19:53 2020 +0300 @@ -15,9 +15,7 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgPathProvider; import jetbrains.buildServer.vcs.VcsException; -import org.jetbrains.annotations.NotNull; import org.testng.annotations.Test; import java.io.File; @@ -54,14 +52,11 @@ } private List<FileStatus> runStatus(final String fromId, final String toId) throws IOException, VcsException { - return runCommand(new CommandExecutor<List<FileStatus>>() { - public List<FileStatus> execute(@NotNull HgVcsRoot root, @NotNull HgPathProvider hgPathProvider, @NotNull File workingDir) throws VcsException { - return new StatusCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) - .fromRevision(fromId) - .toRevision(toId) - .call(); - } - }); + return runCommand((root, hgPathProvider, workingDir) -> + new StatusCommand(myCommandSettingsFactory.create(), hgPathProvider.getHgPath(root), workingDir, root.getAuthSettings()) + .fromRevision(fromId) + .toRevision(toId) + .call()); } }