fix some warning and removed some unused imports

This commit is contained in:
Sebastian Sdorra
2017-01-14 12:05:53 +01:00
parent c149b180a1
commit 7e6f4e1a7f
5 changed files with 26 additions and 59 deletions

View File

@@ -52,12 +52,10 @@ import sonia.scm.util.AssertUtil;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContextProvider;
import sonia.scm.schedule.Scheduler;
import sonia.scm.schedule.Task;
@@ -307,21 +305,17 @@ public class GitRepositoryHandler
protected void create(Repository repository, File directory)
throws RepositoryException, IOException
{
org.eclipse.jgit.lib.Repository gitRepository = null;
try
{
gitRepository = new FileRepositoryBuilder().setGitDir(
directory).readEnvironment().findGitDir().build();
try (org.eclipse.jgit.lib.Repository gitRepository = build(directory)) {
gitRepository.create(true);
}
finally
{
if (gitRepository != null)
{
gitRepository.close();
}
}
}
private org.eclipse.jgit.lib.Repository build(File directory) throws IOException {
return new FileRepositoryBuilder()
.setGitDir(directory)
.readEnvironment()
.findGitDir()
.build();
}
/**

View File

@@ -269,7 +269,7 @@ public class GitBrowseCommand extends AbstractGitCommand
walk.markStart(commit);
result = Util.getFirst(walk);
}
catch (Exception ex)
catch (IOException ex)
{
logger.error("could not parse commit for file", ex);
}
@@ -414,7 +414,7 @@ public class GitBrowseCommand extends AbstractGitCommand
revision);
}
Map<String, SubRepository> subRepositories = null;
Map<String, SubRepository> subRepositories;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
@@ -456,7 +456,6 @@ public class GitBrowseCommand extends AbstractGitCommand
//~--- fields ---------------------------------------------------------------
/** Field description */
private Map<ObjectId, Map<String, SubRepository>> subrepositoryCache =
Maps.newHashMap();
/** sub repository cache */
private final Map<ObjectId, Map<String, SubRepository>> subrepositoryCache = Maps.newHashMap();
}

View File

@@ -36,6 +36,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import com.google.common.io.Closer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -126,7 +127,6 @@ public class AbstractHgHandler
* @param handler
* @param context
* @param repository
* @param repositoryDirectory
*/
protected AbstractHgHandler(HgRepositoryHandler handler, HgContext context,
Repository repository)
@@ -166,7 +166,7 @@ public class AbstractHgHandler
*/
protected Map<String, String> createEnvironment(String revision, String path)
{
Map<String, String> env = new HashMap<String, String>();
Map<String, String> env = new HashMap<>();
env.put(ENV_REVISION, HgUtil.getRevision(revision));
env.put(ENV_PATH, Util.nonNull(path));
@@ -301,31 +301,16 @@ public class AbstractHgHandler
throws IOException, RepositoryException
{
Process p = createScriptProcess(script, extraEnv);
T result = null;
InputStream input = null;
OutputStream output = null;
try
{
handleErrorStream(p.getErrorStream());
input = p.getInputStream();
result =
(T) handler.getJaxbContext().createUnmarshaller().unmarshal(input);
input.close();
}
catch (JAXBException ex)
{
handleErrorStream(p.getErrorStream());
try (InputStream input = p.getInputStream()) {
return (T) handler.getJaxbContext().createUnmarshaller().unmarshal(input);
} catch (JAXBException ex) {
logger.error("could not parse result", ex);
throw new RepositoryException("could not parse result", ex);
}
finally
{
Closeables.closeQuietly(input);
Closeables.closeQuietly(output);
}
return result;
}
//~--- methods --------------------------------------------------------------

View File

@@ -34,7 +34,6 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import com.google.common.io.Resources;
import org.junit.Rule;
@@ -109,20 +108,13 @@ public class HgWindowsPackageFixTest
*/
private File createHgBat(String number) throws IOException
{
URL url =
Resources.getResource("sonia/scm/repository/hg.bat.".concat(number));
URL url = Resources.getResource("sonia/scm/repository/hg.bat.".concat(number));
File file = tempFolder.newFile(number);
FileOutputStream fos = null;
try
try (FileOutputStream fos = new FileOutputStream(file))
{
fos = new FileOutputStream(file);
Resources.copy(url, fos);
}
finally
{
Closeables.closeQuietly(fos);
}
return file;
}

View File

@@ -112,11 +112,8 @@ public class SvnBrowseCommand extends AbstractSvnCommand
String path = request.getPath();
long revisionNumber = SvnUtil.getRevisionNumber(request.getRevision());
if (logger.isDebugEnabled())
{
logger.debug("browser repository {} in path {} at revision {}",
new Object[] { repository.getName(),
path, revisionNumber });
if (logger.isDebugEnabled()) {
logger.debug("browser repository {} in path {} at revision {}", repository.getName(), path, revisionNumber);
}
BrowserResult result = null;