id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
15,900
rundeck/rundeck
rundeck-storage/rundeck-storage-conf/src/main/java/org/rundeck/storage/conf/TreeStack.java
TreeStack.listStackDirectory
private Set<Resource<T>> listStackDirectory(Path path) { HashSet<Resource<T>> merge = new HashSet<Resource<T>>(); if (treeHandlerList.size() > 0) { for (SelectiveTree<T> treeHandler : treeHandlerList) { if (PathUtil.hasRoot(treeHandler.getSubPath(), path) && !PathUtil.equals( treeHandler.getSubPath(), path )) { String relativePath = PathUtil.removePrefix(path.getPath(), treeHandler.getSubPath().getPath()); String[] components = PathUtil.componentsFromPathString(relativePath); Path subpath = PathUtil.appendPath(path, components[0]); merge.add(new ResourceBase<T>(subpath, null, true)); } } } return merge; }
java
private Set<Resource<T>> listStackDirectory(Path path) { HashSet<Resource<T>> merge = new HashSet<Resource<T>>(); if (treeHandlerList.size() > 0) { for (SelectiveTree<T> treeHandler : treeHandlerList) { if (PathUtil.hasRoot(treeHandler.getSubPath(), path) && !PathUtil.equals( treeHandler.getSubPath(), path )) { String relativePath = PathUtil.removePrefix(path.getPath(), treeHandler.getSubPath().getPath()); String[] components = PathUtil.componentsFromPathString(relativePath); Path subpath = PathUtil.appendPath(path, components[0]); merge.add(new ResourceBase<T>(subpath, null, true)); } } } return merge; }
[ "private", "Set", "<", "Resource", "<", "T", ">", ">", "listStackDirectory", "(", "Path", "path", ")", "{", "HashSet", "<", "Resource", "<", "T", ">>", "merge", "=", "new", "HashSet", "<", "Resource", "<", "T", ">", ">", "(", ")", ";", "if", "(", "treeHandlerList", ".", "size", "(", ")", ">", "0", ")", "{", "for", "(", "SelectiveTree", "<", "T", ">", "treeHandler", ":", "treeHandlerList", ")", "{", "if", "(", "PathUtil", ".", "hasRoot", "(", "treeHandler", ".", "getSubPath", "(", ")", ",", "path", ")", "&&", "!", "PathUtil", ".", "equals", "(", "treeHandler", ".", "getSubPath", "(", ")", ",", "path", ")", ")", "{", "String", "relativePath", "=", "PathUtil", ".", "removePrefix", "(", "path", ".", "getPath", "(", ")", ",", "treeHandler", ".", "getSubPath", "(", ")", ".", "getPath", "(", ")", ")", ";", "String", "[", "]", "components", "=", "PathUtil", ".", "componentsFromPathString", "(", "relativePath", ")", ";", "Path", "subpath", "=", "PathUtil", ".", "appendPath", "(", "path", ",", "components", "[", "0", "]", ")", ";", "merge", ".", "add", "(", "new", "ResourceBase", "<", "T", ">", "(", "subpath", ",", "null", ",", "true", ")", ")", ";", "}", "}", "}", "return", "merge", ";", "}" ]
List all treeHandlers as directories which have the given path as a parent @param path path @return
[ "List", "all", "treeHandlers", "as", "directories", "which", "have", "the", "given", "path", "as", "a", "parent" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-conf/src/main/java/org/rundeck/storage/conf/TreeStack.java#L156-L172
15,901
rundeck/rundeck
plugins/orchestrator-plugin/src/main/java/org/rundeck/plugin/example/RandomSubsetOrchestratorPlugin.java
RandomSubsetOrchestratorPlugin.genSeed
public static long genSeed(final String ident) { try { MessageDigest instance = MessageDigest.getInstance("SHA-1"); byte[] strbytes = ident.getBytes("UTF-8"); byte[] digest = instance.digest(strbytes); //use first 8 bytes as a long return ByteBuffer.wrap(digest, 0, Long.BYTES).getLong(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { //not random looking return ident.hashCode(); } }
java
public static long genSeed(final String ident) { try { MessageDigest instance = MessageDigest.getInstance("SHA-1"); byte[] strbytes = ident.getBytes("UTF-8"); byte[] digest = instance.digest(strbytes); //use first 8 bytes as a long return ByteBuffer.wrap(digest, 0, Long.BYTES).getLong(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { //not random looking return ident.hashCode(); } }
[ "public", "static", "long", "genSeed", "(", "final", "String", "ident", ")", "{", "try", "{", "MessageDigest", "instance", "=", "MessageDigest", ".", "getInstance", "(", "\"SHA-1\"", ")", ";", "byte", "[", "]", "strbytes", "=", "ident", ".", "getBytes", "(", "\"UTF-8\"", ")", ";", "byte", "[", "]", "digest", "=", "instance", ".", "digest", "(", "strbytes", ")", ";", "//use first 8 bytes as a long", "return", "ByteBuffer", ".", "wrap", "(", "digest", ",", "0", ",", "Long", ".", "BYTES", ")", ".", "getLong", "(", ")", ";", "}", "catch", "(", "NoSuchAlgorithmException", "|", "UnsupportedEncodingException", "e", ")", "{", "//not random looking", "return", "ident", ".", "hashCode", "(", ")", ";", "}", "}" ]
generate random seed from unique ident string @param ident @return seed long
[ "generate", "random", "seed", "from", "unique", "ident", "string" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/plugins/orchestrator-plugin/src/main/java/org/rundeck/plugin/example/RandomSubsetOrchestratorPlugin.java#L58-L70
15,902
rundeck/rundeck
examples/example-java-logging-plugins/src/main/java/com/dtolabs/rundeck/plugin/example/ExampleStreamingLogWriterPlugin.java
ExampleStreamingLogWriterPlugin.openStream
public void openStream() throws IOException { socket = new Socket(host, port); socketStream = socket.getOutputStream(); if (null != context.get("name") && null != context.get("id")) { Object group = context.get("group"); String desc = (null != group ? group + "/" : "") + context.get("name"); write("Job started: " + desc + ": " + context.get("id")); } write("Execution: " + context.get("execid")); }
java
public void openStream() throws IOException { socket = new Socket(host, port); socketStream = socket.getOutputStream(); if (null != context.get("name") && null != context.get("id")) { Object group = context.get("group"); String desc = (null != group ? group + "/" : "") + context.get("name"); write("Job started: " + desc + ": " + context.get("id")); } write("Execution: " + context.get("execid")); }
[ "public", "void", "openStream", "(", ")", "throws", "IOException", "{", "socket", "=", "new", "Socket", "(", "host", ",", "port", ")", ";", "socketStream", "=", "socket", ".", "getOutputStream", "(", ")", ";", "if", "(", "null", "!=", "context", ".", "get", "(", "\"name\"", ")", "&&", "null", "!=", "context", ".", "get", "(", "\"id\"", ")", ")", "{", "Object", "group", "=", "context", ".", "get", "(", "\"group\"", ")", ";", "String", "desc", "=", "(", "null", "!=", "group", "?", "group", "+", "\"/\"", ":", "\"\"", ")", "+", "context", ".", "get", "(", "\"name\"", ")", ";", "write", "(", "\"Job started: \"", "+", "desc", "+", "\": \"", "+", "context", ".", "get", "(", "\"id\"", ")", ")", ";", "}", "write", "(", "\"Execution: \"", "+", "context", ".", "get", "(", "\"execid\"", ")", ")", ";", "}" ]
Open a stream, called before addEntry is called
[ "Open", "a", "stream", "called", "before", "addEntry", "is", "called" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/examples/example-java-logging-plugins/src/main/java/com/dtolabs/rundeck/plugin/example/ExampleStreamingLogWriterPlugin.java#L39-L48
15,903
rundeck/rundeck
examples/example-java-logging-plugins/src/main/java/com/dtolabs/rundeck/plugin/example/ExampleStreamingLogWriterPlugin.java
ExampleStreamingLogWriterPlugin.addEvent
public void addEvent(LogEvent event) { try { write(getString(event)); } catch (IOException e) { e.printStackTrace(); } }
java
public void addEvent(LogEvent event) { try { write(getString(event)); } catch (IOException e) { e.printStackTrace(); } }
[ "public", "void", "addEvent", "(", "LogEvent", "event", ")", "{", "try", "{", "write", "(", "getString", "(", "event", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}" ]
Add a new event @param event
[ "Add", "a", "new", "event" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/examples/example-java-logging-plugins/src/main/java/com/dtolabs/rundeck/plugin/example/ExampleStreamingLogWriterPlugin.java#L55-L61
15,904
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/data/SharedDataContextUtils.java
SharedDataContextUtils.escapeShell
public static String escapeShell(final String s) { if(null==s){ return s; } if (s.startsWith("'") && s.endsWith("'")) { return s; } else if (s.startsWith("\"") && s.endsWith("\"")) { return s.replaceAll("([\\\\`])", "\\\\$1"); } return s.replaceAll("([&><|;\\\\`])", "\\\\$1"); }
java
public static String escapeShell(final String s) { if(null==s){ return s; } if (s.startsWith("'") && s.endsWith("'")) { return s; } else if (s.startsWith("\"") && s.endsWith("\"")) { return s.replaceAll("([\\\\`])", "\\\\$1"); } return s.replaceAll("([&><|;\\\\`])", "\\\\$1"); }
[ "public", "static", "String", "escapeShell", "(", "final", "String", "s", ")", "{", "if", "(", "null", "==", "s", ")", "{", "return", "s", ";", "}", "if", "(", "s", ".", "startsWith", "(", "\"'\"", ")", "&&", "s", ".", "endsWith", "(", "\"'\"", ")", ")", "{", "return", "s", ";", "}", "else", "if", "(", "s", ".", "startsWith", "(", "\"\\\"\"", ")", "&&", "s", ".", "endsWith", "(", "\"\\\"\"", ")", ")", "{", "return", "s", ".", "replaceAll", "(", "\"([\\\\\\\\`])\"", ",", "\"\\\\\\\\$1\"", ")", ";", "}", "return", "s", ".", "replaceAll", "(", "\"([&><|;\\\\\\\\`])\"", ",", "\"\\\\\\\\$1\"", ")", ";", "}" ]
Escape characters meaningful to bash shell unless the string is already surrounded in single quotes @param s string @return escaped string
[ "Escape", "characters", "meaningful", "to", "bash", "shell", "unless", "the", "string", "is", "already", "surrounded", "in", "single", "quotes" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/data/SharedDataContextUtils.java#L179-L189
15,905
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/data/SharedDataContextUtils.java
SharedDataContextUtils.escapeWindowsShell
public static String escapeWindowsShell(final String s) { if (null == s) { return s; } if (s.startsWith("'") && s.endsWith("'")) { return s; } else if (s.startsWith("\"") && s.endsWith("\"")) { return s.replaceAll("([`^])", "^$1"); } return s.replaceAll("([&><|;^`])", "^$1"); }
java
public static String escapeWindowsShell(final String s) { if (null == s) { return s; } if (s.startsWith("'") && s.endsWith("'")) { return s; } else if (s.startsWith("\"") && s.endsWith("\"")) { return s.replaceAll("([`^])", "^$1"); } return s.replaceAll("([&><|;^`])", "^$1"); }
[ "public", "static", "String", "escapeWindowsShell", "(", "final", "String", "s", ")", "{", "if", "(", "null", "==", "s", ")", "{", "return", "s", ";", "}", "if", "(", "s", ".", "startsWith", "(", "\"'\"", ")", "&&", "s", ".", "endsWith", "(", "\"'\"", ")", ")", "{", "return", "s", ";", "}", "else", "if", "(", "s", ".", "startsWith", "(", "\"\\\"\"", ")", "&&", "s", ".", "endsWith", "(", "\"\\\"\"", ")", ")", "{", "return", "s", ".", "replaceAll", "(", "\"([`^])\"", ",", "\"^$1\"", ")", ";", "}", "return", "s", ".", "replaceAll", "(", "\"([&><|;^`])\"", ",", "\"^$1\"", ")", ";", "}" ]
Escape characters meaningful to windows unless the string is already surrounded in single quotes @param s string @return escaped string
[ "Escape", "characters", "meaningful", "to", "windows", "unless", "the", "string", "is", "already", "surrounded", "in", "single", "quotes" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/data/SharedDataContextUtils.java#L198-L208
15,906
rundeck/rundeck
core/src/main/java/com/dtolabs/utils/PropertiesUtil.java
PropertiesUtil.stringFromProperties
public static String stringFromProperties(Properties props) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); props.store(baos, null); String propsString; propsString = URLEncoder.encode(baos.toString("ISO-8859-1"), "ISO-8859-1"); return propsString; }
java
public static String stringFromProperties(Properties props) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); props.store(baos, null); String propsString; propsString = URLEncoder.encode(baos.toString("ISO-8859-1"), "ISO-8859-1"); return propsString; }
[ "public", "static", "String", "stringFromProperties", "(", "Properties", "props", ")", "throws", "IOException", "{", "ByteArrayOutputStream", "baos", "=", "new", "ByteArrayOutputStream", "(", "2048", ")", ";", "props", ".", "store", "(", "baos", ",", "null", ")", ";", "String", "propsString", ";", "propsString", "=", "URLEncoder", ".", "encode", "(", "baos", ".", "toString", "(", "\"ISO-8859-1\"", ")", ",", "\"ISO-8859-1\"", ")", ";", "return", "propsString", ";", "}" ]
Returns the Properties formatted as a String @param props properties @return String format from the Properties @throws java.io.IOException if an error occurs
[ "Returns", "the", "Properties", "formatted", "as", "a", "String" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/utils/PropertiesUtil.java#L54-L62
15,907
rundeck/rundeck
core/src/main/java/com/dtolabs/utils/PropertiesUtil.java
PropertiesUtil.propertiesFromString
public static Properties propertiesFromString(String propString) throws IOException { Properties props = new Properties(); String pstring = URLDecoder.decode(propString, "ISO-8859-1"); props.load(new ByteArrayInputStream(pstring.getBytes())); return props; }
java
public static Properties propertiesFromString(String propString) throws IOException { Properties props = new Properties(); String pstring = URLDecoder.decode(propString, "ISO-8859-1"); props.load(new ByteArrayInputStream(pstring.getBytes())); return props; }
[ "public", "static", "Properties", "propertiesFromString", "(", "String", "propString", ")", "throws", "IOException", "{", "Properties", "props", "=", "new", "Properties", "(", ")", ";", "String", "pstring", "=", "URLDecoder", ".", "decode", "(", "propString", ",", "\"ISO-8859-1\"", ")", ";", "props", ".", "load", "(", "new", "ByteArrayInputStream", "(", "pstring", ".", "getBytes", "(", ")", ")", ")", ";", "return", "props", ";", "}" ]
Convert a String into a Properties object @param propString properties string @return properties @throws IOException if an error occurs
[ "Convert", "a", "String", "into", "a", "Properties", "object" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/utils/PropertiesUtil.java#L73-L82
15,908
rundeck/rundeck
core/src/main/java/com/dtolabs/utils/PropertiesUtil.java
PropertiesUtil.listPropertiesWithPrefix
public static Collection listPropertiesWithPrefix(Properties props, String prefix) { final HashSet set = new HashSet(); for (Iterator i = props.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); if (key.startsWith(prefix)) { set.add(props.getProperty(key)); } } return set; }
java
public static Collection listPropertiesWithPrefix(Properties props, String prefix) { final HashSet set = new HashSet(); for (Iterator i = props.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); if (key.startsWith(prefix)) { set.add(props.getProperty(key)); } } return set; }
[ "public", "static", "Collection", "listPropertiesWithPrefix", "(", "Properties", "props", ",", "String", "prefix", ")", "{", "final", "HashSet", "set", "=", "new", "HashSet", "(", ")", ";", "for", "(", "Iterator", "i", "=", "props", ".", "keySet", "(", ")", ".", "iterator", "(", ")", ";", "i", ".", "hasNext", "(", ")", ";", ")", "{", "String", "key", "=", "(", "String", ")", "i", ".", "next", "(", ")", ";", "if", "(", "key", ".", "startsWith", "(", "prefix", ")", ")", "{", "set", ".", "add", "(", "props", ".", "getProperty", "(", "key", ")", ")", ";", "}", "}", "return", "set", ";", "}" ]
Returns a Collection of all property values that have keys with a certain prefix. @param props the Properties to reaqd @param prefix the prefix @return Collection of all property values with keys with a certain prefix
[ "Returns", "a", "Collection", "of", "all", "property", "values", "that", "have", "keys", "with", "a", "certain", "prefix", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/utils/PropertiesUtil.java#L125-L134
15,909
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java
AbstractDescribableScriptPlugin.loadConfigData
protected Map<String, Map<String, String>> loadConfigData( final ExecutionContext context, final Map<String, Object> instanceData, final Map<String, Map<String, String>> localDataContext, final Description description, final String serviceName ) throws ConfigurationException { final PropertyResolver resolver = PropertyResolverFactory.createPluginRuntimeResolver( context, instanceData, serviceName, getProvider().getName() ); final Map<String, Object> config = PluginAdapterUtility.mapDescribedProperties( resolver, description, PropertyScope.Instance ); //expand properties Map<String, Object> expanded = DataContextUtils.replaceDataReferences( config, localDataContext ); Map<String, String> data = MapData.toStringStringMap(expanded); loadContentConversionPropertyValues( data, context, description.getProperties() ); Map<String, Map<String, String>> newLocalDataContext = localDataContext; VersionCompare pluginVersion = VersionCompare.forString(provider.getPluginMeta().getRundeckPluginVersion()); if(pluginVersion.atLeast(VersionCompare.forString(ScriptPluginProviderLoader.VERSION_2_0))){ //new context variable name newLocalDataContext = DataContextUtils.addContext(serviceName.toLowerCase(), data, localDataContext); } //using "config" name to old plugins return DataContextUtils.addContext("config", data, newLocalDataContext); }
java
protected Map<String, Map<String, String>> loadConfigData( final ExecutionContext context, final Map<String, Object> instanceData, final Map<String, Map<String, String>> localDataContext, final Description description, final String serviceName ) throws ConfigurationException { final PropertyResolver resolver = PropertyResolverFactory.createPluginRuntimeResolver( context, instanceData, serviceName, getProvider().getName() ); final Map<String, Object> config = PluginAdapterUtility.mapDescribedProperties( resolver, description, PropertyScope.Instance ); //expand properties Map<String, Object> expanded = DataContextUtils.replaceDataReferences( config, localDataContext ); Map<String, String> data = MapData.toStringStringMap(expanded); loadContentConversionPropertyValues( data, context, description.getProperties() ); Map<String, Map<String, String>> newLocalDataContext = localDataContext; VersionCompare pluginVersion = VersionCompare.forString(provider.getPluginMeta().getRundeckPluginVersion()); if(pluginVersion.atLeast(VersionCompare.forString(ScriptPluginProviderLoader.VERSION_2_0))){ //new context variable name newLocalDataContext = DataContextUtils.addContext(serviceName.toLowerCase(), data, localDataContext); } //using "config" name to old plugins return DataContextUtils.addContext("config", data, newLocalDataContext); }
[ "protected", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "loadConfigData", "(", "final", "ExecutionContext", "context", ",", "final", "Map", "<", "String", ",", "Object", ">", "instanceData", ",", "final", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "localDataContext", ",", "final", "Description", "description", ",", "final", "String", "serviceName", ")", "throws", "ConfigurationException", "{", "final", "PropertyResolver", "resolver", "=", "PropertyResolverFactory", ".", "createPluginRuntimeResolver", "(", "context", ",", "instanceData", ",", "serviceName", ",", "getProvider", "(", ")", ".", "getName", "(", ")", ")", ";", "final", "Map", "<", "String", ",", "Object", ">", "config", "=", "PluginAdapterUtility", ".", "mapDescribedProperties", "(", "resolver", ",", "description", ",", "PropertyScope", ".", "Instance", ")", ";", "//expand properties", "Map", "<", "String", ",", "Object", ">", "expanded", "=", "DataContextUtils", ".", "replaceDataReferences", "(", "config", ",", "localDataContext", ")", ";", "Map", "<", "String", ",", "String", ">", "data", "=", "MapData", ".", "toStringStringMap", "(", "expanded", ")", ";", "loadContentConversionPropertyValues", "(", "data", ",", "context", ",", "description", ".", "getProperties", "(", ")", ")", ";", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "newLocalDataContext", "=", "localDataContext", ";", "VersionCompare", "pluginVersion", "=", "VersionCompare", ".", "forString", "(", "provider", ".", "getPluginMeta", "(", ")", ".", "getRundeckPluginVersion", "(", ")", ")", ";", "if", "(", "pluginVersion", ".", "atLeast", "(", "VersionCompare", ".", "forString", "(", "ScriptPluginProviderLoader", ".", "VERSION_2_0", ")", ")", ")", "{", "//new context variable name", "newLocalDataContext", "=", "DataContextUtils", ".", "addContext", "(", "serviceName", ".", "toLowerCase", "(", ")", ",", "data", ",", "localDataContext", ")", ";", "}", "//using \"config\" name to old plugins", "return", "DataContextUtils", ".", "addContext", "(", "\"config\"", ",", "data", ",", "newLocalDataContext", ")", ";", "}" ]
Loads the plugin configuration values stored in project or framework properties, also @param context execution context @param localDataContext current context data @param description plugin description @param instanceData instance data @param serviceName service name @return context data with a new "config" entry containing the loaded plugin config properties. @throws ConfigurationException configuration error
[ "Loads", "the", "plugin", "configuration", "values", "stored", "in", "project", "or", "framework", "properties", "also" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java#L326-L374
15,910
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java
AbstractDescribableScriptPlugin.loadContentConversionPropertyValues
protected void loadContentConversionPropertyValues( final Map<String, String> data, final ExecutionContext context, final List<Property> pluginProperties ) throws ConfigurationException { //look for "valueConversion" properties for (Property property : pluginProperties) { String name = property.getName(); String propValue = data.get(name); if (null == propValue) { continue; } Map<String, Object> renderingOptions = property.getRenderingOptions(); if (renderingOptions != null) { Object conversion = renderingOptions.get(StringRenderingConstants.VALUE_CONVERSION_KEY); if (StringRenderingConstants.ValueConversion.STORAGE_PATH_AUTOMATIC_READ.equalsOrString(conversion)) { convertStoragePathValue(data, context.getStorageTree(), name, propValue, renderingOptions); } else if (StringRenderingConstants.ValueConversion.PRIVATE_DATA_CONTEXT.equalsOrString(conversion)) { convertPrivateDataValue(data, context.getPrivateDataContextObject(), name, propValue, renderingOptions); } } } }
java
protected void loadContentConversionPropertyValues( final Map<String, String> data, final ExecutionContext context, final List<Property> pluginProperties ) throws ConfigurationException { //look for "valueConversion" properties for (Property property : pluginProperties) { String name = property.getName(); String propValue = data.get(name); if (null == propValue) { continue; } Map<String, Object> renderingOptions = property.getRenderingOptions(); if (renderingOptions != null) { Object conversion = renderingOptions.get(StringRenderingConstants.VALUE_CONVERSION_KEY); if (StringRenderingConstants.ValueConversion.STORAGE_PATH_AUTOMATIC_READ.equalsOrString(conversion)) { convertStoragePathValue(data, context.getStorageTree(), name, propValue, renderingOptions); } else if (StringRenderingConstants.ValueConversion.PRIVATE_DATA_CONTEXT.equalsOrString(conversion)) { convertPrivateDataValue(data, context.getPrivateDataContextObject(), name, propValue, renderingOptions); } } } }
[ "protected", "void", "loadContentConversionPropertyValues", "(", "final", "Map", "<", "String", ",", "String", ">", "data", ",", "final", "ExecutionContext", "context", ",", "final", "List", "<", "Property", ">", "pluginProperties", ")", "throws", "ConfigurationException", "{", "//look for \"valueConversion\" properties", "for", "(", "Property", "property", ":", "pluginProperties", ")", "{", "String", "name", "=", "property", ".", "getName", "(", ")", ";", "String", "propValue", "=", "data", ".", "get", "(", "name", ")", ";", "if", "(", "null", "==", "propValue", ")", "{", "continue", ";", "}", "Map", "<", "String", ",", "Object", ">", "renderingOptions", "=", "property", ".", "getRenderingOptions", "(", ")", ";", "if", "(", "renderingOptions", "!=", "null", ")", "{", "Object", "conversion", "=", "renderingOptions", ".", "get", "(", "StringRenderingConstants", ".", "VALUE_CONVERSION_KEY", ")", ";", "if", "(", "StringRenderingConstants", ".", "ValueConversion", ".", "STORAGE_PATH_AUTOMATIC_READ", ".", "equalsOrString", "(", "conversion", ")", ")", "{", "convertStoragePathValue", "(", "data", ",", "context", ".", "getStorageTree", "(", ")", ",", "name", ",", "propValue", ",", "renderingOptions", ")", ";", "}", "else", "if", "(", "StringRenderingConstants", ".", "ValueConversion", ".", "PRIVATE_DATA_CONTEXT", ".", "equalsOrString", "(", "conversion", ")", ")", "{", "convertPrivateDataValue", "(", "data", ",", "context", ".", "getPrivateDataContextObject", "(", ")", ",", "name", ",", "propValue", ",", "renderingOptions", ")", ";", "}", "}", "}", "}" ]
Looks for properties with content conversion, and converts the values @param data map of values for config properties @param context execution context @param pluginProperties definition of plugin properties
[ "Looks", "for", "properties", "with", "content", "conversion", "and", "converts", "the", "values" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java#L383-L407
15,911
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java
AbstractDescribableScriptPlugin.convertStoragePathValue
private void convertStoragePathValue( final Map<String, String> data, final StorageTree storageTree, final String name, final String propValue, final Map<String, Object> renderingOptions ) throws ConfigurationException { //a storage path property String root = null; if (null != renderingOptions.get( StringRenderingConstants.STORAGE_PATH_ROOT_KEY)) { root = renderingOptions.get(StringRenderingConstants.STORAGE_PATH_ROOT_KEY).toString(); } String filter = null; if (null != renderingOptions.get(StringRenderingConstants.STORAGE_FILE_META_FILTER_KEY)) { filter = renderingOptions.get(StringRenderingConstants.STORAGE_FILE_META_FILTER_KEY).toString(); } boolean clearValue = isValueConversionFailureRemove(renderingOptions); if (null != root && !PathUtil.hasRoot(propValue, root)) { if(clearValue) { data.remove(name); } return; } try { Resource<ResourceMeta> resource = storageTree.getResource(propValue); ResourceMeta contents = resource.getContents(); //test filter if (filter != null) { String[] filterComponents = filter.split("=", 2); if (filterComponents.length == 2) { String key = filterComponents[0]; String test = filterComponents[1]; Map<String, String> meta = contents.getMeta(); if (meta == null || !test.equals(meta.get(key))) { if(clearValue) { data.remove(name); } return; } } } //finally load storage contents into a string ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); contents.writeContent(byteArrayOutputStream); data.put(name, new String(byteArrayOutputStream.toByteArray())); } catch (StorageException | IOException e) { if(clearValue) { data.remove(name); return; } throw new ConfigurationException("Unable to load configuration key '" + name + "' value from storage path: " + propValue, e); } }
java
private void convertStoragePathValue( final Map<String, String> data, final StorageTree storageTree, final String name, final String propValue, final Map<String, Object> renderingOptions ) throws ConfigurationException { //a storage path property String root = null; if (null != renderingOptions.get( StringRenderingConstants.STORAGE_PATH_ROOT_KEY)) { root = renderingOptions.get(StringRenderingConstants.STORAGE_PATH_ROOT_KEY).toString(); } String filter = null; if (null != renderingOptions.get(StringRenderingConstants.STORAGE_FILE_META_FILTER_KEY)) { filter = renderingOptions.get(StringRenderingConstants.STORAGE_FILE_META_FILTER_KEY).toString(); } boolean clearValue = isValueConversionFailureRemove(renderingOptions); if (null != root && !PathUtil.hasRoot(propValue, root)) { if(clearValue) { data.remove(name); } return; } try { Resource<ResourceMeta> resource = storageTree.getResource(propValue); ResourceMeta contents = resource.getContents(); //test filter if (filter != null) { String[] filterComponents = filter.split("=", 2); if (filterComponents.length == 2) { String key = filterComponents[0]; String test = filterComponents[1]; Map<String, String> meta = contents.getMeta(); if (meta == null || !test.equals(meta.get(key))) { if(clearValue) { data.remove(name); } return; } } } //finally load storage contents into a string ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); contents.writeContent(byteArrayOutputStream); data.put(name, new String(byteArrayOutputStream.toByteArray())); } catch (StorageException | IOException e) { if(clearValue) { data.remove(name); return; } throw new ConfigurationException("Unable to load configuration key '" + name + "' value from storage path: " + propValue, e); } }
[ "private", "void", "convertStoragePathValue", "(", "final", "Map", "<", "String", ",", "String", ">", "data", ",", "final", "StorageTree", "storageTree", ",", "final", "String", "name", ",", "final", "String", "propValue", ",", "final", "Map", "<", "String", ",", "Object", ">", "renderingOptions", ")", "throws", "ConfigurationException", "{", "//a storage path property", "String", "root", "=", "null", ";", "if", "(", "null", "!=", "renderingOptions", ".", "get", "(", "StringRenderingConstants", ".", "STORAGE_PATH_ROOT_KEY", ")", ")", "{", "root", "=", "renderingOptions", ".", "get", "(", "StringRenderingConstants", ".", "STORAGE_PATH_ROOT_KEY", ")", ".", "toString", "(", ")", ";", "}", "String", "filter", "=", "null", ";", "if", "(", "null", "!=", "renderingOptions", ".", "get", "(", "StringRenderingConstants", ".", "STORAGE_FILE_META_FILTER_KEY", ")", ")", "{", "filter", "=", "renderingOptions", ".", "get", "(", "StringRenderingConstants", ".", "STORAGE_FILE_META_FILTER_KEY", ")", ".", "toString", "(", ")", ";", "}", "boolean", "clearValue", "=", "isValueConversionFailureRemove", "(", "renderingOptions", ")", ";", "if", "(", "null", "!=", "root", "&&", "!", "PathUtil", ".", "hasRoot", "(", "propValue", ",", "root", ")", ")", "{", "if", "(", "clearValue", ")", "{", "data", ".", "remove", "(", "name", ")", ";", "}", "return", ";", "}", "try", "{", "Resource", "<", "ResourceMeta", ">", "resource", "=", "storageTree", ".", "getResource", "(", "propValue", ")", ";", "ResourceMeta", "contents", "=", "resource", ".", "getContents", "(", ")", ";", "//test filter", "if", "(", "filter", "!=", "null", ")", "{", "String", "[", "]", "filterComponents", "=", "filter", ".", "split", "(", "\"=\"", ",", "2", ")", ";", "if", "(", "filterComponents", ".", "length", "==", "2", ")", "{", "String", "key", "=", "filterComponents", "[", "0", "]", ";", "String", "test", "=", "filterComponents", "[", "1", "]", ";", "Map", "<", "String", ",", "String", ">", "meta", "=", "contents", ".", "getMeta", "(", ")", ";", "if", "(", "meta", "==", "null", "||", "!", "test", ".", "equals", "(", "meta", ".", "get", "(", "key", ")", ")", ")", "{", "if", "(", "clearValue", ")", "{", "data", ".", "remove", "(", "name", ")", ";", "}", "return", ";", "}", "}", "}", "//finally load storage contents into a string", "ByteArrayOutputStream", "byteArrayOutputStream", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "contents", ".", "writeContent", "(", "byteArrayOutputStream", ")", ";", "data", ".", "put", "(", "name", ",", "new", "String", "(", "byteArrayOutputStream", ".", "toByteArray", "(", ")", ")", ")", ";", "}", "catch", "(", "StorageException", "|", "IOException", "e", ")", "{", "if", "(", "clearValue", ")", "{", "data", ".", "remove", "(", "name", ")", ";", "return", ";", "}", "throw", "new", "ConfigurationException", "(", "\"Unable to load configuration key '\"", "+", "name", "+", "\"' value from storage path: \"", "+", "propValue", ",", "e", ")", ";", "}", "}" ]
Converts storage path properties by loading the values into the config data. @param data config data @param storageTree storage @param name property name @param propValue value to convert @param renderingOptions options @throws ConfigurationException
[ "Converts", "storage", "path", "properties", "by", "loading", "the", "values", "into", "the", "config", "data", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java#L418-L472
15,912
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java
AbstractDescribableScriptPlugin.convertPrivateDataValue
private void convertPrivateDataValue( final Map<String, String> data, final DataContext privateDataContext, final String name, final String propValue, final Map<String, Object> renderingOptions ) throws ConfigurationException { boolean clearValue = isValueConversionFailureRemove(renderingOptions); String[] prop = propValue.split("\\.", 2); if (prop.length < 2 || prop[0].length() < 1 || prop[1].length() < 1) { throw new ConfigurationException( "Unable to load '" + name + "' configuration value: Expected 'option.name' format, but saw: " + propValue ); } String newvalue = privateDataContext.resolve(prop[0], prop[1]); if (null == newvalue) { if(clearValue) { data.remove(name); } return; } data.put(name, newvalue); }
java
private void convertPrivateDataValue( final Map<String, String> data, final DataContext privateDataContext, final String name, final String propValue, final Map<String, Object> renderingOptions ) throws ConfigurationException { boolean clearValue = isValueConversionFailureRemove(renderingOptions); String[] prop = propValue.split("\\.", 2); if (prop.length < 2 || prop[0].length() < 1 || prop[1].length() < 1) { throw new ConfigurationException( "Unable to load '" + name + "' configuration value: Expected 'option.name' format, but saw: " + propValue ); } String newvalue = privateDataContext.resolve(prop[0], prop[1]); if (null == newvalue) { if(clearValue) { data.remove(name); } return; } data.put(name, newvalue); }
[ "private", "void", "convertPrivateDataValue", "(", "final", "Map", "<", "String", ",", "String", ">", "data", ",", "final", "DataContext", "privateDataContext", ",", "final", "String", "name", ",", "final", "String", "propValue", ",", "final", "Map", "<", "String", ",", "Object", ">", "renderingOptions", ")", "throws", "ConfigurationException", "{", "boolean", "clearValue", "=", "isValueConversionFailureRemove", "(", "renderingOptions", ")", ";", "String", "[", "]", "prop", "=", "propValue", ".", "split", "(", "\"\\\\.\"", ",", "2", ")", ";", "if", "(", "prop", ".", "length", "<", "2", "||", "prop", "[", "0", "]", ".", "length", "(", ")", "<", "1", "||", "prop", "[", "1", "]", ".", "length", "(", ")", "<", "1", ")", "{", "throw", "new", "ConfigurationException", "(", "\"Unable to load '\"", "+", "name", "+", "\"' configuration value: Expected 'option.name' format, but saw: \"", "+", "propValue", ")", ";", "}", "String", "newvalue", "=", "privateDataContext", ".", "resolve", "(", "prop", "[", "0", "]", ",", "prop", "[", "1", "]", ")", ";", "if", "(", "null", "==", "newvalue", ")", "{", "if", "(", "clearValue", ")", "{", "data", ".", "remove", "(", "name", ")", ";", "}", "return", ";", "}", "data", ".", "put", "(", "name", ",", "newvalue", ")", ";", "}" ]
Converts properties that refer to a private data context value @param data config data @param privateDataContext private data @param name property name @param propValue value to convert
[ "Converts", "properties", "that", "refer", "to", "a", "private", "data", "context", "value" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/AbstractDescribableScriptPlugin.java#L481-L509
15,913
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/tasks/net/ThreadBoundJschLogger.java
ThreadBoundJschLogger.getInstance
public static ThreadBoundJschLogger getInstance(final PluginLogger logger, final int loggingLevel) { getInstance(); instance.setThreadLogger(logger, loggingLevel); return instance; }
java
public static ThreadBoundJschLogger getInstance(final PluginLogger logger, final int loggingLevel) { getInstance(); instance.setThreadLogger(logger, loggingLevel); return instance; }
[ "public", "static", "ThreadBoundJschLogger", "getInstance", "(", "final", "PluginLogger", "logger", ",", "final", "int", "loggingLevel", ")", "{", "getInstance", "(", ")", ";", "instance", ".", "setThreadLogger", "(", "logger", ",", "loggingLevel", ")", ";", "return", "instance", ";", "}" ]
Bind to static Jsch logger, and return the logger instance @return the shared instance @param logger logger @param loggingLevel level
[ "Bind", "to", "static", "Jsch", "logger", "and", "return", "the", "logger", "instance" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/tasks/net/ThreadBoundJschLogger.java#L58-L62
15,914
rundeck/rundeck
rundeck-storage/rundeck-storage-filesys/src/main/java/org/rundeck/storage/data/file/FileTree.java
FileTree.filterResources
private Set<Resource<T>> filterResources(Path path, Predicate<Resource> test) { validatePath(path); if (!hasDirectory(path)) { throw StorageException.listException(path, "not a directory path: " + path); } File file = filepathMapper.directoryForPath(path); HashSet<Resource<T>> files = new HashSet<Resource<T>>(); try { for (File file1 : file.listFiles()) { Resource<T> res = loadResource(filepathMapper.pathForContentFile(file1), false); if (null == test || test.apply(res)) { files.add(res); } } } catch (IOException e) { throw StorageException.listException(path, "Failed to list directory: " + path + ": " + e.getMessage(), e); } return files; }
java
private Set<Resource<T>> filterResources(Path path, Predicate<Resource> test) { validatePath(path); if (!hasDirectory(path)) { throw StorageException.listException(path, "not a directory path: " + path); } File file = filepathMapper.directoryForPath(path); HashSet<Resource<T>> files = new HashSet<Resource<T>>(); try { for (File file1 : file.listFiles()) { Resource<T> res = loadResource(filepathMapper.pathForContentFile(file1), false); if (null == test || test.apply(res)) { files.add(res); } } } catch (IOException e) { throw StorageException.listException(path, "Failed to list directory: " + path + ": " + e.getMessage(), e); } return files; }
[ "private", "Set", "<", "Resource", "<", "T", ">", ">", "filterResources", "(", "Path", "path", ",", "Predicate", "<", "Resource", ">", "test", ")", "{", "validatePath", "(", "path", ")", ";", "if", "(", "!", "hasDirectory", "(", "path", ")", ")", "{", "throw", "StorageException", ".", "listException", "(", "path", ",", "\"not a directory path: \"", "+", "path", ")", ";", "}", "File", "file", "=", "filepathMapper", ".", "directoryForPath", "(", "path", ")", ";", "HashSet", "<", "Resource", "<", "T", ">", ">", "files", "=", "new", "HashSet", "<", "Resource", "<", "T", ">", ">", "(", ")", ";", "try", "{", "for", "(", "File", "file1", ":", "file", ".", "listFiles", "(", ")", ")", "{", "Resource", "<", "T", ">", "res", "=", "loadResource", "(", "filepathMapper", ".", "pathForContentFile", "(", "file1", ")", ",", "false", ")", ";", "if", "(", "null", "==", "test", "||", "test", ".", "apply", "(", "res", ")", ")", "{", "files", ".", "add", "(", "res", ")", ";", "}", "}", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "StorageException", ".", "listException", "(", "path", ",", "\"Failed to list directory: \"", "+", "path", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "return", "files", ";", "}" ]
Return a filtered set of resources @param path path @param test predicate test, or null to match all @return set of matching resources
[ "Return", "a", "filtered", "set", "of", "resources" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-filesys/src/main/java/org/rundeck/storage/data/file/FileTree.java#L163-L181
15,915
rundeck/rundeck
rundeck-storage/rundeck-storage-filesys/src/main/java/org/rundeck/storage/data/file/LockingTree.java
LockingTree.pathSynch
protected Object pathSynch(Path path) { Object newref = new Object(); Object oldref = locks.putIfAbsent(path.getPath(), newref); return null != oldref ? oldref : newref; }
java
protected Object pathSynch(Path path) { Object newref = new Object(); Object oldref = locks.putIfAbsent(path.getPath(), newref); return null != oldref ? oldref : newref; }
[ "protected", "Object", "pathSynch", "(", "Path", "path", ")", "{", "Object", "newref", "=", "new", "Object", "(", ")", ";", "Object", "oldref", "=", "locks", ".", "putIfAbsent", "(", "path", ".", "getPath", "(", ")", ",", "newref", ")", ";", "return", "null", "!=", "oldref", "?", "oldref", ":", "newref", ";", "}" ]
Return an object that can be synchronized on for the given path. @param path path @return synch object
[ "Return", "an", "object", "that", "can", "be", "synchronized", "on", "for", "the", "given", "path", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-filesys/src/main/java/org/rundeck/storage/data/file/LockingTree.java#L47-L51
15,916
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/YamlPolicyCollection.java
YamlPolicyCollection.load
private <T> void load(YamlSourceLoader<T> loader, YamlPolicyCreator<T> creator) throws IOException { int index = 1; try (final YamlSourceLoader<T> loader1 = loader) { for (T yamlDoc : loader1.loadAll()) { String ident = identity + "[" + index + "]"; if (null == yamlDoc) { continue; } try { Policy yamlPolicy = creator.createYamlPolicy( yamlDoc, identity + "[" + index + "]", index ); all.add(yamlPolicy); ruleSet.addAll(yamlPolicy.getRuleSet().getRules()); } catch (AclPolicySyntaxException e) { validationError(ident, e.getMessage()); logger.debug( "ERROR parsing a policy in file: " + identity + "[" + index + "]. Reason: " + e.getMessage(), e ); } index++; } } }
java
private <T> void load(YamlSourceLoader<T> loader, YamlPolicyCreator<T> creator) throws IOException { int index = 1; try (final YamlSourceLoader<T> loader1 = loader) { for (T yamlDoc : loader1.loadAll()) { String ident = identity + "[" + index + "]"; if (null == yamlDoc) { continue; } try { Policy yamlPolicy = creator.createYamlPolicy( yamlDoc, identity + "[" + index + "]", index ); all.add(yamlPolicy); ruleSet.addAll(yamlPolicy.getRuleSet().getRules()); } catch (AclPolicySyntaxException e) { validationError(ident, e.getMessage()); logger.debug( "ERROR parsing a policy in file: " + identity + "[" + index + "]. Reason: " + e.getMessage(), e ); } index++; } } }
[ "private", "<", "T", ">", "void", "load", "(", "YamlSourceLoader", "<", "T", ">", "loader", ",", "YamlPolicyCreator", "<", "T", ">", "creator", ")", "throws", "IOException", "{", "int", "index", "=", "1", ";", "try", "(", "final", "YamlSourceLoader", "<", "T", ">", "loader1", "=", "loader", ")", "{", "for", "(", "T", "yamlDoc", ":", "loader1", ".", "loadAll", "(", ")", ")", "{", "String", "ident", "=", "identity", "+", "\"[\"", "+", "index", "+", "\"]\"", ";", "if", "(", "null", "==", "yamlDoc", ")", "{", "continue", ";", "}", "try", "{", "Policy", "yamlPolicy", "=", "creator", ".", "createYamlPolicy", "(", "yamlDoc", ",", "identity", "+", "\"[\"", "+", "index", "+", "\"]\"", ",", "index", ")", ";", "all", ".", "add", "(", "yamlPolicy", ")", ";", "ruleSet", ".", "addAll", "(", "yamlPolicy", ".", "getRuleSet", "(", ")", ".", "getRules", "(", ")", ")", ";", "}", "catch", "(", "AclPolicySyntaxException", "e", ")", "{", "validationError", "(", "ident", ",", "e", ".", "getMessage", "(", ")", ")", ";", "logger", ".", "debug", "(", "\"ERROR parsing a policy in file: \"", "+", "identity", "+", "\"[\"", "+", "index", "+", "\"]. Reason: \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "index", "++", ";", "}", "}", "}" ]
load yaml stream as sequence of policy documents @throws IOException
[ "load", "yaml", "stream", "as", "sequence", "of", "policy", "documents" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/YamlPolicyCollection.java#L81-L114
15,917
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/ExecutionUtils.java
ExecutionUtils.getMessageLogLevel
public static String getMessageLogLevel(final int level, final String defLevel) { switch (level) { case (Constants.ERR_LEVEL): return Constants.MSG_ERR; case (Constants.DEBUG_LEVEL): return Constants.MSG_DEBUG; case (Constants.INFO_LEVEL): return Constants.MSG_INFO; case (Constants.VERBOSE_LEVEL): return Constants.MSG_VERBOSE; case (Constants.WARN_LEVEL): return Constants.MSG_WARN; default: return defLevel; } }
java
public static String getMessageLogLevel(final int level, final String defLevel) { switch (level) { case (Constants.ERR_LEVEL): return Constants.MSG_ERR; case (Constants.DEBUG_LEVEL): return Constants.MSG_DEBUG; case (Constants.INFO_LEVEL): return Constants.MSG_INFO; case (Constants.VERBOSE_LEVEL): return Constants.MSG_VERBOSE; case (Constants.WARN_LEVEL): return Constants.MSG_WARN; default: return defLevel; } }
[ "public", "static", "String", "getMessageLogLevel", "(", "final", "int", "level", ",", "final", "String", "defLevel", ")", "{", "switch", "(", "level", ")", "{", "case", "(", "Constants", ".", "ERR_LEVEL", ")", ":", "return", "Constants", ".", "MSG_ERR", ";", "case", "(", "Constants", ".", "DEBUG_LEVEL", ")", ":", "return", "Constants", ".", "MSG_DEBUG", ";", "case", "(", "Constants", ".", "INFO_LEVEL", ")", ":", "return", "Constants", ".", "MSG_INFO", ";", "case", "(", "Constants", ".", "VERBOSE_LEVEL", ")", ":", "return", "Constants", ".", "MSG_VERBOSE", ";", "case", "(", "Constants", ".", "WARN_LEVEL", ")", ":", "return", "Constants", ".", "MSG_WARN", ";", "default", ":", "return", "defLevel", ";", "}", "}" ]
Get message loglevel string for the integer value @param level integer level @param defLevel default string to return if integer doesn't match @return loglevel string, or the default value
[ "Get", "message", "loglevel", "string", "for", "the", "integer", "value" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/ExecutionUtils.java#L44-L59
15,918
rundeck/rundeck
rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java
PathUtil.parentPathString
public static String parentPathString(String path) { String[] split = componentsFromPathString(path); if (split.length > 1) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < split.length - 1; i++) { if (i > 0) { stringBuilder.append(SEPARATOR); } stringBuilder.append(split[i]); } return stringBuilder.toString(); } return ""; }
java
public static String parentPathString(String path) { String[] split = componentsFromPathString(path); if (split.length > 1) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < split.length - 1; i++) { if (i > 0) { stringBuilder.append(SEPARATOR); } stringBuilder.append(split[i]); } return stringBuilder.toString(); } return ""; }
[ "public", "static", "String", "parentPathString", "(", "String", "path", ")", "{", "String", "[", "]", "split", "=", "componentsFromPathString", "(", "path", ")", ";", "if", "(", "split", ".", "length", ">", "1", ")", "{", "StringBuilder", "stringBuilder", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "split", ".", "length", "-", "1", ";", "i", "++", ")", "{", "if", "(", "i", ">", "0", ")", "{", "stringBuilder", ".", "append", "(", "SEPARATOR", ")", ";", "}", "stringBuilder", ".", "append", "(", "split", "[", "i", "]", ")", ";", "}", "return", "stringBuilder", ".", "toString", "(", ")", ";", "}", "return", "\"\"", ";", "}" ]
Return the string representing the parent of the given path @param path path string @return parent path string
[ "Return", "the", "string", "representing", "the", "parent", "of", "the", "given", "path" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java#L190-L203
15,919
rundeck/rundeck
rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java
PathUtil.cleanPath
public static String cleanPath(String path) { if (path.endsWith(SEPARATOR)) { path = path.replaceAll(SEPARATOR + "+$", ""); } if (path.startsWith(SEPARATOR)) { path = path.replaceAll("^" + SEPARATOR + "+", ""); } return path.replaceAll("/+", SEPARATOR); }
java
public static String cleanPath(String path) { if (path.endsWith(SEPARATOR)) { path = path.replaceAll(SEPARATOR + "+$", ""); } if (path.startsWith(SEPARATOR)) { path = path.replaceAll("^" + SEPARATOR + "+", ""); } return path.replaceAll("/+", SEPARATOR); }
[ "public", "static", "String", "cleanPath", "(", "String", "path", ")", "{", "if", "(", "path", ".", "endsWith", "(", "SEPARATOR", ")", ")", "{", "path", "=", "path", ".", "replaceAll", "(", "SEPARATOR", "+", "\"+$\"", ",", "\"\"", ")", ";", "}", "if", "(", "path", ".", "startsWith", "(", "SEPARATOR", ")", ")", "{", "path", "=", "path", ".", "replaceAll", "(", "\"^\"", "+", "SEPARATOR", "+", "\"+\"", ",", "\"\"", ")", ";", "}", "return", "path", ".", "replaceAll", "(", "\"/+\"", ",", "SEPARATOR", ")", ";", "}" ]
Clean the path string by removing leading and trailing slashes and removing duplicate slashes. @param path input path @return cleaned path string
[ "Clean", "the", "path", "string", "by", "removing", "leading", "and", "trailing", "slashes", "and", "removing", "duplicate", "slashes", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java#L210-L218
15,920
rundeck/rundeck
rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java
PathUtil.exactMetadataResourceSelector
public static <T extends ContentMeta> ResourceSelector<T> exactMetadataResourceSelector(final Map<String, String> required, final boolean requireAll) { return new ResourceSelector<T>() { @Override public boolean matchesContent(T content) { for (String key : required.keySet()) { String expect = required.get(key); String test = content.getMeta().get(key); if (null != test && expect.equals(test)) { if (!requireAll) { return true; } } else if (requireAll) { return false; } } return requireAll; } }; }
java
public static <T extends ContentMeta> ResourceSelector<T> exactMetadataResourceSelector(final Map<String, String> required, final boolean requireAll) { return new ResourceSelector<T>() { @Override public boolean matchesContent(T content) { for (String key : required.keySet()) { String expect = required.get(key); String test = content.getMeta().get(key); if (null != test && expect.equals(test)) { if (!requireAll) { return true; } } else if (requireAll) { return false; } } return requireAll; } }; }
[ "public", "static", "<", "T", "extends", "ContentMeta", ">", "ResourceSelector", "<", "T", ">", "exactMetadataResourceSelector", "(", "final", "Map", "<", "String", ",", "String", ">", "required", ",", "final", "boolean", "requireAll", ")", "{", "return", "new", "ResourceSelector", "<", "T", ">", "(", ")", "{", "@", "Override", "public", "boolean", "matchesContent", "(", "T", "content", ")", "{", "for", "(", "String", "key", ":", "required", ".", "keySet", "(", ")", ")", "{", "String", "expect", "=", "required", ".", "get", "(", "key", ")", ";", "String", "test", "=", "content", ".", "getMeta", "(", ")", ".", "get", "(", "key", ")", ";", "if", "(", "null", "!=", "test", "&&", "expect", ".", "equals", "(", "test", ")", ")", "{", "if", "(", "!", "requireAll", ")", "{", "return", "true", ";", "}", "}", "else", "if", "(", "requireAll", ")", "{", "return", "false", ";", "}", "}", "return", "requireAll", ";", "}", "}", ";", "}" ]
A resource selector which requires metadata values to be equal to some required strings @param required required metadata strings @param requireAll if true, require all values are equal, otherwise require one value to be equal @param <T> content type @return selector for resources with all or some required metadata values
[ "A", "resource", "selector", "which", "requires", "metadata", "values", "to", "be", "equal", "to", "some", "required", "strings" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java#L292-L311
15,921
rundeck/rundeck
rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java
PathUtil.regexMetadataResourceSelector
public static <T extends ContentMeta> ResourceSelector<T> regexMetadataResourceSelector(final Map<String, String> required, final boolean requireAll) { return new ResourceSelector<T>() { Map<String, Pattern> patternMap = new HashMap<String, Pattern>(); private Pattern forString(String regex) { if (null == patternMap.get(regex)) { Pattern compile = null; try { compile = Pattern.compile(regex); } catch (PatternSyntaxException ignored) { return null; } patternMap.put(regex, compile); } return patternMap.get(regex); } @Override public boolean matchesContent(T content) { for (String key : required.keySet()) { Pattern pattern = forString(required.get(key)); String test = content.getMeta().get(key); if (null != test && null != pattern && pattern.matcher(test).matches()) { if (!requireAll) { return true; } } else if (requireAll) { return false; } } return requireAll; } }; }
java
public static <T extends ContentMeta> ResourceSelector<T> regexMetadataResourceSelector(final Map<String, String> required, final boolean requireAll) { return new ResourceSelector<T>() { Map<String, Pattern> patternMap = new HashMap<String, Pattern>(); private Pattern forString(String regex) { if (null == patternMap.get(regex)) { Pattern compile = null; try { compile = Pattern.compile(regex); } catch (PatternSyntaxException ignored) { return null; } patternMap.put(regex, compile); } return patternMap.get(regex); } @Override public boolean matchesContent(T content) { for (String key : required.keySet()) { Pattern pattern = forString(required.get(key)); String test = content.getMeta().get(key); if (null != test && null != pattern && pattern.matcher(test).matches()) { if (!requireAll) { return true; } } else if (requireAll) { return false; } } return requireAll; } }; }
[ "public", "static", "<", "T", "extends", "ContentMeta", ">", "ResourceSelector", "<", "T", ">", "regexMetadataResourceSelector", "(", "final", "Map", "<", "String", ",", "String", ">", "required", ",", "final", "boolean", "requireAll", ")", "{", "return", "new", "ResourceSelector", "<", "T", ">", "(", ")", "{", "Map", "<", "String", ",", "Pattern", ">", "patternMap", "=", "new", "HashMap", "<", "String", ",", "Pattern", ">", "(", ")", ";", "private", "Pattern", "forString", "(", "String", "regex", ")", "{", "if", "(", "null", "==", "patternMap", ".", "get", "(", "regex", ")", ")", "{", "Pattern", "compile", "=", "null", ";", "try", "{", "compile", "=", "Pattern", ".", "compile", "(", "regex", ")", ";", "}", "catch", "(", "PatternSyntaxException", "ignored", ")", "{", "return", "null", ";", "}", "patternMap", ".", "put", "(", "regex", ",", "compile", ")", ";", "}", "return", "patternMap", ".", "get", "(", "regex", ")", ";", "}", "@", "Override", "public", "boolean", "matchesContent", "(", "T", "content", ")", "{", "for", "(", "String", "key", ":", "required", ".", "keySet", "(", ")", ")", "{", "Pattern", "pattern", "=", "forString", "(", "required", ".", "get", "(", "key", ")", ")", ";", "String", "test", "=", "content", ".", "getMeta", "(", ")", ".", "get", "(", "key", ")", ";", "if", "(", "null", "!=", "test", "&&", "null", "!=", "pattern", "&&", "pattern", ".", "matcher", "(", "test", ")", ".", "matches", "(", ")", ")", "{", "if", "(", "!", "requireAll", ")", "{", "return", "true", ";", "}", "}", "else", "if", "(", "requireAll", ")", "{", "return", "false", ";", "}", "}", "return", "requireAll", ";", "}", "}", ";", "}" ]
A resource selector which requires metadata values to match regexes @param required required metadata regexes @param requireAll if true, require all values match regexes, otherwise require one value to match the regex @param <T> content type @return selector for resources with all or some matching metadata values
[ "A", "resource", "selector", "which", "requires", "metadata", "values", "to", "match", "regexes" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java#L322-L356
15,922
rundeck/rundeck
rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java
PathUtil.composeSelector
public static <T extends ContentMeta> ResourceSelector<T> composeSelector(final ResourceSelector<T> a, final ResourceSelector<T> b, final boolean and) { return new ResourceSelector<T>() { @Override public boolean matchesContent(T content) { boolean a1 = a.matchesContent(content); if (a1 && !and || !a1 && and) { return a1; } return b.matchesContent(content); } }; }
java
public static <T extends ContentMeta> ResourceSelector<T> composeSelector(final ResourceSelector<T> a, final ResourceSelector<T> b, final boolean and) { return new ResourceSelector<T>() { @Override public boolean matchesContent(T content) { boolean a1 = a.matchesContent(content); if (a1 && !and || !a1 && and) { return a1; } return b.matchesContent(content); } }; }
[ "public", "static", "<", "T", "extends", "ContentMeta", ">", "ResourceSelector", "<", "T", ">", "composeSelector", "(", "final", "ResourceSelector", "<", "T", ">", "a", ",", "final", "ResourceSelector", "<", "T", ">", "b", ",", "final", "boolean", "and", ")", "{", "return", "new", "ResourceSelector", "<", "T", ">", "(", ")", "{", "@", "Override", "public", "boolean", "matchesContent", "(", "T", "content", ")", "{", "boolean", "a1", "=", "a", ".", "matchesContent", "(", "content", ")", ";", "if", "(", "a1", "&&", "!", "and", "||", "!", "a1", "&&", "and", ")", "{", "return", "a1", ";", "}", "return", "b", ".", "matchesContent", "(", "content", ")", ";", "}", "}", ";", "}" ]
compose two selectors @param a selector 1 @param b selector 2 @param and true indicates AND, otherwise OR @param <T> resource type @return new selector appyling the operator to the selector
[ "compose", "two", "selectors" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java#L368-L380
15,923
rundeck/rundeck
rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java
PathUtil.allResourceSelector
public static <T extends ContentMeta> ResourceSelector<T> allResourceSelector() { return new ResourceSelector<T>() { @Override public boolean matchesContent(T content) { return true; } }; }
java
public static <T extends ContentMeta> ResourceSelector<T> allResourceSelector() { return new ResourceSelector<T>() { @Override public boolean matchesContent(T content) { return true; } }; }
[ "public", "static", "<", "T", "extends", "ContentMeta", ">", "ResourceSelector", "<", "T", ">", "allResourceSelector", "(", ")", "{", "return", "new", "ResourceSelector", "<", "T", ">", "(", ")", "{", "@", "Override", "public", "boolean", "matchesContent", "(", "T", "content", ")", "{", "return", "true", ";", "}", "}", ";", "}" ]
A resource selector which always matches @param <T> content type @return selector
[ "A", "resource", "selector", "which", "always", "matches" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-api/src/main/java/org/rundeck/storage/api/PathUtil.java#L389-L396
15,924
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/AuthorizationUtil.java
AuthorizationUtil.resourceType
public static Map<String, String> resourceType(String kind, Map<String, String> meta) { HashMap<String, String> authResource = new HashMap<String, String>(); if (null != meta) { authResource.putAll(meta); } authResource.put(TYPE_FIELD, GENERIC_RESOURCE_TYPE_NAME); authResource.put(TYPE_KIND_FIELD, kind); return authResource; }
java
public static Map<String, String> resourceType(String kind, Map<String, String> meta) { HashMap<String, String> authResource = new HashMap<String, String>(); if (null != meta) { authResource.putAll(meta); } authResource.put(TYPE_FIELD, GENERIC_RESOURCE_TYPE_NAME); authResource.put(TYPE_KIND_FIELD, kind); return authResource; }
[ "public", "static", "Map", "<", "String", ",", "String", ">", "resourceType", "(", "String", "kind", ",", "Map", "<", "String", ",", "String", ">", "meta", ")", "{", "HashMap", "<", "String", ",", "String", ">", "authResource", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "if", "(", "null", "!=", "meta", ")", "{", "authResource", ".", "putAll", "(", "meta", ")", ";", "}", "authResource", ".", "put", "(", "TYPE_FIELD", ",", "GENERIC_RESOURCE_TYPE_NAME", ")", ";", "authResource", ".", "put", "(", "TYPE_KIND_FIELD", ",", "kind", ")", ";", "return", "authResource", ";", "}" ]
Return a resource map for a generic resource type @param kind the resource type name @param meta the attributes about the resource type @return the resource map describing a resource type
[ "Return", "a", "resource", "map", "for", "a", "generic", "resource", "type" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/AuthorizationUtil.java#L113-L121
15,925
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/AuthorizationUtil.java
AuthorizationUtil.context
public static Set<Attribute> context(String key, String value){ if(null==key) { throw new IllegalArgumentException("key cannot be null"); } if(null==value){ throw new IllegalArgumentException("value cannot be null"); } return Collections.singleton( new Attribute( URI.create(EnvironmentalContext.URI_BASE + key), value ) ); }
java
public static Set<Attribute> context(String key, String value){ if(null==key) { throw new IllegalArgumentException("key cannot be null"); } if(null==value){ throw new IllegalArgumentException("value cannot be null"); } return Collections.singleton( new Attribute( URI.create(EnvironmentalContext.URI_BASE + key), value ) ); }
[ "public", "static", "Set", "<", "Attribute", ">", "context", "(", "String", "key", ",", "String", "value", ")", "{", "if", "(", "null", "==", "key", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"key cannot be null\"", ")", ";", "}", "if", "(", "null", "==", "value", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"value cannot be null\"", ")", ";", "}", "return", "Collections", ".", "singleton", "(", "new", "Attribute", "(", "URI", ".", "create", "(", "EnvironmentalContext", ".", "URI_BASE", "+", "key", ")", ",", "value", ")", ")", ";", "}" ]
Create a singleton context attribute set @param key context key @param value context value @return attribute set
[ "Create", "a", "singleton", "context", "attribute", "set" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/AuthorizationUtil.java#L155-L168
15,926
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/AuthorizationUtil.java
AuthorizationUtil.contextAsString
public static String contextAsString(final Set<Attribute> context) { StringBuilder sb = new StringBuilder(); for (Attribute attribute : context) { if(sb.length()<1) { sb.append("{"); }else { sb.append(", "); } sb.append(Attribute.propertyKeyForURIBase(attribute, EnvironmentalContext.URI_BASE)) .append("=") .append(attribute.getValue()) ; } sb.append("}"); return sb.toString(); }
java
public static String contextAsString(final Set<Attribute> context) { StringBuilder sb = new StringBuilder(); for (Attribute attribute : context) { if(sb.length()<1) { sb.append("{"); }else { sb.append(", "); } sb.append(Attribute.propertyKeyForURIBase(attribute, EnvironmentalContext.URI_BASE)) .append("=") .append(attribute.getValue()) ; } sb.append("}"); return sb.toString(); }
[ "public", "static", "String", "contextAsString", "(", "final", "Set", "<", "Attribute", ">", "context", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "Attribute", "attribute", ":", "context", ")", "{", "if", "(", "sb", ".", "length", "(", ")", "<", "1", ")", "{", "sb", ".", "append", "(", "\"{\"", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "\", \"", ")", ";", "}", "sb", ".", "append", "(", "Attribute", ".", "propertyKeyForURIBase", "(", "attribute", ",", "EnvironmentalContext", ".", "URI_BASE", ")", ")", ".", "append", "(", "\"=\"", ")", ".", "append", "(", "attribute", ".", "getValue", "(", ")", ")", ";", "}", "sb", ".", "append", "(", "\"}\"", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Generate a string representation of the context attribute set @param context context set @return string
[ "Generate", "a", "string", "representation", "of", "the", "context", "attribute", "set" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/AuthorizationUtil.java#L175-L190
15,927
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/BaseScriptPlugin.java
BaseScriptPlugin.runPluginScript
protected int runPluginScript( final PluginStepContext executionContext, final PrintStream outputStream, final PrintStream errorStream, final Framework framework, final Map<String, Object> configuration ) throws IOException, InterruptedException, ConfigurationException { Description pluginDesc = getDescription(); final DataContext localDataContext = createScriptDataContext( framework, executionContext.getFrameworkProject(), executionContext.getDataContext() ); Map<String, Object> instanceData = new HashMap<>(configuration); Map<String, String> data = MapData.toStringStringMap(instanceData); loadContentConversionPropertyValues( data, executionContext.getExecutionContext(), pluginDesc.getProperties() ); localDataContext.merge(new BaseDataContext("config", data)); final String[] finalargs = createScriptArgs(localDataContext); executionContext.getLogger().log(3, "[" + getProvider().getName() + "] executing: " + Arrays.asList( finalargs)); Map<String, String> envMap = new HashMap<>(); if (isMergeEnvVars()) { envMap.putAll(getScriptExecHelper().loadLocalEnvironment()); } envMap.putAll(DataContextUtils.generateEnvVarsFromContext(localDataContext)); return getScriptExecHelper().runLocalCommand( finalargs, envMap, null, outputStream, errorStream ); }
java
protected int runPluginScript( final PluginStepContext executionContext, final PrintStream outputStream, final PrintStream errorStream, final Framework framework, final Map<String, Object> configuration ) throws IOException, InterruptedException, ConfigurationException { Description pluginDesc = getDescription(); final DataContext localDataContext = createScriptDataContext( framework, executionContext.getFrameworkProject(), executionContext.getDataContext() ); Map<String, Object> instanceData = new HashMap<>(configuration); Map<String, String> data = MapData.toStringStringMap(instanceData); loadContentConversionPropertyValues( data, executionContext.getExecutionContext(), pluginDesc.getProperties() ); localDataContext.merge(new BaseDataContext("config", data)); final String[] finalargs = createScriptArgs(localDataContext); executionContext.getLogger().log(3, "[" + getProvider().getName() + "] executing: " + Arrays.asList( finalargs)); Map<String, String> envMap = new HashMap<>(); if (isMergeEnvVars()) { envMap.putAll(getScriptExecHelper().loadLocalEnvironment()); } envMap.putAll(DataContextUtils.generateEnvVarsFromContext(localDataContext)); return getScriptExecHelper().runLocalCommand( finalargs, envMap, null, outputStream, errorStream ); }
[ "protected", "int", "runPluginScript", "(", "final", "PluginStepContext", "executionContext", ",", "final", "PrintStream", "outputStream", ",", "final", "PrintStream", "errorStream", ",", "final", "Framework", "framework", ",", "final", "Map", "<", "String", ",", "Object", ">", "configuration", ")", "throws", "IOException", ",", "InterruptedException", ",", "ConfigurationException", "{", "Description", "pluginDesc", "=", "getDescription", "(", ")", ";", "final", "DataContext", "localDataContext", "=", "createScriptDataContext", "(", "framework", ",", "executionContext", ".", "getFrameworkProject", "(", ")", ",", "executionContext", ".", "getDataContext", "(", ")", ")", ";", "Map", "<", "String", ",", "Object", ">", "instanceData", "=", "new", "HashMap", "<>", "(", "configuration", ")", ";", "Map", "<", "String", ",", "String", ">", "data", "=", "MapData", ".", "toStringStringMap", "(", "instanceData", ")", ";", "loadContentConversionPropertyValues", "(", "data", ",", "executionContext", ".", "getExecutionContext", "(", ")", ",", "pluginDesc", ".", "getProperties", "(", ")", ")", ";", "localDataContext", ".", "merge", "(", "new", "BaseDataContext", "(", "\"config\"", ",", "data", ")", ")", ";", "final", "String", "[", "]", "finalargs", "=", "createScriptArgs", "(", "localDataContext", ")", ";", "executionContext", ".", "getLogger", "(", ")", ".", "log", "(", "3", ",", "\"[\"", "+", "getProvider", "(", ")", ".", "getName", "(", ")", "+", "\"] executing: \"", "+", "Arrays", ".", "asList", "(", "finalargs", ")", ")", ";", "Map", "<", "String", ",", "String", ">", "envMap", "=", "new", "HashMap", "<>", "(", ")", ";", "if", "(", "isMergeEnvVars", "(", ")", ")", "{", "envMap", ".", "putAll", "(", "getScriptExecHelper", "(", ")", ".", "loadLocalEnvironment", "(", ")", ")", ";", "}", "envMap", ".", "putAll", "(", "DataContextUtils", ".", "generateEnvVarsFromContext", "(", "localDataContext", ")", ")", ";", "return", "getScriptExecHelper", "(", ")", ".", "runLocalCommand", "(", "finalargs", ",", "envMap", ",", "null", ",", "outputStream", ",", "errorStream", ")", ";", "}" ]
Runs the script configured for the script plugin and channels the output to two streams. @param executionContext context @param outputStream output stream @param errorStream error stream @param framework fwlk @param configuration configuration @return exit code @throws IOException if any IO exception occurs @throws InterruptedException if interrupted while waiting for the command to finish
[ "Runs", "the", "script", "configured", "for", "the", "script", "plugin", "and", "channels", "the", "output", "to", "two", "streams", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/BaseScriptPlugin.java#L77-L119
15,928
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/BaseScriptPlugin.java
BaseScriptPlugin.createStepItemDataContext
protected Map<String, Map<String, String>> createStepItemDataContext(final Framework framework, final String project, final Map<String, Map<String, String>> context, final Map<String, Object> configuration) { final Map<String, Map<String, String>> localDataContext = createScriptDataContext(framework, project, context); final HashMap<String, String> configMap = new HashMap<String, String>(); //convert values to string for (final Map.Entry<String, Object> entry : configuration.entrySet()) { configMap.put(entry.getKey(), entry.getValue().toString()); } localDataContext.put("config", configMap); return localDataContext; }
java
protected Map<String, Map<String, String>> createStepItemDataContext(final Framework framework, final String project, final Map<String, Map<String, String>> context, final Map<String, Object> configuration) { final Map<String, Map<String, String>> localDataContext = createScriptDataContext(framework, project, context); final HashMap<String, String> configMap = new HashMap<String, String>(); //convert values to string for (final Map.Entry<String, Object> entry : configuration.entrySet()) { configMap.put(entry.getKey(), entry.getValue().toString()); } localDataContext.put("config", configMap); return localDataContext; }
[ "protected", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "createStepItemDataContext", "(", "final", "Framework", "framework", ",", "final", "String", "project", ",", "final", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "context", ",", "final", "Map", "<", "String", ",", "Object", ">", "configuration", ")", "{", "final", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "localDataContext", "=", "createScriptDataContext", "(", "framework", ",", "project", ",", "context", ")", ";", "final", "HashMap", "<", "String", ",", "String", ">", "configMap", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", ")", ";", "//convert values to string", "for", "(", "final", "Map", ".", "Entry", "<", "String", ",", "Object", ">", "entry", ":", "configuration", ".", "entrySet", "(", ")", ")", "{", "configMap", ".", "put", "(", "entry", ".", "getKey", "(", ")", ",", "entry", ".", "getValue", "(", ")", ".", "toString", "(", ")", ")", ";", "}", "localDataContext", ".", "put", "(", "\"config\"", ",", "configMap", ")", ";", "return", "localDataContext", ";", "}" ]
Create a data context containing the plugin values "file","scriptfile" and "base", as well as all config values. @param framework fwk @param project project name @param context data context @param configuration configuration @return data context
[ "Create", "a", "data", "context", "containing", "the", "plugin", "values", "file", "scriptfile", "and", "base", "as", "well", "as", "all", "config", "values", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/BaseScriptPlugin.java#L129-L143
15,929
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/BaseScriptPlugin.java
BaseScriptPlugin.createScriptDataContext
protected DataContext createScriptDataContext( final Framework framework, final String project, final Map<String, Map<String, String>> context) { BaseDataContext localDataContext = new BaseDataContext(); localDataContext.merge(ScriptDataContextUtil.createScriptDataContextObjectForProject(framework, project)); localDataContext.group("plugin").putAll(createPluginData()); localDataContext.putAll(context); return localDataContext; }
java
protected DataContext createScriptDataContext( final Framework framework, final String project, final Map<String, Map<String, String>> context) { BaseDataContext localDataContext = new BaseDataContext(); localDataContext.merge(ScriptDataContextUtil.createScriptDataContextObjectForProject(framework, project)); localDataContext.group("plugin").putAll(createPluginData()); localDataContext.putAll(context); return localDataContext; }
[ "protected", "DataContext", "createScriptDataContext", "(", "final", "Framework", "framework", ",", "final", "String", "project", ",", "final", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "context", ")", "{", "BaseDataContext", "localDataContext", "=", "new", "BaseDataContext", "(", ")", ";", "localDataContext", ".", "merge", "(", "ScriptDataContextUtil", ".", "createScriptDataContextObjectForProject", "(", "framework", ",", "project", ")", ")", ";", "localDataContext", ".", "group", "(", "\"plugin\"", ")", ".", "putAll", "(", "createPluginData", "(", ")", ")", ";", "localDataContext", ".", "putAll", "(", "context", ")", ";", "return", "localDataContext", ";", "}" ]
create script data context @param framework fwk @param project project name @param context orig context @return new data context
[ "create", "script", "data", "context" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/BaseScriptPlugin.java#L152-L161
15,930
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/storage/StorageConverterPluginAdapter.java
StorageConverterPluginAdapter.filter
private ResourceMeta filter(Path path, ResourceMeta resourceMeta, Operation op) { ResourceMetaBuilder resourceMetaBuilder = StorageUtil.create(new HashMap<String, String>(resourceMeta.getMeta())); final HasInputStream result; switch (op) { case READ: case UPDATE: case CREATE: try { if (op == Operation.CREATE) { result = plugin.createResource(path, resourceMetaBuilder, resourceMeta); } else if (op == Operation.READ) { result = plugin.readResource(path, resourceMetaBuilder, resourceMeta); } else { result = plugin.updateResource(path, resourceMetaBuilder, resourceMeta); } } catch (Throwable e) { throw new StorageException("Converter Plugin " + providerName + " threw exception during " + op + ": " + e.getMessage(), e, StorageException.Event.valueOf(op.toString()), path); } break; default: throw new IllegalStateException(); } logger.debug( "Plugin(" + providerName + "):" + op + ":" + path + ";" + (null == result ? "_" : "+") + ":" + resourceMetaBuilder.getResourceMeta() ); //construct the new data return StorageUtil.withStream(null == result ? resourceMeta : result, resourceMetaBuilder.getResourceMeta()); }
java
private ResourceMeta filter(Path path, ResourceMeta resourceMeta, Operation op) { ResourceMetaBuilder resourceMetaBuilder = StorageUtil.create(new HashMap<String, String>(resourceMeta.getMeta())); final HasInputStream result; switch (op) { case READ: case UPDATE: case CREATE: try { if (op == Operation.CREATE) { result = plugin.createResource(path, resourceMetaBuilder, resourceMeta); } else if (op == Operation.READ) { result = plugin.readResource(path, resourceMetaBuilder, resourceMeta); } else { result = plugin.updateResource(path, resourceMetaBuilder, resourceMeta); } } catch (Throwable e) { throw new StorageException("Converter Plugin " + providerName + " threw exception during " + op + ": " + e.getMessage(), e, StorageException.Event.valueOf(op.toString()), path); } break; default: throw new IllegalStateException(); } logger.debug( "Plugin(" + providerName + "):" + op + ":" + path + ";" + (null == result ? "_" : "+") + ":" + resourceMetaBuilder.getResourceMeta() ); //construct the new data return StorageUtil.withStream(null == result ? resourceMeta : result, resourceMetaBuilder.getResourceMeta()); }
[ "private", "ResourceMeta", "filter", "(", "Path", "path", ",", "ResourceMeta", "resourceMeta", ",", "Operation", "op", ")", "{", "ResourceMetaBuilder", "resourceMetaBuilder", "=", "StorageUtil", ".", "create", "(", "new", "HashMap", "<", "String", ",", "String", ">", "(", "resourceMeta", ".", "getMeta", "(", ")", ")", ")", ";", "final", "HasInputStream", "result", ";", "switch", "(", "op", ")", "{", "case", "READ", ":", "case", "UPDATE", ":", "case", "CREATE", ":", "try", "{", "if", "(", "op", "==", "Operation", ".", "CREATE", ")", "{", "result", "=", "plugin", ".", "createResource", "(", "path", ",", "resourceMetaBuilder", ",", "resourceMeta", ")", ";", "}", "else", "if", "(", "op", "==", "Operation", ".", "READ", ")", "{", "result", "=", "plugin", ".", "readResource", "(", "path", ",", "resourceMetaBuilder", ",", "resourceMeta", ")", ";", "}", "else", "{", "result", "=", "plugin", ".", "updateResource", "(", "path", ",", "resourceMetaBuilder", ",", "resourceMeta", ")", ";", "}", "}", "catch", "(", "Throwable", "e", ")", "{", "throw", "new", "StorageException", "(", "\"Converter Plugin \"", "+", "providerName", "+", "\" threw exception during \"", "+", "op", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ",", "StorageException", ".", "Event", ".", "valueOf", "(", "op", ".", "toString", "(", ")", ")", ",", "path", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "IllegalStateException", "(", ")", ";", "}", "logger", ".", "debug", "(", "\"Plugin(\"", "+", "providerName", "+", "\"):\"", "+", "op", "+", "\":\"", "+", "path", "+", "\";\"", "+", "(", "null", "==", "result", "?", "\"_\"", ":", "\"+\"", ")", "+", "\":\"", "+", "resourceMetaBuilder", ".", "getResourceMeta", "(", ")", ")", ";", "//construct the new data", "return", "StorageUtil", ".", "withStream", "(", "null", "==", "result", "?", "resourceMeta", ":", "result", ",", "resourceMetaBuilder", ".", "getResourceMeta", "(", ")", ")", ";", "}" ]
perform appropriate plugin filter method based on the operation enacted @param path path @param resourceMeta resource @param op operation @return new resource
[ "perform", "appropriate", "plugin", "filter", "method", "based", "on", "the", "operation", "enacted" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/storage/StorageConverterPluginAdapter.java#L52-L82
15,931
rundeck/rundeck
core/src/main/java/com/dtolabs/shared/resources/ResourceXMLParser.java
ResourceXMLParser.parse
public void parse() throws ResourceXMLParserException, IOException { final EntityResolver resolver = createEntityResolver(); final SAXReader reader = new SAXReader(false); reader.setEntityResolver(resolver); try { final Document doc; if(null==this.doc){ final InputStream in; if(null!=file){ in = new FileInputStream(file); }else{ in = input; } try{ doc=reader.read(in); }finally{ if(null!=file){ in.close(); } } }else{ doc=this.doc; } final EntitySet set = new EntitySet(); final Element root = doc.getRootElement(); final List list = root.selectNodes(entityXpath); for (final Object n : list) { final Node node = (Node) n; final Entity ent = parseEnt(node, set); if (null != receiver) { if (!receiver.resourceParsed(ent)) { break; } } } if (null != receiver) { receiver.resourcesParsed(set); } } catch (DocumentException e) { throw new ResourceXMLParserException(e); } }
java
public void parse() throws ResourceXMLParserException, IOException { final EntityResolver resolver = createEntityResolver(); final SAXReader reader = new SAXReader(false); reader.setEntityResolver(resolver); try { final Document doc; if(null==this.doc){ final InputStream in; if(null!=file){ in = new FileInputStream(file); }else{ in = input; } try{ doc=reader.read(in); }finally{ if(null!=file){ in.close(); } } }else{ doc=this.doc; } final EntitySet set = new EntitySet(); final Element root = doc.getRootElement(); final List list = root.selectNodes(entityXpath); for (final Object n : list) { final Node node = (Node) n; final Entity ent = parseEnt(node, set); if (null != receiver) { if (!receiver.resourceParsed(ent)) { break; } } } if (null != receiver) { receiver.resourcesParsed(set); } } catch (DocumentException e) { throw new ResourceXMLParserException(e); } }
[ "public", "void", "parse", "(", ")", "throws", "ResourceXMLParserException", ",", "IOException", "{", "final", "EntityResolver", "resolver", "=", "createEntityResolver", "(", ")", ";", "final", "SAXReader", "reader", "=", "new", "SAXReader", "(", "false", ")", ";", "reader", ".", "setEntityResolver", "(", "resolver", ")", ";", "try", "{", "final", "Document", "doc", ";", "if", "(", "null", "==", "this", ".", "doc", ")", "{", "final", "InputStream", "in", ";", "if", "(", "null", "!=", "file", ")", "{", "in", "=", "new", "FileInputStream", "(", "file", ")", ";", "}", "else", "{", "in", "=", "input", ";", "}", "try", "{", "doc", "=", "reader", ".", "read", "(", "in", ")", ";", "}", "finally", "{", "if", "(", "null", "!=", "file", ")", "{", "in", ".", "close", "(", ")", ";", "}", "}", "}", "else", "{", "doc", "=", "this", ".", "doc", ";", "}", "final", "EntitySet", "set", "=", "new", "EntitySet", "(", ")", ";", "final", "Element", "root", "=", "doc", ".", "getRootElement", "(", ")", ";", "final", "List", "list", "=", "root", ".", "selectNodes", "(", "entityXpath", ")", ";", "for", "(", "final", "Object", "n", ":", "list", ")", "{", "final", "Node", "node", "=", "(", "Node", ")", "n", ";", "final", "Entity", "ent", "=", "parseEnt", "(", "node", ",", "set", ")", ";", "if", "(", "null", "!=", "receiver", ")", "{", "if", "(", "!", "receiver", ".", "resourceParsed", "(", "ent", ")", ")", "{", "break", ";", "}", "}", "}", "if", "(", "null", "!=", "receiver", ")", "{", "receiver", ".", "resourcesParsed", "(", "set", ")", ";", "}", "}", "catch", "(", "DocumentException", "e", ")", "{", "throw", "new", "ResourceXMLParserException", "(", "e", ")", ";", "}", "}" ]
Parse the document, applying the configured Receiver to the parsed entities @throws ResourceXMLParserException parse error @throws java.io.IOException io error
[ "Parse", "the", "document", "applying", "the", "configured", "Receiver", "to", "the", "parsed", "entities" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/shared/resources/ResourceXMLParser.java#L97-L143
15,932
rundeck/rundeck
core/src/main/java/com/dtolabs/shared/resources/ResourceXMLParser.java
ResourceXMLParser.parseEnt
private Entity parseEnt(final Node node, final EntitySet set) throws ResourceXMLParserException { final Entity ent = parseResourceRef(set, node); ent.setResourceType(node.getName()); parseEntProperties(ent, node); parseEntSubAttributes(ent, node); return ent; }
java
private Entity parseEnt(final Node node, final EntitySet set) throws ResourceXMLParserException { final Entity ent = parseResourceRef(set, node); ent.setResourceType(node.getName()); parseEntProperties(ent, node); parseEntSubAttributes(ent, node); return ent; }
[ "private", "Entity", "parseEnt", "(", "final", "Node", "node", ",", "final", "EntitySet", "set", ")", "throws", "ResourceXMLParserException", "{", "final", "Entity", "ent", "=", "parseResourceRef", "(", "set", ",", "node", ")", ";", "ent", ".", "setResourceType", "(", "node", ".", "getName", "(", ")", ")", ";", "parseEntProperties", "(", "ent", ",", "node", ")", ";", "parseEntSubAttributes", "(", "ent", ",", "node", ")", ";", "return", "ent", ";", "}" ]
Given xml Node and EntitySet, parse the entity defined in the Node @param node DOM node @param set entity set holder @return parsed Entity object @throws ResourceXMLParserException if entity definition was previously found, or another error occurs
[ "Given", "xml", "Node", "and", "EntitySet", "parse", "the", "entity", "defined", "in", "the", "Node" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/shared/resources/ResourceXMLParser.java#L183-L189
15,933
rundeck/rundeck
examples/example-java-storage-converter-plugin/src/main/java/org/rundeck/plugin/example/ExampleConverterPlugin.java
ExampleConverterPlugin.readResource
@Override public HasInputStream readResource(Path path, ResourceMetaBuilder resourceMetaBuilder, final HasInputStream hasResourceStream) { if (wasEncoded(resourceMetaBuilder)) { return decode(hasResourceStream); } //return null to indicate no change was performed on the data return null; }
java
@Override public HasInputStream readResource(Path path, ResourceMetaBuilder resourceMetaBuilder, final HasInputStream hasResourceStream) { if (wasEncoded(resourceMetaBuilder)) { return decode(hasResourceStream); } //return null to indicate no change was performed on the data return null; }
[ "@", "Override", "public", "HasInputStream", "readResource", "(", "Path", "path", ",", "ResourceMetaBuilder", "resourceMetaBuilder", ",", "final", "HasInputStream", "hasResourceStream", ")", "{", "if", "(", "wasEncoded", "(", "resourceMetaBuilder", ")", ")", "{", "return", "decode", "(", "hasResourceStream", ")", ";", "}", "//return null to indicate no change was performed on the data", "return", "null", ";", "}" ]
Reads stored data, so decodes a base64 stream if the metadata indicates it has been encoded @param path @param resourceMetaBuilder @param hasResourceStream @return
[ "Reads", "stored", "data", "so", "decodes", "a", "base64", "stream", "if", "the", "metadata", "indicates", "it", "has", "been", "encoded" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/examples/example-java-storage-converter-plugin/src/main/java/org/rundeck/plugin/example/ExampleConverterPlugin.java#L94-L102
15,934
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/MapData.java
MapData.toStringStringMap
public static Map<String, String> toStringStringMap(Map input) { Map<String, String> map = new HashMap<>(); for (Object o : input.keySet()) { map.put(o.toString(), input.get(o) != null ? input.get(o).toString() : ""); } return map; }
java
public static Map<String, String> toStringStringMap(Map input) { Map<String, String> map = new HashMap<>(); for (Object o : input.keySet()) { map.put(o.toString(), input.get(o) != null ? input.get(o).toString() : ""); } return map; }
[ "public", "static", "Map", "<", "String", ",", "String", ">", "toStringStringMap", "(", "Map", "input", ")", "{", "Map", "<", "String", ",", "String", ">", "map", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "Object", "o", ":", "input", ".", "keySet", "(", ")", ")", "{", "map", ".", "put", "(", "o", ".", "toString", "(", ")", ",", "input", ".", "get", "(", "o", ")", "!=", "null", "?", "input", ".", "get", "(", "o", ")", ".", "toString", "(", ")", ":", "\"\"", ")", ";", "}", "return", "map", ";", "}" ]
Convert all values to string via toString @param input
[ "Convert", "all", "values", "to", "string", "via", "toString" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/MapData.java#L173-L179
15,935
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/resources/DirectoryResourceModelSource.java
DirectoryResourceModelSource.loadFileSources
private void loadFileSources(final File directory, final String project) { //clear source sequence if (!directory.isDirectory()) { logger.warn("Not a directory: " + directory); } //get supported parser extensions final Set<String> exts = new HashSet<String>( framework.getResourceFormatParserService().listSupportedFileExtensions()); final File[] files = directory.listFiles(new FilenameFilter() { public boolean accept(final File file, final String s) { return exts.contains( ResourceFormatParserService.getFileExtension(s)); } }); //set of previously cached file sources by file if (null != files) { //sort on filename Arrays.sort(files, null); synchronized (sourceCache) { final HashSet<File> trackedFiles = new HashSet<File>(sourceCache.keySet()); for (final File file : files) { //remove file that we want to keep trackedFiles.remove(file); if (!sourceCache.containsKey(file)) { logger.debug("Adding new resources file to cache: " + file.getAbsolutePath()); try { final ResourceModelSource source = createFileSource(project, file); sourceCache.put(file, source); } catch (ExecutionServiceException e) { e.printStackTrace(); logger.debug("Failed adding file " + file.getAbsolutePath() + ": " + e.getMessage(), e); } } } //remaining trackedFiles are files that have been removed from the dir for (final File oldFile : trackedFiles) { logger.debug("Removing from cache: " + oldFile.getAbsolutePath()); sourceCache.remove(oldFile); } } } }
java
private void loadFileSources(final File directory, final String project) { //clear source sequence if (!directory.isDirectory()) { logger.warn("Not a directory: " + directory); } //get supported parser extensions final Set<String> exts = new HashSet<String>( framework.getResourceFormatParserService().listSupportedFileExtensions()); final File[] files = directory.listFiles(new FilenameFilter() { public boolean accept(final File file, final String s) { return exts.contains( ResourceFormatParserService.getFileExtension(s)); } }); //set of previously cached file sources by file if (null != files) { //sort on filename Arrays.sort(files, null); synchronized (sourceCache) { final HashSet<File> trackedFiles = new HashSet<File>(sourceCache.keySet()); for (final File file : files) { //remove file that we want to keep trackedFiles.remove(file); if (!sourceCache.containsKey(file)) { logger.debug("Adding new resources file to cache: " + file.getAbsolutePath()); try { final ResourceModelSource source = createFileSource(project, file); sourceCache.put(file, source); } catch (ExecutionServiceException e) { e.printStackTrace(); logger.debug("Failed adding file " + file.getAbsolutePath() + ": " + e.getMessage(), e); } } } //remaining trackedFiles are files that have been removed from the dir for (final File oldFile : trackedFiles) { logger.debug("Removing from cache: " + oldFile.getAbsolutePath()); sourceCache.remove(oldFile); } } } }
[ "private", "void", "loadFileSources", "(", "final", "File", "directory", ",", "final", "String", "project", ")", "{", "//clear source sequence", "if", "(", "!", "directory", ".", "isDirectory", "(", ")", ")", "{", "logger", ".", "warn", "(", "\"Not a directory: \"", "+", "directory", ")", ";", "}", "//get supported parser extensions", "final", "Set", "<", "String", ">", "exts", "=", "new", "HashSet", "<", "String", ">", "(", "framework", ".", "getResourceFormatParserService", "(", ")", ".", "listSupportedFileExtensions", "(", ")", ")", ";", "final", "File", "[", "]", "files", "=", "directory", ".", "listFiles", "(", "new", "FilenameFilter", "(", ")", "{", "public", "boolean", "accept", "(", "final", "File", "file", ",", "final", "String", "s", ")", "{", "return", "exts", ".", "contains", "(", "ResourceFormatParserService", ".", "getFileExtension", "(", "s", ")", ")", ";", "}", "}", ")", ";", "//set of previously cached file sources by file", "if", "(", "null", "!=", "files", ")", "{", "//sort on filename", "Arrays", ".", "sort", "(", "files", ",", "null", ")", ";", "synchronized", "(", "sourceCache", ")", "{", "final", "HashSet", "<", "File", ">", "trackedFiles", "=", "new", "HashSet", "<", "File", ">", "(", "sourceCache", ".", "keySet", "(", ")", ")", ";", "for", "(", "final", "File", "file", ":", "files", ")", "{", "//remove file that we want to keep", "trackedFiles", ".", "remove", "(", "file", ")", ";", "if", "(", "!", "sourceCache", ".", "containsKey", "(", "file", ")", ")", "{", "logger", ".", "debug", "(", "\"Adding new resources file to cache: \"", "+", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "try", "{", "final", "ResourceModelSource", "source", "=", "createFileSource", "(", "project", ",", "file", ")", ";", "sourceCache", ".", "put", "(", "file", ",", "source", ")", ";", "}", "catch", "(", "ExecutionServiceException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "logger", ".", "debug", "(", "\"Failed adding file \"", "+", "file", ".", "getAbsolutePath", "(", ")", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}", "}", "//remaining trackedFiles are files that have been removed from the dir", "for", "(", "final", "File", "oldFile", ":", "trackedFiles", ")", "{", "logger", ".", "debug", "(", "\"Removing from cache: \"", "+", "oldFile", ".", "getAbsolutePath", "(", ")", ")", ";", "sourceCache", ".", "remove", "(", "oldFile", ")", ";", "}", "}", "}", "}" ]
Discover new files in the directory, and add file sources
[ "Discover", "new", "files", "in", "the", "directory", "and", "add", "file", "sources" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/resources/DirectoryResourceModelSource.java#L179-L223
15,936
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java
BaseTool.initOptions
protected void initOptions() { if (null != toolOptions && !optionsHaveInited) { for (CLIToolOptions toolOpts : toolOptions) { toolOpts.addOptions(options); } optionsHaveInited=true; } }
java
protected void initOptions() { if (null != toolOptions && !optionsHaveInited) { for (CLIToolOptions toolOpts : toolOptions) { toolOpts.addOptions(options); } optionsHaveInited=true; } }
[ "protected", "void", "initOptions", "(", ")", "{", "if", "(", "null", "!=", "toolOptions", "&&", "!", "optionsHaveInited", ")", "{", "for", "(", "CLIToolOptions", "toolOpts", ":", "toolOptions", ")", "{", "toolOpts", ".", "addOptions", "(", "options", ")", ";", "}", "optionsHaveInited", "=", "true", ";", "}", "}" ]
initialize any options, will apply this for each CLIToolOptions added to the tool. subclasses may override this but should call super
[ "initialize", "any", "options", "will", "apply", "this", "for", "each", "CLIToolOptions", "added", "to", "the", "tool", ".", "subclasses", "may", "override", "this", "but", "should", "call", "super" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java#L83-L90
15,937
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java
BaseTool.optionDisplayString
protected String optionDisplayString(final String opt, boolean extended) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("-").append(opt); Option option = getOption(opt); if(null!=option) { if (option.getLongOpt() != null) { stringBuffer.append("/--"); stringBuffer.append(option.getLongOpt()); } if(option.getArgName()!=null && extended){ stringBuffer.append(" <"); stringBuffer.append(option.getArgName()); stringBuffer.append(">"); } } return stringBuffer.toString(); }
java
protected String optionDisplayString(final String opt, boolean extended) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("-").append(opt); Option option = getOption(opt); if(null!=option) { if (option.getLongOpt() != null) { stringBuffer.append("/--"); stringBuffer.append(option.getLongOpt()); } if(option.getArgName()!=null && extended){ stringBuffer.append(" <"); stringBuffer.append(option.getArgName()); stringBuffer.append(">"); } } return stringBuffer.toString(); }
[ "protected", "String", "optionDisplayString", "(", "final", "String", "opt", ",", "boolean", "extended", ")", "{", "StringBuffer", "stringBuffer", "=", "new", "StringBuffer", "(", ")", ";", "stringBuffer", ".", "append", "(", "\"-\"", ")", ".", "append", "(", "opt", ")", ";", "Option", "option", "=", "getOption", "(", "opt", ")", ";", "if", "(", "null", "!=", "option", ")", "{", "if", "(", "option", ".", "getLongOpt", "(", ")", "!=", "null", ")", "{", "stringBuffer", ".", "append", "(", "\"/--\"", ")", ";", "stringBuffer", ".", "append", "(", "option", ".", "getLongOpt", "(", ")", ")", ";", "}", "if", "(", "option", ".", "getArgName", "(", ")", "!=", "null", "&&", "extended", ")", "{", "stringBuffer", ".", "append", "(", "\" <\"", ")", ";", "stringBuffer", ".", "append", "(", "option", ".", "getArgName", "(", ")", ")", ";", "stringBuffer", ".", "append", "(", "\">\"", ")", ";", "}", "}", "return", "stringBuffer", ".", "toString", "(", ")", ";", "}" ]
Return a string to display the specified option in help text @param extended if true, include full argument descriptor @param opt opt name @return display string
[ "Return", "a", "string", "to", "display", "the", "specified", "option", "in", "help", "text" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java#L111-L127
15,938
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java
BaseTool.run
public void run(final String[] args) throws CLIToolException { PropertyConfigurator.configure(Constants.getLog4jPropertiesFile().getAbsolutePath()); CommandLine cli = parseArgs(args); validateOptions(cli,args); go(); }
java
public void run(final String[] args) throws CLIToolException { PropertyConfigurator.configure(Constants.getLog4jPropertiesFile().getAbsolutePath()); CommandLine cli = parseArgs(args); validateOptions(cli,args); go(); }
[ "public", "void", "run", "(", "final", "String", "[", "]", "args", ")", "throws", "CLIToolException", "{", "PropertyConfigurator", ".", "configure", "(", "Constants", ".", "getLog4jPropertiesFile", "(", ")", ".", "getAbsolutePath", "(", ")", ")", ";", "CommandLine", "cli", "=", "parseArgs", "(", "args", ")", ";", "validateOptions", "(", "cli", ",", "args", ")", ";", "go", "(", ")", ";", "}" ]
Run the tool's lifecycle given the input arguments. @param args the cli arg vector @throws CLIToolException if an error occurs
[ "Run", "the", "tool", "s", "lifecycle", "given", "the", "input", "arguments", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java#L151-L156
15,939
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java
BaseTool.parseArgs
public CommandLine parseArgs(final String[] args) throws CLIToolOptionsException { initOptions(); final CommandLineParser parser = new PosixParser(); try { commandLine = parser.parse(getOptions(), args); } catch (ParseException e) { help(); throw new CLIToolOptionsException(e); } if (null != toolOptions) { for (final CLIToolOptions toolOpts : toolOptions) { toolOpts.parseArgs(commandLine, args); } } return commandLine; }
java
public CommandLine parseArgs(final String[] args) throws CLIToolOptionsException { initOptions(); final CommandLineParser parser = new PosixParser(); try { commandLine = parser.parse(getOptions(), args); } catch (ParseException e) { help(); throw new CLIToolOptionsException(e); } if (null != toolOptions) { for (final CLIToolOptions toolOpts : toolOptions) { toolOpts.parseArgs(commandLine, args); } } return commandLine; }
[ "public", "CommandLine", "parseArgs", "(", "final", "String", "[", "]", "args", ")", "throws", "CLIToolOptionsException", "{", "initOptions", "(", ")", ";", "final", "CommandLineParser", "parser", "=", "new", "PosixParser", "(", ")", ";", "try", "{", "commandLine", "=", "parser", ".", "parse", "(", "getOptions", "(", ")", ",", "args", ")", ";", "}", "catch", "(", "ParseException", "e", ")", "{", "help", "(", ")", ";", "throw", "new", "CLIToolOptionsException", "(", "e", ")", ";", "}", "if", "(", "null", "!=", "toolOptions", ")", "{", "for", "(", "final", "CLIToolOptions", "toolOpts", ":", "toolOptions", ")", "{", "toolOpts", ".", "parseArgs", "(", "commandLine", ",", "args", ")", ";", "}", "}", "return", "commandLine", ";", "}" ]
Parse the options, will apply this for each CLIToolOptions added to the tool. subclasses may override this but should call super
[ "Parse", "the", "options", "will", "apply", "this", "for", "each", "CLIToolOptions", "added", "to", "the", "tool", ".", "subclasses", "may", "override", "this", "but", "should", "call", "super" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java#L162-L177
15,940
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java
BaseTool.validateOptions
public void validateOptions(final CommandLine cli, final String[] args) throws CLIToolOptionsException { if (null != toolOptions) { for (final CLIToolOptions toolOpts : toolOptions) { toolOpts.validate(cli,args); } } }
java
public void validateOptions(final CommandLine cli, final String[] args) throws CLIToolOptionsException { if (null != toolOptions) { for (final CLIToolOptions toolOpts : toolOptions) { toolOpts.validate(cli,args); } } }
[ "public", "void", "validateOptions", "(", "final", "CommandLine", "cli", ",", "final", "String", "[", "]", "args", ")", "throws", "CLIToolOptionsException", "{", "if", "(", "null", "!=", "toolOptions", ")", "{", "for", "(", "final", "CLIToolOptions", "toolOpts", ":", "toolOptions", ")", "{", "toolOpts", ".", "validate", "(", "cli", ",", "args", ")", ";", "}", "}", "}" ]
Validate the values parsed by the options, will apply this for each CLIToolOptions added to the tool. subclasses may override this but should call super @param cli cli @param args args @throws CLIToolOptionsException if an error occurs
[ "Validate", "the", "values", "parsed", "by", "the", "options", "will", "apply", "this", "for", "each", "CLIToolOptions", "added", "to", "the", "tool", ".", "subclasses", "may", "override", "this", "but", "should", "call", "super" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java#L186-L192
15,941
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java
BaseTool.help
public void help() { final HelpFormatter formatter = new HelpFormatter(); final String helpString = getHelpString(); formatter.printHelp(80, helpString, "options:", getOptions(), "[RUNDECK version " + VersionConstants.VERSION + " (" + VersionConstants.BUILD + ")]"); }
java
public void help() { final HelpFormatter formatter = new HelpFormatter(); final String helpString = getHelpString(); formatter.printHelp(80, helpString, "options:", getOptions(), "[RUNDECK version " + VersionConstants.VERSION + " (" + VersionConstants.BUILD + ")]"); }
[ "public", "void", "help", "(", ")", "{", "final", "HelpFormatter", "formatter", "=", "new", "HelpFormatter", "(", ")", ";", "final", "String", "helpString", "=", "getHelpString", "(", ")", ";", "formatter", ".", "printHelp", "(", "80", ",", "helpString", ",", "\"options:\"", ",", "getOptions", "(", ")", ",", "\"[RUNDECK version \"", "+", "VersionConstants", ".", "VERSION", "+", "\" (\"", "+", "VersionConstants", ".", "BUILD", "+", "\")]\"", ")", ";", "}" ]
Writes help message .
[ "Writes", "help", "message", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/cli/BaseTool.java#L212-L220
15,942
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/UpdateUtils.java
UpdateUtils.updateFileFromFile
public static void updateFileFromFile(final File sourceFile, final String destinationFilePath) throws UpdateException { if (!sourceFile.exists()) { throw new UpdateException("Source file does not exist: " + sourceFile); } if (!sourceFile.isFile()) { throw new UpdateException("Not a file: " + sourceFile); } if (sourceFile.length() < 1) { throw new UpdateException("Source file is empty: " + sourceFile); } try { updateFileFromInputStream(new FileInputStream(sourceFile), destinationFilePath); } catch (IOException e) { throw new UpdateException("Unable to update file: " + e.getMessage(), e); } }
java
public static void updateFileFromFile(final File sourceFile, final String destinationFilePath) throws UpdateException { if (!sourceFile.exists()) { throw new UpdateException("Source file does not exist: " + sourceFile); } if (!sourceFile.isFile()) { throw new UpdateException("Not a file: " + sourceFile); } if (sourceFile.length() < 1) { throw new UpdateException("Source file is empty: " + sourceFile); } try { updateFileFromInputStream(new FileInputStream(sourceFile), destinationFilePath); } catch (IOException e) { throw new UpdateException("Unable to update file: " + e.getMessage(), e); } }
[ "public", "static", "void", "updateFileFromFile", "(", "final", "File", "sourceFile", ",", "final", "String", "destinationFilePath", ")", "throws", "UpdateException", "{", "if", "(", "!", "sourceFile", ".", "exists", "(", ")", ")", "{", "throw", "new", "UpdateException", "(", "\"Source file does not exist: \"", "+", "sourceFile", ")", ";", "}", "if", "(", "!", "sourceFile", ".", "isFile", "(", ")", ")", "{", "throw", "new", "UpdateException", "(", "\"Not a file: \"", "+", "sourceFile", ")", ";", "}", "if", "(", "sourceFile", ".", "length", "(", ")", "<", "1", ")", "{", "throw", "new", "UpdateException", "(", "\"Source file is empty: \"", "+", "sourceFile", ")", ";", "}", "try", "{", "updateFileFromInputStream", "(", "new", "FileInputStream", "(", "sourceFile", ")", ",", "destinationFilePath", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "UpdateException", "(", "\"Unable to update file: \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Get the source File and store it to a destination file path @param sourceFile source @param destinationFilePath destination @throws UpdateException on error
[ "Get", "the", "source", "File", "and", "store", "it", "to", "a", "destination", "file", "path" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/UpdateUtils.java#L70-L87
15,943
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/UpdateUtils.java
UpdateUtils.moveFile
private static void moveFile(final File fromFile, final File toFile) throws UpdateException { try { // Create parent directory structure if necessary FileUtils.mkParentDirs(toFile); Files.move(fromFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException ioe) { throw new UpdateException("Unable to move temporary file to destination file: " + fromFile + " -> " + toFile + ": " + ioe.toString()); } }
java
private static void moveFile(final File fromFile, final File toFile) throws UpdateException { try { // Create parent directory structure if necessary FileUtils.mkParentDirs(toFile); Files.move(fromFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException ioe) { throw new UpdateException("Unable to move temporary file to destination file: " + fromFile + " -> " + toFile + ": " + ioe.toString()); } }
[ "private", "static", "void", "moveFile", "(", "final", "File", "fromFile", ",", "final", "File", "toFile", ")", "throws", "UpdateException", "{", "try", "{", "// Create parent directory structure if necessary", "FileUtils", ".", "mkParentDirs", "(", "toFile", ")", ";", "Files", ".", "move", "(", "fromFile", ".", "toPath", "(", ")", ",", "toFile", ".", "toPath", "(", ")", ",", "StandardCopyOption", ".", "REPLACE_EXISTING", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "throw", "new", "UpdateException", "(", "\"Unable to move temporary file to destination file: \"", "+", "fromFile", "+", "\" -> \"", "+", "toFile", "+", "\": \"", "+", "ioe", ".", "toString", "(", ")", ")", ";", "}", "}" ]
Rename the file. Handle possible OS specific issues
[ "Rename", "the", "file", ".", "Handle", "possible", "OS", "specific", "issues" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/UpdateUtils.java#L104-L114
15,944
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/UpdateUtils.java
UpdateUtils.update
public static void update(final FileUpdater updater, final File destFile) throws UpdateException { final File lockFile = new File(destFile.getAbsolutePath() + ".lock"); final File newDestFile = new File(destFile.getAbsolutePath() + ".new"); try { // synchronize writing to file within this jvm synchronized (UpdateUtils.class) { final FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel(); //acquire file lock to block external jvm (commandline) from writing to file final FileLock lock = channel.lock(); try { FileUtils.copyFileStreams(destFile, newDestFile); updater.updateFile(newDestFile); if (newDestFile.isFile() && newDestFile.length() > 0) { moveFile(newDestFile, destFile); } else { throw new UpdateException("Result file was empty or not present: " + newDestFile); } } catch (FileUpdaterException e) { throw new UpdateException(e); } finally { lock.release(); channel.close(); } } } catch (IOException e) { throw new UpdateException("Unable to get and write file: " + e.toString(), e); } }
java
public static void update(final FileUpdater updater, final File destFile) throws UpdateException { final File lockFile = new File(destFile.getAbsolutePath() + ".lock"); final File newDestFile = new File(destFile.getAbsolutePath() + ".new"); try { // synchronize writing to file within this jvm synchronized (UpdateUtils.class) { final FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel(); //acquire file lock to block external jvm (commandline) from writing to file final FileLock lock = channel.lock(); try { FileUtils.copyFileStreams(destFile, newDestFile); updater.updateFile(newDestFile); if (newDestFile.isFile() && newDestFile.length() > 0) { moveFile(newDestFile, destFile); } else { throw new UpdateException("Result file was empty or not present: " + newDestFile); } } catch (FileUpdaterException e) { throw new UpdateException(e); } finally { lock.release(); channel.close(); } } } catch (IOException e) { throw new UpdateException("Unable to get and write file: " + e.toString(), e); } }
[ "public", "static", "void", "update", "(", "final", "FileUpdater", "updater", ",", "final", "File", "destFile", ")", "throws", "UpdateException", "{", "final", "File", "lockFile", "=", "new", "File", "(", "destFile", ".", "getAbsolutePath", "(", ")", "+", "\".lock\"", ")", ";", "final", "File", "newDestFile", "=", "new", "File", "(", "destFile", ".", "getAbsolutePath", "(", ")", "+", "\".new\"", ")", ";", "try", "{", "// synchronize writing to file within this jvm", "synchronized", "(", "UpdateUtils", ".", "class", ")", "{", "final", "FileChannel", "channel", "=", "new", "RandomAccessFile", "(", "lockFile", ",", "\"rw\"", ")", ".", "getChannel", "(", ")", ";", "//acquire file lock to block external jvm (commandline) from writing to file", "final", "FileLock", "lock", "=", "channel", ".", "lock", "(", ")", ";", "try", "{", "FileUtils", ".", "copyFileStreams", "(", "destFile", ",", "newDestFile", ")", ";", "updater", ".", "updateFile", "(", "newDestFile", ")", ";", "if", "(", "newDestFile", ".", "isFile", "(", ")", "&&", "newDestFile", ".", "length", "(", ")", ">", "0", ")", "{", "moveFile", "(", "newDestFile", ",", "destFile", ")", ";", "}", "else", "{", "throw", "new", "UpdateException", "(", "\"Result file was empty or not present: \"", "+", "newDestFile", ")", ";", "}", "}", "catch", "(", "FileUpdaterException", "e", ")", "{", "throw", "new", "UpdateException", "(", "e", ")", ";", "}", "finally", "{", "lock", ".", "release", "(", ")", ";", "channel", ".", "close", "(", ")", ";", "}", "}", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "UpdateException", "(", "\"Unable to get and write file: \"", "+", "e", ".", "toString", "(", ")", ",", "e", ")", ";", "}", "}" ]
Update a destination file with an updater implementation, while maintaining appropriate locks around the action and file @param updater updater @param destFile destination @throws UpdateException on error
[ "Update", "a", "destination", "file", "with", "an", "updater", "implementation", "while", "maintaining", "appropriate", "locks", "around", "the", "action", "and", "file" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/UpdateUtils.java#L183-L213
15,945
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/ContextStack.java
ContextStack.copyPush
public ContextStack<T> copyPush(final T value) { final ContextStack<T> stack1 = copy(); stack1.push(value); return stack1; }
java
public ContextStack<T> copyPush(final T value) { final ContextStack<T> stack1 = copy(); stack1.push(value); return stack1; }
[ "public", "ContextStack", "<", "T", ">", "copyPush", "(", "final", "T", "value", ")", "{", "final", "ContextStack", "<", "T", ">", "stack1", "=", "copy", "(", ")", ";", "stack1", ".", "push", "(", "value", ")", ";", "return", "stack1", ";", "}" ]
Return a new stack based with the same contents and one value pushed
[ "Return", "a", "new", "stack", "based", "with", "the", "same", "contents", "and", "one", "value", "pushed" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/ContextStack.java#L95-L99
15,946
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/ContextStack.java
ContextStack.copyPop
public ContextStack<T> copyPop() { final ContextStack<T> stack1 = copy(); stack1.pop(); return stack1; }
java
public ContextStack<T> copyPop() { final ContextStack<T> stack1 = copy(); stack1.pop(); return stack1; }
[ "public", "ContextStack", "<", "T", ">", "copyPop", "(", ")", "{", "final", "ContextStack", "<", "T", ">", "stack1", "=", "copy", "(", ")", ";", "stack1", ".", "pop", "(", ")", ";", "return", "stack1", ";", "}" ]
Return a new stack with the same contents but pop a value
[ "Return", "a", "new", "stack", "with", "the", "same", "contents", "but", "pop", "a", "value" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/ContextStack.java#L104-L108
15,947
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/NodeSupport.java
NodeSupport.getFrameworkNodeHostname
@Override public String getFrameworkNodeHostname() { String hostname = getLookup().getProperty("framework.server.hostname"); if (null!=hostname) { return hostname.trim(); } else { return hostname; } }
java
@Override public String getFrameworkNodeHostname() { String hostname = getLookup().getProperty("framework.server.hostname"); if (null!=hostname) { return hostname.trim(); } else { return hostname; } }
[ "@", "Override", "public", "String", "getFrameworkNodeHostname", "(", ")", "{", "String", "hostname", "=", "getLookup", "(", ")", ".", "getProperty", "(", "\"framework.server.hostname\"", ")", ";", "if", "(", "null", "!=", "hostname", ")", "{", "return", "hostname", ".", "trim", "(", ")", ";", "}", "else", "{", "return", "hostname", ";", "}", "}" ]
Gets the value of "framework.server.hostname" property @return Returns value of framework.server.hostname property
[ "Gets", "the", "value", "of", "framework", ".", "server", ".", "hostname", "property" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/NodeSupport.java#L44-L52
15,948
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/NodeSupport.java
NodeSupport.getFrameworkNodeName
@Override public String getFrameworkNodeName() { String name = getLookup().getProperty("framework.server.name"); if (null!=name) { return name.trim(); } else { return name; } }
java
@Override public String getFrameworkNodeName() { String name = getLookup().getProperty("framework.server.name"); if (null!=name) { return name.trim(); } else { return name; } }
[ "@", "Override", "public", "String", "getFrameworkNodeName", "(", ")", "{", "String", "name", "=", "getLookup", "(", ")", ".", "getProperty", "(", "\"framework.server.name\"", ")", ";", "if", "(", "null", "!=", "name", ")", "{", "return", "name", ".", "trim", "(", ")", ";", "}", "else", "{", "return", "name", ";", "}", "}" ]
Gets the value of "framework.server.name" property @return Returns value of framework.server.name property
[ "Gets", "the", "value", "of", "framework", ".", "server", ".", "name", "property" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/NodeSupport.java#L59-L67
15,949
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/TextUtils.java
TextUtils.escape
public static String escape(String input, char echar, char[] special) { StringBuilder sb = new StringBuilder(); for (Character character : special) { sb.append(character); } sb.append(echar); String s = Matcher.quoteReplacement(new String(new char[]{echar})); return input.replaceAll("[" + Pattern.quote(sb.toString()) + "]", s + "$0"); }
java
public static String escape(String input, char echar, char[] special) { StringBuilder sb = new StringBuilder(); for (Character character : special) { sb.append(character); } sb.append(echar); String s = Matcher.quoteReplacement(new String(new char[]{echar})); return input.replaceAll("[" + Pattern.quote(sb.toString()) + "]", s + "$0"); }
[ "public", "static", "String", "escape", "(", "String", "input", ",", "char", "echar", ",", "char", "[", "]", "special", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "Character", "character", ":", "special", ")", "{", "sb", ".", "append", "(", "character", ")", ";", "}", "sb", ".", "append", "(", "echar", ")", ";", "String", "s", "=", "Matcher", ".", "quoteReplacement", "(", "new", "String", "(", "new", "char", "[", "]", "{", "echar", "}", ")", ")", ";", "return", "input", ".", "replaceAll", "(", "\"[\"", "+", "Pattern", ".", "quote", "(", "sb", ".", "toString", "(", ")", ")", "+", "\"]\"", ",", "s", "+", "\"$0\"", ")", ";", "}" ]
Escape the input string using the escape delimiter for the given special chars @param input input string @param echar escape char @param special all chars that should be escaped, the escape char itself will be automatically included @return escaped string
[ "Escape", "the", "input", "string", "using", "the", "escape", "delimiter", "for", "the", "given", "special", "chars" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/TextUtils.java#L37-L45
15,950
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/TextUtils.java
TextUtils.join
public static String join(String[] input, char separator) { //simple case, no escaping StringBuilder stringBuilder = new StringBuilder(); for (String s : input) { if (stringBuilder.length() > 0) { stringBuilder.append(separator); } stringBuilder.append(s); } return stringBuilder.toString(); }
java
public static String join(String[] input, char separator) { //simple case, no escaping StringBuilder stringBuilder = new StringBuilder(); for (String s : input) { if (stringBuilder.length() > 0) { stringBuilder.append(separator); } stringBuilder.append(s); } return stringBuilder.toString(); }
[ "public", "static", "String", "join", "(", "String", "[", "]", "input", ",", "char", "separator", ")", "{", "//simple case, no escaping", "StringBuilder", "stringBuilder", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "String", "s", ":", "input", ")", "{", "if", "(", "stringBuilder", ".", "length", "(", ")", ">", "0", ")", "{", "stringBuilder", ".", "append", "(", "separator", ")", ";", "}", "stringBuilder", ".", "append", "(", "s", ")", ";", "}", "return", "stringBuilder", ".", "toString", "(", ")", ";", "}" ]
Join an array of strings with the given separator, without escaping @param input input string @param separator separator @return joined string
[ "Join", "an", "array", "of", "strings", "with", "the", "given", "separator", "without", "escaping" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/TextUtils.java#L170-L180
15,951
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/TextUtils.java
TextUtils.joinEscaped
public static String joinEscaped(String[] input, char separator, char echar, char[] special) { StringBuilder sb = new StringBuilder(); char[] schars = new char[(special != null ? special.length : 0) + 1]; if (special != null && special.length > 0) { System.arraycopy(special, 0, schars, 1, special.length); } schars[0] = separator; for (String s : input) { if (sb.length() > 0) { sb.append(separator); } sb.append(escape(s, echar, schars)); } return sb.toString(); }
java
public static String joinEscaped(String[] input, char separator, char echar, char[] special) { StringBuilder sb = new StringBuilder(); char[] schars = new char[(special != null ? special.length : 0) + 1]; if (special != null && special.length > 0) { System.arraycopy(special, 0, schars, 1, special.length); } schars[0] = separator; for (String s : input) { if (sb.length() > 0) { sb.append(separator); } sb.append(escape(s, echar, schars)); } return sb.toString(); }
[ "public", "static", "String", "joinEscaped", "(", "String", "[", "]", "input", ",", "char", "separator", ",", "char", "echar", ",", "char", "[", "]", "special", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "char", "[", "]", "schars", "=", "new", "char", "[", "(", "special", "!=", "null", "?", "special", ".", "length", ":", "0", ")", "+", "1", "]", ";", "if", "(", "special", "!=", "null", "&&", "special", ".", "length", ">", "0", ")", "{", "System", ".", "arraycopy", "(", "special", ",", "0", ",", "schars", ",", "1", ",", "special", ".", "length", ")", ";", "}", "schars", "[", "0", "]", "=", "separator", ";", "for", "(", "String", "s", ":", "input", ")", "{", "if", "(", "sb", ".", "length", "(", ")", ">", "0", ")", "{", "sb", ".", "append", "(", "separator", ")", ";", "}", "sb", ".", "append", "(", "escape", "(", "s", ",", "echar", ",", "schars", ")", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Join an array of strings with the given separator, escape char, and other special chars for escaping @param input input string @param separator separator @param echar escape char @param special all special chars not necessarily including the echar or separator @return joined string
[ "Join", "an", "array", "of", "strings", "with", "the", "given", "separator", "escape", "char", "and", "other", "special", "chars", "for", "escaping" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/TextUtils.java#L192-L206
15,952
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/resources/format/ResourceFormatParserService.java
ResourceFormatParserService.getParserForFileExtension
public ResourceFormatParser getParserForFileExtension(final File file) throws UnsupportedFormatException { String extension = getFileExtension(file.getName()); if (null != extension) { return getParserForFileExtension(extension); } else { throw new UnsupportedFormatException("Could not determine format for file: " + file.getAbsolutePath()); } }
java
public ResourceFormatParser getParserForFileExtension(final File file) throws UnsupportedFormatException { String extension = getFileExtension(file.getName()); if (null != extension) { return getParserForFileExtension(extension); } else { throw new UnsupportedFormatException("Could not determine format for file: " + file.getAbsolutePath()); } }
[ "public", "ResourceFormatParser", "getParserForFileExtension", "(", "final", "File", "file", ")", "throws", "UnsupportedFormatException", "{", "String", "extension", "=", "getFileExtension", "(", "file", ".", "getName", "(", ")", ")", ";", "if", "(", "null", "!=", "extension", ")", "{", "return", "getParserForFileExtension", "(", "extension", ")", ";", "}", "else", "{", "throw", "new", "UnsupportedFormatException", "(", "\"Could not determine format for file: \"", "+", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "}", "}" ]
Return a parser for a file, based on the file extension. @param file the file @return the parser found for the extension @throws UnsupportedFormatException if the file extension does not match an available parser, or if the file has no extension
[ "Return", "a", "parser", "for", "a", "file", "based", "on", "the", "file", "extension", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/resources/format/ResourceFormatParserService.java#L104-L111
15,953
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/resources/format/ResourceFormatParserService.java
ResourceFormatParserService.getParserForFileExtension
public ResourceFormatParser getParserForFileExtension(final String extension) throws UnsupportedFormatException { for (final ResourceFormatParser resourceFormatParser : listParsers()) { if (resourceFormatParser.getFileExtensions().contains(extension)) { return resourceFormatParser; } } throw new UnsupportedFormatException("No provider available to parse file extension: " + extension); }
java
public ResourceFormatParser getParserForFileExtension(final String extension) throws UnsupportedFormatException { for (final ResourceFormatParser resourceFormatParser : listParsers()) { if (resourceFormatParser.getFileExtensions().contains(extension)) { return resourceFormatParser; } } throw new UnsupportedFormatException("No provider available to parse file extension: " + extension); }
[ "public", "ResourceFormatParser", "getParserForFileExtension", "(", "final", "String", "extension", ")", "throws", "UnsupportedFormatException", "{", "for", "(", "final", "ResourceFormatParser", "resourceFormatParser", ":", "listParsers", "(", ")", ")", "{", "if", "(", "resourceFormatParser", ".", "getFileExtensions", "(", ")", ".", "contains", "(", "extension", ")", ")", "{", "return", "resourceFormatParser", ";", "}", "}", "throw", "new", "UnsupportedFormatException", "(", "\"No provider available to parse file extension: \"", "+", "extension", ")", ";", "}" ]
Return a parser for a file, based on the bare file extension. @param extension the file extension string @return the parser found for the extension @throws UnsupportedFormatException if the file extension does not match an available parser, or if the file has no extension
[ "Return", "a", "parser", "for", "a", "file", "based", "on", "the", "bare", "file", "extension", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/resources/format/ResourceFormatParserService.java#L132-L139
15,954
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/resources/format/ResourceFormatParserService.java
ResourceFormatParserService.getParserForMIMEType
public ResourceFormatParser getParserForMIMEType(final String mimeType) throws UnsupportedFormatException { //clean up encoding final String cleanMime; if (null != mimeType && mimeType.indexOf(";") > 0) { cleanMime = mimeType.substring(0, mimeType.indexOf(";")); } else { cleanMime = mimeType; } if (!validMimeType(cleanMime)) { throw new IllegalArgumentException("Invalid MIME type: " + mimeType); } for (final ResourceFormatParser resourceFormatParser : listParsers()) { if(null!= resourceFormatParser.getMIMETypes()){ if (resourceFormatParser.getMIMETypes().contains(cleanMime)) { return resourceFormatParser; } else { for (final String s : resourceFormatParser.getMIMETypes()) { if (validMimeType(s) && s.startsWith("*/")) { String t1 = s.substring(2); String t2 = cleanMime.substring(cleanMime.indexOf("/") + 1); if (t1.equals(t2)) { return resourceFormatParser; } } } } } } throw new UnsupportedFormatException("No provider available to parse MIME type: " + mimeType); }
java
public ResourceFormatParser getParserForMIMEType(final String mimeType) throws UnsupportedFormatException { //clean up encoding final String cleanMime; if (null != mimeType && mimeType.indexOf(";") > 0) { cleanMime = mimeType.substring(0, mimeType.indexOf(";")); } else { cleanMime = mimeType; } if (!validMimeType(cleanMime)) { throw new IllegalArgumentException("Invalid MIME type: " + mimeType); } for (final ResourceFormatParser resourceFormatParser : listParsers()) { if(null!= resourceFormatParser.getMIMETypes()){ if (resourceFormatParser.getMIMETypes().contains(cleanMime)) { return resourceFormatParser; } else { for (final String s : resourceFormatParser.getMIMETypes()) { if (validMimeType(s) && s.startsWith("*/")) { String t1 = s.substring(2); String t2 = cleanMime.substring(cleanMime.indexOf("/") + 1); if (t1.equals(t2)) { return resourceFormatParser; } } } } } } throw new UnsupportedFormatException("No provider available to parse MIME type: " + mimeType); }
[ "public", "ResourceFormatParser", "getParserForMIMEType", "(", "final", "String", "mimeType", ")", "throws", "UnsupportedFormatException", "{", "//clean up encoding", "final", "String", "cleanMime", ";", "if", "(", "null", "!=", "mimeType", "&&", "mimeType", ".", "indexOf", "(", "\";\"", ")", ">", "0", ")", "{", "cleanMime", "=", "mimeType", ".", "substring", "(", "0", ",", "mimeType", ".", "indexOf", "(", "\";\"", ")", ")", ";", "}", "else", "{", "cleanMime", "=", "mimeType", ";", "}", "if", "(", "!", "validMimeType", "(", "cleanMime", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid MIME type: \"", "+", "mimeType", ")", ";", "}", "for", "(", "final", "ResourceFormatParser", "resourceFormatParser", ":", "listParsers", "(", ")", ")", "{", "if", "(", "null", "!=", "resourceFormatParser", ".", "getMIMETypes", "(", ")", ")", "{", "if", "(", "resourceFormatParser", ".", "getMIMETypes", "(", ")", ".", "contains", "(", "cleanMime", ")", ")", "{", "return", "resourceFormatParser", ";", "}", "else", "{", "for", "(", "final", "String", "s", ":", "resourceFormatParser", ".", "getMIMETypes", "(", ")", ")", "{", "if", "(", "validMimeType", "(", "s", ")", "&&", "s", ".", "startsWith", "(", "\"*/\"", ")", ")", "{", "String", "t1", "=", "s", ".", "substring", "(", "2", ")", ";", "String", "t2", "=", "cleanMime", ".", "substring", "(", "cleanMime", ".", "indexOf", "(", "\"/\"", ")", "+", "1", ")", ";", "if", "(", "t1", ".", "equals", "(", "t2", ")", ")", "{", "return", "resourceFormatParser", ";", "}", "}", "}", "}", "}", "}", "throw", "new", "UnsupportedFormatException", "(", "\"No provider available to parse MIME type: \"", "+", "mimeType", ")", ";", "}" ]
Return a parser for a mime type. @param mimeType the MIME type string @return The first matching parser for the mime type @throws UnsupportedFormatException if no parser are available for the MIME type
[ "Return", "a", "parser", "for", "a", "mime", "type", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/resources/format/ResourceFormatParserService.java#L167-L196
15,955
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java
StringArrayUtil.merge
public static String[] merge(final String[] input, final String[] list) { final List<String> v = new ArrayList<String>(Arrays.asList(list)); for (final String anInput : input) { if ((null != anInput) && !v.contains(anInput)) { v.add(anInput); } } return v.toArray(new String[v.size()]); }
java
public static String[] merge(final String[] input, final String[] list) { final List<String> v = new ArrayList<String>(Arrays.asList(list)); for (final String anInput : input) { if ((null != anInput) && !v.contains(anInput)) { v.add(anInput); } } return v.toArray(new String[v.size()]); }
[ "public", "static", "String", "[", "]", "merge", "(", "final", "String", "[", "]", "input", ",", "final", "String", "[", "]", "list", ")", "{", "final", "List", "<", "String", ">", "v", "=", "new", "ArrayList", "<", "String", ">", "(", "Arrays", ".", "asList", "(", "list", ")", ")", ";", "for", "(", "final", "String", "anInput", ":", "input", ")", "{", "if", "(", "(", "null", "!=", "anInput", ")", "&&", "!", "v", ".", "contains", "(", "anInput", ")", ")", "{", "v", ".", "add", "(", "anInput", ")", ";", "}", "}", "return", "v", ".", "toArray", "(", "new", "String", "[", "v", ".", "size", "(", ")", "]", ")", ";", "}" ]
Merge to string arrays @param input Array elements to add @param list List to merge input into @return string array of merged set
[ "Merge", "to", "string", "arrays" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java#L33-L41
15,956
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java
StringArrayUtil.subtract
public static String[] subtract(final String[] input, final String[] list) { final Set<String> difference = new HashSet<String>(Arrays.asList(list)); difference.removeAll(Arrays.asList(input)); return difference.toArray(new String[difference.size()]); }
java
public static String[] subtract(final String[] input, final String[] list) { final Set<String> difference = new HashSet<String>(Arrays.asList(list)); difference.removeAll(Arrays.asList(input)); return difference.toArray(new String[difference.size()]); }
[ "public", "static", "String", "[", "]", "subtract", "(", "final", "String", "[", "]", "input", ",", "final", "String", "[", "]", "list", ")", "{", "final", "Set", "<", "String", ">", "difference", "=", "new", "HashSet", "<", "String", ">", "(", "Arrays", ".", "asList", "(", "list", ")", ")", ";", "difference", ".", "removeAll", "(", "Arrays", ".", "asList", "(", "input", ")", ")", ";", "return", "difference", ".", "toArray", "(", "new", "String", "[", "difference", ".", "size", "(", ")", "]", ")", ";", "}" ]
Subtract one string array from another @param input Array elements to subtract @param list List to subtract from @return string array of merged set
[ "Subtract", "one", "string", "array", "from", "another" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java#L50-L54
15,957
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java
StringArrayUtil.asString
public static String asString(final Object[] input, final String delim) { final StringBuffer sb = new StringBuffer(); for (int i = 0 ; i < input.length ; i++) { if (i > 0) { sb.append(delim); } sb.append(input[i].toString()); } return sb.toString(); }
java
public static String asString(final Object[] input, final String delim) { final StringBuffer sb = new StringBuffer(); for (int i = 0 ; i < input.length ; i++) { if (i > 0) { sb.append(delim); } sb.append(input[i].toString()); } return sb.toString(); }
[ "public", "static", "String", "asString", "(", "final", "Object", "[", "]", "input", ",", "final", "String", "delim", ")", "{", "final", "StringBuffer", "sb", "=", "new", "StringBuffer", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "input", ".", "length", ";", "i", "++", ")", "{", "if", "(", "i", ">", "0", ")", "{", "sb", ".", "append", "(", "delim", ")", ";", "}", "sb", ".", "append", "(", "input", "[", "i", "]", ".", "toString", "(", ")", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Format an array of objects as a string separated by a delimiter by calling toString on each object @param input List to format @param delim delimiter string to insert between elements @return formatted string
[ "Format", "an", "array", "of", "objects", "as", "a", "string", "separated", "by", "a", "delimiter", "by", "calling", "toString", "on", "each", "object" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java#L63-L72
15,958
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java
StringArrayUtil.difference
public static String[] difference(final String[] list1, final String[] list2) { HashSet<String> set = new HashSet<String>(); HashSet<String> set1 = new HashSet<String>(Arrays.asList(list1)); HashSet<String> set2 = new HashSet<String>(Arrays.asList(list2)); for (final String s : list1) { if (!set2.contains(s)) { set.add(s); } } for (final String s : list2) { if (!set1.contains(s)) { set.add(s); } } return set.toArray(new String[set.size()]); }
java
public static String[] difference(final String[] list1, final String[] list2) { HashSet<String> set = new HashSet<String>(); HashSet<String> set1 = new HashSet<String>(Arrays.asList(list1)); HashSet<String> set2 = new HashSet<String>(Arrays.asList(list2)); for (final String s : list1) { if (!set2.contains(s)) { set.add(s); } } for (final String s : list2) { if (!set1.contains(s)) { set.add(s); } } return set.toArray(new String[set.size()]); }
[ "public", "static", "String", "[", "]", "difference", "(", "final", "String", "[", "]", "list1", ",", "final", "String", "[", "]", "list2", ")", "{", "HashSet", "<", "String", ">", "set", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "HashSet", "<", "String", ">", "set1", "=", "new", "HashSet", "<", "String", ">", "(", "Arrays", ".", "asList", "(", "list1", ")", ")", ";", "HashSet", "<", "String", ">", "set2", "=", "new", "HashSet", "<", "String", ">", "(", "Arrays", ".", "asList", "(", "list2", ")", ")", ";", "for", "(", "final", "String", "s", ":", "list1", ")", "{", "if", "(", "!", "set2", ".", "contains", "(", "s", ")", ")", "{", "set", ".", "add", "(", "s", ")", ";", "}", "}", "for", "(", "final", "String", "s", ":", "list2", ")", "{", "if", "(", "!", "set1", ".", "contains", "(", "s", ")", ")", "{", "set", ".", "add", "(", "s", ")", ";", "}", "}", "return", "set", ".", "toArray", "(", "new", "String", "[", "set", ".", "size", "(", ")", "]", ")", ";", "}" ]
The difference set operation @param list1 list1 @param list2 list2 @return the set of all items not in both lists
[ "The", "difference", "set", "operation" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/StringArrayUtil.java#L96-L111
15,959
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/resources/FileResourceModelSource.java
FileResourceModelSource.parseFile
public static INodeSet parseFile(final File file, final Framework framework, final String project) throws ResourceModelSourceException, ConfigurationException { final FileResourceModelSource prov = new FileResourceModelSource(framework); prov.configure( Configuration.build() .file(file) .includeServerNode(false) .generateFileAutomatically(false) .project(project) .requireFileExists(true) ); return prov.getNodes(); }
java
public static INodeSet parseFile(final File file, final Framework framework, final String project) throws ResourceModelSourceException, ConfigurationException { final FileResourceModelSource prov = new FileResourceModelSource(framework); prov.configure( Configuration.build() .file(file) .includeServerNode(false) .generateFileAutomatically(false) .project(project) .requireFileExists(true) ); return prov.getNodes(); }
[ "public", "static", "INodeSet", "parseFile", "(", "final", "File", "file", ",", "final", "Framework", "framework", ",", "final", "String", "project", ")", "throws", "ResourceModelSourceException", ",", "ConfigurationException", "{", "final", "FileResourceModelSource", "prov", "=", "new", "FileResourceModelSource", "(", "framework", ")", ";", "prov", ".", "configure", "(", "Configuration", ".", "build", "(", ")", ".", "file", "(", "file", ")", ".", "includeServerNode", "(", "false", ")", ".", "generateFileAutomatically", "(", "false", ")", ".", "project", "(", "project", ")", ".", "requireFileExists", "(", "true", ")", ")", ";", "return", "prov", ".", "getNodes", "(", ")", ";", "}" ]
Utility method to directly parse the nodes from a file @param file file @param framework fwk @param project project name @return nodes @throws ResourceModelSourceException if an error occurs @throws ConfigurationException if a configuration error occurs
[ "Utility", "method", "to", "directly", "parse", "the", "nodes", "from", "a", "file" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/resources/FileResourceModelSource.java#L203-L217
15,960
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/storage/StorageUtil.java
StorageUtil.create
public static ResourceMetaBuilder create(Map<String, String> meta) { ResourceMetaBuilder mutableRundeckResourceMeta = new ResourceMetaBuilder(meta); return mutableRundeckResourceMeta; }
java
public static ResourceMetaBuilder create(Map<String, String> meta) { ResourceMetaBuilder mutableRundeckResourceMeta = new ResourceMetaBuilder(meta); return mutableRundeckResourceMeta; }
[ "public", "static", "ResourceMetaBuilder", "create", "(", "Map", "<", "String", ",", "String", ">", "meta", ")", "{", "ResourceMetaBuilder", "mutableRundeckResourceMeta", "=", "new", "ResourceMetaBuilder", "(", "meta", ")", ";", "return", "mutableRundeckResourceMeta", ";", "}" ]
Create a new builder with a set of metadata @param meta original metadata @return builder
[ "Create", "a", "new", "builder", "with", "a", "set", "of", "metadata" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/storage/StorageUtil.java#L87-L90
15,961
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/storage/StorageUtil.java
StorageUtil.deletePathRecursive
public static boolean deletePathRecursive(Tree<ResourceMeta> tree, Path path){ if(tree.hasResource(path)) { //delete just this resource return tree.deleteResource(path); }else if (tree.hasDirectory(path)) { //list resources and delete Set<Resource<ResourceMeta>> resources = tree.listDirectory(path); boolean failed=false; for (Resource<ResourceMeta> resource : resources) { if(resource.isDirectory()){ if(!deletePathRecursive(tree,resource.getPath())){ failed=true; } }else { if(!tree.deleteResource(resource.getPath())){ failed=true; } } } return !failed; }else{ return true; } }
java
public static boolean deletePathRecursive(Tree<ResourceMeta> tree, Path path){ if(tree.hasResource(path)) { //delete just this resource return tree.deleteResource(path); }else if (tree.hasDirectory(path)) { //list resources and delete Set<Resource<ResourceMeta>> resources = tree.listDirectory(path); boolean failed=false; for (Resource<ResourceMeta> resource : resources) { if(resource.isDirectory()){ if(!deletePathRecursive(tree,resource.getPath())){ failed=true; } }else { if(!tree.deleteResource(resource.getPath())){ failed=true; } } } return !failed; }else{ return true; } }
[ "public", "static", "boolean", "deletePathRecursive", "(", "Tree", "<", "ResourceMeta", ">", "tree", ",", "Path", "path", ")", "{", "if", "(", "tree", ".", "hasResource", "(", "path", ")", ")", "{", "//delete just this resource", "return", "tree", ".", "deleteResource", "(", "path", ")", ";", "}", "else", "if", "(", "tree", ".", "hasDirectory", "(", "path", ")", ")", "{", "//list resources and delete", "Set", "<", "Resource", "<", "ResourceMeta", ">>", "resources", "=", "tree", ".", "listDirectory", "(", "path", ")", ";", "boolean", "failed", "=", "false", ";", "for", "(", "Resource", "<", "ResourceMeta", ">", "resource", ":", "resources", ")", "{", "if", "(", "resource", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "!", "deletePathRecursive", "(", "tree", ",", "resource", ".", "getPath", "(", ")", ")", ")", "{", "failed", "=", "true", ";", "}", "}", "else", "{", "if", "(", "!", "tree", ".", "deleteResource", "(", "resource", ".", "getPath", "(", ")", ")", ")", "{", "failed", "=", "true", ";", "}", "}", "}", "return", "!", "failed", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Delete all resources and subdirectories of the given resource path @param tree tree @param path path @return true if all resources were deleted successfully.
[ "Delete", "all", "resources", "and", "subdirectories", "of", "the", "given", "resource", "path" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/storage/StorageUtil.java#L123-L146
15,962
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/storage/StorageUtil.java
StorageUtil.resolvedTree
public static <S> StorageTree resolvedTree(S context, ExtTree<S, ResourceMeta> authStorage) { return ResolvedExtTree.with(context, authStorage); }
java
public static <S> StorageTree resolvedTree(S context, ExtTree<S, ResourceMeta> authStorage) { return ResolvedExtTree.with(context, authStorage); }
[ "public", "static", "<", "S", ">", "StorageTree", "resolvedTree", "(", "S", "context", ",", "ExtTree", "<", "S", ",", "ResourceMeta", ">", "authStorage", ")", "{", "return", "ResolvedExtTree", ".", "with", "(", "context", ",", "authStorage", ")", ";", "}" ]
Create a StorageTree using authorization context and authorizing tree @param context auth context @param authStorage authorizing storage tree @param <S> context type @return StorageTree for the authorization context
[ "Create", "a", "StorageTree", "using", "authorization", "context", "and", "authorizing", "tree" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/storage/StorageUtil.java#L184-L186
15,963
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/PoliciesCache.java
PoliciesCache.fromFile
public static PoliciesCache fromFile(File singleFile, Set<Attribute> forcedContext) { return fromSourceProvider(YamlProvider.getFileProvider(singleFile), forcedContext); }
java
public static PoliciesCache fromFile(File singleFile, Set<Attribute> forcedContext) { return fromSourceProvider(YamlProvider.getFileProvider(singleFile), forcedContext); }
[ "public", "static", "PoliciesCache", "fromFile", "(", "File", "singleFile", ",", "Set", "<", "Attribute", ">", "forcedContext", ")", "{", "return", "fromSourceProvider", "(", "YamlProvider", ".", "getFileProvider", "(", "singleFile", ")", ",", "forcedContext", ")", ";", "}" ]
Create a cache from a single file source @param singleFile file @return cache
[ "Create", "a", "cache", "from", "a", "single", "file", "source" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/PoliciesCache.java#L155-L157
15,964
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/PoliciesCache.java
PoliciesCache.fromSourceProvider
public static PoliciesCache fromSourceProvider( final SourceProvider provider, final Set<Attribute> forcedContext ) { return new PoliciesCache(provider, forcedContext); }
java
public static PoliciesCache fromSourceProvider( final SourceProvider provider, final Set<Attribute> forcedContext ) { return new PoliciesCache(provider, forcedContext); }
[ "public", "static", "PoliciesCache", "fromSourceProvider", "(", "final", "SourceProvider", "provider", ",", "final", "Set", "<", "Attribute", ">", "forcedContext", ")", "{", "return", "new", "PoliciesCache", "(", "provider", ",", "forcedContext", ")", ";", "}" ]
Create from a provider with a forced context @param provider source provider @param forcedContext forced context @return policies cache
[ "Create", "from", "a", "provider", "with", "a", "forced", "context" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/PoliciesCache.java#L175-L181
15,965
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/PoliciesCache.java
PoliciesCache.fromDir
public static PoliciesCache fromDir(File rootDir, final Set<Attribute> forcedContext) { return fromSourceProvider(YamlProvider.getDirProvider(rootDir),forcedContext); }
java
public static PoliciesCache fromDir(File rootDir, final Set<Attribute> forcedContext) { return fromSourceProvider(YamlProvider.getDirProvider(rootDir),forcedContext); }
[ "public", "static", "PoliciesCache", "fromDir", "(", "File", "rootDir", ",", "final", "Set", "<", "Attribute", ">", "forcedContext", ")", "{", "return", "fromSourceProvider", "(", "YamlProvider", ".", "getDirProvider", "(", "rootDir", ")", ",", "forcedContext", ")", ";", "}" ]
Create a cache from a directory source @param rootDir base director @return cache
[ "Create", "a", "cache", "from", "a", "directory", "source" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/authorization/providers/PoliciesCache.java#L197-L199
15,966
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/plugins/util/PropertyBuilder.java
PropertyBuilder.renderingAsTextarea
public PropertyBuilder renderingAsTextarea() { if (this.type != Property.Type.String) { throw new IllegalStateException("stringRenderingTextarea can only be applied to a String property"); } return renderingOption(StringRenderingConstants.DISPLAY_TYPE_KEY, StringRenderingConstants.DisplayType .MULTI_LINE); }
java
public PropertyBuilder renderingAsTextarea() { if (this.type != Property.Type.String) { throw new IllegalStateException("stringRenderingTextarea can only be applied to a String property"); } return renderingOption(StringRenderingConstants.DISPLAY_TYPE_KEY, StringRenderingConstants.DisplayType .MULTI_LINE); }
[ "public", "PropertyBuilder", "renderingAsTextarea", "(", ")", "{", "if", "(", "this", ".", "type", "!=", "Property", ".", "Type", ".", "String", ")", "{", "throw", "new", "IllegalStateException", "(", "\"stringRenderingTextarea can only be applied to a String property\"", ")", ";", "}", "return", "renderingOption", "(", "StringRenderingConstants", ".", "DISPLAY_TYPE_KEY", ",", "StringRenderingConstants", ".", "DisplayType", ".", "MULTI_LINE", ")", ";", "}" ]
Set the string property to display as a Multi-line Text area. @return this builder @throws IllegalStateException if the property type is not {@link Property.Type#String}
[ "Set", "the", "string", "property", "to", "display", "as", "a", "Multi", "-", "line", "Text", "area", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/plugins/util/PropertyBuilder.java#L315-L321
15,967
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/plugins/util/PropertyBuilder.java
PropertyBuilder.renderingAsPassword
public PropertyBuilder renderingAsPassword() { if (this.type != Property.Type.String) { throw new IllegalStateException("stringRenderingPassword can only be applied to a String property"); } return renderingOption(StringRenderingConstants.DISPLAY_TYPE_KEY, StringRenderingConstants.DisplayType .PASSWORD); }
java
public PropertyBuilder renderingAsPassword() { if (this.type != Property.Type.String) { throw new IllegalStateException("stringRenderingPassword can only be applied to a String property"); } return renderingOption(StringRenderingConstants.DISPLAY_TYPE_KEY, StringRenderingConstants.DisplayType .PASSWORD); }
[ "public", "PropertyBuilder", "renderingAsPassword", "(", ")", "{", "if", "(", "this", ".", "type", "!=", "Property", ".", "Type", ".", "String", ")", "{", "throw", "new", "IllegalStateException", "(", "\"stringRenderingPassword can only be applied to a String property\"", ")", ";", "}", "return", "renderingOption", "(", "StringRenderingConstants", ".", "DISPLAY_TYPE_KEY", ",", "StringRenderingConstants", ".", "DisplayType", ".", "PASSWORD", ")", ";", "}" ]
Set the string property to display as a Password. @return this builder @throws IllegalStateException if the property type is not {@link Property.Type#String}
[ "Set", "the", "string", "property", "to", "display", "as", "a", "Password", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/plugins/util/PropertyBuilder.java#L327-L333
15,968
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/plugins/util/PropertyBuilder.java
PropertyBuilder.build
public Property build() { if (null == type) { throw new IllegalStateException("type is required"); } if (null == name) { throw new IllegalStateException("name is required"); } return PropertyUtil.forType( type, name, title, description, required, value, values, labels, validator, scope, renderingOptions, dynamicValues ); }
java
public Property build() { if (null == type) { throw new IllegalStateException("type is required"); } if (null == name) { throw new IllegalStateException("name is required"); } return PropertyUtil.forType( type, name, title, description, required, value, values, labels, validator, scope, renderingOptions, dynamicValues ); }
[ "public", "Property", "build", "(", ")", "{", "if", "(", "null", "==", "type", ")", "{", "throw", "new", "IllegalStateException", "(", "\"type is required\"", ")", ";", "}", "if", "(", "null", "==", "name", ")", "{", "throw", "new", "IllegalStateException", "(", "\"name is required\"", ")", ";", "}", "return", "PropertyUtil", ".", "forType", "(", "type", ",", "name", ",", "title", ",", "description", ",", "required", ",", "value", ",", "values", ",", "labels", ",", "validator", ",", "scope", ",", "renderingOptions", ",", "dynamicValues", ")", ";", "}" ]
Build the Property object @return built property @throws IllegalStateException if type or name is not set
[ "Build", "the", "Property", "object" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/plugins/util/PropertyBuilder.java#L340-L361
15,969
rundeck/rundeck
rundeck-storage/rundeck-storage-conf/src/main/java/org/rundeck/storage/conf/SubPathTree.java
SubPathTree.translatePathExternal
private String translatePathExternal(String intpath) { if (fullPath) { return intpath; } else { return PathUtil.appendPath(rootPath.getPath(), intpath); } }
java
private String translatePathExternal(String intpath) { if (fullPath) { return intpath; } else { return PathUtil.appendPath(rootPath.getPath(), intpath); } }
[ "private", "String", "translatePathExternal", "(", "String", "intpath", ")", "{", "if", "(", "fullPath", ")", "{", "return", "intpath", ";", "}", "else", "{", "return", "PathUtil", ".", "appendPath", "(", "rootPath", ".", "getPath", "(", ")", ",", "intpath", ")", ";", "}", "}" ]
convert internal path to external @param intpath @return
[ "convert", "internal", "path", "to", "external" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-conf/src/main/java/org/rundeck/storage/conf/SubPathTree.java#L80-L86
15,970
rundeck/rundeck
rundeck-storage/rundeck-storage-conf/src/main/java/org/rundeck/storage/conf/SubPathTree.java
SubPathTree.translateResourceExternal
private Resource<T> translateResourceExternal(Resource<T> resource) { if (fullPath) { return resource; } return new translatedResource<T>(resource, translatePathExternal(resource.getPath())); }
java
private Resource<T> translateResourceExternal(Resource<T> resource) { if (fullPath) { return resource; } return new translatedResource<T>(resource, translatePathExternal(resource.getPath())); }
[ "private", "Resource", "<", "T", ">", "translateResourceExternal", "(", "Resource", "<", "T", ">", "resource", ")", "{", "if", "(", "fullPath", ")", "{", "return", "resource", ";", "}", "return", "new", "translatedResource", "<", "T", ">", "(", "resource", ",", "translatePathExternal", "(", "resource", ".", "getPath", "(", ")", ")", ")", ";", "}" ]
Expose a resource with a path that maps to external path @param resource @return
[ "Expose", "a", "resource", "with", "a", "path", "that", "maps", "to", "external", "path" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/rundeck-storage/rundeck-storage-conf/src/main/java/org/rundeck/storage/conf/SubPathTree.java#L183-L188
15,971
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/resources/ResourceModelSourceService.java
ResourceModelSourceService.factoryConverter
public static Function<ResourceModelSourceFactory, ResourceModelSource> factoryConverter( final Properties configuration ) { //nb: not using lambda due to inability to mock this class within grails tests, some conflict with cglib and // j8 lambdas return new Function<ResourceModelSourceFactory, ResourceModelSource>() { @Override public ResourceModelSource apply(final ResourceModelSourceFactory resourceModelSourceFactory) { try { return resourceModelSourceFactory.createResourceModelSource(configuration); } catch (ConfigurationException e) { throw new RuntimeException(e); } } }; }
java
public static Function<ResourceModelSourceFactory, ResourceModelSource> factoryConverter( final Properties configuration ) { //nb: not using lambda due to inability to mock this class within grails tests, some conflict with cglib and // j8 lambdas return new Function<ResourceModelSourceFactory, ResourceModelSource>() { @Override public ResourceModelSource apply(final ResourceModelSourceFactory resourceModelSourceFactory) { try { return resourceModelSourceFactory.createResourceModelSource(configuration); } catch (ConfigurationException e) { throw new RuntimeException(e); } } }; }
[ "public", "static", "Function", "<", "ResourceModelSourceFactory", ",", "ResourceModelSource", ">", "factoryConverter", "(", "final", "Properties", "configuration", ")", "{", "//nb: not using lambda due to inability to mock this class within grails tests, some conflict with cglib and", "// j8 lambdas", "return", "new", "Function", "<", "ResourceModelSourceFactory", ",", "ResourceModelSource", ">", "(", ")", "{", "@", "Override", "public", "ResourceModelSource", "apply", "(", "final", "ResourceModelSourceFactory", "resourceModelSourceFactory", ")", "{", "try", "{", "return", "resourceModelSourceFactory", ".", "createResourceModelSource", "(", "configuration", ")", ";", "}", "catch", "(", "ConfigurationException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "}", "}", ";", "}" ]
Given input configuration, produce a function to convert from a factory to model source @param configuration @return
[ "Given", "input", "configuration", "produce", "a", "function", "to", "convert", "from", "a", "factory", "to", "model", "source" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/resources/ResourceModelSourceService.java#L123-L139
15,972
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/steps/node/NodeStepDataResultImpl.java
NodeStepDataResultImpl.with
public static NodeStepResult with(final NodeStepResult result, final WFSharedContext dataContext) { return new NodeStepDataResultImpl( result, result.getException(), result.getFailureReason(), result.getFailureMessage(), result.getFailureData(), result.getNode(), dataContext ); }
java
public static NodeStepResult with(final NodeStepResult result, final WFSharedContext dataContext) { return new NodeStepDataResultImpl( result, result.getException(), result.getFailureReason(), result.getFailureMessage(), result.getFailureData(), result.getNode(), dataContext ); }
[ "public", "static", "NodeStepResult", "with", "(", "final", "NodeStepResult", "result", ",", "final", "WFSharedContext", "dataContext", ")", "{", "return", "new", "NodeStepDataResultImpl", "(", "result", ",", "result", ".", "getException", "(", ")", ",", "result", ".", "getFailureReason", "(", ")", ",", "result", ".", "getFailureMessage", "(", ")", ",", "result", ".", "getFailureData", "(", ")", ",", "result", ".", "getNode", "(", ")", ",", "dataContext", ")", ";", "}" ]
Add a data context to a source result @param result @param dataContext @return
[ "Add", "a", "data", "context", "to", "a", "source", "result" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/steps/node/NodeStepDataResultImpl.java#L43-L53
15,973
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/ExecArgList.java
ExecArgList.buildCommandForNode
@Deprecated public ArrayList<String> buildCommandForNode(Map<String, Map<String, String>> dataContext, String osFamily) { return buildCommandForNode(this, dataContext, osFamily); }
java
@Deprecated public ArrayList<String> buildCommandForNode(Map<String, Map<String, String>> dataContext, String osFamily) { return buildCommandForNode(this, dataContext, osFamily); }
[ "@", "Deprecated", "public", "ArrayList", "<", "String", ">", "buildCommandForNode", "(", "Map", "<", "String", ",", "Map", "<", "String", ",", "String", ">", ">", "dataContext", ",", "String", "osFamily", ")", "{", "return", "buildCommandForNode", "(", "this", ",", "dataContext", ",", "osFamily", ")", ";", "}" ]
Generate the quoted and expanded argument list, by expanding property values given the data context, and quoting for the given OS @param dataContext property value data context @param osFamily OS family to determine quoting @return list of strings
[ "Generate", "the", "quoted", "and", "expanded", "argument", "list", "by", "expanding", "property", "values", "given", "the", "data", "context", "and", "quoting", "for", "the", "given", "OS" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/ExecArgList.java#L140-L143
15,974
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/ExecArgList.java
ExecArgList.visitWith
public void visitWith(ExecArg.Visitor visitor) { for (ExecArg arg : getList()) { arg.accept(visitor); } }
java
public void visitWith(ExecArg.Visitor visitor) { for (ExecArg arg : getList()) { arg.accept(visitor); } }
[ "public", "void", "visitWith", "(", "ExecArg", ".", "Visitor", "visitor", ")", "{", "for", "(", "ExecArg", "arg", ":", "getList", "(", ")", ")", "{", "arg", ".", "accept", "(", "visitor", ")", ";", "}", "}" ]
Visit with a visitor @param visitor visitor
[ "Visit", "with", "a", "visitor" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/ExecArgList.java#L256-L260
15,975
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/ZipUtil.java
ZipUtil.extractZip
public static void extractZip(final String path, final File dest) throws IOException { extractZip(path, dest, null); }
java
public static void extractZip(final String path, final File dest) throws IOException { extractZip(path, dest, null); }
[ "public", "static", "void", "extractZip", "(", "final", "String", "path", ",", "final", "File", "dest", ")", "throws", "IOException", "{", "extractZip", "(", "path", ",", "dest", ",", "null", ")", ";", "}" ]
Extracts all contents of the file to the destination directory @param path zip file path @param dest destination directory @throws IOException on io error
[ "Extracts", "all", "contents", "of", "the", "file", "to", "the", "destination", "directory" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/ZipUtil.java#L45-L47
15,976
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/utils/ZipUtil.java
ZipUtil.extractZipFile
public static void extractZipFile(final String path, final File dest, final String fileName) throws IOException { FilenameFilter filter = null; if (null != fileName) { filter = new FilenameFilter() { public boolean accept(final File file, final String name) { return fileName.equals(name) || fileName.startsWith(name); } }; } extractZip(path, dest, filter, null, null); }
java
public static void extractZipFile(final String path, final File dest, final String fileName) throws IOException { FilenameFilter filter = null; if (null != fileName) { filter = new FilenameFilter() { public boolean accept(final File file, final String name) { return fileName.equals(name) || fileName.startsWith(name); } }; } extractZip(path, dest, filter, null, null); }
[ "public", "static", "void", "extractZipFile", "(", "final", "String", "path", ",", "final", "File", "dest", ",", "final", "String", "fileName", ")", "throws", "IOException", "{", "FilenameFilter", "filter", "=", "null", ";", "if", "(", "null", "!=", "fileName", ")", "{", "filter", "=", "new", "FilenameFilter", "(", ")", "{", "public", "boolean", "accept", "(", "final", "File", "file", ",", "final", "String", "name", ")", "{", "return", "fileName", ".", "equals", "(", "name", ")", "||", "fileName", ".", "startsWith", "(", "name", ")", ";", "}", "}", ";", "}", "extractZip", "(", "path", ",", "dest", ",", "filter", ",", "null", ",", "null", ")", ";", "}" ]
Extracts a single entry from the zip @param path zip file path @param dest destination directory @param fileName specific filepath to extract @throws IOException on io error
[ "Extracts", "a", "single", "entry", "from", "the", "zip" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/utils/ZipUtil.java#L70-L80
15,977
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/FrameworkProjectMgr.java
FrameworkProjectMgr.createFrameworkProjectStrict
@Override public IRundeckProject createFrameworkProjectStrict(final String projectName, final Properties properties) { return createFrameworkProjectInt(projectName,properties,true); }
java
@Override public IRundeckProject createFrameworkProjectStrict(final String projectName, final Properties properties) { return createFrameworkProjectInt(projectName,properties,true); }
[ "@", "Override", "public", "IRundeckProject", "createFrameworkProjectStrict", "(", "final", "String", "projectName", ",", "final", "Properties", "properties", ")", "{", "return", "createFrameworkProjectInt", "(", "projectName", ",", "properties", ",", "true", ")", ";", "}" ]
Create a new project if it doesn't, otherwise throw exception @param projectName name of project @param properties config properties @return new project @throws IllegalArgumentException if the project already exists
[ "Create", "a", "new", "project", "if", "it", "doesn", "t", "otherwise", "throw", "exception" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/FrameworkProjectMgr.java#L107-L111
15,978
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/FrameworkProjectMgr.java
FrameworkProjectMgr.removeFrameworkProject
@Override public void removeFrameworkProject(final String projectName){ synchronized (projectCache) { removeSubDir(projectName); projectCache.remove(projectName); } }
java
@Override public void removeFrameworkProject(final String projectName){ synchronized (projectCache) { removeSubDir(projectName); projectCache.remove(projectName); } }
[ "@", "Override", "public", "void", "removeFrameworkProject", "(", "final", "String", "projectName", ")", "{", "synchronized", "(", "projectCache", ")", "{", "removeSubDir", "(", "projectName", ")", ";", "projectCache", ".", "remove", "(", "projectName", ")", ";", "}", "}" ]
Remove a project definition @param projectName name of the project
[ "Remove", "a", "project", "definition" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/FrameworkProjectMgr.java#L158-L164
15,979
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.load
@SuppressWarnings("unchecked") public synchronized <T> T load(final PluggableService<T> service, final String providerName) throws ProviderLoaderException { final ProviderIdent ident = new ProviderIdent(service.getName(), providerName); debug("loadInstance for " + ident + ": " + pluginJar); if (null == pluginProviderDefs.get(ident)) { final String[] strings = getClassnames(); for (final String classname : strings) { final Class<?> cls; try { cls = loadClass(classname); if (matchesProviderDeclaration(ident, cls)) { pluginProviderDefs.put(ident, cls); } } catch (PluginException e) { log.error("Failed to load class from " + pluginJar + ": classname: " + classname + ": " + e.getMessage()); } } } final Class<T> cls = pluginProviderDefs.get(ident); if (null != cls) { try { return createProviderForClass(service, cls); } catch (PluginException e) { throw new ProviderLoaderException(e, service.getName(), providerName); } } return null; }
java
@SuppressWarnings("unchecked") public synchronized <T> T load(final PluggableService<T> service, final String providerName) throws ProviderLoaderException { final ProviderIdent ident = new ProviderIdent(service.getName(), providerName); debug("loadInstance for " + ident + ": " + pluginJar); if (null == pluginProviderDefs.get(ident)) { final String[] strings = getClassnames(); for (final String classname : strings) { final Class<?> cls; try { cls = loadClass(classname); if (matchesProviderDeclaration(ident, cls)) { pluginProviderDefs.put(ident, cls); } } catch (PluginException e) { log.error("Failed to load class from " + pluginJar + ": classname: " + classname + ": " + e.getMessage()); } } } final Class<T> cls = pluginProviderDefs.get(ident); if (null != cls) { try { return createProviderForClass(service, cls); } catch (PluginException e) { throw new ProviderLoaderException(e, service.getName(), providerName); } } return null; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "synchronized", "<", "T", ">", "T", "load", "(", "final", "PluggableService", "<", "T", ">", "service", ",", "final", "String", "providerName", ")", "throws", "ProviderLoaderException", "{", "final", "ProviderIdent", "ident", "=", "new", "ProviderIdent", "(", "service", ".", "getName", "(", ")", ",", "providerName", ")", ";", "debug", "(", "\"loadInstance for \"", "+", "ident", "+", "\": \"", "+", "pluginJar", ")", ";", "if", "(", "null", "==", "pluginProviderDefs", ".", "get", "(", "ident", ")", ")", "{", "final", "String", "[", "]", "strings", "=", "getClassnames", "(", ")", ";", "for", "(", "final", "String", "classname", ":", "strings", ")", "{", "final", "Class", "<", "?", ">", "cls", ";", "try", "{", "cls", "=", "loadClass", "(", "classname", ")", ";", "if", "(", "matchesProviderDeclaration", "(", "ident", ",", "cls", ")", ")", "{", "pluginProviderDefs", ".", "put", "(", "ident", ",", "cls", ")", ";", "}", "}", "catch", "(", "PluginException", "e", ")", "{", "log", ".", "error", "(", "\"Failed to load class from \"", "+", "pluginJar", "+", "\": classname: \"", "+", "classname", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}", "}", "final", "Class", "<", "T", ">", "cls", "=", "pluginProviderDefs", ".", "get", "(", "ident", ")", ";", "if", "(", "null", "!=", "cls", ")", "{", "try", "{", "return", "createProviderForClass", "(", "service", ",", "cls", ")", ";", "}", "catch", "(", "PluginException", "e", ")", "{", "throw", "new", "ProviderLoaderException", "(", "e", ",", "service", ".", "getName", "(", ")", ",", "providerName", ")", ";", "}", "}", "return", "null", ";", "}" ]
Load provider instance for the service
[ "Load", "provider", "instance", "for", "the", "service" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L169-L199
15,980
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.getClassnames
public String[] getClassnames() { final Attributes attributes = getMainAttributes(); if (null == attributes) { return null; } final String value = attributes.getValue(RUNDECK_PLUGIN_CLASSNAMES); if (null == value) { return null; } return value.split(","); }
java
public String[] getClassnames() { final Attributes attributes = getMainAttributes(); if (null == attributes) { return null; } final String value = attributes.getValue(RUNDECK_PLUGIN_CLASSNAMES); if (null == value) { return null; } return value.split(","); }
[ "public", "String", "[", "]", "getClassnames", "(", ")", "{", "final", "Attributes", "attributes", "=", "getMainAttributes", "(", ")", ";", "if", "(", "null", "==", "attributes", ")", "{", "return", "null", ";", "}", "final", "String", "value", "=", "attributes", ".", "getValue", "(", "RUNDECK_PLUGIN_CLASSNAMES", ")", ";", "if", "(", "null", "==", "value", ")", "{", "return", "null", ";", "}", "return", "value", ".", "split", "(", "\",\"", ")", ";", "}" ]
Get the declared list of provider classnames for the file
[ "Get", "the", "declared", "list", "of", "provider", "classnames", "for", "the", "file" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L223-L233
15,981
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.getMainAttributes
private Attributes getMainAttributes() { if (null == mainAttributes) { mainAttributes = getJarMainAttributes(pluginJar); String pluginName = mainAttributes.getValue(RUNDECK_PLUGIN_NAME); if(pluginName == null) { //Fallback to something that will rarely change //This is not ideal, but old plugins do not always have a name //set in the attributes pluginName = mainAttributes.getValue(RUNDECK_PLUGIN_CLASSNAMES); } pluginId = PluginUtils.generateShaIdFromName(pluginName); } return mainAttributes; }
java
private Attributes getMainAttributes() { if (null == mainAttributes) { mainAttributes = getJarMainAttributes(pluginJar); String pluginName = mainAttributes.getValue(RUNDECK_PLUGIN_NAME); if(pluginName == null) { //Fallback to something that will rarely change //This is not ideal, but old plugins do not always have a name //set in the attributes pluginName = mainAttributes.getValue(RUNDECK_PLUGIN_CLASSNAMES); } pluginId = PluginUtils.generateShaIdFromName(pluginName); } return mainAttributes; }
[ "private", "Attributes", "getMainAttributes", "(", ")", "{", "if", "(", "null", "==", "mainAttributes", ")", "{", "mainAttributes", "=", "getJarMainAttributes", "(", "pluginJar", ")", ";", "String", "pluginName", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_NAME", ")", ";", "if", "(", "pluginName", "==", "null", ")", "{", "//Fallback to something that will rarely change", "//This is not ideal, but old plugins do not always have a name", "//set in the attributes", "pluginName", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_CLASSNAMES", ")", ";", "}", "pluginId", "=", "PluginUtils", ".", "generateShaIdFromName", "(", "pluginName", ")", ";", "}", "return", "mainAttributes", ";", "}" ]
return the main attributes from the jar manifest
[ "return", "the", "main", "attributes", "from", "the", "jar", "manifest" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L272-L285
15,982
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.createProviderForClass
static <T,X extends T> T createProviderForClass(final PluggableService<T> service, final Class<X> cls) throws PluginException, ProviderCreationException { debug("Try loading provider " + cls.getName()); if(!(service instanceof JavaClassProviderLoadable)){ return null; } JavaClassProviderLoadable<T> loadable = (JavaClassProviderLoadable<T>) service; final Plugin annotation = getPluginMetadata(cls); final String pluginname = annotation.name(); if (!loadable.isValidProviderClass(cls)) { throw new PluginException("Class " + cls.getName() + " was not a valid plugin class for service: " + service.getName() + ". Expected class " + cls.getName() + ", with a public constructor with no parameter"); } debug("Succeeded loading plugin " + cls.getName() + " for service: " + service.getName()); return loadable.createProviderInstance(cls, pluginname); }
java
static <T,X extends T> T createProviderForClass(final PluggableService<T> service, final Class<X> cls) throws PluginException, ProviderCreationException { debug("Try loading provider " + cls.getName()); if(!(service instanceof JavaClassProviderLoadable)){ return null; } JavaClassProviderLoadable<T> loadable = (JavaClassProviderLoadable<T>) service; final Plugin annotation = getPluginMetadata(cls); final String pluginname = annotation.name(); if (!loadable.isValidProviderClass(cls)) { throw new PluginException("Class " + cls.getName() + " was not a valid plugin class for service: " + service.getName() + ". Expected class " + cls.getName() + ", with a public constructor with no parameter"); } debug("Succeeded loading plugin " + cls.getName() + " for service: " + service.getName()); return loadable.createProviderInstance(cls, pluginname); }
[ "static", "<", "T", ",", "X", "extends", "T", ">", "T", "createProviderForClass", "(", "final", "PluggableService", "<", "T", ">", "service", ",", "final", "Class", "<", "X", ">", "cls", ")", "throws", "PluginException", ",", "ProviderCreationException", "{", "debug", "(", "\"Try loading provider \"", "+", "cls", ".", "getName", "(", ")", ")", ";", "if", "(", "!", "(", "service", "instanceof", "JavaClassProviderLoadable", ")", ")", "{", "return", "null", ";", "}", "JavaClassProviderLoadable", "<", "T", ">", "loadable", "=", "(", "JavaClassProviderLoadable", "<", "T", ">", ")", "service", ";", "final", "Plugin", "annotation", "=", "getPluginMetadata", "(", "cls", ")", ";", "final", "String", "pluginname", "=", "annotation", ".", "name", "(", ")", ";", "if", "(", "!", "loadable", ".", "isValidProviderClass", "(", "cls", ")", ")", "{", "throw", "new", "PluginException", "(", "\"Class \"", "+", "cls", ".", "getName", "(", ")", "+", "\" was not a valid plugin class for service: \"", "+", "service", ".", "getName", "(", ")", "+", "\". Expected class \"", "+", "cls", ".", "getName", "(", ")", "+", "\", with a public constructor with no parameter\"", ")", ";", "}", "debug", "(", "\"Succeeded loading plugin \"", "+", "cls", ".", "getName", "(", ")", "+", "\" for service: \"", "+", "service", ".", "getName", "(", ")", ")", ";", "return", "loadable", ".", "createProviderInstance", "(", "cls", ",", "pluginname", ")", ";", "}" ]
Attempt to create an instance of thea provider for the given service @param cls class @return created instance
[ "Attempt", "to", "create", "an", "instance", "of", "thea", "provider", "for", "the", "given", "service" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L308-L325
15,983
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.getPluginMetadata
static Plugin getPluginMetadata(final Class<?> cls) throws PluginException { // try to get plugin provider name final String pluginname; if (!cls.isAnnotationPresent(Plugin.class)) { throw new PluginException("No Plugin annotation was found for the class: " + cls.getName()); } final Plugin annotation = (Plugin) cls.getAnnotation(Plugin.class); pluginname = annotation.name(); if (null == pluginname || "".equals(pluginname)) { throw new PluginException("Plugin annotation 'name' cannot be empty for the class: " + cls.getName()); } // get service name from annotation final String servicename = annotation.service(); if (null == servicename || "".equals(servicename)) { throw new PluginException("Plugin annotation 'service' cannot be empty for the class: " + cls.getName()); } return annotation; }
java
static Plugin getPluginMetadata(final Class<?> cls) throws PluginException { // try to get plugin provider name final String pluginname; if (!cls.isAnnotationPresent(Plugin.class)) { throw new PluginException("No Plugin annotation was found for the class: " + cls.getName()); } final Plugin annotation = (Plugin) cls.getAnnotation(Plugin.class); pluginname = annotation.name(); if (null == pluginname || "".equals(pluginname)) { throw new PluginException("Plugin annotation 'name' cannot be empty for the class: " + cls.getName()); } // get service name from annotation final String servicename = annotation.service(); if (null == servicename || "".equals(servicename)) { throw new PluginException("Plugin annotation 'service' cannot be empty for the class: " + cls.getName()); } return annotation; }
[ "static", "Plugin", "getPluginMetadata", "(", "final", "Class", "<", "?", ">", "cls", ")", "throws", "PluginException", "{", "// try to get plugin provider name", "final", "String", "pluginname", ";", "if", "(", "!", "cls", ".", "isAnnotationPresent", "(", "Plugin", ".", "class", ")", ")", "{", "throw", "new", "PluginException", "(", "\"No Plugin annotation was found for the class: \"", "+", "cls", ".", "getName", "(", ")", ")", ";", "}", "final", "Plugin", "annotation", "=", "(", "Plugin", ")", "cls", ".", "getAnnotation", "(", "Plugin", ".", "class", ")", ";", "pluginname", "=", "annotation", ".", "name", "(", ")", ";", "if", "(", "null", "==", "pluginname", "||", "\"\"", ".", "equals", "(", "pluginname", ")", ")", "{", "throw", "new", "PluginException", "(", "\"Plugin annotation 'name' cannot be empty for the class: \"", "+", "cls", ".", "getName", "(", ")", ")", ";", "}", "// get service name from annotation", "final", "String", "servicename", "=", "annotation", ".", "service", "(", ")", ";", "if", "(", "null", "==", "servicename", "||", "\"\"", ".", "equals", "(", "servicename", ")", ")", "{", "throw", "new", "PluginException", "(", "\"Plugin annotation 'service' cannot be empty for the class: \"", "+", "cls", ".", "getName", "(", ")", ")", ";", "}", "return", "annotation", ";", "}" ]
Get the Plugin annotation for the class
[ "Get", "the", "Plugin", "annotation", "for", "the", "class" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L336-L354
15,984
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.createCachedJar
protected File createCachedJar(final File dir, final String jarName) throws PluginException { File cachedJar; try { cachedJar = new File(dir, jarName); cachedJar.deleteOnExit(); FileUtils.fileCopy(pluginJar, cachedJar, true); } catch (IOException e) { throw new PluginException(e); } return cachedJar; }
java
protected File createCachedJar(final File dir, final String jarName) throws PluginException { File cachedJar; try { cachedJar = new File(dir, jarName); cachedJar.deleteOnExit(); FileUtils.fileCopy(pluginJar, cachedJar, true); } catch (IOException e) { throw new PluginException(e); } return cachedJar; }
[ "protected", "File", "createCachedJar", "(", "final", "File", "dir", ",", "final", "String", "jarName", ")", "throws", "PluginException", "{", "File", "cachedJar", ";", "try", "{", "cachedJar", "=", "new", "File", "(", "dir", ",", "jarName", ")", ";", "cachedJar", ".", "deleteOnExit", "(", ")", ";", "FileUtils", ".", "fileCopy", "(", "pluginJar", ",", "cachedJar", ",", "true", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "PluginException", "(", "e", ")", ";", "}", "return", "cachedJar", ";", "}" ]
Creates a single cached version of the pluginJar located within pluginJarCacheDirectory deleting all existing versions of pluginJar @param jarName
[ "Creates", "a", "single", "cached", "version", "of", "the", "pluginJar", "located", "within", "pluginJarCacheDirectory", "deleting", "all", "existing", "versions", "of", "pluginJar" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L405-L415
15,985
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.loadClass
private Class<?> loadClass(final String classname) throws PluginException { if (null == classname) { throw new IllegalArgumentException("A null java class name was specified."); } if (null != classCache.get(classname)) { return classCache.get(classname); } CachedJar cachedJar1 = getCachedJar(); debug("loadClass! " + classname + ": " + cachedJar1.getCachedJar()); final Class<?> cls; final URLClassLoader urlClassLoader = cachedJar1.getClassLoader(); try { cls = Class.forName(classname, true, urlClassLoader); classCache.put(classname, cls); } catch (ClassNotFoundException e) { throw new PluginException("Class not found: " + classname, e); } catch (Throwable t) { throw new PluginException("Error loading class: " + classname, t); } return cls; }
java
private Class<?> loadClass(final String classname) throws PluginException { if (null == classname) { throw new IllegalArgumentException("A null java class name was specified."); } if (null != classCache.get(classname)) { return classCache.get(classname); } CachedJar cachedJar1 = getCachedJar(); debug("loadClass! " + classname + ": " + cachedJar1.getCachedJar()); final Class<?> cls; final URLClassLoader urlClassLoader = cachedJar1.getClassLoader(); try { cls = Class.forName(classname, true, urlClassLoader); classCache.put(classname, cls); } catch (ClassNotFoundException e) { throw new PluginException("Class not found: " + classname, e); } catch (Throwable t) { throw new PluginException("Error loading class: " + classname, t); } return cls; }
[ "private", "Class", "<", "?", ">", "loadClass", "(", "final", "String", "classname", ")", "throws", "PluginException", "{", "if", "(", "null", "==", "classname", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"A null java class name was specified.\"", ")", ";", "}", "if", "(", "null", "!=", "classCache", ".", "get", "(", "classname", ")", ")", "{", "return", "classCache", ".", "get", "(", "classname", ")", ";", "}", "CachedJar", "cachedJar1", "=", "getCachedJar", "(", ")", ";", "debug", "(", "\"loadClass! \"", "+", "classname", "+", "\": \"", "+", "cachedJar1", ".", "getCachedJar", "(", ")", ")", ";", "final", "Class", "<", "?", ">", "cls", ";", "final", "URLClassLoader", "urlClassLoader", "=", "cachedJar1", ".", "getClassLoader", "(", ")", ";", "try", "{", "cls", "=", "Class", ".", "forName", "(", "classname", ",", "true", ",", "urlClassLoader", ")", ";", "classCache", ".", "put", "(", "classname", ",", "cls", ")", ";", "}", "catch", "(", "ClassNotFoundException", "e", ")", "{", "throw", "new", "PluginException", "(", "\"Class not found: \"", "+", "classname", ",", "e", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "throw", "new", "PluginException", "(", "\"Error loading class: \"", "+", "classname", ",", "t", ")", ";", "}", "return", "cls", ";", "}" ]
Load a class from the jar file by name
[ "Load", "a", "class", "from", "the", "jar", "file", "by", "name" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L420-L441
15,986
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.extractDependentLibs
protected Collection<File> extractDependentLibs(final File cachedir) throws IOException { final Attributes attributes = getMainAttributes(); if (null == attributes) { debug("no manifest attributes"); return null; } final ArrayList<File> files = new ArrayList<File>(); final String libs = attributes.getValue(RUNDECK_PLUGIN_LIBS); if (null != libs) { debug("jar libs listed: " + libs + " for file: " + pluginJar); if (!cachedir.isDirectory()) { if (!cachedir.mkdirs()) { debug("Failed to create cachedJar dir for dependent libs: " + cachedir); } } final String[] libsarr = libs.split(" "); extractJarContents(libsarr, cachedir); for (final String s : libsarr) { File libFile = new File(cachedir, s); libFile.deleteOnExit(); files.add(libFile); } } else { debug("no jar libs listed in manifest: " + pluginJar); } return files; }
java
protected Collection<File> extractDependentLibs(final File cachedir) throws IOException { final Attributes attributes = getMainAttributes(); if (null == attributes) { debug("no manifest attributes"); return null; } final ArrayList<File> files = new ArrayList<File>(); final String libs = attributes.getValue(RUNDECK_PLUGIN_LIBS); if (null != libs) { debug("jar libs listed: " + libs + " for file: " + pluginJar); if (!cachedir.isDirectory()) { if (!cachedir.mkdirs()) { debug("Failed to create cachedJar dir for dependent libs: " + cachedir); } } final String[] libsarr = libs.split(" "); extractJarContents(libsarr, cachedir); for (final String s : libsarr) { File libFile = new File(cachedir, s); libFile.deleteOnExit(); files.add(libFile); } } else { debug("no jar libs listed in manifest: " + pluginJar); } return files; }
[ "protected", "Collection", "<", "File", ">", "extractDependentLibs", "(", "final", "File", "cachedir", ")", "throws", "IOException", "{", "final", "Attributes", "attributes", "=", "getMainAttributes", "(", ")", ";", "if", "(", "null", "==", "attributes", ")", "{", "debug", "(", "\"no manifest attributes\"", ")", ";", "return", "null", ";", "}", "final", "ArrayList", "<", "File", ">", "files", "=", "new", "ArrayList", "<", "File", ">", "(", ")", ";", "final", "String", "libs", "=", "attributes", ".", "getValue", "(", "RUNDECK_PLUGIN_LIBS", ")", ";", "if", "(", "null", "!=", "libs", ")", "{", "debug", "(", "\"jar libs listed: \"", "+", "libs", "+", "\" for file: \"", "+", "pluginJar", ")", ";", "if", "(", "!", "cachedir", ".", "isDirectory", "(", ")", ")", "{", "if", "(", "!", "cachedir", ".", "mkdirs", "(", ")", ")", "{", "debug", "(", "\"Failed to create cachedJar dir for dependent libs: \"", "+", "cachedir", ")", ";", "}", "}", "final", "String", "[", "]", "libsarr", "=", "libs", ".", "split", "(", "\" \"", ")", ";", "extractJarContents", "(", "libsarr", ",", "cachedir", ")", ";", "for", "(", "final", "String", "s", ":", "libsarr", ")", "{", "File", "libFile", "=", "new", "File", "(", "cachedir", ",", "s", ")", ";", "libFile", ".", "deleteOnExit", "(", ")", ";", "files", ".", "add", "(", "libFile", ")", ";", "}", "}", "else", "{", "debug", "(", "\"no jar libs listed in manifest: \"", "+", "pluginJar", ")", ";", "}", "return", "files", ";", "}" ]
Extract the dependent libs and return the extracted jar files @return the collection of extracted files
[ "Extract", "the", "dependent", "libs", "and", "return", "the", "extracted", "jar", "files" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L492-L519
15,987
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.isLoaderFor
public synchronized boolean isLoaderFor(final ProviderIdent ident) { final String[] strings = getClassnames(); for (final String classname : strings) { try { if (matchesProviderDeclaration(ident, loadClass(classname))) { return true; } } catch (PluginException e) { e.printStackTrace(); } } return false; }
java
public synchronized boolean isLoaderFor(final ProviderIdent ident) { final String[] strings = getClassnames(); for (final String classname : strings) { try { if (matchesProviderDeclaration(ident, loadClass(classname))) { return true; } } catch (PluginException e) { e.printStackTrace(); } } return false; }
[ "public", "synchronized", "boolean", "isLoaderFor", "(", "final", "ProviderIdent", "ident", ")", "{", "final", "String", "[", "]", "strings", "=", "getClassnames", "(", ")", ";", "for", "(", "final", "String", "classname", ":", "strings", ")", "{", "try", "{", "if", "(", "matchesProviderDeclaration", "(", "ident", ",", "loadClass", "(", "classname", ")", ")", ")", "{", "return", "true", ";", "}", "}", "catch", "(", "PluginException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "return", "false", ";", "}" ]
Return true if the file has a class that provides the ident.
[ "Return", "true", "if", "the", "file", "has", "a", "class", "that", "provides", "the", "ident", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L573-L585
15,988
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.close
@Override public void close() throws IOException { debug(String.format("close jar provider loader for: %s", pluginJar)); synchronized (this) { closed = true; } if (null != cachedJar) { cachedJar.close(); classCache.clear(); cachedJar = null; } }
java
@Override public void close() throws IOException { debug(String.format("close jar provider loader for: %s", pluginJar)); synchronized (this) { closed = true; } if (null != cachedJar) { cachedJar.close(); classCache.clear(); cachedJar = null; } }
[ "@", "Override", "public", "void", "close", "(", ")", "throws", "IOException", "{", "debug", "(", "String", ".", "format", "(", "\"close jar provider loader for: %s\"", ",", "pluginJar", ")", ")", ";", "synchronized", "(", "this", ")", "{", "closed", "=", "true", ";", "}", "if", "(", "null", "!=", "cachedJar", ")", "{", "cachedJar", ".", "close", "(", ")", ";", "classCache", ".", "clear", "(", ")", ";", "cachedJar", "=", "null", ";", "}", "}" ]
Close class loaders and delete cached files @throws IOException
[ "Close", "class", "loaders", "and", "delete", "cached", "files" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L624-L635
15,989
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.expire
public void expire() { synchronized (this) { expired = true; } int i = loadCount.get(); debug(String.format("expire jar provider loader for: %s (loadCount: %d)", pluginJar, i)); if (i <= 0) { try { close(); } catch (IOException e) { } } }
java
public void expire() { synchronized (this) { expired = true; } int i = loadCount.get(); debug(String.format("expire jar provider loader for: %s (loadCount: %d)", pluginJar, i)); if (i <= 0) { try { close(); } catch (IOException e) { } } }
[ "public", "void", "expire", "(", ")", "{", "synchronized", "(", "this", ")", "{", "expired", "=", "true", ";", "}", "int", "i", "=", "loadCount", ".", "get", "(", ")", ";", "debug", "(", "String", ".", "format", "(", "\"expire jar provider loader for: %s (loadCount: %d)\"", ",", "pluginJar", ",", "i", ")", ")", ";", "if", "(", "i", "<=", "0", ")", "{", "try", "{", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "}", "}", "}" ]
Expire the loader cache item
[ "Expire", "the", "loader", "cache", "item" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L652-L665
15,990
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.isValidJarPlugin
public static boolean isValidJarPlugin(final File file) { try { try (final JarInputStream jarInputStream = new JarInputStream(new FileInputStream(file))) { final Manifest manifest = jarInputStream.getManifest(); if (null == manifest) { return false; } final Attributes mainAttributes = manifest.getMainAttributes(); validateJarManifest(mainAttributes); } return true; } catch (IOException | InvalidManifestException e) { log.error(file.getAbsolutePath() + ": " + e.getMessage()); return false; } }
java
public static boolean isValidJarPlugin(final File file) { try { try (final JarInputStream jarInputStream = new JarInputStream(new FileInputStream(file))) { final Manifest manifest = jarInputStream.getManifest(); if (null == manifest) { return false; } final Attributes mainAttributes = manifest.getMainAttributes(); validateJarManifest(mainAttributes); } return true; } catch (IOException | InvalidManifestException e) { log.error(file.getAbsolutePath() + ": " + e.getMessage()); return false; } }
[ "public", "static", "boolean", "isValidJarPlugin", "(", "final", "File", "file", ")", "{", "try", "{", "try", "(", "final", "JarInputStream", "jarInputStream", "=", "new", "JarInputStream", "(", "new", "FileInputStream", "(", "file", ")", ")", ")", "{", "final", "Manifest", "manifest", "=", "jarInputStream", ".", "getManifest", "(", ")", ";", "if", "(", "null", "==", "manifest", ")", "{", "return", "false", ";", "}", "final", "Attributes", "mainAttributes", "=", "manifest", ".", "getMainAttributes", "(", ")", ";", "validateJarManifest", "(", "mainAttributes", ")", ";", "}", "return", "true", ";", "}", "catch", "(", "IOException", "|", "InvalidManifestException", "e", ")", "{", "log", ".", "error", "(", "file", ".", "getAbsolutePath", "(", ")", "+", "\": \"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "}" ]
Return true if the file is a valid jar plugin file
[ "Return", "true", "if", "the", "file", "is", "a", "valid", "jar", "plugin", "file" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L707-L722
15,991
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.validateJarManifest
static void validateJarManifest(final Attributes mainAttributes) throws InvalidManifestException { final String value1 = mainAttributes.getValue(RUNDECK_PLUGIN_ARCHIVE); final String plugvers = mainAttributes.getValue(RUNDECK_PLUGIN_VERSION); final String plugclassnames = mainAttributes.getValue(RUNDECK_PLUGIN_CLASSNAMES); if (null == value1) { throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_ARCHIVE); } else if (!"true".equals(value1)) { throw new InvalidManifestException(RUNDECK_PLUGIN_ARCHIVE + " was not 'true': " + value1); } if (null == plugvers) { throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_VERSION); } final VersionCompare pluginVersion = VersionCompare.forString(plugvers); if (!pluginVersion.atLeast(LOWEST_JAR_PLUGIN_VERSION)) { throw new InvalidManifestException("Unsupported plugin version: " + RUNDECK_PLUGIN_VERSION + ": " + plugvers); } if (null == plugclassnames) { throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_CLASSNAMES); } if(plugvers.equals(JAR_PLUGIN_VERSION_2_0)) { String pluginName = mainAttributes.getValue(RUNDECK_PLUGIN_NAME); if(pluginName == null) throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_NAME); String rundeckCompat = mainAttributes.getValue(RUNDECK_PLUGIN_RUNDECK_COMPAT_VER); if(rundeckCompat == null) throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_RUNDECK_COMPAT_VER); ArrayList<String> errors = new ArrayList<>(); PluginValidation.State state = PluginMetadataValidator.validateRundeckCompatibility(errors, rundeckCompat); if (!state.isValid()) { throw new InvalidManifestException(String.join("\n", errors)); } } }
java
static void validateJarManifest(final Attributes mainAttributes) throws InvalidManifestException { final String value1 = mainAttributes.getValue(RUNDECK_PLUGIN_ARCHIVE); final String plugvers = mainAttributes.getValue(RUNDECK_PLUGIN_VERSION); final String plugclassnames = mainAttributes.getValue(RUNDECK_PLUGIN_CLASSNAMES); if (null == value1) { throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_ARCHIVE); } else if (!"true".equals(value1)) { throw new InvalidManifestException(RUNDECK_PLUGIN_ARCHIVE + " was not 'true': " + value1); } if (null == plugvers) { throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_VERSION); } final VersionCompare pluginVersion = VersionCompare.forString(plugvers); if (!pluginVersion.atLeast(LOWEST_JAR_PLUGIN_VERSION)) { throw new InvalidManifestException("Unsupported plugin version: " + RUNDECK_PLUGIN_VERSION + ": " + plugvers); } if (null == plugclassnames) { throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_CLASSNAMES); } if(plugvers.equals(JAR_PLUGIN_VERSION_2_0)) { String pluginName = mainAttributes.getValue(RUNDECK_PLUGIN_NAME); if(pluginName == null) throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_NAME); String rundeckCompat = mainAttributes.getValue(RUNDECK_PLUGIN_RUNDECK_COMPAT_VER); if(rundeckCompat == null) throw new InvalidManifestException("Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_RUNDECK_COMPAT_VER); ArrayList<String> errors = new ArrayList<>(); PluginValidation.State state = PluginMetadataValidator.validateRundeckCompatibility(errors, rundeckCompat); if (!state.isValid()) { throw new InvalidManifestException(String.join("\n", errors)); } } }
[ "static", "void", "validateJarManifest", "(", "final", "Attributes", "mainAttributes", ")", "throws", "InvalidManifestException", "{", "final", "String", "value1", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_ARCHIVE", ")", ";", "final", "String", "plugvers", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_VERSION", ")", ";", "final", "String", "plugclassnames", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_CLASSNAMES", ")", ";", "if", "(", "null", "==", "value1", ")", "{", "throw", "new", "InvalidManifestException", "(", "\"Jar plugin manifest attribute missing: \"", "+", "RUNDECK_PLUGIN_ARCHIVE", ")", ";", "}", "else", "if", "(", "!", "\"true\"", ".", "equals", "(", "value1", ")", ")", "{", "throw", "new", "InvalidManifestException", "(", "RUNDECK_PLUGIN_ARCHIVE", "+", "\" was not 'true': \"", "+", "value1", ")", ";", "}", "if", "(", "null", "==", "plugvers", ")", "{", "throw", "new", "InvalidManifestException", "(", "\"Jar plugin manifest attribute missing: \"", "+", "RUNDECK_PLUGIN_VERSION", ")", ";", "}", "final", "VersionCompare", "pluginVersion", "=", "VersionCompare", ".", "forString", "(", "plugvers", ")", ";", "if", "(", "!", "pluginVersion", ".", "atLeast", "(", "LOWEST_JAR_PLUGIN_VERSION", ")", ")", "{", "throw", "new", "InvalidManifestException", "(", "\"Unsupported plugin version: \"", "+", "RUNDECK_PLUGIN_VERSION", "+", "\": \"", "+", "plugvers", ")", ";", "}", "if", "(", "null", "==", "plugclassnames", ")", "{", "throw", "new", "InvalidManifestException", "(", "\"Jar plugin manifest attribute missing: \"", "+", "RUNDECK_PLUGIN_CLASSNAMES", ")", ";", "}", "if", "(", "plugvers", ".", "equals", "(", "JAR_PLUGIN_VERSION_2_0", ")", ")", "{", "String", "pluginName", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_NAME", ")", ";", "if", "(", "pluginName", "==", "null", ")", "throw", "new", "InvalidManifestException", "(", "\"Jar plugin manifest attribute missing: \"", "+", "RUNDECK_PLUGIN_NAME", ")", ";", "String", "rundeckCompat", "=", "mainAttributes", ".", "getValue", "(", "RUNDECK_PLUGIN_RUNDECK_COMPAT_VER", ")", ";", "if", "(", "rundeckCompat", "==", "null", ")", "throw", "new", "InvalidManifestException", "(", "\"Jar plugin manifest attribute missing: \"", "+", "RUNDECK_PLUGIN_RUNDECK_COMPAT_VER", ")", ";", "ArrayList", "<", "String", ">", "errors", "=", "new", "ArrayList", "<>", "(", ")", ";", "PluginValidation", ".", "State", "state", "=", "PluginMetadataValidator", ".", "validateRundeckCompatibility", "(", "errors", ",", "rundeckCompat", ")", ";", "if", "(", "!", "state", ".", "isValid", "(", ")", ")", "{", "throw", "new", "InvalidManifestException", "(", "String", ".", "join", "(", "\"\\n\"", ",", "errors", ")", ")", ";", "}", "}", "}" ]
Validate whether the jar file has a valid manifest, throw exception if invalid
[ "Validate", "whether", "the", "jar", "file", "has", "a", "valid", "manifest", "throw", "exception", "if", "invalid" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L727-L761
15,992
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java
JarPluginProviderLoader.getLoadLocalLibsFirstForFile
static boolean getLoadLocalLibsFirstForFile(final File file) { Attributes attributes = loadMainAttributes(file); if (null == attributes) { return false; } boolean loadFirstDefault=true; String loadFirst = attributes.getValue(RUNDECK_PLUGIN_LIBS_LOAD_FIRST); if(null!=loadFirst){ return Boolean.valueOf(loadFirst); } return loadFirstDefault; }
java
static boolean getLoadLocalLibsFirstForFile(final File file) { Attributes attributes = loadMainAttributes(file); if (null == attributes) { return false; } boolean loadFirstDefault=true; String loadFirst = attributes.getValue(RUNDECK_PLUGIN_LIBS_LOAD_FIRST); if(null!=loadFirst){ return Boolean.valueOf(loadFirst); } return loadFirstDefault; }
[ "static", "boolean", "getLoadLocalLibsFirstForFile", "(", "final", "File", "file", ")", "{", "Attributes", "attributes", "=", "loadMainAttributes", "(", "file", ")", ";", "if", "(", "null", "==", "attributes", ")", "{", "return", "false", ";", "}", "boolean", "loadFirstDefault", "=", "true", ";", "String", "loadFirst", "=", "attributes", ".", "getValue", "(", "RUNDECK_PLUGIN_LIBS_LOAD_FIRST", ")", ";", "if", "(", "null", "!=", "loadFirst", ")", "{", "return", "Boolean", ".", "valueOf", "(", "loadFirst", ")", ";", "}", "return", "loadFirstDefault", ";", "}" ]
Return true if the jar attributes declare it should load local dependency classes first. @param file plugin file @return true if plugin libs load first is set
[ "Return", "true", "if", "the", "jar", "attributes", "declare", "it", "should", "load", "local", "dependency", "classes", "first", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/plugins/JarPluginProviderLoader.java#L787-L798
15,993
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/ServiceSupport.java
ServiceSupport.initialize
public void initialize(Framework framework) { setFramework(framework); //plugin manager service inited first. any pluggable services will then be //able to try to load providers via the plugin manager NodeStepExecutionService.getInstanceForFramework(getFramework()); NodeExecutorService.getInstanceForFramework(getFramework()); FileCopierService.getInstanceForFramework(getFramework()); NodeDispatcherService.getInstanceForFramework(getFramework()); getExecutionService(); WorkflowExecutionService.getInstanceForFramework(getFramework()); StepExecutionService.getInstanceForFramework(getFramework()); ResourceModelSourceService.getInstanceForFramework(getFramework()); ResourceFormatParserService.getInstanceForFramework(getFramework()); ResourceFormatGeneratorService.getInstanceForFramework(getFramework()); }
java
public void initialize(Framework framework) { setFramework(framework); //plugin manager service inited first. any pluggable services will then be //able to try to load providers via the plugin manager NodeStepExecutionService.getInstanceForFramework(getFramework()); NodeExecutorService.getInstanceForFramework(getFramework()); FileCopierService.getInstanceForFramework(getFramework()); NodeDispatcherService.getInstanceForFramework(getFramework()); getExecutionService(); WorkflowExecutionService.getInstanceForFramework(getFramework()); StepExecutionService.getInstanceForFramework(getFramework()); ResourceModelSourceService.getInstanceForFramework(getFramework()); ResourceFormatParserService.getInstanceForFramework(getFramework()); ResourceFormatGeneratorService.getInstanceForFramework(getFramework()); }
[ "public", "void", "initialize", "(", "Framework", "framework", ")", "{", "setFramework", "(", "framework", ")", ";", "//plugin manager service inited first. any pluggable services will then be", "//able to try to load providers via the plugin manager", "NodeStepExecutionService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "NodeExecutorService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "FileCopierService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "NodeDispatcherService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "getExecutionService", "(", ")", ";", "WorkflowExecutionService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "StepExecutionService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "ResourceModelSourceService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "ResourceFormatParserService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "ResourceFormatGeneratorService", ".", "getInstanceForFramework", "(", "getFramework", "(", ")", ")", ";", "}" ]
Initialize children, the various resource management objects
[ "Initialize", "children", "the", "various", "resource", "management", "objects" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/ServiceSupport.java#L56-L70
15,994
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/common/ServiceSupport.java
ServiceSupport.setService
@Override public void setService(final String name, final FrameworkSupportService service){ synchronized (services){ if(null==services.get(name) && null!=service) { services.put(name, service); }else if(null==service) { services.remove(name); } } }
java
@Override public void setService(final String name, final FrameworkSupportService service){ synchronized (services){ if(null==services.get(name) && null!=service) { services.put(name, service); }else if(null==service) { services.remove(name); } } }
[ "@", "Override", "public", "void", "setService", "(", "final", "String", "name", ",", "final", "FrameworkSupportService", "service", ")", "{", "synchronized", "(", "services", ")", "{", "if", "(", "null", "==", "services", ".", "get", "(", "name", ")", "&&", "null", "!=", "service", ")", "{", "services", ".", "put", "(", "name", ",", "service", ")", ";", "}", "else", "if", "(", "null", "==", "service", ")", "{", "services", ".", "remove", "(", "name", ")", ";", "}", "}", "}" ]
Set a service by name @param name name @param service service
[ "Set", "a", "service", "by", "name" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/common/ServiceSupport.java#L85-L94
15,995
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java
BaseWorkflowExecutor.executeWFItem
protected StepExecutionResult executeWFItem( final StepExecutionContext executionContext, final Map<Integer, StepExecutionResult> failedMap, final int c, final StepExecutionItem cmd ) { boolean hasHandler= cmd instanceof HasFailureHandler; boolean hideError = false; if(hasHandler){ final HasFailureHandler handles = (HasFailureHandler) cmd; final StepExecutionItem handler = handles.getFailureHandler(); if(null != handler && handler instanceof HandlerExecutionItem){ hideError = ((HandlerExecutionItem)handler).isKeepgoingOnSuccess(); } } if(null != executionContext.getExecutionListener()) { executionContext.getExecutionListener().ignoreErrors(hideError); } if (null != executionContext.getExecutionListener()) { executionContext.getExecutionListener().log( Constants.DEBUG_LEVEL, c + ": Workflow step executing: " + cmd ); } StepExecutionResult result; try { result = framework.getExecutionService().executeStep( ExecutionContextImpl.builder(executionContext).stepNumber(c).build(), cmd ); if (!result.isSuccess()) { failedMap.put(c, result); } } catch (StepException e) { result = StepExecutionResultImpl.wrapStepException(e); failedMap.put(c, result); } if (null != executionContext.getExecutionListener()) { executionContext.getExecutionListener().log( Constants.DEBUG_LEVEL, c + ": Workflow step finished, result: " + result ); } return result; }
java
protected StepExecutionResult executeWFItem( final StepExecutionContext executionContext, final Map<Integer, StepExecutionResult> failedMap, final int c, final StepExecutionItem cmd ) { boolean hasHandler= cmd instanceof HasFailureHandler; boolean hideError = false; if(hasHandler){ final HasFailureHandler handles = (HasFailureHandler) cmd; final StepExecutionItem handler = handles.getFailureHandler(); if(null != handler && handler instanceof HandlerExecutionItem){ hideError = ((HandlerExecutionItem)handler).isKeepgoingOnSuccess(); } } if(null != executionContext.getExecutionListener()) { executionContext.getExecutionListener().ignoreErrors(hideError); } if (null != executionContext.getExecutionListener()) { executionContext.getExecutionListener().log( Constants.DEBUG_LEVEL, c + ": Workflow step executing: " + cmd ); } StepExecutionResult result; try { result = framework.getExecutionService().executeStep( ExecutionContextImpl.builder(executionContext).stepNumber(c).build(), cmd ); if (!result.isSuccess()) { failedMap.put(c, result); } } catch (StepException e) { result = StepExecutionResultImpl.wrapStepException(e); failedMap.put(c, result); } if (null != executionContext.getExecutionListener()) { executionContext.getExecutionListener().log( Constants.DEBUG_LEVEL, c + ": Workflow step finished, result: " + result ); } return result; }
[ "protected", "StepExecutionResult", "executeWFItem", "(", "final", "StepExecutionContext", "executionContext", ",", "final", "Map", "<", "Integer", ",", "StepExecutionResult", ">", "failedMap", ",", "final", "int", "c", ",", "final", "StepExecutionItem", "cmd", ")", "{", "boolean", "hasHandler", "=", "cmd", "instanceof", "HasFailureHandler", ";", "boolean", "hideError", "=", "false", ";", "if", "(", "hasHandler", ")", "{", "final", "HasFailureHandler", "handles", "=", "(", "HasFailureHandler", ")", "cmd", ";", "final", "StepExecutionItem", "handler", "=", "handles", ".", "getFailureHandler", "(", ")", ";", "if", "(", "null", "!=", "handler", "&&", "handler", "instanceof", "HandlerExecutionItem", ")", "{", "hideError", "=", "(", "(", "HandlerExecutionItem", ")", "handler", ")", ".", "isKeepgoingOnSuccess", "(", ")", ";", "}", "}", "if", "(", "null", "!=", "executionContext", ".", "getExecutionListener", "(", ")", ")", "{", "executionContext", ".", "getExecutionListener", "(", ")", ".", "ignoreErrors", "(", "hideError", ")", ";", "}", "if", "(", "null", "!=", "executionContext", ".", "getExecutionListener", "(", ")", ")", "{", "executionContext", ".", "getExecutionListener", "(", ")", ".", "log", "(", "Constants", ".", "DEBUG_LEVEL", ",", "c", "+", "\": Workflow step executing: \"", "+", "cmd", ")", ";", "}", "StepExecutionResult", "result", ";", "try", "{", "result", "=", "framework", ".", "getExecutionService", "(", ")", ".", "executeStep", "(", "ExecutionContextImpl", ".", "builder", "(", "executionContext", ")", ".", "stepNumber", "(", "c", ")", ".", "build", "(", ")", ",", "cmd", ")", ";", "if", "(", "!", "result", ".", "isSuccess", "(", ")", ")", "{", "failedMap", ".", "put", "(", "c", ",", "result", ")", ";", "}", "}", "catch", "(", "StepException", "e", ")", "{", "result", "=", "StepExecutionResultImpl", ".", "wrapStepException", "(", "e", ")", ";", "failedMap", ".", "put", "(", "c", ",", "result", ")", ";", "}", "if", "(", "null", "!=", "executionContext", ".", "getExecutionListener", "(", ")", ")", "{", "executionContext", ".", "getExecutionListener", "(", ")", ".", "log", "(", "Constants", ".", "DEBUG_LEVEL", ",", "c", "+", "\": Workflow step finished, result: \"", "+", "result", ")", ";", "}", "return", "result", ";", "}" ]
Execute a workflow item, returns true if the item succeeds. This method will throw an exception if the workflow item fails and the Workflow is has keepgoing==false. @param executionContext context @param failedMap List to add any messages if the item fails @param c index of the WF item @param cmd WF item descriptor @return true if the execution succeeds, false otherwise
[ "Execute", "a", "workflow", "item", "returns", "true", "if", "the", "item", "succeeds", ".", "This", "method", "will", "throw", "an", "exception", "if", "the", "workflow", "item", "fails", "and", "the", "Workflow", "is", "has", "keepgoing", "==", "false", "." ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java#L259-L305
15,996
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java
BaseWorkflowExecutor.executeWorkflowItemsForNodeSet
protected WorkflowStatusResult executeWorkflowItemsForNodeSet( final StepExecutionContext executionContext, final Map<Integer, StepExecutionResult> failedMap, final List<StepExecutionResult> resultList, final List<StepExecutionItem> iWorkflowCmdItems, final boolean keepgoing, final int beginStepIndex, WFSharedContext sharedContext ) { boolean workflowsuccess = true; String statusString = null; ControlBehavior controlBehavior = null; final WorkflowExecutionListener wlistener = getWorkflowListener(executionContext); int c = beginStepIndex; WFSharedContext currentData = new WFSharedContext(sharedContext); StepExecutionContext newContext = ExecutionContextImpl.builder(executionContext) .sharedDataContext(currentData) .build(); for (final StepExecutionItem cmd : iWorkflowCmdItems) { StepResultCapture stepResultCapture = executeWorkflowStep( newContext, failedMap, resultList, keepgoing, wlistener, c, cmd ); statusString = stepResultCapture.getStatusString(); controlBehavior = stepResultCapture.getControlBehavior(); currentData.merge(stepResultCapture.getResultData()); if (!stepResultCapture.isSuccess()) { workflowsuccess = false; } if (stepResultCapture.getControlBehavior() == ControlBehavior.Halt || !stepResultCapture.isSuccess() && !keepgoing) { break; } c++; } return workflowResult( workflowsuccess, statusString, null != controlBehavior ? controlBehavior : ControlBehavior.Continue, currentData ); }
java
protected WorkflowStatusResult executeWorkflowItemsForNodeSet( final StepExecutionContext executionContext, final Map<Integer, StepExecutionResult> failedMap, final List<StepExecutionResult> resultList, final List<StepExecutionItem> iWorkflowCmdItems, final boolean keepgoing, final int beginStepIndex, WFSharedContext sharedContext ) { boolean workflowsuccess = true; String statusString = null; ControlBehavior controlBehavior = null; final WorkflowExecutionListener wlistener = getWorkflowListener(executionContext); int c = beginStepIndex; WFSharedContext currentData = new WFSharedContext(sharedContext); StepExecutionContext newContext = ExecutionContextImpl.builder(executionContext) .sharedDataContext(currentData) .build(); for (final StepExecutionItem cmd : iWorkflowCmdItems) { StepResultCapture stepResultCapture = executeWorkflowStep( newContext, failedMap, resultList, keepgoing, wlistener, c, cmd ); statusString = stepResultCapture.getStatusString(); controlBehavior = stepResultCapture.getControlBehavior(); currentData.merge(stepResultCapture.getResultData()); if (!stepResultCapture.isSuccess()) { workflowsuccess = false; } if (stepResultCapture.getControlBehavior() == ControlBehavior.Halt || !stepResultCapture.isSuccess() && !keepgoing) { break; } c++; } return workflowResult( workflowsuccess, statusString, null != controlBehavior ? controlBehavior : ControlBehavior.Continue, currentData ); }
[ "protected", "WorkflowStatusResult", "executeWorkflowItemsForNodeSet", "(", "final", "StepExecutionContext", "executionContext", ",", "final", "Map", "<", "Integer", ",", "StepExecutionResult", ">", "failedMap", ",", "final", "List", "<", "StepExecutionResult", ">", "resultList", ",", "final", "List", "<", "StepExecutionItem", ">", "iWorkflowCmdItems", ",", "final", "boolean", "keepgoing", ",", "final", "int", "beginStepIndex", ",", "WFSharedContext", "sharedContext", ")", "{", "boolean", "workflowsuccess", "=", "true", ";", "String", "statusString", "=", "null", ";", "ControlBehavior", "controlBehavior", "=", "null", ";", "final", "WorkflowExecutionListener", "wlistener", "=", "getWorkflowListener", "(", "executionContext", ")", ";", "int", "c", "=", "beginStepIndex", ";", "WFSharedContext", "currentData", "=", "new", "WFSharedContext", "(", "sharedContext", ")", ";", "StepExecutionContext", "newContext", "=", "ExecutionContextImpl", ".", "builder", "(", "executionContext", ")", ".", "sharedDataContext", "(", "currentData", ")", ".", "build", "(", ")", ";", "for", "(", "final", "StepExecutionItem", "cmd", ":", "iWorkflowCmdItems", ")", "{", "StepResultCapture", "stepResultCapture", "=", "executeWorkflowStep", "(", "newContext", ",", "failedMap", ",", "resultList", ",", "keepgoing", ",", "wlistener", ",", "c", ",", "cmd", ")", ";", "statusString", "=", "stepResultCapture", ".", "getStatusString", "(", ")", ";", "controlBehavior", "=", "stepResultCapture", ".", "getControlBehavior", "(", ")", ";", "currentData", ".", "merge", "(", "stepResultCapture", ".", "getResultData", "(", ")", ")", ";", "if", "(", "!", "stepResultCapture", ".", "isSuccess", "(", ")", ")", "{", "workflowsuccess", "=", "false", ";", "}", "if", "(", "stepResultCapture", ".", "getControlBehavior", "(", ")", "==", "ControlBehavior", ".", "Halt", "||", "!", "stepResultCapture", ".", "isSuccess", "(", ")", "&&", "!", "keepgoing", ")", "{", "break", ";", "}", "c", "++", ";", "}", "return", "workflowResult", "(", "workflowsuccess", ",", "statusString", ",", "null", "!=", "controlBehavior", "?", "controlBehavior", ":", "ControlBehavior", ".", "Continue", ",", "currentData", ")", ";", "}" ]
Execute the sequence of ExecutionItems within the context, and with the given keepgoing value @param executionContext context @param failedMap failures @param resultList results @param iWorkflowCmdItems list of steps @param keepgoing true to keepgoing on step failure @param beginStepIndex beginning step index @return true if successful @deprecated should invoke engine workflow executor
[ "Execute", "the", "sequence", "of", "ExecutionItems", "within", "the", "context", "and", "with", "the", "given", "keepgoing", "value" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java#L322-L372
15,997
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java
BaseWorkflowExecutor.addStepFailureContextData
protected void addStepFailureContextData( StepExecutionResult stepResult, ExecutionContextImpl.Builder builder ) { HashMap<String, String> resultData = new HashMap<>(); if (null != stepResult.getFailureData()) { //convert values to string for (final Map.Entry<String, Object> entry : stepResult.getFailureData().entrySet()) { resultData.put(entry.getKey(), entry.getValue().toString()); } } FailureReason reason = stepResult.getFailureReason(); if (null == reason) { reason = StepFailureReason.Unknown; } resultData.put("reason", reason.toString()); String message = stepResult.getFailureMessage(); if (null == message) { message = "No message"; } resultData.put("message", message); //add to data context builder.setContext("result", resultData); }
java
protected void addStepFailureContextData( StepExecutionResult stepResult, ExecutionContextImpl.Builder builder ) { HashMap<String, String> resultData = new HashMap<>(); if (null != stepResult.getFailureData()) { //convert values to string for (final Map.Entry<String, Object> entry : stepResult.getFailureData().entrySet()) { resultData.put(entry.getKey(), entry.getValue().toString()); } } FailureReason reason = stepResult.getFailureReason(); if (null == reason) { reason = StepFailureReason.Unknown; } resultData.put("reason", reason.toString()); String message = stepResult.getFailureMessage(); if (null == message) { message = "No message"; } resultData.put("message", message); //add to data context builder.setContext("result", resultData); }
[ "protected", "void", "addStepFailureContextData", "(", "StepExecutionResult", "stepResult", ",", "ExecutionContextImpl", ".", "Builder", "builder", ")", "{", "HashMap", "<", "String", ",", "String", ">", "resultData", "=", "new", "HashMap", "<>", "(", ")", ";", "if", "(", "null", "!=", "stepResult", ".", "getFailureData", "(", ")", ")", "{", "//convert values to string", "for", "(", "final", "Map", ".", "Entry", "<", "String", ",", "Object", ">", "entry", ":", "stepResult", ".", "getFailureData", "(", ")", ".", "entrySet", "(", ")", ")", "{", "resultData", ".", "put", "(", "entry", ".", "getKey", "(", ")", ",", "entry", ".", "getValue", "(", ")", ".", "toString", "(", ")", ")", ";", "}", "}", "FailureReason", "reason", "=", "stepResult", ".", "getFailureReason", "(", ")", ";", "if", "(", "null", "==", "reason", ")", "{", "reason", "=", "StepFailureReason", ".", "Unknown", ";", "}", "resultData", ".", "put", "(", "\"reason\"", ",", "reason", ".", "toString", "(", ")", ")", ";", "String", "message", "=", "stepResult", ".", "getFailureMessage", "(", ")", ";", "if", "(", "null", "==", "message", ")", "{", "message", "=", "\"No message\"", ";", "}", "resultData", ".", "put", "(", "\"message\"", ",", "message", ")", ";", "//add to data context", "builder", ".", "setContext", "(", "\"result\"", ",", "resultData", ")", ";", "}" ]
Add step result failure information to the data context @param stepResult result @return new context
[ "Add", "step", "result", "failure", "information", "to", "the", "data", "context" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java#L381-L407
15,998
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java
BaseWorkflowExecutor.addNodeStepFailureContextData
protected void addNodeStepFailureContextData( final StepExecutionResult dispatcherStepResult, final ExecutionContextImpl.Builder builder ) { final Map<String, ? extends NodeStepResult> resultMap; if (NodeDispatchStepExecutor.isWrappedDispatcherResult(dispatcherStepResult)) { DispatcherResult dispatcherResult = NodeDispatchStepExecutor.extractDispatcherResult(dispatcherStepResult); resultMap = dispatcherResult.getResults(); } else if (NodeDispatchStepExecutor.isWrappedDispatcherException(dispatcherStepResult)) { DispatcherException exception = NodeDispatchStepExecutor.extractDispatcherException(dispatcherStepResult); HashMap<String, NodeStepResult> nodeResults = new HashMap<>(); NodeStepException nodeStepException = exception.getNodeStepException(); if (null != nodeStepException && null != exception.getNode()) { NodeStepResult nodeExecutorResult = nodeStepResultFromNodeStepException( exception.getNode(), nodeStepException ); nodeResults.put( nodeStepException.getNodeName(), nodeExecutorResult ); } resultMap = nodeResults; } else { return; } if (null != resultMap) { for (final Map.Entry<String, ? extends NodeStepResult> dentry : resultMap.entrySet()) { String nodename = dentry.getKey(); NodeStepResult stepResult = dentry.getValue(); HashMap<String, String> resultData = new HashMap<>(); if (null != stepResult.getFailureData()) { //convert values to string for (final Map.Entry<String, Object> entry : stepResult.getFailureData().entrySet()) { resultData.put(entry.getKey(), entry.getValue().toString()); } } FailureReason reason = stepResult.getFailureReason(); if (null == reason) { reason = StepFailureReason.Unknown; } resultData.put("reason", reason.toString()); String message = stepResult.getFailureMessage(); if (null == message) { message = "No message"; } resultData.put("message", message); //add to data context // builder.mergeContext("result", resultData); builder.nodeDataContext(nodename, new BaseDataContext("result", resultData)); } } }
java
protected void addNodeStepFailureContextData( final StepExecutionResult dispatcherStepResult, final ExecutionContextImpl.Builder builder ) { final Map<String, ? extends NodeStepResult> resultMap; if (NodeDispatchStepExecutor.isWrappedDispatcherResult(dispatcherStepResult)) { DispatcherResult dispatcherResult = NodeDispatchStepExecutor.extractDispatcherResult(dispatcherStepResult); resultMap = dispatcherResult.getResults(); } else if (NodeDispatchStepExecutor.isWrappedDispatcherException(dispatcherStepResult)) { DispatcherException exception = NodeDispatchStepExecutor.extractDispatcherException(dispatcherStepResult); HashMap<String, NodeStepResult> nodeResults = new HashMap<>(); NodeStepException nodeStepException = exception.getNodeStepException(); if (null != nodeStepException && null != exception.getNode()) { NodeStepResult nodeExecutorResult = nodeStepResultFromNodeStepException( exception.getNode(), nodeStepException ); nodeResults.put( nodeStepException.getNodeName(), nodeExecutorResult ); } resultMap = nodeResults; } else { return; } if (null != resultMap) { for (final Map.Entry<String, ? extends NodeStepResult> dentry : resultMap.entrySet()) { String nodename = dentry.getKey(); NodeStepResult stepResult = dentry.getValue(); HashMap<String, String> resultData = new HashMap<>(); if (null != stepResult.getFailureData()) { //convert values to string for (final Map.Entry<String, Object> entry : stepResult.getFailureData().entrySet()) { resultData.put(entry.getKey(), entry.getValue().toString()); } } FailureReason reason = stepResult.getFailureReason(); if (null == reason) { reason = StepFailureReason.Unknown; } resultData.put("reason", reason.toString()); String message = stepResult.getFailureMessage(); if (null == message) { message = "No message"; } resultData.put("message", message); //add to data context // builder.mergeContext("result", resultData); builder.nodeDataContext(nodename, new BaseDataContext("result", resultData)); } } }
[ "protected", "void", "addNodeStepFailureContextData", "(", "final", "StepExecutionResult", "dispatcherStepResult", ",", "final", "ExecutionContextImpl", ".", "Builder", "builder", ")", "{", "final", "Map", "<", "String", ",", "?", "extends", "NodeStepResult", ">", "resultMap", ";", "if", "(", "NodeDispatchStepExecutor", ".", "isWrappedDispatcherResult", "(", "dispatcherStepResult", ")", ")", "{", "DispatcherResult", "dispatcherResult", "=", "NodeDispatchStepExecutor", ".", "extractDispatcherResult", "(", "dispatcherStepResult", ")", ";", "resultMap", "=", "dispatcherResult", ".", "getResults", "(", ")", ";", "}", "else", "if", "(", "NodeDispatchStepExecutor", ".", "isWrappedDispatcherException", "(", "dispatcherStepResult", ")", ")", "{", "DispatcherException", "exception", "=", "NodeDispatchStepExecutor", ".", "extractDispatcherException", "(", "dispatcherStepResult", ")", ";", "HashMap", "<", "String", ",", "NodeStepResult", ">", "nodeResults", "=", "new", "HashMap", "<>", "(", ")", ";", "NodeStepException", "nodeStepException", "=", "exception", ".", "getNodeStepException", "(", ")", ";", "if", "(", "null", "!=", "nodeStepException", "&&", "null", "!=", "exception", ".", "getNode", "(", ")", ")", "{", "NodeStepResult", "nodeExecutorResult", "=", "nodeStepResultFromNodeStepException", "(", "exception", ".", "getNode", "(", ")", ",", "nodeStepException", ")", ";", "nodeResults", ".", "put", "(", "nodeStepException", ".", "getNodeName", "(", ")", ",", "nodeExecutorResult", ")", ";", "}", "resultMap", "=", "nodeResults", ";", "}", "else", "{", "return", ";", "}", "if", "(", "null", "!=", "resultMap", ")", "{", "for", "(", "final", "Map", ".", "Entry", "<", "String", ",", "?", "extends", "NodeStepResult", ">", "dentry", ":", "resultMap", ".", "entrySet", "(", ")", ")", "{", "String", "nodename", "=", "dentry", ".", "getKey", "(", ")", ";", "NodeStepResult", "stepResult", "=", "dentry", ".", "getValue", "(", ")", ";", "HashMap", "<", "String", ",", "String", ">", "resultData", "=", "new", "HashMap", "<>", "(", ")", ";", "if", "(", "null", "!=", "stepResult", ".", "getFailureData", "(", ")", ")", "{", "//convert values to string", "for", "(", "final", "Map", ".", "Entry", "<", "String", ",", "Object", ">", "entry", ":", "stepResult", ".", "getFailureData", "(", ")", ".", "entrySet", "(", ")", ")", "{", "resultData", ".", "put", "(", "entry", ".", "getKey", "(", ")", ",", "entry", ".", "getValue", "(", ")", ".", "toString", "(", ")", ")", ";", "}", "}", "FailureReason", "reason", "=", "stepResult", ".", "getFailureReason", "(", ")", ";", "if", "(", "null", "==", "reason", ")", "{", "reason", "=", "StepFailureReason", ".", "Unknown", ";", "}", "resultData", ".", "put", "(", "\"reason\"", ",", "reason", ".", "toString", "(", ")", ")", ";", "String", "message", "=", "stepResult", ".", "getFailureMessage", "(", ")", ";", "if", "(", "null", "==", "message", ")", "{", "message", "=", "\"No message\"", ";", "}", "resultData", ".", "put", "(", "\"message\"", ",", "message", ")", ";", "//add to data context", "// builder.mergeContext(\"result\", resultData);", "builder", ".", "nodeDataContext", "(", "nodename", ",", "new", "BaseDataContext", "(", "\"result\"", ",", "resultData", ")", ")", ";", "}", "}", "}" ]
Add any node-specific step failure information to the node-specific data contexts @param dispatcherStepResult result @param builder @return new context
[ "Add", "any", "node", "-", "specific", "step", "failure", "information", "to", "the", "node", "-", "specific", "data", "contexts" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java#L417-L471
15,999
rundeck/rundeck
core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java
BaseWorkflowExecutor.convertFailures
protected Map<String, Collection<StepExecutionResult>> convertFailures( final Map<Integer, StepExecutionResult> failedMap ) { final Map<String, Collection<StepExecutionResult>> failures = new HashMap<>(); for (final Map.Entry<Integer, StepExecutionResult> entry : failedMap.entrySet()) { final StepExecutionResult o = entry.getValue(); if (NodeDispatchStepExecutor.isWrappedDispatcherResult(o)) { //indicates dispatcher returned node results final DispatcherResult dispatcherResult = NodeDispatchStepExecutor.extractDispatcherResult(o); for (final String s : dispatcherResult.getResults().keySet()) { final NodeStepResult interpreterResult = dispatcherResult.getResults().get(s); if (!failures.containsKey(s)) { failures.put(s, new ArrayList<>()); } failures.get(s).add(interpreterResult); } } else if (NodeDispatchStepExecutor.isWrappedDispatcherException(o)) { DispatcherException e = NodeDispatchStepExecutor.extractDispatcherException(o); final INodeEntry node = e.getNode(); if (null != node) { //dispatch failed for a specific node final String key = node.getNodename(); if (!failures.containsKey(key)) { failures.put(key, new ArrayList<>()); } NodeStepException nodeStepException = e.getNodeStepException(); if (null != nodeStepException) { failures.get(key).add( nodeStepResultFromNodeStepException(node, nodeStepException) ); } } } } return failures; }
java
protected Map<String, Collection<StepExecutionResult>> convertFailures( final Map<Integer, StepExecutionResult> failedMap ) { final Map<String, Collection<StepExecutionResult>> failures = new HashMap<>(); for (final Map.Entry<Integer, StepExecutionResult> entry : failedMap.entrySet()) { final StepExecutionResult o = entry.getValue(); if (NodeDispatchStepExecutor.isWrappedDispatcherResult(o)) { //indicates dispatcher returned node results final DispatcherResult dispatcherResult = NodeDispatchStepExecutor.extractDispatcherResult(o); for (final String s : dispatcherResult.getResults().keySet()) { final NodeStepResult interpreterResult = dispatcherResult.getResults().get(s); if (!failures.containsKey(s)) { failures.put(s, new ArrayList<>()); } failures.get(s).add(interpreterResult); } } else if (NodeDispatchStepExecutor.isWrappedDispatcherException(o)) { DispatcherException e = NodeDispatchStepExecutor.extractDispatcherException(o); final INodeEntry node = e.getNode(); if (null != node) { //dispatch failed for a specific node final String key = node.getNodename(); if (!failures.containsKey(key)) { failures.put(key, new ArrayList<>()); } NodeStepException nodeStepException = e.getNodeStepException(); if (null != nodeStepException) { failures.get(key).add( nodeStepResultFromNodeStepException(node, nodeStepException) ); } } } } return failures; }
[ "protected", "Map", "<", "String", ",", "Collection", "<", "StepExecutionResult", ">", ">", "convertFailures", "(", "final", "Map", "<", "Integer", ",", "StepExecutionResult", ">", "failedMap", ")", "{", "final", "Map", "<", "String", ",", "Collection", "<", "StepExecutionResult", ">", ">", "failures", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "final", "Map", ".", "Entry", "<", "Integer", ",", "StepExecutionResult", ">", "entry", ":", "failedMap", ".", "entrySet", "(", ")", ")", "{", "final", "StepExecutionResult", "o", "=", "entry", ".", "getValue", "(", ")", ";", "if", "(", "NodeDispatchStepExecutor", ".", "isWrappedDispatcherResult", "(", "o", ")", ")", "{", "//indicates dispatcher returned node results", "final", "DispatcherResult", "dispatcherResult", "=", "NodeDispatchStepExecutor", ".", "extractDispatcherResult", "(", "o", ")", ";", "for", "(", "final", "String", "s", ":", "dispatcherResult", ".", "getResults", "(", ")", ".", "keySet", "(", ")", ")", "{", "final", "NodeStepResult", "interpreterResult", "=", "dispatcherResult", ".", "getResults", "(", ")", ".", "get", "(", "s", ")", ";", "if", "(", "!", "failures", ".", "containsKey", "(", "s", ")", ")", "{", "failures", ".", "put", "(", "s", ",", "new", "ArrayList", "<>", "(", ")", ")", ";", "}", "failures", ".", "get", "(", "s", ")", ".", "add", "(", "interpreterResult", ")", ";", "}", "}", "else", "if", "(", "NodeDispatchStepExecutor", ".", "isWrappedDispatcherException", "(", "o", ")", ")", "{", "DispatcherException", "e", "=", "NodeDispatchStepExecutor", ".", "extractDispatcherException", "(", "o", ")", ";", "final", "INodeEntry", "node", "=", "e", ".", "getNode", "(", ")", ";", "if", "(", "null", "!=", "node", ")", "{", "//dispatch failed for a specific node", "final", "String", "key", "=", "node", ".", "getNodename", "(", ")", ";", "if", "(", "!", "failures", ".", "containsKey", "(", "key", ")", ")", "{", "failures", ".", "put", "(", "key", ",", "new", "ArrayList", "<>", "(", ")", ")", ";", "}", "NodeStepException", "nodeStepException", "=", "e", ".", "getNodeStepException", "(", ")", ";", "if", "(", "null", "!=", "nodeStepException", ")", "{", "failures", ".", "get", "(", "key", ")", ".", "add", "(", "nodeStepResultFromNodeStepException", "(", "node", ",", "nodeStepException", ")", ")", ";", "}", "}", "}", "}", "return", "failures", ";", "}" ]
Convert map of step execution results keyed by step number, to a collection of step execution results keyed by node name @param failedMap failures @return converted
[ "Convert", "map", "of", "step", "execution", "results", "keyed", "by", "step", "number", "to", "a", "collection", "of", "step", "execution", "results", "keyed", "by", "node", "name" ]
8070f774f55bffaa1118ff0c03aea319d40a9668
https://github.com/rundeck/rundeck/blob/8070f774f55bffaa1118ff0c03aea319d40a9668/core/src/main/java/com/dtolabs/rundeck/core/execution/workflow/BaseWorkflowExecutor.java#L498-L538