Java源码示例:org.tigris.subversion.svnclientadapter.SVNRevision

示例1
/**
 * {@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);
	}
}
 
示例2
public ISVNProperty[] getProperties(SVNUrl url, SVNRevision revision,
		SVNRevision pegRevision, boolean recurse) throws SVNClientException {
	try {
		notificationHandler.setCommand(ISVNNotifyListener.Command.PROPLIST);
		String target = url.toString();
		notificationHandler.logCommandLine("proplist " + target);
		notificationHandler.setBaseDir();
		JhlProplistCallback callback = new JhlProplistCallback(false);
		Depth depth;
		if (recurse) {
			depth = Depth.infinity;
		} else {
			depth = Depth.empty;
		}
		svnClient.properties(target, JhlConverter.convert(revision),
				JhlConverter.convert(pegRevision), depth, null, callback);
		return callback.getPropertyData();
	} catch (ClientException e) {
		notificationHandler.logException(e);
		throw new SVNClientException(e);
	}
}
 
示例3
private ISVNProperty[] getPropertiesIncludingInherited(String path,
		boolean isFile) throws SVNClientException {
	try {
		notificationHandler.setCommand(ISVNNotifyListener.Command.PROPLIST);
		notificationHandler.logCommandLine("proplist " + path);
		notificationHandler.setBaseDir();
		InheritedJhlProplistCallback callback = new InheritedJhlProplistCallback(
				isFile);
		Revision revision = null;
		if (!isFile) {
			revision = JhlConverter.convert(SVNRevision.HEAD);
		}
		svnClient.properties(path, revision, revision, Depth.empty, null,
				callback);
		return callback.getPropertyData();
	} catch (ClientException e) {
		notificationHandler.logException(e);
		throw new SVNClientException(e);
	}
}
 
示例4
private void testCopyURL2FilePrevRevision(String srcPath,
                                          String targetFileName) throws Exception {
    createAndCommitParentFolders(srcPath);
    File file = createFile(srcPath);
    write(file, 1);
    add(file);
    commit(file);
    SVNRevision prevRev = getRevision(file);
    write(file, 2);
    commit(getWC());

    File filecopy = createFile(renameFile(srcPath, targetFileName));
    filecopy.delete();

    ISVNClientAdapter c = getNbClient();
    c.copy(getFileUrl(file), filecopy, prevRev);

    assertContents(filecopy, 1);
    if (isSvnkit()) {
        // svnkit does not notify about files
        assertNotifiedFiles(new File[] {});
    } else {
        assertNotifiedFiles(new File[] {filecopy});
    }
}
 
示例5
public ISVNProperty propertyGet(SVNUrl url, SVNRevision revision,
		SVNRevision peg, String propertyName) throws SVNClientException {
	try {
		notificationHandler.setCommand(ISVNNotifyListener.Command.PROPGET);
		String target = url.toString();
		String commandLine = "propget -r " + revision.toString() + " "
				+ propertyName + " " + target;
		if (!peg.equals(SVNRevision.HEAD))
			commandLine += "@" + peg.toString();
		notificationHandler.logCommandLine(commandLine);
		notificationHandler.setBaseDir();
		byte[] bytes = svnClient.propertyGet(target, propertyName,
				JhlConverter.convert(revision), JhlConverter.convert(peg));
		if (bytes == null)
			return null;
		else
			return JhlPropertyData.newForUrl(target, propertyName, bytes);
	} catch (ClientException e) {
		notificationHandler.logException(e);
		throw new SVNClientException(e);
	}
}
 
示例6
public void testSwitchToFile() throws Exception {                                        
    File file = createFile("file");
    add(file);
    commit(file);
            
    File filecopy = createFile("filecopy");
    
    ISVNClientAdapter c = getNbClient();
    c.copy(getFileUrl(file), getFileUrl(filecopy), "copy", SVNRevision.HEAD);

    assertCopy(getFileUrl(filecopy));
    assertInfo(file, getFileUrl(file));
    
    c.switchToUrl(file, getFileUrl(filecopy), SVNRevision.HEAD, false);
    
    assertInfo(file, getFileUrl(filecopy));         
    assertNotifiedFiles();// XXX empty also in svnCA - why?! - no output from cli
}
 
示例7
public void execute(IAction action) throws InterruptedException, InvocationTargetException {
       if (action != null && !action.isEnabled()) { 
       	action.setEnabled(true);
       } 
       else {
       	IPreferenceStore store = SVNUIPlugin.getPlugin().getPreferenceStore();
        IResource[] resources = getSelectedResources(); 
        SVNConflictResolver conflictResolver = new SVNConflictResolver(resources[0], store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_TEXT_FILES), store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_BINARY_FILES), store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_PROPERTIES), store.getInt(ISVNUIConstants.PREF_UPDATE_TO_HEAD_CONFLICT_HANDLING_TREE_CONFLICTS));
       	UpdateOperation updateOperation = new UpdateOperation(getTargetPart(), resources, SVNRevision.HEAD);
    	updateOperation.setDepth(depth);
    	updateOperation.setSetDepth(setDepth);
    	updateOperation.setForce(store.getBoolean(ISVNUIConstants.PREF_UPDATE_TO_HEAD_ALLOW_UNVERSIONED_OBSTRUCTIONS));
    	updateOperation.setIgnoreExternals(store.getBoolean(ISVNUIConstants.PREF_UPDATE_TO_HEAD_IGNORE_EXTERNALS));
    	updateOperation.setCanRunAsJob(canRunAsJob);
    	updateOperation.setConflictResolver(conflictResolver);
       	updateOperation.run();
       } 		
}
 
示例8
private void testCopyURL2URLPrevRevision(String srcPath,
                                         String targetFileName) throws Exception {
    createAndCommitParentFolders(srcPath);
    File file = createFile(srcPath);
    write(file, 1);
    add(file);
    commit(file);
    SVNRevision prevRev = getRevision(file);
    write(file, 2);
    commit(getWC());

    File filecopy = createFile(renameFile(srcPath, targetFileName));
    filecopy.delete();

    ISVNClientAdapter c = getNbClient();
    c.copy(getFileUrl(file), getFileUrl(filecopy), "copy", prevRev);

    ISVNLogMessage[] logs = getLog(getFileUrl(filecopy));
    assertEquals(((SVNRevision.Number)prevRev).getNumber() ,logs[0].getChangedPaths()[0].getCopySrcRevision().getNumber());

    InputStream is = getContent(getFileUrl(filecopy));
    assertContents(is, 1);
    assertNotifiedFiles(new File[] {});
}
 
示例9
private void testCommitFolder(String folderName, String fileName) throws Exception {
    File folder = createFolder(folderName);
    File file = createFile(folder, fileName);
            
    add(folder);               
    assertStatus(SVNStatusKind.ADDED, file);
    assertStatus(SVNStatusKind.ADDED, folder);

    SVNRevision revisionBefore = (SVNRevision.Number) getRevision(getRepoUrl());
    
    ISVNClientAdapter client = getNbClient();        
    long r = client.commit(new File[] {folder}, "commit", true);
    
    SVNRevision revisionAfter = (SVNRevision.Number) getRevision(getRepoUrl());
    
    assertTrue(file.exists());        
    assertStatus(SVNStatusKind.NORMAL, file);                
    assertStatus(SVNStatusKind.NORMAL, folder);                
    assertNotSame(revisionBefore, revisionAfter);
    assertEquals(((SVNRevision.Number)revisionAfter).getNumber(), r);
    assertNotifiedFiles(new File[] {file, folder});
    
}
 
示例10
/**
 * {@inheritDoc}
 */
