Add forced_traits as an option to Config.new#612
Add forced_traits as an option to Config.new#612marcheiligers wants to merge 2 commits intojruby:masterfrom
forced_traits as an option to Config.new#612Conversation
|
@kares @chadlwilson Can you take a look at this? I think we're due for a full refactoring of how we configure (and detect configuration) of the resulting war/jar file, but this might be a reasonable half-step to allow jarring up applications that would otherwise be detected as a rack-able war file. |
|
Thanks for the work here @marcheiligers ! I'm a bit concerned that by introducing Perhaps we should go through all the traits and see how to model that consistently to ensure it makes sense? warbler/lib/warbler/traits/nogemspec.rb Line 19 in 62bbd62 rack conflicts with rails warbler/lib/warbler/traits/rack.rb Line 15 in 0747bcf ...etc "Force" styleWith this approach, if I am correct, it seems you can forcibly enable a trait; e.g to resolve a conflict (executable jar vs war) but you cannot forcibly disable a trait which is otherwise detected but unwanted? For example, the use case at #587 (comment) where One could argue that with your approach we would just define a In other words, the challenge perhaps is not solely being able to deal with conflicts between traits where the detection is (arguably) indeterminate, but traits which you do not want to be detected at all? Would it be simpler to
Other thoughts
|
| # characteristics of the project that are either auto-detected or | ||
| # configured. | ||
| attr_accessor :traits | ||
| attr_reader :traits |
There was a problem hiding this comment.
Any idea why this attribute is also in the Traits super? Do we need to change both? (i'm not an expert with this particular Ruby magic)
Line 18 in cc3bce2
There was a problem hiding this comment.
I actually removed that other one in this PR, since the Traits module never uses it. Config includes Trait, and having both (previously attr_accessor :traits) doesn't do any harm, but is redundant.
I changed it to attr_reader so you cannot assign a new array of Traits in Config, but actually it doesn't prevent you from manipulating the existing array. This is a way that one could remove an unwanted Trait (config.traits.reject! { |t| t.is_a?(Warbler::Traits::Gemspec) }) but doing so does not remove the config changes that that Trait will already have made in before_configure. (I'm just thinking out loud here).
| @forced_traits = forced_traits | ||
| @traits = auto_detect_traits |
There was a problem hiding this comment.
Bit of a nitpick, but perhaps we don't need to store the forced_traits and can just pass them to auto_detect_traits for consideration, and continue to store only the "resolved" traits. Avoids the coupling ion the instance vars between calls and makes it a bit more obvious that auto_detect_traits is not solely auto detection - without have to rename the method and potentially breaking any overrides/monkey-patches.
There was a problem hiding this comment.
I did both during development 🤣. In the end I decided to assign it to an instance var in case it became useful to know what was forced later. I'm not married to it.
|
Thanks for the review, @chadlwilson
Agreed on the concern, but I needed a way to know that if you're forcing it to be a Jar, then it can't also be a War, which would've
The table below represents the current state. Italic Conflicts have not been introduced in this PR, but would seem to be the obvious ones that make sense.
Correct on not being able to remove an unwanted trait. Also, NoGemspec is not the opposite of Gemspec ... a (normal) Rails War has neither Gemspec nor NoGemspec traits. So, does Rails conflict with Gemspec and NoGemspec? This seems to indicate that it does, but I'm not sure. Forcing NoGemspec would probably work, but would result in a slightly different outcome than what they're doing now which has neither Trait. I'll have to experiment with this.
I had considered this and decided against it as it would require the end-user to know the full set of traits needed. For @headius' Sidekiq example, that would be
That would be neat, but I think these concerns are orthogonal. It
It's not bypassing prerequisites detection. It's just removing conflicts if you force a particular trait. The rest of the auto-detection still happens. Agreed on documentation (and failing fast) though.
|
Co-authored-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
|
I've been noodling on the #587 (comment) problem and how it relates to the issue @headius raised. The solution presented in this PR (forcing traits) does not solve the issue in the comment (rejecting a trait). A solution allowing for rejecting (or ignoring) Traits would solve the issue from the comment, but not the original issue (rejecting One solution that would work has been suggested above is that the The other option is that we provide a second argument I'll create a second PR to see what the "full list of Traits" solution looks like. |
|
Really? I haven't actually tried it yet, but I thought the way this worked for the specific case was by forcing trait x it causes it to reject all traits that are defined to conflict, which serves the need of opting out of war detection when you just want a regular jar and no servlet container? (I'll come back to the longer message in a bit) |
Implements #587