abstract class AbstractProtocMojo extends AbstractMojo
This class is extended by ProtocCompileMojo
and
ProtocTestCompileMojo
in order to override the specific configuration for
compiling the main or test classes respectively.
Modifier and Type | Field and Description |
---|---|
protected boolean |
attachDescriptorSet
If set to
true , the generated descriptor set will be attached to the build. |
protected boolean |
attachProtoSources
If set to
true , then the specified protobuf source files from this project will be attached
as resources to the build, for subsequent inclusion into the final artifact. |
protected org.sonatype.plexus.build.incremental.BuildContext |
buildContext
Build context that tracks changes to the source and target files.
|
protected String |
descriptorSetFileName
The descriptor set file name.
|
protected boolean |
includeDependenciesInDescriptorSet
If
true and writeDescriptorSet has been set, the compiler will include
all dependencies in the descriptor set making it "self-contained". |
protected boolean |
includeSourceInfoInDescriptorSet
If
true and writeDescriptorSet has been set, do not strip SourceCodeInfo
from the FileDescriptorProto. |
protected MavenProject |
project
The current Maven project.
|
protected MavenProjectHelper |
projectHelper
A helper used to add resources to the project.
|
protected MavenSession |
session
The current Maven Session Object.
|
protected ToolchainManager |
toolchainManager
An optional tool chain manager.
|
protected boolean |
useArgumentFile
If set to
true , all command line arguments to protoc will be written to a file,
and only a path to that file will be passed to protoc on the command line. |
protected boolean |
writeDescriptorSet
If set to
true , the compiler will generate a binary descriptor set file for the
specified .proto files. |
Constructor and Description |
---|
AbstractProtocMojo() |
Modifier and Type | Method and Description |
---|---|
protected void |
addProtocBuilderParameters(Protoc.Builder protocBuilder)
Adds mojo-specific parameters to the protoc builder.
|
protected boolean |
checkFilesUpToDate(Iterable<File> sourceFiles,
Iterable<File> targetFiles)
Checks that the source files don't have modification time that is later than the target files.
|
protected void |
checkParameters() |
protected Artifact |
createDependencyArtifact(String artifactSpec)
Creates a dependency artifact from a specification in
groupId:artifactId:version[:type[:classifier]] format. |
protected Artifact |
createDependencyArtifact(String groupId,
String artifactId,
String version,
String type,
String classifier) |
protected void |
createProtocPlugins()
Generates native launchers for java protoc plugins.
|
protected String |
detectJavaHome()
Attempts to detect java home directory, using
jdk toolchain if available,
with a fallback to java.home system property. |
protected void |
doAttachFiles() |
protected abstract void |
doAttachGeneratedFiles() |
protected abstract void |
doAttachProtoSources() |
void |
execute()
Executes the mojo.
|
protected static List<File> |
findGeneratedFilesInDirectory(File directory) |
protected List<File> |
findProtoFilesInDirectories(Iterable<File> directories) |
protected List<File> |
findProtoFilesInDirectory(File directory) |
protected List<File> |
getDependencyArtifactFiles()
Gets the
File for each dependency artifact. |
protected abstract List<Artifact> |
getDependencyArtifacts() |
protected abstract File |
getDescriptorSetOutputDirectory()
Returns output directory for descriptor set file.
|
protected String[] |
getExcludes() |
protected String[] |
getIncludes() |
protected abstract File |
getOutputDirectory()
Returns the output directory for generated sources.
|
protected abstract File |
getProtoSourceRoot() |
protected boolean |
hasDelta(Iterable<File> files)
Checks if the injected build context has changes in any of the specified files.
|
protected static long |
lastModified(Iterable<File> files)
Returns timestamp for the most recently modified file in the given set.
|
protected List<File> |
makeProtoPathFromJars(File temporaryProtoFileDirectory,
Iterable<File> classpathElementFiles)
Unpacks proto descriptors that are bundled inside dependent artifacts into a temporary directory.
|
protected File |
resolveBinaryArtifact(Artifact artifact) |
protected boolean |
skipMojo()
Determine if the mojo execution should get skipped.
|
protected static String |
toHexString(byte[] byteArray) |
protected String |
truncatePath(String jarPath)
Truncates the path of jar files so that they are relative to the local repository.
|
getLog, getPluginContext, setLog, setPluginContext
@Parameter(defaultValue="${project}", readonly=true) protected MavenProject project
@Parameter(defaultValue="${session}", readonly=true) protected MavenSession session
@Component protected org.sonatype.plexus.build.incremental.BuildContext buildContext
@Component protected ToolchainManager toolchainManager
@Component protected MavenProjectHelper projectHelper
@Parameter(required=true, defaultValue="true") protected boolean attachProtoSources
true
, then the specified protobuf source files from this project will be attached
as resources to the build, for subsequent inclusion into the final artifact.
This is the default behaviour, as it allows downstream projects to import protobuf definitions
from the upstream projects, and those imports are automatically resolved at build time.
If distribution of .proto
source files is undesirable for security reasons
or because of other considerations, then this parameter should be set to false
.
@Parameter(required=true, defaultValue="${project.build.finalName}.protobin") protected String descriptorSetFileName
writeDescriptorSet
is set to true
.@Parameter(required=true, defaultValue="false") protected boolean writeDescriptorSet
true
, the compiler will generate a binary descriptor set file for the
specified .proto
files.@Parameter(required=true, defaultValue="false") protected boolean attachDescriptorSet
true
, the generated descriptor set will be attached to the build.@Parameter(required=false, defaultValue="false") protected boolean includeDependenciesInDescriptorSet
true
and writeDescriptorSet
has been set, the compiler will include
all dependencies in the descriptor set making it "self-contained".@Parameter(required=false, defaultValue="false") protected boolean includeSourceInfoInDescriptorSet
true
and writeDescriptorSet
has been set, do not strip SourceCodeInfo
from the FileDescriptorProto. This results in vastly larger descriptors that include information
about the original location of each decl in the source file as well as surrounding comments.@Parameter(required=false, defaultValue="false") protected boolean useArgumentFile
true
, all command line arguments to protoc will be written to a file,
and only a path to that file will be passed to protoc on the command line.
This helps prevent Command line is too long errors when the number of .proto
files is large.
NOTE: This is only supported for protoc 3.5.0 and higher.
public void execute() throws MojoExecutionException, MojoFailureException
protected void createProtocPlugins()
protected String detectJavaHome()
jdk
toolchain if available,
with a fallback to java.home
system property.protected void addProtocBuilderParameters(Protoc.Builder protocBuilder)
protocBuilder
- the builder to be modified.protected boolean skipMojo()
Determine if the mojo execution should get skipped.
This is the case if:skip
is true
forceMojoExecution
is false
true
if the mojo execution should be skipped.protected static List<File> findGeneratedFilesInDirectory(File directory)
protected static long lastModified(Iterable<File> files)
files
- a collection of file descriptors.protected boolean checkFilesUpToDate(Iterable<File> sourceFiles, Iterable<File> targetFiles)
sourceFiles
- a collection of source files.targetFiles
- a collection of target files.true
, if source files are not later than the target files; false
, otherwise.protected boolean hasDelta(Iterable<File> files)
files
- files to be checked for changes.true
, if at least one file has changes; false
, if no files have changes.protected void checkParameters()
protected abstract File getProtoSourceRoot()
protected String[] getIncludes()
protected String[] getExcludes()
protected abstract File getOutputDirectory()
protected abstract File getDescriptorSetOutputDirectory()
protected void doAttachFiles()
protected abstract void doAttachProtoSources()
protected abstract void doAttachGeneratedFiles()
protected List<File> getDependencyArtifactFiles()
File
for each dependency artifact.protected List<File> makeProtoPathFromJars(File temporaryProtoFileDirectory, Iterable<File> classpathElementFiles)
temporaryProtoFileDirectory
- temporary directory to serve as root for unpacked structure.classpathElementFiles
- classpath elements, can be either jar files or directories.protected List<File> findProtoFilesInDirectories(Iterable<File> directories)
protected String truncatePath(String jarPath)
jarPath
- the full path of a jar file.protected static String toHexString(byte[] byteArray)
protected Artifact createDependencyArtifact(String artifactSpec)
groupId:artifactId:version[:type[:classifier]]
format.artifactSpec
- artifact specification.Copyright © 2016–2018 Maven Protocol Buffers Plugin Authors. All rights reserved.