Search in sources :

Example 11 with FileLocker

use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.

the class FileLockServiceTest method testNegativeTimeout.

@Test(expected = IllegalArgumentException.class)
public void testNegativeTimeout() throws IOException {
    FileLocker fileLocker = subject.getFileLocker(newTestFile());
    fileLocker.lock(-1L);
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) Test(org.junit.Test)

Example 12 with FileLocker

use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.

the class FileLockServiceTest method testLockReentranceDifferentLocker.

@Test
public void testLockReentranceDifferentLocker() throws IOException {
    final File testFile = newTestFile();
    FileLocker fileLocker1 = subject.getFileLocker(testFile);
    FileLocker fileLocker2 = subject.getFileLocker(testFile);
    // same file but different locker objects
    assertNotSame(fileLocker1, fileLocker2);
    fileLocker1.lock();
    try {
        fileLocker2.lock(0L);
        fail("lock already held by same VM but could be acquired a second time");
    } catch (LockTimeoutException e) {
    // expected
    } finally {
        fileLocker1.release();
    }
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) File(java.io.File) LockTimeoutException(org.eclipse.tycho.locking.facade.LockTimeoutException) Test(org.junit.Test)

Example 13 with FileLocker

use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.

the class FileLockServiceTest method testReuseLockerObject.

@Test
public void testReuseLockerObject() throws IOException {
    FileLocker fileLocker = subject.getFileLocker(newTestFile());
    lockAndRelease(fileLocker);
    lockAndRelease(fileLocker);
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) Test(org.junit.Test)

Example 14 with FileLocker

use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.

the class FileLockServiceTest method testIsLocked.

@Test
public void testIsLocked() throws IOException {
    FileLocker fileLocker = subject.getFileLocker(newTestFile());
    assertFalse(fileLocker.isLocked());
    fileLocker.lock();
    try {
        assertTrue(fileLocker.isLocked());
    } finally {
        fileLocker.release();
        assertFalse(fileLocker.isLocked());
    }
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) Test(org.junit.Test)

Example 15 with FileLocker

use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.

the class TychoOsgiRuntimeLocator method addRuntimeArtifact.

private void addRuntimeArtifact(EquinoxRuntimeDescription description, MavenSession session, Dependency dependency) throws MavenExecutionException {
    Artifact artifact = resolveDependency(session, dependency);
    if ("zip".equals(dependency.getType())) {
        File artifactFile = new File(session.getLocalRepository().getBasedir(), session.getLocalRepository().pathOf(artifact));
        File eclipseDir = new File(artifactFile.getParentFile(), "eclipse");
        FileLocker locker = fileLockService.getFileLocker(artifactFile);
        locker.lock();
        try {
            if (!eclipseDir.exists() || artifact.isSnapshot()) {
                logger.debug("Extracting Tycho's OSGi runtime");
                if (artifact.getFile().lastModified() > eclipseDir.lastModified()) {
                    logger.debug("Unpacking Tycho's OSGi runtime to " + eclipseDir);
                    try {
                        FileUtils.deleteDirectory(eclipseDir);
                    } catch (IOException e) {
                        logger.warn("Failed to delete Tycho's OSGi runtime " + eclipseDir + ": " + e.getMessage());
                    }
                    unArchiver.setSourceFile(artifact.getFile());
                    unArchiver.setDestDirectory(eclipseDir.getParentFile());
                    try {
                        unArchiver.extract();
                    } catch (ArchiverException e) {
                        throw new MavenExecutionException("Failed to unpack Tycho's OSGi runtime: " + e.getMessage(), e);
                    }
                    eclipseDir.setLastModified(artifact.getFile().lastModified());
                }
            }
        } finally {
            locker.release();
        }
        description.addInstallation(eclipseDir);
    } else {
        description.addBundle(artifact.getFile());
    }
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) MavenExecutionException(org.apache.maven.MavenExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

FileLocker (org.eclipse.tycho.locking.facade.FileLocker)17 File (java.io.File)9 Test (org.junit.Test)9 IOException (java.io.IOException)3 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)3 LockTimeoutException (org.eclipse.tycho.locking.facade.LockTimeoutException)3 JarFile (java.util.jar.JarFile)2 ZipFile (java.util.zip.ZipFile)2 Random (java.util.Random)1 JarEntry (java.util.jar.JarEntry)1 ZipEntry (java.util.zip.ZipEntry)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1 Artifact (org.apache.maven.artifact.Artifact)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 ZipUnArchiver (org.codehaus.plexus.archiver.zip.ZipUnArchiver)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 RawInputStreamFacade (org.codehaus.plexus.util.io.RawInputStreamFacade)1 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)1