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

[JENKINS-43507] Allow SCMSource and SCMNavigator subtypes to share common traits #103

Merged
merged 24 commits into from
Jun 27, 2017

Conversation

stephenc
Copy link
Member

@stephenc stephenc commented May 4, 2017

Downstream of jenkinsci/scm-api-plugin#36

See JENKINS-43507

@reviewbybees

Todo

  • Ensure that the trait implementations work correctly when BitBucket branch source picks up traits

@stephenc stephenc requested review from jglick and rsandell May 4, 2017 13:36
@stephenc
Copy link
Member Author

stephenc commented May 4, 2017

Screenshot the maximum bling new configuration (showing the shared traits for matching branch names)
screen shot 2017-05-04 at 14 33 43

@ghost
Copy link

ghost commented May 4, 2017

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.

Copy link
Member

@jglick jglick left a 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>
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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()) {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Not actually used.

Copy link
Member Author

Choose a reason for hiding this comment

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

used now

@jglick
Copy link
Member

jglick commented Jun 15, 2017

test failures

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Uncompilable.

Copy link
Member

@jglick jglick left a 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>
Copy link
Member

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>
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

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

https://github.com/jenkinsci/maven-hpi-plugin/blob/b3052ae8d3204b0f6630c94c4d7ed930443f6007/src/main/java/org/jenkinsci/maven/plugins/hpi/AbstractHpiMojo.java#L114-L117

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) {
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Member Author

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) {
Copy link
Member

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() {
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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);
Copy link
Member

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,
Copy link
Member

Choose a reason for hiding this comment

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

Gratuitous diff hunk.

Copy link
Member Author

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) {
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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

@stephenc stephenc merged commit bfc7cbd into jenkinsci:master Jun 27, 2017
@stephenc stephenc deleted the jenkins-43507 branch June 27, 2017 08:41
return;
}
Launcher launcher = node.createLauncher(listener);
StandardUsernameCredentials credentials = getCredentials(request.credentialsId());
Copy link
Member

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.

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.

2 participants