@Override
public String cat(URL url) throws SvnClientException {
	try {
		try (final InputStream content = client.getContent(toSVNUrl(url), SVNRevision.HEAD)) {
			return IOUtils.toString(content, StandardCharsets.UTF_8);
		}
	} catch (IOException | SVNClientException e) {
		throw new SvnClientException(e);
	}
}
 
示例11
private IAction getGetContentsAction() {
  if(getContentsAction == null) {
    getContentsAction = getContextMenuAction(Policy.bind("HistoryView.getContentsAction"), new IWorkspaceRunnable() { //$NON-NLS-1$
          public void run(IProgressMonitor monitor) throws CoreException {
            ISelection selection = getSelection();
            if( !(selection instanceof IStructuredSelection))
              return;
            IStructuredSelection ss = (IStructuredSelection) selection;
            ISVNRemoteFile remoteFile = (ISVNRemoteFile) getLogEntry(ss).getRemoteResource();
            monitor.beginTask(null, 100);
            try {
              if(remoteFile != null) {
                if(confirmOverwrite()) {
              	if (remoteFile instanceof RemoteResource) {
              		if (resource != null) {
              			ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
              			((RemoteResource)remoteFile).setPegRevision(localResource.getRevision());
              		} else {
              			((RemoteResource)remoteFile).setPegRevision(SVNRevision.HEAD);
              		}
              	}
                  InputStream in = ((IResourceVariant) remoteFile).getStorage(new SubProgressMonitor(monitor, 50))
                      .getContents();
                  IFile file = (IFile) resource;
                  file.setContents(in, false, true, new SubProgressMonitor(monitor, 50));
                }
              }
            } catch(TeamException e) {
              throw new CoreException(e.getStatus());
            } finally {
              monitor.done();
            }
          }
        });
    PlatformUI.getWorkbench().getHelpSystem().setHelp(getContentsAction, IHelpContextIds.GET_FILE_CONTENTS_ACTION);
  }
  return getContentsAction;
}
 
