From bcf1baabaf30e1152d1a4a105de0d685299f33d1 Mon Sep 17 00:00:00 2001 From: Jess Sightler Date: Fri, 20 Feb 2015 15:59:43 -0500 Subject: [PATCH] WINDUP-465: Fixed some issues... some related files were missed in the initial move --- .../windup/config/parser/ParserContext.java | 81 +++++-- .../config/parser/XMLRuleProviderLoader.java | 3 +- .../config/loader/WindupRuleLoaderImpl.java | 6 +- .../XSLTTransformationHandler.java | 25 ++- .../xslt/jboss-app-to-jboss5.xsl | 10 - .../xslt/jboss4-persistence-to-jboss5.xsl | 22 -- .../xslt/weblogic-ejb-to-jboss.xsl | 104 --------- .../xslt/weblogic-entity2-to-jboss.xsl | 203 ------------------ .../xslt/weblogic-jboss5-web-xml.xsl | 16 -- .../xslt/weblogic-jms-to-jboss-messaging.xsl | 52 ----- .../xslt/weblogic10-ejb-to-jboss.xsl | 104 --------- .../xslt/weblogic9-ejb-to-jboss.xsl | 104 --------- .../xslt/websphere-jboss5-web-xml.xsl | 16 -- .../xslt/websphere-psrules-to-drools.xsl | 134 ------------ .../transformations/xslt/wsdl-pom-plugin.xsl | 37 ---- .../xslt/wsdl2java-xmlbeans-pom-plugin.xsl | 41 ---- .../xslt/jboss4-mq-to-jboss5.xsl | 0 17 files changed, 91 insertions(+), 867 deletions(-) delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/jboss-app-to-jboss5.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/jboss4-persistence-to-jboss5.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/weblogic-ejb-to-jboss.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/weblogic-entity2-to-jboss.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jboss5-web-xml.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jms-to-jboss-messaging.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/weblogic10-ejb-to-jboss.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/weblogic9-ejb-to-jboss.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/websphere-jboss5-web-xml.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/websphere-psrules-to-drools.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/wsdl-pom-plugin.xsl delete mode 100644 rules-xml/addon/src/main/resources/transformations/xslt/wsdl2java-xmlbeans-pom-plugin.xsl rename rules-xml/{addon/src/main => tests/src/test}/resources/transformations/xslt/jboss4-mq-to-jboss5.xsl (100%) diff --git a/config-xml/addon/src/main/java/org/jboss/windup/config/parser/ParserContext.java b/config-xml/addon/src/main/java/org/jboss/windup/config/parser/ParserContext.java index 9f9ccc1cdb..10d7f9f476 100644 --- a/config-xml/addon/src/main/java/org/jboss/windup/config/parser/ParserContext.java +++ b/config-xml/addon/src/main/java/org/jboss/windup/config/parser/ParserContext.java @@ -2,12 +2,17 @@ import static org.joox.JOOX.$; +import java.net.URI; +import java.net.URL; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + import org.jboss.forge.furnace.Furnace; import org.jboss.forge.furnace.addons.Addon; import org.jboss.forge.furnace.proxy.Proxies; @@ -19,11 +24,12 @@ import org.jboss.windup.util.exception.WindupException; import org.ocpsoft.rewrite.config.ConfigurationRuleBuilderPerform; import org.ocpsoft.rewrite.config.ConfigurationRuleParameterWhere; +import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * Handles maintaining the list of handlers associated with each tag/namespace pair, as well as selecting the right - * handler for element. This also maintains the current {@link WindupRuleProviderBuilder} being constructed. + * Handles maintaining the list of handlers associated with each tag/namespace pair, as well as selecting the right handler for element. This also + * maintains the current {@link WindupRuleProviderBuilder} being constructed. */ public class ParserContext { @@ -34,15 +40,18 @@ public class ParserContext private final Map> handlers = new HashMap<>(); /** - * The addon containing the xml file currently being parsed. This is needed mainly because of the classloader that loaded the Addon (XSLTTransformation needs it.) + * The addon containing the xml file currently being parsed. This is needed mainly because of the classloader that loaded the Addon + * (XSLTTransformation needs it.) */ private Addon addonContainingInputXML; /** - * The folder containing the xml file currently being parse. This should be the root folder from which any other - * resource lookups should be based. Eg, it may be the user scripts folder. + * The folder containing the xml file currently being parse. This should be the root folder from which any other resource lookups should be based. + * Eg, it may be the user scripts folder. * * If this is set, it should take precedent over the Addon for resource lookups. */ + private Path xmlInputRootPath; + private Path xmlInputPath; /** @@ -89,6 +98,36 @@ public T processElement(Element element) throws ConfigurationException + "] in namespace: [" + namespace + "]"); } + /** + * Processes the XML document at the provided {@link URL} and returns a result from the namespace element handlers. + */ + public T processDocument(URI uri) throws ConfigurationException + { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + dbFactory.setNamespaceAware(true); + DocumentBuilder dBuilder = null; + + try + { + dBuilder = dbFactory.newDocumentBuilder(); + } + catch (Exception e) + { + throw new WindupException("Failed to build xml parser due to: " + e.getMessage(), e); + } + + try + { + Document doc = dBuilder.parse(uri.toString()); + return processElement(doc.getDocumentElement()); + } + catch (Exception e) + { + throw new WindupException("Failed to parse document at: " + uri + ", due to: " + e.getMessage(), e); + } + + } + /** * Gets a {@link List} of all {@link RuleProviders} found so far. */ @@ -170,10 +209,7 @@ public Addon getAddonContainingInputXML() } /** - * The folder containing the xml file currently being parse. This should be the root folder from which any other - * resource lookups should be based. Eg, it may be the user scripts folder. - * - * If this is set, it should take precedent over the Addon for resource lookups. + * The path to the rule xml file itself (eg, /path/to/rule.windup.xml). */ public void setXmlInputPath(Path xmlInputPath) { @@ -181,13 +217,32 @@ public void setXmlInputPath(Path xmlInputPath) } /** - * The folder containing the xml file currently being parse. This should be the root folder from which any other - * resource lookups should be based. Eg, it may be the user scripts folder. + * The path to the rule xml file itself (eg, /path/to/rule.windup.xml). + */ + public Path getXmlInputPath() + { + return this.xmlInputPath; + } + + /** + * The folder containing the xml file currently being parsed. This should be the root folder from which any other resource lookups should be + * based. Eg, it may be the user scripts folder. * * If this is set, it should take precedent over the Addon for resource lookups. */ - public Path getXmlInputPath() + public void setXmlInputRootPath(Path xmlRootInputPath) + { + this.xmlInputRootPath = xmlRootInputPath; + } + + /** + * The folder containing the xml file currently being parsed. This should be the root folder from which any other resource lookups should be + * based. Eg, it may be the user scripts folder. + * + * If this is set, it should take precedent over the Addon for resource lookups. + */ + public Path getXmlInputRootPath() { - return xmlInputPath; + return xmlInputRootPath; } } diff --git a/config-xml/addon/src/main/java/org/jboss/windup/config/parser/XMLRuleProviderLoader.java b/config-xml/addon/src/main/java/org/jboss/windup/config/parser/XMLRuleProviderLoader.java index 3157d46c87..7485c9a9a5 100644 --- a/config-xml/addon/src/main/java/org/jboss/windup/config/parser/XMLRuleProviderLoader.java +++ b/config-xml/addon/src/main/java/org/jboss/windup/config/parser/XMLRuleProviderLoader.java @@ -116,7 +116,8 @@ public List getProviders(GraphContext context) ParserContext parser = new ParserContext(furnace); String userRulesPath = userRulesFileModel.getFilePath(); - parser.setXmlInputPath(Paths.get(userRulesPath)); + parser.setXmlInputPath(Paths.get(resource.toURI())); + parser.setXmlInputRootPath(Paths.get(userRulesPath)); parser.processElement(doc.getDocumentElement()); List parsedProviders = parser.getRuleProviders(); diff --git a/config/impl/src/main/java/org/jboss/windup/config/loader/WindupRuleLoaderImpl.java b/config/impl/src/main/java/org/jboss/windup/config/loader/WindupRuleLoaderImpl.java index 40e504fd41..1fac4b2d64 100644 --- a/config/impl/src/main/java/org/jboss/windup/config/loader/WindupRuleLoaderImpl.java +++ b/config/impl/src/main/java/org/jboss/windup/config/loader/WindupRuleLoaderImpl.java @@ -93,12 +93,12 @@ private void checkForDuplicates(List providers) String typeMessage; if (previousProvider.getClass().equals(provider.getClass())) { - typeMessage = " (type: " + Proxies.unwrapProxyClassName(provider.getClass()) + ")"; + typeMessage = " (type: " + previousProvider.getOrigin() + " and " + provider.getOrigin() + ")"; } else { - typeMessage = " (types: " + Proxies.unwrapProxyClassName(previousProvider.getClass()) + " and " - + Proxies.unwrapProxyClassName(provider.getClass()) + ")"; + typeMessage = " (types: " + Proxies.unwrapProxyClassName(previousProvider.getClass()) + " at " + previousProvider.getOrigin() + + " and " + Proxies.unwrapProxyClassName(provider.getClass()) + " at " + provider.getOrigin() + ")"; } throw new WindupException("Found two providers with the same id: " + provider.getID() + typeMessage); diff --git a/rules-xml/addon/src/main/java/org/jboss/windup/rules/apps/xml/confighandler/XSLTTransformationHandler.java b/rules-xml/addon/src/main/java/org/jboss/windup/rules/apps/xml/confighandler/XSLTTransformationHandler.java index b7ca24537c..3720a5f9f9 100644 --- a/rules-xml/addon/src/main/java/org/jboss/windup/rules/apps/xml/confighandler/XSLTTransformationHandler.java +++ b/rules-xml/addon/src/main/java/org/jboss/windup/rules/apps/xml/confighandler/XSLTTransformationHandler.java @@ -2,8 +2,8 @@ import static org.joox.JOOX.$; +import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -15,7 +15,6 @@ import org.jboss.windup.config.parser.ParserContext; import org.jboss.windup.rules.apps.xml.operation.xslt.XSLTTransformation; import org.jboss.windup.util.exception.WindupException; -import org.jboss.windup.util.xml.NamespaceEntry; import org.ocpsoft.rewrite.config.Condition; import org.w3c.dom.Element; @@ -64,7 +63,7 @@ public XSLTTransformation processElement(ParserContext handlerManager, Element e parameters.put(param.getKey(), param.getValue()); } - Path pathContainingXml = handlerManager.getXmlInputPath(); + Path pathContainingXml = handlerManager.getXmlInputRootPath(); if (pathContainingXml != null) { String fullPath; @@ -74,18 +73,30 @@ public XSLTTransformation processElement(ParserContext handlerManager, Element e } else { - fullPath = pathContainingXml.resolve(template).toAbsolutePath().toString(); + Path path = pathContainingXml.resolve(template).toAbsolutePath(); + + // If we can't find it at the default location, try relative to the rule xml file itself + if (!Files.exists(path)) + { + // This contains the parent of the rule itself (eg, /path/to/rules/rule.windup.xml would result in /path/to/rules/) + Path rulesParentPath = handlerManager.getXmlInputPath().getParent(); + fullPath = rulesParentPath.resolve(template).normalize().toAbsolutePath().toString(); + } + else + { + fullPath = path.normalize().toString(); + } } if (of != null) { - return (XSLTTransformation)XSLTTransformation + return (XSLTTransformation) XSLTTransformation .of(of) .usingFilesystem(fullPath) .withDescription(description) .withExtension(extension) .withParameters(parameters); } - return (XSLTTransformation)XSLTTransformation + return (XSLTTransformation) XSLTTransformation .usingFilesystem(fullPath) .withDescription(description) .withExtension(extension) @@ -96,7 +107,7 @@ public XSLTTransformation processElement(ParserContext handlerManager, Element e ClassLoader xmlFileAddonClassLoader = handlerManager.getAddonContainingInputXML().getClassLoader(); if (of != null) { - return (XSLTTransformation)XSLTTransformation + return (XSLTTransformation) XSLTTransformation .of(of) .using(template, xmlFileAddonClassLoader) .withDescription(description) diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/jboss-app-to-jboss5.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/jboss-app-to-jboss5.xsl deleted file mode 100644 index 1c0a6946e8..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/jboss-app-to-jboss5.xsl +++ /dev/null @@ -1,10 +0,0 @@ - - - - - <!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD Java EE Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd"> - - - - - \ No newline at end of file diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/jboss4-persistence-to-jboss5.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/jboss4-persistence-to-jboss5.xsl deleted file mode 100644 index 9b2c5b6bff..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/jboss4-persistence-to-jboss5.xsl +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd - 1.0 - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-ejb-to-jboss.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-ejb-to-jboss.xsl deleted file mode 100644 index a39c0efb8c..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-ejb-to-jboss.xsl +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - java: - - - - - true - - - - - true - - - - - - - - - - - - - - - - - - java: - - - true - FIXME: Entity Bean Configuration Name - - - true - - - - - true - - - - - - - - - - - - - /topic/ - - - - - - - - - - - - - - - ejb/ - - - - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-entity2-to-jboss.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-entity2-to-jboss.xsl deleted file mode 100644 index 16c01ef3cc..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-entity2-to-jboss.xsl +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - true - - - false - - - false - - - - - - - true - - - true - - - false - - - - - - - true - - - true - - - true - - - - - - - true - - - true - - - false - - - - - - - - - - - - - - - - - - - - - - - - - java:/ - - - - TODO: Replace with Mapping - - - - - - - - - - - - - - - - - - - - - - - - oracle-sequence - - sequence - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TODO: Complete ejb relationship - - - - - - - - - - - - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jboss5-web-xml.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jboss5-web-xml.xsl deleted file mode 100644 index 1f04cae02a..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jboss5-web-xml.xsl +++ /dev/null @@ -1,16 +0,0 @@ - - - - - <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd"> - - - - - - - - - - - \ No newline at end of file diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jms-to-jboss-messaging.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jms-to-jboss-messaging.xsl deleted file mode 100644 index 9898bb6459..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic-jms-to-jboss-messaging.xsl +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - org.jboss.jms.server.destination.QueueService - jboss.messaging.destination:service=Queue,name= - xmdesc/Queue-xmbean.xml - - - ServerPeer - jboss.messaging:service=ServerPeer - - - - jboss.messaging:service=PostOffice - - - - - - - - org.jboss.jms.server.destination.TopicService - jboss.messaging.destination:service=Topic,name= - xmdesc/Topic-xmbean.xml - - - ServerPeer - jboss.messaging:service=ServerPeer - - - - jboss.messaging:service=PostOffice - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic10-ejb-to-jboss.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/weblogic10-ejb-to-jboss.xsl deleted file mode 100644 index 8f5c25fe47..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic10-ejb-to-jboss.xsl +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - java: - - - - - true - - - - - true - - - - - - - - - - - - - - - - - - java: - - - true - FIXME: Entity Bean Configuration Name - - - true - - - - - true - - - - - - - - - - - - - /topic/ - - - - - - - - - - - - - - - ejb/ - - - - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic9-ejb-to-jboss.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/weblogic9-ejb-to-jboss.xsl deleted file mode 100644 index 4fd2e69e4a..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/weblogic9-ejb-to-jboss.xsl +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - java: - - - - - true - - - - - true - - - - - - - - - - - - - - - - - - java: - - - true - FIXME: Entity Bean Configuration Name - - - true - - - - - true - - - - - - - - - - - - - /topic/ - - - - - - - - - - - - - - - ejb/ - - - - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/websphere-jboss5-web-xml.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/websphere-jboss5-web-xml.xsl deleted file mode 100644 index a053543224..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/websphere-jboss5-web-xml.xsl +++ /dev/null @@ -1,16 +0,0 @@ - - - - - <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd"> - - - - - - - - - - - \ No newline at end of file diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/websphere-psrules-to-drools.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/websphere-psrules-to-drools.xsl deleted file mode 100644 index aeb21f4c8d..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/websphere-psrules-to-drools.xsl +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - - - - - - - - -template " - - " - - - - - - -end template - - - -========== TEMPLATE DATA =============== - - - - - - - - - -======================================= - - - - rule " - - @{row.rowNumber}" - - - ruleflow-group " - - " - - - - - -end - - - - - -when - - - - - - - - ( - - - - || - - - ) - - - - - ( - - - - ) - - - - - - - - - - - - - - - - - -then - - - - - - - - ; - - - - - - - - - - - - - - - - = " - - " - - - - \ No newline at end of file diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/wsdl-pom-plugin.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/wsdl-pom-plugin.xsl deleted file mode 100644 index 268d9b9609..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/wsdl-pom-plugin.xsl +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - org.apache.cxf - cxf-codegen-plugin - 2.2.7 - - - generate-sources - generate-sources - - ${basedir}/src/main/java - - - PATH_TO_WSDL - - - - -keep - -impl - -verbose - - - - wsdl2java - - - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/wsdl2java-xmlbeans-pom-plugin.xsl b/rules-xml/addon/src/main/resources/transformations/xslt/wsdl2java-xmlbeans-pom-plugin.xsl deleted file mode 100644 index 7e6892eacb..0000000000 --- a/rules-xml/addon/src/main/resources/transformations/xslt/wsdl2java-xmlbeans-pom-plugin.xsl +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - org.apache.cxf - cxf-codegen-plugin - 2.2.7 - - - generate-sources - generate-sources - - ${basedir}/src/main/java - - - PATH_TO_WSDL - - - - -keep - -impl - -verbose - -client - -db - xmlbeans - -autoNameResolution - - - - wsdl2java - - - - - - - diff --git a/rules-xml/addon/src/main/resources/transformations/xslt/jboss4-mq-to-jboss5.xsl b/rules-xml/tests/src/test/resources/transformations/xslt/jboss4-mq-to-jboss5.xsl similarity index 100% rename from rules-xml/addon/src/main/resources/transformations/xslt/jboss4-mq-to-jboss5.xsl rename to rules-xml/tests/src/test/resources/transformations/xslt/jboss4-mq-to-jboss5.xsl