mirror of
				https://github.com/scm-manager/scm-manager.git
				synced 2025-10-31 10:35:56 +01:00 
			
		
		
		
	fixed returning null for getScmRepository from SimpleSvnWorkDirFactory
This commit is contained in:
		| @@ -24,19 +24,11 @@ public class SimpleSvnWorkDirFactory extends SimpleWorkdirFactory<File, File, Sv | ||||
|  | ||||
|   @Override | ||||
|   protected Repository getScmRepository(SvnContext context) { | ||||
|     return null; | ||||
|     return context.getRepository(); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected void closeRepository(File workingCopy) { | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected void closeWorkdirInternal(File workdir) { | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   protected ParentAndClone<File, File> cloneRepository(SvnContext context, File workingCopy, String initialBranch) throws IOException { | ||||
|   protected ParentAndClone<File, File> cloneRepository(SvnContext context, File workingCopy, String initialBranch) { | ||||
|  | ||||
|     final SvnOperationFactory svnOperationFactory = new SvnOperationFactory(); | ||||
|  | ||||
| @@ -60,4 +52,12 @@ public class SimpleSvnWorkDirFactory extends SimpleWorkdirFactory<File, File, Sv | ||||
|  | ||||
|     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.SVNRepositoryFactory; | ||||
|  | ||||
| import sonia.scm.repository.Repository; | ||||
| import sonia.scm.repository.SvnUtil; | ||||
|  | ||||
| //~--- JDK imports ------------------------------------------------------------ | ||||
|  | ||||
| import java.io.Closeable; | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @author Sebastian Sdorra | ||||
|  */ | ||||
| public class SvnContext implements Closeable | ||||
| { | ||||
| public class SvnContext implements Closeable { | ||||
|  | ||||
|   /** | ||||
|    * the logger for SvnContext | ||||
|    */ | ||||
|   private static final Logger logger = | ||||
|     LoggerFactory.getLogger(SvnContext.class); | ||||
|   private static final Logger LOG = LoggerFactory.getLogger(SvnContext.class); | ||||
|  | ||||
|   //~--- constructors --------------------------------------------------------- | ||||
|   private final Repository repository; | ||||
|   private final File directory; | ||||
|  | ||||
|   /** | ||||
|    * Constructs ... | ||||
|    * | ||||
|    * | ||||
|    * @param directory | ||||
|    */ | ||||
|   public SvnContext(File directory) | ||||
|   { | ||||
|   private SVNRepository svnRepository; | ||||
|  | ||||
|   public SvnContext(Repository repository, File directory) { | ||||
|     this.repository = repository; | ||||
|     this.directory = directory; | ||||
|   } | ||||
|  | ||||
|   //~--- methods -------------------------------------------------------------- | ||||
|  | ||||
|   /** | ||||
|    * 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()); | ||||
|     } | ||||
|  | ||||
|   public Repository getRepository() { | ||||
|     return repository; | ||||
|   } | ||||
|  | ||||
|   //~--- get methods ---------------------------------------------------------- | ||||
|  | ||||
|   /** | ||||
|    * Method description | ||||
|    * | ||||
|    * | ||||
|    * @return | ||||
|    */ | ||||
|   public File getDirectory() | ||||
|   { | ||||
|   public File getDirectory() { | ||||
|     return directory; | ||||
|   } | ||||
|  | ||||
|   //~--- fields --------------------------------------------------------------- | ||||
|   public SVNURL createUrl() throws SVNException { | ||||
|     return SVNURL.fromFile(directory); | ||||
|   } | ||||
|  | ||||
|   /** Field description */ | ||||
|   private File directory; | ||||
|   public SVNRepository open() throws SVNException { | ||||
|     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; | ||||
| } | ||||
|   | ||||
| @@ -66,7 +66,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider | ||||
|     Repository repository, SvnWorkDirFactory workdirFactory) | ||||
|   { | ||||
|     this.repository = repository; | ||||
|     this.context = new SvnContext(handler.getDirectory(repository.getId())); | ||||
|     this.context = new SvnContext(repository, handler.getDirectory(repository.getId())); | ||||
|     this.workDirFactory = workdirFactory; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -72,7 +72,7 @@ public class AbstractSvnCommandTestBase extends ZippedRepositoryTestBase | ||||
|   { | ||||
|     if (context == null) | ||||
|     { | ||||
|       context = new SvnContext(repositoryDirectory); | ||||
|       context = new SvnContext(repository, repositoryDirectory); | ||||
|     } | ||||
|  | ||||
|     return context; | ||||
|   | ||||
| @@ -5,6 +5,7 @@ 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; | ||||
|  | ||||
| @@ -66,4 +67,11 @@ public class SimpleSvnWorkDirFactoryTest extends AbstractSvnCommandTestBase { | ||||
|     assertThat(directory).doesNotExist(); | ||||
|     assertThat(workingRepository).doesNotExist(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void shouldReturnRepository() { | ||||
|     SimpleSvnWorkDirFactory factory = new SimpleSvnWorkDirFactory(workdirProvider); | ||||
|     Repository scmRepository = factory.getScmRepository(createContext()); | ||||
|     assertThat(scmRepository).isSameAs(repository); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -116,6 +116,6 @@ public class SvnUnbundleCommandTest extends AbstractSvnCommandTestBase | ||||
|  | ||||
|     SVNRepositoryFactory.createLocalRepository(folder, true, true); | ||||
|  | ||||
|     return new SvnContext(folder); | ||||
|     return new SvnContext(repository, folder); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user