示例12
/**
 * {@inheritDoc}
 */
@Override
public void update(Path path) throws SvnClientException {
	try {
		client.update(path.toFile(), SVNRevision.HEAD, true);
	} catch (SVNClientException e) {
		throw new SvnClientException(e);
	}
}
 
示例13
private SVNRevision getRevisionFrom() {
    String value = panel.dateFromTextField.getText().trim();
    if(value.equals("")) {
        return new SVNRevision.Number(1);
    }
    try {
        return new SVNRevision.DateSpec(DATE_FORMAT.parse(value));
    } catch (ParseException ex) {
        return null; // should not happen
    }
}
 
示例14
private void getAllLogEntries() {
   BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
        public void run() {
            try {
	            if (remoteResource == null) {
	                ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
					if ( localResource != null
					        && !localResource.getStatus().isAdded()
					        && localResource.getStatus().isManaged() ) {
					    remoteResource = localResource.getBaseResource();
					}
	            }
	            if (remoteResource != null) {
	            	if (SVNUIPlugin.getPlugin().getPreferenceStore().getBoolean(ISVNUIConstants.PREF_SHOW_TAGS_IN_REMOTE))
	            		tagManager = new AliasManager(remoteResource.getUrl());
					SVNRevision pegRevision = remoteResource.getRevision();
					SVNRevision revisionEnd = new SVNRevision.Number(0);
					revisionStart = SVNRevision.HEAD;
					boolean stopOnCopy = store.getBoolean(ISVNUIConstants.PREF_STOP_ON_COPY);
					long limit = 0;
					entries = getLogEntries(remoteResource, pegRevision, revisionStart, revisionEnd, stopOnCopy, limit, tagManager);
					if (getNextButton != null) getNextButton.setEnabled(false);	
	            }
			} catch (TeamException e) {
				SVNUIPlugin.openError(Display.getCurrent().getActiveShell(), null, null, e);
			}	
        }       
   });
   if (tableHistoryViewer != null) tableHistoryViewer.refresh();
}
 
示例15
public SwitchToUrlCommand(SVNWorkspaceRoot root, IResource resource, SVNUrl svnUrl, SVNRevision svnRevision) {
    super();
    this.root = root;
    this.resource = resource;
    this.svnUrl = svnUrl;
    this.svnRevision = svnRevision;
}
 
示例16
public SVNRevision getMergeStartRevision() {
    try {
        return mergeStartRepositoryPaths.getRepositoryFiles()[0].getRevision();
    } catch (MalformedURLException ex) {
        // should be already checked and
        // not happen at this place anymore
        Subversion.LOG.log(Level.INFO, null, ex);
    }
    return null;
}
 
示例17
public boolean pathExists() throws SVNException{
	ISVNClientAdapter svnClient = getSVNClient();
	try{
		svnClient.getList(getUrl(), SVNRevision.HEAD, false);
	}catch(SVNClientException e){
		return false;
	}
	return true;
}
 
