Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleDateFormat variable expansion, is it possible? #104

Open
drapostolos opened this issue Oct 18, 2014 · 12 comments
Open

SimpleDateFormat variable expansion, is it possible? #104

drapostolos opened this issue Oct 18, 2014 · 12 comments

Comments

@drapostolos
Copy link
Contributor

I would like to define a Config interface like this:

public interface Configuration extends Config {
    @DefaultValue("${user.home}${file.separator}${date:yyyyMMdd-HHmmssSSS}")
    String logDirPath();
}

where

    public static void main(String[] args) throws Throwable {

        Configuration cfg = ConfigFactory.create(
                Configuration.class,
                System.getProperties());
        System.out.println(cfg.logDirPath());
        System.out.println(cfg.logDirPath());
    }

prints the expected output:

C:\Users\alex\20141018-163934471
C:\Users\alex\20141018-163934471

Where theX in "${date:X}" represent any pattern as used by java.text.SimpleDateFormat.

More generally, it would be nice to be able to register custom substitutors. Something like this

public interface Configuration extends Config {
    @SubstitutorClasses(names = {"date", "xyz"}, classes = {DateSubstitutor.class, XyzSubstitutor.class})
    @DefaultValue("${user.home}${file.separator}${date:yyyyMMdd-HHmmssSSS}")
    String logDirPath();
}

Could this be a possible feature for OWNER in the future?

@lviggiano
Copy link
Collaborator

This looks as an interesting add.

@drapostolos
Copy link
Contributor Author

I'll submit a pull request as soon as I get the time.

@lviggiano
Copy link
Collaborator

Define some junit tests first to show how this shall be used. I'd like to
see some preview on how you would design such feature, abd how that should
work.
Il 22/ott/2014 23:32 "Alexander Poulikakos" [email protected] ha
scritto:

I'll submit a pull request as soon as I get the time.


Reply to this email directly or view it on GitHub
#104 (comment).

@lviggiano
Copy link
Collaborator

I mean, from your example:

public interface Configuration extends Config {
    @DefaultValue("${user.home}${file.separator}${date:yyyyMMdd-HHmmssSSS}")
    String logDirPath();
}

${date:...} comes from a property file, so it's already a string, why would you format that differently if you can specify that properly on the first place?

Registering a custom substitutor may be interesting, though I'd like to see a test case to figure out how the feature would work.

Try to design a simple API for that: adding complexity adds overhead on other important features that are still missing. But also, once we introduce something in the API, I'd like to have some clean+simple+powerful api, so we don't need to change the feature later (breaking backward compatibility).

@drapostolos
Copy link
Contributor Author

Just added a pull request for this, containing only the unit tests. See #108

@drapostolos
Copy link
Contributor Author

Updated the pull request #108 with the actual implementation.

@lviggiano
Copy link
Collaborator

I'll look into it asap

@drapostolos
Copy link
Contributor Author

FYI This feature is inspired by a similar feature in apache commons configuration (which I have found useful).
See this chapter in their User Guide.

@drapostolos
Copy link
Contributor Author

Any comments on this?

/Alex

@lviggiano
Copy link
Collaborator

I didn't had time to study this in deep, yet. I think I got a general understanding, but not a complete idea on this.

Unfortunately I am working on this project on my spare time.
There is no schedule that I am following, so I can't give an estimation on when this task will be accomplished.

@drapostolos
Copy link
Contributor Author

Fair enough. Just wanted to be sure you haven't forgotten about it. Will remind you again in a month or two.

/Alex

@drapostolos
Copy link
Contributor Author

just a friendly reminder about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants