org.tmatesoft.svn.core.SVNDirEntry Java Examples

The following examples show how to use org.tmatesoft.svn.core.SVNDirEntry. 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: SubversionCommit.java    From Getaviz with Apache License 2.0 6 votes vote down vote up
private Map<String, VersionedFile> getFiles(String path, Iterable<Pattern> filters) throws FilesNotAvailableException {
	IterablePatternMatcher matcher = new IterablePatternMatcher();
	try {
		Map<String, VersionedFile> returnable = new HashMap<String, VersionedFile>();
		List<SVNDirEntry> entries = new ArrayList<SVNDirEntry>();
		repo.getDir(path, entry.getRevision(), false, entries);
		for (SVNDirEntry dirEntry : entries) {
			SVNNodeKind kind = dirEntry.getKind();
			String currentFilePath = path + dirEntry.getName();
			if (SVNNodeKind.FILE.equals(kind)) {
				if (matcher.isIncluded(filters, currentFilePath)) {
					returnable.put(currentFilePath, new LazySvnVersionedFile(repo, currentFilePath, this.entry.getRevision()));
				}
			} else if (SVNNodeKind.DIR.equals(kind)) {
				returnable.putAll(getFiles(currentFilePath + "/", filters));
			} else {
				System.err.println("skipping unknown versioned item " + currentFilePath);
			}
		}
		return returnable;
	} catch (SVNException e) {
		throw new FilesNotAvailableException(e);
	}
}
 
Example #2
Source File: SubversionRepository.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void searchEntriesFor(SVNRepository repository, long latestRevision, Map<String, String> pathmap, String searchable) throws SVNException {
	List<SVNDirEntry> currentEntries = new ArrayList<>();
	try {
		repository.getDir(searchable, latestRevision, false, currentEntries);
	} catch (SVNException e) {
		if(!SVNErrorCode.FS_NOT_FOUND.equals(e.getErrorMessage().getErrorCode())){
			throw e;
		}
	}
	addToMap(currentEntries, pathmap, basePath + "/" + searchable + "/");
}
 
Example #3
Source File: SubversionRepository.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addToMap(List<SVNDirEntry> currentEntries, Map<String, String> pathMap, String basePath) {
	for(SVNDirEntry entry : currentEntries){
		if(SVNNodeKind.DIR.equals(entry.getKind())){
			String entryName = entry.getName();
			pathMap.put(entryName, basePath + entryName);
		}
	}
}
 
Example #4
Source File: SvnClient.java    From steady with Apache License 2.0 5 votes vote down vote up
public Map<String, String> listEntries(String _path, String _asof, String _until) {
	Map<String, String> l = new HashMap<String, String>();
	//String rel_path = url.toString().replace(rootRepo.getDir("", -1, null, (Collection<SVNDirEntry>)null).iterator().next(), "");
	try {
		Collection<SVNDirEntry> entries = this.rootRepo.getDir(_path, -1, null,(Collection<SVNDirEntry>) null); //this.getDirEntries(path);
		Iterator<SVNDirEntry> iterator = entries.iterator();
		String name = null, path = null;

		long rev = -1;
		// Use an iterator to get all directory entries in a certain path ("tags/")

		int asof  = (_asof==null?-1:Integer.parseInt(_asof));
		int until = (_until==null?-1:Integer.parseInt(_until));

		while (iterator.hasNext()) {
			SVNDirEntry entry = (SVNDirEntry) iterator.next();

			SvnClient.log.debug( "Path mess: " + entry.getPath() + " | " + entry.getRelativePath() + " | " + entry.getRepositoryRoot() + " | " + entry.getExternalParentUrl() + " | "  + entry.getURL());

			name = entry.getName();
			rev = entry.getRevision();
			path = entry.getURL().toString().substring(entry.getRepositoryRoot().toString().length());
			if( asof<rev && (_until==null || rev<until) )
				l.put(path, Long.toString(rev));
		}
	} catch (Exception e) {
		SvnClient.log.error( "Error while getting directory entries: " + e.getMessage() );
	}

	// return the tag name and the corresponding revision number
	return l;
}
 
Example #5
Source File: SvnUtil.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public static void listEntries(SVNRepository repository, String path) throws SVNException {
       Collection<?> entries = repository.getDir(path, -1, null, (Collection<?>) null);
       Iterator<?> iterator = entries.iterator();
       while (iterator.hasNext()) {
           SVNDirEntry entry = (SVNDirEntry) iterator.next();
           System.out.println("/" + (path.equals("") ? "" : path + "/") + entry.getName() + " (author: '" + entry.getAuthor() + "'; revision: " + entry.getRevision() + "; date: " + entry.getDate() + ")");
           if (entry.getKind() == SVNNodeKind.DIR) {
               listEntries(repository, (path.equals("")) ? entry.getName(): path + "/" + entry.getName());
           }
       }
}
 
Example #6
Source File: SvnUtil.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
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 #7
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new metadata object both in the local store and in the SVN
 * repository
 *
 * @param store
 *            the store this object is stored in
 * @param fo
 *            the file storing the data in the local filesystem
 * @param id
 *            the id of the metadata object
 */
MCRVersionedMetadata(MCRMetadataStore store, Path fo, int id, String docType, boolean deleted) {
    super(store, fo, id, docType);
    super.deleted = deleted;
    revision = () -> {
        try {
            // 1. current revision, 2. deleted revision, empty()
            return Optional.ofNullable(Optional.ofNullable(getStore().getRepository().info(getFilePath(), -1))
                .map(SVNDirEntry::getRevision).orElseGet(this::getLastRevision));
        } catch (SVNException e) {
            LOGGER.error("Could not get last revision of {}_{}", getStore().getID(), id, e);
            return Optional.empty();
        }
    };
}
 
