Skip to content

Commit

Permalink
Merge pull request #410 from apache/feature/RAT-379
Browse files Browse the repository at this point in the history
RAT-397: Make project importable into Eclipse
  • Loading branch information
ottlinger authored Jan 12, 2025
2 parents 657ab37 + 2baba8a commit e886682
Showing 1 changed file with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,51 @@
*/

// Copy a set of resource files from the parent project to target/classes/META-INF,
// so that they become a part of the generated jar file. See RAT-379.
// so that they become a part of the generated jar file. See RAT-379 for details.

import java.io.FileNotFoundException;
import java.nio.file.attribute.FileTime;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption

final Path sourceDir = Paths.get("${sourceDir}")
final Path targetDir = Paths.get("${targetDir}")

final Path sourceDir = Paths.get("${sourceDir}");
final Path targetDir = Paths.get("${targetDir}");
if (!Files.isDirectory(sourceDir)) {
final String msg = "Source directory not found: " + sourceDir.toAbsolutePath();
log.error(msg);
throw new FileNotFoundException(msg);
final String msg = "Source directory not found: " + sourceDir.toAbsolutePath()
System.err.println(msg)
throw new FileNotFoundException(msg)
}
log.debug("copyResourcesFromParent: Using source directory " + sourceDir + ", resolved to " + sourceDir.toAbsolutePath());
log.debug("copyResourcesFromParent: Using target directory " + targetDir + ", resolved to " + targetDir.toAbsolutePath());
Files.createDirectories(targetDir);
for (StringTokenizer st = new StringTokenizer("${filesToCopy}", ","); st.hasMoreTokens(); ) {
final String token = st.nextToken();
final Path sourceFile = sourceDir.resolve(token);

// System.out.println("copyResourcesFromParent: Using source directory " + sourceDir + ", resolved to " + sourceDir.toAbsolutePath())
// System.out.println("copyResourcesFromParent: Using target directory " + targetDir + ", resolved to " + targetDir.toAbsolutePath())
Files.createDirectories(targetDir)

for (StringTokenizer st = new StringTokenizer("${filesToCopy}", ","); st.hasMoreTokens(); ) {
final String token = st.nextToken()
final Path sourceFile = sourceDir.resolve(token)
if (!Files.isRegularFile(sourceFile)) {
final String msg = "Source file " + token + " not found in source directory " + sourceDir;
log.error("copyResourcesFromParent: " + msg);
log.error("copyResourcesFromParent: A possible reason is, that you did clone only the apache-rat-core subproject from Git.");
throw new FileNotFoundException(msg);
final String msg = "Source file " + token + " not found in source directory " + sourceDir
System.err.println("copyResourcesFromParent: " + msg)
System.err.println("copyResourcesFromParent: A possible reason is, that you did clone only the apache-rat-core subproject from Git.")
throw new FileNotFoundException(msg)
}
final Path targetFile = targetDir.resolve(token);
final boolean replacing = Files.isRegularFile(targetFile);
final Path targetFile = targetDir.resolve(token)
final boolean replacing = Files.isRegularFile(targetFile)
if (replacing) {
final FileTime sourceTime = Files.getLastModifiedTime(sourceFile);
final FileTime targetTime = Files.getLastModifiedTime(targetFile);
if (sourceTime != null && targetTime != null && sourceTime.compareTo(targetTime) >= 0) {
log.debug("copyResourcesFromParent: Skipping source file "
+ sourceFile + ", because target file " + targetFile + " appears to be uptodate.");
continue;
final FileTime sourceTime = Files.getLastModifiedTime(sourceFile)
final FileTime targetTime = Files.getLastModifiedTime(targetFile)
if (sourceTime != null && targetTime != null && sourceTime >= targetTime) {
System.out.println("Skipping " + sourceFile + ", as target " + targetFile + " appears to be up-to-date already.")
continue
}
}
log.debug("copyResourcesFromParent: Copying source file " + sourceFile
+ " to target file " + targetFile);
System.out.println("Copying " + sourceFile
+ " to " + targetFile)
if (replacing) {
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING);
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING)
} else {
Files.copy(sourceFile, targetFile);
Files.copy(sourceFile, targetFile)
}
}

0 comments on commit e886682

Please sign in to comment.