@Test public void resolved_image_file_path_with_imagedir_not_found() { File imageFolder = TestResourcesLoader.assertTestFile("codeassist/include/test1/subfolder2"); Collection<AsciiDoctorMarker> errors = new ArrayList<>(); validatorToTest.validate(imageFolder, Collections.singleton(new AsciiDoctorFileReference("image::unknown.png", 1, 20, 20)),errors); assertEquals(1,errors.size()); }
public void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors) { if (errors == null) { return; } if (referenceBaseFileOrFolder == null) { return; } if (!referenceBaseFileOrFolder.exists()) { return; } File referenceBaseDirectory = referenceBaseFileOrFolder; if (!referenceBaseDirectory.isDirectory()) { referenceBaseDirectory = referenceBaseDirectory.getParentFile(); } for (AsciiDoctorFileReference reference : references) { String filePathAsString = reference.getFilePath(); Path referenceBaseDirPath = referenceBaseDirectory.toPath(); Path filePath = Paths.get(filePathAsString); File expectedFile = referenceBaseDirPath.resolve(filePath).toFile(); String problem = null; if (!expectedFile.exists()) { problem = ".. references not existing file:" + expectedFile.getAbsolutePath(); } else if (expectedFile.isDirectory()) { problem = ".. points to a directory not a file:" + expectedFile.getAbsolutePath(); } if (problem != null) { AsciiDoctorMarker marker = new AsciiDoctorMarker(reference.getPosition(), reference.getEnd(), ValidationConstants.VALIDATION_FAILED + reference.getTargetPrefix() + problem); errors.add(marker); } } }
AsciiDoctorFileReferenceValidator { public void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors) { if (errors == null) { return; } if (referenceBaseFileOrFolder == null) { return; } if (!referenceBaseFileOrFolder.exists()) { return; } File referenceBaseDirectory = referenceBaseFileOrFolder; if (!referenceBaseDirectory.isDirectory()) { referenceBaseDirectory = referenceBaseDirectory.getParentFile(); } for (AsciiDoctorFileReference reference : references) { String filePathAsString = reference.getFilePath(); Path referenceBaseDirPath = referenceBaseDirectory.toPath(); Path filePath = Paths.get(filePathAsString); File expectedFile = referenceBaseDirPath.resolve(filePath).toFile(); String problem = null; if (!expectedFile.exists()) { problem = ".. references not existing file:" + expectedFile.getAbsolutePath(); } else if (expectedFile.isDirectory()) { problem = ".. points to a directory not a file:" + expectedFile.getAbsolutePath(); } if (problem != null) { AsciiDoctorMarker marker = new AsciiDoctorMarker(reference.getPosition(), reference.getEnd(), ValidationConstants.VALIDATION_FAILED + reference.getTargetPrefix() + problem); errors.add(marker); } } } }
AsciiDoctorFileReferenceValidator { public void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors) { if (errors == null) { return; } if (referenceBaseFileOrFolder == null) { return; } if (!referenceBaseFileOrFolder.exists()) { return; } File referenceBaseDirectory = referenceBaseFileOrFolder; if (!referenceBaseDirectory.isDirectory()) { referenceBaseDirectory = referenceBaseDirectory.getParentFile(); } for (AsciiDoctorFileReference reference : references) { String filePathAsString = reference.getFilePath(); Path referenceBaseDirPath = referenceBaseDirectory.toPath(); Path filePath = Paths.get(filePathAsString); File expectedFile = referenceBaseDirPath.resolve(filePath).toFile(); String problem = null; if (!expectedFile.exists()) { problem = ".. references not existing file:" + expectedFile.getAbsolutePath(); } else if (expectedFile.isDirectory()) { problem = ".. points to a directory not a file:" + expectedFile.getAbsolutePath(); } if (problem != null) { AsciiDoctorMarker marker = new AsciiDoctorMarker(reference.getPosition(), reference.getEnd(), ValidationConstants.VALIDATION_FAILED + reference.getTargetPrefix() + problem); errors.add(marker); } } }  }
AsciiDoctorFileReferenceValidator { public void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors) { if (errors == null) { return; } if (referenceBaseFileOrFolder == null) { return; } if (!referenceBaseFileOrFolder.exists()) { return; } File referenceBaseDirectory = referenceBaseFileOrFolder; if (!referenceBaseDirectory.isDirectory()) { referenceBaseDirectory = referenceBaseDirectory.getParentFile(); } for (AsciiDoctorFileReference reference : references) { String filePathAsString = reference.getFilePath(); Path referenceBaseDirPath = referenceBaseDirectory.toPath(); Path filePath = Paths.get(filePathAsString); File expectedFile = referenceBaseDirPath.resolve(filePath).toFile(); String problem = null; if (!expectedFile.exists()) { problem = ".. references not existing file:" + expectedFile.getAbsolutePath(); } else if (expectedFile.isDirectory()) { problem = ".. points to a directory not a file:" + expectedFile.getAbsolutePath(); } if (problem != null) { AsciiDoctorMarker marker = new AsciiDoctorMarker(reference.getPosition(), reference.getEnd(), ValidationConstants.VALIDATION_FAILED + reference.getTargetPrefix() + problem); errors.add(marker); } } }  void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors); }
AsciiDoctorFileReferenceValidator { public void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors) { if (errors == null) { return; } if (referenceBaseFileOrFolder == null) { return; } if (!referenceBaseFileOrFolder.exists()) { return; } File referenceBaseDirectory = referenceBaseFileOrFolder; if (!referenceBaseDirectory.isDirectory()) { referenceBaseDirectory = referenceBaseDirectory.getParentFile(); } for (AsciiDoctorFileReference reference : references) { String filePathAsString = reference.getFilePath(); Path referenceBaseDirPath = referenceBaseDirectory.toPath(); Path filePath = Paths.get(filePathAsString); File expectedFile = referenceBaseDirPath.resolve(filePath).toFile(); String problem = null; if (!expectedFile.exists()) { problem = ".. references not existing file:" + expectedFile.getAbsolutePath(); } else if (expectedFile.isDirectory()) { problem = ".. points to a directory not a file:" + expectedFile.getAbsolutePath(); } if (problem != null) { AsciiDoctorMarker marker = new AsciiDoctorMarker(reference.getPosition(), reference.getEnd(), ValidationConstants.VALIDATION_FAILED + reference.getTargetPrefix() + problem); errors.add(marker); } } }  void validate(File referenceBaseFileOrFolder, Collection<AsciiDoctorFileReference> references, Collection<AsciiDoctorMarker> errors);  }