-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
A bit of javadoc for codegen #31939
A bit of javadoc for codegen #31939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
|
||
import io.quarkus.bootstrap.model.ApplicationModel; | ||
|
||
/** | ||
* Code generation context | ||
*/ | ||
public class CodeGenContext { | ||
private final ApplicationModel model; | ||
private final Path outDir; | ||
|
@@ -15,6 +18,17 @@ public class CodeGenContext { | |
private final Config config; | ||
private final boolean test; | ||
|
||
/** | ||
* Creates a code generation context | ||
* | ||
* @param model application model | ||
* @param outDir target directory for the generated output | ||
* @param workDir working directory, typically the main build directory of the project | ||
* @param inputDir directory containing input content for a code generator | ||
* @param redirectIO whether the code generating process should redirect its IO | ||
* @param config application build time configuration | ||
* @param test indicates whether the code generation is being triggered for tests | ||
*/ | ||
public CodeGenContext(ApplicationModel model, Path outDir, Path workDir, Path inputDir, boolean redirectIO, | ||
Config config, boolean test) { | ||
this.model = model; | ||
|
@@ -26,30 +40,77 @@ public CodeGenContext(ApplicationModel model, Path outDir, Path workDir, Path in | |
this.test = test; | ||
} | ||
|
||
/** | ||
* Application model | ||
* | ||
* @return application model | ||
*/ | ||
public ApplicationModel applicationModel() { | ||
return model; | ||
} | ||
|
||
/** | ||
* Target directory for the generated output. | ||
* The directory would typically be resolved as {@code <project.build.directory>/generated-sources/<codegen-provider-id>}, | ||
* where {@code <codegen-provider-id> would match the value of {@link CodeGenProvider#providerId()}. | ||
* For example, for a code gen provider {@code foo}, the output directory in a typical Maven project would be | ||
* {@code target/generated-sources/foo}. | ||
* | ||
* @return target directory for the generated output | ||
*/ | ||
public Path outDir() { | ||
return outDir; | ||
} | ||
|
||
/** | ||
* Working directory, typically the main build directory of the project. | ||
* For a typical Maven project it would be the {@code target} directory. | ||
* | ||
* @return working directory, typically the main build directory of the project | ||
*/ | ||
public Path workDir() { | ||
return workDir; | ||
} | ||
|
||
/** | ||
* Directory containing input content for a code generator. | ||
* For the main application build of a typical Maven project the input sources directory | ||
* would be {@code <project.basedir>/src/main/<codegen-provider-id>}, while for the tests it would be | ||
* {@code <project.basedir>/src/test/<codegen-provider-id>}, where {@code <codegen-provider-id} | ||
* would match the value of {@link CodeGenProvider#providerId()}. | ||
* | ||
* @return directory containing input content a code generator | ||
*/ | ||
public Path inputDir() { | ||
return inputDir; | ||
} | ||
|
||
/** | ||
* Whether any new processes spawned by a given {@link CodeGenProvider} should inherit the | ||
* launching process' output streams | ||
* or redirect its output and error streams using {@link java.lang.ProcessBuilder.Redirect#PIPE}. | ||
* In the current implementation this is typically set to {@code true} by the framework. | ||
* | ||
* @return whether the code generation process should redirect its error and output streams | ||
*/ | ||
public boolean shouldRedirectIO() { | ||
return redirectIO; | ||
} | ||
|
||
/** | ||
* Application build time configuration | ||
* | ||
* @return application build time configuration | ||
*/ | ||
public Config config() { | ||
return config; | ||
} | ||
|
||
/** | ||
* Indicates whether the code generation is being triggered for tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily. We do generate code for tests when launching dev mode to be able to run continuous testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I see, thanks for explaining! Then the text is correct. |
||
* | ||
* @return indicates whether the code generation is being triggered for tests | ||
*/ | ||
public boolean test() { | ||
return test; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,38 @@ | |
import java.net.URL; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Provides context for a given path visit | ||
*/ | ||
public interface PathVisit { | ||
|
||
/** | ||
* The root of the path tree the current path belongs to. | ||
* For a {@link PathTree} created for an archive, this will be the path to the archive file. | ||
* For a {@link PathTree} created for a directory, this will be the path to the directory. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolute or relative (to what)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the caller that provides the value of the root. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Peter, based on my comment above, I wouldn't say it's "de facto absolute". It really depends on what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, "de facto absolute" is perhaps misleading. What I mean is "ready for IO operations" or simply "granted to exist". I admit it is rather trivial to document for getRoot() but it would be really nice to add a sentence to getPath() stating something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, thanks |
||
* | ||
* @return root of the path tree the current path belongs to | ||
*/ | ||
Path getRoot(); | ||
|
||
/** | ||
* The path being visited. The {@link java.nio.file.FileSystem} the path belongs to | ||
* will depend on the implementation of the {@link PathTree} being visited. For example, | ||
* for an archive it will be a ZIP {@link java.nio.file.FileSystem} implementation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolute or relative (to what)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might depend on whether the root is absolute or relative. It will be a path that can be read during the visit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly, that's a piece of super important info I'd like to find in JavaDoc! |
||
* | ||
* The returned path is granted to exist in the underlying file system (unless it was deleted by a parallel process or | ||
* thread) and therefore it can be used for I/O operations straight away without further resolving, e.g. against | ||
* {@link #getRoot()} | ||
* | ||
* @return path being visited | ||
*/ | ||
Path getPath(); | ||
|
||
/** | ||
* {@link java.net.URL} that can be used to read the content of the path. | ||
* | ||
* @return URL that can be used to read the content of the path | ||
*/ | ||
default URL getUrl() { | ||
try { | ||
return getPath().toUri().toURL(); | ||
|
@@ -18,7 +44,20 @@ default URL getUrl() { | |
} | ||
} | ||
|
||
/** | ||
* Path relative to the root of the tree as a string with a provided path element separator. | ||
* For a {@link PathTree} created for an archive, the returned path will be relative to the root | ||
* of the corresponding {@link java.nio.file.FileSystem} implementation. | ||
* For a {@link PathTree} created for a directory, the returned path will be relative to the directory | ||
* used as the root of the path tree. | ||
* | ||
* @param separator path element separator | ||
* @return path relative to the root of the tree as a string with a provided path element separator | ||
*/ | ||
String getRelativePath(String separator); | ||
|
||
/** | ||
* Terminates walking over a {@link PathTree} after this visit. | ||
*/ | ||
void stopWalking(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
package io.quarkus.paths; | ||
|
||
/** | ||
* {@link PathTree} path visitor | ||
*/ | ||
public interface PathVisitor { | ||
|
||
/** | ||
* Called to visit a path when walking a path tree or when a caller | ||
* requested to visit a specific path in a tree. In the latter case | ||
* if the requested path does not exist, the {@code visit} argument | ||
* will be null and it'll be up to the caller how to handle that, | ||
* i.e. whether to throw a path not found exception or return silently. | ||
* | ||
* @param visit visit object or null, in case the requested path does not exist | ||
*/ | ||
void visitPath(PathVisit visit); | ||
} |
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.
Absolute or relative (to what?).
An example would be nice, something like
{@code src/main/foo} for a CodeGenProvider having inputDirectory {@code foo}