Skip to content

"generate source" mojo iterates over the files if source is a dir. - #184

Merged
phax merged 3 commits into
phax:masterfrom
glelouet:plugin_work_dir
Aug 29, 2026
Merged

"generate source" mojo iterates over the files if source is a dir.#184
phax merged 3 commits into
phax:masterfrom
glelouet:plugin_work_dir

Conversation

@glelouet

@glelouet glelouet commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

The plugin can now be configured with a directory rather than an url / single file

In the example module, the pom references the concreteYaml directory to generate some trivial concrete classes, before the files in that directory were in a single one.

            <configuration>
              <source>concreteYaml</source> <!-- << here -->
              <rootPackage>com.helger.jcodemodel.examples.plugin.yaml.concrete</rootPackage>

This is done at the plugin level so generators should not be changed.

When a dir is found, all the files in it are applied to the generator, on the same JCM which is exported at the end. Therefore, each file must be valid on their own, and should not reference type from another one.

Also more docs for api.

No change is applied otherwise, and it only allows to use directory, so previous behavor did not change

The test is that the yaml plugin example actually split the definition
in three yaml files, in a dir. This dir is assigned as the plugin's
"source" value.

Also more docs for api.
@glelouet
glelouet requested a review from phax August 29, 2026 16:08
@glelouet glelouet added enhancement minor minor-level change : new feature, no breaking change labels Aug 29, 2026
@glelouet

Copy link
Copy Markdown
Collaborator Author

Note : this modification is because I want to extract the implicit structure from a yaml file into a flatStructure, then from it into corresponding java class.
so something like

a:
  b: c
  d: 5

would produce

A : 
 b : String
 d : int
Root:
 a : A

needs a lot of time to work on it though. The goal is to generate yaml parser from yaml file. And later spring entity from yaml files :D

* if it is a dir. Otherwise, return empty stream.
*/
@NonNull
protected Stream <InputStream> streamFiles (File rootFile)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We should change the return type to a "pair (InputStream, filename)" so that error messages from the caller can provide more details

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I was thinking about that. The issue is that eg for urls there is no such a file name to be provided, and when the data is set, it's priority is higher and does not have a file name either.

Was still thinking about it.

getLog ().info ("while trying to open " + m_sSource + " as a url", e);
getLog ().error ("while trying to open " + m_sSource + " as a file", fileException);
getLog ().error ("while trying to open " + m_sSource + " as a url", e);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The log errors should be split into the appropriate branches

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, I did it exactly like this on purpose.
If the first call fails, but not the second, it means there was no point complaining about the file not existing.

When set, the plugin accepts only files containing that param, when the
source is a directory
@glelouet

Copy link
Copy Markdown
Collaborator Author

@phax the new sourcesFilte param :
I named it m_sSourcesFilter first but I had errors when compiling the examples so I renamed it to sourcesFilter and it passed.

@phax
phax merged commit e3b5e6e into phax:master Aug 29, 2026
4 checks passed
@glelouet
glelouet deleted the plugin_work_dir branch August 30, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement minor minor-level change : new feature, no breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants