Skip to content

Commit

Permalink
Merge pull request #115 from ascopes/feature/fail-on-missing-sources
Browse files Browse the repository at this point in the history
Default to failing on missing sources.
  • Loading branch information
ascopes authored Mar 9, 2024
2 parents 3ac2424 + b2c0f33 commit 6181a0b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/it/java-main-empty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<version>@project.version@</version>

<configuration>
<failOnMissingSources>false</failOnMissingSources>
<protocVersion>${protobuf.version}</protocVersion>
</configuration>

Expand Down
1 change: 1 addition & 0 deletions src/it/java-test-empty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<version>@project.version@</version>

<configuration>
<failOnMissingSources>false</failOnMissingSources>
<protocVersion>${protobuf.version}</protocVersion>
</configuration>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ public abstract class AbstractGenerateMojo extends AbstractMojo {
@Parameter
private @Nullable Path outputDirectory;

/**
* Whether to fail on missing sources.
*
* <p>If no sources are detected, it is usually a sign that this plugin
* is misconfigured, or that you are including this plugin in a project
* that does not need it. For this reason, the plugin defaults this setting
* to being enabled. If you wish to not fail, you can explicitly set this
* to false instead.
*
* @since 0.5.0
*/
@Parameter(defaultValue = "true")
private boolean failOnMissingSources;

/**
* Specify that any warnings emitted by {@code protoc} should be treated as errors and fail the
* build.
Expand Down Expand Up @@ -291,11 +305,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {

var request = ImmutableGenerationRequest.builder()
.additionalImportPaths(nonNullList(additionalImportPaths))
.allowedDependencyScopes(allowedScopes())
.binaryMavenPlugins(nonNullList(binaryMavenPlugins))
.binaryPathPlugins(nonNullList(binaryPathPlugins))
.binaryUrlPlugins(nonNullList(binaryUrlPlugins))
.jvmMavenPlugins(nonNullList(jvmMavenPlugins))
.allowedDependencyScopes(allowedScopes())
.isFailOnMissingSources(failOnMissingSources)
.isFatalWarnings(fatalWarnings)
.isJavaEnabled(javaEnabled)
.isKotlinEnabled(kotlinEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public interface GenerationRequest {

SourceRootRegistrar getSourceRootRegistrar();

boolean isFailOnMissingSources();

boolean isFatalWarnings();

boolean isJavaEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ public boolean generate(GenerationRequest request) throws ResolutionException, I
var sourcePaths = discoverCompilableSources(request);

if (sourcePaths.isEmpty()) {
// We might want to add the ability to throw an error here in the future.
// For now, let's just avoid doing additional work. This also prevents protobuf
// failing because we provided no sources to it.
log.info("No protobuf sources found; nothing to do!");
return true;
if (request.isFailOnMissingSources()) {
log.error("No protobuf sources found. If this is unexpected, check your "
+ "configuration and try again.");
return false;
} else {
log.info("No protobuf sources found; nothing to do!");
return true;
}
}

createOutputDirectories(request);
Expand Down

0 comments on commit 6181a0b

Please sign in to comment.