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
[JENKINS-26535] added support for parameterized parameter types #52
Conversation
[JENKINS-26535]
return new ArrayType(type, of(Types.getTypeArgument(Types.getBaseClass(type,Collection.class), 0, Object.class))); | ||
} | ||
Class<?> c = Types.erasure(type); | ||
// Assume it is a nested object of some sort. |
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.
Most of this is actually reindentation, making the diff look a lot bigger than it actually is. Had to apply the WS ignore setting in GitHub to see it.
if (Types.isSubClassOf(type, Collection.class)) { | ||
return new ArrayType(type, of(Types.getTypeArgument(Types.getBaseClass(type,Collection.class), 0, Object.class))); | ||
} | ||
throw new UnsupportedOperationException("do not know how to categorize attributes of type " + type); |
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 seems to have been removed and I am not sure why. Where is the fallback?
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 guess it is just not necessary any more and whatever sanity-checking was needed is already done in DescribableModel
?
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 fallback became unreachable, so I removed it. I was surprised that no unit tests failed. There is not much sanity-checking in DescribableModel
or DescribableParameter
.
I thought about limiting support for Homo
/HeterogeneousObjectType
to Describable
types and keeping the fallback, but that triggered a test failure in DescribableModelTest#recursion
since Recursion
is not a Describable
. I'm not sure if that is on purpose.
I pushed some tests for the problems that have been mentioned in the description of JENKINS-26535. So I'm pretty confident that this fixes JENKINS-26535. I also ran the Job DSL tests successfully with a snapshot build. |
@daspilker @jglick Is it ready for release? |
plugin/src/test/java/org/jenkinsci/plugins/structs/describable/DescribableModelTest.java
Show resolved
Hide resolved
…/DescribableModelTest.java Co-Authored-By: Joseph Petersen <josephp90@gmail.com>
@abayer @dwnusbaum @jglick 👋 we have a test case that confirms that JENKINS-26535 is resolved 👍 Would be great with a release! |
@car-roll this is still a blocker, can this be added to fix this very old bug |
I do not maintain this plugin, do not ask me. |
You reviewed the code so maybe the maintainer is waiting for your approval? 😅 |
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-wise everything looks fine to me, but I'm not familiar enough with this part of the code to give an approval. I will defer to @dwnusbaum or @abayer
Also, apologies for the late reply 😢 I had meant to comment on this earlier.
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 code seems ok to me. I don't feel like I really understand the implications, and I'm not aware of the original intent behind this code to know if there is any reason to not do this (for example, I think that previously, parameters of type Map
were not supported in some cases based on some testing I did with ParallelStep
, but I retested with this PR, and now they appear to be supported. Is that a problem? 🤷♂).
I also ran workflow-cps's tests against this change and didn't see any regressions. Are there any other plugins whose tests should be run against the change?
Because |
The basic description is in structs-plugin/plugin/src/main/java/org/jenkinsci/plugins/structs/describable/DescribableModel.java Lines 278 to 281 in 696fe7b
|
@jglick Ok, well with this PR in its current state, they are supported (at least as constructor parameters). I guess this is related to the old fallback that throws an |
👋 This is still blocking would be great to have a release 🙏 |
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 it is good to go. Thanks a lot @daspilker !
Apparently I am listed as a plugin maintainer. I would be interested to cut the release if @jglick and @dwnusbaum are satisfied by the current state |
I would leave it to @dwnusbaum. |
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.
@oleg-nenashev My understanding of this PR is that in addition to fixing the things described in JENKINS-26535 that we want to fix, it allows some other things that we do not want to allow. For example, in master
, DescribableModel
does not support this class:
public class MapParameter {
@DataBoundConstructor
public MapParameter(Map<String, String> data) { }
}
This test (copy it into DescribableModelTest
if you want to try it yourself (make sure that MapParameter
is marked as static
if it is an inner class)), which passes against master
, shows what happens if you try to use DescribableModel
with MapParameter
today:
@Test
public void mapParameter() throws Exception {
schema(MapParameter.class, "MapParameter(data: java.lang.UnsupportedOperationException: do not know how to categorize attributes of type java.util.Map<java.lang.String, java.lang.String>)");
}
That test no longer passes when run against this PR, because now, DescribableModel
supports Map
parameters. Here is the passing version of the test when using this PR:
@Test
public void mapParameter() throws Exception {
schema(MapParameter.class, "MapParameter(data: Map{})");
}
I think this change in behavior would be the same for any class with type parameters, not just Map
.
@jglick's comment here leads me to believe that this is a bad thing, but I do not totally understand the implications. I don't think it would cause any regressions, but I'm not really sure how it would affect existing use cases of DescribableModel
.
As @daspilker noted here, one seemingly reasonable way to disallow these types breaks an existing test (DescribableModelTest#recursion
), so it is unclear what should be done.
To recap, I think we need answers to these questions before we can merge this PR:
- Does the fact that the
MapParameter
class is now supported byDescribableModel
represent a problem with this PR that needs to be fixed before it is merged? - Should
DescribableModelTest#recursion
pass as-is, or doesmaster
have a bug andRecursion
should need to implementDescribable
for the test to pass?- If the latter, what are the implications of fixing the code so that that test fails? Does any existing code rely on that behavior?
It looks like this pull request is stuck. I therefore like to ask who could follow up on it? |
Now all traits consistently have a @symbol annotation. This improves configuration with JobDSL. Otherwise there is a clash e.g. with the github-branch-source-plugin.
Hi @dwnusbaum, just taking a bit of a look at this, The test case you suggested doesn't appear to be passing anymore on master,
Is there any chance you could update it, I would be interested in taking a look here, but not familiar with the code at all, thanks! |
@timja, sorry, the problem is just that
|
I cannot recall now all the reasons why I permitted non- |
Is there a reason why As you can see in the step docs there are multiple steps that take Map as an argument. I was hoping the description of Map and List could be similar in the docs, but the way structs describes Lists and Maps is different (ArrrayType vs ErrorType). |
Neither are legal. Besides atomic-ish types, only |
And these plugins are implemented incorrectly. |
Follow up of https://groups.google.com/forum/#!msg/jenkinsci-dev/-XVFCCiE4Bs
This fixed the issue mentioned on the mailing list, but does probably not work for all cases and might not fix JENKINS-26535 completely.