@Test public void testParseExportedVariables_listWithMixedValuesAndRandom() { Map<String,ExportedVariable> variables = VariableHelpers.parseExportedVariables( "key1 = \"value1 is here\" , random[port] key2= value2, key3 = \"key33\", key4 = oops " ); Assert.assertEquals( 4, variables.size()); ExportedVariable var = variables.get( "key1" ); Assert.assertEquals( "value1 is here", var.getValue()); Assert.assertFalse( var.isRandom()); var = variables.get( "key2" ); Assert.assertEquals( "value2", var.getValue()); Assert.assertTrue( var.isRandom()); Assert.assertEquals( RandomKind.PORT, var.getRandomKind()); var = variables.get( "key3" ); Assert.assertEquals( "key33", var.getValue()); Assert.assertFalse( var.isRandom()); var = variables.get( "key4" ); Assert.assertEquals( "oops", var.getValue()); Assert.assertFalse( var.isRandom()); }
public static Map<String,ExportedVariable> parseExportedVariables( String line ) { Pattern randomPattern = Pattern.compile( ParsingConstants.PROPERTY_GRAPH_RANDOM_PATTERN, Pattern.CASE_INSENSITIVE ); Pattern varPattern = Pattern.compile( "([^,=]+)(\\s*=\\s*(\"([^\",]+)\"|([^,]+)))?" ); Map<String,ExportedVariable> result = new LinkedHashMap<> (); Matcher varMatcher = varPattern.matcher( line ); while( varMatcher.find()) { String key = varMatcher.group( 1 ).trim(); if( Utils.isEmptyOrWhitespaces( key )) continue; String value = null; if( varMatcher.group( 3 ) != null ) { if( varMatcher.group( 5 ) != null ) value = varMatcher.group( 5 ).trim(); else value = varMatcher.group( 4 ); } ExportedVariable var = new ExportedVariable(); Matcher m = randomPattern.matcher( key ); if( m.matches()) { var.setRandom( true ); var.setRawKind( m.group( 1 )); key = m.group( 2 ).trim(); } var.setName( key.trim()); if( value != null ) var.setValue( value ); result.put( var.getName(), var ); } return result; }
VariableHelpers { public static Map<String,ExportedVariable> parseExportedVariables( String line ) { Pattern randomPattern = Pattern.compile( ParsingConstants.PROPERTY_GRAPH_RANDOM_PATTERN, Pattern.CASE_INSENSITIVE ); Pattern varPattern = Pattern.compile( "([^,=]+)(\\s*=\\s*(\"([^\",]+)\"|([^,]+)))?" ); Map<String,ExportedVariable> result = new LinkedHashMap<> (); Matcher varMatcher = varPattern.matcher( line ); while( varMatcher.find()) { String key = varMatcher.group( 1 ).trim(); if( Utils.isEmptyOrWhitespaces( key )) continue; String value = null; if( varMatcher.group( 3 ) != null ) { if( varMatcher.group( 5 ) != null ) value = varMatcher.group( 5 ).trim(); else value = varMatcher.group( 4 ); } ExportedVariable var = new ExportedVariable(); Matcher m = randomPattern.matcher( key ); if( m.matches()) { var.setRandom( true ); var.setRawKind( m.group( 1 )); key = m.group( 2 ).trim(); } var.setName( key.trim()); if( value != null ) var.setValue( value ); result.put( var.getName(), var ); } return result; } }
VariableHelpers { public static Map<String,ExportedVariable> parseExportedVariables( String line ) { Pattern randomPattern = Pattern.compile( ParsingConstants.PROPERTY_GRAPH_RANDOM_PATTERN, Pattern.CASE_INSENSITIVE ); Pattern varPattern = Pattern.compile( "([^,=]+)(\\s*=\\s*(\"([^\",]+)\"|([^,]+)))?" ); Map<String,ExportedVariable> result = new LinkedHashMap<> (); Matcher varMatcher = varPattern.matcher( line ); while( varMatcher.find()) { String key = varMatcher.group( 1 ).trim(); if( Utils.isEmptyOrWhitespaces( key )) continue; String value = null; if( varMatcher.group( 3 ) != null ) { if( varMatcher.group( 5 ) != null ) value = varMatcher.group( 5 ).trim(); else value = varMatcher.group( 4 ); } ExportedVariable var = new ExportedVariable(); Matcher m = randomPattern.matcher( key ); if( m.matches()) { var.setRandom( true ); var.setRawKind( m.group( 1 )); key = m.group( 2 ).trim(); } var.setName( key.trim()); if( value != null ) var.setValue( value ); result.put( var.getName(), var ); } return result; } private  VariableHelpers(); }
VariableHelpers { public static Map<String,ExportedVariable> parseExportedVariables( String line ) { Pattern randomPattern = Pattern.compile( ParsingConstants.PROPERTY_GRAPH_RANDOM_PATTERN, Pattern.CASE_INSENSITIVE ); Pattern varPattern = Pattern.compile( "([^,=]+)(\\s*=\\s*(\"([^\",]+)\"|([^,]+)))?" ); Map<String,ExportedVariable> result = new LinkedHashMap<> (); Matcher varMatcher = varPattern.matcher( line ); while( varMatcher.find()) { String key = varMatcher.group( 1 ).trim(); if( Utils.isEmptyOrWhitespaces( key )) continue; String value = null; if( varMatcher.group( 3 ) != null ) { if( varMatcher.group( 5 ) != null ) value = varMatcher.group( 5 ).trim(); else value = varMatcher.group( 4 ); } ExportedVariable var = new ExportedVariable(); Matcher m = randomPattern.matcher( key ); if( m.matches()) { var.setRandom( true ); var.setRawKind( m.group( 1 )); key = m.group( 2 ).trim(); } var.setName( key.trim()); if( value != null ) var.setValue( value ); result.put( var.getName(), var ); } return result; } private  VariableHelpers(); static Map.Entry<String,String> parseVariableName( String variableName ); static Map.Entry<String,String> parseExportedVariable( String exportedVariable ); static Map<String,ExportedVariable> parseExportedVariables( String line ); static Set<String> findPrefixesForExportedVariables( Instance instance ); static Set<String> findPrefixesForImportedVariables( Instance instance ); static Set<String> findPrefixesForMandatoryImportedVariables( Instance instance ); static Set<String> findPrefixesForExternalImports( AbstractApplication app ); }
VariableHelpers { public static Map<String,ExportedVariable> parseExportedVariables( String line ) { Pattern randomPattern = Pattern.compile( ParsingConstants.PROPERTY_GRAPH_RANDOM_PATTERN, Pattern.CASE_INSENSITIVE ); Pattern varPattern = Pattern.compile( "([^,=]+)(\\s*=\\s*(\"([^\",]+)\"|([^,]+)))?" ); Map<String,ExportedVariable> result = new LinkedHashMap<> (); Matcher varMatcher = varPattern.matcher( line ); while( varMatcher.find()) { String key = varMatcher.group( 1 ).trim(); if( Utils.isEmptyOrWhitespaces( key )) continue; String value = null; if( varMatcher.group( 3 ) != null ) { if( varMatcher.group( 5 ) != null ) value = varMatcher.group( 5 ).trim(); else value = varMatcher.group( 4 ); } ExportedVariable var = new ExportedVariable(); Matcher m = randomPattern.matcher( key ); if( m.matches()) { var.setRandom( true ); var.setRawKind( m.group( 1 )); key = m.group( 2 ).trim(); } var.setName( key.trim()); if( value != null ) var.setValue( value ); result.put( var.getName(), var ); } return result; } private  VariableHelpers(); static Map.Entry<String,String> parseVariableName( String variableName ); static Map.Entry<String,String> parseExportedVariable( String exportedVariable ); static Map<String,ExportedVariable> parseExportedVariables( String line ); static Set<String> findPrefixesForExportedVariables( Instance instance ); static Set<String> findPrefixesForImportedVariables( Instance instance ); static Set<String> findPrefixesForMandatoryImportedVariables( Instance instance ); static Set<String> findPrefixesForExternalImports( AbstractApplication app );  }