Search in sources :

Example 1 with FileLockService

use of org.eclipse.tycho.locking.facade.FileLockService 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();
    }
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) FileLockService(org.eclipse.tycho.locking.facade.FileLockService)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)1 ZipUnArchiver (org.codehaus.plexus.archiver.zip.ZipUnArchiver)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 FileLockService (org.eclipse.tycho.locking.facade.FileLockService)1 FileLocker (org.eclipse.tycho.locking.facade.FileLocker)1