mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
fix some code smells reported by sonarqube
This commit is contained in:
@@ -36,8 +36,6 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
import sonia.scm.GenericDAO;
|
import sonia.scm.GenericDAO;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data access object for repositories. This class should only used by the
|
* Data access object for repositories. This class should only used by the
|
||||||
* {@link RepositoryManager}. Plugins and other classes should use the
|
* {@link RepositoryManager}. Plugins and other classes should use the
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ class PathDatabase {
|
|||||||
|
|
||||||
private void ensureParentDirectoryExists() {
|
private void ensureParentDirectoryExists() {
|
||||||
Path parent = storePath.getParent();
|
Path parent = storePath.getParent();
|
||||||
if (!Files.exists(parent)) {
|
// Files.exists is slow on java 8
|
||||||
|
if (!parent.toFile().exists()) {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(parent);
|
Files.createDirectories(parent);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import sonia.scm.store.StoreConstants;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -98,7 +97,8 @@ public class XmlRepositoryDAO implements PathBasedRepositoryDAO {
|
|||||||
private void read() {
|
private void read() {
|
||||||
Path storePath = createStorePath();
|
Path storePath = createStorePath();
|
||||||
|
|
||||||
if (!Files.exists(storePath)) {
|
// Files.exists is slow on java 8
|
||||||
|
if (!storePath.toFile().exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public final class XmlStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static XMLStreamReader createReader(Path path) throws IOException, XMLStreamException {
|
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 {
|
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 {
|
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 {
|
public static IndentXMLStreamWriter createWriter(File file) throws IOException, XMLStreamException {
|
||||||
|
|||||||
@@ -367,27 +367,6 @@ public class HgRepositoryHandler
|
|||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- 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
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
import sonia.scm.repository.HgHookManager;
|
import sonia.scm.repository.HgHookManager;
|
||||||
import sonia.scm.repository.HgRepositoryHandler;
|
import sonia.scm.repository.HgRepositoryHandler;
|
||||||
import sonia.scm.repository.Repository;
|
|
||||||
import sonia.scm.repository.RepositoryHookType;
|
import sonia.scm.repository.RepositoryHookType;
|
||||||
import sonia.scm.repository.api.HgHookBranchProvider;
|
import sonia.scm.repository.api.HgHookBranchProvider;
|
||||||
import sonia.scm.repository.api.HgHookMessageProvider;
|
import sonia.scm.repository.api.HgHookMessageProvider;
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
public final class RepositoryTestData {
|
public final class RepositoryTestData {
|
||||||
|
|
||||||
|
public static final String NAMESPACE = "hitchhiker";
|
||||||
|
public static final String MAIL_DOMAIN = "@hitchhiker.com";
|
||||||
|
|
||||||
private RepositoryTestData() {
|
private RepositoryTestData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +46,9 @@ public final class RepositoryTestData {
|
|||||||
public static Repository create42Puzzle(String type) {
|
public static Repository create42Puzzle(String type) {
|
||||||
return new RepositoryBuilder()
|
return new RepositoryBuilder()
|
||||||
.type(type)
|
.type(type)
|
||||||
.contact("douglas.adams@hitchhiker.com")
|
.contact("douglas.adams" + MAIL_DOMAIN)
|
||||||
.name("42Puzzle")
|
.name("42Puzzle")
|
||||||
.namespace("hitchhiker")
|
.namespace(NAMESPACE)
|
||||||
.description("The 42 Puzzle")
|
.description("The 42 Puzzle")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -58,9 +61,9 @@ public final class RepositoryTestData {
|
|||||||
public static Repository createHappyVerticalPeopleTransporter(String type) {
|
public static Repository createHappyVerticalPeopleTransporter(String type) {
|
||||||
return new RepositoryBuilder()
|
return new RepositoryBuilder()
|
||||||
.type(type)
|
.type(type)
|
||||||
.contact("zaphod.beeblebrox@hitchhiker.com")
|
.contact("zaphod.beeblebrox" + MAIL_DOMAIN)
|
||||||
.name("happyVerticalPeopleTransporter")
|
.name("happyVerticalPeopleTransporter")
|
||||||
.namespace("hitchhiker")
|
.namespace(NAMESPACE)
|
||||||
.description("Happy Vertical People Transporter")
|
.description("Happy Vertical People Transporter")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -72,9 +75,9 @@ public final class RepositoryTestData {
|
|||||||
public static Repository createHeartOfGold(String type) {
|
public static Repository createHeartOfGold(String type) {
|
||||||
return new RepositoryBuilder()
|
return new RepositoryBuilder()
|
||||||
.type(type)
|
.type(type)
|
||||||
.contact("zaphod.beeblebrox@hitchhiker.com")
|
.contact("zaphod.beeblebrox" + MAIL_DOMAIN)
|
||||||
.name("HeartOfGold")
|
.name("HeartOfGold")
|
||||||
.namespace("hitchhiker")
|
.namespace(NAMESPACE)
|
||||||
.description(
|
.description(
|
||||||
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive")
|
"Heart of Gold is the first prototype ship to successfully utilise the revolutionary Infinite Improbability Drive")
|
||||||
.build();
|
.build();
|
||||||
@@ -88,9 +91,9 @@ public final class RepositoryTestData {
|
|||||||
public static Repository createRestaurantAtTheEndOfTheUniverse(String type) {
|
public static Repository createRestaurantAtTheEndOfTheUniverse(String type) {
|
||||||
return new RepositoryBuilder()
|
return new RepositoryBuilder()
|
||||||
.type(type)
|
.type(type)
|
||||||
.contact("douglas.adams@hitchhiker.com")
|
.contact("douglas.adams" + MAIL_DOMAIN)
|
||||||
.name("RestaurantAtTheEndOfTheUniverse")
|
.name("RestaurantAtTheEndOfTheUniverse")
|
||||||
.namespace("hitchhiker")
|
.namespace(NAMESPACE)
|
||||||
.description("The Restaurant at the End of the Universe")
|
.description("The Restaurant at the End of the Universe")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import sonia.scm.AlreadyExistsException;
|
import sonia.scm.AlreadyExistsException;
|
||||||
@@ -70,20 +69,9 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.hasProperty;
|
import static org.junit.Assert.*;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.mockito.Mockito.*;
|
||||||
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;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -109,9 +97,6 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository> {
|
|||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
|
|
||||||
private ScmConfiguration configuration;
|
private ScmConfiguration configuration;
|
||||||
|
|
||||||
private String mockedNamespace = "default_namespace";
|
private String mockedNamespace = "default_namespace";
|
||||||
|
|||||||
Reference in New Issue
Block a user