-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ochaloup/tofile
Going to 1.0.0.Final
- Loading branch information
Showing
7 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/groovy/org/jboss/qe/dscreator/common/Utils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jboss.qe.dscreator.common | ||
|
||
import java.util.Properties; | ||
|
||
class Utils { | ||
|
||
/** | ||
* Loading java.util.Properties from file and putting them to Properties instance. | ||
* | ||
* @param dbAllocPropsFile path to properties file | ||
* @return properties instance | ||
*/ | ||
public static Properties loadDbAllocatorProperties(String dbAllocPropsFile) { | ||
Properties props = new Properties() | ||
File propertiesFile = new File((String) dbAllocPropsFile) | ||
if (!propertiesFile.exists()) { | ||
System.err.println("File " + propertiesFile.absoluteFile + " doesn't exist") | ||
System.exit(500) | ||
} | ||
propertiesFile.withInputStream { | ||
stream -> props.load(stream) | ||
} | ||
return props | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/groovy/org/jboss/qe/dscreator/common/XMLDatasourcePrinter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jboss.qe.dscreator.common | ||
|
||
import groovy.xml.XmlUtil; | ||
|
||
/** | ||
* Class with utility methods to print xml string to file or something. | ||
*/ | ||
class XMLDatasourcePrinter { | ||
/** | ||
* Printing xml datasource to -ds.xml file. | ||
* | ||
* @param xmlFormat datasource created by datasource factory which implements methods of XMLFormattable and returns xml as string | ||
* @param outFile where to save the ds.xml file | ||
*/ | ||
def printToFile(XMLFormattable xmlFormat, String outFile) { | ||
FileWriter fileWriter = new FileWriter(outFile) | ||
def xmlOut = XmlUtil.serialize("\n<datasources>" + xmlFormat.toXml() + "</datasources>"); | ||
fileWriter.write(xmlOut) | ||
fileWriter.flush() | ||
} | ||
|
||
/** | ||
* Taking the datasource and putting it inside of the standalone.xml configuration. | ||
* | ||
* @param xmlFormat datasource created by datasource factory which implements methods of XMLFormattable and returns xml as string | ||
* @param standaloneXmlFile path to standalone.xml file | ||
* @param datasourceName name of datasource which will be added to config xml file | ||
* @param isXA is the datasource xa or not | ||
*/ | ||
def printToStandaloneXml(XMLFormattable xmlFormat, String standaloneXmlFile, String datasourceName, boolean isXA) { | ||
def standaloneXmlNode = new XmlParser(false, true).parseText(new File(standaloneXmlFile).text) | ||
def datasourceNode = new XmlParser(false, true).parseText(xmlFormat.toXml()) | ||
|
||
// we want to have new datasource if it's not added yet | ||
String datasourceType = isXA ? 'xa-datasource' : 'datasource' | ||
if(standaloneXmlNode.profile.subsystem.datasources."${datasourceType}".find{it.'@name' == datasourceName} == null) { | ||
// warn: not sure why but appendNode does strange things here | ||
standaloneXmlNode.profile.subsystem.datasources[0]?.append(datasourceNode) | ||
} | ||
|
||
// writing results back to config file (standalone.xml) | ||
new XmlNodePrinter(new PrintWriter(standaloneXmlFile)).print(standaloneXmlNode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/groovy/org/jboss/qe/dscreator/datasource/DatasourceFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/groovy/org/jboss/qe/dscreator/xadatasource/XADatasourceFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters