-
-
Notifications
You must be signed in to change notification settings - Fork 363
Review: feat: be able to change the destination of each created file #1610
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
Conversation
|
||
public interface OutputDestination { | ||
|
||
Path getOutputPath(File defaultOutputDirectory, Path packagePath, String filename); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
src/main/java/spoon/Launcher.java
Outdated
@@ -95,6 +95,8 @@ | |||
private List<String> processorTypes = new ArrayList<>(); | |||
private List<Processor<? extends CtElement>> processors = new ArrayList<>(); | |||
|
|||
private OutputDestination outputDirectory = new DefaultOutputDestination(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no state plz
I like that idea. |
I think three methods is too much. The users that will use this interface should be able to do an instanceof . WDYT? |
What about method like this:
the |
ping? |
I have an issue because the output destination is stored in two places in the:
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? |
sounds good for me |
rebase now that we have #1770 ? |
c9e7049
to
fbd9940
Compare
travis fails? @tdurieux ? |
no there is still a lot of work to do. |
…utput directory for each create file
0ed5729
to
244a370
Compare
I finished to clean up this PR. But I'm not sure if the interface and the implementation of |
/** | ||
* Set the output destination that handles where source files are written | ||
*/ | ||
void setOutputDesination(OutputDestination outputDestination); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?..
I changed some names so for me it's ready to merge @tdurieux @monperrus |
That's good. Could you add a test case for this new feature? |
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
|
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
|
test added @monperrus |
thanks a lot! |
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)