Package org.cyclonedx.maven
Class BaseCycloneDxMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.cyclonedx.maven.BaseCycloneDxMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo,org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
- Direct Known Subclasses:
CycloneDxAggregateMojo,CycloneDxMojo,CycloneDxPackageMojo
public abstract class BaseCycloneDxMojo extends org.apache.maven.plugin.AbstractMojo implements org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerdependencyAnalyzerDependencyAnalyzerprotected String[]excludeArtifactIdprotected BooleanexcludeTestProjectprotected static StringMESSAGE_CALCULATING_HASHESprotected static StringMESSAGE_CREATING_BOMprotected static StringMESSAGE_RESOLVING_DEPSVarious messages sent to console.protected static StringMESSAGE_VALIDATING_BOMprotected static StringMESSAGE_VALIDATION_FAILUREprotected static StringMESSAGE_WRITING_BOM
-
Constructor Summary
Constructors Constructor Description BaseCycloneDxMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddMavenProjectsAsDependencies(List<org.apache.maven.project.MavenProject> reactorProjects, Set<org.cyclonedx.model.Dependency> dependencies)protected Set<org.cyclonedx.model.Dependency>buildDependencyGraph(Set<String> componentRefs, org.apache.maven.project.MavenProject mavenProject)voidcontextualize(org.codehaus.plexus.context.Context theContext)protected org.cyclonedx.model.Componentconvert(org.apache.maven.artifact.Artifact artifact)Converts a Maven artifact (dependency or transitive dependency) into a CycloneDX component./protected org.cyclonedx.model.Metadataconvert(org.apache.maven.project.MavenProject project)Converts a MavenProject into a Metadata object.protected org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzercreateProjectDependencyAnalyzer()protected voidexecute(Set<org.cyclonedx.model.Component> components, Set<org.cyclonedx.model.Dependency> dependencies, org.apache.maven.project.MavenProject mavenProject)protected org.cyclonedx.model.Component.ScopegetComponentScope(org.cyclonedx.model.Component component, org.apache.maven.artifact.Artifact artifact, org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis dependencyAnalysis)Method to identify component scope based on dependency analysisString[]getExcludeArtifactId()Returns if excluded ArtifactId are defined.protected BooleangetExcludeTestProject()Returns if project artifactId with the word test should be excluded in bom.String[]getExcludeTypes()Returns if excluded types are defined.BooleangetIncludeBomSerialNumber()Returns if the resulting BOM should contain a unique serial number.protected BooleangetIncludeCompileScope()Returns if compile scoped artifacts should be included in bom.BooleangetIncludeLicenseText()Returns if license text should be included in bom.protected BooleangetIncludeProvidedScope()Returns if provided scoped artifacts should be included in bom.protected BooleangetIncludeRuntimeScope()Returns if runtime scoped artifacts should be included in bom.protected BooleangetIncludeSystemScope()Returns if system scoped artifacts should be included in bom.protected BooleangetIncludeTestScope()Returns if test scoped artifacts should be included in bom.StringgetOutputFormat()Returns the CycloneDX output format that should be generated.StringgetOutputName()Returns the CycloneDX output name that should be generated.protected org.apache.maven.project.MavenProjectgetProject()Returns a reference to the current project.protected List<org.apache.maven.project.MavenProject>getReactorProjects()Returns the list of Maven Projects in this build.StringgetSchemaVersion()Returns the CycloneDX schema version the BOM will comply with.org.apache.maven.execution.MavenSessiongetSession()protected BooleangetSkip()Returns if CycloneDX execution should be skipped.protected voidlogParameters()protected org.cyclonedx.CycloneDxSchema.VersionschemaVersion()Resolves the CycloneDX schema the mojo has been requested to use.protected booleanshouldInclude(org.apache.maven.artifact.Artifact artifact)-
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
-
-
-
Field Detail
-
excludeArtifactId
@Parameter(property="excludeArtifactId", required=false) protected String[] excludeArtifactId
-
excludeTestProject
@Parameter(property="excludeTestProject", defaultValue="false", required=false) protected Boolean excludeTestProject
-
MESSAGE_RESOLVING_DEPS
protected static final String MESSAGE_RESOLVING_DEPS
Various messages sent to console.- See Also:
- Constant Field Values
-
MESSAGE_CREATING_BOM
protected static final String MESSAGE_CREATING_BOM
- See Also:
- Constant Field Values
-
MESSAGE_CALCULATING_HASHES
protected static final String MESSAGE_CALCULATING_HASHES
- See Also:
- Constant Field Values
-
MESSAGE_WRITING_BOM
protected static final String MESSAGE_WRITING_BOM
- See Also:
- Constant Field Values
-
MESSAGE_VALIDATING_BOM
protected static final String MESSAGE_VALIDATING_BOM
- See Also:
- Constant Field Values
-
MESSAGE_VALIDATION_FAILURE
protected static final String MESSAGE_VALIDATION_FAILURE
- See Also:
- Constant Field Values
-
dependencyAnalyzer
protected org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer dependencyAnalyzer
DependencyAnalyzer
-
-
Method Detail
-
getSession
public org.apache.maven.execution.MavenSession getSession()
-
getProject
protected org.apache.maven.project.MavenProject getProject()
Returns a reference to the current project. This method is used instead of auto-binding the project via component annotation in concrete implementations of this. If the child has a@Component MavenProject project;defined then the abstract class (i.e. this class) will not have access to the current project (just the way Maven works with the binding).- Returns:
- returns a reference to the current project
-
getReactorProjects
protected List<org.apache.maven.project.MavenProject> getReactorProjects()
Returns the list of Maven Projects in this build.- Returns:
- the list of Maven Projects in this build
-
getSchemaVersion
public String getSchemaVersion()
Returns the CycloneDX schema version the BOM will comply with.- Returns:
- the CycloneDX schema version
-
getOutputFormat
public String getOutputFormat()
Returns the CycloneDX output format that should be generated.- Returns:
- the CycloneDX output format
-
getOutputName
public String getOutputName()
Returns the CycloneDX output name that should be generated.- Returns:
- the CycloneDX output name
-
getIncludeBomSerialNumber
public Boolean getIncludeBomSerialNumber()
Returns if the resulting BOM should contain a unique serial number.- Returns:
- true if serial number should be included, otherwise false
-
getIncludeCompileScope
protected Boolean getIncludeCompileScope()
Returns if compile scoped artifacts should be included in bom.- Returns:
- true if artifact should be included, otherwise false
-
getIncludeProvidedScope
protected Boolean getIncludeProvidedScope()
Returns if provided scoped artifacts should be included in bom.- Returns:
- true if artifact should be included, otherwise false
-
getIncludeRuntimeScope
protected Boolean getIncludeRuntimeScope()
Returns if runtime scoped artifacts should be included in bom.- Returns:
- true if artifact should be included, otherwise false
-
getIncludeTestScope
protected Boolean getIncludeTestScope()
Returns if test scoped artifacts should be included in bom.- Returns:
- true if artifact should be included, otherwise false
-
getIncludeSystemScope
protected Boolean getIncludeSystemScope()
Returns if system scoped artifacts should be included in bom.- Returns:
- true if artifact should be included, otherwise false
-
getIncludeLicenseText
public Boolean getIncludeLicenseText()
Returns if license text should be included in bom.- Returns:
- true if license text should be included, otherwise false
-
getExcludeTypes
public String[] getExcludeTypes()
Returns if excluded types are defined.- Returns:
- an array of excluded types
-
getExcludeArtifactId
public String[] getExcludeArtifactId()
Returns if excluded ArtifactId are defined.- Returns:
- an array of excluded Artifact Id
-
getExcludeTestProject
protected Boolean getExcludeTestProject()
Returns if project artifactId with the word test should be excluded in bom.- Returns:
- true if artifactId should be excluded, otherwise false
-
getSkip
protected Boolean getSkip()
Returns if CycloneDX execution should be skipped.- Returns:
- true if execution should be skipped, otherwise false
-
shouldInclude
protected boolean shouldInclude(org.apache.maven.artifact.Artifact artifact)
-
convert
protected org.cyclonedx.model.Metadata convert(org.apache.maven.project.MavenProject project)
Converts a MavenProject into a Metadata object.- Parameters:
project- the MavenProject to convert- Returns:
- a CycloneDX Metadata object
-
convert
protected org.cyclonedx.model.Component convert(org.apache.maven.artifact.Artifact artifact)
Converts a Maven artifact (dependency or transitive dependency) into a CycloneDX component./- Parameters:
artifact- the artifact to convert- Returns:
- a CycloneDX component
-
execute
protected void execute(Set<org.cyclonedx.model.Component> components, Set<org.cyclonedx.model.Dependency> dependencies, org.apache.maven.project.MavenProject mavenProject) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
schemaVersion
protected org.cyclonedx.CycloneDxSchema.Version schemaVersion()
Resolves the CycloneDX schema the mojo has been requested to use.- Returns:
- the CycloneDX schema to use
-
buildDependencyGraph
protected Set<org.cyclonedx.model.Dependency> buildDependencyGraph(Set<String> componentRefs, org.apache.maven.project.MavenProject mavenProject) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
addMavenProjectsAsDependencies
protected void addMavenProjectsAsDependencies(List<org.apache.maven.project.MavenProject> reactorProjects, Set<org.cyclonedx.model.Dependency> dependencies)
-
logParameters
protected void logParameters()
-
contextualize
public void contextualize(org.codehaus.plexus.context.Context theContext) throws org.codehaus.plexus.context.ContextException- Specified by:
contextualizein interfaceorg.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable- Throws:
org.codehaus.plexus.context.ContextException
-
createProjectDependencyAnalyzer
protected org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer createProjectDependencyAnalyzer() throws org.apache.maven.plugin.MojoExecutionException- Returns:
ProjectDependencyAnalyzer- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of an error.
-
getComponentScope
protected org.cyclonedx.model.Component.Scope getComponentScope(org.cyclonedx.model.Component component, org.apache.maven.artifact.Artifact artifact, org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis dependencyAnalysis)Method to identify component scope based on dependency analysis- Parameters:
component- Componentartifact- Artifact from maven projectdependencyAnalysis- Dependency analysis data- Returns:
- Component.Scope - Required: If the component is used. Optional: If it is unused
-
-