Search in sources :

Example 16 with FileLocker

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

the class LocalMavenRepositoryTool method getArtifactIndexLines.

public Set<String> getArtifactIndexLines() throws IOException {
    File indexFile = getArtifactIndexFile();
    FileLocker locker = fileLockService.getFileLocker(indexFile);
    locker.lock();
    try {
        return readLines(indexFile);
    } finally {
        locker.release();
    }
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) File(java.io.File)

Example 17 with FileLocker

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

the class ProductExportMojo method unzipDirectory.

private void unzipDirectory(File source, String sourceRelPath, File target, String excludes) throws IOException {
    FileLocker locker = fileLockService.getFileLocker(source);
    locker.lock();
    try {
        ZipFile zip = new ZipFile(source);
        try {
            Enumeration<? extends ZipEntry> entries = zip.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.isDirectory()) {
                    continue;
                }
                String name = entry.getName();
                if (name.startsWith(sourceRelPath) && !SelectorUtils.matchPath(excludes, name)) {
                    File targetFile = new File(target, name.substring(sourceRelPath.length()));
                    targetFile.getParentFile().mkdirs();
                    FileUtils.copyStreamToFile(new RawInputStreamFacade(zip.getInputStream(entry)), targetFile);
                }
            }
        } finally {
            zip.close();
        }
    } finally {
        locker.release();
    }
}
Also used : FileLocker(org.eclipse.tycho.locking.facade.FileLocker) RawInputStreamFacade(org.codehaus.plexus.util.io.RawInputStreamFacade) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ZipFile(java.util.zip.ZipFile) File(java.io.File)

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