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