Assert.assertNotNull("transformer", transformer);
long lastModified;
if (!source.exists()) {
throw new InjectionException("source file does not exist : " + source);
}
LOG.debug("source exists");
if (source.isDirectory()) {
throw new InjectionException("source file is a directory : " + source);
}
LOG.debug("source is real file (not dir)");
if (source.canRead() == false) {
throw new InjectionException("source file can not be read (check permissions): " + source);
}
LOG.debug("source can be read");
lastModified = source.lastModified();
if (target.exists()) {
LOG.debug("target exists " + target.getAbsolutePath());
if (forceOverwrite == false) {
throw new InjectionException("target exists and forceOverwrite is disabled : " + source);
}
if (target.isDirectory()) {
throw new InjectionException("target is directory : " + target);
}
if (target.canWrite() == false) {
throw new InjectionException("unable to write to target (check permissions) : " + target);
}
// newer is bigger
if (target.lastModified() > source.lastModified()) {
// target is newer than source
if (!overwriteNewer) {
throw new InjectionException("target is newer than source and overwriteNewer is disabled : "
+ source);
}
}
processUsingSwapFile(transformer, options, source, target);