Hello Andy,

The error occurs because you use SvnRepositoryGetLock incorrectly. This class 
is an analog of one of 
"svnlook" commands, it requires local access to FSFS repository. To get locks 
use 
svnOperationFactory.createGetInfo() method.

Have a look at the test that I've added for you as an example in r9744-9745. 
The test code is below:


    @Test
    public void testSvnRepositoryGetLock() throws Exception {
        final TestOptions options = TestOptions.getInstance();

        final SvnOperationFactory svnOperationFactory = new 
SvnOperationFactory();
        final Sandbox sandbox = 
Sandbox.createWithCleanup(getClass().getSimpleName() + 
".testSvnRepositoryGetLock", options);
        try {
            final SVNURL url = sandbox.createSvnRepository();

            final CommitBuilder commitBuilder = new CommitBuilder(url);
            commitBuilder.addFile("directory/file");
            commitBuilder.commit();

            final WorkingCopy workingCopy = sandbox.checkoutNewWorkingCopy(url);
            final File file = workingCopy.getFile("directory/file");

            final String expectedLockMessage = "Lock message";
            final String expectedLockOwner = "owner";

            final SvnSetLock setLock = svnOperationFactory.createSetLock();
            svnOperationFactory.setAuthenticationManager(new 
BasicAuthenticationManager(expectedLockOwner, null));
            setLock.setSingleTarget(SvnTarget.fromFile(file));
            setLock.setLockMessage(expectedLockMessage);
            setLock.setStealLock(true);
            setLock.run();

            //svnlook-like way to obtain lock, requires access to FSFS 
repository
            final SvnRepositoryGetLock getLock = 
svnOperationFactory.createRepositoryGetLock();
            getLock.setRepositoryRoot(new File(url.getPath()));
            getLock.setPath("directory/file");
            SVNLock lock = getLock.run();

            checkLockOwnerAndMessage(expectedLockMessage, expectedLockOwner, 
lock);

            //svn info-like way to obtain lock, requires only working copy 
(even working copy is not 
mandatory, one can use SvnTarget#fromURL)
            final SvnGetInfo getInfo = svnOperationFactory.createGetInfo();
            getInfo.setSingleTarget(SvnTarget.fromFile(file));
            final SvnInfo info = getInfo.run();

            lock = info.getLock();
            checkLockOwnerAndMessage(expectedLockMessage, expectedLockOwner, 
lock);

        } finally {
            svnOperationFactory.dispose();
            sandbox.dispose();
        }
    }

    private void checkLockOwnerAndMessage(String expectedLockMessage, String 
expectedLockOwner, 
SVNLock lock) {
        String actualLockOwner = lock == null ? null : lock.getOwner();
        String actualLockMessage = lock == null ? null : lock.getComment();

        Assert.assertEquals(expectedLockOwner, actualLockOwner);
        Assert.assertEquals(expectedLockMessage, actualLockMessage);
    }


--
Dmitry Pavlenko,
TMate Software,
http://subgit.com/ - git-svn bridge

> I'm trying to determine whether or not a file is locked, and if so, what
> the username of the lock's owner is. Here's what I've tried so far:
> 
> =======================================================================
> 
>     SvnRepositoryGetLock svnRepositoryGetLock
>       = svnOperationFactory.createRepositoryGetLock();
> 
>     String workingCopyDirPath = workingCopyDir.getAbsolutePath();
>     SvnTarget fileTarget = SvnTarget.fromFile(requestedFile);
>     svnRepositoryGetLock.setSingleTarget(fileTarget);
>     svnRepositoryGetLock.setPath(workingCopyDirPath);
> 
>     SVNLock svnLock = svnRepositoryGetLock.run();
> 
>     return (svnLock == null ? null : svnLock.getOwner());
> 
> 
> Unfortunately, it's not working. It produces this error:
> 
> Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn:
> E160004: Can't read length line from file format: format (No such file or
> directory) at
> org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.j
> ava:85) at
> org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.j
> ava:69) at
> org.tmatesoft.svn.core.internal.io.fs.FSFile.readLine(FSFile.java:137) at
> org.tmatesoft.svn.core.internal.io.fs.FSFile.readInt(FSFile.java:101) at
> org.tmatesoft.svn.core.internal.io.fs.FSFS.openRoot(FSFS.java:237) at
> org.tmatesoft.svn.core.internal.io.fs.FSFS.open(FSFS.java:197) at
> org.tmatesoft.svn.core.internal.wc.SVNAdminHelper.openRepository(SVNAdminH
> elper.java:77) at
> org.tmatesoft.svn.core.wc.admin.SVNLookClient.open(SVNLookClient.java:1253
> ) at
> org.tmatesoft.svn.core.wc.admin.SVNLookClient.doGetLock(SVNLookClient.java
> :674) at
> org.tmatesoft.svn.core.internal.wc2.admin.SvnRepositoryGetLockImpl.run(Svn
> RepositoryGetLockImpl.java:16) at
> org.tmatesoft.svn.core.internal.wc2.admin.SvnRepositoryGetLockImpl.run(Svn
> RepositoryGetLockImpl.java:9) at
> org.tmatesoft.svn.core.internal.wc2.SvnOperationRunner.run(SvnOperationRun
> ner.java:20) at
> org.tmatesoft.svn.core.wc2.SvnOperationFactory.run(SvnOperationFactory.jav
> a:1235) at
> org.tmatesoft.svn.core.wc2.SvnOperation.run(SvnOperation.java:291) at
> com.iii.app.SvnSget.getLockOwner(SvnSget.java:127)
>         at com.iii.app.SvnSget.main(SvnSget.java:83)
> Caused by: java.io.FileNotFoundException: format (No such file or
> directory) at java.io.FileInputStream.open(Native Method)
>         at java.io.FileInputStream.<init>(Unknown Source)
>         at
> org.tmatesoft.svn.core.internal.wc.SVNFileUtil.createFileInputStream(SVNFi
> leUtil.java:1680) at
> org.tmatesoft.svn.core.internal.io.fs.FSFile.getChannel(FSFile.java:393)
> at org.tmatesoft.svn.core.internal.io.fs.FSFile.fill(FSFile.java:373) at
> org.tmatesoft.svn.core.internal.io.fs.FSFile.read(FSFile.java:295) at
> org.tmatesoft.svn.core.internal.io.fs.FSFile.readLine(FSFile.java:124) ...
> 13 more
> 
> So, how far off am I? Am I right to use SvnRepositoryGetLock, or should I
> be attacking this some other way?
> 
> Thanks for any help,
> 
>     Andy
> 
> 
> Andy Cohen
> Principal Software Engineer
> Product Development
> Innovative Interfaces, Inc.
> 5850 Shellmound Way
> Emeryville, CA 94608
> 
> [letter-t]  510-655-6200 Ext 4221
> [letter-e]  aco...@iii.com
> 
> [INNOIcon]<http://www.iii.com/>     [TwritterIcon]
> <https://twitter.com/iii_Innovative>      [FacebookIcon]
> <https://www.facebook.com/InnovativeInterfaces>

Reply via email to