mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 10:16:16 +01:00
refactor: replace anonymous types with lambdas
This commit is contained in:
@@ -35,11 +35,8 @@ package sonia.scm.repository.api;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.io.DeepCopy;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.PreProcessorUtil;
|
||||
@@ -47,11 +44,12 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.spi.HookChangesetProvider;
|
||||
import sonia.scm.repository.spi.HookChangesetRequest;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The {@link HookChangesetBuilder} is able to return all {@link Changeset}s
|
||||
@@ -120,35 +118,26 @@ public final class HookChangesetBuilder
|
||||
|
||||
if (!disablePreProcessors)
|
||||
{
|
||||
changesets = Iterables.transform(changesets,
|
||||
new Function<Changeset, Changeset>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Changeset apply(Changeset c)
|
||||
{
|
||||
final Function<Changeset, Changeset> changesetFunction = c -> {
|
||||
Changeset copy = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
copy = DeepCopy.copy(c);
|
||||
preProcessorUtil.prepareForReturn(repository, copy,
|
||||
!disableEscaping);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
logger.error("could not create a copy of changeset", ex);
|
||||
}
|
||||
|
||||
if (copy == null)
|
||||
{
|
||||
if (copy == null) {
|
||||
copy = c;
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
changesets = StreamSupport.stream(changesets.spliterator(), false)
|
||||
.map(changesetFunction::apply)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return changesets;
|
||||
|
||||
@@ -34,24 +34,20 @@ package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -94,12 +90,7 @@ public class GitBranchesCommand extends AbstractGitCommand
|
||||
{
|
||||
List<Ref> refs = git.branchList().call();
|
||||
|
||||
branches = Lists.transform(refs, new Function<Ref, Branch>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Branch apply(Ref ref)
|
||||
{
|
||||
branches = Lists.transform(refs, ref -> {
|
||||
Branch branch = null;
|
||||
String branchName = GitUtil.getBranch(ref);
|
||||
|
||||
@@ -109,7 +100,6 @@ public class GitBranchesCommand extends AbstractGitCommand
|
||||
}
|
||||
|
||||
return branch;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -40,17 +40,9 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Branches;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.*;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.template.Template;
|
||||
@@ -63,16 +55,16 @@ import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -311,15 +303,9 @@ public class GitRepositoryViewer
|
||||
.getChangesets();
|
||||
|
||||
Iterable<ChangesetModel> changesets =
|
||||
Iterables.transform(cpr, new Function<Changeset,ChangesetModel>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public ChangesetModel apply(Changeset changeset)
|
||||
{
|
||||
return new ChangesetModel(changeset);
|
||||
}
|
||||
});
|
||||
StreamSupport.stream(cpr.spliterator(), false)
|
||||
.map(ChangesetModel::new)
|
||||
.collect(Collectors.toList());
|
||||
//J+
|
||||
|
||||
model = new BranchModel(name, changesets);
|
||||
|
||||
@@ -37,35 +37,31 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.api.CommitCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.ScmTransportProtocol;
|
||||
import org.eclipse.jgit.transport.Transport;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -122,23 +118,7 @@ public class AbstractRemoteCommandTestBase
|
||||
{
|
||||
|
||||
// store reference to handle weak references
|
||||
proto = new ScmTransportProtocol(new Provider<HookEventFacade>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public HookEventFacade get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}, new Provider<GitRepositoryHandler>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public GitRepositoryHandler get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
proto = new ScmTransportProtocol(() -> null, () -> null);
|
||||
Transport.register(proto);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,21 +37,18 @@ package sonia.scm.installer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.RegistryUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -222,14 +219,7 @@ public class WindowsHgInstaller extends AbstractHgInstaller
|
||||
private boolean checkForOptimizedByteCode(String part)
|
||||
{
|
||||
File libDir = new File(part);
|
||||
String[] pyoFiles = libDir.list(new FilenameFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File file, String name)
|
||||
{
|
||||
return name.toLowerCase().endsWith(".pyo");
|
||||
}
|
||||
});
|
||||
String[] pyoFiles = libDir.list((file, name) -> name.toLowerCase().endsWith(".pyo"));
|
||||
|
||||
return Util.isNotEmpty(pyoFiles);
|
||||
}
|
||||
|
||||
@@ -37,26 +37,18 @@ package sonia.scm.repository;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
import sonia.scm.web.HgUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -232,11 +224,7 @@ public class AbstractHgHandler
|
||||
{
|
||||
if (errorStream != null)
|
||||
{
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
new Thread(() -> {
|
||||
try
|
||||
{
|
||||
String content = IOUtil.getContent(errorStream);
|
||||
@@ -250,7 +238,6 @@ public class AbstractHgHandler
|
||||
{
|
||||
logger.error("error during logging", ex);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,20 +36,17 @@ package sonia.scm.repository.spi;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.aragost.javahg.Changeset;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import sonia.scm.repository.Branch;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -87,26 +84,18 @@ public class HgBranchesCommand extends AbstractCommand
|
||||
List<com.aragost.javahg.commands.Branch> hgBranches =
|
||||
com.aragost.javahg.commands.BranchesCommand.on(open()).execute();
|
||||
|
||||
List<Branch> branches = Lists.transform(hgBranches,
|
||||
new Function<com.aragost.javahg.commands.Branch,
|
||||
Branch>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Branch apply(com.aragost.javahg.commands.Branch hgBranch)
|
||||
{
|
||||
final Function<com.aragost.javahg.commands.Branch, Branch> branchFunction = hgBranch -> {
|
||||
String node = null;
|
||||
Changeset changeset = hgBranch.getBranchTip();
|
||||
|
||||
if (changeset != null)
|
||||
{
|
||||
if (changeset != null) {
|
||||
node = changeset.getNode();
|
||||
}
|
||||
|
||||
return new Branch(hgBranch.getName(), node);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return branches;
|
||||
return Lists.transform(hgBranches,
|
||||
branchFunction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,27 +41,21 @@ import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.subject.Subject.Builder;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.security.Role;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import sonia.scm.security.Role;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -96,12 +90,7 @@ public final class MockUtil
|
||||
|
||||
when(subject.isAuthenticated()).thenReturn(Boolean.TRUE);
|
||||
when(subject.isPermitted(anyListOf(Permission.class))).then(
|
||||
new Answer<Boolean[]>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Boolean[] answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
invocation -> {
|
||||
List<Permission> permissions =
|
||||
(List<Permission>) invocation.getArguments()[0];
|
||||
Boolean[] returnArray = new Boolean[permissions.size()];
|
||||
@@ -109,7 +98,6 @@ public final class MockUtil
|
||||
Arrays.fill(returnArray, Boolean.TRUE);
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
});
|
||||
when(subject.isPermitted(any(Permission.class))).thenReturn(Boolean.TRUE);
|
||||
when(subject.isPermitted(any(String.class))).thenReturn(Boolean.TRUE);
|
||||
|
||||
@@ -38,31 +38,26 @@ package sonia.scm;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Module;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.ClassLoaders;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -103,12 +98,7 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
||||
classLoader.getResources(OVERRIDE_PATH);
|
||||
final JAXBContext context = JAXBContext.newInstance(ClassOverrides.class);
|
||||
|
||||
ClassLoaders.executeInContext(classLoader, new Runnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ClassLoaders.executeInContext(classLoader, () -> {
|
||||
while (overridesEnm.hasMoreElements())
|
||||
{
|
||||
URL overrideUrl = overridesEnm.nextElement();
|
||||
@@ -133,7 +123,6 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
||||
"could not load ".concat(overrideUrl.toExternalForm()), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@@ -217,28 +206,21 @@ public class ClassOverrides implements Iterable<ClassOverride>
|
||||
|
||||
if (Util.isNotEmpty(moduleClasses))
|
||||
{
|
||||
modules = Lists.transform(moduleClasses,
|
||||
new Function<Class<? extends Module>, Module>()
|
||||
{
|
||||
@Override
|
||||
public Module apply(Class<? extends Module> moduleClass)
|
||||
{
|
||||
final Function<Class<? extends Module>, Module> classModuleFunction = moduleClass -> {
|
||||
Module module = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
module = moduleClass.newInstance();
|
||||
}
|
||||
catch (IllegalAccessException | InstantiationException ex)
|
||||
{
|
||||
} catch (IllegalAccessException | InstantiationException ex) {
|
||||
logger.error(
|
||||
"could not create module instance of ".concat(
|
||||
moduleClass.getName()), ex);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
});
|
||||
};
|
||||
modules = Lists.transform(moduleClasses,
|
||||
classModuleFunction);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -64,14 +64,7 @@ public class ScmEventBusModule extends AbstractModule
|
||||
@Override
|
||||
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter)
|
||||
{
|
||||
encounter.register(new InjectionListener<I>()
|
||||
{
|
||||
@Override
|
||||
public void afterInjection(Object object)
|
||||
{
|
||||
ScmEventBus.getInstance().register(object);
|
||||
}
|
||||
});
|
||||
encounter.register((InjectionListener<I>) object -> ScmEventBus.getInstance().register(object));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -73,11 +73,7 @@ public class ScmInitializerModule extends AbstractModule
|
||||
@Override
|
||||
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter)
|
||||
{
|
||||
encounter.register(new InjectionListener<I>()
|
||||
{
|
||||
@Override
|
||||
public void afterInjection(Object i)
|
||||
{
|
||||
encounter.register((InjectionListener<I>) i -> {
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("initialize initable {}", i.getClass());
|
||||
@@ -86,7 +82,6 @@ public class ScmInitializerModule extends AbstractModule
|
||||
Initable initable = (Initable) i;
|
||||
|
||||
initable.init(SCMContext.getContext());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -35,39 +35,27 @@ package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||
|
||||
import sonia.scm.api.rest.Permission;
|
||||
import sonia.scm.security.AssignedPermission;
|
||||
import sonia.scm.security.SecuritySystem;
|
||||
import sonia.scm.security.StoredAssignedPermission;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Abstract base class for global permission resources.
|
||||
@@ -277,15 +265,7 @@ public abstract class AbstractPermissionResource
|
||||
securitySystem.getPermissions(predicate);
|
||||
|
||||
return Lists.transform(permissions,
|
||||
new Function<StoredAssignedPermission, Permission>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Permission apply(StoredAssignedPermission mgp)
|
||||
{
|
||||
return new Permission(mgp.getId(), mgp.getPermission());
|
||||
}
|
||||
});
|
||||
mgp -> new Permission(mgp.getId(), mgp.getPermission()));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -156,23 +156,18 @@ public class SearchResource
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public SearchResults searchGroups(@QueryParam("query") String queryString)
|
||||
{
|
||||
return groupSearchHandler.search(queryString,
|
||||
new Function<Group, SearchResult>()
|
||||
{
|
||||
@Override
|
||||
public SearchResult apply(Group group)
|
||||
{
|
||||
final Function<Group, SearchResult> groupSearchResultFunction = group -> {
|
||||
String label = group.getName();
|
||||
String description = group.getDescription();
|
||||
|
||||
if (description != null)
|
||||
{
|
||||
if (description != null) {
|
||||
label = label.concat(" (").concat(description).concat(")");
|
||||
}
|
||||
|
||||
return new SearchResult(group.getName(), label);
|
||||
}
|
||||
});
|
||||
};
|
||||
return groupSearchHandler.search(queryString,
|
||||
groupSearchResultFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,19 +186,15 @@ public class SearchResource
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public SearchResults searchUsers(@QueryParam("query") String queryString)
|
||||
{
|
||||
return userSearchHandler.search(queryString,
|
||||
new Function<User, SearchResult>()
|
||||
{
|
||||
@Override
|
||||
public SearchResult apply(User user)
|
||||
{
|
||||
final Function<User, SearchResult> userSearchResultFunction = user -> {
|
||||
StringBuilder label = new StringBuilder(user.getName());
|
||||
|
||||
label.append(" (").append(user.getDisplayName()).append(")");
|
||||
|
||||
return new SearchResult(user.getName(), label.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
return userSearchHandler.search(queryString,
|
||||
userSearchResultFunction);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -34,13 +34,14 @@ import com.github.legman.ReferenceType;
|
||||
import com.github.legman.Subscribe;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import javax.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.EagerSingleton;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHookEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* {@link PostReceiveRepositoryHookEvent} which stores receives data and passes it to the {@link DebugService}.
|
||||
*
|
||||
@@ -84,5 +85,5 @@ public final class DebugHook
|
||||
));
|
||||
}
|
||||
|
||||
private static final Function<Changeset, String> IDEXTRACTOR = (Changeset changeset) -> changeset.getId();
|
||||
private static final Function<Changeset, String> IDEXTRACTOR = Changeset::getId;
|
||||
}
|
||||
|
||||
@@ -40,10 +40,8 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
@@ -52,16 +50,10 @@ import sonia.scm.search.SearchUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -269,22 +261,17 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
}
|
||||
|
||||
final PermissionActionCheck<Group> check = GroupPermissions.read();
|
||||
return SearchUtil.search(searchRequest, groupDAO.getAll(),
|
||||
new TransformFilter<Group>()
|
||||
{
|
||||
@Override
|
||||
public Group accept(Group group)
|
||||
{
|
||||
final TransformFilter<Group> groupTransformFilter = group -> {
|
||||
Group result = null;
|
||||
|
||||
if (check.isPermitted(group) && matches(searchRequest, group))
|
||||
{
|
||||
if (check.isPermitted(group) && matches(searchRequest, group)) {
|
||||
result = group.clone();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
};
|
||||
return SearchUtil.search(searchRequest, groupDAO.getAll(),
|
||||
groupTransformFilter);
|
||||
}
|
||||
|
||||
private boolean matches(SearchRequest searchRequest, Group group) {
|
||||
@@ -374,17 +361,13 @@ public class DefaultGroupManager extends AbstractGroupManager
|
||||
{
|
||||
final PermissionActionCheck<Group> check = GroupPermissions.read();
|
||||
|
||||
return Util.createSubCollection(groupDAO.getAll(), comparator,
|
||||
new CollectionAppender<Group>()
|
||||
{
|
||||
@Override
|
||||
public void append(Collection<Group> collection, Group group)
|
||||
{
|
||||
final CollectionAppender<Group> groupCollectionAppender = (collection, group) -> {
|
||||
if (check.isPermitted(group)) {
|
||||
collection.add(group.clone());
|
||||
}
|
||||
}
|
||||
}, start, limit);
|
||||
};
|
||||
return Util.createSubCollection(groupDAO.getAll(), comparator,
|
||||
groupCollectionAppender, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,14 +33,13 @@ package sonia.scm.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -96,15 +95,7 @@ public final class PluginNode
|
||||
*/
|
||||
public PluginNode getChild(final String id)
|
||||
{
|
||||
return Iterables.find(children, new Predicate<PluginNode>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean apply(PluginNode node)
|
||||
{
|
||||
return node.getId().equals(id);
|
||||
}
|
||||
});
|
||||
return Iterables.find(children, node -> node.getId().equals(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,42 +41,22 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.apache.shiro.concurrent.SubjectAwareExecutorService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ArgumentIsInvalidException;
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.*;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.util.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Default implementation of {@link RepositoryManager}.
|
||||
@@ -459,18 +439,13 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
|
||||
final PermissionActionCheck<Repository> check =
|
||||
RepositoryPermissions.read();
|
||||
|
||||
return Util.createSubCollection(repositoryDAO.getAll(), comparator,
|
||||
new CollectionAppender<Repository>()
|
||||
{
|
||||
@Override
|
||||
public void append(Collection<Repository> collection, Repository item)
|
||||
{
|
||||
if (check.isPermitted(item))
|
||||
{
|
||||
final CollectionAppender<Repository> repositoryCollectionAppender = (collection, item) -> {
|
||||
if (check.isPermitted(item)) {
|
||||
collection.add(item.clone());
|
||||
}
|
||||
}
|
||||
}, start, limit);
|
||||
};
|
||||
return Util.createSubCollection(repositoryDAO.getAll(), comparator,
|
||||
repositoryCollectionAppender, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -128,15 +128,7 @@ public class HealthCheckContextListener implements ServletContextListener
|
||||
{
|
||||
|
||||
// excute health checks for all repsitories asynchronous
|
||||
SecurityUtils.getSubject().execute(new Runnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
healthChecker.checkAll();
|
||||
}
|
||||
});
|
||||
SecurityUtils.getSubject().execute(healthChecker::checkAll);
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
@@ -35,21 +35,16 @@ import com.google.common.base.Throwables;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import javax.inject.Inject;
|
||||
import org.quartz.CronScheduleBuilder;
|
||||
import org.quartz.JobBuilder;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobDetail;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.quartz.Trigger;
|
||||
import org.quartz.TriggerBuilder;
|
||||
import org.quartz.*;
|
||||
import org.quartz.impl.StdSchedulerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.Initable;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* {@link Scheduler} which uses the quartz scheduler.
|
||||
*
|
||||
@@ -130,13 +125,7 @@ public class QuartzScheduler implements Scheduler, Initable {
|
||||
@Override
|
||||
public Task schedule(String expression, final Runnable runnable)
|
||||
{
|
||||
return schedule(expression, new Provider<Runnable>(){
|
||||
@Override
|
||||
public Runnable get()
|
||||
{
|
||||
return runnable;
|
||||
}
|
||||
});
|
||||
return schedule(expression, () -> runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,6 @@ package sonia.scm.security;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.legman.Subscribe;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
@@ -44,12 +43,9 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.group.GroupEvent;
|
||||
@@ -58,23 +54,20 @@ import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
import sonia.scm.user.UserEvent;
|
||||
import sonia.scm.util.ClassLoaders;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* TODO add events
|
||||
@@ -191,16 +184,8 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
{
|
||||
if (event.getEventType() == HandlerEventType.DELETE)
|
||||
{
|
||||
deletePermissions(new Predicate<AssignedPermission>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean apply(AssignedPermission p)
|
||||
{
|
||||
return !p.isGroupPermission()
|
||||
&& event.getItem().getName().equals(p.getName());
|
||||
}
|
||||
});
|
||||
deletePermissions(p -> !(p != null && p.isGroupPermission())
|
||||
&& event.getItem().getName().equals(p != null ? p.getName() : null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,16 +200,8 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
{
|
||||
if (event.getEventType() == HandlerEventType.DELETE)
|
||||
{
|
||||
deletePermissions(new Predicate<AssignedPermission>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean apply(AssignedPermission p)
|
||||
{
|
||||
return p.isGroupPermission()
|
||||
&& event.getItem().getName().equals(p.getName());
|
||||
}
|
||||
});
|
||||
deletePermissions(p -> (p != null && p.isGroupPermission())
|
||||
&& event.getItem().getName().equals(p.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,13 +38,10 @@ package sonia.scm.user;
|
||||
import com.github.sdorra.ssp.PermissionActionCheck;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.TransformFilter;
|
||||
import sonia.scm.search.SearchRequest;
|
||||
import sonia.scm.search.SearchUtil;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
@@ -52,20 +49,14 @@ import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -297,16 +288,12 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
}
|
||||
|
||||
final PermissionActionCheck<User> check = UserPermissions.read();
|
||||
return SearchUtil.search(searchRequest, userDAO.getAll(), new TransformFilter<User>() {
|
||||
@Override
|
||||
public User accept(User user)
|
||||
{
|
||||
return SearchUtil.search(searchRequest, userDAO.getAll(), user -> {
|
||||
User result = null;
|
||||
if (check.isPermitted(user) && matches(searchRequest, user)) {
|
||||
result = user.clone();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -392,17 +379,13 @@ public class DefaultUserManager extends AbstractUserManager
|
||||
@Override
|
||||
public Collection<User> getAll(Comparator<User> comaparator, int start, int limit) {
|
||||
final PermissionActionCheck<User> check = UserPermissions.read();
|
||||
return Util.createSubCollection(userDAO.getAll(), comaparator,
|
||||
new CollectionAppender<User>()
|
||||
{
|
||||
@Override
|
||||
public void append(Collection<User> collection, User item)
|
||||
{
|
||||
final CollectionAppender<User> userCollectionAppender = (collection, item) -> {
|
||||
if (check.isPermitted(item)) {
|
||||
collection.add(item.clone());
|
||||
}
|
||||
}
|
||||
}, start, limit);
|
||||
};
|
||||
return Util.createSubCollection(userDAO.getAll(), comaparator,
|
||||
userCollectionAppender, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,10 +37,8 @@ package sonia.scm.web.cgi;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
@@ -48,23 +46,17 @@ import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -510,11 +502,7 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
||||
*/
|
||||
private void processErrorStreamAsync(final Process process)
|
||||
{
|
||||
executor.execute(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
executor.execute(() -> {
|
||||
InputStream errorStream = null;
|
||||
|
||||
try
|
||||
@@ -530,7 +518,6 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
||||
{
|
||||
IOUtil.close(errorStream);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.Files;
|
||||
@@ -196,15 +195,7 @@ public class CacheConfigurationTestLoader implements CacheConfigurationLoader
|
||||
else
|
||||
{
|
||||
urlIterator = Iterators.transform(moduleConfigurations,
|
||||
new Function<String, URL>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public URL apply(String resource)
|
||||
{
|
||||
return getResource(resource);
|
||||
}
|
||||
});
|
||||
this::getResource);
|
||||
}
|
||||
|
||||
return urlIterator;
|
||||
|
||||
@@ -35,18 +35,14 @@ package sonia.scm.cache;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Assume;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -166,14 +162,7 @@ public abstract class CacheTestBase
|
||||
cache.put("a-1", "test123");
|
||||
cache.put("a-2", "test123");
|
||||
|
||||
Iterable<String> previous = cache.removeAll(new Predicate<String>()
|
||||
{
|
||||
@Override
|
||||
public boolean apply(String item)
|
||||
{
|
||||
return item.startsWith("test");
|
||||
}
|
||||
});
|
||||
Iterable<String> previous = cache.removeAll(item -> item != null && item.startsWith("test"));
|
||||
|
||||
assertThat(previous, containsInAnyOrder("test123", "test456"));
|
||||
assertNull(cache.get("test-1"));
|
||||
|
||||
@@ -34,31 +34,27 @@ package sonia.scm.plugin;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -370,15 +366,10 @@ public class PluginProcessorTest
|
||||
private PluginWrapper findPlugin(Iterable<PluginWrapper> plugin,
|
||||
final String id)
|
||||
{
|
||||
return Iterables.find(plugin, new Predicate<PluginWrapper>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean apply(PluginWrapper input)
|
||||
{
|
||||
return id.equals(input.getId());
|
||||
}
|
||||
});
|
||||
return StreamSupport.stream(plugin.spliterator(), false)
|
||||
.filter(input -> id.equals(input.getId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
@@ -33,26 +33,22 @@ package sonia.scm.plugin;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -265,15 +261,7 @@ public class PluginTreeTest
|
||||
*/
|
||||
private List<String> unwrapIds(List<PluginNode> nodes)
|
||||
{
|
||||
return Lists.transform(nodes, new Function<PluginNode, String>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public String apply(PluginNode input)
|
||||
{
|
||||
return input.getId();
|
||||
}
|
||||
});
|
||||
return Lists.transform(nodes, PluginNode::getId);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
@@ -35,22 +35,15 @@ package sonia.scm.security;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -96,15 +89,10 @@ public class DefaultKeyGeneratorTest
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Future<Set<String>> future = executor.submit(new Callable<Set<String>>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Set<String> call()
|
||||
{
|
||||
Future<Set<String>> future = executor.submit(() -> {
|
||||
Set<String> keys = Sets.newHashSet();
|
||||
|
||||
for (int i = 0; i < 1000; i++)
|
||||
for (int i1 = 0; i1 < 1000; i1++)
|
||||
{
|
||||
String key = generator.createKey();
|
||||
|
||||
@@ -117,7 +105,6 @@ public class DefaultKeyGeneratorTest
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
});
|
||||
|
||||
futureSet.add(future);
|
||||
|
||||
@@ -34,27 +34,23 @@ package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||
import org.apache.shiro.realm.SimpleAccountRealm;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -184,15 +180,7 @@ public class DefaultSecuritySystemTest extends AbstractTestBase
|
||||
createPermission("hitchhiker", true, "repository:*:READ");
|
||||
|
||||
List<StoredAssignedPermission> filtered =
|
||||
securitySystem.getPermissions(new Predicate<AssignedPermission>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean apply(AssignedPermission input)
|
||||
{
|
||||
return !input.isGroupPermission();
|
||||
}
|
||||
});
|
||||
securitySystem.getPermissions(input -> !(input != null && input.isGroupPermission()));
|
||||
|
||||
assertEquals(2, filtered.size());
|
||||
assertThat(filtered, containsInAnyOrder(trillian, dent));
|
||||
|
||||
@@ -89,15 +89,8 @@ public class MustacheTemplateTest extends TemplateTestBase
|
||||
@Override
|
||||
protected void prepareEnv(Map<String, Object> env)
|
||||
{
|
||||
env.put("test", new Function<String, String>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public String apply(String input)
|
||||
{
|
||||
env.put("test", (Function<String, String>) input -> {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user