Class JGitverUtils
- java.lang.Object
-
- fr.brouillard.oss.jgitver.JGitverUtils
-
public final class JGitverUtils extends Object
Misc utils used by the plugin.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJGitverUtils.CLI
-
Field Summary
Fields Modifier and Type Field Description static StringEXTENSION_ARTIFACT_IDstatic StringEXTENSION_EXPORT_PROPERTIES_PATHstatic StringEXTENSION_FLATTENstatic StringEXTENSION_FORCE_COMPUTATIONstatic StringEXTENSION_GROUP_IDstatic StringEXTENSION_PREFIXstatic StringEXTENSION_SKIPstatic StringEXTENSION_USE_VERSIONstatic StringPROJECT_VERSIONstatic StringSESSION_MAVEN_PROPERTIES_KEY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidattachModifiedPomFilesToTheProject(List<org.apache.maven.project.MavenProject> projects, Set<GAV> gavs, String version, Boolean resolveProjectVersion, org.codehaus.plexus.logging.Logger logger)Attach modified POM files to the projects so install/deployed files contains new version.static voidchangeBaseDir(org.apache.maven.project.MavenProject project, File initialBaseDir)Changes basedir(dangerous).static FilecreatePomDumpFile()Creates temporary file to save updated pom mode.static Optional<String>exportPropertiesPath(org.apache.maven.execution.MavenSession session, org.codehaus.plexus.logging.Logger logger)Provides the path (file name) to export properties to if defined as user or system property.static voidfailAsOldMechanism(java.util.function.Consumer<? super CharSequence> logger)fail the build by throwing aMavenExecutionExceptionand logging a failure message.static voidfillPropertiesFromMetadatas(Properties properties, JGitverInformationProvider informationProvider, org.codehaus.plexus.logging.Logger logger)Fill properties from meta data.static Optional<String>getProperty(org.apache.maven.execution.MavenSession session, String propertyName, org.codehaus.plexus.logging.Logger logger)Tries to get the property from the user properties (MavenSession.getUserProperties()) or from the system properties (MavenSession.getSystemProperties()).static org.apache.maven.model.ModelloadInitialModel(File pomFile)Loads initial model from pom file.static StringnormalizeSystemPropertyName(String mavenPropertyName)Derives an IEEE Std 1003.1-2001 compliant property name by replacing all non-compliant characters with underscore.static voidsetProjectPomFile(org.apache.maven.project.MavenProject project, File newPom, org.codehaus.plexus.logging.Logger logger)Changes the pom file of the given project.static booleanshouldForceComputation(org.apache.maven.execution.MavenSession session)Tells if forceComputation should be set during the version calculation.static booleanshouldSkip(org.apache.maven.execution.MavenSession session)Tells if this jgitver extension should be skipped for the given maven session execution.static booleanshouldUseFlattenPlugin(org.apache.maven.execution.MavenSession session)Tells if this jgitver extension should use maven-flatten-plugin instead of its own mechanism.static Optional<String>versionOverride(org.apache.maven.execution.MavenSession session, org.codehaus.plexus.logging.Logger logger)Provides the version to use if defined as user or system property.static voidwriteModelPom(org.apache.maven.model.Model mavenModel, File pomFile)Writes updated model to temporary pom file.
-
-
-
Field Detail
-
EXTENSION_PREFIX
public static final String EXTENSION_PREFIX
- See Also:
- Constant Field Values
-
EXTENSION_GROUP_ID
public static final String EXTENSION_GROUP_ID
- See Also:
- Constant Field Values
-
EXTENSION_ARTIFACT_ID
public static final String EXTENSION_ARTIFACT_ID
- See Also:
- Constant Field Values
-
SESSION_MAVEN_PROPERTIES_KEY
public static final String SESSION_MAVEN_PROPERTIES_KEY
- See Also:
- Constant Field Values
-
PROJECT_VERSION
public static final String PROJECT_VERSION
- See Also:
- Constant Field Values
-
EXTENSION_SKIP
public static final String EXTENSION_SKIP
- See Also:
- Constant Field Values
-
EXTENSION_FORCE_COMPUTATION
public static final String EXTENSION_FORCE_COMPUTATION
- See Also:
- Constant Field Values
-
EXTENSION_FLATTEN
public static final String EXTENSION_FLATTEN
- See Also:
- Constant Field Values
-
EXTENSION_USE_VERSION
public static final String EXTENSION_USE_VERSION
- See Also:
- Constant Field Values
-
EXTENSION_EXPORT_PROPERTIES_PATH
public static final String EXTENSION_EXPORT_PROPERTIES_PATH
- See Also:
- Constant Field Values
-
-
Method Detail
-
loadInitialModel
public static org.apache.maven.model.Model loadInitialModel(File pomFile) throws IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Loads initial model from pom file.- Parameters:
pomFile- pomFile.- Returns:
- Model.
- Throws:
IOException- IOException.org.codehaus.plexus.util.xml.pull.XmlPullParserException- XmlPullParserException.
-
createPomDumpFile
public static File createPomDumpFile() throws IOException
Creates temporary file to save updated pom mode.- Returns:
- File.
- Throws:
IOException- IOException.
-
writeModelPom
public static void writeModelPom(org.apache.maven.model.Model mavenModel, File pomFile) throws IOExceptionWrites updated model to temporary pom file.- Parameters:
mavenModel- mavenModel.pomFile- pomFile.- Throws:
IOException- IOException.
-
changeBaseDir
public static void changeBaseDir(org.apache.maven.project.MavenProject project, File initialBaseDir) throws NoSuchFieldException, IllegalAccessExceptionChanges basedir(dangerous).- Parameters:
project- project.initialBaseDir- initialBaseDir.- Throws:
NoSuchFieldException- NoSuchFieldException.IllegalAccessException- IllegalAccessException.
-
setProjectPomFile
public static void setProjectPomFile(org.apache.maven.project.MavenProject project, File newPom, org.codehaus.plexus.logging.Logger logger)Changes the pom file of the given project.- Parameters:
project- the project to change the pomnewPom- the pom file to set on the projectlogger- a logger to use
-
fillPropertiesFromMetadatas
public static void fillPropertiesFromMetadatas(Properties properties, JGitverInformationProvider informationProvider, org.codehaus.plexus.logging.Logger logger)
Fill properties from meta data.- Parameters:
properties- properties.informationProvider- the jgitver to extract information from.logger- logger.
-
attachModifiedPomFilesToTheProject
public static void attachModifiedPomFilesToTheProject(List<org.apache.maven.project.MavenProject> projects, Set<GAV> gavs, String version, Boolean resolveProjectVersion, org.codehaus.plexus.logging.Logger logger) throws IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Attach modified POM files to the projects so install/deployed files contains new version.- Parameters:
projects- projects.gavs- list of registered GAVs of modified projects.version- the version to setlogger- the logger to report to- Throws:
IOException- if project model cannot be read correctlyorg.codehaus.plexus.util.xml.pull.XmlPullParserException- if project model cannot be interpreted correctly
-
failAsOldMechanism
public static void failAsOldMechanism(java.util.function.Consumer<? super CharSequence> logger) throws org.apache.maven.MavenExecutionException
fail the build by throwing aMavenExecutionExceptionand logging a failure message.- Parameters:
logger- the logger to log information- Throws:
org.apache.maven.MavenExecutionException- to make the build fail
-
shouldSkip
public static boolean shouldSkip(org.apache.maven.execution.MavenSession session)
Tells if this jgitver extension should be skipped for the given maven session execution. To skip execution launch maven with a user propertymvn -Djgitver.skip=true/falseThe value of the property is evaluated using @Boolean.parseBoolean(String).- Parameters:
session- a running maven session- Returns:
- true if jgitver extension should be skipped
-
shouldForceComputation
public static boolean shouldForceComputation(org.apache.maven.execution.MavenSession session)
Tells if forceComputation should be set during the version calculation.mvn -Djgitver.skip=true/falseThe value of the property is evaluated using @Boolean.parseBoolean(String).- Parameters:
session- a running maven session- Returns:
- true if jgitver extension should be skipped
-
shouldUseFlattenPlugin
public static boolean shouldUseFlattenPlugin(org.apache.maven.execution.MavenSession session)
Tells if this jgitver extension should use maven-flatten-plugin instead of its own mechanism. To activate flatten pluginmvn -Djgitver.flatten=true/falseThe value of the property is evaluated using @Boolean.parseBoolean(String).- Parameters:
session- a running maven session- Returns:
- true if jgitver extension should use flatten
-
versionOverride
public static Optional<String> versionOverride(org.apache.maven.execution.MavenSession session, org.codehaus.plexus.logging.Logger logger)
Provides the version to use if defined as user or system property.- Parameters:
session- a running maven sessionlogger- logger- Returns:
- an Optional containing the version to use if the corresponding user or system property has been defined
-
exportPropertiesPath
public static Optional<String> exportPropertiesPath(org.apache.maven.execution.MavenSession session, org.codehaus.plexus.logging.Logger logger)
Provides the path (file name) to export properties to if defined as user or system property.- Parameters:
session- a running maven sessionlogger- logger- Returns:
- an Optional containing the output filename to use if the corresponding user or system property has been defined
-
getProperty
public static Optional<String> getProperty(org.apache.maven.execution.MavenSession session, String propertyName, org.codehaus.plexus.logging.Logger logger)
Tries to get the property from the user properties (MavenSession.getUserProperties()) or from the system properties (MavenSession.getSystemProperties()).The variable can be defined with it's exact name or with it's IEEE Std 1003.1-2001 compliant version (
normalizeSystemPropertyName(String)).User properties have higher priority than all other properties. Environment properties have higher priority than system properties. Exact matches have higher priority than IEEE Std 1003.1-2001 compliant versions.
- Parameters:
session- A running maven session.propertyName- The name of the property to retrieve.logger- logger.- Returns:
- The value of the property of empty if it has not been defined.
-
normalizeSystemPropertyName
public static String normalizeSystemPropertyName(String mavenPropertyName)
Derives an IEEE Std 1003.1-2001 compliant property name by replacing all non-compliant characters with underscore.In IEEE Std 1003.1-2001 it was defined that the variable name consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit. Although IEEE Std 1003.1-2008 / IEEE POSIX P1003.2/ISO 9945.2 doesn't define a lexical convention for variable names, most bash implementations use `[a-zA-Z_]+[a-zA-Z0-9_]*`.
- Returns:
- A derived IEEE Std 1003.1-2001 compliant property name.
-
-