void setOutputStream(OutputStream os) { if (myOutputStream != null) { myRepository.getDebugLog().flushStream(myOutputStream); } myOutputStream = os; }
public long getDir(String path, long revision, Map properties, final ISVNDirEntryHandler handler) throws SVNException { Long rev = getRevisionObject(revision); try { openConnection(); String fullPath = getFullPath(path); final SVNURL url = getLocation().setPath(fullPath, false); path = getRepositoryPath(path); write("(w(s(n)ww))", buffer); authenticate(); buffer = read("[(N(*P)", buffer, true); revision = buffer[0] != null ? SVNReader.getLong(buffer, 0) : revision; ISVNDirEntryHandler nestedHandler = new ISVNDirEntryHandler() { if (handler != null) { buffer[0] = nestedHandler; read("(*D)))", buffer, true); } else { read("()))", null, true); closeSession(); throw e; } finally { closeConnection();
public SVNRepository createRepositoryImpl(SVNURL location, ISVNSession options) { return new SVNRepositoryImpl(location, options); }
public void run(SVNException error) { if (error != null) { closeSession(); } closeConnection(); } });
public void testConnection() throws SVNException { try { openConnection(); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } }
public void testConnection() throws SVNException { try { openConnection(); } finally { closeConnection(); } }
public String getRevisionPropertyValue(long revision, String propertyName) throws SVNException { assertValidRevision(revision); Object[] buffer = new Object[] { "rev-prop", getRevisionObject(revision), propertyName }; try { openConnection(); write("(w(ns))", buffer); authenticate(); buffer = read("[((?S))]", buffer, true); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } return (String) buffer[0]; }
public void replay(long lowRevision, long highRevision, boolean sendDeltas, ISVNEditor editor) throws SVNException { Object[] buffer = new Object[]{"replay", getRevisionObject(highRevision), getRevisionObject(lowRevision), Boolean.valueOf(sendDeltas)}; try { openConnection(); write("(w(nnw))", buffer); authenticate(); SVNEditModeReader editReader = new SVNEditModeReader(myConnection, editor, true); editReader.driveEditor(); read("", null, false); } catch (SVNException e) { closeSession(); handleUnsupportedCommand(e, "Server doesn't support the replay command"); } finally { closeConnection(); } }
public long getLatestRevision() throws SVNException { Object[] buffer = new Object[] { "get-latest-rev" }; try { openConnection(); write("(w())", buffer); authenticate(); buffer = read("[(N)]", buffer, true); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } return SVNReader.getLong(buffer, 0); }
public SVNNodeKind checkPath(String path, long revision) throws SVNException { try { openConnection(); path = getLocationRelativePath(path); Object[] buffer = new Object[]{"check-path", path, getRevisionObject(revision)}; write("(w(s(n)))", buffer); authenticate(); List values = read("w", null, false); return SVNNodeKind.parseKind(SVNReader.getString(values, 0)); } catch (SVNException e) { closeSession(); throw e; } finally { closeConnection(); } }
private boolean reparent(SVNURL url) throws SVNException { if (myConnection != null) { if (getLocation().equals(url)) { return true; } lock(); try { Object[] buffer = new Object[] {"reparent", url.toString()}; write("(w(s))", buffer); authenticate(); read("[()]", null, true); return true; } catch (SVNException e) { closeSession(); if (e instanceof SVNCancelException || e instanceof SVNAuthenticationException) { throw e; } } finally { unlock(); } } return false; }
public void setPath(String path, String lockToken, long revision, boolean startEmpty) throws SVNException { assertValidRevision(revision); if (lockToken == null) { write("(w(snw))", new Object[] { "set-path", path, getRevisionObject(revision), Boolean.valueOf(startEmpty) }); } else { write("(w(snw(s)))", new Object[] { "set-path", path, getRevisionObject(revision), Boolean.valueOf(startEmpty), lockToken }); } }
protected void openConnection() throws SVNException { fireConnectionOpened(); lock(); // check if connection is stale. if (myConnection != null && myConnection.isConnectionStale()) { closeSession(); } if (myConnection != null) { if (reparent(getLocation())) { return; } closeSession(); } ISVNConnector connector = SVNRepositoryFactoryImpl.getConnectorFactory().createConnector(this); myConnection = new SVNConnection(connector, this); try { myConnection.open(this); authenticate(); } finally { if (myConnection != null) { myRealm = myConnection.getRealm(); } } }
String host = repository.getLocation().getHost(); if (repository.getLocation().getUserInfo() != null) { String username = repository.getLocation().getUserInfo(); host = username + "@" + host; if (repository.getAuthenticationManager() != null) { SVNAuthentication auth = repository.getAuthenticationManager().getFirstAuthentication(ISVNAuthenticationManager.USERNAME, host, repository.getLocation()); if (auth == null) { SVNErrorManager.cancel("Authentication cancelled"); repository.getAuthenticationManager().acknowledgeAuthentication(true, ISVNAuthenticationManager.USERNAME, host, null, auth); expandedTunnel += " --tunnel-user " + auth.getUserName(); repository.setExternalUserName(auth.getUserName()); myInputStream = repository.getDebugLog().createLogStream(myProcess.getInputStream()); myOutputStream = repository.getDebugLog().createLogStream(myProcess.getOutputStream());
public SVNAuthentication authenticate(List mechs, String realm, SVNRepositoryImpl repository) throws SVNException { boolean failed = true; setLastError(null); myAuthenticationManager = repository.getAuthenticationManager(); myAuthentication = null; boolean isAnonymous = false; if (mechs.contains("EXTERNAL") && repository.getExternalUserName() != null) { mechs = new ArrayList(); mechs.add("EXTERNAL"); myClient = createSaslClient(mechs, realm, repository, repository.getLocation()); while(true) { if (myClient == null) { if (tryAuthentication(repository, getMechanismName(myClient, isAnonymous))) { if (myAuthenticationManager != null && myAuthentication != null) { String realmName = getFullRealmName(repository.getLocation(), realm); BasicAuthenticationManager.acknowledgeAuthentication(true, myAuthentication.getKind(), realmName, null, myAuthentication, repository.getLocation(), myAuthenticationManager); String realmName = getFullRealmName(repository.getLocation(), realm); BasicAuthenticationManager.acknowledgeAuthentication(false, myAuthentication.getKind(), realmName, getLastError(), myAuthentication, repository.getLocation(), myAuthenticationManager); } else { myAuthentication = null; myClient = createSaslClient(mechs, realm, repository, repository.getLocation());
private boolean reparent(SVNURL url) throws SVNException { if (myConnection != null) { if (getLocation().equals(url)) { return true; } try { Object[] buffer = new Object[]{"reparent", url.toString()}; write("(w(s))", buffer); authenticate(); read("", null, false); String newLocation = url.toString(); String rootLocation = myRepositoryRoot.toString(); return newLocation.startsWith(rootLocation) && (newLocation.length() == rootLocation.length() || (newLocation.length() > rootLocation.length() && newLocation.charAt(rootLocation.length()) == '/')); } catch (SVNException e) { if (e instanceof SVNCancelException || e instanceof SVNAuthenticationException) { throw e; } } } return false; }
public void open(SVNRepositoryImpl repository) throws SVNException { // 1. expand tunnel spec (when env. is used). String expandedTunnel = expandTunnelSpec(myName, myTunnelSpec); // 2. create tunnel command using repo URL. String host = repository.getLocation().getHost(); if (repository.getLocation().getUserInfo() != null && !"".equals(repository.getLocation().getUserInfo())) { String username = repository.getLocation().getUserInfo(); host = username + "@" + host; } expandedTunnel = MessageFormat.format(TUNNEL_COMMAND, new Object[] {expandedTunnel, host}); // 3. get and append --tunnel-user if needed. if (repository.getAuthenticationManager() != null) { SVNAuthentication auth = repository.getAuthenticationManager().getFirstAuthentication(ISVNAuthenticationManager.USERNAME, host, repository.getLocation()); if (auth == null) { SVNErrorManager.cancel("Authentication cancelled", SVNLogType.NETWORK); } String userName = auth.getUserName(); if (userName == null || "".equals(userName.trim())) { userName = System.getProperty("user.name"); } auth = new SVNUserNameAuthentication(userName, auth.isStorageAllowed(), repository.getLocation(), false); repository.getAuthenticationManager().acknowledgeAuthentication(true, ISVNAuthenticationManager.USERNAME, host, null, auth); expandedTunnel += " --tunnel-user " + userName; repository.setExternalUserName(userName); } SVNDebugLog.getDefaultLog().logFinest(SVNLogType.NETWORK, "tunnel command: " + expandedTunnel); open(repository, expandedTunnel); }
public void open(SVNRepositoryImpl repository) throws SVNException { if (mySocket != null) { return; } SVNURL location = repository.getLocation(); try { int connectTimeout = repository.getAuthenticationManager() != null ? repository.getAuthenticationManager().getConnectTimeout(repository) : DEFAULT_SVN_TIMEOUT; int readTimeout = repository.getAuthenticationManager() != null ? repository.getAuthenticationManager().getReadTimeout(repository) : DEFAULT_SVN_TIMEOUT; mySocket = SVNSocketFactory.createPlainSocket(location.getHost(), location.getPort(), connectTimeout, readTimeout, repository.getCanceller()); } catch (SocketTimeoutException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_SVN_IO_ERROR, "timed out waiting for server", null, SVNErrorMessage.TYPE_ERROR, e); SVNErrorManager.error(err, e, SVNLogType.NETWORK); } catch (UnknownHostException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_SVN_IO_ERROR, "Unknown host " + e.getMessage(), null, SVNErrorMessage.TYPE_ERROR, e); SVNErrorManager.error(err, e, SVNLogType.NETWORK); } catch (ConnectException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_SVN_IO_ERROR, "connection refused by the server", null, SVNErrorMessage.TYPE_ERROR, e); SVNErrorManager.error(err, e, SVNLogType.NETWORK); } catch (IOException e) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_SVN_IO_ERROR, e.getLocalizedMessage()); SVNErrorManager.error(err, e, SVNLogType.NETWORK); } }
private void openConnection() throws SVNException { if (myConnection != null) { // attempt to reparent, close connection if reparent failed. if (reparent(getLocation())) { return; } } lock(); ISVNConnector connector = SVNRepositoryFactoryImpl.getConnectorFactory().createConnector(this); myConnection = new SVNConnection(connector, this); try { myConnection.open(this); authenticate(); } finally { myRealm = myConnection.getRealm(); } }
protected void closeConnection() { if (!getOptions().keepConnection(this)) { closeSession(); } unlock(); fireConnectionClosed(); }