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

Versioning contract module #8

Closed

Conversation

FilipMalczak
Copy link

THIS SHOULDN'T BE MERGED YET!

This needs some aesthetical work yet, but I'm creating a pull request to be able to discuss the ideas and solutions.

See issue #7 .

@marcphilipp
Copy link
Member

Looks promising! 👍

Now we just need to determine all old and new API elements, call it, and see if it works... 😉

@FilipMalczak
Copy link
Author

Now we just need to determine all old and new API elements, call it, and see if it works...

I was already thinking about it. I imagine that the best orchestration for that would be as part of CI pipeline.

I'd start with Maven and Gradle plugins, that would provide 2 or 3 tasks or targets.

First task would be generateDescriptor that would generate descriptor from source sets and store into target/api/current.json (JSON as an example, it could be YML, XML, whatever is structural). Descriptor would be generated by parsing each available source file (e.g. with javaparser and javasymbolsolver ).

Second would be compareDescriptors that would compare descriptors loaded from target/api/current.json and src/api/lastVersion.json. Comparison would be done with help of graph from this pull request.

Third would be storeDescriptor that would copy descriptor from target/... to the src/... one. I'm not sure about this task, though and I think this could be done via standard utils from build tool.

Given paths would be defaults, tasks would have to be configurable to support inclusion and exclusions of source sets and custom descriptor paths and names.

Buildscript writer would have to decide how to orchestrate those two steps - manually, on developer machine, on CI server, etc, but it would provide the most basic steps needed.

targetCompatibility = 1.8
}

//todo: can we use Lombok? it will clean up implementation a bit, but I'm not sure whether we want any dependencies
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we be using Lombok to generate immutable data holder classes? If so, and if the API Guardian team would be willing to adopt it, then AutoValue would arguably be a better choice, since it doesn't hack into javac unlike Lombok. (Lombok is known to have interoperability problems with other tools like error-prone, so IMO it's not the safest tool to use.)

boolean majorVersionChanged, boolean minorVersionChanged){
return previousStatePredicate.test(previousState) && nextStatePredicate.test(nextState) &&
(!requiresMajorVersionIncrement || majorVersionChanged) &&
(!requiresMinorVersionIncrement || minorVersionChanged);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bug: should be: doesnt require minor change or minor change happened or major change happened

public static List<StateTransitionRule> rules = asList(
onMajorVersionIncrement(ALL_STATES, ALL_STATES),
anytime(asList(INTERNAL, EXPERIMENTAL), NONE),
anytime(DEPRECATED, INTERNAL),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this one.

STABLE;

public boolean featureExists(){
switch (this){
Copy link

@whiskeysierra whiskeysierra Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

return this != NONE

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does the job, but I wanted to keep consistency between descriptive methods. I'd say that compiler should optimize it to equivalent code in both cases and the performance trade-off isn't worth inconsistent code, especially that this tooling isn't supposed to be super-fast, but rather super-clear.

@FilipMalczak
Copy link
Author

@apiguardian - I could use some style hints here. Please see TODOs, mainly about VersionComponentChange and APIElementState.

@anyone - does anyone have an idea for tests that won't be basically re-write of the whole state graph?

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

Successfully merging this pull request may close these issues.

None yet

4 participants