public static <T> T interpolate(final Map<String, Object> values, final T object) { interpolator.setDefaultLookup(new MapOfMapStrLookup(values)); return proxy(object); }
@Test public void testPreserveImplementedInterfaces() { Object object = new Test1Class(); Object newObject = VariableInterpolation.interpolate(new HashMap<>(), object); assertTrue(newObject instanceof Test1); object = new Test2Class(); newObject = VariableInterpolation.interpolate(new HashMap<>(), object); assertTrue(newObject instanceof Test1); object = new Test3Class(); newObject = VariableInterpolation.interpolate(new HashMap<>(), object); assertTrue(newObject instanceof Test1); }
@Test public void missingContentTest() { final Test1 object = new Test1() { }; final Test1 newObject = VariableInterpolation.interpolate(new HashMap<String, Object>() {{ put("input", new HashMap<String, String>() {{ put("value2", "myvalue2"); }}); }}, object); assertEquals("", newObject.getValue1()); assertEquals("myvalue2", newObject.getValue2()); assertEquals("", newObject.getValue3()); }
@Test public void basicTest() { final Test1 object = new Test1() { }; final Test1 newObject = VariableInterpolation.interpolate(new HashMap<String, Object>() {{ put("input", new HashMap<String, String>() {{ put("value1", "myvalue1"); put("value2", "myvalue2"); }}); }}, object); assertEquals("myvalue1", newObject.getValue1()); assertEquals("myvalue2", newObject.getValue2()); assertEquals("myvalue1", newObject.getValue3()); }
private Optional<OpenShiftRuntime> create(final OpenShiftRuntimeConfig runtimeConfig) throws ProvisioningException { final Optional<OpenShiftProvider> _openshiftProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), OpenShiftProvider.class); if (!_openshiftProvider.isPresent()) { return Optional.empty(); } OpenShiftProvider openshiftProvider = _openshiftProvider.get(); OpenShiftClient openshiftClient = openshift.getOpenShiftClient(openshiftProvider); LOG.info("Creating runtime..."); OpenShiftRuntimeState runtimeState; try { runtimeState = openshiftClient.create(runtimeConfig); } catch (OpenShiftClientException ex) { throw new ProvisioningException(ex.getMessage(), ex); } final String id = runtimeConfig.getRuntimeId().toString(); LOG.info("Created runtime: " + id); OpenShiftRuntimeEndpoint endpoint = openshiftClient.getRuntimeEndpoint(id); return Optional.of(new OpenShiftRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig, openshiftProvider, endpoint, new OpenShiftRuntimeInfo(runtimeConfig), runtimeState)); }
@Test public void testVariablesResolution() { Map<String, String> values = new HashMap<>(); values.put(ContextAwareWildflyRuntimeExecConfig.WAR_PATH, FILE_PATH); values.put(ContextAwareWildflyRuntimeExecConfig.REDEPLOY_STRATEGY, REDEPLOY_OPTION); values.put(ContextAwareWildflyRuntimeExecConfig.RUNTIME_NAME, RUNTIME_NAME); final ContextAwareWildflyRuntimeExecConfig config = new ContextAwareWildflyRuntimeExecConfig(); final ContextAwareWildflyRuntimeExecConfig varConfig = interpolate(singletonMap("input", values), config); assertEquals(FILE_PATH, varConfig.getWarPath()); assertEquals(REDEPLOY_OPTION, varConfig.getRedeployStrategy()); assertEquals(RUNTIME_NAME, varConfig.getRuntimeName()); } }
@Override public String lookup(String key) { if (this.map == null) { return null; } else { int dotIndex = key.indexOf("."); Object obj = this.map.get(key.substring(0, dotIndex < 0 ? key.length() : dotIndex)); if (obj instanceof Map) { return new MapOfMapStrLookup(((Map) obj)).lookup(key.substring(key.indexOf(".") + 1)); } else if (obj != null && !(obj instanceof String) && key.contains(".")) { final String subkey = key.substring(key.indexOf(".") + 1); for (PropertyDescriptor descriptor : new PropertyUtilsBean().getPropertyDescriptors(obj)) { if (descriptor.getName().equals(subkey)) { try { return descriptor.getReadMethod().invoke(obj).toString(); } catch (Exception ex) { continue; } } } } return obj == null ? "" : obj.toString(); } } }
public static <T> T proxy(final T instance) { try { Class<?>[] _interfaces; Class<?> currentClass = instance.getClass(); do { _interfaces = currentClass.getInterfaces(); currentClass = currentClass.getSuperclass(); } while (_interfaces.length == 0 && currentClass != null); T result = (T) new ByteBuddy() .subclass(Object.class) .implement(_interfaces) .method(ElementMatchers.any()) .intercept(InvocationHandlerAdapter.of(new InterpolationHandler(instance))) .make() .load(instance.getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .newInstance(); if (instance instanceof CloneableConfig) { return (T) ((CloneableConfig) result).asNewClone(result); } return result; } catch (final Exception ignored) { ignored.printStackTrace(); return instance; } }
@Test public void missingContentTest() { final Test1 object = new Test1() { }; final Test1 newObject = VariableInterpolation.interpolate(new HashMap<String, Object>() {{ put("input", new HashMap<String, String>() {{ put("value2", "myvalue2"); }}); }}, object); assertEquals("", newObject.getValue1()); assertEquals("myvalue2", newObject.getValue2()); assertEquals("", newObject.getValue3()); }
@Test public void basicTest() { final Test1 object = new Test1() { }; final Test1 newObject = VariableInterpolation.interpolate(new HashMap<String, Object>() {{ put("input", new HashMap<String, String>() {{ put("value1", "myvalue1"); put("value2", "myvalue2"); }}); }}, object); assertEquals("myvalue1", newObject.getValue1()); assertEquals("myvalue2", newObject.getValue2()); assertEquals("myvalue1", newObject.getValue3()); }
@Test public void testPreserveImplementedInterfaces() { Object object = new Test1Class(); Object newObject = VariableInterpolation.interpolate(new HashMap<>(), object); assertTrue(newObject instanceof Test1); object = new Test2Class(); newObject = VariableInterpolation.interpolate(new HashMap<>(), object); assertTrue(newObject instanceof Test1); object = new Test3Class(); newObject = VariableInterpolation.interpolate(new HashMap<>(), object); assertTrue(newObject instanceof Test1); }
endpoint.setContext(appContext); return Optional.of(new WildflyRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig,
((ContextAware) output).setContext(Collections.unmodifiableMap(context.getValues())); final Object newOutput = interpolate(context.getValues(), output); if (executor == null) {
public static <T> T interpolate(final Map<String, Object> values, final T object) { interpolator.setDefaultLookup(new MapOfMapStrLookup(values)); return proxy(object); }
@Override public String lookup(String key) { if (this.map == null) { return null; } else { int dotIndex = key.indexOf("."); Object obj = this.map.get(key.substring(0, dotIndex < 0 ? key.length() : dotIndex)); if (obj instanceof Map) { return new MapOfMapStrLookup(((Map) obj)).lookup(key.substring(key.indexOf(".") + 1)); } else if (obj != null && !(obj instanceof String) && key.contains(".")) { final String subkey = key.substring(key.indexOf(".") + 1); for (PropertyDescriptor descriptor : new PropertyUtilsBean().getPropertyDescriptors(obj)) { if (descriptor.getName().equals(subkey)) { try { return descriptor.getReadMethod().invoke(obj).toString(); } catch (Exception ex) { continue; } } } } return obj == null ? "" : obj.toString(); } } }
public static <T> T proxy(final T instance) { try { Class<?>[] _interfaces; Class<?> currentClass = instance.getClass(); do { _interfaces = currentClass.getInterfaces(); currentClass = currentClass.getSuperclass(); } while (_interfaces.length == 0 && currentClass != null); T result = (T) new ByteBuddy() .subclass(Object.class) .implement(_interfaces) .method(ElementMatchers.any()) .intercept(InvocationHandlerAdapter.of(new InterpolationHandler(instance))) .make() .load(instance.getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .newInstance(); if (instance instanceof CloneableConfig) { return (T) ((CloneableConfig) result).asNewClone(result); } return result; } catch (final Exception ignored) { ignored.printStackTrace(); return instance; } }
endpoint.setContext(appContext); return Optional.of(new WildflyRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig,
((ContextAware) output).setContext(Collections.unmodifiableMap(context.getValues())); final Object newOutput = interpolate(context.getValues(), output); if (executor == null) {
dockerRuntimeEndpoint.setContext(""); return Optional.of(new DockerRuntime(shortId, buildRuntimeName(runtimeConfig, shortId), runtimeConfig,
dockerRuntimeEndpoint.setContext(""); return Optional.of(new DockerRuntime(shortId, buildRuntimeName(runtimeConfig, shortId), runtimeConfig,