fix some code smells reported by sonarqube

This commit is contained in:
Sebastian Sdorra
2018-11-30 08:19:47 +01:00
parent 53be8b112b
commit 84dd6bf60f
8 changed files with 21 additions and 55 deletions

View File

@@ -36,8 +36,6 @@ package sonia.scm.repository;
import sonia.scm.GenericDAO;
import java.io.File;
/**
* Data access object for repositories. This class should only used by the
* {@link RepositoryManager}. Plugins and other classes should use the

View File

@@ -61,7 +61,8 @@ class PathDatabase {
private void ensureParentDirectoryExists() {
Path parent = storePath.getParent();
if (!Files.exists(parent)) {
// Files.exists is slow on java 8
if (!parent.toFile().exists()) {
try {
Files.createDirectories(parent);
} catch (IOException ex) {

View File

@@ -47,7 +47,6 @@ import sonia.scm.store.StoreConstants;
import javax.inject.Inject;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Clock;
import java.util.Collection;
@@ -98,7 +97,8 @@ public class XmlRepositoryDAO implements PathBasedRepositoryDAO {
private void read() {
Path storePath = createStorePath();
if (!Files.exists(storePath)) {
// Files.exists is slow on java 8
if (!storePath.toFile().exists()) {
return;
}

View File

@@ -13,6 +13,7 @@ import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -44,7 +45,7 @@ public final class XmlStreams {
}
public static XMLStreamReader createReader(Path path) throws IOException, XMLStreamException {
return createReader(Files.newBufferedReader(path, Charsets.UTF_8));
return createReader(Files.newBufferedReader(path, StandardCharsets.UTF_8));
}
public static XMLStreamReader createReader(File file) throws IOException, XMLStreamException {
@@ -57,7 +58,7 @@ public final class XmlStreams {
public static IndentXMLStreamWriter createWriter(Path path) throws IOException, XMLStreamException {
return createWriter(Files.newBufferedWriter(path, Charsets.UTF_8));
return createWriter(Files.newBufferedWriter(path, StandardCharsets.UTF_8));
}
public static IndentXMLStreamWriter createWriter(File file) throws IOException, XMLStreamException {

View File

@@ -367,27 +367,6 @@ public class HgRepositoryHandler
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param file
*/
private void createNewFile(File file)
{
try
{
if (!file.createNewFile() && logger.isErrorEnabled())
{
logger.error("could not create file {}", file);
}
}
catch (IOException ex)
{
logger.error("could not create file {}".concat(file.getPath()), ex);
}
}
/**
* Method description
*

View File

@@ -35,7 +35,6 @@ package sonia.scm.repository.spi;
import sonia.scm.repository.HgHookManager;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryHookType;
import sonia.scm.repository.api.HgHookBranchProvider;
import sonia.scm.repository.api.HgHookMessageProvider;

View File

@@ -33,6 +33,9 @@ package sonia.scm.repository;
public final class RepositoryTestData {
public static final String NAMESPACE = "hitchhiker";
public static final String MAIL_DOMAIN = "@hitchhiker.com";
private RepositoryTestData() {
}
@@ -43,9 +46,9 @@ public final class RepositoryTestData {
public static Repository create42Puzzle(String type) {
return new RepositoryBuilder()
.type(type)
.contact("douglas.adams@hitchhiker.com")
.contact("douglas.adams" + MAIL_DOMAIN)
.name("42Puzzle")
.namespace("hitchhiker")
.namespace(NAMESPACE)
.description("The 42 Puzzle")
.build();
}
@@ -58,9 +61,9 @@ public final class RepositoryTestData {
public static Repository createHappyVerticalPeopleTransporter(String type) {
return new RepositoryBuilder()
.type(type)
.contact("zaphod.beeblebrox@hitchhiker.com")
.contact("zaphod.beeblebrox" + MAIL_DOMAIN)
.name("happyVerticalPeopleTransporter")
.namespace("hitchhiker")
.namespace(NAMESPACE)
.description("Happy Vertical People Transporter")
.build();
}
@@ -72,9 +75,9 @@ public final class RepositoryTestData {
public static Repository createHeartOfGold(String type) {
return new RepositoryBuilder()
.type(type)
.contact("zaphod.beeblebrox@hitchhiker.com")
.contact("zaphod.beeblebrox" + MAIL_DOMAIN)
.name("HeartOfGold")
.namespace("hitchhiker")
.namespace(NAMESPACE)
.description(
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive")
.build();
@@ -88,9 +91,9 @@ public final class RepositoryTestData {
public static Repository createRestaurantAtTheEndOfTheUniverse(String type) {
return new RepositoryBuilder()
.type(type)
.contact("douglas.adams@hitchhiker.com")
.contact("douglas.adams" + MAIL_DOMAIN)
.name("RestaurantAtTheEndOfTheUniverse")
.namespace("hitchhiker")
.namespace(NAMESPACE)
.description("The Restaurant at the End of the Universe")
.build();
}

View File

@@ -43,7 +43,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import sonia.scm.AlreadyExistsException;
@@ -70,20 +69,9 @@ import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
//~--- JDK imports ------------------------------------------------------------
@@ -109,9 +97,6 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository> {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private ScmConfiguration configuration;
private String mockedNamespace = "default_namespace";