Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAT-397: Make project importable into Eclipse #410

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading