-
Notifications
You must be signed in to change notification settings - Fork 119
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-43507] Allow SCMSource and SCMNavigator subtypes to share common traits #103
Conversation
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
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.
A few little mistakes but basically sounds good.
pom.xml
Outdated
@@ -7,7 +7,7 @@ | |||
<relativePath /> | |||
</parent> | |||
<artifactId>mercurial</artifactId> | |||
<version>1.61-SNAPSHOT</version> | |||
<version>2.0-SNAPSHOT</version> |
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.
Why the outdentation?
result.setClean(clean()); | ||
result.setCredentialsId(credentialsId()); | ||
result.setInstallation(installation()); | ||
result.setDisableChangeLog(false); |
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.
Why? This is the default.
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.RestrictedSince; |
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.
Hmm, maybe this should be moved into access-restrictions-annotation
.
|
||
@DataBoundConstructor | ||
public MercurialSCMSource(String id, String installation, String source, String credentialsId, String branchPattern, String modules, String subdir, HgBrowser browser, boolean clean) { | ||
public MercurialSCMSource(String id, String source, String credentialsId) { |
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.
Even credentialsId
could be in a @DataBoundSetter
. null
is a legal value.
@Override | ||
public @Nonnull | ||
SCMSourceCriteria.Probe create(@Nonnull SCMHead branch, @Nullable final | ||
MercurialRevision revision) { |
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.
Do you have your IDE set to some ridiclously small fill column or something? This method header could all be on one line…
@DataBoundConstructor public CleanMercurialSCMSourceTrait() { } | ||
|
||
@Override protected <B extends SCMBuilder<B, S>, S extends SCM> void decorateBuilder(B builder) { | ||
((MercurialSCMBuilder<?>) builder).withClean(true); |
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.
Why the exotic typing of the method signature if we are going to wind up casting anyway?
@@ -0,0 +1,121 @@ | |||
/* | |||
* The MIT License |
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.
BTW license is present on some, but not all, newly added files.
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.
should be fixed now
/** | ||
* Exposes {@link HgBrowser} configuration of a {@link MercurialSCMSource} as a {@link SCMSourceTrait}. | ||
* | ||
* @since 3.4.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.
Huh?!
@Override public boolean isApplicableToBuilder(@Nonnull Class<? extends SCMBuilder> builderClass) { | ||
if (super.isApplicableToBuilder(builderClass) && MercurialSCMBuilder.class.isAssignableFrom(builderClass)) { | ||
for (MercurialInstallation i : MercurialInstallation.allInstallations()) { | ||
if (i.isUseCaches()) { |
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.
Well…if you have no installations set to useCaches
then you cannot use MercurialSCMSource
at all. So whenever this method is called, it should be returning true.
@@ -0,0 +1 @@ | |||
MercurialBrowserSCMSourceTrait.displayName=Configure Repository Browser |
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.
Not actually used.
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.
used now
test failures |
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.
Uncompilable.
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.
Some nits, and diff could have been made shorter, but overall looks good.
Please do not rebase commits again if you can help it.
pom.xml
Outdated
@@ -69,9 +70,23 @@ | |||
<url>https://repo.jenkins-ci.org/public/</url> | |||
</pluginRepository> | |||
</pluginRepositories> | |||
<dependencyManagement> |
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.
Why? We are already reusing the property. And in my experience, dependencyManagement
does not in fact work to align versions of artifacts with different classifiers.
<groupId>org.jenkins-ci.tools</groupId> | ||
<artifactId>maven-hpi-plugin</artifactId> | ||
<configuration> | ||
<compatibleSinceVersion>2.0</compatibleSinceVersion> |
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.
What specifically is incompatible? I will need to have a list for release notes. It seems like you are updating everything relevant in readResolve
so what am I missing?
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 the flag that the data format has changed and you cannot downgrade after upgrading without a backup
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.
Hmm, that is generally true of any plugin release. Certainly we do not routinely add this attribute. It adds a warning to the update center which will be alarming.
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.
Really... that is the stated purpose of the attribute and I use it every time there is a field migration... adding new fields is not a warning
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 oldest version of this plugin which the current version is configuration-compatible with
If we add new additional fields (the majority of the time changes in plugins are this category), on downgrade the new fields will be silently ignored
If we migrate fields - which is what we are doing here - then the old field will no longer be available after the job has been saved, which is exactly a break in configuration compatibility, which is why this is the marker in the sand
String source; | ||
|
||
public MercurialSCMBuilder(@Nonnull SCMHead head, @CheckForNull SCMRevision revision, String source, | ||
String credentialsId) { |
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.
Nullability—source
nonnull, credentialsId
OK?
return (B) this; | ||
} | ||
|
||
@SuppressWarnings("unchecked") public @Nonnull B withCredentialsId(String credentialsId) { |
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.
Wait then why include it in the constructor?
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.
because you are supposed to provide the default credentials in the constructor... then traits can decorate to switch to alternative credentials
return modules; | ||
@Deprecated @Restricted(DoNotUse.class) @RestrictedSince("2.0") public String getInstallation() { | ||
for (SCMSourceTrait t: traits) { | ||
if (t instanceof MercurialInstallationSCMSourceTrait) { |
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.
Would be useful to have a
<T extends SCMSourceTrait> public List<? extends T> getTraits(Class<T> type);
} | ||
|
||
public String getModules() { | ||
return modules; | ||
@Deprecated @Restricted(DoNotUse.class) @RestrictedSince("2.0") public String getInstallation() { |
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.
@Restricted
is unnecessary. @Deprecated
suffices.
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.
Restrictions let up use plugin version stats to guide removing old code. Depreciation does not force dependent plugins to update.
I am making the path to removing the compatibility methods easier to reach
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 deprecated methods need to remain for a couple years either way, and do little harm.
Launcher launcher = node.createLauncher(listener); | ||
StandardUsernameCredentials credentials = getCredentials(request.credentialsId()); | ||
final FilePath cache = Cache.fromURL(source, credentials, inst.getMasterCacheRoot()) | ||
.repositoryCache(inst, node, launcher, listener, true); |
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.
Did you somehow contrive to make this diff as long as possible? Would much rather see this diff hunk disappear, and the try
block simply not be indented.
@NonNull | ||
@Override | ||
protected List<Action> retrieveActions(@NonNull SCMHead head, | ||
@Override protected @Nonnull List<Action> retrieveActions(@NonNull SCMHead head, |
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.
Gratuitous diff hunk.
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.
aligning with annotation conventions... can remove but then I wouldn't be practicing why I preached ;-)
private boolean hasAccessToCredentialsMetadata(SCMSourceOwner owner){ | ||
if (owner == null){ | ||
private boolean hasAccessToCredentialsMetadata(SCMSourceOwner owner) { | ||
if (owner == null) { |
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.
Please stop wantonly reformatting source files!
return getTrait(CleanMercurialSCMSourceTrait.class) != null; | ||
} | ||
|
||
private @CheckForNull <T extends SCMSourceTrait> T getTrait(@Nonnull Class<T> traitClass) { |
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 am to take it that it is illegal to have multiple instances of the same trait class? I guess you are using the corresponding control mode in scm-api
?
@@ -0,0 +1 @@ | |||
Behaviours=Behaviors |
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.
you have got to be kidding me
return; | ||
} | ||
Launcher launcher = node.createLauncher(listener); | ||
StandardUsernameCredentials credentials = getCredentials(request.credentialsId()); |
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 regressed credentials handling: #108. Means that authenticated repository access is not being tested.
Downstream of jenkinsci/scm-api-plugin#36
See JENKINS-43507
@reviewbybees
Todo