示例18
private SVNRevision.Number getNumber(String revision) {
    if (revision == null) {
        return null;
    }            
    try {
        return new SVNRevision.Number(Long.parseLong(revision));
    } catch (NumberFormatException e) {
        return new SVNRevision.Number(-1);
    }
}
 
示例19
public RepositoryBranchTagOperation(IWorkbenchPart part, ISVNClientAdapter svnClient, SVNUrl[] sourceUrls, SVNUrl destinationUrl, SVNRevision revision, String message, boolean makeParents) {
	super(part);
	this.svnClient = svnClient;
       this.sourceUrls = sourceUrls;
       this.destinationUrl = destinationUrl;
       this.revision = revision;
       this.message = message;
       this.makeParents = makeParents;
}
 
示例20
@Override
public ISVNProperty[] getProperties(SVNUrl url, SVNRevision revision, SVNRevision pegRevision, boolean recursive) throws SVNClientException {
    ListPropertiesCommand cmd = new ListPropertiesCommand(url, revision.toString(), recursive);
    exec(cmd);
    List<String> names = cmd.getPropertyNames();
    List<ISVNProperty> props = new ArrayList<ISVNProperty>(names.size());
    for (String name : names) {
        ISVNProperty prop = propertyGet(url, name);
        if (prop != null) {
            props.add(prop);
        }
    }
    return props.toArray(new ISVNProperty[props.size()]);
}
 
示例21
private void testCatFile(String path) throws Exception {
    createAndCommitParentFolders(path);
    File file = createFile(path);
    write(file, 1);
    add(file);
    commit(file);

    InputStream is1 = getNbClient().getContent(file, SVNRevision.HEAD);
    InputStream is2 = new FileInputStream(file);

    assertInputStreams(is2, is1);
}
 
示例22
public SVNDiffSummary[] diffSummarize(File path, SVNRevision pegRevision,
		SVNRevision startRevision, SVNRevision endRevision, int depth,
		boolean ignoreAncestry) throws SVNClientException {
	String target = fileToSVNPath(path, false);
	return this.diffSummarize(target, pegRevision, startRevision,
			endRevision, depth, ignoreAncestry);
}
 
示例23
private void logLimit(Log log) throws Exception {                                
    File file = createFile("file");
    add(file);
    write(file, "1");        
    commit(file, "msg1");
    ISVNInfo info1 = getInfo(file);        
    
    write(file, "2");
    commit(file, "msg2");
    ISVNInfo info2 = getInfo(file);
    
    write(file, "3");
    commit(file, "msg3");

    ISVNLogMessage[] logsNb = null;
    switch(log) {
        case file:
            logsNb = getNbClient().getLogMessages(file, new SVNRevision.Number(0), SVNRevision.HEAD, false, true, 2);
            break;
        case url:
            logsNb = getNbClient().getLogMessages(getFileUrl(file), null, new SVNRevision.Number(0), SVNRevision.HEAD, false, true, 2);
            break;
        default:
            fail("no idea!");
    }
    
    // test
    assertEquals(2, logsNb.length);         
    String testName = getName();        
    assertLogMessage(info1, logsNb[0], "msg1",  new ISVNLogMessageChangePath[] { new ChangePath('A', "/" + testName + "/" + testName + "_wc/file", null, null) });
    assertLogMessage(info2, logsNb[1], "msg2",  new ISVNLogMessageChangePath[] { new ChangePath('M', "/" + testName + "/" + testName + "_wc/file", null, null) });
}
 
示例24
@Override
public long commit(File[] files, String message, boolean keep, boolean recursive) throws SVNClientException {
    int retry = 0;
    CommitCommand cmd = null;
    while (true) {
        try {
            cmd = new CommitCommand(files, keep, recursive, message); // prevent cmd reuse
            exec(cmd);
            break;
        } catch (SVNClientException e) {
            if (e.getMessage().startsWith("svn: Attempted to lock an already-locked dir")) {
                Subversion.LOG.fine("ComandlineClient.comit() : " + e.getMessage());
                try {
                    retry++;
                    if (retry > 14) {
                        throw e;
                    }
                    Thread.sleep(retry * 50);
                } catch (InterruptedException ex) {
                    break;
                }
            } else {
                throw e;
            }
        }
    }
    return cmd != null ? cmd.getRevision() : SVNRevision.SVN_INVALID_REVNUM;
}
 
