@Test public void testFormatExportedVars_severalInstances() { TestApplication app = new TestApplication(); app.getTomcat().getComponent().exportedVariables.put( "path", new ExportedVariable( "path", "apps" )); Map<String,String> exportedVariables = ScriptUtils.formatExportedVars( app.getTomcatVm()); Assert.assertEquals( 0, exportedVariables.size()); exportedVariables = ScriptUtils.formatExportedVars( app.getTomcat()); Assert.assertEquals( 1, exportedVariables.size()); Assert.assertEquals( "apps", exportedVariables.get( "path" )); exportedVariables = ScriptUtils.formatExportedVars( app.getWar()); Assert.assertEquals( 3, exportedVariables.size()); Assert.assertEquals( "apps", exportedVariables.get( "ANCESTOR_tomcat_path" )); Assert.assertEquals( "8080", exportedVariables.get( "port" )); Assert.assertNull( exportedVariables.get( "ip" )); }
public static Map<String,String> formatExportedVars( Instance instance ) { Map<String, String> exportedVars = new HashMap<> (); for( Instance inst = instance; inst != null; inst = inst.getParent()) { String prefix = ""; if( inst != instance ) prefix = "ANCESTOR_" + inst.getComponent().getName() + "_"; Map<String,String> exports = InstanceHelpers.findAllExportedVariables( inst ); for(Entry<String, String> entry : exports.entrySet()) { String vname = prefix + VariableHelpers.parseVariableName( entry.getKey()).getValue(); vname = vname.replaceAll( "(-|%s)+", "_" ); exportedVars.put( vname, entry.getValue()); } } return exportedVars; }
ScriptUtils { public static Map<String,String> formatExportedVars( Instance instance ) { Map<String, String> exportedVars = new HashMap<> (); for( Instance inst = instance; inst != null; inst = inst.getParent()) { String prefix = ""; if( inst != instance ) prefix = "ANCESTOR_" + inst.getComponent().getName() + "_"; Map<String,String> exports = InstanceHelpers.findAllExportedVariables( inst ); for(Entry<String, String> entry : exports.entrySet()) { String vname = prefix + VariableHelpers.parseVariableName( entry.getKey()).getValue(); vname = vname.replaceAll( "(-|%s)+", "_" ); exportedVars.put( vname, entry.getValue()); } } return exportedVars; } }
ScriptUtils { public static Map<String,String> formatExportedVars( Instance instance ) { Map<String, String> exportedVars = new HashMap<> (); for( Instance inst = instance; inst != null; inst = inst.getParent()) { String prefix = ""; if( inst != instance ) prefix = "ANCESTOR_" + inst.getComponent().getName() + "_"; Map<String,String> exports = InstanceHelpers.findAllExportedVariables( inst ); for(Entry<String, String> entry : exports.entrySet()) { String vname = prefix + VariableHelpers.parseVariableName( entry.getKey()).getValue(); vname = vname.replaceAll( "(-|%s)+", "_" ); exportedVars.put( vname, entry.getValue()); } } return exportedVars; } private  ScriptUtils(); }
ScriptUtils { public static Map<String,String> formatExportedVars( Instance instance ) { Map<String, String> exportedVars = new HashMap<> (); for( Instance inst = instance; inst != null; inst = inst.getParent()) { String prefix = ""; if( inst != instance ) prefix = "ANCESTOR_" + inst.getComponent().getName() + "_"; Map<String,String> exports = InstanceHelpers.findAllExportedVariables( inst ); for(Entry<String, String> entry : exports.entrySet()) { String vname = prefix + VariableHelpers.parseVariableName( entry.getKey()).getValue(); vname = vname.replaceAll( "(-|%s)+", "_" ); exportedVars.put( vname, entry.getValue()); } } return exportedVars; } private  ScriptUtils(); static Map<String,String> formatExportedVars( Instance instance ); static Map<String,String> formatImportedVars( Instance instance ); static void setScriptsExecutable( File fileOrDir ); }
ScriptUtils { public static Map<String,String> formatExportedVars( Instance instance ) { Map<String, String> exportedVars = new HashMap<> (); for( Instance inst = instance; inst != null; inst = inst.getParent()) { String prefix = ""; if( inst != instance ) prefix = "ANCESTOR_" + inst.getComponent().getName() + "_"; Map<String,String> exports = InstanceHelpers.findAllExportedVariables( inst ); for(Entry<String, String> entry : exports.entrySet()) { String vname = prefix + VariableHelpers.parseVariableName( entry.getKey()).getValue(); vname = vname.replaceAll( "(-|%s)+", "_" ); exportedVars.put( vname, entry.getValue()); } } return exportedVars; } private  ScriptUtils(); static Map<String,String> formatExportedVars( Instance instance ); static Map<String,String> formatImportedVars( Instance instance ); static void setScriptsExecutable( File fileOrDir );  }