[kepler-code] r28821 - trunk/modules/workflow-scheduler-gui/src/org/kepler/module/workflowschedulergui
tao at ecoinformatics.org
tao at ecoinformatics.org
Thu Oct 20 14:15:13 PDT 2011
Author: tao
Date: 2011-10-20 14:15:13 -0700 (Thu, 20 Oct 2011)
New Revision: 28821
Modified:
trunk/modules/workflow-scheduler-gui/src/org/kepler/module/workflowschedulergui/Initialize.java
Log:
Add code to copy configuration to keplerData dir.
Modified: trunk/modules/workflow-scheduler-gui/src/org/kepler/module/workflowschedulergui/Initialize.java
===================================================================
--- trunk/modules/workflow-scheduler-gui/src/org/kepler/module/workflowschedulergui/Initialize.java 2011-10-20 14:03:57 UTC (rev 28820)
+++ trunk/modules/workflow-scheduler-gui/src/org/kepler/module/workflowschedulergui/Initialize.java 2011-10-20 21:15:13 UTC (rev 28821)
@@ -30,12 +30,18 @@
package org.kepler.module.workflowschedulergui;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.util.List;
+import org.kepler.build.modules.Module;
import org.kepler.configuration.ConfigurationManager;
import org.kepler.configuration.ConfigurationNamespace;
import org.kepler.configuration.ConfigurationProperty;
+import org.kepler.configuration.RootConfigurationProperty;
import org.kepler.module.ModuleInitializer;
+import org.kepler.util.DotKeplerManager;
/** Module initializer for workflow-scheduler-gui.
@@ -47,18 +53,20 @@
{
private static final String SCHEDULER = "scheduler";
private static final String URL = "url";
- private static String CURRENTMODULENAME = "workflow-scheduler-gui";
+ private static final String CURRENTMODULENAME = "workflow-scheduler-gui";
private static ConfigurationProperty workflowSchedulerGUIProperty = null;
private static ConfigurationManager cm = ConfigurationManager.getInstance();
private static String schedulerURL = null;
+ private static String configFileLocation = null;
/** Perform any module-specific initializations. */
public void initializeModule()
{
- //System.out.println("start of workflow-scheduler-gui module initializing");
+ System.out.println("start of workflow-scheduler-gui module initializing");
addLocalProperties("workflow-scheduler-gui", "uiMenuMappings", "gui");
- workflowSchedulerGUIProperty = cm.getProperty(ConfigurationManager.getModule(CURRENTMODULENAME));
+ workflowSchedulerGUIProperty = cm.getProperty(ConfigurationManager.getModule(CURRENTMODULENAME));
schedulerURL = getSchedulerURLFromConfig();
+ copyConfigToPersistentDir();
}
@@ -142,5 +150,89 @@
return url;
}
+ /*
+ * Copy the configuration.xml of this module from application resource directory to kepler data
+ * driectory if the configuration.xml of this module doesn't exist on KeplerData directory
+ */
+ private static void copyConfigToPersistentDir()
+ {
+ RootConfigurationProperty property = null;
+ List list = cm.getProperties(ConfigurationManager.getModule(CURRENTMODULENAME));
+ if(list != null)
+ {
+ for (int i = 0; i < list.size(); i++)
+ {
+ RootConfigurationProperty rcp = (RootConfigurationProperty) list.get(i);
+ if (rcp.getNamespace().equals(ConfigurationProperty.namespaceDefault))
+ {
+ property = rcp;
+ break;
+ }
+ }
+ }
+ if(property != null)
+ {
+ String filename = property.getFile().getName();
+ Module m = property.getModule();
+
+ //first check to see if the configurations directory exists in .kepler
+ File configDirOnResource = m.getConfigurationsDir();
+ File configFileOnResource = new File(configDirOnResource, filename);
+ if(!configFileOnResource.exists())
+ {
+ System.err.println("Intilaize.copyConfigToPersistentDir - the configure file "+filename+" doesn't exist on this directory "+configDirOnResource.getPath());
+ return;
+ }
+ File modConfDir = DotKeplerManager.getInstance().getModuleConfigurationDirectory(m.getName());
+ ///File modConfDir = DotKeplerManager.getInstance().getModuleConfigurationDirectory(m.getStemName());
+ if(!modConfDir.exists())
+ { //create the dir
+ modConfDir.mkdirs();
+ }
+ //now we can save the property to keplerData/configurations if the configuration doesn't exist
+ try
+ {
+ File configFile = new File(modConfDir, filename);
+ configFileLocation = configFile.getAbsolutePath();
+ if(!configFile.exists())
+ {
+ //since serialize properties to kepler data directory will removing all comments on the configuration file,
+ //we will copy the file from resource directory to kepler data directory directly
+ FileReader reader = new FileReader(configFileOnResource);
+ FileWriter fw = new FileWriter(configFile);
+ char[] charArray = new char[1052];
+ int size = reader.read(charArray);
+ while(size != -1)
+ {
+ fw.write(charArray, 0, size);
+ fw.flush();
+ size = reader.read(charArray);
+ }
+ fw.close();
+ reader.close();
+ //System.out.println("=======copy the config file of the workflow-scheduler-gui from resource to kepler data");
+ }
+ else
+ {
+ //System.out.println("=======NOT copy the config file of the workflow-scheduler-gui from resource to kepler data since the file exists");
+ }
+
+ }
+ catch(Exception e)
+ {
+ System.err.println("Error copying configuration " +
+ filename + " to directory " + modConfDir.getAbsolutePath() +
+ " : " + e.getMessage());
+ }
+ }
+ else
+ {
+ //System.out.println("=======NOT copy the config file of the workflow-scheduler-gui from resource to kepler data since the property is null");
+ }
+
+ }
+
+
+
}
More information about the Kepler-cvs
mailing list