@Test( expected = TargetException.class ) public void testPrepareParameter_invalidCapability() throws Exception { String input = "AUDIT_CONTROL, read minds"; DockerUtils.prepareParameter( input, Capability[].class ); }
public static Object prepareParameter( String rawValue, Class<?> clazz ) throws TargetException { Object result; if( clazz == int.class || clazz == Integer.class ) result = Integer.parseInt( rawValue ); else if( clazz == long.class || clazz == Long.class ) result = Long.parseLong( rawValue ); else if( clazz == boolean.class || clazz == Boolean.class ) result = Boolean.parseBoolean( rawValue ); else if( clazz == String[].class ) { List<String> parts = Utils.splitNicely( rawValue, "," ); result = parts.toArray( new String[ parts.size()]); } else if( clazz == Capability[].class ) { List<Capability> caps = new ArrayList<> (); for( String s : Utils.splitNicely( rawValue, "," )) { try { caps.add( Capability.valueOf( s )); } catch( Exception e ) { throw new TargetException( "Unknown capability: " + s ); } } result = caps.toArray( new Capability[ caps.size()]); } else result = rawValue; return result; }
DockerUtils { public static Object prepareParameter( String rawValue, Class<?> clazz ) throws TargetException { Object result; if( clazz == int.class || clazz == Integer.class ) result = Integer.parseInt( rawValue ); else if( clazz == long.class || clazz == Long.class ) result = Long.parseLong( rawValue ); else if( clazz == boolean.class || clazz == Boolean.class ) result = Boolean.parseBoolean( rawValue ); else if( clazz == String[].class ) { List<String> parts = Utils.splitNicely( rawValue, "," ); result = parts.toArray( new String[ parts.size()]); } else if( clazz == Capability[].class ) { List<Capability> caps = new ArrayList<> (); for( String s : Utils.splitNicely( rawValue, "," )) { try { caps.add( Capability.valueOf( s )); } catch( Exception e ) { throw new TargetException( "Unknown capability: " + s ); } } result = caps.toArray( new Capability[ caps.size()]); } else result = rawValue; return result; } }
DockerUtils { public static Object prepareParameter( String rawValue, Class<?> clazz ) throws TargetException { Object result; if( clazz == int.class || clazz == Integer.class ) result = Integer.parseInt( rawValue ); else if( clazz == long.class || clazz == Long.class ) result = Long.parseLong( rawValue ); else if( clazz == boolean.class || clazz == Boolean.class ) result = Boolean.parseBoolean( rawValue ); else if( clazz == String[].class ) { List<String> parts = Utils.splitNicely( rawValue, "," ); result = parts.toArray( new String[ parts.size()]); } else if( clazz == Capability[].class ) { List<Capability> caps = new ArrayList<> (); for( String s : Utils.splitNicely( rawValue, "," )) { try { caps.add( Capability.valueOf( s )); } catch( Exception e ) { throw new TargetException( "Unknown capability: " + s ); } } result = caps.toArray( new Capability[ caps.size()]); } else result = rawValue; return result; } private  DockerUtils(); }
DockerUtils { public static Object prepareParameter( String rawValue, Class<?> clazz ) throws TargetException { Object result; if( clazz == int.class || clazz == Integer.class ) result = Integer.parseInt( rawValue ); else if( clazz == long.class || clazz == Long.class ) result = Long.parseLong( rawValue ); else if( clazz == boolean.class || clazz == Boolean.class ) result = Boolean.parseBoolean( rawValue ); else if( clazz == String[].class ) { List<String> parts = Utils.splitNicely( rawValue, "," ); result = parts.toArray( new String[ parts.size()]); } else if( clazz == Capability[].class ) { List<Capability> caps = new ArrayList<> (); for( String s : Utils.splitNicely( rawValue, "," )) { try { caps.add( Capability.valueOf( s )); } catch( Exception e ) { throw new TargetException( "Unknown capability: " + s ); } } result = caps.toArray( new Capability[ caps.size()]); } else result = rawValue; return result; } private  DockerUtils(); static DockerClient createDockerClient( Map<String,String> targetProperties ); static void deleteImageIfItExists( String imageId, DockerClient dockerClient ); static Image findImageByIdOrByTag( String name, DockerClient dockerClient ); static Image findImageById( String imageId, List<Image> images ); static Image findImageByTag( String imageTag, List<Image> images ); static Container findContainerByIdOrByName( String name, DockerClient dockerClient ); static ContainerState getContainerState( String containerId, DockerClient dockerClient ); static void configureOptions( Map<String,String> options, CreateContainerCmd cmd ); static Object prepareParameter( String rawValue, Class<?> clazz ); static boolean extractBoolean( Boolean bool ); static String findDefaultImageVersion( String rawVersion ); static String buildContainerNameFrom( String scopedInstancePath, String applicationName ); }
DockerUtils { public static Object prepareParameter( String rawValue, Class<?> clazz ) throws TargetException { Object result; if( clazz == int.class || clazz == Integer.class ) result = Integer.parseInt( rawValue ); else if( clazz == long.class || clazz == Long.class ) result = Long.parseLong( rawValue ); else if( clazz == boolean.class || clazz == Boolean.class ) result = Boolean.parseBoolean( rawValue ); else if( clazz == String[].class ) { List<String> parts = Utils.splitNicely( rawValue, "," ); result = parts.toArray( new String[ parts.size()]); } else if( clazz == Capability[].class ) { List<Capability> caps = new ArrayList<> (); for( String s : Utils.splitNicely( rawValue, "," )) { try { caps.add( Capability.valueOf( s )); } catch( Exception e ) { throw new TargetException( "Unknown capability: " + s ); } } result = caps.toArray( new Capability[ caps.size()]); } else result = rawValue; return result; } private  DockerUtils(); static DockerClient createDockerClient( Map<String,String> targetProperties ); static void deleteImageIfItExists( String imageId, DockerClient dockerClient ); static Image findImageByIdOrByTag( String name, DockerClient dockerClient ); static Image findImageById( String imageId, List<Image> images ); static Image findImageByTag( String imageTag, List<Image> images ); static Container findContainerByIdOrByName( String name, DockerClient dockerClient ); static ContainerState getContainerState( String containerId, DockerClient dockerClient ); static void configureOptions( Map<String,String> options, CreateContainerCmd cmd ); static Object prepareParameter( String rawValue, Class<?> clazz ); static boolean extractBoolean( Boolean bool ); static String findDefaultImageVersion( String rawVersion ); static String buildContainerNameFrom( String scopedInstancePath, String applicationName ); static final String LATEST; }