-
Notifications
You must be signed in to change notification settings - Fork 161
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
feat: Catalog templates with property list #1205
Conversation
- 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
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.
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) { |
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 think this needs checking that the value isn't empty
if (split.length > 0) { | ||
templatePropertyInput.setKey(split[0]); | ||
} | ||
if (split.length > 1) { |
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.
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) { |
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.
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, |
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.
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<>()))); |
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.
Use Collections.emptyMap()
here.
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.*; |
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.
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 |
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.
Could you add some description here?
return catalogFile; | ||
} | ||
|
||
/** | ||
* Adds a new template to the given catalog | ||
* | ||
* @param properties |
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.
Same here
.append(Util.repeat(" ", indent + 4)) | ||
.append(ConsoleOutput.cyan(entry.getKey())) | ||
.append(" = "); | ||
if (StringUtils.isNotBlank(entry.getValue().getDescription())) { |
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.
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") |
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.
This is just my personal preference but I'd suggest simply using default
instead of default-value
.
Thank you for the feedback @quintesse . Will take a look on these. |
- Changes based on PR requests - Test for TemplatePropertyConverter
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.
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).
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 :-) |
Once it builds and tests correctly of course 😉 |
...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 |
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 😞 |
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. |
@nandorholozsnyak Oh, Spotless works well enough, it's just the chosen configuration that I'm somewhat unhappy with :-) |
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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. |
ef42f8d
to
a223b8d
Compare
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.
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
e64038d
to
11a01e6
Compare
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. |
Good job @nandorholozsnyak, thanks ! |
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? |
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 :-) |
Associated issue: #1203