Skip to content

Conversation

tdurieux
Copy link
Collaborator

What do you think?

The idea of this is to be able to override DefaultOutputDestination and defines your output strategy in getOutputPath(File defaultOutputDirectory, Path packagePath, String filename)


public interface OutputDestination {

Path getOutputPath(File defaultOutputDirectory, Path packagePath, String filename);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Path, Path?


Path getOutputPath(File defaultOutputDirectory, Path packagePath, String filename);

Path getOutputPath(CtPackage type, File defaultOutputDirectory,
Copy link
Collaborator

Choose a reason for hiding this comment

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

additional arg at the end?

@@ -95,6 +95,8 @@
private List<String> processorTypes = new ArrayList<>();
private List<Processor<? extends CtElement>> processors = new ArrayList<>();

private OutputDestination outputDirectory = new DefaultOutputDestination();
Copy link
Collaborator

Choose a reason for hiding this comment

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

no state plz

@pvojtechovsky
Copy link
Collaborator

I like that idea.
Note: Interface OutputDestination with 3 methods cannot be implemented using lambda. May be you can implement two of them as default methods directly in interface?

@tdurieux
Copy link
Collaborator Author

I think three methods is too much.
I propose to only have
getOutputPath(CtElement element, File defaultOutputDirectory, Path packagePath, String filename).

The users that will use this interface should be able to do an instanceof .

WDYT?

@pvojtechovsky
Copy link
Collaborator

What about method like this:

Path getOutputPath(CtPackage package, CtType type, File defaultOutputDirectory, Path packagePath, String filename)

the type might be sometime null

@monperrus monperrus changed the title wip: feat: be able to change the destination of each created file WIP: feat: be able to change the destination of each created file Nov 10, 2017
@monperrus
Copy link
Collaborator

ping?

@tdurieux
Copy link
Collaborator Author

I have an issue because the output destination is stored in two places in the:

  • ModelBuilder
  • FileGenerator

I think it is an issue, but I don't know which one is the best to keep

@surli
Copy link
Collaborator

surli commented Dec 1, 2017

I think it is an issue, but I don't know which one is the best to keep

I propose to put the output destination in Environment and to only store it there. Then other classes could get it through Environment. WDYT?

@pvojtechovsky
Copy link
Collaborator

to put the output destination in Environment

sounds good for me

@monperrus
Copy link
Collaborator

rebase now that we have #1770 ?

@tdurieux tdurieux force-pushed the feat_output_destination branch from c9e7049 to fbd9940 Compare December 8, 2017 11:58
@monperrus
Copy link
Collaborator

monperrus commented Dec 18, 2017

travis fails? @tdurieux ?

@tdurieux
Copy link
Collaborator Author

no there is still a lot of work to do.
The current implementation is not nice, way to much state

@tdurieux tdurieux force-pushed the feat_output_destination branch from 0ed5729 to 244a370 Compare December 20, 2017 09:31
@tdurieux
Copy link
Collaborator Author

I finished to clean up this PR.

But I'm not sure if the interface and the implementation of OutputDestination is good enough.
I made DefaultOutputDestination in the way that it is easy to overwrite.
Probably, the method that will be overwritten by the client is Path getDirectoryPath(CtModule module, CtPackage pack, CtType type) which returns the root path of the destination.

@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@tdurieux tdurieux changed the title WIP: feat: be able to change the destination of each created file Review: feat: be able to change the destination of each created file Dec 20, 2017
@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
/**
* Set the output destination that handles where source files are written
*/
void setOutputDesination(OutputDestination outputDestination);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name is a bit confusing with sourceOutputDirectory, and for me it looks like a strategy for the final location of the output. So WDYT about renaming it to something like setOutputStrategy or setOuputHandler?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree

if (!packageDir.exists()) {
if (!packageDir.mkdirs()) {
private Path getElementPath(CtPackage type) {
return createFolders(getEnvironment().getOutputDestination()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't you delegate the creation of the folder to the output destination strategy? We can imagine different implementation e.g. a strategy for not creating new directory, or for not overwritten existing files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

strategy for not creating a new directory, or for not overwritten existing files.

it is not exactly the same responsibility, what you ask is more something like, isToPrint, not whereToPrint

Copy link
Collaborator

Choose a reason for hiding this comment

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

it is not exactly the same responsibility, what you ask is more something like, isToPrint, not whereToPrint

In fact I see the OutputDestinationStrategy as the main handler in Spoon to manage the pathes of the output. In that sense, its responsibility is indeed, not only to say where to print, but also to say if it's ok to print things at this specific location.
The idea behind it is that you only need to provide your own implementation of OutputDestinationStrategy whenever you need a specific behaviour related to path, beeing where, if or how.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know how to communicate with the output processor. The use case is not clear to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just rename getOutputPath to createOutputPath, and inside this method you create the needed folders?..

@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@INRIA INRIA deleted a comment from spoon-bot Dec 20, 2017
@surli
Copy link
Collaborator

surli commented Jan 3, 2018

I changed some names so for me it's ready to merge @tdurieux @monperrus

@INRIA INRIA deleted a comment from spoon-bot Jan 3, 2018
@INRIA INRIA deleted a comment from spoon-bot Jan 3, 2018
@monperrus
Copy link
Collaborator

That's good. Could you add a test case for this new feature?

@spoon-bot
Copy link
Collaborator

Detected changes by Revapi: 2.

Old API: fr.inria.gforge.spoon:spoon-core:jar:6.2.0-20180110.234716-39

New API: fr.inria.gforge.spoon:spoon-core:jar:6.2.0-SNAPSHOT

Name Change 1
Old none
New method Environment::getOutputDestinationHandler()
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking
Name Change 2
Old none
New method Environment::setOutputDestinationHandler(OutputDestinationHandler)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking

@spoon-bot
Copy link
Collaborator

Detected changes by Revapi: 2.

Old API: fr.inria.gforge.spoon:spoon-core:jar:6.2.0-20180110.234716-39

New API: fr.inria.gforge.spoon:spoon-core:jar:6.2.0-SNAPSHOT

Name Change 1
Old none
New method Environment::getOutputDestinationHandler()
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking,
Name Change 2
Old none
New method Environment::setOutputDestinationHandler(OutputDestinationHandler)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking,

@INRIA INRIA deleted a comment from spoon-bot Jan 11, 2018
@surli
Copy link
Collaborator

surli commented Jan 11, 2018

test added @monperrus

@monperrus monperrus merged commit 368343f into INRIA:master Jan 11, 2018
@monperrus
Copy link
Collaborator

thanks a lot!

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.

5 participants