java.lang.Object
fr.paris.lutece.plugins.releaser.util.pom.PomParser

public class PomParser extends Object
PomParser.
  • Field Details

    • TYPE_MAVEN_PLUGIN

      public static final String TYPE_MAVEN_PLUGIN
      Type given to Maven build plugins extracted as dependencies.
      See Also:
  • Constructor Details

    • PomParser

      public PomParser()
  • Method Details

    • getDependencies

      public List<Dependency> getDependencies()
      Gets the dependencies.
      Returns:
      the dependencies
    • parse

      public void parse(Site site, String strPOM)
      Parses the.
      Parameters:
      site - the site
      strPOM - the str POM
    • parsePomPath

      public void parsePomPath(Component component, String pomPath)
      Parses the pom path.
      Parameters:
      component - the component
      pomPath - the pom path
    • parse

      public void parse(Component component, String strPOM)
      Parses the.
      Parameters:
      component - the component
      strPOM - the str POM
    • parse

      public void parse(Component component, InputStream inputStream)
      Parses the.
      Parameters:
      component - the component
      inputStream - the input stream
    • getProperties

      public static Map<String,String> getProperties(fr.paris.lutece.plugins.releaser.business.jaxb.maven.Model model)
      Returns the properties declared in the pom, plus the implicit project.version and project.parent.version.
      Parameters:
      model - the JAXB model of the pom
      Returns:
      the properties (never null)
    • resolveValue

      public static String resolveValue(String strValue, Map<String,String> mapProperties)
      Resolves the Maven property placeholders (${name}) of a value, recursively. Unknown placeholders are left as is.
      Parameters:
      strValue - the value, possibly null
      mapProperties - the properties
      Returns:
      the resolved value
    • parseVersion

      public String parseVersion(String strPOM)
      Returns the version of a pom, inherited from its parent when the project declares none.
      Parameters:
      strPOM - the pom content
      Returns:
      the version, null if absent or if the pom cannot be parsed
    • parseParent

      public Dependency parseParent(String strPOM)
      Returns the parent of a pom as a dependency : groupId, artifactId and version.
      Parameters:
      strPOM - the pom content
      Returns:
      the parent, null if the pom has none or cannot be parsed
    • parseModules

      public List<String> parseModules(String strPOM)
      Returns the modules declared by a pom, in declaration order.
      Parameters:
      strPOM - the pom content
      Returns:
      the module names (empty if the pom has none or cannot be parsed)
    • parseProperty

      public String parseProperty(String strPOM, String strName)
      Returns the value of a property of a pom, resolved against the other properties.
      Parameters:
      strPOM - the pom content
      strName - the property name
      Returns:
      the value, null if the property is absent or the pom cannot be parsed
    • parseReferencedArtifacts

      public List<Dependency> parseReferencedArtifacts(String strPOM, String strGroupIdPrefix)
      Extracts every artifact referenced by a pom : dependencies, managed dependencies, build plugins and managed plugins. Versions are resolved against the pom properties. Artifacts are deduplicated on groupId:artifactId (first declaration wins) and optionally filtered on a groupId prefix.
      Parameters:
      strPOM - the pom content
      strGroupIdPrefix - the groupId prefix to keep, or null to keep every artifact
      Returns:
      the artifacts, in declaration order (empty if the pom cannot be parsed)
    • parseVersionProperties

      public List<Dependency> parseVersionProperties(String strPOM, String strPropertyPrefix, String strPropertySuffix, String strBomPOM)
      Extracts the artifacts whose version is driven by a naming convention on the pom properties, such as lutece.<artifactId>.version. The groupId of each artifact is looked up in the managed dependencies of an optional bill of materials, resolved with the same properties.
      Parameters:
      strPOM - the pom holding the version properties
      strPropertyPrefix - the property prefix (ex : lutece.)
      strPropertySuffix - the property suffix (ex : .version)
      strBomPOM - the bill of materials pom, or null
      Returns:
      the artifacts, in property declaration order (groupId null when unknown ; empty if the pom cannot be parsed)
    • unmarshal

      public static <T> T unmarshal(Class<T> docClass, InputSource inputSource) throws javax.xml.bind.JAXBException
      Unmarshal.
      Type Parameters:
      T - the generic type
      Parameters:
      docClass - the doc class
      inputSource - the input source
      Returns:
      the t
      Throws:
      javax.xml.bind.JAXBException - the JAXB exception
    • newSaxParserFactory

      public static SAXParserFactory newSaxParserFactory() throws ParserConfigurationException
      Returns a SAX parser factory that refuses DOCTYPE declarations and never resolves external entities : the POMs read come from repositories and Nexus, an external entity could read a file of the server or call any URL.
      Returns:
      the namespace aware factory
      Throws:
      ParserConfigurationException - if the parser cannot be secured
    • newDocumentBuilderFactory

      public static DocumentBuilderFactory newDocumentBuilderFactory() throws ParserConfigurationException
      Returns a DOM builder factory that never resolves external entities nor external DTDs. A DOCTYPE stays allowed : old plugin.xml descriptors may declare one.
      Returns:
      the factory
      Throws:
      ParserConfigurationException - if the parser cannot be secured