Skip to content

Commit

Permalink
NPE guard and error log. More robust files lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Jan 15, 2024
1 parent a64c831 commit 77bd34b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ protected void processDeviate(Deviate deviate, AbstractModule module, ProcessedD
}
break;
case "not-supported":
if (targetNode.eContainer() == null) {
processedModel.addProcessorError(moduleFileName(module), deviation.getReference(),
"Deviation target node has no apparent.");
break;
}
Object eGet = targetNode.eContainer().eGet(targetNode.eContainingFeature(), true);
if (eGet instanceof EList) {
((EList<?>) eGet).remove(targetNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ private static List<AbstractModule> loadModuleFileAndDependencies(List<String> m
if (!extensionProvider.getFileExtensions().isEmpty())
fileExts = extensionProvider.getFileExtensions();
}
loadAdditionalFiles(implicitLookup, rs, fileExts, false);
if(implicitLookup.canRead() && implicitLookup.isDirectory()) {
loadAdditionalFiles(implicitLookup, rs, fileExts, false);
}

// handle --path argument
if (paths != null) {
Expand All @@ -149,8 +151,9 @@ private static List<AbstractModule> loadModuleFileAndDependencies(List<String> m
System.err.println("Path " + folder.getAbsolutePath() + " doesn't exist. Skipped.");
} else if (!folder.isDirectory()) {
System.err.println("Path " + folder.getAbsolutePath() + " is not a directory. Skipped.");
} else {
loadAdditionalFiles(folder.getAbsoluteFile(), rs, fileExts, !noPathRecurse);
}
loadAdditionalFiles(folder.getAbsoluteFile(), rs, fileExts, !noPathRecurse);
}
}

Expand All @@ -174,14 +177,18 @@ private static List<AbstractModule> loadModuleFileAndDependencies(List<String> m

private static void loadAdditionalFiles(File parent, XtextResourceSet rs, Set<String> fileExtensions,
final boolean recursive) {
for (File file : parent.listFiles()) {
File[] files = parent.listFiles();
if(files == null) {
return;
}
for (File file : files) {
URI fileURI = URI.createFileURI(file.getAbsolutePath());
if (file.isFile() && fileExtensions.contains(fileURI.fileExtension())) {
if (rs.getResource(fileURI, false) == null) {
rs.getResource(fileURI, true);
}
}
if (recursive && file.isDirectory()) {
if (recursive && file.canRead() && file.isDirectory()) {
loadAdditionalFiles(file, rs, fileExtensions, recursive);
}
}
Expand Down

0 comments on commit 77bd34b

Please sign in to comment.