Refine search
private String update(SvnOperationFactory svnOperationFactory, String label) throws SVNException { logger.debug("Repo already checked out - updating instead."); try { final SvnUpdate update = svnOperationFactory.createUpdate(); update.setSingleTarget(SvnTarget.fromFile(getWorkingDirectory())); long[] ids = update.run(); StringBuilder version = new StringBuilder(); for (long id : ids) { if (version.length() > 0) { version.append(","); } version.append(id); } return version.toString(); } catch (Exception e) { String message = "Could not update remote for " + label + " (current local=" + getWorkingDirectory().getPath() + "), remote: " + this.getUri() + ")"; if (logger.isDebugEnabled()) { logger.debug(message, e); } else if (logger.isWarnEnabled()) { logger.warn(message); } } final SVNStatus status = SVNClientManager.newInstance().getStatusClient() .doStatus(getWorkingDirectory(), false); return status != null ? status.getRevision().toString() : null; }
public void dispose() { if (myClientManager != null) { myClientManager.dispose(); myClientManager = null; } }
@Override public void reset() { SVNRepository repository = null; try { SVNRevision revision = SVNRevision.HEAD; SVNURL url = SVNURL.parseURIEncoded(path); repository = SVNRepositoryFactory.create(url); authenticateIfNecessary(repository); SVNClientManager ourClientManager = SVNClientManager.newInstance(null, repository.getAuthenticationManager()); SVNUpdateClient updateClient = ourClientManager.getUpdateClient(); updateClient.setIgnoreExternals(false); updateClient.doCheckout(url, new File(workingCopyPath), revision, revision, SVNDepth.INFINITY, true); } catch (Exception e) { throw new RuntimeException(e); } finally { if (repository != null) repository.closeSession(); } }
try { final SVNClientManager cm = upc!=null ? SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),upc.new AuthenticationManagerImpl(listener)) : SubversionSCM.createSvnClientManager(getBuild().getProject()); try { SVNURL src = SVNURL.parseURIDecoded(e.getKey().url); SVNURL dst = SVNURL.parseURIDecoded(e.getValue()); SVNCopyClient svncc = cm.getCopyClient(); SVNRevision sourceRevision = SVNRevision.create(e.getKey().revision); SVNCopySource csrc = new SVNCopySource(sourceRevision, sourceRevision, src); svncc.doCopy( dst, false, true, false, comment, null); } catch (SVNException x) { x.printStackTrace(listener.error("Failed to tag")); return; workerThread = null; } finally { cm.dispose();
public static void main(String[] args) { ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("admin", "john"); SVNClientManager manager = SVNClientManager.newInstance(); manager.setAuthenticationManager(authManager); SVNCommitClient commitClient = SVNClientManager.newInstance().getCommitClient(); try { SVNCommitInfo info = commitClient.doMkDir(new SVNURL[] { SVNURL.parseURIEncoded("http://192.168.3.127/repository/koux/trunk") }, "commitMessage", null, true); long newRevision = info.getNewRevision(); System.out.println(newRevision); } catch (SVNException e) { e.printStackTrace(); } }
/** * Updates an existing local working copy from the repository. * * @return the revision of the fetched content * * @throws IOException thrown if there is a problem updating the working copy */ private SVNRevision updateResourceDirectory() throws IOException { try { final long newRevision = clientManager.getUpdateClient().doUpdate(workingCopyDirectory, retrievalRevision, SVNDepth.INFINITY, true, true); log.debug("Updated local working directory {} to revision {} from remote repository {}", new Object[] { workingCopyDirectory.getAbsolutePath(), newRevision, remoteRepository.toDecodedString(),}); return SVNRevision.create(newRevision); } catch (final SVNException e) { final String errMsg = "Unable to update working copy of resoure " + remoteRepository.toDecodedString() + " in working copy " + workingCopyDirectory.getAbsolutePath() + " to revsion " + retrievalRevision.toString(); log.error(errMsg, e); throw new IOException(errMsg, e); } }
@Override @Deprecated public String blame(String file, String currentCommit, Integer line) { try { SVNURL url = SVNURL.parseURIEncoded(path + File.separator + file); ISVNAuthenticationManager authManager = getAuthenticationManager(); SVNLogClient logClient = SVNClientManager.newInstance(null, authManager).getLogClient(); boolean ignoreMimeType = false; boolean includeMergedRevisions = false; logClient.doAnnotate(url, SVNRevision.UNDEFINED, SVNRevision.create(Integer.parseInt(currentCommit)), SVNRevision.HEAD, ignoreMimeType, includeMergedRevisions, null, null); return String.valueOf(SVNRevision.create(Integer.parseInt(currentCommit)).getNumber()); } catch (SVNException e) { throw new RuntimeException(e); } }
public static String urlFromWorkspace(FileNode workspace) throws IOException { SVNClientManager clientManager; clientManager = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true)); try { return clientManager.getWCClient().doInfo(workspace.toPath().toFile(), SVNRevision.UNDEFINED).getURL().toString(); } catch (SVNException e) { throw new IOException("cannot determine workspace url: " + e.getMessage(), e); } finally { clientManager.dispose(); } } }
@Override public void switchToVersion(String version) throws Exception { Log.logInfoRB("SVN_START", "checkout to " + version); filesForCommit.clear(); SVNURL url = SVNURL.parseURIEncoded(SVNEncodingUtil.autoURIEncode(config.getUrl())); SVNRevision toRev; if (version != null) { toRev = SVNRevision.create(Long.parseLong(version)); } else { toRev = SVNRevision.HEAD; } try { ourClientManager.getUpdateClient().doCheckout(url, baseDirectory, SVNRevision.HEAD, toRev, SVNDepth.INFINITY, false); Log.logInfoRB("SVN_FINISH", "checkout"); } catch (Exception ex) { Log.logErrorRB("SVN_ERROR", "checkout", ex.getMessage()); checkNetworkException(ex); throw ex; } }
/** * Fetches the content from the SVN repository and creates the local working copy. * * @return the revision of the fetched content * * @throws ResourceException thrown if there is a problem checking out the content from the repository */ private SVNRevision checkoutResourceDirectory() throws ResourceException { try { long newRevision = clientManager.getUpdateClient().doCheckout(remoteRepository, workingCopyDirectory, retrievalRevision, retrievalRevision, SVNDepth.INFINITY, true); log.debug( "Checked out revision {} from remote repository {} and stored it in local working directory {}", new Object[] { newRevision, remoteRepository.toDecodedString(), workingCopyDirectory.getAbsolutePath(), }); return SVNRevision.create(newRevision); } catch (SVNException e) { String errMsg = "Unable to check out revsion " + retrievalRevision.toString() + " from remote repository " + remoteRepository.toDecodedString() + " to local working directory " + workingCopyDirectory.getAbsolutePath(); log.error(errMsg, e); throw new ResourceException(errMsg, e); } }
@Override public C execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception { final Long revision = parseRevisionOrDie(version); // use raw repo to check if the path exists final SVNNodeKind nodeType = repo.checkPath(path, revision); if (SVNNodeKind.NONE.equals(nodeType)) { LOGGER.warn(repo.getLocation() + "/" + path + " @r" + revision + " is SVNNodeKind.NONE returning " + defaultValue); return defaultValue; } final SVNWCClient client = clientManager.getWCClient(); final SVNURL url = svnUrl.appendPath(path, true); final SVNRevision svnRevision = SVNRevision.create(revision); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); client.doGetFileContents(url, svnRevision, svnRevision, /* expandKeywords */ false, baos); final C testDefinition = objectMapper.readValue(baos.toByteArray(), c); try { baos.close(); } catch (IOException e) { /* ignore */ } return testDefinition; }
public String invoke(File p, VirtualChannel channel) throws IOException { final SVNClientManager manager = SubversionSCM.createSvnClientManager(authProvider); try { final SVNWCClient svnwc = manager.getWCClient(); SVNInfo info; try { info = svnwc.doInfo(p, SVNRevision.WORKING); return info.getURL().toDecodedString(); } catch (SVNException e) { e.printStackTrace(); return null; } } finally { manager.dispose(); } }
public boolean remoteUrlExist( ScmProviderRepository repository, CommandParameters parameters ) throws ScmException { SvnJavaScmProviderRepository javaRepo = (SvnJavaScmProviderRepository) repository; String url = ( (SvnScmProviderRepository) repository ).getUrl(); try { javaRepo.getClientManager().getWCClient().doInfo( SVNURL.parseURIEncoded( url ), SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.EMPTY, new ISVNInfoHandler() { public void handleInfo( SVNInfo svnInfo ) throws SVNException { svnInfo.getAuthor(); } } ); } catch ( SVNException e ) { if ( e.getMessage().indexOf( "E170000" ) > -1 ) { return false; } throw new ScmException( e.getMessage(), e ); } return true; }
SVNURL svnurl = SVNURL.parseURIDecoded(url); SVNRepository repository = SVNRepositoryFactory.create(svnurl); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(uname, password); repository.setAuthenticationManager(authManager); SVNClientManager ourClientManager = SVNClientManager.newInstance(); ourClientManager.setAuthenticationManager(authManager); SVNUpdateClient updateClient = ourClientManager.getUpdateClient(); updateClient.setIgnoreExternals(true); long latestRevision = repository.getLatestRevision(); if (updateClient.doCheckout(svnurl, destinationDir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, allowUnversionedObstructions) == latestRevision) { ourClientManager.dispose(); }
/** * Gets the repository revision just committed. */ public long revision() throws Exception { // .getLookClient().doGetYoungestRevision(repo) would show last committed revision but would not be sensitive to checked-out branch; which is clearer? return SVNClientManager.newInstance().getStatusClient().doStatus(wc, true).getRemoteRevision().getNumber(); // http://stackoverflow.com/a/2295674/12916 }
private String getDiffText(SVNRepository repository, SVNURL url, SVNLogEntryPath entry, long revision) { try { SVNClientManager clientManager = SVNClientManager.newInstance(null, repository.getAuthenticationManager()); SVNDiffClient diffClient = clientManager.getDiffClient(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SVNRevision startRevision = SVNRevision.create(revision - 1); SVNRevision endRevision = SVNRevision.create(revision); diffClient.doDiff(url, startRevision, startRevision, endRevision, SVNDepth.FILES, true, out); String diffText = out.toString("UTF-8"); if (diffText.length() > MAX_SIZE_OF_A_DIFF) { log.error("diffs for " + entry.getPath() + " too big"); diffText = "-- TOO BIG --"; } return diffText; } catch (Exception e) { return ""; } }
public Void invoke(File ws, VirtualChannel channel) throws IOException, InterruptedException { File workingCopy = new File(ws, location.getLocalDir()).getCanonicalFile(); try { SVNURL svnUrl = SVNURL.parseURIEncoded(tagUrl); SVNCopyClient copyClient; try { copyClient = SubversionSCM.createClientManager(authProvider).getCopyClient(); } catch (NoSuchMethodError e) { //todo remove when backward compatibility not needed //fallback for older versions of org.jenkins-ci.plugins:subversion buildListener.getLogger().println( "[RELEASE] You are using an old subversion jenkins plugin, please consider upgrading."); copyClient = SubversionSCM.createSvnClientManager(authProvider).getCopyClient(); } buildListener.getLogger().println("[RELEASE] Creating subversion tag: " + tagUrl); SVNCopySource source = new SVNCopySource(SVNRevision.WORKING, SVNRevision.WORKING, workingCopy); SVNCommitInfo commitInfo = copyClient.doCopy(new SVNCopySource[]{source}, svnUrl, false, true, true, commitMessage, new SVNProperties()); SVNErrorMessage errorMessage = commitInfo.getErrorMessage(); if (errorMessage != null) { throw new IOException("Failed to create tag: " + errorMessage.getFullMessage()); } return null; } catch (SVNException e) { debuggingLogger.log(Level.FINE, "Failed to create tag", e); throw new IOException("Subversion tag creation failed: " + e.getMessage()); } } }
public void checkout(FileNode dest, long revision) throws IOException, SVNException { checkDirectory(); dest.checkDirectory(); SVNUpdateClient client = getRoot().getClientMananger().getUpdateClient(); client.doCheckout(getSvnurl(), dest.toPath().toFile(), SVNRevision.UNDEFINED, SVNRevision.create(revision), SVNDepth.INFINITY, false); }
private SVNURL checkRootURLOfTarget(SVNURL rootURL, String target) throws SVNException { SVNPath svnPath = new SVNPath(target, true); SVNWCClient client = getClientManager().getWCClient(); File path = svnPath.isFile() ? svnPath.getFile() : null; SVNURL url = svnPath.isURL() ? svnPath.getURL() : null; SVNURL tmpRootURL = null; try { tmpRootURL = client.getReposRoot(path, url, svnPath.getPegRevision()); } catch (SVNException svne) { SVNErrorMessage err = svne.getErrorMessage(); if (err.getErrorCode() == SVNErrorCode.ENTRY_NOT_FOUND || err.getErrorCode() == SVNErrorCode.WC_NOT_DIRECTORY) { return rootURL; } throw svne; } if (rootURL != null) { if (!rootURL.equals(tmpRootURL)) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ILLEGAL_TARGET, "All non-relative targets must have the same root URL"); SVNErrorManager.error(err, SVNLogType.CLIENT); } return rootURL; } return tmpRootURL; }
public SvnConnection(String address, String pathToLocalRepos) throws SVNException { if(log.isDebugEnabled()) { log.debug("SVN repository"); } if (address.lastIndexOf('/') != -1){ svnPath = address.substring(0, address.lastIndexOf('/')); fileName = address.substring(address.lastIndexOf('/') + 1); } addressSvn = address; remoteUrl = SVNURL.parseURIEncoded(svnPath); authManager = SVNWCUtil.createDefaultAuthenticationManager(); svnOption = SVNWCUtil.createDefaultOptions(false); svnOption.setPropertyValue(SVNProperty.EOL_STYLE, SVNProperty.EOL_STYLE_LF); manager = SVNClientManager.newInstance(svnOption, authManager); this.pathToLocalRepos = pathToLocalRepos; }