Java源码示例:org.tigris.subversion.svnclientadapter.SVNClientException
示例1
/**
* @param provider to authenticate when required
* @param configuration the configuration to get and set the username and
* password
* @throws SvnClientException
*/
@Inject
public SvnClientJavaHl(ICredentialProvider provider, IConfiguration configuration) throws SvnClientException {
try {
if (!SVNClientAdapterFactory.isSVNClientAvailable(JhlClientAdapterFactory.JAVAHL_CLIENT)) {
JhlClientAdapterFactory.setup();
}
client = SVNClientAdapterFactory.createSVNClient(JhlClientAdapterFactory.JAVAHL_CLIENT);
final String username = configuration.getSvnUsername();
if (username != null) {
client.setUsername(username);
}
final String password = configuration.getSvnPassword();
if (password != null) {
client.setPassword(password);
}
client.addPasswordCallback(new SVNPromptUserPassword(provider, configuration, client));
} catch (SVNClientException | ConfigurationException e) {
throw new SvnClientException(e);
}
}
示例2
private static void startCommitTask(final CommitPanel panel, final CommitTable data, final Context ctx, final File[] rootFiles, final Collection<SvnHook> hooks) {
final Map<SvnFileNode, CommitOptions> commitFiles = data.getCommitFiles();
final String message = panel.getCommitMessage();
SvnModuleConfig.getDefault().setLastCanceledCommitMessage(""); //NOI18N
org.netbeans.modules.versioning.util.Utils.insert(SvnModuleConfig.getDefault().getPreferences(), RECENT_COMMIT_MESSAGES, message.trim(), 20);
SVNUrl repository = null;
try {
repository = getSvnUrl(ctx);
} catch (SVNClientException ex) {
SvnClientExceptionHandler.notifyException(ex, true, true);
}
RequestProcessor rp = Subversion.getInstance().getRequestProcessor(repository);
SvnProgressSupport support = new SvnProgressSupport() {
@Override
public void perform() {
performCommit(message, commitFiles, ctx, rootFiles, this, hooks);
}
};
support.start(rp, repository, org.openide.util.NbBundle.getMessage(CommitAction.class, "LBL_Commit_Progress")); // NOI18N
}
示例3
public void deleteNotVersionedFolder() throws IOException, SVNClientException {
// init
File folder = new File(wc, "folder2");
folder.mkdirs();
assertEquals(SVNStatusKind.UNVERSIONED, getSVNStatus(folder).getTextStatus());
// delete
delete(folder);
// test
assertFalse(folder.exists());
assertEquals(SVNStatusKind.UNVERSIONED, getSVNStatus(folder).getTextStatus());
assertEquals(FileInformation.STATUS_UNKNOWN, getStatus(folder));
// commit(wc);
}
示例4
/**
* {@inheritDoc}
*/
@Override
public void merge(Path path, URL url, long revision, boolean recursivly, boolean recordOnly)
throws SvnClientException {
try {
final SVNRevisionRange[] revisionRange = new SVNRevisionRange[] {
new SVNRevisionRange(new Number(revision - 1), new Number(revision)) };
client.merge(toSVNUrl(url), // SVN URL
SVNRevision.HEAD, // pegRevision
revisionRange, // revisions to merge (must be in the form N-1:M)
path.toFile(), // target local path
false, // force
recursivly ? Depth.infinity : Depth.empty, // how deep to traverse into subdirectories
false, // ignoreAncestry
false, // dryRun
recordOnly); // recordOnly
} catch (MalformedURLException | SVNClientException e) {
throw new SvnClientException(e);
}
}
示例5
/**
* Checks if the target folder already exists in the repository.
* If it does exist, user will be asked to confirm the import into the existing folder.
* @param client
* @param repositoryFileUrl
* @return true if the target does not exist or user wishes to import anyway.
*/
private boolean importIntoExisting(SvnClient client, SVNUrl repositoryFileUrl) {
try {
ISVNInfo info = client.getInfo(repositoryFileUrl);
if (info != null) {
// target folder exists, ask user for confirmation
final boolean flags[] = {true};
NotifyDescriptor nd = new NotifyDescriptor(NbBundle.getMessage(ImportStep.class, "MSG_ImportIntoExisting", SvnUtils.decodeToString(repositoryFileUrl)), //NOI18N
NbBundle.getMessage(ImportStep.class, "CTL_TargetFolderExists"), NotifyDescriptor.YES_NO_CANCEL_OPTION, //NOI18N
NotifyDescriptor.QUESTION_MESSAGE, null, NotifyDescriptor.YES_OPTION);
if (DialogDisplayer.getDefault().notify(nd) != NotifyDescriptor.YES_OPTION) {
flags[0] = false;
}
return flags[0];
}
} catch (SVNClientException ex) {
// ignore
}
return true;
}
示例6
@Override
public boolean areCollocated(File a, File b) {
File fra = getTopmostManagedAncestor(a);
File frb = getTopmostManagedAncestor(b);
if (fra == null || !fra.equals(frb)) return false;
try {
SVNUrl ra = SvnUtils.getRepositoryRootUrl(a);
if(ra == null) {
// this might happen. there is either no svn client available or
// no repository url stored in the metadata (svn < 1.3).
// one way or another, can't do anything reasonable at this point
Subversion.LOG.log(Level.WARNING, "areCollocated returning false due to missing repository url for {0} {1}", new Object[] {a, b});
return false;
}
SVNUrl rb = SvnUtils.getRepositoryRootUrl(b);
SVNUrl rr = SvnUtils.getRepositoryRootUrl(fra);
return ra.equals(rb) && ra.equals(rr);
} catch (SVNClientException e) {
if (!WorkingCopyAttributesCache.getInstance().isSuppressed(e)) {
Subversion.LOG.log(Level.INFO, null, e);
}
Subversion.LOG.log(Level.WARNING, "areCollocated returning false due to catched exception " + a + " " + b);
// root not found
return false;
}
}
示例7
/**
* Returns log message for given revision
* @param client
* @param file
* @param revision
* @return log message
* @throws org.tigris.subversion.svnclientadapter.SVNClientException
*/
private static ISVNLogMessage getLogMessage (ISVNClientAdapter client, File file, long revision) throws SVNClientException {
SVNRevision rev = SVNRevision.HEAD;
ISVNLogMessage log = null;
try {
rev = SVNRevision.getRevision(String.valueOf(revision));
} catch (ParseException ex) {
Subversion.LOG.log(Level.WARNING, "" + revision, ex);
}
if (Subversion.LOG.isLoggable(Level.FINER)) {
Subversion.LOG.log(Level.FINER, "{0}: getting last commit message for svn hooks", CommitAction.class.getName());
}
// log has to be called directly on the file
final SVNUrl fileRepositoryUrl = SvnUtils.getRepositoryUrl(file);
ISVNLogMessage[] ls = client.getLogMessages(fileRepositoryUrl, rev, rev);
if (ls.length > 0) {
log = ls[0];
} else {
Subversion.LOG.log(Level.WARNING, "no logs available for file {0} with repo url {1}", new Object[]{file, fileRepositoryUrl});
}
return log;
}
示例8
private String validateTargetPath(CreateCopy createCopy) {
String errorText = null;
try {
RepositoryFile toRepositoryFile = createCopy.getToRepositoryFile();
SvnClient client = Subversion.getInstance().getClient(toRepositoryFile.getRepositoryUrl());
ISVNInfo info = null;
try {
info = client.getInfo(toRepositoryFile.getFileUrl());
} catch (SVNClientException e) {
if (!SvnClientExceptionHandler.isWrongUrl(e.getMessage())) {
throw e;
}
}
if (info != null) {
errorText = NbBundle.getMessage(CreateCopyAction.class, "MSG_CreateCopy_Target_Exists"); // NOI18N
}
} catch (SVNClientException ex) {
errorText = null;
}
return errorText;
}
示例9
public void deleteA_CreateA() throws IOException, SVNClientException {
// init
File fileA = new File(wc, "A");
fileA.createNewFile();
commit(wc);
assertEquals(SVNStatusKind.NORMAL, getSVNStatus(fileA).getTextStatus());
// delete
FileObject fo = FileUtil.toFileObject(fileA);
fo.delete();
// test if deleted
assertFalse(fileA.exists());
assertEquals(SVNStatusKind.DELETED, getSVNStatus(fileA).getTextStatus());
// create
fo.getParent().createData(fo.getName());
// test
assertTrue(fileA.exists());
assertEquals(SVNStatusKind.NORMAL, getSVNStatus(fileA).getTextStatus());
assertEquals(FileInformation.STATUS_VERSIONED_UPTODATE, getStatus(fileA));
}
示例10
@Override
protected SvnClient getFullWorkingClient() throws SVNClientException {
String fac = System.getProperty("svnClientAdapterFactory", "javahl");
boolean resetNeeded = !"javahl".equals(fac); // for javahl setup, there's no need to change anything
try {
if (resetNeeded) {
SvnModuleConfig.getDefault().setPreferredFactoryType("javahl");
System.setProperty("svnClientAdapterFactory", "javahl");
SvnClientFactory.resetClient();
}
SvnClient c = SvnClientFactory.getInstance().createSvnClient();
assertTrue(c.toString().contains("JhlClientAdapter"));
return c;
} finally {
if (resetNeeded) {
SvnModuleConfig.getDefault().setPreferredFactoryType(fac);
System.setProperty("svnClientAdapterFactory", fac);
SvnClientFactory.resetClient();
}
}
}
示例11
public void testCommit() throws SVNClientException, IOException {
File folder = new File(workDir, "testCommitFolder");
folder.mkdirs();
TestKit.svnimport(repoDir, folder);
ISVNStatus s = TestKit.getSVNStatus(folder);
assertEquals(SVNStatusKind.NORMAL, s.getTextStatus());
File file = new File(folder, "file");
file.createNewFile();
TestKit.add(file);
s = TestKit.getSVNStatus(file);
assertEquals(SVNStatusKind.ADDED, s.getTextStatus());
Subversion.getInstance().versionedFilesChanged();
SvnUtils.refreshParents(folder);
Subversion.getInstance().getStatusCache().refreshRecursively(folder);
org.netbeans.modules.subversion.api.Subversion.commit(new File[] {folder}, "", "", "msg");
s = TestKit.getSVNStatus(file);
assertEquals(SVNStatusKind.NORMAL, s.getTextStatus());
}
示例12
@Override
protected SVNRevision getRevision(Context ctx) {
File[] roots = ctx.getRootFiles();
SVNRevision revision = null;
if(roots == null || roots.length == 0) return null;
File interestingFile = roots[0];
final SVNUrl rootUrl;
final SVNUrl url;
try {
rootUrl = SvnUtils.getRepositoryRootUrl(interestingFile);
url = SvnUtils.getRepositoryUrl(interestingFile);
} catch (SVNClientException ex) {
SvnClientExceptionHandler.notifyException(ex, true, true);
return null;
}
final RepositoryFile repositoryFile = new RepositoryFile(rootUrl, url, SVNRevision.HEAD);
final UpdateTo updateTo = new UpdateTo(repositoryFile, Subversion.getInstance().getStatusCache().containsFiles(ctx, FileInformation.STATUS_LOCAL_CHANGE, true));
if(updateTo.showDialog()) {
revision = updateTo.getSelectedRevision();
}
return revision;
}
示例13
/**
* {@inheritDoc}
*/
@Override
public void checkoutEmpty(Path path, URL url) throws SvnClientException {
Objects.requireNonNull(url);
checkPath(path);
try {
client.checkout(toSVNUrl(url), path.toFile(), SVNRevision.HEAD, Depth.empty, false, false);
} catch (MalformedURLException | SVNClientException e) {
throw new SvnClientException(e);
}
}
示例14
/**
* {@inheritDoc}
*/
@Override
public void commit(Path path, String message) throws SvnClientException {
try {
client.commit(new File[] { path.toFile() }, message, true);
} catch (SVNClientException e) {
throw new SvnClientException(e);
}
}
示例15
/**
* {@inheritDoc}
*/
@Override
public URL getSvnUrl(Path path) throws SvnClientException {
try {
final ISVNInfo info = client.getInfoFromWorkingCopy(path.toFile());
return new URL(info.getUrlString());
} catch (MalformedURLException | SVNClientException e) {
throw new SvnClientException(e);
}
}
示例16
private SVNUrl getRepositoryUrl (File file) {
SVNUrl url = null;
try {
url = SvnUtils.getRepositoryRootUrl(file);
} catch (SVNClientException ex) {
LOG.log(Level.FINE, "getRepositoryUrl: No repository root url found for managed file : [" + file + "]", ex); //NOI18N
try {
url = SvnUtils.getRepositoryUrl(file); // try to falback
} catch (SVNClientException ex1) {
LOG.log(Level.FINE, "getRepositoryUrl: No repository url found for managed file : [" + file + "]", ex1); //NOI18N
}
}
return url;
}
示例17
private void readEntry(File file) {
try {
entry = SvnUtils.getSingleStatus(Subversion.getInstance().getClient(false), file);
} catch (SVNClientException e) {
// at least log the exception
if (!WorkingCopyAttributesCache.getInstance().isSuppressed(e)) {
Subversion.LOG.log(Level.INFO, null, e);
}
}
}
示例18
protected void cleanUpRepo() throws SVNClientException, IOException, InterruptedException {
ISVNClientAdapter client = getFullWorkingClient();
ISVNDirEntry[] entries = client.getList(repoUrl, SVNRevision.HEAD, false);
SVNUrl[] urls = new SVNUrl[entries.length];
for (int i = 0; i < entries.length; i++) {
urls[i] = repoUrl.appendPath(entries[i].getPath());
}
cliRemove(urls);
}
示例19
/**
* A SVNClientAdapterFactory will be setup, according to the svnClientAdapterFactory property.<br>
* The CommandlineClientAdapterFactory is default as long no value is set for svnClientAdapterFactory.
*
*/
private void setup() {
try {
exception = null;
// ping config file copying
SvnConfigFiles.getInstance();
String factoryType = getDefaultFactoryType(false);
if (factoryType.trim().equals(FACTORY_TYPE_JAVAHL)) {
if(setupJavaHl()) {
return;
}
LOG.log(Level.INFO, "JavaHL not available. Falling back on SvnKit.");
if(setupSvnKit()) {
return;
}
LOG.log(Level.INFO, "SvnKit not available. Falling back on commandline.");
setupCommandline();
} else if(factoryType.trim().equals(FACTORY_TYPE_SVNKIT)) {
if(setupSvnKit()) {
return;
}
LOG.log(Level.INFO, "SvnKit not available. Falling back on javahl.");
if(setupJavaHl()) {
return;
}
LOG.log(Level.INFO, "JavaHL not available. Falling back on comandline.");
setupCommandline();
} else if(factoryType.trim().equals(FACTORY_TYPE_COMMANDLINE)) {
setupCommandline();
} else {
throw new SVNClientException("Unknown factory: " + factoryType);
}
} catch (SVNClientException e) {
exception = e;
}
}
示例20
private void checkErrors(SvnCommand cmd) throws SVNClientException {
List<String> errors = cmd.getCmdError();
if(errors == null || errors.isEmpty()) {
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < errors.size(); i++) {
sb.append(errors.get(i));
if (i < errors.size() - 1) {
sb.append('\n');
}
}
throw new SVNClientException(sb.toString());
}
示例21
private void checkVersion() throws SVNClientException {
CommandlineClient cc = new CommandlineClient();
try {
setConfigDir(cc);
cli16Version = cc.checkSupportedVersion();
} catch (SVNClientException e) {
LOG.log(Level.FINE, "checking version", e);
throw e;
}
}
示例22
protected void setupAdapter(ISVNClientAdapter adapter, String username, char[] password, ISVNPromptUserPassword callback) {
adapter.setUsername(username);
if(callback != null) {
adapter.addPasswordCallback(callback);
} else {
// do not set password for javahl, it seems that in that case the password is stored permanently in ~/.subversion/auth
adapter.setPassword(password == null ? "" : new String(password)); //NOI18N
}
try {
File configDir = FileUtil.normalizeFile(new File(SvnConfigFiles.getNBConfigPath()));
adapter.setConfigDirectory(configDir);
} catch (SVNClientException ex) {
SvnClientExceptionHandler.notifyException(ex, false, false);
}
}
示例23
private static SvnClient getClient(Context ctx, SvnProgressSupport support) {
try {
return Subversion.getInstance().getClient(ctx, support);
} catch (SVNClientException ex) {
SvnClientExceptionHandler.notifyException(ex, true, true); // should not hapen
return null;
}
}
示例24
protected RequestProcessor createRequestProcessor(Node[] nodes) {
SVNUrl repository = null;
try {
repository = getSvnUrl(nodes);
} catch (SVNClientException ex) {
SvnClientExceptionHandler.notifyException(ex, false, false);
}
return Subversion.getInstance().getRequestProcessor(repository);
}
示例25
private void exec(SvnCommand cmd) throws SVNClientException {
try {
config(cmd);
cli.exec(cmd);
} catch (IOException ex) {
Subversion.LOG.log(Level.FINE, null, ex);
throw new SVNClientException(ex);
}
checkErrors(cmd);
}
示例26
@Override
protected void performContextAction (Node[] nodes) {
Context ctx = getContext(nodes);
final File[] roots = ctx.getRootFiles();
if (roots == null || roots.length == 0) {
Subversion.LOG.log(Level.FINE, "No versioned folder in the selected context for {0}", nodes); //NOI18N
return;
}
File root = roots[0];
SVNUrl repositoryUrl = null;
try {
repositoryUrl = SvnUtils.getRepositoryRootUrl(root);
} catch (SVNClientException ex) {
SvnClientExceptionHandler.notifyException(ex, true, true);
return;
}
if(repositoryUrl == null) {
Subversion.LOG.log(Level.WARNING, "Could not retrieve repository root for context file {0}", new Object[]{ root }); //NOI18N
return;
}
SvnShelveChangesSupport supp = new SvnShelveChangesSupport(roots);
if (supp.prepare("org.netbeans.modules.subversion.ui.shelve.ShelveChangesPanel")) { //NOI18N
RequestProcessor rp = Subversion.getInstance().getRequestProcessor(repositoryUrl);
supp.startAsync(rp, repositoryUrl);
}
}
示例27
@RandomlyFails
public void testCheckoutLocalLevel() throws MalformedURLException, SVNClientException, IOException {
FileUtils.deleteRecursively(workDir);
TestKit.mkdirs(repoDir, "testCheckoutLocalLevelfolder1/folder2/folder3");
String url = TestUtilities.formatFileURL(repoDir) + "/testCheckoutLocalLevelfolder1/folder2";
org.netbeans.modules.subversion.api.Subversion.checkoutRepositoryFolder(
url,
new String[0],
workDir,
username,
password,
true,
false);
assertTrue(workDir.exists());
String[] files = workDir.list();
assertEquals(2, files.length); // one folder + metadata
String s = null;
for (String f : files) {
if(f.equals("folder3")) {
s = f;
break;
}
}
assertEquals("folder3", s);
}
示例28
private void cleanUpRepo() throws SVNClientException {
ISVNClientAdapter client = getClient();
ISVNDirEntry[] entries = client.getList(repoUrl, SVNRevision.HEAD, false);
SVNUrl[] urls = new SVNUrl[entries.length];
for (int i = 0; i < entries.length; i++) {
urls[i] = repoUrl.appendPath(entries[i].getPath());
}
client.remove(urls, "cleanup");
}
示例29
private void cliRemove(SVNUrl... urls) throws SVNClientException, IOException, InterruptedException {
for (SVNUrl url : urls) {
String[] cmd = new String[] {"svn", "remove", url.toString(), "-m", "remove"};
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
}
}
示例30
@Override
public void diff(SVNUrl arg0, SVNRevision arg1, SVNRevision arg2, SVNRevision arg3, File arg4, boolean arg5) throws SVNClientException {
throw new UnsupportedOperationException("Not supported yet.");
}