org.tmatesoft.svn.core.SVNException Java Examples
The following examples show how to use
org.tmatesoft.svn.core.SVNException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SvnClient.java From steady with Apache License 2.0 | 6 votes |
/** * Performs a search in the repository root. * */ public Map<String, String> searchCommitLog(String _str, Date _asOf) { final Map<String,String> hits = new HashMap<String,String>(); try { // Update revision log this.updateCommitLog(_asOf); for (SVNLogEntry logEntry : this.logEntries) { if (logEntry.getMessage()!=null && logEntry.getMessage().contains(_str)) { SvnClient.log.info("Revision '" + logEntry.getRevision() + "' : " + logEntry.getMessage().trim()); hits.put(String.valueOf(logEntry.getRevision()), logEntry.getMessage().trim()); } } } catch (SVNException e) { SvnClient.log.error("Error while searching commit log: " + e.getMessage()); } return hits; }
Example #2
Source File: SvnWorkingCopyManager.java From scava with Eclipse Public License 2.0 | 6 votes |
public void checkoutBroken(File workingDirectory, VcsRepository repository, String revision) throws WorkingCopyCheckoutException { try { SvnUtil.setupLibrary(); final SvnOperationFactory svnOperationFactory = new SvnOperationFactory(); try { final SvnCheckout checkout = svnOperationFactory.createCheckout(); checkout.setSingleTarget(SvnTarget.fromFile(workingDirectory)); checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(repository.getUrl()), SVNRevision.create(Long.parseLong(revision)))); checkout.run(); } finally { svnOperationFactory.dispose(); } } catch (NumberFormatException | SVNException e) { throw new WorkingCopyCheckoutException(repository, revision, e); } }
Example #3
Source File: GitBranch.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
public void updateRevisions() throws IOException, SVNException { boolean gotNewRevisions = false; while (true) { loadRevisions(); if (!cacheRevisions()) { break; } gotNewRevisions = true; } if (gotNewRevisions) { final boolean locksChanged = repository.wrapLockWrite(lockStorage -> lockStorage.cleanupInvalidLocks(this)); if (locksChanged) repository.getContext().getShared().getCacheDB().commit(); } }
Example #4
Source File: ReplayRangeCmd.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
@Override protected void processCommand(@NotNull SessionContext context, @NotNull Params args) throws IOException, SVNException { if (args.startRev > args.endRev) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.UNKNOWN, "Invalid revision range: start: " + args.startRev + ", end " + args.endRev)); } final SvnServerWriter writer = context.getWriter(); for (int revision = args.startRev; revision <= args.endRev; revision++) { final GitRevision revisionInfo = context.getBranch().getRevisionInfo(revision); writer .listBegin() .word("revprops") .writeMap(revisionInfo.getProperties(true)) .listEnd(); ReplayCmd.replayRevision(context, revision, args.lowRevision, args.sendDeltas); } writer .listBegin() .word("success") .listBegin().listEnd() .listEnd(); }
Example #5
Source File: ReplayCmd.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
static void replayRevision(@NotNull SessionContext context, int revision, int lowRevision, boolean sendDeltas) throws IOException, SVNException { final DeltaCmd.ReportPipeline pipeline = new DeltaCmd.ReportPipeline( new DeltaParams( new int[]{revision}, "", "", sendDeltas, Depth.Infinity, SendCopyFrom.OnlyRelative, false, false, lowRevision ) ); pipeline.setPathReport("", revision - 1, false, SVNDepth.INFINITY); pipeline.sendDelta(context); final SvnServerWriter writer = context.getWriter(); writer .listBegin() .word("finish-replay") .listBegin().listEnd() .listEnd(); }
Example #6
Source File: MCRVersionedMetadata.java From mycore with GNU General Public License v3.0 | 6 votes |
private long getLastRevision(boolean deleted) throws SVNException { SVNRepository repository = getStore().getRepository(); if (repository.getLatestRevision() == 0) { //new repository cannot hold a revision yet (MCR-1196) return -1; } final String path = getFilePath(); String dir = getDirectory(); LastRevisionLogHandler lastRevisionLogHandler = new LastRevisionLogHandler(path, deleted); int limit = 0; //we stop through LastRevisionFoundException try { repository.log(new String[] { dir }, repository.getLatestRevision(), 0, true, true, limit, false, null, lastRevisionLogHandler); } catch (LastRevisionFoundException ignored) { } return lastRevisionLogHandler.getLastRevision(); }
Example #7
Source File: GitWriter.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
public void saveFile(@NotNull String name, @NotNull GitDeltaConsumer deltaConsumer, boolean modify) throws SVNException, IOException { final GitDeltaConsumer gitDeltaConsumer = deltaConsumer; final GitTreeUpdate current = treeStack.element(); final GitTreeEntry entry = current.getEntries().get(name); final GitObject<ObjectId> originalId = gitDeltaConsumer.getOriginalId(); if (modify ^ (entry != null)) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.WC_NOT_UP_TO_DATE, "Working copy is not up-to-date: " + getFullPath(name))); } final GitObject<ObjectId> objectId = gitDeltaConsumer.getObjectId(); if (objectId == null) { // Content not updated. if (originalId == null) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.INCOMPLETE_DATA, "Added file without content: " + getFullPath(name))); } return; } current.getEntries().put(name, new GitTreeEntry(getFileMode(gitDeltaConsumer.getProperties()), objectId, name)); commitActions.add(action -> action.checkProperties(name, gitDeltaConsumer.getProperties(), gitDeltaConsumer)); }
Example #8
Source File: SvnFilePropertyTest.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
/** * Check commit .gitattributes. */ @Test public void commitDirWithoutProperties() throws Exception { try (SvnTestServer server = SvnTestServer.createEmpty()) { final SVNRepository repo = server.openSvnRepository(); try { final long latestRevision = repo.getLatestRevision(); final ISVNEditor editor = repo.getCommitEditor("Create directory: /foo", null, false, null); editor.openRoot(-1); editor.addDir("/foo", null, latestRevision); // Empty file. final String filePath = "/foo/.gitattributes"; editor.addFile(filePath, null, -1); sendDeltaAndClose(editor, filePath, null, "*.txt\t\t\ttext\n"); // Close dir editor.closeDir(); editor.closeDir(); editor.closeEdit(); Assert.fail(); } catch (SVNException e) { Assert.assertTrue(e.getMessage().contains(SVNProperty.INHERITABLE_AUTO_PROPS)); } } }
Example #9
Source File: SVNKitEnvironmentRepositoryIntegrationTests.java From spring-cloud-config with Apache License 2.0 | 6 votes |
private void updateRepoForUpdate(String uri) throws SVNException, FileNotFoundException, IOException { SvnOperationFactory svnFactory = new SvnOperationFactory(); final SvnCheckout checkout = svnFactory.createCheckout(); checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(uri))); checkout.setSingleTarget(SvnTarget.fromFile(this.workingDir)); checkout.run(); // update bar.properties File barProps = new File(this.workingDir, "trunk/bar.properties"); StreamUtils.copy("foo: foo", Charset.defaultCharset(), new FileOutputStream(barProps)); // commit to repo SvnCommit svnCommit = svnFactory.createCommit(); svnCommit.setCommitMessage("update bar.properties"); svnCommit.setSingleTarget(SvnTarget.fromFile(barProps)); svnCommit.run(); }
Example #10
Source File: SvnKitDiff.java From StatSVN with GNU Lesser General Public License v3.0 | 6 votes |
/** * Gets a single diff for a file between two revisions. */ public int[] getLineDiff(String oldRevNr, String newRevNr, String filename) throws IOException, BinaryDiffException { int oldRevisionNo = Integer.parseInt(oldRevNr); int newRevisionNo = Integer.parseInt(newRevNr); File newFile = new File(getProcessor().getInfoProcessor().relativeToAbsolutePath(filename)); File oldFile = newFile; ByteArrayOutputStream diffBytes = new ByteArrayOutputStream(); try { getManager().getDiffClient().doDiff(oldFile, SVNRevision.create(oldRevisionNo), newFile, SVNRevision.create(newRevisionNo), SVNDepth.INFINITY, false, diffBytes, null); } catch (SVNException ex) { handleSvnException(ex); } String modDiffDataStr = replaceRelativePathWithinDiffData(getCheckoutDirectory(), diffBytes.toString()); return parseSingleDiffStream(new ByteArrayInputStream(modDiffDataStr.getBytes())); }
Example #11
Source File: SvnKitDiff.java From StatSVN with GNU Lesser General Public License v3.0 | 6 votes |
/** * Gets diffs inside one revision. * * @return a list of diffs that were extracted from one particular revision */ public Vector getLineDiff(String newRevNr) throws IOException, BinaryDiffException { ByteArrayOutputStream diffBytes = new ByteArrayOutputStream(); int revisionNo = Integer.parseInt(newRevNr); try { getManager().getDiffClient().doDiff(getCheckoutDirectory(), SVNRevision.create(revisionNo), SVNRevision.create(revisionNo - 1), SVNRevision.create(revisionNo), SVNDepth.INFINITY, false, diffBytes, null); } catch (SVNException ex) { handleSvnException(ex); } String modDiffDataStr = replaceRelativePathWithinDiffData(getCheckoutDirectory(), diffBytes.toString()); final Vector answer = new Vector(); parseMultipleDiffStream(answer, new ByteArrayInputStream(modDiffDataStr.getBytes())); return answer; }
Example #12
Source File: LazySvnVersionedFile.java From Getaviz with Apache License 2.0 | 5 votes |
@Override public byte[] getContent() throws FilesNotAvailableException { try { ByteArrayOutputStream output = new ByteArrayOutputStream(ONE_MB); repo.getFile(currentFilePath, revision, null, output); return output.toByteArray(); } catch (SVNException e) { throw new FilesNotAvailableException(e); } }
Example #13
Source File: WebServer.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
/** * Return current user information. * * @param authorization HTTP authorization header value. * @return Return value: * <ul> * <li>no authorization header - anonymous user;</li> * <li>invalid authorization header - null;</li> * <li>valid authorization header - user information.</li> * </ul> */ @Nullable public User getAuthInfo(@Nullable final String authorization, int tokenEnsureTime) { final UserDB userDB = context.sure(UserDB.class); // Check HTTP authorization. if (authorization == null) { return User.getAnonymous(); } if (authorization.startsWith(AUTH_BASIC)) { final String raw = new String(Base64.decode(authorization.substring(AUTH_BASIC.length()).trim()), StandardCharsets.UTF_8); final int separator = raw.indexOf(':'); if (separator > 0) { final String username = raw.substring(0, separator); final String password = raw.substring(separator + 1); try { return userDB.check(username, password); } catch (SVNException e) { log.error("Authorization error: " + e.getMessage(), e); } } return null; } if (authorization.startsWith(AUTH_TOKEN)) { return TokenHelper.parseToken(createEncryption(), authorization.substring(AUTH_TOKEN.length()).trim(), tokenEnsureTime); } return null; }
Example #14
Source File: GitWriter.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
public void openDir(@NotNull String name) throws SVNException, IOException { final GitTreeUpdate current = treeStack.element(); final GitTreeEntry originalDir = current.getEntries().remove(name); if ((originalDir == null) || (!originalDir.getFileMode().equals(FileMode.TREE))) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, getFullPath(name))); } commitActions.add(action -> action.openDir(name)); treeStack.push(new GitTreeUpdate(name, branch.getRepository().loadTree(originalDir))); }
Example #15
Source File: GitWriter.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
public void addDir(@NotNull String name, @Nullable GitFile sourceDir) throws SVNException, IOException { final GitTreeUpdate current = treeStack.element(); if (current.getEntries().containsKey(name)) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_ALREADY_EXISTS, getFullPath(name))); } commitActions.add(action -> action.openDir(name)); treeStack.push(new GitTreeUpdate(name, branch.getRepository().loadTree(sourceDir == null ? null : sourceDir.getTreeEntry()))); }
Example #16
Source File: SubversionRepositoryInitializer.java From Getaviz with Apache License 2.0 | 5 votes |
public SVNRepository initRepository(boolean cached) throws SVNException, MalformedURLException { SVNRepository repo = null; SVNURL svnUrl = SVNURL.parseURIEncoded(url); if (url.startsWith(HTTP_SCHEME + SCHEME_SEPARATOR) || url.startsWith(HTTPS_SCHEME + SCHEME_SEPARATOR)) { DAVRepositoryFactory.setup(); repo = DAVRepositoryFactory.create(svnUrl); repo.testConnection(); if(cached) { TmpDirCreator tmpDirCreator = new TmpDirCreator(url); File tempDir = tmpDirCreator.getLocalTempDir(); SVNURL cachedRepoPath = SVNURL.parseURIEncoded(FILE_SCHEME + SCHEME_SEPARATOR + tempDir); if(!tempDir.exists()){ messageOutputStream.println("Caching subversion repository " + svnUrl + " This can take a while..."); tempDir.mkdirs(); cachedRepoPath = SVNRepositoryFactory.createLocalRepository(tempDir, true, true); tmpDirCreator.writeIdFileToTempDir(); SVNRepository targetRepo = SVNRepositoryFactory.create(cachedRepoPath); SVNRepositoryReplicator replicator = SVNRepositoryReplicator.newInstance(); replicator.setReplicationHandler(new ProgressBarReplicationHandler(repo.getLatestRevision())); replicator.replicateRepository(repo, targetRepo, -1, -1); messageOutputStream.println("\nCaching finished succesfully..."); } svnUrl = cachedRepoPath; FSRepositoryFactory.setup(); repo = FSRepositoryFactory.create(svnUrl); } } else if (url.startsWith(SVN_SCHEME + SCHEME_SEPARATOR)) { SVNRepositoryFactoryImpl.setup(); repo = SVNRepositoryFactoryImpl.create(svnUrl); } else if (url.startsWith(FILE_SCHEME + SCHEME_SEPARATOR)) { FSRepositoryFactory.setup(); repo = FSRepositoryFactory.create(svnUrl); } else throw new MalformedURLException(String.format("URL %s is not an supported SVN url!", url)); repo.testConnection(); return repo; }
Example #17
Source File: SvnUtil.java From scava with Eclipse Public License 2.0 | 5 votes |
public static List<SVNDirEntry> getEntries(SVNRepository repository, String path) throws SVNException { Collection<?> entries = repository.getDir(path, -1, null, (Collection<?>) null); List<SVNDirEntry> entryURLs= new ArrayList<SVNDirEntry>(); Iterator<?> iterator = entries.iterator(); while (iterator.hasNext()) { SVNDirEntry entry = (SVNDirEntry) iterator.next(); entryURLs.add(entry); if (entry.getKind() == SVNNodeKind.DIR) { entryURLs.addAll(getEntries(repository, (path.equals("")) ? entry.getName(): path + "/" + entry.getName()) ); } } return entryURLs; }
Example #18
Source File: CommitCmd.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull GitFile getEntry(@NotNull String name) throws IOException, SVNException { if (source == null) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "Can't find node: " + name)); } final GitFile file = source.getEntry(name); if (file == null) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND, "Can't find node: " + name + " in " + source.getFullPath())); } return file; }
Example #19
Source File: GitLabMappingConfig.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull @Override public RepositoryMapping create(@NotNull SharedContext context, boolean canUseParallelIndexing) throws IOException { final GitLabContext gitlab = context.sure(GitLabContext.class); final GitlabAPI api = gitlab.connect(); // Get repositories. final GitLabMapping mapping = new GitLabMapping(context, this, gitlab); for (GitlabProject project : api.getProjects()) mapping.updateRepository(project); final Consumer<GitLabProject> init = repository -> { try { repository.initRevisions(); } catch (IOException | SVNException e) { throw new RuntimeException(String.format("[%s]: failed to initialize", repository), e); } }; if (canUseParallelIndexing) { mapping.getMapping().values().parallelStream().forEach(init); } else { mapping.getMapping().values().forEach(init); } return mapping; }
Example #20
Source File: GitBranch.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull public GitWriter createWriter(@NotNull User user) throws SVNException { if (user.getEmail() == null || user.getEmail().isEmpty()) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "Users with undefined email can't create commits")); } return new GitWriter(this, repository.getPusher(), pushLock, user); }
Example #21
Source File: GitBranch.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull public GitRevision getRevision(@NotNull ObjectId revisionId) throws SVNException { lock.readLock().lock(); try { final GitRevision revision = revisionByHash.get(revisionId); if (revision == null) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_NO_SUCH_REVISION, "No such revision " + revisionId.name())); } return revision; } finally { lock.readLock().unlock(); } }
Example #22
Source File: SvnTesterExternal.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
public SvnTesterExternal(@NotNull SVNURL url, @Nullable ISVNAuthenticationManager authManager) throws SVNException { this.url = url; this.authManager = authManager; this.suffix = UUID.randomUUID().toString(); final SVNRepository repo = openSvnRepository(url); try { final ISVNEditor editor = repo.getCommitEditor("Create subdir for test", null, false, null); editor.openRoot(-1); editor.addDir(suffix, null, -1); editor.closeDir(); editor.closeEdit(); } finally { repo.closeSession(); } }
Example #23
Source File: MCRVersionedMetadata.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Lists all versions of this metadata object available in the subversion * repository * * @return all stored versions of this metadata object */ @SuppressWarnings("unchecked") public List<MCRMetadataVersion> listVersions() throws IOException { try { List<MCRMetadataVersion> versions = new ArrayList<>(); SVNRepository repository = getStore().getRepository(); String path = getFilePath(); String dir = getDirectory(); Collection<SVNLogEntry> entries = null; try { entries = repository.log(new String[] { dir }, null, 0, repository.getLatestRevision(), true, true); } catch (Exception ioex) { LOGGER.error("Could not get versions", ioex); return versions; } for (SVNLogEntry entry : entries) { SVNLogEntryPath svnLogEntryPath = entry.getChangedPaths().get(path); if (svnLogEntryPath != null) { char type = svnLogEntryPath.getType(); versions.add(new MCRMetadataVersion(this, entry, type)); } } return versions; } catch (SVNException svnExc) { throw new IOException(svnExc); } }
Example #24
Source File: MCRVersionedMetadata.java From mycore with GNU General Public License v3.0 | 5 votes |
public MCRMetadataVersion getRevision(long revision) throws IOException { try { if (revision < 0) { revision = getLastPresentRevision(); if (revision < 0) { LOGGER.warn("Metadata object {} in store {} has no last revision!", getID(), getStore().getID()); return null; } } SVNRepository repository = getStore().getRepository(); String path = getFilePath(); String dir = getDirectory(); @SuppressWarnings("unchecked") Collection<SVNLogEntry> log = repository.log(new String[] { dir }, null, revision, revision, true, true); for (SVNLogEntry logEntry : log) { SVNLogEntryPath svnLogEntryPath = logEntry.getChangedPaths().get(path); if (svnLogEntryPath != null) { char type = svnLogEntryPath.getType(); return new MCRMetadataVersion(this, logEntry, type); } } LOGGER.warn("Metadata object {} in store {} has no revision ''{}''!", getID(), getStore().getID(), getRevision()); return null; } catch (SVNException svnExc) { throw new IOException(svnExc); } }
Example #25
Source File: CommitCmd.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull private FileUpdater getFile(@NotNull String token) throws SVNException { final FileUpdater file = files.get(token); if (file == null) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.ILLEGAL_TARGET, "Invalid file token: " + token)); } return file; }
Example #26
Source File: GetFileRevsTest.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
private void assertFileRevisions(@NotNull SVNRepository repository, long startRev, long endRev, long... expected) throws SVNException { final List<SVNFileRevision> fileRevisions = new ArrayList<>(); repository.getFileRevisions(fileName, fileRevisions, startRev, endRev); Assert.assertEquals(fileRevisions.size(), expected.length); for (int i = 0; i < expected.length; ++i) { Assert.assertEquals(fileRevisions.get(i).getRevision(), expected[i]); } }
Example #27
Source File: WCDepthTest.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@Test public void files() throws SVNException { checkout("a/b", SVNDepth.FILES); Assert.assertFalse(Files.exists(wc.resolve("c"))); Assert.assertTrue(Files.exists(wc.resolve("e"))); update("", null); Assert.assertFalse(Files.exists(wc.resolve("c"))); Assert.assertTrue(Files.exists(wc.resolve("e"))); update("", SVNDepth.INFINITY); Assert.assertTrue(Files.exists(wc.resolve("c/d"))); }
Example #28
Source File: CheckPathAndStatCmdTest.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
private static void assertPath(@NotNull SVNRepository repository, @NotNull String path, long rev, @NotNull SVNNodeKind expectedKind) throws SVNException { final SVNNodeKind nodeKind = repository.checkPath(path, rev); Assert.assertEquals(nodeKind, expectedKind); final SVNDirEntry info = repository.info(path, rev); if (expectedKind == SVNNodeKind.NONE) { Assert.assertNull(info); } else { Assert.assertEquals(info.getKind(), expectedKind); Assert.assertEquals(info.getRevision(), rev); } }
Example #29
Source File: ReparentCmd.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@Override protected void processCommand(@NotNull SessionContext context, @NotNull Params args) throws IOException, SVNException { context.setParent(args.url); final SvnServerWriter writer = context.getWriter(); writer .listBegin() .word("success") .listBegin() .listEnd() .listEnd(); }
Example #30
Source File: WCDepthTest.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@Test public void infinity() throws SVNException { checkout("", SVNDepth.INFINITY); Assert.assertTrue(Files.exists(wc.resolve("a/b/c/d"))); Assert.assertTrue(Files.exists(wc.resolve("a/b/e"))); update("", null); Assert.assertTrue(Files.exists(wc.resolve("a/b/c/d"))); Assert.assertTrue(Files.exists(wc.resolve("a/b/e"))); }