Class JGitverUtils


  • public final class JGitverUtils
    extends Object
    Misc utils used by the plugin.
    • 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 IOException
        Writes updated model to temporary pom file.
        Parameters:
        mavenModel - mavenModel.
        pomFile - pomFile.
        Throws:
        IOException - IOException.
      • 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 pom
        newPom - the pom file to set on the project
        logger - 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 set
        logger - the logger to report to
        Throws:
        IOException - if project model cannot be read correctly
        org.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 a MavenExecutionException and 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 property
             mvn -Djgitver.skip=true/false
         
        The 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/false
         
        The 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 plugin
             mvn -Djgitver.flatten=true/false
         
        The 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 session
        logger - 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 session
        logger - 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.