示例25
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");
}
 
示例26
@Override
RevertModifications.RevisionInterval getRevisionInterval() {                       
    SVNRevision revision1 = getRevision(startPath);
    SVNRevision revision2 = getRevision(endPath);
    if(revision1 == null || revision2 == null) {
        return null;
    }

    return getResortedRevisionInterval(revision1, revision2);            
}
 
示例27
public SVNRevision.Number getLastChangedRevision() {
       // we don't use 
       // return (SVNRevision.Number)JhlConverter.convert(_s.getLastChangedRevision());
       // as _s.getLastChangedRevision() is currently broken if revision is -1 
	if (lastChangedRevision != null)
		return lastChangedRevision;
	if (_s.getReposLastCmtAuthor() == null)
		return JhlConverter.convertRevisionNumber(_s.getLastChangedRevisionNumber());
	else
		if (_s.getReposLastCmtRevisionNumber() == 0)
			return null;
		return JhlConverter.convertRevisionNumber(_s.getReposLastCmtRevisionNumber());
}
 
示例28
public void execute(IAction action) throws InterruptedException, InvocationTargetException {
       if (action != null && !action.isEnabled()) { 
       	action.setEnabled(true);
       } 
       else {
        IResource[] resources = getSelectedResources();         
        String pageName;
        if (resources.length > 1) pageName = "UpdateDialogWithConflictHandling.multiple"; //$NON-NLS-1$	
        else pageName = "UpdateDialogWithConflictHandling"; //$NON-NLS-1$	        
        SvnWizardUpdatePage updatePage = new SvnWizardUpdatePage(pageName, resources);
        updatePage.setDefaultRevision(revision);
        updatePage.setDepth(depth);
        updatePage.setSetDepth(setDepth);
        SvnWizard wizard = new SvnWizard(updatePage);
        SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
        wizard.setParentDialog(dialog);
        if (dialog.open() == SvnWizardDialog.OK) {	  
        	SVNRevision svnRevision = updatePage.getRevision();
        	UpdateOperation updateOperation = new UpdateOperation(getTargetPart(), resources, svnRevision);
        	updateOperation.setDepth(updatePage.getDepth());
	    	updateOperation.setSetDepth(updatePage.isSetDepth());
	    	updateOperation.setForce(updatePage.isForce());
	    	updateOperation.setIgnoreExternals(updatePage.isIgnoreExternals());
	    	updateOperation.setCanRunAsJob(canRunAsJob);
	    	updateOperation.setConflictResolver(updatePage.getConflictResolver());
        	updateOperation.run();
        }
       } 		
}
 
示例29
public RepositoryFile(SVNUrl repositoryUrl, SVNRevision revision) {
    assert repositoryUrl != null;        
    assert revision != null;
    
    this.repositoryUrl = repositoryUrl;
    this.revision = revision;
    repositoryRoot = true;
}
 
示例30
private SVNDiffSummary[] diffSummarize(String target,
		SVNRevision pegRevision, SVNRevision startRevision,
		SVNRevision endRevision, int depth, boolean ignoreAncestry)
		throws SVNClientException {
	try {
		notificationHandler.setCommand(ISVNNotifyListener.Command.DIFF);

		if (pegRevision == null)
			pegRevision = SVNRevision.HEAD;
		if (startRevision == null)
			startRevision = SVNRevision.HEAD;
		if (endRevision == null)
			endRevision = SVNRevision.HEAD;

		String commandLine = "diff --summarize";
		Depth d = JhlConverter.depth(depth);
		commandLine += depthCommandLine(d);
		if (ignoreAncestry)
			commandLine += " --ignoreAncestry";
		commandLine += " -r " + startRevision + ":" + endRevision + " "
				+ target;
		notificationHandler.logCommandLine(commandLine);
		notificationHandler.setBaseDir();
		JhlDiffSummaryReceiver callback = new JhlDiffSummaryReceiver();
		svnClient.diffSummarize(target, JhlConverter.convert(pegRevision),
				JhlConverter.convert(startRevision),
				JhlConverter.convert(endRevision), d, null, ignoreAncestry,
				callback);
		return callback.getDiffSummary();
	} catch (ClientException e) {
		notificationHandler.logException(e);
		throw new SVNClientException(e);
	}
}