Class AbstractProtocMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.xolstice.maven.plugin.protobuf.AbstractProtocMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractProtocCompileMojo, AbstractProtocTestCompileMojo
abstract class AbstractProtocMojo
extends org.apache.maven.plugin.AbstractMojo
Abstract Mojo implementation.
This class is extended by ProtocCompileMojo and
ProtocTestCompileMojo in order to override the specific configuration for
compiling the main or test classes respectively.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIf set totrue, the generated descriptor set will be attached to the build.protected booleanIf set totrue, 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.BuildContextBuild context that tracks changes to the source and target files.protected StringThe descriptor set file name.protected booleanIftrueandwriteDescriptorSethas been set, the compiler will include all dependencies in the descriptor set making it "self-contained".protected booleanIftrueandwriteDescriptorSethas been set, do not strip SourceCodeInfo from the FileDescriptorProto.protected org.apache.maven.project.MavenProjectThe current Maven project.protected org.apache.maven.project.MavenProjectHelperA helper used to add resources to the project.protected org.apache.maven.execution.MavenSessionThe current Maven Session Object.protected org.apache.maven.toolchain.ToolchainManagerAn optional tool chain manager.protected booleanIf set totrue, 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 booleanIf set totrue, the compiler will generate a binary descriptor set file for the specified.protofiles.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddProtocBuilderParameters(Protoc.Builder protocBuilder) Adds mojo-specific parameters to the protoc builder.protected booleancheckFilesUpToDate(Iterable<File> sourceFiles, Iterable<File> targetFiles) Checks that the source files don't have modification time that is later than the target files.protected voidprotected org.apache.maven.artifact.ArtifactcreateDependencyArtifact(String artifactSpec) Creates a dependency artifact from a specification ingroupId:artifactId:version[:type[:classifier]]format.protected org.apache.maven.artifact.ArtifactcreateDependencyArtifact(String groupId, String artifactId, String version, String type, String classifier) protected voidGenerates native launchers for java protoc plugins.protected StringAttempts to detect java home directory, usingjdktoolchain if available, with a fallback tojava.homesystem property.protected voidprotected abstract voidprotected abstract voidvoidexecute()Executes the mojo.findGeneratedFilesInDirectory(File directory) findProtoFilesInDirectories(Iterable<File> directories) findProtoFilesInDirectory(File directory) Gets theFilefor each dependency artifact.protected abstract List<org.apache.maven.artifact.Artifact> protected abstract FileReturns output directory for descriptor set file.protected String[]protected String[]protected abstract FileReturns the output directory for generated sources.protected abstract Fileprotected booleanChecks if the injected build context has changes in any of the specified files.protected static longlastModified(Iterable<File> files) Returns timestamp for the most recently modified file in the given set.makeProtoPathFromJars(File temporaryProtoFileDirectory, Iterable<File> classpathElementFiles) Unpacks proto descriptors that are bundled inside dependent artifacts into a temporary directory.protected FileresolveBinaryArtifact(org.apache.maven.artifact.Artifact artifact) protected booleanskipMojo()Determine if the mojo execution should get skipped.protected static StringtoHexString(byte[] byteArray) protected StringtruncatePath(String jarPath) Truncates the path of jar files so that they are relative to the local repository.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
project
@Parameter(defaultValue="${project}", readonly=true) protected org.apache.maven.project.MavenProject projectThe current Maven project. -
session
@Parameter(defaultValue="${session}", readonly=true) protected org.apache.maven.execution.MavenSession sessionThe current Maven Session Object.- Since:
- 0.2.0
-
buildContext
@Component protected org.sonatype.plexus.build.incremental.BuildContext buildContextBuild context that tracks changes to the source and target files.- Since:
- 0.3.0
-
toolchainManager
@Component protected org.apache.maven.toolchain.ToolchainManager toolchainManagerAn optional tool chain manager.- Since:
- 0.2.0
-
projectHelper
@Component protected org.apache.maven.project.MavenProjectHelper projectHelperA helper used to add resources to the project. -
attachProtoSources
@Parameter(required=true, defaultValue="true") protected boolean attachProtoSourcesIf set totrue, 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
.protosource files is undesirable for security reasons or because of other considerations, then this parameter should be set tofalse.- Since:
- 0.4.1
-
descriptorSetFileName
@Parameter(required=true, defaultValue="${project.build.finalName}.protobin") protected String descriptorSetFileNameThe descriptor set file name. Only used ifwriteDescriptorSetis set totrue.- Since:
- 0.3.0
-
writeDescriptorSet
@Parameter(required=true, defaultValue="false") protected boolean writeDescriptorSetIf set totrue, the compiler will generate a binary descriptor set file for the specified.protofiles.- Since:
- 0.3.0
-
attachDescriptorSet
@Parameter(required=true, defaultValue="false") protected boolean attachDescriptorSetIf set totrue, the generated descriptor set will be attached to the build.- Since:
- 0.4.1
-
includeDependenciesInDescriptorSet
@Parameter(required=false, defaultValue="false") protected boolean includeDependenciesInDescriptorSetIftrueandwriteDescriptorSethas been set, the compiler will include all dependencies in the descriptor set making it "self-contained".- Since:
- 0.3.0
-
includeSourceInfoInDescriptorSet
@Parameter(required=false, defaultValue="false") protected boolean includeSourceInfoInDescriptorSetIftrueandwriteDescriptorSethas 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.- Since:
- 0.4.4
-
useArgumentFile
@Parameter(required=false, defaultValue="false") protected boolean useArgumentFileIf set totrue, 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.protofiles is large.NOTE: This is only supported for protoc 3.5.0 and higher.
- Since:
- 0.6.0
-
-
Constructor Details
-
AbstractProtocMojo
AbstractProtocMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionExecutes the mojo.- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
createProtocPlugins
protected void createProtocPlugins()Generates native launchers for java protoc plugins. These launchers will later be added as parameters for protoc compiler.- Since:
- 0.3.0
-
detectJavaHome
Attempts to detect java home directory, usingjdktoolchain if available, with a fallback tojava.homesystem property.- Returns:
- path to java home directory.
- Since:
- 0.3.0
-
addProtocBuilderParameters
Adds mojo-specific parameters to the protoc builder.- Parameters:
protocBuilder- the builder to be modified.
-
skipMojo
protected boolean skipMojo()Determine if the mojo execution should get skipped.
This is the case if:skipistrue- if the mojo gets executed on a project with packaging type 'pom' and
forceMojoExecutionisfalse
- Returns:
trueif the mojo execution should be skipped.- Since:
- 0.2.0
-
findGeneratedFilesInDirectory
-
lastModified
-
checkFilesUpToDate
Checks that the source files don't have modification time that is later than the target files.- Parameters:
sourceFiles- a collection of source files.targetFiles- a collection of target files.- Returns:
true, if source files are not later than the target files;false, otherwise.
-
hasDelta
-
checkParameters
protected void checkParameters() -
getProtoSourceRoot
-
getIncludes
-
getExcludes
-
getDependencyArtifacts
-
getOutputDirectory
Returns the output directory for generated sources. Depends on build phase so must be defined in concrete implementation.- Returns:
- output directory for generated sources.
-
getDescriptorSetOutputDirectory
Returns output directory for descriptor set file. Depends on build phase so must be defined in concrete implementation.- Returns:
- output directory for generated descriptor set.
- Since:
- 0.3.0
-
doAttachFiles
protected void doAttachFiles() -
doAttachProtoSources
protected abstract void doAttachProtoSources() -
doAttachGeneratedFiles
protected abstract void doAttachGeneratedFiles() -
getDependencyArtifactFiles
-
makeProtoPathFromJars
protected List<File> makeProtoPathFromJars(File temporaryProtoFileDirectory, Iterable<File> classpathElementFiles) Unpacks proto descriptors that are bundled inside dependent artifacts into a temporary directory. This is needed because protobuf compiler cannot handle imported descriptors that are packed inside jar files.- Parameters:
temporaryProtoFileDirectory- temporary directory to serve as root for unpacked structure.classpathElementFiles- classpath elements, can be either jar files or directories.- Returns:
- a list of import roots for protobuf compiler (these will all be subdirectories of the temporary directory).
-
findProtoFilesInDirectory
-
findProtoFilesInDirectories
-
truncatePath
-
toHexString
-
resolveBinaryArtifact
-
createDependencyArtifact
Creates a dependency artifact from a specification ingroupId:artifactId:version[:type[:classifier]]format.- Parameters:
artifactSpec- artifact specification.- Returns:
- artifact object instance.
-
createDependencyArtifact
-