[Yanel-commits] rev 44437 -
public/yanel/trunk/src/build/java/org/wyona/yanel/ant
michi at wyona.com
michi at wyona.com
Thu Aug 27 14:53:14 CEST 2009
Author: michi
Date: 2009-08-27 14:53:14 +0200 (Thu, 27 Aug 2009)
New Revision: 44437
Modified:
public/yanel/trunk/src/build/java/org/wyona/yanel/ant/MergeResourceTypesConfigsTask.java
Log:
insert packages automatically
Modified: public/yanel/trunk/src/build/java/org/wyona/yanel/ant/MergeResourceTypesConfigsTask.java
===================================================================
--- public/yanel/trunk/src/build/java/org/wyona/yanel/ant/MergeResourceTypesConfigsTask.java 2009-08-27 12:06:33 UTC (rev 44436)
+++ public/yanel/trunk/src/build/java/org/wyona/yanel/ant/MergeResourceTypesConfigsTask.java 2009-08-27 12:53:14 UTC (rev 44437)
@@ -32,6 +32,8 @@
private Path globalResourceTypesConfigFile;
private boolean isBinaryRelease;
+ private String NAMESPACE = "http://www.wyona.org/yanel/1.0";
+
/**
*
*/
@@ -43,7 +45,9 @@
log("INFO: Global resource-types config directory: " + globalResourceTypesConfigFile);
File globalResourceTypesConfig = new File(globalResourceTypesConfigFile.toString());
- // TODO: Insert the package name automatically if binary release and no package and copy-dir-name specified
+ if (isBinaryRelease) {
+ insertPackageAttribute(globalResourceTypesConfig);
+ }
RealmManagerConfig realmManagerConfig = new RealmManagerConfig();
try {
@@ -111,8 +115,7 @@
Element rootElement = globalDoc.getDocumentElement();
rootElement.appendChild(globalDoc.createComment("Realm specific resource-types (" + resourceTypesConfigOfRealm + "):")); // Only formatting
- String namespace = "http://www.wyona.org/yanel/1.0";
- Element[] resourceTypeElements = XMLHelper.getChildElements(realmDoc.getDocumentElement(), "resource-type", namespace);
+ Element[] resourceTypeElements = XMLHelper.getChildElements(realmDoc.getDocumentElement(), "resource-type", NAMESPACE);
for (int i = 0; i < resourceTypeElements.length; i++) {
String srcAttr = resourceTypeElements[i].getAttribute("src");
if (srcAttr != null) {
@@ -122,7 +125,7 @@
// TODO: Check for duplicated resource-types also based re package attribute!
if (!resourceTypeExists(srcAttr, rootElement)) {
rootElement.appendChild(globalDoc.createTextNode("\n ")); // Only formatting
- Element rtElement = globalDoc.createElementNS(namespace, "resource-type");
+ Element rtElement = globalDoc.createElementNS(NAMESPACE, "resource-type");
//Element rtElement = globalDoc.createElementNS(namespace, "todo");
if (srcAttr != null && !srcAttr.equals("")) {
@@ -181,4 +184,29 @@
//return Class.forName(classname).getPackage().getName(); // NOTE: This doesn't work, because java classloader check
return classname.substring(0, classname.lastIndexOf(".")); // NOTE: This doesn't work in the case of ...
}
+
+ /**
+ * Insert package attributes automatically if binary release and no copy-dir-name attribute exists
+ * @param globalResourceTypesConfig Copied resource types configuration file (see build/classes/resource-types.xml)
+ */
+ private void insertPackageAttribute(File globalResourceTypesConfig) {
+ log.warn("DEBUG: Patch file: " + globalResourceTypesConfig);
+ try {
+ Document doc = XMLHelper.readDocument(new java.io.FileInputStream(globalResourceTypesConfig));
+ Element[] resourceTypeElements = XMLHelper.getChildElements(doc.getDocumentElement(), "resource-type", NAMESPACE);
+ for (int i = 0; i < resourceTypeElements.length; i++) {
+ if (!resourceTypeElements[i].hasAttribute("copy-dir-name")) {
+ if (!resourceTypeElements[i].hasAttribute("package")) {
+ String srcAttr = resourceTypeElements[i].getAttribute("src");
+ log.warn("DEBUG: Set package automatically for resource type: " + srcAttr);
+ resourceTypeElements[i].setAttribute("package", getJavaPackageOfResourceType(srcAttr));
+ }
+ }
+ }
+ log.warn("DEBUG: Overwrite file: " + globalResourceTypesConfig);
+ XMLHelper.writeDocument(doc, new java.io.FileOutputStream(globalResourceTypesConfig));
+ } catch(Exception e) {
+ log.error(e, e);
+ }
+ }
}
More information about the Yanel-commits
mailing list