public static Object injectCommandLineParameter()

in azure-maven-plugin-lib/src/main/java/com/microsoft/azure/maven/utils/SystemPropertyUtils.java [19:45]


    public static Object injectCommandLineParameter(String prefix, Object obj, @Nonnull Class cls) {
        Object result = obj;
        try {
            if (result == null) {
                try {
                    result = cls.getDeclaredConstructor().newInstance();
                } catch (InstantiationException | InvocationTargetException | NoSuchMethodException e) {
                    throw new AzureException(String.format("Class %s should have a default constructor for inject properties", cls.getName()));
                }
            }
            final List<Field> fields = FieldUtils.getAllFieldsList(cls);
            for (final Field field : fields) {
                if (!Modifier.isStatic(field.getModifiers()) && field.getType().equals(String.class)) {
                    final String propertyValue = System.getProperty(String.format("%s.%s", prefix, field.getName()));
                    if (StringUtils.isNotBlank(propertyValue)) {
                        final String objValue = (String) FieldUtils.readField(result, field.getName(), true);
                        if (StringUtils.isBlank(objValue)) {
                            FieldUtils.writeField(result, field.getName(), propertyValue, true);;
                        }
                    }
                }
            }
        } catch (IllegalAccessException ex) {
            throw new AzureException(ex.getMessage());
        }
        return result;
    }