Class ShrinkWrapManipulator
java.lang.Object
com.flowlogix.util.ShrinkWrapManipulator
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTcreateDeployment
(Class<TT> archiveType) Simple method to create ShrinkWrap (Arquillian archive from existing maven POM filestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTcreateDeployment
(Class<TT> archiveType, @NonNull String archiveName) Simple method to create ShrinkWrap (Arquillian) archive from existing maven POM filestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTcreateDeployment
(Class<TT> archiveType, @NonNull String archiveName, Path pomFilePath) Simple method to create ShrinkWrap (Arquillian) archive from existing maven POM filestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTcreateDeployment
(Class<TT> archiveType, Path pomFilePath) Simple method to create ShrinkWrap (Arquillian archive from existing maven POM filestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTcreateDeployment
(Class<TT> archiveType, UnaryOperator<String> nameTransformer) Simple method to create ShrinkWrap (Arquillian archive from existing maven POM filestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTcreateDeployment
(Class<TT> archiveType, UnaryOperator<String> nameTransformer, Path pomFilePath) Simple method to create ShrinkWrap (Arquillian archive from existing maven POM filestatic String
getContextParamValue
(String paramName) Constructs XPath for web.xml context paramstatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTlogArchiveContents
(TT archive, Consumer<String> consumer) Logs the contents of the archive to the consumer<TT extends org.jboss.shrinkwrap.api.Archive<TT>>
StringmanipulateXml
(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 filestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTpackageSlf4j
(TT archive) Adds SLF4J to the archivestatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTpackageTestRequirements
(TT deployment) Adds test requirements to the deployment Currently adds PayaraServerLifecycleExtension and org.assertj packagesstatic <TT extends org.jboss.shrinkwrap.api.Archive<TT>>
TTpayaraClassDelegation
(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 methodstatic URL
toHttpsURL
(URL httpUrl) Transform http to https URL usingsslPort
system property, and default port 8181 if system property is not definedstatic 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 definedorg.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
-
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 namepomFilePath
-- 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 logconsumer
- 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 modifydelegate
- 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 modifyactions
- 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 modifyactions
- list of actions to perform
-
toHttpsURL
-
toHttpsURL
-
getContextParamValue
-
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 fromactions
- to perform on the xml filexmlFileName
- xml file name to retrive from the archive- Returns:
- string representation of the modified xml file
-