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

feat: Catalog templates with property list #1205

Merged

Conversation

nandorholozsnyak
Copy link
Contributor

  • Property can have description and default value
  • Adding multiple property at the same time with a specific format
  • Listing templates returns the list of the template properties too

Associated issue: #1203

- Property can have description and default value
- Adding multiple property at the same time with a specific format
- Listing templates returns the list of the template properties too
Copy link
Contributor

@quintesse quintesse left a comment

Choose a reason for hiding this comment

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

Looks good! Just needs a couple of minor changes.
It also needs tests and changes to the docs :-)

public TemplateAdd.TemplatePropertyInput convert(final String input) throws Exception {
String[] split = input.split(":");
TemplateAdd.TemplatePropertyInput templatePropertyInput = new TemplateAdd.TemplatePropertyInput();
if (split.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs checking that the value isn't empty

if (split.length > 0) {
templatePropertyInput.setKey(split[0]);
}
if (split.length > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

And this probably shouldn't set the value if the split value is empty (so foo::bar would skip setting the description)

if (split.length > 1) {
templatePropertyInput.setDescription(split[1]);
}
if (split.length > 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, skip if empty.


public Template(Map<String, String> fileRefs, String description, Catalog catalog) {
public Template(Map<String, String> fileRefs, String description, Catalog catalog,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not wrong of course, but could you change the order a bit? The catalog is meant to be the last argument in the list.

@@ -59,7 +59,7 @@ public Catalog(String baseRef, String description, ResourceRef catalogRef, Map<S
new Alias(a.scriptRef, a.description, a.arguments, a.javaOptions, a.dependencies, a.repositories,
a.classpaths, a.properties, a.javaVersion, a.mainClass, this)));
templates.forEach((key, t) -> this.templates.put(key,
new Template(t.fileRefs, t.description, this)));
new Template(t.fileRefs, t.description, this, new HashMap<>())));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Collections.emptyMap() here.

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure you run ./gradlew spotlessApply before committing, no * imports are allowed.
I always run ./gradlew spotlessApply clean build installDist to make sure all my code has been cleaned up.

@@ -120,22 +117,25 @@ private static void removeAlias(Catalog catalog, String name) {
/**
* Adds a new template to the nearest catalog
*
* @param name The name of the new template
* @param properties
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some description here?

return catalogFile;
}

/**
* Adds a new template to the given catalog
*
* @param properties
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

.append(Util.repeat(" ", indent + 4))
.append(ConsoleOutput.cyan(entry.getKey()))
.append(" = ");
if (StringUtils.isNotBlank(entry.getValue().getDescription())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the changes I suggested for the TemplatePropertyConverter I'd simply check for null here.

public class TemplateProperty {

private String description;
@SerializedName(value = "default-value")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just my personal preference but I'd suggest simply using default instead of default-value.

@nandorholozsnyak
Copy link
Contributor Author

Thank you for the feedback @quintesse . Will take a look on these.
Just a quick feedback, in the Contribution file maybe some code standard and requirements should be visible, I understand I have to write the tests and make sure it is well formatted, but for the formatting issues I do remember I ran the spotless plugin before committing :D I'm just setting up the git hook for it to never happen again.
Is there any proper documentation about the code layering and structure?

- Changes based on PR requests
- Test for TemplatePropertyConverter
quintesse
quintesse previously approved these changes Jan 20, 2022
Copy link
Contributor

@quintesse quintesse left a comment

Choose a reason for hiding this comment

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

This would already be good enough to merge IMO.
But we need a couple of more tests, especially in TestTemplate, just to make sure that the information gets stored and retrieved correctly. A couple of edge cases perhaps (wrongly formatted property, things like that).

@quintesse
Copy link
Contributor

Is there any proper documentation about the code layering and structure?

Not really, I'd just look at the surrounding code when you add/change things and try to follow that style as much as possible. And if you write something completely new then we tend to just let you write it as you want, as long as it is good code :-)

@quintesse
Copy link
Contributor

This would already be good enough to merge IMO.

Once it builds and tests correctly of course 😉

@maxandersen
Copy link
Collaborator

Is there any proper documentation about the code layering and structure?

Not really, I'd just look at the surrounding code when you add/change things and try to follow that style as much as possible. And if you write something completely new then we tend to just let you write it as you want, as long as it is good code :-)

...and we apply code formatting automatically so the way I code is just whatever I need with whatever formatting my ide uses - Then run the spotlessapply
And it will fix it. Avoids having to think about formatting :)

@quintesse
Copy link
Contributor

And it will fix it

We should do something about the indenting, though. The fact that it tries to line up with the end of the first line (or whatever it is it tries to do) often creates some pretty horrible indents 😞

@nandorholozsnyak
Copy link
Contributor Author

I have never used Spotless before but .editorconfig. For me it was working well, of course if you are an Eclipse or Netbeans user you need a plugin for it in the IDE, but it has Gradle plugins as well.
https://editorconfig.org/

@quintesse
Copy link
Contributor

@nandorholozsnyak Oh, Spotless works well enough, it's just the chosen configuration that I'm somewhat unhappy with :-)

@codecov
Copy link

codecov bot commented Jan 23, 2022

Codecov Report

Merging #1205 (e64038d) into main (8919f79) will decrease coverage by 0.11%.
The diff coverage is 44.94%.

❗ Current head e64038d differs from pull request most recent head 11a01e6. Consider uploading reports for the commit 11a01e6 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1205      +/-   ##
============================================
- Coverage     58.96%   58.84%   -0.12%     
- Complexity     1049     1057       +8     
============================================
  Files            84       86       +2     
  Lines          5578     5659      +81     
  Branches        937      954      +17     
============================================
+ Hits           3289     3330      +41     
- Misses         1806     1837      +31     
- Partials        483      492       +9     
Flag Coverage Δ
Linux 57.69% <44.94%> (-0.11%) ⬇️
Windows 57.60% <44.94%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/main/java/dev/jbang/catalog/Catalog.java 70.00% <ø> (ø)
src/main/java/dev/jbang/cli/Catalog.java 32.38% <0.00%> (ø)
.../main/java/dev/jbang/catalog/TemplateProperty.java 27.77% <27.77%> (ø)
src/main/java/dev/jbang/cli/Template.java 47.61% <43.85%> (-0.21%) ⬇️
src/main/java/dev/jbang/catalog/CatalogUtil.java 61.78% <50.00%> (ø)
.../java/dev/jbang/cli/TemplatePropertyConverter.java 80.00% <80.00%> (ø)
src/main/java/dev/jbang/catalog/Template.java 48.00% <100.00%> (+2.16%) ⬆️
src/main/java/dev/jbang/cli/App.java 51.93% <0.00%> (+0.20%) ⬆️
src/main/java/dev/jbang/source/JarSource.java 79.06% <0.00%> (+4.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82de0ae...11a01e6. Read the comment docs.

@nandorholozsnyak nandorholozsnyak marked this pull request as ready for review January 23, 2022 11:17
@nandorholozsnyak
Copy link
Contributor Author

Hey @quintesse I added tests and small changes. I added the CLI docs as well, but I'm not sure if it would be enough or not.

@nandorholozsnyak nandorholozsnyak force-pushed the jbang-catalog-template-properties branch from ef42f8d to a223b8d Compare January 23, 2022 21:23
Copy link
Contributor

@quintesse quintesse left a comment

Choose a reason for hiding this comment

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

Code looks good! Please run ./gradlew spotlessApply and re-push because that's what making the CI build fail right now.

…command

test: Test for template properties adding and reading
fix: Template properties NPE check
fix: Spotless applied
@nandorholozsnyak nandorholozsnyak force-pushed the jbang-catalog-template-properties branch from e64038d to 11a01e6 Compare January 24, 2022 21:11
@nandorholozsnyak
Copy link
Contributor Author

Btw, locally I use Java 17 (Temurin) and the build fails with that, so this is why I was not able to spot what is not working, Spotless is not working with that, or at least some things are not okay with that.
I ran the code you mentioned, now it should be working.

@quintesse quintesse merged commit 106be11 into jbangdev:main Jan 24, 2022
@quintesse
Copy link
Contributor

Good job @nandorholozsnyak, thanks !

@nandorholozsnyak
Copy link
Contributor Author

Just a quick question @quintesse , did I just screw up the Codecov reports? I see that the master is failing because of the codecov report, and I just saw your new PR and checked the code as well and saw a lot of "misses" by the codecov. Should I open a PR to fix those?

@quintesse
Copy link
Contributor

Codecov is still in somewhat of an experimental phase for us right now, so don't worry too much about it. At some point we'll want to do something with that information though :-)

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.

3 participants