Skip to content

Commit

Permalink
Don't Fail codesnippet-maven-plugin when Sources Don't Exist (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft authored Jan 12, 2022
1 parent 5e9f60d commit 608fbc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/java-packages/codesnippet-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.azure.tools</groupId>
<artifactId>codesnippet-maven-plugin</artifactId>
<version>1.0.0-beta.4</version>
<version>1.0.0-beta.5</version>
<packaging>maven-plugin</packaging>

<name>Codesnippet Maven Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,41 +138,47 @@ private static void runCodesnippets(Path codesnippetRootDirectory, String codesn
return;
}

// Get the files that match the codesnippet glob and are contained in the codesnippet root directory.
List<Path> codesnippetFiles = globFiles(codesnippetRootDirectory, codesnippetGlob, false);

// Only get the source files if sources are included in the update.
List<Path> sourceFiles = Collections.emptyList();
if (includeSources) {
if (includeSources && sourcesRootDirectory.toFile().exists()) {
// Get the files that match the sources glob and are contained in the sources root directory.
sourceFiles = globFiles(sourcesRootDirectory, sourcesGlob, true);
}

// Only get the README files if READMEs are included in the update.
List<Path> readmeFiles = Collections.emptyList();
if (includeReadme && readmeRootDirectory.toFile().exists()) {
readmeFiles = globFiles(readmeRootDirectory, readmeGlob, true);
}

if (sourceFiles.isEmpty() && readmeFiles.isEmpty()) {
logger.info("No files to update.");
return;
}

// Get the files that match the codesnippet glob and are contained in the codesnippet root directory.
List<Path> codesnippetFiles = globFiles(codesnippetRootDirectory, codesnippetGlob, false);

// scan the sample files for all the snippet files
Map<String, Codesnippet> foundSnippets = getAllSnippets(codesnippetFiles);

List<CodesnippetError> errors = new ArrayList<>();

// walk across all the java files, run UpdateSrcSnippets
if (includeSources) {
for (Path sourcePath : sourceFiles) {
if (mode == ExecutionMode.UPDATE) {
errors.addAll(updateSourceCodeSnippets(sourcePath, foundSnippets, maxLineLength));
} else {
errors.addAll(verifySourceCodeSnippets(sourcePath, foundSnippets, maxLineLength));
}
// Updates all source files.
for (Path sourcePath : sourceFiles) {
if (mode == ExecutionMode.UPDATE) {
errors.addAll(updateSourceCodeSnippets(sourcePath, foundSnippets, maxLineLength));
} else {
errors.addAll(verifySourceCodeSnippets(sourcePath, foundSnippets, maxLineLength));
}
}

// now find folderToVerify/README.md
// run Update ReadmeSnippets on that
if (includeReadme) {
for (Path readmeFile : globFiles(readmeRootDirectory, readmeGlob, true)) {
if (mode == ExecutionMode.UPDATE) {
errors.addAll(updateReadmeCodesnippets(readmeFile, foundSnippets));
} else {
errors.addAll(verifyReadmeCodesnippets(readmeFile, foundSnippets));
}
// Update all README files.
for (Path readmeFile : readmeFiles) {
if (mode == ExecutionMode.UPDATE) {
errors.addAll(updateReadmeCodesnippets(readmeFile, foundSnippets));
} else {
errors.addAll(verifyReadmeCodesnippets(readmeFile, foundSnippets));
}
}

Expand Down

0 comments on commit 608fbc3

Please sign in to comment.