Class ShrinkWrapManipulator

java.lang.Object
com.flowlogix.util.ShrinkWrapManipulator

public class ShrinkWrapManipulator extends Object
modifies xml files inside the archive according to xpath and function

Examples:

static WebArchive deployProductionMode() {
    var archive = ShrinkWrapManipulator.createDeployment(WebArchive.class);
    // add classes to the archive here
    var productionList = List.of(new Action(getContextParamValue(
            jakartify("javax.faces.PROJECT_STAGE")),
            node -> node.setTextContent("Production")));
    new ShrinkWrapManipulator().webXmlXPath(archive, productionList);
    return archive;
}
public static WebArchive deployPersistence() {
    var archive = ShrinkWrapManipulator.createDeployment(WebArchive.class);
    // add classes to the archive here
    String version = System.getProperty("project.version");
    new ShrinkWrapManipulator().persistenceXmlXPath(archive,
            List.of(new Action("//persistence/persistence-unit/jar-file",
                    node -> node.setTextContent(String.format("lib/entities-%s.jar", version)))));
    return archive;
}
Author:
lprimak
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    createDeployment(Class<TT> archiveType)
    Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    createDeployment(Class<TT> archiveType, @NonNull String archiveName)
    Simple method to create ShrinkWrap (Arquillian) archive from existing maven POM file
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    createDeployment(Class<TT> archiveType, @NonNull String archiveName, Path pomFilePath)
    Simple method to create ShrinkWrap (Arquillian) archive from existing maven POM file
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    createDeployment(Class<TT> archiveType, Path pomFilePath)
    Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    createDeployment(Class<TT> archiveType, UnaryOperator<String> nameTransformer)
    Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    createDeployment(Class<TT> archiveType, UnaryOperator<String> nameTransformer, Path pomFilePath)
    Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
    static String
    Constructs XPath for web.xml context param
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    logArchiveContents(TT archive, Consumer<String> consumer)
    Logs the contents of the archive to the consumer
    <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    String
    manipulateXml(org.jboss.shrinkwrap.api.Archive<TT> archive, List<ShrinkWrapManipulator.Action> actions, String xmlFileName)
    Parse XML file from the archive, perform actions to modify the file, and return a string representing the modified XML file
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    packageSlf4j(TT archive)
    Adds SLF4J to the archive
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    packageTestRequirements(TT deployment)
    Adds test requirements to the deployment Currently adds PayaraServerLifecycleExtension and org.assertj packages
    static <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    TT
    payaraClassDelegation(TT archive, boolean delegate)
    Adds payara-web.xml to the archive with the specified class delegation
    <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
    org.jboss.shrinkwrap.api.Archive<TT>
    persistenceXmlXPath(org.jboss.shrinkwrap.api.Archive<TT> archive, List<ShrinkWrapManipulator.Action> actions)
    modifies persistence.xml according to xpath and method
    static URL
    toHttpsURL(URL httpUrl)
    Transform http to https URL using sslPort system property, and default port 8181 if system property is not defined
    static URL
    toHttpsURL(URL httpUrl, String sslPortPropertyName, int defaultPort)
    Transform http to https URL using the specified system property and default port, if the system property is not defined
    org.jboss.shrinkwrap.api.spec.WebArchive
    webXmlXPath(org.jboss.shrinkwrap.api.spec.WebArchive archive, List<ShrinkWrapManipulator.Action> actions)
    modifies web.xml according to xpath and method

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ShrinkWrapManipulator

      public ShrinkWrapManipulator()
  • Method Details

    • createDeployment

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT createDeployment(Class<TT> archiveType)
      Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archiveType -
      Returns:
    • createDeployment

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT createDeployment(Class<TT> archiveType, Path pomFilePath)
      Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archiveType -
      pomFilePath -
      Returns:
    • createDeployment

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT createDeployment(Class<TT> archiveType, UnaryOperator<String> nameTransformer)
      Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archiveType -
      nameTransformer - transforms the UUID to a more suitable name
      Returns:
      new archive
    • createDeployment

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT createDeployment(Class<TT> archiveType, UnaryOperator<String> nameTransformer, Path pomFilePath)
      Simple method to create ShrinkWrap (Arquillian archive from existing maven POM file
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archiveType -
      nameTransformer - transforms the UUID to a more suitable name
      pomFilePath -
      Returns:
      new archive
    • createDeployment

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT createDeployment(Class<TT> archiveType, @NonNull @NonNull String archiveName)
      Simple method to create ShrinkWrap (Arquillian) archive from existing maven POM file
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archiveType -
      archiveName -
      Returns:
      new archive
    • createDeployment

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT createDeployment(Class<TT> archiveType, @NonNull @NonNull String archiveName, Path pomFilePath)
      Simple method to create ShrinkWrap (Arquillian) archive from existing maven POM file
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archiveType -
      archiveName -
      pomFilePath -
      Returns:
      new archive
    • logArchiveContents

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT logArchiveContents(TT archive, Consumer<String> consumer)
      Logs the contents of the archive to the consumer
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archive - to log
      consumer - to log the contents
      Returns:
      the same archive
    • payaraClassDelegation

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT payaraClassDelegation(TT archive, boolean delegate)
      Adds payara-web.xml to the archive with the specified class delegation
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archive - to modify
      delegate - whether to delegate or not
      Returns:
      the same archive
    • packageSlf4j

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT packageSlf4j(TT archive)
      Adds SLF4J to the archive
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      archive - to modify
      Returns:
      the same archive
    • packageTestRequirements

      public static <TT extends org.jboss.shrinkwrap.api.Archive<TT>> TT packageTestRequirements(TT deployment)
      Adds test requirements to the deployment Currently adds PayaraServerLifecycleExtension and org.assertj packages
      Type Parameters:
      TT - ShrinkWrap archive type
      Parameters:
      deployment - to modify
      Returns:
      the same deployment
    • webXmlXPath

      public org.jboss.shrinkwrap.api.spec.WebArchive webXmlXPath(org.jboss.shrinkwrap.api.spec.WebArchive archive, List<ShrinkWrapManipulator.Action> actions)
      modifies web.xml according to xpath and method
      Parameters:
      archive - to modify
      actions - list of actions to perform
    • persistenceXmlXPath

      public <TT extends org.jboss.shrinkwrap.api.Archive<TT>> org.jboss.shrinkwrap.api.Archive<TT> persistenceXmlXPath(org.jboss.shrinkwrap.api.Archive<TT> archive, List<ShrinkWrapManipulator.Action> actions)
      modifies persistence.xml according to xpath and method
      Parameters:
      archive - to modify
      actions - list of actions to perform
    • toHttpsURL

      public static URL toHttpsURL(URL httpUrl)
      Transform http to https URL using sslPort system property, and default port 8181 if system property is not defined
      Parameters:
      httpUrl - http URL
      Returns:
      https URL
    • toHttpsURL

      public static URL toHttpsURL(URL httpUrl, String sslPortPropertyName, int defaultPort)
      Transform http to https URL using the specified system property and default port, if the system property is not defined
      Parameters:
      httpUrl - http URL
      sslPortPropertyName -
      defaultPort -
      Returns:
      https URL
    • getContextParamValue

      public static String getContextParamValue(String paramName)
      Constructs XPath for web.xml context param
      Parameters:
      paramName -
      Returns:
      XPath for web.xml context param
    • manipulateXml

      public <TT extends org.jboss.shrinkwrap.api.Archive<TT>> String manipulateXml(org.jboss.shrinkwrap.api.Archive<TT> archive, List<ShrinkWrapManipulator.Action> actions, String xmlFileName)
      Parse XML file from the archive, perform actions to modify the file, and return a string representing the modified XML file
      Parameters:
      archive - to retrieve the xml file from
      actions - to perform on the xml file
      xmlFileName - xml file name to retrive from the archive
      Returns:
      string representation of the modified xml file