Package org.apache.maven.plugins.install
Class InstallFileMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.install.InstallFileMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="install-file", requiresProject=false, aggregator=true, threadSafe=true) public class InstallFileMojo extends org.apache.maven.plugin.AbstractMojoInstalls a file in the local repository.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringartifactIdArtifactId of the artifact to be installed.private java.lang.StringclassifierClassifier type of the artifact to be installed.private static java.util.regex.PatternENCODING_PSEUDO_ATTRTheencodingpseudo-attribute of an XML declaration.private java.lang.StringextensionExtension of the artifact to be installed.private java.io.FilefileThe file to be installed in the local repository.private java.lang.BooleangeneratePomGenerate a minimal POM for the artifact if none is supplied via the parameterpomFile.private java.lang.StringgroupIdGroupId of the artifact to be installed.private static java.lang.StringILLEGAL_VERSION_CHARSprivate static java.util.function.Predicate<java.lang.String>IS_EMPTYprivate static java.util.function.Predicate<java.util.jar.JarEntry>IS_POM_ENTRYprivate static java.util.function.Predicate<java.lang.String>IS_POM_PACKAGINGprivate java.io.FilejavadocThe bundled API docs for the artifact.private java.io.FilelocalRepositoryPathThe path for a specific local repository directory.private org.slf4j.Loggerlogprivate static java.lang.StringLSprivate java.lang.StringpackagingPackaging type of the artifact to be installed.private static java.util.regex.PatternPOM_ENTRY_PATTERNprivate java.io.FilepomFileLocation of an existing POM file to be installed alongside the main artifact, given by thefileparameter.private org.eclipse.aether.RepositorySystemrepositorySystemprivate org.apache.maven.execution.MavenSessionsessionprivate java.io.FilesourcesThe bundled sources for the artifact.private java.lang.StringversionVersion of the artifact to be installed.
-
Constructor Summary
Constructors Constructor Description InstallFileMojo(org.eclipse.aether.RepositorySystem repositorySystem)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.nio.charset.CharsetcharsetOrFail(java.lang.String name, java.lang.String entryName)Resolves a detected or declared encoding name, failing closed if this JVM cannot decode it.private booleancontentDiffers(java.io.File existing, java.io.File candidate)Returnstrueif the two files exist with different content, or cannot be compared (fail-closed for warning purposes).private voidcrossCheckOperatorCoordinates(java.lang.String entryName, org.apache.maven.model.Model model)Cross-checks every operator-supplied coordinate (groupId, artifactId, version) against the effective values declared by the embedded POM and fails on any mismatch.private java.nio.charset.CharsetdetectXmlCharset(byte[] bytes, java.lang.String entryName)Detects the character encoding of raw XML bytes the way an XML parser is required to (XML 1.0 Appendix F): byte-order mark first, then the byte pattern of a leading<?xml, then theencodingpseudo-attribute of the XML declaration, defaulting to UTF-8.voidexecute()private org.apache.maven.model.ModelgenerateModel()Generates a minimal model from the user-supplied artifact information.private java.io.FilegeneratePomFile()Generates a (temporary) POM file from the plugin configuration.private java.io.FilegetLocalRepositoryFile(org.eclipse.aether.RepositorySystemSession session, org.eclipse.aether.artifact.Artifact artifact)Gets the path of the specified artifact within the local repository.private java.io.FilegetPomLocalRepositoryFile(org.eclipse.aether.RepositorySystemSession session, org.eclipse.aether.artifact.Artifact artifact)Gets the path of the specified artifact POM within the local repository.private booleanisValidGroupId(java.lang.String groupId)Returnstrueif passed in string is a valid Maven groupId: a valid ID whose dot-separated segments are all non-empty.private booleanisValidId(java.lang.String id)Returnstrueif passed in string is "valid Maven ID" (artifactId or packaging): non-empty, not consisting solely of'.'characters (so it can never form a./..path segment in the local repository layout), and using only allowed characters.private booleanisValidVersion(java.lang.String version)Returnstrueif passed in string is "valid Maven (simple.private voidprocessModel(org.apache.maven.model.Model model)Populates missing mojo parameters from the specified POM.private java.io.FilereadingPomFromJarFile()private org.apache.maven.model.ModelreadModel(java.io.File pomFile)Parses a POM.private voidrejectDoctype(java.nio.file.Path embeddedPom, java.lang.String entryName)Defense-in-depth pre-screen for the JAR embedded POM: the entry is wire-origin, potentially attacker-authored XML, and it is handed toMavenXpp3Readerwhose DTD and external-entity posture this plugin can neither configure nor guarantee across core versions.private voidvalidateEmbeddedPomEntryPath(java.lang.String entryName, org.apache.maven.model.Model model)Verifies that the<groupId>/<artifactId>components of the matchedMETA-INF/maven/<groupId>/<artifactId>/pom.xmlentry path agree with the effective coordinates declared by the embedded POM itself.private voidverifyContainment(org.eclipse.aether.RepositorySystemSession repoSession, java.io.File artifactLocalFile)Defense in depth: verifies that the composed layout path stays inside the local repository.
-
-
-
Field Detail
-
LS
private static final java.lang.String LS
-
ILLEGAL_VERSION_CHARS
private static final java.lang.String ILLEGAL_VERSION_CHARS
- See Also:
- Constant Field Values
-
ENCODING_PSEUDO_ATTR
private static final java.util.regex.Pattern ENCODING_PSEUDO_ATTR
Theencodingpseudo-attribute of an XML declaration.
-
log
private final org.slf4j.Logger log
-
repositorySystem
private final org.eclipse.aether.RepositorySystem repositorySystem
-
session
@Parameter(defaultValue="${session}", required=true, readonly=true) private org.apache.maven.execution.MavenSession session
-
groupId
@Parameter(property="groupId") private java.lang.String groupId
GroupId of the artifact to be installed. Retrieved from POM file if one is specified or extracted frompom.xmlin jar if available.
-
artifactId
@Parameter(property="artifactId") private java.lang.String artifactId
ArtifactId of the artifact to be installed. Retrieved from POM file if one is specified or extracted frompom.xmlin jar if available.
-
version
@Parameter(property="version") private java.lang.String version
Version of the artifact to be installed. Retrieved from POM file if one is specified or extracted frompom.xmlin jar if available.
-
packaging
@Parameter(property="packaging") private java.lang.String packaging
Packaging type of the artifact to be installed. Retrieved from POM file if one is specified or extracted frompom.xmlin jar if available.
-
classifier
@Parameter(property="classifier") private java.lang.String classifier
Classifier type of the artifact to be installed. For example, "sources" or "javadoc". Defaults to none which means this is the project's main artifact.- Since:
- 2.2
-
extension
@Parameter(property="extension") private java.lang.String extension
Extension of the artifact to be installed. If set, will override plugin own logic to detect extension. If not set, as Maven expected, packaging determines the artifact extension.- Since:
- 3.1.3
-
file
@Parameter(property="file", required=true) private java.io.File fileThe file to be installed in the local repository.
-
javadoc
@Parameter(property="javadoc") private java.io.File javadoc
The bundled API docs for the artifact.- Since:
- 2.3
-
sources
@Parameter(property="sources") private java.io.File sources
The bundled sources for the artifact.- Since:
- 2.3
-
pomFile
@Parameter(property="pomFile") private java.io.File pomFile
Location of an existing POM file to be installed alongside the main artifact, given by thefileparameter.- Since:
- 2.1
-
generatePom
@Parameter(property="generatePom") private java.lang.Boolean generatePom
Generate a minimal POM for the artifact if none is supplied via the parameterpomFile. Defaults totrueif there is no existing POM in the local repository yet.- Since:
- 2.1
-
localRepositoryPath
@Parameter(property="localRepositoryPath") private java.io.File localRepositoryPath
The path for a specific local repository directory. If not specified the local repository path configured in the Maven settings will be used.- Since:
- 2.2
-
IS_EMPTY
private static final java.util.function.Predicate<java.lang.String> IS_EMPTY
-
IS_POM_PACKAGING
private static final java.util.function.Predicate<java.lang.String> IS_POM_PACKAGING
-
POM_ENTRY_PATTERN
private static final java.util.regex.Pattern POM_ENTRY_PATTERN
-
IS_POM_ENTRY
private static final java.util.function.Predicate<java.util.jar.JarEntry> IS_POM_ENTRY
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
readingPomFromJarFile
private java.io.File readingPomFromJarFile() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
readModel
private org.apache.maven.model.Model readModel(java.io.File pomFile) throws org.apache.maven.plugin.MojoExecutionExceptionParses a POM.- Parameters:
pomFile- The path of the POM file to parse, must not benull.- Returns:
- The model from the POM file, never
null. - Throws:
org.apache.maven.plugin.MojoExecutionException- If the POM could not be parsed.
-
rejectDoctype
private void rejectDoctype(java.nio.file.Path embeddedPom, java.lang.String entryName) throws org.apache.maven.plugin.MojoExecutionExceptionDefense-in-depth pre-screen for the JAR embedded POM: the entry is wire-origin, potentially attacker-authored XML, and it is handed toMavenXpp3Readerwhose DTD and external-entity posture this plugin can neither configure nor guarantee across core versions. A valid POM never carries a DOCTYPE declaration, so any embedded POM containing one is rejected before it reaches the parser. The scan is encoding-aware: the bytes are decoded with the same charset an XML parser is required to autodetect (BOM / first-bytes / encoding pseudo-attribute, XML 1.0 Appendix F), so a UTF-16 or UTF-32 document cannot smuggle a NUL-interleaved DOCTYPE past a naive single-byte scan. This intentionally does not apply to the operator's own-DpomFile.- Parameters:
embeddedPom- the temporary file holding the extracted entry, must not benullentryName- the name of the matched JAR entry, must not benull- Throws:
org.apache.maven.plugin.MojoExecutionException- if the content contains a DOCTYPE declaration or cannot be read
-
detectXmlCharset
private java.nio.charset.Charset detectXmlCharset(byte[] bytes, java.lang.String entryName) throws org.apache.maven.plugin.MojoExecutionExceptionDetects the character encoding of raw XML bytes the way an XML parser is required to (XML 1.0 Appendix F): byte-order mark first, then the byte pattern of a leading<?xml, then theencodingpseudo-attribute of the XML declaration, defaulting to UTF-8.- Parameters:
bytes- the raw entry bytes, must not benullentryName- the name of the matched JAR entry, for error messages- Returns:
- the detected charset, never
null - Throws:
org.apache.maven.plugin.MojoExecutionException- if the detected/declared encoding is unsupported
-
charsetOrFail
private java.nio.charset.Charset charsetOrFail(java.lang.String name, java.lang.String entryName) throws org.apache.maven.plugin.MojoExecutionExceptionResolves a detected or declared encoding name, failing closed if this JVM cannot decode it.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
validateEmbeddedPomEntryPath
private void validateEmbeddedPomEntryPath(java.lang.String entryName, org.apache.maven.model.Model model) throws org.apache.maven.plugin.MojoExecutionExceptionVerifies that the<groupId>/<artifactId>components of the matchedMETA-INF/maven/<groupId>/<artifactId>/pom.xmlentry path agree with the effective coordinates declared by the embedded POM itself.- Parameters:
entryName- the name of the matched JAR entry, must not benullmodel- the model parsed from that entry, must not benull- Throws:
org.apache.maven.plugin.MojoExecutionException- if the entry path does not match the model
-
crossCheckOperatorCoordinates
private void crossCheckOperatorCoordinates(java.lang.String entryName, org.apache.maven.model.Model model) throws org.apache.maven.plugin.MojoExecutionExceptionCross-checks every operator-supplied coordinate (groupId, artifactId, version) against the effective values declared by the embedded POM and fails on any mismatch.- Parameters:
entryName- the name of the matched JAR entry, must not benullmodel- the model parsed from that entry, must not benull- Throws:
org.apache.maven.plugin.MojoExecutionException- if an operator-supplied coordinate disagrees with the embedded POM
-
contentDiffers
private boolean contentDiffers(java.io.File existing, java.io.File candidate)Returnstrueif the two files exist with different content, or cannot be compared (fail-closed for warning purposes). Uses byte-by-byte comparison sinceFiles.mismatch()is not available on Java 8.
-
verifyContainment
private void verifyContainment(org.eclipse.aether.RepositorySystemSession repoSession, java.io.File artifactLocalFile) throws org.apache.maven.plugin.MojoExecutionExceptionDefense in depth: verifies that the composed layout path stays inside the local repository.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
processModel
private void processModel(org.apache.maven.model.Model model)
Populates missing mojo parameters from the specified POM.- Parameters:
model- The POM to extract missing artifact coordinates from, must not benull.
-
generateModel
private org.apache.maven.model.Model generateModel()
Generates a minimal model from the user-supplied artifact information.- Returns:
- The generated model, never
null.
-
generatePomFile
private java.io.File generatePomFile() throws org.apache.maven.plugin.MojoExecutionExceptionGenerates a (temporary) POM file from the plugin configuration. It's the responsibility of the caller to delete the generated file when no longer needed.- Returns:
- The path to the generated POM file, never
null. - Throws:
org.apache.maven.plugin.MojoExecutionException- If the POM file could not be generated.
-
getLocalRepositoryFile
private java.io.File getLocalRepositoryFile(org.eclipse.aether.RepositorySystemSession session, org.eclipse.aether.artifact.Artifact artifact)Gets the path of the specified artifact within the local repository. Note that the returned path need not exist (yet).
-
getPomLocalRepositoryFile
private java.io.File getPomLocalRepositoryFile(org.eclipse.aether.RepositorySystemSession session, org.eclipse.aether.artifact.Artifact artifact)Gets the path of the specified artifact POM within the local repository. Note that the returned path need not exist (yet).
-
isValidId
private boolean isValidId(java.lang.String id)
Returnstrueif passed in string is "valid Maven ID" (artifactId or packaging): non-empty, not consisting solely of'.'characters (so it can never form a./..path segment in the local repository layout), and using only allowed characters.
-
isValidGroupId
private boolean isValidGroupId(java.lang.String groupId)
Returnstrueif passed in string is a valid Maven groupId: a valid ID whose dot-separated segments are all non-empty. Leading, trailing or consecutive dots would produce empty path segments after the dots-to-directories transform of the local repository layout.
-
isValidVersion
private boolean isValidVersion(java.lang.String version)
Returnstrueif passed in string is "valid Maven (simple. non range, expression, etc) version": non-empty, not consisting solely of'.'characters, and free of illegal characters.
-
-