use of java.nio.file.NoSuchFileException in project archiva by apache.
the class DuplicateArtifactsConsumerTest method testConsumerArtifactFileNotExist.
@Test
public void testConsumerArtifactFileNotExist() throws Exception {
consumer.beginScan(config, new Date());
try {
consumer.processFile("com/example/test/test-artifact/2.0/test-artifact-2.0.jar");
fail("Should have failed to find file");
} catch (ConsumerException e) {
assertTrue(e.getCause() instanceof NoSuchFileException);
} finally {
consumer.completeScan();
}
verify(metadataRepository, never()).addMetadataFacet(eq(TEST_REPO), Matchers.<MetadataFacet>anyObject());
}
use of java.nio.file.NoSuchFileException in project archiva by apache.
the class DefaultFileLockManager method writeFileLock.
@Override
public Lock writeFileLock(Path file) throws FileLockException, FileLockTimeoutException {
if (skipLocking) {
return new Lock(file);
}
try {
mkdirs(file.getParent());
} catch (IOException e) {
throw new FileLockException("Could not create directory " + file.getParent(), e);
}
StopWatch stopWatch = new StopWatch();
boolean acquired = false;
Lock lock = null;
stopWatch.start();
while (!acquired) {
// Make sure that not a bad lock is returned, if a exception was thrown.
lock = null;
if (timeout > 0) {
long delta = stopWatch.getTime();
log.debug("delta {}, timeout {}", delta, timeout);
if (delta > timeout) {
log.warn("Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file);
// we could not get the lock within the timeout period, so throw FileLockTimeoutException
throw new FileLockTimeoutException();
}
}
Lock current = lockFiles.get(file);
try {
if (current != null) {
log.trace("write lock file exist continue wait");
continue;
}
lock = new Lock(file, true);
createNewFileQuietly(file);
lock.openLock(true, timeout > 0);
// We are not returning an existing lock. If the lock is not
// exclusive, another thread may release the lock and the client
// knows nothing about it.
// The only atomic operation is the putIfAbsent operation, so if
// this returns null everything is OK, otherwise we should start at
// the beginning.
current = lockFiles.putIfAbsent(file, lock);
if (current == null) {
// Success
acquired = true;
} else {
// We try again
lock.close();
lock = null;
}
} catch (FileNotFoundException | NoSuchFileException e) {
log.debug("write Lock skip: {} try to create file", e.getMessage());
createNewFileQuietly(file);
} catch (IOException e) {
throw new FileLockException(e.getMessage(), e);
} catch (IllegalStateException e) {
log.trace("openLock {}:{}", e.getClass(), e.getMessage());
}
}
return lock;
}
use of java.nio.file.NoSuchFileException in project archiva by apache.
the class DefaultFileLockManager method readFileLock.
@Override
public Lock readFileLock(Path file) throws FileLockException, FileLockTimeoutException {
if (skipLocking) {
return new Lock(file);
}
StopWatch stopWatch = new StopWatch();
boolean acquired = false;
try {
mkdirs(file.getParent());
} catch (IOException e) {
throw new FileLockException("Could not create directories " + file.getParent(), e);
}
Lock lock = null;
stopWatch.start();
while (!acquired) {
// Make sure that not a bad lock is returned, if a exception was thrown.
lock = null;
if (timeout > 0) {
long delta = stopWatch.getTime();
log.debug("delta {}, timeout {}", delta, timeout);
if (delta > timeout) {
log.warn("Cannot acquire read lock within {} millis. Will skip the file: {}", timeout, file);
// we could not get the lock within the timeout period, so throw FileLockTimeoutException
throw new FileLockTimeoutException();
}
}
Lock current = lockFiles.get(file);
if (current != null) {
log.trace("read lock file exist continue wait");
continue;
}
try {
lock = new Lock(file, false);
createNewFileQuietly(file);
lock.openLock(false, timeout > 0);
// We are not returning an existing lock. If the lock is not
// exclusive, another thread may release the lock and the client
// knows nothing about it.
// The only atomic operation is the putIfAbsent operation, so if
// this returns null everything is OK, otherwise we should start at
// the beginning.
current = lockFiles.putIfAbsent(file, lock);
if (current == null) {
// Success
acquired = true;
} else {
// We try again
lock.close();
lock = null;
}
} catch (FileNotFoundException | NoSuchFileException e) {
log.debug("read Lock skip: {} try to create file", e.getMessage());
createNewFileQuietly(file);
} catch (IOException e) {
throw new FileLockException(e.getMessage(), e);
} catch (IllegalStateException e) {
log.trace("openLock {}:{}", e.getClass(), e.getMessage());
}
}
return lock;
}
use of java.nio.file.NoSuchFileException in project Bytecoder by mirkosertic.
the class ModulePath method scan.
/**
* Scan the given module path entry. If the entry is a directory then it is
* a directory of modules or an exploded module. If the entry is a regular
* file then it is assumed to be a packaged module.
*
* @throws FindException if an error occurs scanning the entry
*/
private Map<String, ModuleReference> scan(Path entry) {
BasicFileAttributes attrs;
try {
attrs = Files.readAttributes(entry, BasicFileAttributes.class);
} catch (NoSuchFileException e) {
return Collections.emptyMap();
} catch (IOException ioe) {
throw new FindException(ioe);
}
try {
if (attrs.isDirectory()) {
Path mi = entry.resolve(MODULE_INFO);
if (!Files.exists(mi)) {
// assume a directory of modules
return scanDirectory(entry);
}
}
// packaged or exploded module
ModuleReference mref = readModule(entry, attrs);
if (mref != null) {
String name = mref.descriptor().name();
return Collections.singletonMap(name, mref);
}
// not recognized
String msg;
if (!isLinkPhase && entry.toString().endsWith(".jmod")) {
msg = "JMOD format not supported at execution time";
} else {
msg = "Module format not recognized";
}
throw new FindException(msg + ": " + entry);
} catch (IOException ioe) {
throw new FindException(ioe);
}
}
use of java.nio.file.NoSuchFileException in project Bytecoder by mirkosertic.
the class JrtFileSystem method checkNode.
Node checkNode(JrtPath path) throws IOException {
ensureOpen();
String p = path.getResolvedPath();
Node node = lookup(p);
if (node == null) {
node = lookupSymbolic(p);
if (node == null) {
throw new NoSuchFileException(p);
}
}
return node;
}
Aggregations