idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
9,600 | public void addEvent ( LogEvent event ) { try { write ( getString ( event ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } | Add a new event |
9,601 | 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 |
9,602 | 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 |
9,603 | 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 |
9,604 | 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 |
9,605 | 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 . |
9,606 | 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 ) ; 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 ) ) ) { newLocalDataContext = DataContextUtils . addContext ( serviceName . toLowerCase ( ) , data , localDataContext ) ; } return DataContextUtils . addContext ( "config" , data , newLocalDataContext ) ; } | Loads the plugin configuration values stored in project or framework properties also |
9,607 | protected void loadContentConversionPropertyValues ( final Map < String , String > data , final ExecutionContext context , final List < Property > pluginProperties ) throws ConfigurationException { 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 |
9,608 | private void convertStoragePathValue ( final Map < String , String > data , final StorageTree storageTree , final String name , final String propValue , final Map < String , Object > renderingOptions ) throws ConfigurationException { 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 ( ) ; 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 ; } } } 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 . |
9,609 | 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 |
9,610 | 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 |
9,611 | 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 |
9,612 | 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 . |
9,613 | 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 |
9,614 | 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 |
9,615 | 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 |
9,616 | 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 . |
9,617 | public static < T extends ContentMeta > ResourceSelector < T > exactMetadataResourceSelector ( final Map < String , String > required , final boolean requireAll ) { return new ResourceSelector < T > ( ) { 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 |
9,618 | 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 ) ; } 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 |
9,619 | public static < T extends ContentMeta > ResourceSelector < T > composeSelector ( final ResourceSelector < T > a , final ResourceSelector < T > b , final boolean and ) { return new ResourceSelector < T > ( ) { public boolean matchesContent ( T content ) { boolean a1 = a . matchesContent ( content ) ; if ( a1 && ! and || ! a1 && and ) { return a1 ; } return b . matchesContent ( content ) ; } } ; } | compose two selectors |
9,620 | public static < T extends ContentMeta > ResourceSelector < T > allResourceSelector ( ) { return new ResourceSelector < T > ( ) { public boolean matchesContent ( T content ) { return true ; } } ; } | A resource selector which always matches |
9,621 | 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 |
9,622 | 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 |
9,623 | 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 |
9,624 | 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 . |
9,625 | 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 > ( ) ; 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 . |
9,626 | 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 |
9,627 | 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 ( ) ) ; return StorageUtil . withStream ( null == result ? resourceMeta : result , resourceMetaBuilder . getResourceMeta ( ) ) ; } | perform appropriate plugin filter method based on the operation enacted |
9,628 | 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 |
9,629 | 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 |
9,630 | public HasInputStream readResource ( Path path , ResourceMetaBuilder resourceMetaBuilder , final HasInputStream hasResourceStream ) { if ( wasEncoded ( resourceMetaBuilder ) ) { return decode ( hasResourceStream ) ; } return null ; } | Reads stored data so decodes a base64 stream if the metadata indicates it has been encoded |
9,631 | 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 |
9,632 | private void loadFileSources ( final File directory , final String project ) { if ( ! directory . isDirectory ( ) ) { logger . warn ( "Not a directory: " + directory ) ; } 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 ) ) ; } } ) ; if ( null != files ) { Arrays . sort ( files , null ) ; synchronized ( sourceCache ) { final HashSet < File > trackedFiles = new HashSet < File > ( sourceCache . keySet ( ) ) ; for ( final File file : files ) { 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 ) ; } } } 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 |
9,633 | 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 |
9,634 | 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 |
9,635 | 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 . |
9,636 | 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 |
9,637 | 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 |
9,638 | 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 . |
9,639 | 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 |
9,640 | private static void moveFile ( final File fromFile , final File toFile ) throws UpdateException { try { 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 |
9,641 | 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 { synchronized ( UpdateUtils . class ) { final FileChannel channel = new RandomAccessFile ( lockFile , "rw" ) . getChannel ( ) ; 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 |
9,642 | 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 |
9,643 | 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 |
9,644 | 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 |
9,645 | 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 |
9,646 | 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 |
9,647 | public static String join ( String [ ] input , char separator ) { 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 |
9,648 | 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 |
9,649 | 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 . |
9,650 | 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 . |
9,651 | public ResourceFormatParser getParserForMIMEType ( final String mimeType ) throws UnsupportedFormatException { 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 . |
9,652 | 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 |
9,653 | 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 |
9,654 | 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 |
9,655 | 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 |
9,656 | 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 |
9,657 | public static ResourceMetaBuilder create ( Map < String , String > meta ) { ResourceMetaBuilder mutableRundeckResourceMeta = new ResourceMetaBuilder ( meta ) ; return mutableRundeckResourceMeta ; } | Create a new builder with a set of metadata |
9,658 | public static boolean deletePathRecursive ( Tree < ResourceMeta > tree , Path path ) { if ( tree . hasResource ( path ) ) { return tree . deleteResource ( path ) ; } else if ( tree . hasDirectory ( path ) ) { 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 |
9,659 | 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 |
9,660 | public static PoliciesCache fromFile ( File singleFile , Set < Attribute > forcedContext ) { return fromSourceProvider ( YamlProvider . getFileProvider ( singleFile ) , forcedContext ) ; } | Create a cache from a single file source |
9,661 | public static PoliciesCache fromSourceProvider ( final SourceProvider provider , final Set < Attribute > forcedContext ) { return new PoliciesCache ( provider , forcedContext ) ; } | Create from a provider with a forced context |
9,662 | public static PoliciesCache fromDir ( File rootDir , final Set < Attribute > forcedContext ) { return fromSourceProvider ( YamlProvider . getDirProvider ( rootDir ) , forcedContext ) ; } | Create a cache from a directory source |
9,663 | 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 . |
9,664 | 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 . |
9,665 | 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 |
9,666 | private String translatePathExternal ( String intpath ) { if ( fullPath ) { return intpath ; } else { return PathUtil . appendPath ( rootPath . getPath ( ) , intpath ) ; } } | convert internal path to external |
9,667 | 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 |
9,668 | public static Function < ResourceModelSourceFactory , ResourceModelSource > factoryConverter ( final Properties configuration ) { return new Function < ResourceModelSourceFactory , ResourceModelSource > ( ) { 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 |
9,669 | 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 |
9,670 | 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 |
9,671 | public void visitWith ( ExecArg . Visitor visitor ) { for ( ExecArg arg : getList ( ) ) { arg . accept ( visitor ) ; } } | Visit with a visitor |
9,672 | 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 |
9,673 | 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 |
9,674 | 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 |
9,675 | public void removeFrameworkProject ( final String projectName ) { synchronized ( projectCache ) { removeSubDir ( projectName ) ; projectCache . remove ( projectName ) ; } } | Remove a project definition |
9,676 | @ 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 |
9,677 | 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 |
9,678 | private Attributes getMainAttributes ( ) { if ( null == mainAttributes ) { mainAttributes = getJarMainAttributes ( pluginJar ) ; String pluginName = mainAttributes . getValue ( RUNDECK_PLUGIN_NAME ) ; if ( pluginName == null ) { pluginName = mainAttributes . getValue ( RUNDECK_PLUGIN_CLASSNAMES ) ; } pluginId = PluginUtils . generateShaIdFromName ( pluginName ) ; } return mainAttributes ; } | return the main attributes from the jar manifest |
9,679 | 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 |
9,680 | static Plugin getPluginMetadata ( final Class < ? > cls ) throws PluginException { 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 ( ) ) ; } 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 |
9,681 | 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 |
9,682 | 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 |
9,683 | 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 |
9,684 | 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 . |
9,685 | 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 |
9,686 | 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 |
9,687 | 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 |
9,688 | 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 |
9,689 | 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 . |
9,690 | public void initialize ( Framework framework ) { setFramework ( framework ) ; 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 |
9,691 | 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 |
9,692 | 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 . |
9,693 | 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 |
9,694 | protected void addStepFailureContextData ( StepExecutionResult stepResult , ExecutionContextImpl . Builder builder ) { HashMap < String , String > resultData = new HashMap < > ( ) ; if ( null != stepResult . getFailureData ( ) ) { 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 ) ; builder . setContext ( "result" , resultData ) ; } | Add step result failure information to the data context |
9,695 | 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 ( ) ) { 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 ) ; builder . nodeDataContext ( nodename , new BaseDataContext ( "result" , resultData ) ) ; } } } | Add any node - specific step failure information to the node - specific data contexts |
9,696 | 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 ) ) { 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 ) { 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 |
9,697 | public static Description descriptionForProvider ( final boolean includeFieldProperties , final Object providerForType ) { if ( providerForType instanceof Describable ) { final Describable desc = ( Describable ) providerForType ; return desc . getDescription ( ) ; } else if ( PluginAdapterUtility . canBuildDescription ( providerForType ) ) { return PluginAdapterUtility . buildDescription ( providerForType , DescriptionBuilder . builder ( ) , includeFieldProperties ) ; } return null ; } | Get or build the description of a plugin instance of a given type |
9,698 | public synchronized void remove ( final File file ) { final T t = cache . get ( file ) ; expiry . remove ( file ) ; cache . remove ( file ) ; if ( null != t && t instanceof Expireable ) { final Expireable exp = ( Expireable ) t ; exp . expire ( ) ; } } | Remove entry for a file . |
9,699 | public static FrameworkProjectConfig create ( final String name , final File propertyFile , final IFilesystemFramework filesystemFramework ) { return new FrameworkProjectConfig ( name , propertyFile , filesystemFramework ) ; } | Create from existing file |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.