Example #8
Source File: MCRVersionedMetadata.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the version in the local store is up to date with the latest
 * version in SVN repository
 *
 * @return true, if the local version in store is the latest version
 */
public boolean isUpToDate() throws IOException {
    SVNDirEntry entry;
    try {
        SVNRepository repository = getStore().getRepository();
        entry = repository.info(getFilePath(), -1);
    } catch (SVNException e) {
        throw new IOException(e);
    }
    return entry.getRevision() <= getRevision();
}
 
Example #9
Source File: CheckPathAndStatCmdTest.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
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 #10
Source File: FilterableSVNDirEntryHandler.java    From proctor with Apache License 2.0 5 votes vote down vote up
@Override
public void handleDirEntry(SVNDirEntry svnDirEntry) throws SVNException {
    // from the svn docs: The directory entry for url is reported using an empty path.
    // If SVNDepth.IMMEDIATES, lists its immediate file and directory entries
    // So identify the parent as the one with an empty relative path
    if (StringUtils.isBlank(svnDirEntry.getRelativePath())) {
        this.parent = svnDirEntry;
    } else if (childFilter.apply(svnDirEntry)) {
        this.children.add(svnDirEntry);
    }
}
 
Example #11
Source File: SvnPersisterCoreImpl.java    From proctor with Apache License 2.0 4 votes vote down vote up
@Override
public TestVersionResult determineVersions(final String fetchRevision) throws StoreException.ReadException {
    checkShutdownState();

    return doReadWithClientAndRepository(new SvnOperation<TestVersionResult>() {
        @Override
        public TestVersionResult execute(final SVNRepository repo, final SVNClientManager clientManager) throws Exception {
            final String testDefPath = testDefinitionsDirectory;
            /*
            final SVNDirEntry info = repo.info(testDefPath, 2);
            if (info == null) {
                LOGGER.warn("No test matrix found in " + testDefPath + " under " + svnPath);
                return null;
            }
            */
            final Long revision = fetchRevision.length() > 0 ? parseRevisionOrDie(fetchRevision) : Long.valueOf(-1);
            final SVNRevision svnRevision = revision.longValue() > 0 ? SVNRevision.create(revision.longValue()) : SVNRevision.HEAD;
            final SVNLogClient logClient = clientManager.getLogClient();
            final FilterableSVNDirEntryHandler handler = new FilterableSVNDirEntryHandler();
            final SVNURL url = SvnPersisterCoreImpl.this.svnUrl.appendPath(testDefPath, false);
            logClient.doList(url,
                             svnRevision,
                             svnRevision,
                             /* fetchlocks */false,
                             SVNDepth.IMMEDIATES,
                             SVNDirEntry.DIRENT_KIND | SVNDirEntry.DIRENT_CREATED_REVISION,
                             handler);


            final SVNDirEntry logEntry = handler.getParent();

            final List<TestVersionResult.Test> tests = Lists.newArrayListWithExpectedSize(handler.getChildren().size());
            for (final SVNDirEntry testDefFile : handler.getChildren()) {
                if (testDefFile.getKind() != SVNNodeKind.DIR) {
                    LOGGER.warn(String.format("svn kind (%s) is not SVNNodeKind.DIR, skipping %s", testDefFile.getKind(), testDefFile.getURL()));
                    continue;
                }
                final String testName = testDefFile.getName();
                final long testRevision;

                /*
                    When a svn directory gets copied using svn cp source-dir destination-dir, the revision
                    returned by svn list --verbose directory is different from that of svn log directory/sub-dir
                    The revision returned by svn list is the revision of the on the source-dir instead of the destination-dir
                    The code below checks to see if the directory at the provided revision exists, if it does it will use this revision.
                    If the directory does does not exist, try and identify the correct revision using svn log.
                 */
                final SVNLogEntry log = getMostRecentLogEntry(clientManager, testDefPath + "/" + testDefFile.getRelativePath(), svnRevision);
                if (log != null && log.getRevision() != testDefFile.getRevision()) {
                    // The difference in the log.revision and the list.revision can occur during an ( svn cp )
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("svn log r" + log.getRevision() + " is different than svn list r" + testDefFile.getRevision() + " for " + testDefFile.getURL());
                    }
                    testRevision = log.getRevision();
                } else {
                    testRevision = testDefFile.getRevision();
                }

                tests.add(new TestVersionResult.Test(testName, String.valueOf(testRevision)));
            }

            final String matrixRevision = String.valueOf(logEntry.getRevision());
            return new TestVersionResult(
                tests,
                logEntry.getDate(),
                logEntry.getAuthor(),
                matrixRevision,
                logEntry.getCommitMessage()
            );
        }

        @Override
        public StoreException handleException(final Exception e) throws StoreException {
            throw new StoreException.ReadException("Unable to read from SVN", e);
        }
    });
}
 
Example #12
Source File: FilterableSVNDirEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
FilterableSVNDirEntryHandler() {
    this(Predicates.<SVNDirEntry>alwaysTrue());
}
 
Example #13
Source File: FilterableSVNDirEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
FilterableSVNDirEntryHandler(final Predicate<SVNDirEntry> childFilter) {
    this.childFilter = childFilter;
}
 
Example #14
Source File: FilterableSVNDirEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
public SVNDirEntry getParent() {
    return parent;
}
 
Example #15
Source File: FilterableSVNDirEntryHandler.java    From proctor with Apache License 2.0 4 votes vote down vote up
public List<SVNDirEntry> getChildren() {
    return children;
}