mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
merge 2.0.0-m3
This commit is contained in:
@@ -178,7 +178,7 @@ public final class LogCommandBuilder
|
|||||||
logger.debug("get changeset for {} with disabled cache", id);
|
logger.debug("get changeset for {} with disabled cache", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeset = logCommand.getChangeset(id);
|
changeset = logCommand.getChangeset(id, request);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -192,7 +192,7 @@ public final class LogCommandBuilder
|
|||||||
logger.debug("get changeset for {}", id);
|
logger.debug("get changeset for {}", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeset = logCommand.getChangeset(id);
|
changeset = logCommand.getChangeset(id, request);
|
||||||
|
|
||||||
if (changeset != null)
|
if (changeset != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public interface LogCommand {
|
public interface LogCommand {
|
||||||
|
|
||||||
Changeset getChangeset(String id) throws IOException;
|
Changeset getChangeset(String id, LogCommandRequest request) throws IOException;
|
||||||
|
|
||||||
ChangesetPagingResult getChangesets(LogCommandRequest request) throws IOException;
|
ChangesetPagingResult getChangesets(LogCommandRequest request) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import sonia.scm.repository.Repository;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C> {
|
public abstract class SimpleWorkdirFactory<R, W, C> implements WorkdirFactory<R, W, C> {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SimpleWorkdirFactory.class);
|
private static final Logger logger = LoggerFactory.getLogger(SimpleWorkdirFactory.class);
|
||||||
|
|
||||||
@@ -19,11 +19,11 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorkingCopy<R> createWorkingCopy(C context, String initialBranch) {
|
public WorkingCopy<R, W> createWorkingCopy(C context, String initialBranch) {
|
||||||
try {
|
try {
|
||||||
File directory = workdirProvider.createNewWorkdir();
|
File directory = workdirProvider.createNewWorkdir();
|
||||||
ParentAndClone<R> parentAndClone = cloneRepository(context, directory, initialBranch);
|
ParentAndClone<R, W> parentAndClone = cloneRepository(context, directory, initialBranch);
|
||||||
return new WorkingCopy<>(parentAndClone.getClone(), parentAndClone.getParent(), this::close, directory);
|
return new WorkingCopy<>(parentAndClone.getClone(), parentAndClone.getParent(), this::closeWorkdir, this::closeCentral, directory);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new InternalRepositoryException(getScmRepository(context), "could not clone repository in temporary directory", e);
|
throw new InternalRepositoryException(getScmRepository(context), "could not clone repository in temporary directory", e);
|
||||||
}
|
}
|
||||||
@@ -32,12 +32,15 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
|
|||||||
protected abstract Repository getScmRepository(C context);
|
protected abstract Repository getScmRepository(C context);
|
||||||
|
|
||||||
@SuppressWarnings("squid:S00112")
|
@SuppressWarnings("squid:S00112")
|
||||||
// We do allow implementations to throw arbitrary exceptions here, so that we can handle them in close
|
// We do allow implementations to throw arbitrary exceptions here, so that we can handle them in closeCentral
|
||||||
protected abstract void closeRepository(R repository) throws Exception;
|
protected abstract void closeRepository(R repository) throws Exception;
|
||||||
|
@SuppressWarnings("squid:S00112")
|
||||||
|
// We do allow implementations to throw arbitrary exceptions here, so that we can handle them in closeWorkdir
|
||||||
|
protected abstract void closeWorkdirInternal(W workdir) throws Exception;
|
||||||
|
|
||||||
protected abstract ParentAndClone<R> cloneRepository(C context, File target, String initialBranch) throws IOException;
|
protected abstract ParentAndClone<R, W> cloneRepository(C context, File target, String initialBranch) throws IOException;
|
||||||
|
|
||||||
private void close(R repository) {
|
private void closeCentral(R repository) {
|
||||||
try {
|
try {
|
||||||
closeRepository(repository);
|
closeRepository(repository);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -45,11 +48,19 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class ParentAndClone<R> {
|
private void closeWorkdir(W repository) {
|
||||||
private final R parent;
|
try {
|
||||||
private final R clone;
|
closeWorkdirInternal(repository);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("could not close temporary repository clone", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ParentAndClone(R parent, R clone) {
|
protected static class ParentAndClone<R, W> {
|
||||||
|
private final R parent;
|
||||||
|
private final W clone;
|
||||||
|
|
||||||
|
public ParentAndClone(R parent, W clone) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.clone = clone;
|
this.clone = clone;
|
||||||
}
|
}
|
||||||
@@ -58,7 +69,7 @@ public abstract class SimpleWorkdirFactory<R, C> implements WorkdirFactory<R, C>
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public R getClone() {
|
public W getClone() {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package sonia.scm.repository.util;
|
package sonia.scm.repository.util;
|
||||||
|
|
||||||
public interface WorkdirFactory<R, C> {
|
public interface WorkdirFactory<R, W, C> {
|
||||||
WorkingCopy<R> createWorkingCopy(C context, String initialBranch);
|
WorkingCopy<R, W> createWorkingCopy(C context, String initialBranch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,23 +8,25 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class WorkingCopy<R> implements AutoCloseable {
|
public class WorkingCopy<R, W> implements AutoCloseable {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WorkingCopy.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WorkingCopy.class);
|
||||||
|
|
||||||
private final File directory;
|
private final File directory;
|
||||||
private final R workingRepository;
|
private final W workingRepository;
|
||||||
private final R centralRepository;
|
private final R centralRepository;
|
||||||
private final Consumer<R> cleanup;
|
private final Consumer<W> cleanupWorkdir;
|
||||||
|
private final Consumer<R> cleanupCentral;
|
||||||
|
|
||||||
public WorkingCopy(R workingRepository, R centralRepository, Consumer<R> cleanup, File directory) {
|
public WorkingCopy(W workingRepository, R centralRepository, Consumer<W> cleanupWorkdir, Consumer<R> cleanupCentral, File directory) {
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.workingRepository = workingRepository;
|
this.workingRepository = workingRepository;
|
||||||
this.centralRepository = centralRepository;
|
this.centralRepository = centralRepository;
|
||||||
this.cleanup = cleanup;
|
this.cleanupCentral = cleanupCentral;
|
||||||
|
this.cleanupWorkdir = cleanupWorkdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public R getWorkingRepository() {
|
public W getWorkingRepository() {
|
||||||
return workingRepository;
|
return workingRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +41,8 @@ public class WorkingCopy<R> implements AutoCloseable {
|
|||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
cleanup.accept(workingRepository);
|
cleanupWorkdir.accept(workingRepository);
|
||||||
cleanup.accept(centralRepository);
|
cleanupCentral.accept(centralRepository);
|
||||||
IOUtil.delete(directory);
|
IOUtil.delete(directory);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn("could not delete temporary workdir '{}'", directory, e);
|
LOG.warn("could not delete temporary workdir '{}'", directory, e);
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ public class SimpleWorkdirFactoryTest {
|
|||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
private SimpleWorkdirFactory<Closeable, Context> simpleWorkdirFactory;
|
private SimpleWorkdirFactory<Closeable, Closeable, Context> simpleWorkdirFactory;
|
||||||
|
|
||||||
private String initialBranchForLastCloneCall;
|
private String initialBranchForLastCloneCall;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void initFactory() throws IOException {
|
public void initFactory() throws IOException {
|
||||||
WorkdirProvider workdirProvider = new WorkdirProvider(temporaryFolder.newFolder());
|
WorkdirProvider workdirProvider = new WorkdirProvider(temporaryFolder.newFolder());
|
||||||
simpleWorkdirFactory = new SimpleWorkdirFactory<Closeable, Context>(workdirProvider) {
|
simpleWorkdirFactory = new SimpleWorkdirFactory<Closeable, Closeable, Context>(workdirProvider) {
|
||||||
@Override
|
@Override
|
||||||
protected Repository getScmRepository(Context context) {
|
protected Repository getScmRepository(Context context) {
|
||||||
return REPOSITORY;
|
return REPOSITORY;
|
||||||
@@ -43,7 +43,12 @@ public class SimpleWorkdirFactoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ParentAndClone<Closeable> cloneRepository(Context context, File target, String initialBranch) {
|
protected void closeWorkdirInternal(Closeable workdir) throws Exception {
|
||||||
|
workdir.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ParentAndClone<Closeable, Closeable> cloneRepository(Context context, File target, String initialBranch) {
|
||||||
initialBranchForLastCloneCall = initialBranch;
|
initialBranchForLastCloneCall = initialBranch;
|
||||||
return new ParentAndClone<>(parent, clone);
|
return new ParentAndClone<>(parent, clone);
|
||||||
}
|
}
|
||||||
@@ -53,7 +58,7 @@ public class SimpleWorkdirFactoryTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldCreateParentAndClone() {
|
public void shouldCreateParentAndClone() {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
try (WorkingCopy<Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, null)) {
|
try (WorkingCopy<Closeable, Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, null)) {
|
||||||
assertThat(workingCopy.getCentralRepository()).isSameAs(parent);
|
assertThat(workingCopy.getCentralRepository()).isSameAs(parent);
|
||||||
assertThat(workingCopy.getWorkingRepository()).isSameAs(clone);
|
assertThat(workingCopy.getWorkingRepository()).isSameAs(clone);
|
||||||
}
|
}
|
||||||
@@ -62,7 +67,7 @@ public class SimpleWorkdirFactoryTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldCloseParent() throws IOException {
|
public void shouldCloseParent() throws IOException {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
try (WorkingCopy<Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, null)) {}
|
try (WorkingCopy<Closeable, Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, null)) {}
|
||||||
|
|
||||||
verify(parent).close();
|
verify(parent).close();
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,7 @@ public class SimpleWorkdirFactoryTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldCloseClone() throws IOException {
|
public void shouldCloseClone() throws IOException {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
try (WorkingCopy<Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, null)) {}
|
try (WorkingCopy<Closeable, Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, null)) {}
|
||||||
|
|
||||||
verify(clone).close();
|
verify(clone).close();
|
||||||
}
|
}
|
||||||
@@ -78,7 +83,7 @@ public class SimpleWorkdirFactoryTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldPropagateInitialBranch() {
|
public void shouldPropagateInitialBranch() {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
try (WorkingCopy<Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, "some")) {
|
try (WorkingCopy<Closeable, Closeable> workingCopy = simpleWorkdirFactory.createWorkingCopy(context, "some")) {
|
||||||
assertThat(initialBranchForLastCloneCall).isEqualTo("some");
|
assertThat(initialBranchForLastCloneCall).isEqualTo("some");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import org.eclipse.jgit.lib.Repository;
|
|||||||
import sonia.scm.repository.spi.GitContext;
|
import sonia.scm.repository.spi.GitContext;
|
||||||
import sonia.scm.repository.util.WorkdirFactory;
|
import sonia.scm.repository.util.WorkdirFactory;
|
||||||
|
|
||||||
public interface GitWorkdirFactory extends WorkdirFactory<Repository, GitContext> {
|
public interface GitWorkdirFactory extends WorkdirFactory<Repository, Repository, GitContext> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class AbstractGitCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
<R, W extends GitCloneWorker<R>> R inClone(Function<Git, W> workerSupplier, GitWorkdirFactory workdirFactory, String initialBranch) {
|
<R, W extends GitCloneWorker<R>> R inClone(Function<Git, W> workerSupplier, GitWorkdirFactory workdirFactory, String initialBranch) {
|
||||||
try (WorkingCopy<Repository> workingCopy = workdirFactory.createWorkingCopy(context, initialBranch)) {
|
try (WorkingCopy<Repository, Repository> workingCopy = workdirFactory.createWorkingCopy(context, initialBranch)) {
|
||||||
Repository repository = workingCopy.getWorkingRepository();
|
Repository repository = workingCopy.getWorkingRepository();
|
||||||
logger.debug("cloned repository to folder {}", repository.getWorkTree());
|
logger.debug("cloned repository to folder {}", repository.getWorkTree());
|
||||||
return workerSupplier.apply(new Git(repository)).run();
|
return workerSupplier.apply(new Git(repository)).run();
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Branch branch(BranchRequest request) {
|
public Branch branch(BranchRequest request) {
|
||||||
try (WorkingCopy<org.eclipse.jgit.lib.Repository> workingCopy = workdirFactory.createWorkingCopy(context, request.getParentBranch())) {
|
try (WorkingCopy<org.eclipse.jgit.lib.Repository, org.eclipse.jgit.lib.Repository> workingCopy = workdirFactory.createWorkingCopy(context, request.getParentBranch())) {
|
||||||
Git clone = new Git(workingCopy.getWorkingRepository());
|
Git clone = new Git(workingCopy.getWorkingRepository());
|
||||||
Ref ref = clone.branchCreate().setName(request.getNewBranch()).call();
|
Ref ref = clone.branchCreate().setName(request.getNewBranch()).call();
|
||||||
Iterable<PushResult> call = clone.push().add(request.getNewBranch()).call();
|
Iterable<PushResult> call = clone.push().add(request.getNewBranch()).call();
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Changeset getChangeset(String revision)
|
public Changeset getChangeset(String revision, LogCommandRequest request)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
@@ -131,7 +131,18 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
|||||||
if (commit != null)
|
if (commit != null)
|
||||||
{
|
{
|
||||||
converter = new GitChangesetConverter(gr, revWalk);
|
converter = new GitChangesetConverter(gr, revWalk);
|
||||||
changeset = converter.createChangeset(commit);
|
|
||||||
|
if (isBranchRequested(request)) {
|
||||||
|
String branch = request.getBranch();
|
||||||
|
if (isMergedIntoBranch(gr, revWalk, commit, branch)) {
|
||||||
|
logger.trace("returning commit {} with branch {}", commit.getId(), branch);
|
||||||
|
changeset = converter.createChangeset(commit, branch);
|
||||||
|
} else {
|
||||||
|
logger.debug("returning null, because commit {} was not merged into branch {}", commit.getId(), branch);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
changeset = converter.createChangeset(commit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (logger.isWarnEnabled())
|
else if (logger.isWarnEnabled())
|
||||||
{
|
{
|
||||||
@@ -157,6 +168,18 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
|||||||
return changeset;
|
return changeset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isMergedIntoBranch(Repository repository, RevWalk revWalk, RevCommit commit, String branchName) throws IOException {
|
||||||
|
return revWalk.isMergedInto(commit, findHeadCommitOfBranch(repository, revWalk, branchName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBranchRequested(LogCommandRequest request) {
|
||||||
|
return request != null && !Strings.isNullOrEmpty(request.getBranch());
|
||||||
|
}
|
||||||
|
|
||||||
|
private RevCommit findHeadCommitOfBranch(Repository repository, RevWalk revWalk, String branchName) throws IOException {
|
||||||
|
return revWalk.parseCommit(GitUtil.getCommit(repository, revWalk, repository.findRef(branchName)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.io.IOException;
|
|||||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||||
import static sonia.scm.NotFoundException.notFound;
|
import static sonia.scm.NotFoundException.notFound;
|
||||||
|
|
||||||
public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, GitContext> implements GitWorkdirFactory {
|
public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, Repository, GitContext> implements GitWorkdirFactory {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SimpleGitWorkdirFactory(WorkdirProvider workdirProvider) {
|
public SimpleGitWorkdirFactory(WorkdirProvider workdirProvider) {
|
||||||
@@ -26,7 +26,7 @@ public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, Gi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParentAndClone<Repository> cloneRepository(GitContext context, File target, String initialBranch) {
|
public ParentAndClone<Repository, Repository> cloneRepository(GitContext context, File target, String initialBranch) {
|
||||||
try {
|
try {
|
||||||
Repository clone = Git.cloneRepository()
|
Repository clone = Git.cloneRepository()
|
||||||
.setURI(createScmTransportProtocolUri(context.getDirectory()))
|
.setURI(createScmTransportProtocolUri(context.getDirectory()))
|
||||||
@@ -60,6 +60,13 @@ public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, Gi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void closeWorkdirInternal(Repository workdir) throws Exception {
|
||||||
|
if (workdir != null) {
|
||||||
|
workdir.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected sonia.scm.repository.Repository getScmRepository(GitContext context) {
|
protected sonia.scm.repository.Repository getScmRepository(GitContext context) {
|
||||||
return context.getRepository();
|
return context.getRepository();
|
||||||
|
|||||||
@@ -35,7 +35,11 @@
|
|||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
import sonia.scm.repository.ChangesetPagingResult;
|
import sonia.scm.repository.ChangesetPagingResult;
|
||||||
import sonia.scm.repository.GitRepositoryConfig;
|
import sonia.scm.repository.GitRepositoryConfig;
|
||||||
@@ -51,14 +55,18 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link GitLogCommand}.
|
* Unit tests for {@link GitLogCommand}.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class GitLogCommandTest extends AbstractGitCommandTestBase
|
public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||||
{
|
{
|
||||||
|
@Mock
|
||||||
|
LogCommandRequest request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests log command with the usage of a default branch.
|
* Tests log command with the usage of a default branch.
|
||||||
@@ -171,7 +179,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
public void testGetCommit()
|
public void testGetCommit()
|
||||||
{
|
{
|
||||||
GitLogCommand command = createCommand();
|
GitLogCommand command = createCommand();
|
||||||
Changeset c = command.getChangeset("435df2f061add3589cb3");
|
Changeset c = command.getChangeset("435df2f061add3589cb3", null);
|
||||||
|
|
||||||
assertNotNull(c);
|
assertNotNull(c);
|
||||||
String revision = "435df2f061add3589cb326cc64be9b9c3897ceca";
|
String revision = "435df2f061add3589cb326cc64be9b9c3897ceca";
|
||||||
@@ -193,6 +201,23 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
|||||||
assertThat(modifications.getAdded(), contains("a.txt", "b.txt"));
|
assertThat(modifications.getAdded(), contains("a.txt", "b.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void commitShouldContainBranchIfLogCommandRequestHasBranch()
|
||||||
|
{
|
||||||
|
when(request.getBranch()).thenReturn("master");
|
||||||
|
GitLogCommand command = createCommand();
|
||||||
|
Changeset c = command.getChangeset("435df2f061add3589cb3", request);
|
||||||
|
|
||||||
|
Assertions.assertThat(c.getBranches()).containsOnly("master");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotReturnCommitFromDifferentBranch() {
|
||||||
|
when(request.getBranch()).thenReturn("master");
|
||||||
|
Changeset changeset = createCommand().getChangeset("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", request);
|
||||||
|
Assertions.assertThat(changeset).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRange()
|
public void testGetRange()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class SimpleGitWorkdirFactoryTest extends AbstractGitCommandTestBase {
|
|||||||
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
||||||
File masterRepo = createRepositoryDirectory();
|
File masterRepo = createRepositoryDirectory();
|
||||||
|
|
||||||
try (WorkingCopy<Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
try (WorkingCopy<Repository, Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
|
|
||||||
assertThat(workingCopy.getDirectory())
|
assertThat(workingCopy.getDirectory())
|
||||||
.exists()
|
.exists()
|
||||||
@@ -62,7 +62,7 @@ public class SimpleGitWorkdirFactoryTest extends AbstractGitCommandTestBase {
|
|||||||
public void shouldCheckoutInitialBranch() {
|
public void shouldCheckoutInitialBranch() {
|
||||||
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
||||||
|
|
||||||
try (WorkingCopy<Repository> workingCopy = factory.createWorkingCopy(createContext(), "test-branch")) {
|
try (WorkingCopy<Repository, Repository> workingCopy = factory.createWorkingCopy(createContext(), "test-branch")) {
|
||||||
assertThat(new File(workingCopy.getWorkingRepository().getWorkTree(), "a.txt"))
|
assertThat(new File(workingCopy.getWorkingRepository().getWorkTree(), "a.txt"))
|
||||||
.exists()
|
.exists()
|
||||||
.isFile()
|
.isFile()
|
||||||
@@ -75,10 +75,10 @@ public class SimpleGitWorkdirFactoryTest extends AbstractGitCommandTestBase {
|
|||||||
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
||||||
|
|
||||||
File firstDirectory;
|
File firstDirectory;
|
||||||
try (WorkingCopy<Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
try (WorkingCopy<Repository, Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
firstDirectory = workingCopy.getDirectory();
|
firstDirectory = workingCopy.getDirectory();
|
||||||
}
|
}
|
||||||
try (WorkingCopy<Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
try (WorkingCopy<Repository, Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
File secondDirectory = workingCopy.getDirectory();
|
File secondDirectory = workingCopy.getDirectory();
|
||||||
assertThat(secondDirectory).isNotEqualTo(firstDirectory);
|
assertThat(secondDirectory).isNotEqualTo(firstDirectory);
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ public class SimpleGitWorkdirFactoryTest extends AbstractGitCommandTestBase {
|
|||||||
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
SimpleGitWorkdirFactory factory = new SimpleGitWorkdirFactory(workdirProvider);
|
||||||
|
|
||||||
File directory;
|
File directory;
|
||||||
try (WorkingCopy<Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
try (WorkingCopy<Repository, Repository> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
directory = workingCopy.getWorkingRepository().getWorkTree();
|
directory = workingCopy.getWorkingRepository().getWorkTree();
|
||||||
}
|
}
|
||||||
assertThat(directory).doesNotExist();
|
assertThat(directory).doesNotExist();
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class HgBranchCommand extends AbstractCommand implements BranchCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Branch branch(BranchRequest request) {
|
public Branch branch(BranchRequest request) {
|
||||||
try (WorkingCopy<com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(getContext(), request.getParentBranch())) {
|
try (WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(getContext(), request.getParentBranch())) {
|
||||||
com.aragost.javahg.Repository repository = workingCopy.getWorkingRepository();
|
com.aragost.javahg.Repository repository = workingCopy.getWorkingRepository();
|
||||||
|
|
||||||
Changeset emptyChangeset = createNewBranchWithEmptyCommit(request, repository);
|
Changeset emptyChangeset = createNewBranchWithEmptyCommit(request, repository);
|
||||||
@@ -83,7 +83,7 @@ public class HgBranchCommand extends AbstractCommand implements BranchCommand {
|
|||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pullNewBranchIntoCentralRepository(BranchRequest request, WorkingCopy<com.aragost.javahg.Repository> workingCopy) {
|
private void pullNewBranchIntoCentralRepository(BranchRequest request, WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy) {
|
||||||
try {
|
try {
|
||||||
PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
||||||
workdirFactory.configure(pullCommand);
|
workdirFactory.configure(pullCommand);
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.aragost.javahg.Changeset;
|
||||||
|
import com.aragost.javahg.commands.LogCommand;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import sonia.scm.repository.BrowserResult;
|
import sonia.scm.repository.BrowserResult;
|
||||||
@@ -72,10 +74,10 @@ public class HgBrowseCommand extends AbstractCommand implements BrowseCommand
|
|||||||
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws IOException {
|
public BrowserResult getBrowserResult(BrowseCommandRequest request) throws IOException {
|
||||||
HgFileviewCommand cmd = HgFileviewCommand.on(open());
|
HgFileviewCommand cmd = HgFileviewCommand.on(open());
|
||||||
|
|
||||||
if (!Strings.isNullOrEmpty(request.getRevision()))
|
String revision = MoreObjects.firstNonNull(request.getRevision(), "tip");
|
||||||
{
|
Changeset c = LogCommand.on(getContext().open()).rev(revision).limit(1).single();
|
||||||
cmd.rev(request.getRevision());
|
|
||||||
}
|
cmd.rev(c.getNode());
|
||||||
|
|
||||||
if (!Strings.isNullOrEmpty(request.getPath()))
|
if (!Strings.isNullOrEmpty(request.getPath()))
|
||||||
{
|
{
|
||||||
@@ -98,6 +100,6 @@ public class HgBrowseCommand extends AbstractCommand implements BrowseCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileObject file = cmd.execute();
|
FileObject file = cmd.execute();
|
||||||
return new BrowserResult(MoreObjects.firstNonNull(request.getRevision(), "tip"), file);
|
return new BrowserResult(c.getNode(), revision, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class HgLogCommand extends AbstractCommand implements LogCommand
|
|||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Changeset getChangeset(String id) {
|
public Changeset getChangeset(String id, LogCommandRequest request) {
|
||||||
com.aragost.javahg.Repository repository = open();
|
com.aragost.javahg.Repository repository = open();
|
||||||
HgLogChangesetCommand cmd = on(repository);
|
HgLogChangesetCommand cmd = on(repository);
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class HgModifyCommand implements ModifyCommand {
|
|||||||
@Override
|
@Override
|
||||||
public String execute(ModifyCommandRequest request) {
|
public String execute(ModifyCommandRequest request) {
|
||||||
|
|
||||||
try (WorkingCopy<com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(context, request.getBranch())) {
|
try (WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy = workdirFactory.createWorkingCopy(context, request.getBranch())) {
|
||||||
Repository workingRepository = workingCopy.getWorkingRepository();
|
Repository workingRepository = workingCopy.getWorkingRepository();
|
||||||
request.getRequests().forEach(
|
request.getRequests().forEach(
|
||||||
partialRequest -> {
|
partialRequest -> {
|
||||||
@@ -85,7 +85,7 @@ public class HgModifyCommand implements ModifyCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Changeset> pullModifyChangesToCentralRepository(ModifyCommandRequest request, WorkingCopy<com.aragost.javahg.Repository> workingCopy) {
|
private List<Changeset> pullModifyChangesToCentralRepository(ModifyCommandRequest request, WorkingCopy<com.aragost.javahg.Repository, com.aragost.javahg.Repository> workingCopy) {
|
||||||
try {
|
try {
|
||||||
com.aragost.javahg.commands.PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
com.aragost.javahg.commands.PullCommand pullCommand = PullCommand.on(workingCopy.getCentralRepository());
|
||||||
workdirFactory.configure(pullCommand);
|
workdirFactory.configure(pullCommand);
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ import com.aragost.javahg.Repository;
|
|||||||
import com.aragost.javahg.commands.PullCommand;
|
import com.aragost.javahg.commands.PullCommand;
|
||||||
import sonia.scm.repository.util.WorkdirFactory;
|
import sonia.scm.repository.util.WorkdirFactory;
|
||||||
|
|
||||||
public interface HgWorkdirFactory extends WorkdirFactory<Repository, HgCommandContext> {
|
public interface HgWorkdirFactory extends WorkdirFactory<Repository, Repository, HgCommandContext> {
|
||||||
void configure(PullCommand pullCommand);
|
void configure(PullCommand pullCommand);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.io.IOException;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public class SimpleHgWorkdirFactory extends SimpleWorkdirFactory<Repository, HgCommandContext> implements HgWorkdirFactory {
|
public class SimpleHgWorkdirFactory extends SimpleWorkdirFactory<Repository, Repository, HgCommandContext> implements HgWorkdirFactory {
|
||||||
|
|
||||||
private final Provider<HgRepositoryEnvironmentBuilder> hgRepositoryEnvironmentBuilder;
|
private final Provider<HgRepositoryEnvironmentBuilder> hgRepositoryEnvironmentBuilder;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ public class SimpleHgWorkdirFactory extends SimpleWorkdirFactory<Repository, HgC
|
|||||||
this.hgRepositoryEnvironmentBuilder = hgRepositoryEnvironmentBuilder;
|
this.hgRepositoryEnvironmentBuilder = hgRepositoryEnvironmentBuilder;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public ParentAndClone<Repository> cloneRepository(HgCommandContext context, File target, String initialBranch) throws IOException {
|
public ParentAndClone<Repository, Repository> cloneRepository(HgCommandContext context, File target, String initialBranch) throws IOException {
|
||||||
BiConsumer<sonia.scm.repository.Repository, Map<String, String>> repositoryMapBiConsumer =
|
BiConsumer<sonia.scm.repository.Repository, Map<String, String>> repositoryMapBiConsumer =
|
||||||
(repository, environment) -> hgRepositoryEnvironmentBuilder.get().buildFor(repository, null, environment);
|
(repository, environment) -> hgRepositoryEnvironmentBuilder.get().buildFor(repository, null, environment);
|
||||||
Repository centralRepository = context.openWithSpecialEnvironment(repositoryMapBiConsumer);
|
Repository centralRepository = context.openWithSpecialEnvironment(repositoryMapBiConsumer);
|
||||||
@@ -46,6 +46,11 @@ public class SimpleHgWorkdirFactory extends SimpleWorkdirFactory<Repository, HgC
|
|||||||
repository.close();
|
repository.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void closeWorkdirInternal(Repository workdir) throws Exception {
|
||||||
|
workdir.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected sonia.scm.repository.Repository getScmRepository(HgCommandContext context) {
|
protected sonia.scm.repository.Repository getScmRepository(HgCommandContext context) {
|
||||||
return context.getScmRepository();
|
return context.getScmRepository();
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.commands.LogCommand;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import sonia.scm.repository.BrowserResult;
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.FileObject;
|
import sonia.scm.repository.FileObject;
|
||||||
@@ -40,6 +41,7 @@ import sonia.scm.repository.FileObject;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@@ -79,6 +81,19 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase {
|
|||||||
assertEquals("c", c.getPath());
|
assertEquals("c", c.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBrowseShouldResolveBranchForRevision() throws IOException {
|
||||||
|
String defaultBranchRevision = new LogCommand(cmdContext.open()).rev("default").single().getNode();
|
||||||
|
|
||||||
|
BrowseCommandRequest browseCommandRequest = new BrowseCommandRequest();
|
||||||
|
browseCommandRequest.setRevision("default");
|
||||||
|
|
||||||
|
BrowserResult result = new HgBrowseCommand(cmdContext,
|
||||||
|
repository).getBrowserResult(browseCommandRequest);
|
||||||
|
|
||||||
|
assertThat(result.getRevision()).isEqualTo(defaultBranchRevision);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBrowseSubDirectory() throws IOException {
|
public void testBrowseSubDirectory() throws IOException {
|
||||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class HgLogCommandTest extends AbstractHgCommandTestBase
|
|||||||
HgLogCommand command = createComamnd();
|
HgLogCommand command = createComamnd();
|
||||||
String revision = "a9bacaf1b7fa0cebfca71fed4e59ed69a6319427";
|
String revision = "a9bacaf1b7fa0cebfca71fed4e59ed69a6319427";
|
||||||
Changeset c =
|
Changeset c =
|
||||||
command.getChangeset(revision);
|
command.getChangeset(revision, null);
|
||||||
|
|
||||||
assertNotNull(c);
|
assertNotNull(c);
|
||||||
assertEquals(revision, c.getId());
|
assertEquals(revision, c.getId());
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
import sonia.scm.repository.spi.SvnContext;
|
||||||
|
import sonia.scm.repository.util.WorkdirFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public interface SvnWorkDirFactory extends WorkdirFactory<File, File, SvnContext> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.exception.CloneFailedException;
|
||||||
|
import org.tmatesoft.svn.core.SVNException;
|
||||||
|
import org.tmatesoft.svn.core.SVNURL;
|
||||||
|
import org.tmatesoft.svn.core.wc2.SvnCheckout;
|
||||||
|
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
|
||||||
|
import org.tmatesoft.svn.core.wc2.SvnTarget;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.SvnWorkDirFactory;
|
||||||
|
import sonia.scm.repository.util.SimpleWorkdirFactory;
|
||||||
|
import sonia.scm.repository.util.WorkdirProvider;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class SimpleSvnWorkDirFactory extends SimpleWorkdirFactory<File, File, SvnContext> implements SvnWorkDirFactory {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public SimpleSvnWorkDirFactory(WorkdirProvider workdirProvider) {
|
||||||
|
super(workdirProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Repository getScmRepository(SvnContext context) {
|
||||||
|
return context.getRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ParentAndClone<File, File> cloneRepository(SvnContext context, File workingCopy, String initialBranch) {
|
||||||
|
|
||||||
|
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
|
||||||
|
|
||||||
|
SVNURL source;
|
||||||
|
try {
|
||||||
|
source = SVNURL.fromFile(context.getDirectory());
|
||||||
|
} catch (SVNException ex) {
|
||||||
|
throw new CloneFailedException(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final SvnCheckout checkout = svnOperationFactory.createCheckout();
|
||||||
|
checkout.setSingleTarget(SvnTarget.fromFile(workingCopy));
|
||||||
|
checkout.setSource(SvnTarget.fromURL(source));
|
||||||
|
checkout.run();
|
||||||
|
} catch (SVNException ex) {
|
||||||
|
throw new CloneFailedException(ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
svnOperationFactory.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ParentAndClone<>(context.getDirectory(), workingCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void closeRepository(File workingCopy) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void closeWorkdirInternal(File workdir) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,113 +42,57 @@ import org.tmatesoft.svn.core.SVNURL;
|
|||||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||||
|
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.SvnUtil;
|
import sonia.scm.repository.SvnUtil;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class SvnContext implements Closeable
|
public class SvnContext implements Closeable {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
private static final Logger LOG = LoggerFactory.getLogger(SvnContext.class);
|
||||||
* the logger for SvnContext
|
|
||||||
*/
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(SvnContext.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
private final Repository repository;
|
||||||
|
private final File directory;
|
||||||
|
|
||||||
/**
|
private SVNRepository svnRepository;
|
||||||
* Constructs ...
|
|
||||||
*
|
public SvnContext(Repository repository, File directory) {
|
||||||
*
|
this.repository = repository;
|
||||||
* @param directory
|
|
||||||
*/
|
|
||||||
public SvnContext(File directory)
|
|
||||||
{
|
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
public Repository getRepository() {
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
logger.trace("close svn repository {}", directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
SvnUtil.closeSession(repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws SVNException
|
|
||||||
*/
|
|
||||||
public SVNURL createUrl() throws SVNException
|
|
||||||
{
|
|
||||||
return SVNURL.fromFile(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws SVNException
|
|
||||||
*/
|
|
||||||
public SVNRepository open() throws SVNException
|
|
||||||
{
|
|
||||||
if (repository == null)
|
|
||||||
{
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
logger.trace("open svn repository {}", directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
repository = SVNRepositoryFactory.create(createUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
public File getDirectory() {
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public File getDirectory()
|
|
||||||
{
|
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
public SVNURL createUrl() throws SVNException {
|
||||||
|
return SVNURL.fromFile(directory);
|
||||||
|
}
|
||||||
|
|
||||||
/** Field description */
|
public SVNRepository open() throws SVNException {
|
||||||
private File directory;
|
if (svnRepository == null) {
|
||||||
|
LOG.trace("open svn repository {}", directory);
|
||||||
|
svnRepository = SVNRepositoryFactory.create(createUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
return svnRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
LOG.trace("close svn repository {}", directory);
|
||||||
|
SvnUtil.closeSession(svnRepository);
|
||||||
|
}
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private SVNRepository repository;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Changeset getChangeset(String revision) {
|
public Changeset getChangeset(String revision, LogCommandRequest request) {
|
||||||
Changeset changeset = null;
|
Changeset changeset = null;
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.tmatesoft.svn.core.SVNCommitInfo;
|
||||||
|
import org.tmatesoft.svn.core.SVNDepth;
|
||||||
|
import org.tmatesoft.svn.core.SVNException;
|
||||||
|
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||||
|
import org.tmatesoft.svn.core.wc.SVNWCClient;
|
||||||
|
import sonia.scm.repository.InternalRepositoryException;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.SvnWorkDirFactory;
|
||||||
|
import sonia.scm.repository.util.WorkingCopy;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class SvnModifyCommand implements ModifyCommand {
|
||||||
|
|
||||||
|
private SvnContext context;
|
||||||
|
private SvnWorkDirFactory workDirFactory;
|
||||||
|
private Repository repository;
|
||||||
|
|
||||||
|
SvnModifyCommand(SvnContext context, Repository repository, SvnWorkDirFactory workDirFactory) {
|
||||||
|
this.context = context;
|
||||||
|
this.repository = repository;
|
||||||
|
this.workDirFactory = workDirFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(ModifyCommandRequest request) {
|
||||||
|
SVNClientManager clientManager = SVNClientManager.newInstance();
|
||||||
|
try (WorkingCopy<File, File> workingCopy = workDirFactory.createWorkingCopy(context, null)) {
|
||||||
|
File workingDirectory = workingCopy.getDirectory();
|
||||||
|
modifyWorkingDirectory(request, clientManager, workingDirectory);
|
||||||
|
return commitChanges(clientManager, workingDirectory, request.getCommitMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String commitChanges(SVNClientManager clientManager, File workingDirectory, String commitMessage) {
|
||||||
|
try {
|
||||||
|
SVNCommitInfo svnCommitInfo = clientManager.getCommitClient().doCommit(
|
||||||
|
new File[]{workingDirectory},
|
||||||
|
false,
|
||||||
|
commitMessage,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
SVNDepth.INFINITY
|
||||||
|
);
|
||||||
|
return String.valueOf(svnCommitInfo.getNewRevision());
|
||||||
|
} catch (SVNException e) {
|
||||||
|
throw new InternalRepositoryException(repository, "could not commit changes on repository");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyWorkingDirectory(ModifyCommandRequest request, SVNClientManager clientManager, File workingDirectory) {
|
||||||
|
for (ModifyCommandRequest.PartialRequest partialRequest : request.getRequests()) {
|
||||||
|
try {
|
||||||
|
SVNWCClient wcClient = clientManager.getWCClient();
|
||||||
|
partialRequest.execute(new ModifyWorker(wcClient, workingDirectory));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new InternalRepositoryException(repository, "could not read files from repository");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ModifyWorker implements ModifyWorkerHelper {
|
||||||
|
private final SVNWCClient wcClient;
|
||||||
|
private final File workingDirectory;
|
||||||
|
|
||||||
|
private ModifyWorker(SVNWCClient wcClient, File workingDirectory) {
|
||||||
|
this.wcClient = wcClient;
|
||||||
|
this.workingDirectory = workingDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doScmDelete(String toBeDeleted) {
|
||||||
|
try {
|
||||||
|
wcClient.doDelete(new File(workingDirectory, toBeDeleted), true, true, false);
|
||||||
|
} catch (SVNException e) {
|
||||||
|
throw new InternalRepositoryException(repository, "could not delete file from repository");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFileToScm(String name, Path file) {
|
||||||
|
try {
|
||||||
|
wcClient.doAdd(
|
||||||
|
file.toFile(),
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
SVNDepth.INFINITY,
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
} catch (SVNException e) {
|
||||||
|
throw new InternalRepositoryException(repository, "could not add file to repository");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getWorkDir() {
|
||||||
|
return workingDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Repository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBranch() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,8 +37,10 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.SvnRepositoryHandler;
|
import sonia.scm.repository.SvnRepositoryHandler;
|
||||||
|
import sonia.scm.repository.SvnWorkDirFactory;
|
||||||
import sonia.scm.repository.api.Command;
|
import sonia.scm.repository.api.Command;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -53,17 +55,19 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
//J-
|
//J-
|
||||||
public static final Set<Command> COMMANDS = ImmutableSet.of(
|
public static final Set<Command> COMMANDS = ImmutableSet.of(
|
||||||
Command.BLAME, Command.BROWSE, Command.CAT, Command.DIFF,
|
Command.BLAME, Command.BROWSE, Command.CAT, Command.DIFF,
|
||||||
Command.LOG, Command.BUNDLE, Command.UNBUNDLE
|
Command.LOG, Command.BUNDLE, Command.UNBUNDLE, Command.MODIFY
|
||||||
);
|
);
|
||||||
//J+
|
//J+
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
@Inject
|
||||||
SvnRepositoryServiceProvider(SvnRepositoryHandler handler,
|
SvnRepositoryServiceProvider(SvnRepositoryHandler handler,
|
||||||
Repository repository)
|
Repository repository, SvnWorkDirFactory workdirFactory)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.context = new SvnContext(handler.getDirectory(repository.getId()));
|
this.context = new SvnContext(repository, handler.getDirectory(repository.getId()));
|
||||||
|
this.workDirFactory = workdirFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -158,6 +162,10 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
return new SvnModificationsCommand(context, repository);
|
return new SvnModificationsCommand(context, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModifyCommand getModifyCommand() {
|
||||||
|
return new SvnModifyCommand(context, repository, workDirFactory);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -189,4 +197,6 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private final Repository repository;
|
private final Repository repository;
|
||||||
|
|
||||||
|
private final SvnWorkDirFactory workDirFactory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,15 +36,18 @@ import com.google.inject.Inject;
|
|||||||
import sonia.scm.plugin.Extension;
|
import sonia.scm.plugin.Extension;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.SvnRepositoryHandler;
|
import sonia.scm.repository.SvnRepositoryHandler;
|
||||||
|
import sonia.scm.repository.SvnWorkDirFactory;
|
||||||
|
|
||||||
@Extension
|
@Extension
|
||||||
public class SvnRepositoryServiceResolver implements RepositoryServiceResolver {
|
public class SvnRepositoryServiceResolver implements RepositoryServiceResolver {
|
||||||
|
|
||||||
private SvnRepositoryHandler handler;
|
private SvnRepositoryHandler handler;
|
||||||
|
private SvnWorkDirFactory workdirFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler) {
|
public SvnRepositoryServiceResolver(SvnRepositoryHandler handler, SvnWorkDirFactory workdirFactory) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
this.workdirFactory = workdirFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,7 +55,7 @@ public class SvnRepositoryServiceResolver implements RepositoryServiceResolver {
|
|||||||
SvnRepositoryServiceProvider provider = null;
|
SvnRepositoryServiceProvider provider = null;
|
||||||
|
|
||||||
if (SvnRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
if (SvnRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType())) {
|
||||||
provider = new SvnRepositoryServiceProvider(handler, repository);
|
provider = new SvnRepositoryServiceProvider(handler, repository, workdirFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider;
|
return provider;
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import org.mapstruct.factory.Mappers;
|
|||||||
import sonia.scm.api.v2.resources.SvnConfigDtoToSvnConfigMapper;
|
import sonia.scm.api.v2.resources.SvnConfigDtoToSvnConfigMapper;
|
||||||
import sonia.scm.api.v2.resources.SvnConfigToSvnConfigDtoMapper;
|
import sonia.scm.api.v2.resources.SvnConfigToSvnConfigDtoMapper;
|
||||||
import sonia.scm.plugin.Extension;
|
import sonia.scm.plugin.Extension;
|
||||||
|
import sonia.scm.repository.SvnWorkDirFactory;
|
||||||
|
import sonia.scm.repository.spi.SimpleSvnWorkDirFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -50,5 +52,6 @@ public class SvnServletModule extends ServletModule {
|
|||||||
protected void configureServlets() {
|
protected void configureServlets() {
|
||||||
bind(SvnConfigDtoToSvnConfigMapper.class).to(Mappers.getMapper(SvnConfigDtoToSvnConfigMapper.class).getClass());
|
bind(SvnConfigDtoToSvnConfigMapper.class).to(Mappers.getMapper(SvnConfigDtoToSvnConfigMapper.class).getClass());
|
||||||
bind(SvnConfigToSvnConfigDtoMapper.class).to(Mappers.getMapper(SvnConfigToSvnConfigDtoMapper.class).getClass());
|
bind(SvnConfigToSvnConfigDtoMapper.class).to(Mappers.getMapper(SvnConfigToSvnConfigDtoMapper.class).getClass());
|
||||||
|
bind(SvnWorkDirFactory.class).to(SimpleSvnWorkDirFactory.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class AbstractSvnCommandTestBase extends ZippedRepositoryTestBase
|
|||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
{
|
{
|
||||||
context = new SvnContext(repositoryDirectory);
|
context = new SvnContext(repository, repositoryDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
import org.tmatesoft.svn.core.SVNException;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.util.WorkdirProvider;
|
||||||
|
import sonia.scm.repository.util.WorkingCopy;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class SimpleSvnWorkDirFactoryTest extends AbstractSvnCommandTestBase {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
// keep this so that it will not be garbage collected (Transport keeps this in a week reference)
|
||||||
|
private WorkdirProvider workdirProvider;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initWorkDirProvider() throws IOException {
|
||||||
|
workdirProvider = new WorkdirProvider(temporaryFolder.newFolder());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCheckoutLatestRevision() throws SVNException, IOException {
|
||||||
|
SimpleSvnWorkDirFactory factory = new SimpleSvnWorkDirFactory(workdirProvider);
|
||||||
|
|
||||||
|
try (WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
|
assertThat(new File(workingCopy.getWorkingRepository(), "a.txt"))
|
||||||
|
.exists()
|
||||||
|
.isFile()
|
||||||
|
.hasContent("a and b\nline for blame test");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cloneFromPoolshouldNotBeReused() {
|
||||||
|
SimpleSvnWorkDirFactory factory = new SimpleSvnWorkDirFactory(workdirProvider);
|
||||||
|
|
||||||
|
File firstDirectory;
|
||||||
|
try (WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
|
firstDirectory = workingCopy.getDirectory();
|
||||||
|
}
|
||||||
|
try (WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
|
File secondDirectory = workingCopy.getDirectory();
|
||||||
|
assertThat(secondDirectory).isNotEqualTo(firstDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDeleteCloneOnClose() {
|
||||||
|
SimpleSvnWorkDirFactory factory = new SimpleSvnWorkDirFactory(workdirProvider);
|
||||||
|
|
||||||
|
File directory;
|
||||||
|
File workingRepository;
|
||||||
|
try (WorkingCopy<File, File> workingCopy = factory.createWorkingCopy(createContext(), null)) {
|
||||||
|
directory = workingCopy.getDirectory();
|
||||||
|
workingRepository = workingCopy.getWorkingRepository();
|
||||||
|
|
||||||
|
}
|
||||||
|
assertThat(directory).doesNotExist();
|
||||||
|
assertThat(workingRepository).doesNotExist();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnRepository() {
|
||||||
|
SimpleSvnWorkDirFactory factory = new SimpleSvnWorkDirFactory(workdirProvider);
|
||||||
|
Repository scmRepository = factory.getScmRepository(createContext());
|
||||||
|
assertThat(scmRepository).isSameAs(repository);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -128,7 +128,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCommit() {
|
public void testGetCommit() {
|
||||||
Changeset c = createCommand().getChangeset("3");
|
Changeset c = createCommand().getChangeset("3", null);
|
||||||
|
|
||||||
assertNotNull(c);
|
assertNotNull(c);
|
||||||
assertEquals("3", c.getId());
|
assertEquals("3", c.getId());
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
import sonia.scm.AlreadyExistsException;
|
||||||
|
import sonia.scm.repository.Person;
|
||||||
|
import sonia.scm.repository.util.WorkdirProvider;
|
||||||
|
import sonia.scm.repository.util.WorkingCopy;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
public class SvnModifyCommandTest extends AbstractSvnCommandTestBase {
|
||||||
|
|
||||||
|
private SvnModifyCommand svnModifyCommand;
|
||||||
|
private SvnContext context;
|
||||||
|
private SimpleSvnWorkDirFactory workDirFactory;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initSvnModifyCommand() {
|
||||||
|
context = createContext();
|
||||||
|
workDirFactory = new SimpleSvnWorkDirFactory(new WorkdirProvider(context.getDirectory()));
|
||||||
|
svnModifyCommand = new SvnModifyCommand(context, createRepository(), workDirFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRemoveFiles() {
|
||||||
|
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||||
|
request.addRequest(new ModifyCommandRequest.DeleteFileRequest("a.txt"));
|
||||||
|
request.setCommitMessage("this is great");
|
||||||
|
request.setAuthor(new Person("Arthur Dent", "dent@hitchhiker.com"));
|
||||||
|
|
||||||
|
svnModifyCommand.execute(request);
|
||||||
|
WorkingCopy<File, File> workingCopy = workDirFactory.createWorkingCopy(context, null);
|
||||||
|
assertThat(new File(workingCopy.getWorkingRepository().getAbsolutePath() + "/a.txt")).doesNotExist();
|
||||||
|
assertThat(new File(workingCopy.getWorkingRepository().getAbsolutePath() + "/c")).exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldAddNewFile() throws IOException {
|
||||||
|
File testfile = temporaryFolder.newFile("Test123");
|
||||||
|
|
||||||
|
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||||
|
request.addRequest(new ModifyCommandRequest.CreateFileRequest("Test123", testfile, false));
|
||||||
|
request.setCommitMessage("this is great");
|
||||||
|
request.setAuthor(new Person("Arthur Dent", "dent@hitchhiker.com"));
|
||||||
|
|
||||||
|
svnModifyCommand.execute(request);
|
||||||
|
|
||||||
|
WorkingCopy<File, File> workingCopy = workDirFactory.createWorkingCopy(context, null);
|
||||||
|
assertThat(new File(workingCopy.getWorkingRepository(), "Test123")).exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldThrowFileAlreadyExistsException() throws IOException {
|
||||||
|
File testfile = temporaryFolder.newFile("a.txt");
|
||||||
|
|
||||||
|
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||||
|
request.addRequest(new ModifyCommandRequest.CreateFileRequest("a.txt", testfile, false));
|
||||||
|
request.setCommitMessage("this is great");
|
||||||
|
request.setAuthor(new Person("Arthur Dent", "dent@hitchhiker.com"));
|
||||||
|
|
||||||
|
assertThrows(AlreadyExistsException.class, () -> svnModifyCommand.execute(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldUpdateExistingFile() throws IOException {
|
||||||
|
File testfile = temporaryFolder.newFile("a.txt");
|
||||||
|
|
||||||
|
ModifyCommandRequest request = new ModifyCommandRequest();
|
||||||
|
request.addRequest(new ModifyCommandRequest.CreateFileRequest("a.txt", testfile, true));
|
||||||
|
request.setCommitMessage("this is great");
|
||||||
|
request.setAuthor(new Person("Arthur Dent", "dent@hitchhiker.com"));
|
||||||
|
|
||||||
|
svnModifyCommand.execute(request);
|
||||||
|
|
||||||
|
WorkingCopy<File, File> workingCopy = workDirFactory.createWorkingCopy(context, null);
|
||||||
|
assertThat(new File(workingCopy.getWorkingRepository(), "a.txt")).exists();
|
||||||
|
assertThat(new File(workingCopy.getWorkingRepository(), "a.txt")).hasContent("");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -116,6 +116,6 @@ public class SvnUnbundleCommandTest extends AbstractSvnCommandTestBase
|
|||||||
|
|
||||||
SVNRepositoryFactory.createLocalRepository(folder, true, true);
|
SVNRepositoryFactory.createLocalRepository(folder, true, true);
|
||||||
|
|
||||||
return new SvnContext(folder);
|
return new SvnContext(repository, folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,8 +212,8 @@ public final class MockUtil
|
|||||||
{
|
{
|
||||||
SCMContextProvider provider = mock(SCMContextProvider.class);
|
SCMContextProvider provider = mock(SCMContextProvider.class);
|
||||||
|
|
||||||
when(provider.getBaseDirectory()).thenReturn(directory);
|
lenient().when(provider.getBaseDirectory()).thenReturn(directory);
|
||||||
when(provider.resolve(any(Path.class))).then(ic -> {
|
lenient().when(provider.resolve(any(Path.class))).then(ic -> {
|
||||||
Path p = ic.getArgument(0);
|
Path p = ic.getArgument(0);
|
||||||
return directory.toPath().resolve(p);
|
return directory.toPath().resolve(p);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ type Props = WithTranslation & {
|
|||||||
repository: Repository;
|
repository: Repository;
|
||||||
branch: Branch;
|
branch: Branch;
|
||||||
defaultBranch: Branch;
|
defaultBranch: Branch;
|
||||||
branches: Branch[];
|
|
||||||
revision: string;
|
revision: string;
|
||||||
path: string;
|
path: string;
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
|
sources: File;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FlexStartNav = styled.nav`
|
const FlexStartNav = styled.nav`
|
||||||
@@ -59,7 +59,12 @@ class Breadcrumb extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { baseUrl, branch, defaultBranch, branches, revision, path, repository, t } = this.props;
|
const { repository, baseUrl, branch, defaultBranch, sources, revision, path, t } = this.props;
|
||||||
|
|
||||||
|
let homeUrl = baseUrl + "/";
|
||||||
|
if (revision) {
|
||||||
|
homeUrl += encodeURIComponent(revision) + "/";
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -67,7 +72,7 @@ class Breadcrumb extends React.Component<Props> {
|
|||||||
<FlexStartNav className={classNames("breadcrumb", "sources-breadcrumb")} aria-label="breadcrumbs">
|
<FlexStartNav className={classNames("breadcrumb", "sources-breadcrumb")} aria-label="breadcrumbs">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<Link to={baseUrl + "/" + revision + "/"}>
|
<Link to={homeUrl}>
|
||||||
<HomeIcon title={t("breadcrumb.home")} name="home" color="inherit" />
|
<HomeIcon title={t("breadcrumb.home")} name="home" color="inherit" />
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
@@ -80,9 +85,10 @@ class Breadcrumb extends React.Component<Props> {
|
|||||||
name="repos.sources.actionbar"
|
name="repos.sources.actionbar"
|
||||||
props={{
|
props={{
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
revision,
|
||||||
branch: branch ? branch : defaultBranch,
|
branch: branch ? branch : defaultBranch,
|
||||||
path,
|
path,
|
||||||
isBranchUrl: branches && branches.filter(b => b.name.replace("/", "%2F") === revision).length > 0,
|
sources,
|
||||||
repository
|
repository
|
||||||
}}
|
}}
|
||||||
renderAll={true}
|
renderAll={true}
|
||||||
|
|||||||
@@ -113,7 +113,10 @@
|
|||||||
"description": "Beschreibung",
|
"description": "Beschreibung",
|
||||||
"size": "Größe"
|
"size": "Größe"
|
||||||
},
|
},
|
||||||
"noSources": "Keine Sources in diesem Branch gefunden."
|
"noSources": "Keine Sources in diesem Branch gefunden.",
|
||||||
|
"extension" : {
|
||||||
|
"notBound": "Keine Erweiterung angebunden."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"permission": {
|
"permission": {
|
||||||
"title": "Berechtigungen bearbeiten",
|
"title": "Berechtigungen bearbeiten",
|
||||||
|
|||||||
@@ -113,7 +113,10 @@
|
|||||||
"description": "Description",
|
"description": "Description",
|
||||||
"size": "Size"
|
"size": "Size"
|
||||||
},
|
},
|
||||||
"noSources": "No sources found for this branch."
|
"noSources": "No sources found for this branch.",
|
||||||
|
"extension" : {
|
||||||
|
"notBound": "No extension bound."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"permission": {
|
"permission": {
|
||||||
"title": "Edit Permissions",
|
"title": "Edit Permissions",
|
||||||
|
|||||||
@@ -113,7 +113,10 @@
|
|||||||
"description": "Discripción",
|
"description": "Discripción",
|
||||||
"size": "tamaño"
|
"size": "tamaño"
|
||||||
},
|
},
|
||||||
"noSources": "No se han encontrado fuentes para esta rama."
|
"noSources": "No se han encontrado fuentes para esta rama.",
|
||||||
|
"extension" : {
|
||||||
|
"notBound": "Sin extensión conectada."
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"permission": {
|
"permission": {
|
||||||
"title": "Editar permisos",
|
"title": "Editar permisos",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import PermissionsNavLink from "../components/PermissionsNavLink";
|
|||||||
import Sources from "../sources/containers/Sources";
|
import Sources from "../sources/containers/Sources";
|
||||||
import RepositoryNavLink from "../components/RepositoryNavLink";
|
import RepositoryNavLink from "../components/RepositoryNavLink";
|
||||||
import { getLinks, getRepositoriesLink } from "../../modules/indexResource";
|
import { getLinks, getRepositoriesLink } from "../../modules/indexResource";
|
||||||
|
import SourceExtensions from "../sources/containers/SourceExtensions";
|
||||||
|
|
||||||
type Props = WithTranslation & {
|
type Props = WithTranslation & {
|
||||||
namespace: string;
|
namespace: string;
|
||||||
@@ -67,6 +68,12 @@ class RepositoryRoot extends React.Component<Props> {
|
|||||||
return route.location.pathname.match(regex);
|
return route.location.pathname.match(regex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
matchesSources = (route: any) => {
|
||||||
|
const url = this.matchedUrl();
|
||||||
|
const regex = new RegExp(`${url}(/sources|/sourceext)/.*`);
|
||||||
|
return route.location.pathname.match(regex);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { loading, error, indexLinks, repository, t } = this.props;
|
const { loading, error, indexLinks, repository, t } = this.props;
|
||||||
|
|
||||||
@@ -120,6 +127,15 @@ class RepositoryRoot extends React.Component<Props> {
|
|||||||
path={`${url}/sources/:revision/:path*`}
|
path={`${url}/sources/:revision/:path*`}
|
||||||
render={() => <Sources repository={repository} baseUrl={`${url}/sources`} />}
|
render={() => <Sources repository={repository} baseUrl={`${url}/sources`} />}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path={`${url}/sourceext/:extension`}
|
||||||
|
exact={true}
|
||||||
|
render={() => <SourceExtensions repository={repository} />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path={`${url}/sourceext/:extension/:revision/:path*`}
|
||||||
|
render={() => <SourceExtensions repository={repository} />}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={`${url}/changesets`}
|
path={`${url}/changesets`}
|
||||||
render={() => (
|
render={() => (
|
||||||
@@ -186,6 +202,7 @@ class RepositoryRoot extends React.Component<Props> {
|
|||||||
to={`${url}/sources`}
|
to={`${url}/sources`}
|
||||||
icon="fas fa-code"
|
icon="fas fa-code"
|
||||||
label={t("repositoryRoot.menu.sourcesNavLink")}
|
label={t("repositoryRoot.menu.sourcesNavLink")}
|
||||||
|
activeWhenMatch={this.matchesSources}
|
||||||
activeOnlyWhenExact={false}
|
activeOnlyWhenExact={false}
|
||||||
/>
|
/>
|
||||||
<ExtensionPoint name="repository.navigation" props={extensionProps} renderAll={true} />
|
<ExtensionPoint name="repository.navigation" props={extensionProps} renderAll={true} />
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class Content extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
showHeader() {
|
showHeader() {
|
||||||
const { file, revision } = this.props;
|
const { repository, file, revision } = this.props;
|
||||||
const { showHistory, collapsed } = this.state;
|
const { showHistory, collapsed } = this.state;
|
||||||
const icon = collapsed ? "angle-right" : "angle-down";
|
const icon = collapsed ? "angle-right" : "angle-down";
|
||||||
|
|
||||||
@@ -99,6 +99,7 @@ class Content extends React.Component<Props, State> {
|
|||||||
<ExtensionPoint
|
<ExtensionPoint
|
||||||
name="repos.sources.content.actionbar"
|
name="repos.sources.content.actionbar"
|
||||||
props={{
|
props={{
|
||||||
|
repository,
|
||||||
file,
|
file,
|
||||||
revision,
|
revision,
|
||||||
handleExtensionError: this.handleExtensionError
|
handleExtensionError: this.handleExtensionError
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Repository, File } from "@scm-manager/ui-types";
|
||||||
|
import { withRouter, RouteComponentProps } from "react-router-dom";
|
||||||
|
|
||||||
|
import { ExtensionPoint, binder } from "@scm-manager/ui-extensions";
|
||||||
|
import { fetchSources, getFetchSourcesFailure, getSources, isFetchSourcesPending } from "../modules/sources";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
import { Loading, ErrorNotification } from "@scm-manager/ui-components";
|
||||||
|
import Notification from "@scm-manager/ui-components/src/Notification";
|
||||||
|
import {WithTranslation, withTranslation} from "react-i18next";
|
||||||
|
|
||||||
|
type Props = WithTranslation & RouteComponentProps & {
|
||||||
|
repository: Repository;
|
||||||
|
|
||||||
|
// url params
|
||||||
|
extension: string;
|
||||||
|
revision?: string;
|
||||||
|
path?: string;
|
||||||
|
|
||||||
|
// redux state
|
||||||
|
loading: boolean;
|
||||||
|
error?: Error | null;
|
||||||
|
sources?: File | null;
|
||||||
|
|
||||||
|
// dispatch props
|
||||||
|
fetchSources: (repository: Repository, revision: string, path: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const extensionPointName = "repos.sources.extensions";
|
||||||
|
|
||||||
|
class SourceExtensions extends React.Component<Props> {
|
||||||
|
componentDidMount() {
|
||||||
|
const { fetchSources, repository, revision, path } = this.props;
|
||||||
|
// TODO get typing right
|
||||||
|
fetchSources(repository,revision || "", path || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { loading, error, repository, extension, revision, path, sources, t } = this.props;
|
||||||
|
if (error) {
|
||||||
|
return <ErrorNotification error={error} />;
|
||||||
|
}
|
||||||
|
if (loading) {
|
||||||
|
return <Loading />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const extprops = { extension, repository, revision, path, sources };
|
||||||
|
if (!binder.hasExtension(extensionPointName, extprops)) {
|
||||||
|
return <Notification type="warning">{t("sources.extension.notBound")}</Notification>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <ExtensionPoint name={extensionPointName} props={extprops} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state: any, ownProps: Props): Partial<Props> => {
|
||||||
|
const { repository, match } = ownProps;
|
||||||
|
// @ts-ignore
|
||||||
|
const revision: string = match.params.revision;
|
||||||
|
// @ts-ignore
|
||||||
|
const path: string = match.params.path;
|
||||||
|
// @ts-ignore
|
||||||
|
const extension: string = match.params.extension;
|
||||||
|
const loading = isFetchSourcesPending(state, repository, revision, path);
|
||||||
|
const error = getFetchSourcesFailure(state, repository, revision, path);
|
||||||
|
const sources = getSources(state, repository, revision, path);
|
||||||
|
|
||||||
|
return {
|
||||||
|
repository,
|
||||||
|
extension,
|
||||||
|
revision,
|
||||||
|
path,
|
||||||
|
loading,
|
||||||
|
error,
|
||||||
|
sources
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch: any) => {
|
||||||
|
return {
|
||||||
|
fetchSources: (repository: Repository, revision: string, path: string) => {
|
||||||
|
dispatch(fetchSources(repository, decodeURIComponent(revision), path));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withRouter(
|
||||||
|
connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(withTranslation("repos")(SourceExtensions))
|
||||||
|
);
|
||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
} from "../../branches/modules/branches";
|
} from "../../branches/modules/branches";
|
||||||
import { compose } from "redux";
|
import { compose } from "redux";
|
||||||
import Content from "./Content";
|
import Content from "./Content";
|
||||||
import { fetchSources, isDirectory } from "../modules/sources";
|
import {fetchSources, getSources, isDirectory} from "../modules/sources";
|
||||||
|
|
||||||
type Props = WithTranslation & {
|
type Props = WithTranslation & {
|
||||||
repository: Repository;
|
repository: Repository;
|
||||||
@@ -24,6 +24,7 @@ type Props = WithTranslation & {
|
|||||||
revision: string;
|
revision: string;
|
||||||
path: string;
|
path: string;
|
||||||
currentFileIsDirectory: boolean;
|
currentFileIsDirectory: boolean;
|
||||||
|
sources: File;
|
||||||
|
|
||||||
// dispatch props
|
// dispatch props
|
||||||
fetchBranches: (p: Repository) => void;
|
fetchBranches: (p: Repository) => void;
|
||||||
@@ -52,7 +53,7 @@ class Sources extends React.Component<Props, State> {
|
|||||||
const { fetchBranches, repository, revision, path, fetchSources } = this.props;
|
const { fetchBranches, repository, revision, path, fetchSources } = this.props;
|
||||||
|
|
||||||
fetchBranches(repository);
|
fetchBranches(repository);
|
||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, this.decodeRevision(revision), path);
|
||||||
|
|
||||||
this.redirectToDefaultBranch();
|
this.redirectToDefaultBranch();
|
||||||
}
|
}
|
||||||
@@ -60,12 +61,16 @@ class Sources extends React.Component<Props, State> {
|
|||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const { fetchSources, repository, revision, path } = this.props;
|
const { fetchSources, repository, revision, path } = this.props;
|
||||||
if (prevProps.revision !== revision || prevProps.path !== path) {
|
if (prevProps.revision !== revision || prevProps.path !== path) {
|
||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, this.decodeRevision(revision), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.redirectToDefaultBranch();
|
this.redirectToDefaultBranch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decodeRevision = (revision: string) => {
|
||||||
|
return revision ? decodeURIComponent(revision) : revision;
|
||||||
|
};
|
||||||
|
|
||||||
redirectToDefaultBranch = () => {
|
redirectToDefaultBranch = () => {
|
||||||
const { branches } = this.props;
|
const { branches } = this.props;
|
||||||
if (this.shouldRedirectToDefaultBranch()) {
|
if (this.shouldRedirectToDefaultBranch()) {
|
||||||
@@ -148,23 +153,22 @@ class Sources extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
renderBreadcrumb = () => {
|
renderBreadcrumb = () => {
|
||||||
const { revision, path, baseUrl, branches, repository } = this.props;
|
const { revision, path, baseUrl, branches, sources, repository } = this.props;
|
||||||
const { selectedBranch } = this.state;
|
const { selectedBranch } = this.state;
|
||||||
|
|
||||||
if (revision) {
|
return (
|
||||||
return (
|
<Breadcrumb
|
||||||
<Breadcrumb
|
repository={repository}
|
||||||
revision={encodeURIComponent(revision)}
|
revision={revision}
|
||||||
path={path}
|
path={path}
|
||||||
baseUrl={baseUrl}
|
baseUrl={baseUrl}
|
||||||
branch={selectedBranch}
|
branch={selectedBranch}
|
||||||
defaultBranch={branches && branches.filter(b => b.defaultBranch === true)[0]}
|
defaultBranch={
|
||||||
branches={branches}
|
branches && branches.filter(b => b.defaultBranch === true)[0]
|
||||||
repository={repository}
|
}
|
||||||
/>
|
sources={sources}
|
||||||
);
|
/>
|
||||||
}
|
);
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,15 +182,17 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
const currentFileIsDirectory = decodedRevision
|
const currentFileIsDirectory = decodedRevision
|
||||||
? isDirectory(state, repository, decodedRevision, path)
|
? isDirectory(state, repository, decodedRevision, path)
|
||||||
: isDirectory(state, repository, revision, path);
|
: isDirectory(state, repository, revision, path);
|
||||||
|
const sources = getSources(state, repository, decodedRevision, path);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
repository,
|
repository,
|
||||||
revision: decodedRevision,
|
revision,
|
||||||
path,
|
path,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
branches,
|
branches,
|
||||||
currentFileIsDirectory
|
currentFileIsDirectory,
|
||||||
|
sources
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as types from "../../../modules/types";
|
import * as types from "../../../modules/types";
|
||||||
import { Repository, File, Action } from "@scm-manager/ui-types";
|
import { Repository, File, Action, Link } from "@scm-manager/ui-types";
|
||||||
import { apiClient } from "@scm-manager/ui-components";
|
import { apiClient } from "@scm-manager/ui-components";
|
||||||
import { isPending } from "../../../modules/pending";
|
import { isPending } from "../../../modules/pending";
|
||||||
import { getFailure } from "../../../modules/failure";
|
import { getFailure } from "../../../modules/failure";
|
||||||
@@ -25,7 +25,7 @@ export function fetchSources(repository: Repository, revision: string, path: str
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createUrl(repository: Repository, revision: string, path: string) {
|
function createUrl(repository: Repository, revision: string, path: string) {
|
||||||
const base = repository._links.sources.href;
|
const base = (repository._links.sources as Link).href;
|
||||||
if (!revision && !path) {
|
if (!revision && !path) {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ export function fetchSourcesFailure(repository: Repository, revision: string, pa
|
|||||||
function createItemId(repository: Repository, revision: string, path: string) {
|
function createItemId(repository: Repository, revision: string, path: string) {
|
||||||
const revPart = revision ? revision : "_";
|
const revPart = revision ? revision : "_";
|
||||||
const pathPart = path ? path : "";
|
const pathPart = path ? path : "";
|
||||||
return `${repository.namespace}/${repository.name}/${revPart}/${pathPart}`;
|
return `${repository.namespace}/${repository.name}/${decodeURIComponent(revPart)}/${pathPart}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reducer
|
// reducer
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import de.otto.edison.hal.Embedded;
|
||||||
|
import de.otto.edison.hal.Links;
|
||||||
|
import org.mapstruct.Context;
|
||||||
|
import org.mapstruct.MapperConfig;
|
||||||
|
import org.mapstruct.ObjectFactory;
|
||||||
|
import sonia.scm.repository.BrowserResult;
|
||||||
|
import sonia.scm.repository.FileObject;
|
||||||
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
|
import sonia.scm.repository.SubRepository;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static de.otto.edison.hal.Embedded.embeddedBuilder;
|
||||||
|
import static de.otto.edison.hal.Link.link;
|
||||||
|
|
||||||
|
@MapperConfig
|
||||||
|
abstract class BaseFileObjectDtoMapper extends HalAppenderMapper implements InstantAttributeMapper {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ResourceLinks resourceLinks;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setResourceLinks(ResourceLinks resourceLinks) {
|
||||||
|
this.resourceLinks = resourceLinks;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract SubRepositoryDto mapSubrepository(SubRepository subRepository);
|
||||||
|
|
||||||
|
@ObjectFactory
|
||||||
|
FileObjectDto createDto(@Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult, FileObject fileObject) {
|
||||||
|
String path = removeFirstSlash(fileObject.getPath());
|
||||||
|
Links.Builder links = Links.linkingTo();
|
||||||
|
if (fileObject.isDirectory()) {
|
||||||
|
links.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path));
|
||||||
|
} else {
|
||||||
|
links.self(resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path));
|
||||||
|
links.single(link("history", resourceLinks.fileHistory().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Embedded.Builder embeddedBuilder = embeddedBuilder();
|
||||||
|
applyEnrichers(links, embeddedBuilder, namespaceAndName, browserResult, fileObject);
|
||||||
|
|
||||||
|
return new FileObjectDto(links.build(), embeddedBuilder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract void applyEnrichers(Links.Builder links, Embedded.Builder embeddedBuilder, NamespaceAndName namespaceAndName, BrowserResult browserResult, FileObject fileObject);
|
||||||
|
|
||||||
|
private String removeFirstSlash(String source) {
|
||||||
|
return source.startsWith("/") ? source.substring(1) : source;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,22 +1,60 @@
|
|||||||
package sonia.scm.api.v2.resources;
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import de.otto.edison.hal.Embedded;
|
||||||
|
import de.otto.edison.hal.Links;
|
||||||
|
import org.mapstruct.Context;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.Qualifier;
|
||||||
import sonia.scm.repository.BrowserResult;
|
import sonia.scm.repository.BrowserResult;
|
||||||
|
import sonia.scm.repository.FileObject;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
public class BrowserResultToFileObjectDtoMapper {
|
@Mapper
|
||||||
|
public abstract class BrowserResultToFileObjectDtoMapper extends BaseFileObjectDtoMapper {
|
||||||
private final FileObjectToFileObjectDtoMapper fileObjectToFileObjectDtoMapper;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BrowserResultToFileObjectDtoMapper(FileObjectToFileObjectDtoMapper fileObjectToFileObjectDtoMapper) {
|
private FileObjectToFileObjectDtoMapper childrenMapper;
|
||||||
this.fileObjectToFileObjectDtoMapper = fileObjectToFileObjectDtoMapper;
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setChildrenMapper(FileObjectToFileObjectDtoMapper childrenMapper) {
|
||||||
|
this.childrenMapper = childrenMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileObjectDto map(BrowserResult browserResult, NamespaceAndName namespaceAndName) {
|
FileObjectDto map(BrowserResult browserResult, @Context NamespaceAndName namespaceAndName) {
|
||||||
FileObjectDto fileObjectDto = fileObjectToFileObjectDtoMapper.map(browserResult.getFile(), namespaceAndName, browserResult);
|
FileObjectDto fileObjectDto = fileObjectToDto(browserResult.getFile(), namespaceAndName, browserResult);
|
||||||
fileObjectDto.setRevision( browserResult.getRevision() );
|
fileObjectDto.setRevision(browserResult.getRevision());
|
||||||
return fileObjectDto;
|
return fileObjectDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||||
|
@Mapping(target = "children", qualifiedBy = Children.class)
|
||||||
|
protected abstract FileObjectDto fileObjectToDto(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult);
|
||||||
|
|
||||||
|
@Children
|
||||||
|
protected FileObjectDto childrenToDto(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult) {
|
||||||
|
return childrenMapper.map(fileObject, namespaceAndName, browserResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void applyEnrichers(Links.Builder links, Embedded.Builder embeddedBuilder, NamespaceAndName namespaceAndName, BrowserResult browserResult, FileObject fileObject) {
|
||||||
|
EdisonHalAppender appender = new EdisonHalAppender(links, embeddedBuilder);
|
||||||
|
// we call enrichers, which are only responsible for top level browseresults
|
||||||
|
applyEnrichers(appender, browserResult, namespaceAndName);
|
||||||
|
// we call enrichers, which are responsible for all file object top level browse result and its children
|
||||||
|
applyEnrichers(appender, fileObject, namespaceAndName, browserResult, browserResult.getRevision());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
@interface Children {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,46 +5,18 @@ import de.otto.edison.hal.Links;
|
|||||||
import org.mapstruct.Context;
|
import org.mapstruct.Context;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.ObjectFactory;
|
|
||||||
import sonia.scm.repository.BrowserResult;
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.FileObject;
|
import sonia.scm.repository.FileObject;
|
||||||
import sonia.scm.repository.NamespaceAndName;
|
import sonia.scm.repository.NamespaceAndName;
|
||||||
import sonia.scm.repository.SubRepository;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static de.otto.edison.hal.Embedded.embeddedBuilder;
|
|
||||||
import static de.otto.edison.hal.Link.link;
|
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public abstract class FileObjectToFileObjectDtoMapper extends HalAppenderMapper implements InstantAttributeMapper {
|
public abstract class FileObjectToFileObjectDtoMapper extends BaseFileObjectDtoMapper {
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ResourceLinks resourceLinks;
|
|
||||||
|
|
||||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||||
protected abstract FileObjectDto map(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult);
|
protected abstract FileObjectDto map(FileObject fileObject, @Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult);
|
||||||
|
|
||||||
abstract SubRepositoryDto mapSubrepository(SubRepository subRepository);
|
@Override
|
||||||
|
void applyEnrichers(Links.Builder links, Embedded.Builder embeddedBuilder, NamespaceAndName namespaceAndName, BrowserResult browserResult, FileObject fileObject) {
|
||||||
@ObjectFactory
|
|
||||||
FileObjectDto createDto(@Context NamespaceAndName namespaceAndName, @Context BrowserResult browserResult, FileObject fileObject) {
|
|
||||||
String path = removeFirstSlash(fileObject.getPath());
|
|
||||||
Links.Builder links = Links.linkingTo();
|
|
||||||
if (fileObject.isDirectory()) {
|
|
||||||
links.self(resourceLinks.source().sourceWithPath(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path));
|
|
||||||
} else {
|
|
||||||
links.self(resourceLinks.source().content(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path));
|
|
||||||
links.single(link("history", resourceLinks.fileHistory().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), browserResult.getRevision(), path)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Embedded.Builder embeddedBuilder = embeddedBuilder();
|
|
||||||
applyEnrichers(new EdisonHalAppender(links, embeddedBuilder), fileObject, namespaceAndName, browserResult, browserResult.getRevision());
|
applyEnrichers(new EdisonHalAppender(links, embeddedBuilder), fileObject, namespaceAndName, browserResult, browserResult.getRevision());
|
||||||
|
|
||||||
return new FileObjectDto(links.build(), embeddedBuilder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String removeFirstSlash(String source) {
|
|
||||||
return source.startsWith("/") ? source.substring(1) : source;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class MapperModule extends AbstractModule {
|
|||||||
bind(TagToTagDtoMapper.class).to(Mappers.getMapper(TagToTagDtoMapper.class).getClass());
|
bind(TagToTagDtoMapper.class).to(Mappers.getMapper(TagToTagDtoMapper.class).getClass());
|
||||||
|
|
||||||
bind(FileObjectToFileObjectDtoMapper.class).to(Mappers.getMapper(FileObjectToFileObjectDtoMapper.class).getClass());
|
bind(FileObjectToFileObjectDtoMapper.class).to(Mappers.getMapper(FileObjectToFileObjectDtoMapper.class).getClass());
|
||||||
|
bind(BrowserResultToFileObjectDtoMapper.class).to(Mappers.getMapper(BrowserResultToFileObjectDtoMapper.class).getClass());
|
||||||
bind(ModificationsToDtoMapper.class).to(Mappers.getMapper(ModificationsToDtoMapper.class).getClass());
|
bind(ModificationsToDtoMapper.class).to(Mappers.getMapper(ModificationsToDtoMapper.class).getClass());
|
||||||
|
|
||||||
bind(ReducedObjectModelToDtoMapper.class).to(Mappers.getMapper(ReducedObjectModelToDtoMapper.class).getClass());
|
bind(ReducedObjectModelToDtoMapper.class).to(Mappers.getMapper(ReducedObjectModelToDtoMapper.class).getClass());
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javax.ws.rs.PathParam;
|
|||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
|
||||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||||
import static sonia.scm.NotFoundException.notFound;
|
import static sonia.scm.NotFoundException.notFound;
|
||||||
@@ -57,7 +58,7 @@ public class SourceRootResource {
|
|||||||
BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand();
|
BrowseCommandBuilder browseCommand = repositoryService.getBrowseCommand();
|
||||||
browseCommand.setPath(path);
|
browseCommand.setPath(path);
|
||||||
if (revision != null && !revision.isEmpty()) {
|
if (revision != null && !revision.isEmpty()) {
|
||||||
browseCommand.setRevision(revision);
|
browseCommand.setRevision(URLDecoder.decode(revision, "UTF-8"));
|
||||||
}
|
}
|
||||||
browseCommand.setDisableCache(true);
|
browseCommand.setDisableCache(true);
|
||||||
BrowserResult browserResult = browseCommand.getBrowserResult();
|
BrowserResult browserResult = browseCommand.getBrowserResult();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.apache.shiro.util.ThreadState;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import sonia.scm.repository.BrowserResult;
|
import sonia.scm.repository.BrowserResult;
|
||||||
import sonia.scm.repository.FileObject;
|
import sonia.scm.repository.FileObject;
|
||||||
@@ -21,7 +22,6 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
public class BrowserResultToFileObjectDtoMapperTest {
|
public class BrowserResultToFileObjectDtoMapperTest {
|
||||||
|
|
||||||
private final URI baseUri = URI.create("http://example.com/base/");
|
private final URI baseUri = URI.create("http://example.com/base/");
|
||||||
@SuppressWarnings("unused") // Is injected
|
|
||||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(baseUri);
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
@@ -39,7 +39,10 @@ public class BrowserResultToFileObjectDtoMapperTest {
|
|||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
mapper = new BrowserResultToFileObjectDtoMapper(fileObjectToFileObjectDtoMapper);
|
mapper = Mappers.getMapper(BrowserResultToFileObjectDtoMapper.class);
|
||||||
|
mapper.setChildrenMapper(fileObjectToFileObjectDtoMapper);
|
||||||
|
mapper.setResourceLinks(resourceLinks);
|
||||||
|
|
||||||
subjectThreadState.bind();
|
subjectThreadState.bind();
|
||||||
ThreadContext.bind(subject);
|
ThreadContext.bind(subject);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.jboss.resteasy.mock.MockHttpResponse;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
@@ -49,7 +50,9 @@ public class SourceRootResourceTest extends RepositoryTestBase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareEnvironment() throws Exception {
|
public void prepareEnvironment() throws Exception {
|
||||||
browserResultToFileObjectDtoMapper = new BrowserResultToFileObjectDtoMapper(fileObjectToFileObjectDtoMapper);
|
browserResultToFileObjectDtoMapper = Mappers.getMapper(BrowserResultToFileObjectDtoMapper.class);
|
||||||
|
browserResultToFileObjectDtoMapper.setChildrenMapper(fileObjectToFileObjectDtoMapper);
|
||||||
|
browserResultToFileObjectDtoMapper.setResourceLinks(resourceLinks);
|
||||||
when(serviceFactory.create(new NamespaceAndName("space", "repo"))).thenReturn(service);
|
when(serviceFactory.create(new NamespaceAndName("space", "repo"))).thenReturn(service);
|
||||||
when(service.getBrowseCommand()).thenReturn(browseCommandBuilder);
|
when(service.getBrowseCommand()).thenReturn(browseCommandBuilder);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user