protected void store() { try { ConfigurationManager.getInstance().store(this); } catch (Exception e) { logger.error("There was an error storing the new configuration for: "+this.getName(),e); } }
/** * Constructs the AbstractConfigurable by either reading from a previously stored set of properties, * or by using the default values which results in them being stored for subsequent usage. */ public AbstractConfigurable() { try { ConfigurationManager.getInstance().populate(this); } catch (Exception e) { logger.error("There was an error reading the properties for the Configurable:"+getName(),e); } }
@BeforeClass public static void setup() { ConfigurationManager.getInstance().setBaseConfigLocation(new File(System.getProperty("java.io.tmpdir"))); }
@SuppressWarnings("unchecked") @Test public void testSingleItem() throws Exception { List<String> list = new ArrayList<String>(); list.add("fred"); conf.setPropertyStringList("single", list); ConfigurationManager.getInstance().store(conf); ConfigurationManager.getInstance().populate(conf); assertTrue("should be an ArrayList",conf.getPropertyStringList("single") instanceof List); List<String> l = conf.getPropertyStringList("single"); assertEquals("There should be 1 element",1,l.size()); assertEquals("Its value should be fred","fred",l.get(0)); }
@Test public void saveColoursForDummyColourable() { String dummy = ""; ColourManager manager=ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#000000"); ConfigurationManager instance = ConfigurationManager.getInstance(); instance.setBaseConfigLocation(new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"scratch")); try { instance.store(manager); } catch (Exception e1) { e1.printStackTrace(); } try { instance.populate(manager); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Before public void setup() throws Exception { ConfigurationManager manager = ConfigurationManager.getInstance(); File f = new File(System.getProperty("java.io.tmpdir")); File configTestsDir = new File(f,"configTests"); if (!configTestsDir.exists()) configTestsDir.mkdir(); File d = new File(configTestsDir,UUID.randomUUID().toString()); d.mkdir(); manager.setBaseConfigLocation(d); configFile = new File(d,manager.generateFilename(DummyConfigurable.getInstance())); DummyConfigurable.getInstance().restoreDefaults(); }
throws Exception { try { File configFile = new File(baseConfigLocation,generateFilename(configurable)); if (configFile.exists()) { Properties props = new Properties(); logger.info("Config file for "+configurable.getName()+" not yet created. Creating with default values."); configurable.restoreDefaults(); store(configurable);
@Test public void createConfigManager() { ConfigurationManager instance = ConfigurationManager.getInstance(); assertNotNull("Config Manager should not be null", instance); }
public void actionPerformed(ActionEvent arg0) { String menus = menuItems.getText(); try { workbenchConfiguration.setMaxMenuItems(Integer.valueOf(menus)); } catch (IllegalArgumentException e) { String message = "Invalid menu items number " + menus + ":\n" + e.getLocalizedMessage(); JOptionPane.showMessageDialog(panel, message, "Invalid menu items", JOptionPane.WARNING_MESSAGE); return; } workbenchConfiguration.setCaptureConsole(captureConsole.isSelected()); workbenchConfiguration.setWarnInternalErrors(warnInternal.isSelected()); workbenchConfiguration.setDotLocation(dotLocation.getText()); try { configurationManager.store(workbenchConfiguration); String message = "For the new configuration to be fully applied, it is advised to restart Taverna."; JOptionPane.showMessageDialog(panel, message, "Restart adviced", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { logger.error("Error storing updated configuration", e); } } });
private ConfigurationManager() { File home = ApplicationRuntime.getInstance().getApplicationHomeDir(); File config = new File(home,"conf"); if (!config.exists()) { config.mkdir(); } setBaseConfigLocation(config); }
/** * Write out the properties configuration to disk based on the UUID of the * {@link Configurable} * <br> * Default values are not stored within the file, but only those that have been changed or deleted. * * @param configurable * @throws Exception */ public void store(Configurable configurable) throws Exception { try { Map<String, String> propertyMap = configurable.getInternalPropertyMap(); Properties props = new Properties(); for (String key : propertyMap.keySet()) { if (!propertyMap.get(key).equals(configurable.getDefaultProperty(key))) { props.put(key, propertyMap.get(key)); } } File configFile = new File(baseConfigLocation,generateFilename(configurable)); logger.info("Storing configuration for "+configurable.getName()+" to "+configFile.getAbsolutePath()); props.store(new FileOutputStream(configFile), ""); } catch (Exception e) { throw new Exception("Configuration storage failed: " + e); } }
@Test public void testDefaultValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertFalse("stored properties should not contain the default value",props.containsKey("name")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","john",conf.getProperty("name")); }
@Test public void saveColoursForDummyColourable() { String dummy = ""; ColourManager manager=ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#000000"); ConfigurationManager instance = ConfigurationManager.getInstance(); instance.setBaseConfigLocation(new File(System.getProperty("java.io.tmpdir")+File.separatorChar+"scratch")); try { instance.store(manager); } catch (Exception e1) { e1.printStackTrace(); } try { instance.populate(manager); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Before public void setup() throws Exception { ConfigurationManager manager = ConfigurationManager.getInstance(); File f = new File(System.getProperty("java.io.tmpdir")); File configTestsDir = new File(f,"configTests"); if (!configTestsDir.exists()) configTestsDir.mkdir(); File d = new File(configTestsDir,UUID.randomUUID().toString()); d.mkdir(); manager.setBaseConfigLocation(d); configFile = new File(d,manager.generateFilename(DummyConfigurable.getInstance())); DummyConfigurable.getInstance().restoreDefaults(); }
@Test public void createConfigManager() { ConfigurationManager instance = ConfigurationManager.getInstance(); assertNotNull("Config Manager should not be null", instance); }
@Test public void testList() throws Exception { List<String> list = new ArrayList<String>(); list.add("fred"); list.add("bloggs"); conf.setPropertyStringList("list", list); ConfigurationManager.getInstance().store(conf); ConfigurationManager.getInstance().populate(conf); assertTrue("should be an ArrayList",conf.getPropertyStringList("list") instanceof List); List<String> l = conf.getPropertyStringList("list"); assertEquals("There should be 1 element",2,l.size()); assertEquals("Its value should be fred","fred",l.get(0)); assertEquals("Its value should be bloggs","bloggs",l.get(1)); }
@Test public void saveAsWrongArrayType() throws Exception { String dummy = ""; ColourManager manager = ColourManager.getInstance(); manager.setProperty(dummy.getClass().getCanonicalName(), "#ffffff"); ConfigurationManager instance = ConfigurationManager.getInstance(); File baseLoc = File.createTempFile("test", "scratch"); baseLoc.delete(); assertTrue("Could not make directory " + baseLoc, baseLoc.mkdir()); instance.setBaseConfigLocation(baseLoc); instance.store(manager); instance.populate(manager); manager.getPreferredColour(dummy); }
ConfigurationManager manager = ConfigurationManager.getInstance(); configuration.deleteProperty(selectedCaGridConfigurationName); try { manager.store(configuration); } catch (Exception e) { JOptionPane.showMessageDialog(this,
@Before public void setup() { ConfigurationManager manager = ConfigurationManager.getInstance(); File f = new File(System.getProperty("java.io.tmpdir")); File d = new File(f, UUID.randomUUID().toString()); d.mkdir(); manager.setBaseConfigLocation(d); }
@Test public void testDefaultValues() throws Exception { Configurable conf = DummyConfigurable.getInstance(); ConfigurationManager manager = ConfigurationManager.getInstance(); assertEquals("name should equal john","john",conf.getProperty("name")); manager.store(conf); Properties props = new Properties(); props.load(new FileInputStream(configFile)); assertFalse("stored properties should not contain the default value",props.containsKey("name")); manager.populate(conf); assertEquals("default property name should still exist after re-populating","john",conf.getProperty("name")); }