use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class DefaultBundleReader method getEntry.
@Override
public File getEntry(File bundleLocation, String path) {
if (path.startsWith("external:")) {
getLogger().warn("Ignoring Bundle-ClassPath entry '" + path + "' of bundle " + bundleLocation);
return null;
}
final File result;
if (bundleLocation.isDirectory()) {
result = new File(bundleLocation, path);
} else {
try {
File outputDirectory = new File(cacheDir, bundleLocation.getName());
result = new File(outputDirectory, path);
String resultPath = result.getCanonicalPath();
if (extractedFiles.contains(resultPath) && result.exists()) {
return result;
} else {
FileLocker locker = fileLockService.getFileLocker(outputDirectory);
locker.lock(5 * 60 * 1000L);
try {
extractZipEntries(bundleLocation, path, outputDirectory);
} finally {
locker.release();
}
extractedFiles.add(resultPath);
}
} catch (IOException e) {
throw new RuntimeException("IOException while extracting '" + path + "' from " + bundleLocation, e);
}
}
if (result.exists()) {
return result;
} else {
getLogger().debug("Bundle-ClassPath entry " + path + " does not exist in " + bundleLocation);
return null;
}
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class FeatureXmlTransformer method getInstallSize.
protected long getInstallSize(File location) {
long installSize = 0;
FileLocker locker = fileLockService.getFileLocker(location);
locker.lock();
try {
try {
JarFile jar = new JarFile(location);
try {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
long entrySize = entry.getSize();
if (entrySize > 0) {
installSize += entrySize;
}
}
} finally {
jar.close();
}
} catch (IOException e) {
throw new RuntimeException("Could not determine installation size of file " + location, e);
}
} finally {
locker.release();
}
return installSize;
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class UpdateSiteAssembler method unpackJar.
private void unpackJar(File location, File outputJar) {
ZipUnArchiver unzip;
FileLockService fileLockService;
try {
unzip = (ZipUnArchiver) session.lookup(ZipUnArchiver.ROLE, "zip");
fileLockService = (FileLockService) session.lookup(FileLockService.class.getName());
} catch (ComponentLookupException e) {
throw new RuntimeException("Could not lookup required component", e);
}
outputJar.mkdirs();
if (!outputJar.isDirectory()) {
throw new RuntimeException("Could not create output directory " + outputJar.getAbsolutePath());
}
unzip.setSourceFile(location);
unzip.setDestDirectory(outputJar);
FileLocker locker = fileLockService.getFileLocker(location);
locker.lock();
try {
unzip.extract();
} catch (ArchiverException e) {
throw new RuntimeException("Could not unpack jar", e);
} finally {
locker.release();
}
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class PublishProductMojo method getExpandedLauncherBinaries.
private File getExpandedLauncherBinaries() throws MojoExecutionException, MojoFailureException {
// TODO 364134 take the executable feature from the target platform instead
DependencyArtifacts dependencyArtifacts = TychoProjectUtils.getDependencyArtifacts(getProject());
ArtifactDescriptor artifact = dependencyArtifacts.getArtifact(ArtifactType.TYPE_ECLIPSE_FEATURE, "org.eclipse.equinox.executable", null);
if (artifact == null) {
throw new MojoExecutionException("Unable to locate feature 'org.eclipse.equinox.executable'. This feature is required for native product launchers.");
}
checkMacOSLauncherCompatibility(artifact);
File equinoxExecFeature = artifact.getLocation();
if (equinoxExecFeature.isDirectory()) {
return equinoxExecFeature.getAbsoluteFile();
} else {
File unzipped = new File(getProject().getBuild().getDirectory(), artifact.getKey().getId() + "-" + artifact.getKey().getVersion());
if (unzipped.exists()) {
return unzipped.getAbsoluteFile();
}
try {
FileLocker locker = fileLockService.getFileLocker(equinoxExecFeature);
locker.lock();
try {
// unzip now then:
unzipped.mkdirs();
deflater.setSourceFile(equinoxExecFeature);
deflater.setDestDirectory(unzipped);
deflater.extract();
return unzipped.getAbsoluteFile();
} finally {
locker.release();
}
} catch (ArchiverException e) {
throw new MojoFailureException("Unable to unzip the eqiuinox executable feature", e);
}
}
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class FileLockServiceTest method testLockReentranceSameLocker.
@Test
public void testLockReentranceSameLocker() throws IOException {
FileLocker fileLocker = subject.getFileLocker(newTestFile());
fileLocker.lock();
try {
// locks are not re-entrant
fileLocker.lock(0L);
fail("lock already held by same VM but could be acquired a second time");
} catch (LockTimeoutException e) {
// expected
} finally {
fileLocker.release();
}
}
Aggregations