Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-10626] Ignore files that could not be read.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 19, 2011
1 parent 5c2a29c commit dd79186
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/main/java/hudson/plugins/tasks/parser/WorkspaceScanner.java
Expand Up @@ -136,28 +136,31 @@ public TasksParserResult invoke(final File workspace, final VirtualChannel chann
TasksParserResult javaProject = new TasksParserResult(files.length);
ModuleDetector moduleDetector = createModuleDetector(workspace);
for (String fileName : files) {
File originalFile = new File(workspace, fileName);
Collection<Task> tasks = taskScanner.scan(new InputStreamReader(new FilePath(originalFile).read(),
EncodingValidator.defaultCharset(defaultEncoding)));
if (!tasks.isEmpty()) {
String unixName = fileName.replace('\\', '/');
String packageName = PackageDetectors.detectPackage(unixName, new FilePath(originalFile).read());
String guessedModule = moduleDetector.guessModuleName(originalFile.getAbsolutePath());
String actualModule = StringUtils.defaultIfEmpty(moduleName, guessedModule);

for (Task task : tasks) {
task.setFileName(originalFile.getAbsolutePath());
task.setPackageName(packageName);
task.setModuleName(actualModule);
task.setPathName(workspace.getPath());

ContextHashCode hashCode = new ContextHashCode();
task.setContextHashCode(hashCode.create(originalFile.getAbsolutePath(), task.getPrimaryLineNumber(), defaultEncoding));
try {
File originalFile = new File(workspace, fileName);
Collection<Task> tasks = taskScanner.scan(readFile(originalFile));
if (!tasks.isEmpty()) {
String unixName = fileName.replace('\\', '/');
String packageName = PackageDetectors.detectPackage(unixName, new FilePath(originalFile).read());
String guessedModule = moduleDetector.guessModuleName(originalFile.getAbsolutePath());
String actualModule = StringUtils.defaultIfEmpty(moduleName, guessedModule);

for (Task task : tasks) {
task.setFileName(originalFile.getAbsolutePath());
task.setPackageName(packageName);
task.setModuleName(actualModule);
task.setPathName(workspace.getPath());

ContextHashCode hashCode = new ContextHashCode();
task.setContextHashCode(hashCode.create(originalFile.getAbsolutePath(), task.getPrimaryLineNumber(), defaultEncoding));
}

javaProject.addAnnotations(tasks);
}

javaProject.addAnnotations(tasks);
}

catch (IOException exception) {
// ignore files that could not be read
}
if (Thread.interrupted()) {
throw new InterruptedException("Canceling scanning since build has been aborted.");
}
Expand All @@ -166,6 +169,11 @@ public TasksParserResult invoke(final File workspace, final VirtualChannel chann
return javaProject;
}

private InputStreamReader readFile(final File originalFile) throws IOException {
return new InputStreamReader(new FilePath(originalFile).read(),
EncodingValidator.defaultCharset(defaultEncoding));
}

private ModuleDetector createModuleDetector(final File workspace) {
if (shouldDetectModules) {
return new ModuleDetector(workspace);
Expand Down

0 comments on commit dd79186

Please sign in to comment.