util classes should be final with a private constructor

This commit is contained in:
Sebastian Sdorra
2013-01-31 10:26:16 +01:00
parent 2d5fa22ca4
commit 9adc65d9e5
34 changed files with 393 additions and 134 deletions

View File

@@ -48,9 +48,17 @@ import java.util.zip.ZipFile;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class Util public final class Util
{ {
/**
* Constructs ...
*
*/
private Util() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -50,9 +50,17 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class WrapperUtil public final class WrapperUtil
{ {
/**
* Constructs ...
*
*/
private WrapperUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -78,7 +86,6 @@ public class WrapperUtil
* *
* *
* *
* @param baseUrl
* *
* @param config * @param config
* @param repositories * @param repositories
@@ -86,7 +93,7 @@ public class WrapperUtil
* @return * @return
*/ */
public static List<RepositoryWrapper> wrapRepositories(ServerConfig config, public static List<RepositoryWrapper> wrapRepositories(ServerConfig config,
Collection<Repository> repositories) Collection<Repository> repositories)
{ {
List<RepositoryWrapper> wrappers = new ArrayList<RepositoryWrapper>(); List<RepositoryWrapper> wrappers = new ArrayList<RepositoryWrapper>();

View File

@@ -49,13 +49,21 @@ import com.sun.jersey.api.client.filter.LoggingFilter;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class ClientUtil public final class ClientUtil
{ {
/** the logger for ClientUtil */ /** the logger for ClientUtil */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(ClientUtil.class); LoggerFactory.getLogger(ClientUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private ClientUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -50,7 +50,7 @@ import com.sun.jersey.api.client.WebResource;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class ClientTestUtil public final class ClientTestUtil
{ {
/** Field description */ /** Field description */
@@ -68,6 +68,13 @@ public class ClientTestUtil
/** Field description */ /** Field description */
public static final boolean REQUEST_LOGGING = false; public static final boolean REQUEST_LOGGING = false;
private ClientTestUtil()
{
}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -50,9 +50,17 @@ import java.util.List;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.15 * @since 1.15
*/ */
public class EscapeUtil public final class EscapeUtil
{ {
/**
* Constructs ...
*
*/
private EscapeUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -58,7 +58,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class PermissionUtil public final class PermissionUtil
{ {
/** /**
@@ -67,6 +67,14 @@ public class PermissionUtil
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(PermissionUtil.class); LoggerFactory.getLogger(PermissionUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private PermissionUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -105,7 +113,6 @@ public class PermissionUtil
* *
* *
* @param repository * @param repository
* @param securityContextProvider
* @param pt * @param pt
* *
* @since 1.21 * @since 1.21
@@ -238,7 +245,6 @@ public class PermissionUtil
* *
* @param configuration SCM-Manager main configuration * @param configuration SCM-Manager main configuration
* @param repository repository to check * @param repository repository to check
* @param securityContext current user security context
* *
* @return true if the repository is writable * @return true if the repository is writable
* @since 1.21 * @since 1.21

View File

@@ -59,13 +59,21 @@ import javax.servlet.http.HttpServletRequest;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.11 * @since 1.11
*/ */
public class RepositoryUtil public final class RepositoryUtil
{ {
/** the logger for RepositoryUtil */ /** the logger for RepositoryUtil */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(RepositoryUtil.class); LoggerFactory.getLogger(RepositoryUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private RepositoryUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -79,8 +87,7 @@ public class RepositoryUtil
* @since 1.16 * @since 1.16
*/ */
public static void appendUrl(ScmConfiguration configuration, public static void appendUrl(ScmConfiguration configuration,
RepositoryManager repositoryManager, RepositoryManager repositoryManager, Repository repository)
Repository repository)
{ {
RepositoryHandler handler = RepositoryHandler handler =
repositoryManager.getHandler(repository.getType()); repositoryManager.getHandler(repository.getType());
@@ -106,8 +113,7 @@ public class RepositoryUtil
* @since 1.16 * @since 1.16
*/ */
public static void appendUrl(HttpServletRequest request, public static void appendUrl(HttpServletRequest request,
RepositoryManager repositoryManager, RepositoryManager repositoryManager, Repository repository)
Repository repository)
{ {
RepositoryHandler handler = RepositoryHandler handler =
repositoryManager.getHandler(repository.getType()); repositoryManager.getHandler(repository.getType());
@@ -131,7 +137,7 @@ public class RepositoryUtil
* @return * @return
*/ */
public static List<File> searchRepositoryDirectories(File directory, public static List<File> searchRepositoryDirectories(File directory,
String... names) String... names)
{ {
List<File> repositories = new ArrayList<File>(); List<File> repositories = new ArrayList<File>();
@@ -154,11 +160,11 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static String getRepositoryName(AbstractRepositoryHandler handler, public static String getRepositoryName(AbstractRepositoryHandler handler,
String directoryPath) String directoryPath)
throws IOException throws IOException
{ {
return getRepositoryName(handler.getConfig().getRepositoryDirectory(), return getRepositoryName(handler.getConfig().getRepositoryDirectory(),
new File(directoryPath)); new File(directoryPath));
} }
/** /**
@@ -173,11 +179,11 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static String getRepositoryName(SimpleRepositoryConfig config, public static String getRepositoryName(SimpleRepositoryConfig config,
String directoryPath) String directoryPath)
throws IOException throws IOException
{ {
return getRepositoryName(config.getRepositoryDirectory(), return getRepositoryName(config.getRepositoryDirectory(),
new File(directoryPath)); new File(directoryPath));
} }
/** /**
@@ -192,11 +198,11 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static String getRepositoryName(AbstractRepositoryHandler handler, public static String getRepositoryName(AbstractRepositoryHandler handler,
File directory) File directory)
throws IOException throws IOException
{ {
return getRepositoryName(handler.getConfig().getRepositoryDirectory(), return getRepositoryName(handler.getConfig().getRepositoryDirectory(),
directory); directory);
} }
/** /**
@@ -211,8 +217,8 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static String getRepositoryName(SimpleRepositoryConfig config, public static String getRepositoryName(SimpleRepositoryConfig config,
File directory) File directory)
throws IOException throws IOException
{ {
return getRepositoryName(config.getRepositoryDirectory(), directory); return getRepositoryName(config.getRepositoryDirectory(), directory);
} }
@@ -229,7 +235,7 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static String getRepositoryName(File baseDirectory, File directory) public static String getRepositoryName(File baseDirectory, File directory)
throws IOException throws IOException
{ {
String name = null; String name = null;
String path = directory.getCanonicalPath(); String path = directory.getCanonicalPath();
@@ -262,8 +268,8 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static List<String> getRepositoryNames( public static List<String> getRepositoryNames(
AbstractRepositoryHandler handler, String... directoryNames) AbstractRepositoryHandler handler, String... directoryNames)
throws IOException throws IOException
{ {
return getRepositoryNames(handler.getConfig(), directoryNames); return getRepositoryNames(handler.getConfig(), directoryNames);
} }
@@ -280,8 +286,8 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static List<String> getRepositoryNames(SimpleRepositoryConfig config, public static List<String> getRepositoryNames(SimpleRepositoryConfig config,
String... directoryNames) String... directoryNames)
throws IOException throws IOException
{ {
return getRepositoryNames(config.getRepositoryDirectory(), directoryNames); return getRepositoryNames(config.getRepositoryDirectory(), directoryNames);
} }
@@ -298,8 +304,8 @@ public class RepositoryUtil
* @throws IOException * @throws IOException
*/ */
public static List<String> getRepositoryNames(File baseDirectory, public static List<String> getRepositoryNames(File baseDirectory,
String... directoryNames) String... directoryNames)
throws IOException throws IOException
{ {
List<String> repositories = new ArrayList<String>(); List<String> repositories = new ArrayList<String>();
List<File> repositoryFiles = searchRepositoryDirectories(baseDirectory, List<File> repositoryFiles = searchRepositoryDirectories(baseDirectory,
@@ -329,7 +335,7 @@ public class RepositoryUtil
* @param names * @param names
*/ */
private static void searchRepositoryDirectories(List<File> repositories, private static void searchRepositoryDirectories(List<File> repositories,
File directory, List<String> names) File directory, List<String> names)
{ {
boolean found = false; boolean found = false;

View File

@@ -50,9 +50,17 @@ import java.util.Locale;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class SearchUtil public final class SearchUtil
{ {
/**
* Constructs ...
*
*/
private SearchUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -64,7 +72,7 @@ public class SearchUtil
* @return * @return
*/ */
public static boolean matchesAll(SearchRequest request, String value, public static boolean matchesAll(SearchRequest request, String value,
String... other) String... other)
{ {
boolean result = false; boolean result = false;
String query = createStringQuery(request); String query = createStringQuery(request);
@@ -101,7 +109,7 @@ public class SearchUtil
* @return * @return
*/ */
public static boolean matchesOne(SearchRequest request, String value, public static boolean matchesOne(SearchRequest request, String value,
String... other) String... other)
{ {
boolean result = false; boolean result = false;
String query = createStringQuery(request); String query = createStringQuery(request);
@@ -141,7 +149,7 @@ public class SearchUtil
* @return * @return
*/ */
public static <T> Collection<T> search(SearchRequest searchRequest, public static <T> Collection<T> search(SearchRequest searchRequest,
Collection<T> collection, TransformFilter<T> filter) Collection<T> collection, TransformFilter<T> filter)
{ {
List<T> items = new ArrayList<T>(); List<T> items = new ArrayList<T>();
int index = 0; int index = 0;

View File

@@ -43,7 +43,7 @@ import sonia.scm.util.ServiceUtil;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.7 * @since 1.7
*/ */
public class CipherUtil public final class CipherUtil
{ {
/** Field description */ /** Field description */
@@ -51,8 +51,6 @@ public class CipherUtil
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
private KeyGenerator keyGenerator;
/** /**
* Constructs ... * Constructs ...
* *
@@ -71,17 +69,10 @@ public class CipherUtil
if (cipherHandler == null) if (cipherHandler == null)
{ {
cipherHandler = new DefaultCipherHandler(SCMContext.getContext(), cipherHandler = new DefaultCipherHandler(SCMContext.getContext(),
keyGenerator); keyGenerator);
} }
} }
public KeyGenerator getKeyGenerator()
{
return keyGenerator;
}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
@@ -147,8 +138,22 @@ public class CipherUtil
return cipherHandler; return cipherHandler;
} }
/**
* Method description
*
*
* @return
*/
public KeyGenerator getKeyGenerator()
{
return keyGenerator;
}
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */
private CipherHandler cipherHandler; private CipherHandler cipherHandler;
/** Field description */
private KeyGenerator keyGenerator;
} }

View File

@@ -42,9 +42,17 @@ import sonia.scm.util.Util;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.11 * @since 1.11
*/ */
public class UrlUtil public final class UrlUtil
{ {
/**
* Constructs ...
*
*/
private UrlUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -35,7 +35,6 @@ package sonia.scm.util;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import sonia.scm.ArgumentIsInvalidException;
import sonia.scm.Validateable; import sonia.scm.Validateable;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -46,9 +45,17 @@ import java.util.Collection;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class AssertUtil public final class AssertUtil
{ {
/**
* Constructs ...
*
*/
private AssertUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -48,12 +48,20 @@ import java.security.NoSuchAlgorithmException;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class ChecksumUtil public final class ChecksumUtil
{ {
/** Field description */ /** Field description */
private static final String DIGEST_TYPE = "SHA-1"; private static final String DIGEST_TYPE = "SHA-1";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private ChecksumUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -143,7 +151,7 @@ public class ChecksumUtil
* @return * @return
* *
* @throws IOException * @throws IOException
* *
* @since 1.12 * @since 1.12
*/ */
public static String createChecksum(byte[] content) throws IOException public static String createChecksum(byte[] content) throws IOException

View File

@@ -40,9 +40,15 @@ package sonia.scm.util;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.8 * @since 1.8
*/ */
public class GlobUtil public final class GlobUtil
{ {
private GlobUtil()
{
}
/** /**
* Converts the given glob string to a regular expression string. * Converts the given glob string to a regular expression string.
* *

View File

@@ -61,7 +61,7 @@ import javax.servlet.http.HttpServletResponse;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class HttpUtil public final class HttpUtil
{ {
/** authentication realm for basic authentication */ /** authentication realm for basic authentication */
@@ -160,10 +160,21 @@ public class HttpUtil
/** the logger for HttpUtil */ /** the logger for HttpUtil */
private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class); private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
/** Field description */ /**
* Pattern for url normalization
* @sincee 1.26
*/
private static final Pattern PATTERN_URLNORMALIZE = private static final Pattern PATTERN_URLNORMALIZE =
Pattern.compile("(?:(http://[^:]+):80(/.+)?|(https://[^:]+):443(/.+)?)"); Pattern.compile("(?:(http://[^:]+):80(/.+)?|(https://[^:]+):443(/.+)?)");
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private HttpUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -65,7 +65,7 @@ import java.util.Locale;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class IOUtil public final class IOUtil
{ {
/** Field description */ /** Field description */
@@ -93,16 +93,24 @@ public class IOUtil
/** Field description */ /** Field description */
private static final String[] EXTENSION_SCRIPT_UNIX = { ".sh", ".csh", private static final String[] EXTENSION_SCRIPT_UNIX = { ".sh", ".csh",
".bsh" }; ".bsh" };
/** Field description */ /** Field description */
private static final String[] EXTENSION_SCRIPT_WINDOWS = { ".bat", ".cmd", private static final String[] EXTENSION_SCRIPT_WINDOWS = { ".bat", ".cmd",
".exe" }; ".exe" };
/** Field description */ /** Field description */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(IOUtil.class.getName()); LoggerFactory.getLogger(IOUtil.class.getName());
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private IOUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -137,7 +145,7 @@ public class IOUtil
* @throws IOException * @throws IOException
*/ */
public static void copy(Reader reader, Writer writer, int bufferSize) public static void copy(Reader reader, Writer writer, int bufferSize)
throws IOException throws IOException
{ {
char[] buffer = new char[bufferSize]; char[] buffer = new char[bufferSize];
@@ -186,7 +194,7 @@ public class IOUtil
* @throws IOException * @throws IOException
*/ */
public static void copy(InputStream in, OutputStream out, int bufferSize) public static void copy(InputStream in, OutputStream out, int bufferSize)
throws IOException throws IOException
{ {
byte[] buffer = new byte[bufferSize]; byte[] buffer = new byte[bufferSize];
@@ -210,8 +218,8 @@ public class IOUtil
* @throws IOException * @throws IOException
*/ */
public static void copy(InputStream in, OutputStream out, int bufferSize, public static void copy(InputStream in, OutputStream out, int bufferSize,
int byteCount) int byteCount)
throws IOException throws IOException
{ {
byte buffer[] = new byte[bufferSize]; byte buffer[] = new byte[bufferSize];
int len = bufferSize; int len = bufferSize;
@@ -221,8 +229,8 @@ public class IOUtil
while (byteCount > 0) while (byteCount > 0)
{ {
int max = (byteCount < bufferSize) int max = (byteCount < bufferSize)
? (int) byteCount ? (int) byteCount
: bufferSize; : bufferSize;
len = in.read(buffer, 0, max); len = in.read(buffer, 0, max);
@@ -343,7 +351,7 @@ public class IOUtil
* @param bufferSize * @param bufferSize
*/ */
public static void copyThread(InputStream input, OutputStream output, public static void copyThread(InputStream input, OutputStream output,
int bufferSize) int bufferSize)
{ {
new Thread(new IOStreamCopyThread(input, output, bufferSize)).start(); new Thread(new IOStreamCopyThread(input, output, bufferSize)).start();
} }
@@ -410,7 +418,7 @@ public class IOUtil
* @throws IOException * @throws IOException
*/ */
public static void extract(File archive, File outputDirectory) public static void extract(File archive, File outputDirectory)
throws IOException throws IOException
{ {
String name = archive.getName().toLowerCase(Locale.ENGLISH); String name = archive.getName().toLowerCase(Locale.ENGLISH);
@@ -428,7 +436,7 @@ public class IOUtil
* @throws IOException * @throws IOException
*/ */
public static void extract(File archive, File outputDirectory, String type) public static void extract(File archive, File outputDirectory, String type)
throws IOException throws IOException
{ {
if (type.endsWith(ZipUnArchiver.EXTENSION)) if (type.endsWith(ZipUnArchiver.EXTENSION))
{ {
@@ -451,7 +459,7 @@ public class IOUtil
if (!directory.exists() &&!directory.mkdirs()) if (!directory.exists() &&!directory.mkdirs())
{ {
throw new IllegalStateException( throw new IllegalStateException(
"could not create directory ".concat(directory.getPath())); "could not create directory ".concat(directory.getPath()));
} }
} }
@@ -569,7 +577,7 @@ public class IOUtil
* @return * @return
*/ */
public static List<String> searchAll(String[] path, String cmd, public static List<String> searchAll(String[] path, String cmd,
String checkParameter) String checkParameter)
{ {
List<String> cmds = new ArrayList<String>(); List<String> cmds = new ArrayList<String>();
@@ -737,7 +745,7 @@ public class IOUtil
* @return * @return
*/ */
private static File findFileByExtension(String parentPath, String cmd, private static File findFileByExtension(String parentPath, String cmd,
List<String> potentialExtensions) List<String> potentialExtensions)
{ {
File file = null; File file = null;
@@ -942,7 +950,7 @@ public class IOUtil
* @param bufferSize * @param bufferSize
*/ */
public IOStreamCopyThread(InputStream input, OutputStream output, public IOStreamCopyThread(InputStream input, OutputStream output,
int bufferSize) int bufferSize)
{ {
this.input = input; this.input = input;
this.output = output; this.output = output;

View File

@@ -51,13 +51,21 @@ import java.util.Scanner;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class RegistryUtil public final class RegistryUtil
{ {
/** the logger for RegistryUtil */ /** the logger for RegistryUtil */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(RegistryUtil.class); LoggerFactory.getLogger(RegistryUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private RegistryUtil() {}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
@@ -98,7 +106,7 @@ public class RegistryUtil
* @return * @return
*/ */
public static String getRegistryValue(String key, String subKey, public static String getRegistryValue(String key, String subKey,
String defaultValue) String defaultValue)
{ {
String value = defaultValue; String value = defaultValue;
SimpleCommand command = null; SimpleCommand command = null;

View File

@@ -50,9 +50,17 @@ import sonia.scm.user.User;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class SecurityUtil public final class SecurityUtil
{ {
/**
* Constructs ...
*
*/
private SecurityUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -44,9 +44,17 @@ import java.util.ServiceLoader;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class ServiceUtil public final class ServiceUtil
{ {
/**
* Constructs ...
*
*/
private ServiceUtil() {}
//~--- get methods ----------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -43,7 +43,7 @@ import sonia.scm.ServletContainerDetector;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class SystemUtil public final class SystemUtil
{ {
/** Field description */ /** Field description */
@@ -58,13 +58,20 @@ public class SystemUtil
/** Field description */ /** Field description */
private static Platform platform = private static Platform platform =
new Platform(System.getProperty(PROPERTY_OSNAME), new Platform(System.getProperty(PROPERTY_OSNAME),
System.getProperty(PROPERTY_ARCH), System.getProperty(PROPERTY_ARCH), System.getProperty(PROPERTY_OSARCH));
System.getProperty(PROPERTY_OSARCH));
/** Field description */ /** Field description */
private static ServletContainer servletContainer = private static ServletContainer servletContainer =
ServletContainerDetector.detect(); ServletContainerDetector.detect();
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private SystemUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -55,7 +55,7 @@ import java.util.TimeZone;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class Util public final class Util
{ {
/** Field description */ /** Field description */
@@ -64,6 +64,14 @@ public class Util
/** Field description */ /** Field description */
public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING = "";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private Util() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -107,7 +115,7 @@ public class Util
* @return * @return
*/ */
public static <T> boolean containsOne(Collection<T> collection, public static <T> boolean containsOne(Collection<T> collection,
Collection<T> other) Collection<T> other)
{ {
boolean result = false; boolean result = false;
@@ -198,7 +206,7 @@ public class Util
* @since 1.4 * @since 1.4
*/ */
public static <T> Collection<T> createSubCollection(Collection<T> values, public static <T> Collection<T> createSubCollection(Collection<T> values,
Comparator<T> comparator, int start, int limit) Comparator<T> comparator, int start, int limit)
{ {
return createSubCollection(values, comparator, null, start, limit); return createSubCollection(values, comparator, null, start, limit);
} }
@@ -216,7 +224,7 @@ public class Util
* @since 1.4 * @since 1.4
*/ */
public static <T> Collection<T> createSubCollection(Collection<T> values, public static <T> Collection<T> createSubCollection(Collection<T> values,
int start, int limit) int start, int limit)
{ {
return createSubCollection(values, null, null, start, limit); return createSubCollection(values, null, null, start, limit);
} }
@@ -235,7 +243,7 @@ public class Util
* @since 1.4 * @since 1.4
*/ */
public static <T> Collection<T> createSubCollection(Collection<T> values, public static <T> Collection<T> createSubCollection(Collection<T> values,
CollectionAppender<T> appender, int start, int limit) CollectionAppender<T> appender, int start, int limit)
{ {
return createSubCollection(values, null, appender, start, limit); return createSubCollection(values, null, appender, start, limit);
} }
@@ -256,8 +264,8 @@ public class Util
* @since 1.4 * @since 1.4
*/ */
public static <T> Collection<T> createSubCollection(Collection<T> values, public static <T> Collection<T> createSubCollection(Collection<T> values,
Comparator<T> comparator, CollectionAppender<T> appender, int start, Comparator<T> comparator, CollectionAppender<T> appender, int start,
int limit) int limit)
{ {
List<T> result = new ArrayList<T>(); List<T> result = new ArrayList<T>();
List<T> valueList = new ArrayList(values); List<T> valueList = new ArrayList(values);
@@ -356,8 +364,8 @@ public class Util
public static String nonNull(Object value) public static String nonNull(Object value)
{ {
return (value != null) return (value != null)
? value.toString() ? value.toString()
: ""; : "";
} }
/** /**
@@ -372,7 +380,7 @@ public class Util
* @throws ParseException * @throws ParseException
*/ */
public static Date parseDate(String dateString, TimeZone tz) public static Date parseDate(String dateString, TimeZone tz)
throws ParseException throws ParseException
{ {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN); SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
@@ -407,13 +415,13 @@ public class Util
* @param start * @param start
* *
* @return * @return
* *
* @since 1.17 * @since 1.17
*/ */
public static boolean startWithIgnoreCase(String value, String start) public static boolean startWithIgnoreCase(String value, String start)
{ {
return (value != null) && (start != null) return (value != null) && (start != null)
&& value.toUpperCase(Locale.ENGLISH).startsWith(start); && value.toUpperCase(Locale.ENGLISH).startsWith(start);
} }
/** /**
@@ -584,8 +592,8 @@ public class Util
public static boolean isEquals(Object object, Object other) public static boolean isEquals(Object object, Object other)
{ {
return (object == null) return (object == null)
? other == null ? other == null
: object.equals(other); : object.equals(other);
} }
/** /**

View File

@@ -47,7 +47,7 @@ import java.util.regex.Pattern;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class ValidationUtil public final class ValidationUtil
{ {
/** Field description */ /** Field description */
@@ -65,6 +65,14 @@ public class ValidationUtil
private static final String REGEX_USERNAME = private static final String REGEX_USERNAME =
"^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$"; "^[A-z0-9\\.\\-_@]|[^ ]([A-z0-9\\.\\-_@ ]*[A-z0-9\\.\\-_@]|[^ ])?$";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private ValidationUtil() {}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
@@ -116,7 +124,7 @@ public class ValidationUtil
* @return * @return
*/ */
public static boolean isNotContaining(String value, public static boolean isNotContaining(String value,
String... notAllowedStrings) String... notAllowedStrings)
{ {
boolean result = Util.isNotEmpty(value); boolean result = Util.isNotEmpty(value);

View File

@@ -29,6 +29,8 @@
* *
*/ */
package sonia.scm.util; package sonia.scm.util;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
@@ -56,7 +58,7 @@ import javax.servlet.http.HttpServletResponse;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.15 * @since 1.15
*/ */
public class WebUtil public final class WebUtil
{ {
/** Field description */ /** Field description */
@@ -110,6 +112,14 @@ public class WebUtil
/** Field description */ /** Field description */
private static final Logger logger = LoggerFactory.getLogger(WebUtil.class); private static final Logger logger = LoggerFactory.getLogger(WebUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private WebUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -146,7 +156,7 @@ public class WebUtil
* @param seconds * @param seconds
*/ */
public static void addStaticCacheControls(HttpServletResponse response, public static void addStaticCacheControls(HttpServletResponse response,
long seconds) long seconds)
{ {
long time = new Date().getTime(); long time = new Date().getTime();
@@ -199,7 +209,7 @@ public class WebUtil
public static String getETag(File file) public static String getETag(File file)
{ {
return new StringBuilder("W/\"").append(file.length()).append( return new StringBuilder("W/\"").append(file.length()).append(
file.lastModified()).append("\"").toString(); file.lastModified()).append("\"").toString();
} }
/** /**
@@ -280,7 +290,7 @@ public class WebUtil
Date modifiedSince = getIfModifiedSinceDate(request); Date modifiedSince = getIfModifiedSinceDate(request);
if ((modifiedSince != null) if ((modifiedSince != null)
&& (modifiedSince.getTime() == file.lastModified())) && (modifiedSince.getTime() == file.lastModified()))
{ {
result = false; result = false;
} }
@@ -290,7 +300,7 @@ public class WebUtil
String inmEtag = request.getHeader(HEADER_INM); String inmEtag = request.getHeader(HEADER_INM);
if ((inmEtag != null) && (inmEtag.length() > 0) if ((inmEtag != null) && (inmEtag.length() > 0)
&& inmEtag.equals(getETag(file))) && inmEtag.equals(getETag(file)))
{ {
result = false; result = false;
} }

View File

@@ -30,6 +30,7 @@
*/ */
package sonia.scm.orientdb; package sonia.scm.orientdb;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
@@ -54,7 +55,7 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class OrientDBUtil public final class OrientDBUtil
{ {
/** Field description */ /** Field description */
@@ -66,6 +67,14 @@ public class OrientDBUtil
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(OrientDBUtil.class); LoggerFactory.getLogger(OrientDBUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private OrientDBUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -93,7 +102,7 @@ public class OrientDBUtil
* @return * @return
*/ */
public static List<ODocument> executeListResultQuery( public static List<ODocument> executeListResultQuery(
ODatabaseDocumentTx connection, String query, Object... parameters) ODatabaseDocumentTx connection, String query, Object... parameters)
{ {
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
@@ -118,7 +127,7 @@ public class OrientDBUtil
* @return * @return
*/ */
public static ODocument executeSingleResultQuery( public static ODocument executeSingleResultQuery(
ODatabaseDocumentTx connection, String query, Object... parameters) ODatabaseDocumentTx connection, String query, Object... parameters)
{ {
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
@@ -152,7 +161,7 @@ public class OrientDBUtil
* @return * @return
*/ */
public static <T> List<ODocument> transformToDocuments( public static <T> List<ODocument> transformToDocuments(
Converter<T> converter, List<T> items) Converter<T> converter, List<T> items)
{ {
List<ODocument> docs = null; List<ODocument> docs = null;
@@ -175,14 +184,14 @@ public class OrientDBUtil
* @return * @return
*/ */
public static <T> List<T> transformToItems(Converter<T> converter, public static <T> List<T> transformToItems(Converter<T> converter,
List<ODocument> docs) List<ODocument> docs)
{ {
List<T> items = null; List<T> items = null;
if (Util.isNotEmpty(docs)) if (Util.isNotEmpty(docs))
{ {
items = Lists.transform(docs, items = Lists.transform(docs,
new DocumentConverterFunction<T>(converter)); new DocumentConverterFunction<T>(converter));
} }
return items; return items;
@@ -200,7 +209,7 @@ public class OrientDBUtil
* @author Enter your name here... * @author Enter your name here...
*/ */
private static class DocumentConverterFunction<T> private static class DocumentConverterFunction<T>
implements Function<ODocument, T> implements Function<ODocument, T>
{ {
/** /**
@@ -248,7 +257,7 @@ public class OrientDBUtil
* @author Enter your name here... * @author Enter your name here...
*/ */
private static class ItemConverterFunction<F> private static class ItemConverterFunction<F>
implements Function<F, ODocument> implements Function<F, ODocument>
{ {
/** /**

View File

@@ -48,9 +48,17 @@ import java.util.List;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class PluginUtil public final class PluginUtil
{ {
/**
* Constructs ...
*
*/
private PluginUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *

View File

@@ -63,7 +63,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class GitUtil public final class GitUtil
{ {
/** Field description */ /** Field description */
@@ -84,6 +84,14 @@ public class GitUtil
/** the logger for GitUtil */ /** the logger for GitUtil */
private static final Logger logger = LoggerFactory.getLogger(GitUtil.class); private static final Logger logger = LoggerFactory.getLogger(GitUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private GitUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -48,12 +48,20 @@ import java.io.File;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class HgUtil public final class HgUtil
{ {
/** Field description */ /** Field description */
public static final String REVISION_TIP = "tip"; public static final String REVISION_TIP = "tip";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private HgUtil() {}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**

View File

@@ -30,6 +30,7 @@
*/ */
package sonia.scm.repository; package sonia.scm.repository;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
@@ -40,9 +41,17 @@ import org.junit.Assume;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class HgTestUtil public final class HgTestUtil
{ {
/**
* Constructs ...
*
*/
private HgTestUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -51,6 +60,7 @@ public class HgTestUtil
*/ */
public static void checkForSkip(HgRepositoryHandler handler) public static void checkForSkip(HgRepositoryHandler handler)
{ {
// skip tests if hg not in path // skip tests if hg not in path
if (!handler.isConfigured()) if (!handler.isConfigured())
{ {

View File

@@ -57,7 +57,7 @@ import java.util.Map;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class SvnUtil public final class SvnUtil
{ {
/** /**
@@ -65,6 +65,14 @@ public class SvnUtil
*/ */
private static final Logger logger = LoggerFactory.getLogger(SvnUtil.class); private static final Logger logger = LoggerFactory.getLogger(SvnUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private SvnUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -67,13 +67,21 @@ import javax.servlet.http.HttpServletResponse;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class MockUtil public final class MockUtil
{ {
/** Field description */ /** Field description */
private static final User ADMIN = new User("scmadmin", "SCM Admin", private static final User ADMIN = new User("scmadmin", "SCM Admin",
"scmadmin@scm.org"); "scmadmin@scm.org");
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private MockUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**

View File

@@ -46,7 +46,7 @@ import javax.servlet.ServletContext;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class BootstrapUtil public final class BootstrapUtil
{ {
/** Field description */ /** Field description */
@@ -56,6 +56,14 @@ public class BootstrapUtil
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(BootstrapUtil.class); LoggerFactory.getLogger(BootstrapUtil.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private BootstrapUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -96,7 +104,7 @@ public class BootstrapUtil
* @return * @return
*/ */
public static <T> T loadClass(ClassLoader classLoader, Class<T> clazz, public static <T> T loadClass(ClassLoader classLoader, Class<T> clazz,
String className) String className)
{ {
T instance = null; T instance = null;
@@ -164,7 +172,7 @@ public class BootstrapUtil
* @param classLoader * @param classLoader
*/ */
public static void setClassLoader(ServletContext context, public static void setClassLoader(ServletContext context,
ClassLoader classLoader) ClassLoader classLoader)
{ {
context.setAttribute(CLASSLOADER, classLoader); context.setAttribute(CLASSLOADER, classLoader);
} }

View File

@@ -56,7 +56,7 @@ import javax.xml.bind.Unmarshaller;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class ScmConfigurationUtil public final class ScmConfigurationUtil
{ {
/** Field description */ /** Field description */
@@ -72,13 +72,13 @@ public class ScmConfigurationUtil
* Constructs ... * Constructs ...
* *
*/ */
public ScmConfigurationUtil() private ScmConfigurationUtil()
{ {
try try
{ {
context = JAXBContext.newInstance(ScmConfiguration.class); context = JAXBContext.newInstance(ScmConfiguration.class);
file = new File(SCMContext.getContext().getBaseDirectory(), file = new File(SCMContext.getContext().getBaseDirectory(),
ScmConfiguration.PATH); ScmConfiguration.PATH);
} }
catch (JAXBException ex) catch (JAXBException ex)
{ {

View File

@@ -42,12 +42,20 @@ import sonia.scm.SCMContext;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @deprecated * @deprecated
*/ */
@Deprecated @Deprecated
public class SecurityUtil public final class SecurityUtil
{ {
/**
* Constructs ...
*
*/
private SecurityUtil() {}
//~--- get methods ----------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -57,7 +65,7 @@ public class SecurityUtil
* @return * @return
*/ */
public static String getUsername( public static String getUsername(
Provider<WebSecurityContext> securityContextProvider) Provider<WebSecurityContext> securityContextProvider)
{ {
return getUsername(securityContextProvider.get()); return getUsername(securityContextProvider.get());
} }

View File

@@ -68,7 +68,7 @@ import javax.ws.rs.core.MultivaluedMap;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class IntegrationTestUtil public final class IntegrationTestUtil
{ {
/** Field description */ /** Field description */
@@ -83,6 +83,14 @@ public class IntegrationTestUtil
/** Field description */ /** Field description */
public static final String EXTENSION = ".xml"; public static final String EXTENSION = ".xml";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
private IntegrationTestUtil() {}
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
@@ -96,7 +104,7 @@ public class IntegrationTestUtil
* @return * @return
*/ */
public static ClientResponse authenticate(Client client, String username, public static ClientResponse authenticate(Client client, String username,
String password) String password)
{ {
WebResource wr = createResource(client, "authentication/login"); WebResource wr = createResource(client, "authentication/login");
MultivaluedMap<String, String> formData = new MultivaluedMapImpl(); MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
@@ -105,7 +113,7 @@ public class IntegrationTestUtil
formData.add("password", password); formData.add("password", password);
return wr.type("application/x-www-form-urlencoded").post( return wr.type("application/x-www-form-urlencoded").post(
ClientResponse.class, formData); ClientResponse.class, formData);
} }
/** /**
@@ -165,7 +173,7 @@ public class IntegrationTestUtil
DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig(); DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
config.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, config.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES,
true); true);
return ApacheHttpClient.create(config); return ApacheHttpClient.create(config);
} }
@@ -181,7 +189,7 @@ public class IntegrationTestUtil
* @throws RepositoryClientException * @throws RepositoryClientException
*/ */
public static void createRandomFile(RepositoryClient client) public static void createRandomFile(RepositoryClient client)
throws IOException, RepositoryClientException throws IOException, RepositoryClientException
{ {
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
String name = "file-" + uuid + ".uuid"; String name = "file-" + uuid + ".uuid";
@@ -257,7 +265,7 @@ public class IntegrationTestUtil
public static File createTempDirectory() public static File createTempDirectory()
{ {
File directory = new File(System.getProperty("java.io.tmpdir"), File directory = new File(System.getProperty("java.io.tmpdir"),
UUID.randomUUID().toString()); UUID.randomUUID().toString());
IOUtil.mkdirs(directory); IOUtil.mkdirs(directory);

View File

@@ -51,9 +51,17 @@ import com.sun.jersey.api.client.WebResource;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class RepositoryITUtil public final class RepositoryITUtil
{ {
/**
* Constructs ...
*
*/
private RepositoryITUtil() {}
//~--- methods --------------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -62,7 +70,7 @@ public class RepositoryITUtil
* @param other * @param other
*/ */
public static void assertRepositoriesEquals(Repository repository, public static void assertRepositoriesEquals(Repository repository,
Repository other) Repository other)
{ {
assertEquals(repository.getName(), other.getName()); assertEquals(repository.getName(), other.getName());
assertEquals(repository.getDescription(), other.getDescription()); assertEquals(repository.getDescription(), other.getDescription());
@@ -82,7 +90,7 @@ public class RepositoryITUtil
* @return * @return
*/ */
public static Repository createRepository(Client client, public static Repository createRepository(Client client,
Repository repository) Repository repository)
{ {
WebResource wr = createResource(client, "repositories"); WebResource wr = createResource(client, "repositories");
ClientResponse response = wr.post(ClientResponse.class, repository); ClientResponse response = wr.post(ClientResponse.class, repository);