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

feature: add fluent API for Launcher #3258

Merged
merged 17 commits into from
Feb 26, 2020
Merged

Conversation

MartinWitt
Copy link
Collaborator

Showcase some code for discussion #1563 . There are still a lot of calls to the environment missing. It's only to showcase the idea.

@monperrus
Copy link
Collaborator

monperrus commented Feb 19, 2020 via email

*/
public class FluentLauncher {

Launcher launcher;
Copy link

Choose a reason for hiding this comment

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

Can this be private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes 100%.

return this;
}

public void binaryOutputDirectory(File outputDirectory) {
Copy link

Choose a reason for hiding this comment

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

Does this need to follow the fluent interface idiom?

Copy link
Collaborator Author

@MartinWitt MartinWitt Feb 19, 2020

Choose a reason for hiding this comment

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

yes needs to be changed.

}

// needed???
public SpoonModelBuilder compiler(Factory factory) {
Copy link

Choose a reason for hiding this comment

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

How does a SpoonModelBuilder differ from the FluentLauncher? Conceptually, to me, they seem like they are trying to accomplish the same task: using a builder pattern to configure Spoon. Exposing both may lead to some confusion.

Copy link
Collaborator Author

@MartinWitt MartinWitt Feb 19, 2020

Choose a reason for hiding this comment

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

The SpoonModelBuilder interface doesn't expose a fluent api.

@MartinWitt
Copy link
Collaborator Author

thank you for the review, but the code here is just a draft and far from even worth reading. There are still settings missing, unneeded methods and maybe it's possible to wrap all 3 launcher in the same class. Finding a better name is open too.

@surli
Copy link
Collaborator

surli commented Feb 19, 2020

Thanks for starting this @MartinWitt!
Quite frankly, I would use KISS a lot for this: the main purpose of proposing to create a fluent API was to ease using Spoon.

So I'd just start with some easy well-defined use cases and iterate over them in the launcher. So basically remove everything with the "needed" question, and everything's out of the scope of the usecases expressed in #1563. It should drastically reduce the size of the class.

The idea is to have a first launcher to fit 90% of usecases, for other option users will still have the old non-fluent API and we can improve it later to add ways to access those options.

@MartinWitt
Copy link
Collaborator Author

MartinWitt commented Feb 20, 2020

as @surli suggested, i made the api slim.
Supported operations:

  • setting input resources(String, Iterable)
  • adding processors(processor, Iterable)
  • setting output directory(String, File)
  • enabling autoImports
  • disableConsistencyChecks
  • setting compilanceLevel
  • setting sourceClassPath
  • activating noClasspath mode
  • setting encoding

Are there any imported options someone is missing?
Incremental build and maven launcher could be supported, with creating a second constructor having a launcher type object as parameter. public FluentLauncher(Launcher launcher) , but would make the class more complex.

@surli
Copy link
Collaborator

surli commented Feb 21, 2020

Incremental build and maven launcher could be supported, with creating a second constructor having a launcher type object as parameter. public FluentLauncher(Launcher launcher) , but would make the class more complex.

I'm +1 to add a support for MavenLauncher since it's already an easy usecase for Spoon and it would show how to extend the capabilities of the FluentLauncher with another existing launcher.

@MartinWitt MartinWitt marked this pull request as ready for review February 21, 2020 17:44
@MartinWitt
Copy link
Collaborator Author

MartinWitt commented Feb 21, 2020

There were 2 options for adding the mavenlauncher.
Either copy all constructors with arguments(pretty bad) or creating a new constructor public FluentLauncher(Launcher launcher). The second option allows using new Launchers in the future and using the IncrementalLauncher too.
The testcases are only for showing how to use the FluentLauncher and should be removed afterwards. Is there any need to write real testcases for a wrapper class?

@MartinWitt MartinWitt changed the title WIP: Feature: Fluent API Feature: Fluent API Feb 22, 2020
@MartinWitt MartinWitt changed the title Feature: Fluent API Review: Feature: Fluent API Feb 23, 2020
@monperrus monperrus closed this Feb 24, 2020
@monperrus monperrus reopened this Feb 24, 2020
@monperrus
Copy link
Collaborator

Looks great, we just need a test case, the examples you had are great, could you add them back?

@surli
Copy link
Collaborator

surli commented Feb 24, 2020

That's really cool! +1 for a small unit test, could be done with a mock for the wrapped launcher.

@MartinWitt
Copy link
Collaborator Author

MartinWitt commented Feb 24, 2020

Maybe #3259 is not compatible with the spoon-control-flow code? The CI failure

[ERROR] /home/travis/build/INRIA/spoon/spoon-control-flow/src/main/java/fr/inria/controlflow/ControlFlowBuilder.java:[122,8] fr.inria.controlflow.ControlFlowBuilder is not abstract and does not override abstract method <T,S>visitCtSwitchExpression(spoon.reflect.code.CtSwitchExpression<T,S>) in spoon.reflect.visitor.CtVisitor

seems unrelated to this feature. See #3271 for potential fix.

@surli
Copy link
Collaborator

surli commented Feb 26, 2020

(just for info in case you don't know: you shouldn't need a commit to re-run the CI: triggering Travis from the UI is enough since it performs the build by merging changes with master each time)

@monperrus monperrus changed the title Review: Feature: Fluent API feature: add fluent API for Launcher Feb 26, 2020
@monperrus monperrus merged commit b93001b into INRIA:master Feb 26, 2020
@monperrus
Copy link
Collaborator

Thanks a lot @MartinWitt

@monperrus monperrus mentioned this pull request Mar 20, 2020
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

3 participants