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);
}
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();
}
}
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);
}
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());
}
}
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());
}
}
Aggregations