Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-43507] Need to be better able to filter descriptors based on…
… capabilities
  • Loading branch information
stephenc committed May 5, 2017
1 parent 7a39ba7 commit 5333774
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 43 deletions.
Expand Up @@ -56,14 +56,23 @@ protected SCMNavigatorTraitDescriptor() {
super();
}

/**
* Returns the type of {@link SCMSourceBuilder} that this {@link SCMNavigatorTrait} is applicable to.
*
* @return the type of {@link SCMSourceBuilder} that this {@link SCMNavigatorTrait} is applicable to.
*/
public Class<? extends SCMSourceBuilder> getBuilderClass() {
return SCMSourceBuilder.class;
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified type of {@link SCMSourceBuilder}.
*
* @param builderClass the type of {@link SCMBuilder}.
* @return {@code true} if applicable to the specified type of {@link SCMSourceBuilder}.
*/
public boolean isApplicableToBuilder(@NonNull Class<? extends SCMSourceBuilder> builderClass) {
return true;
return getBuilderClass().isAssignableFrom(builderClass);
}

/**
Expand All @@ -76,14 +85,23 @@ public boolean isApplicableToBuilder(@NonNull SCMSourceBuilder<?, ?> builder) {
return isApplicableToBuilder(builder.getClass()) && isApplicableToSource(builder.sourceClass());
}

/**
* Returns the type of {@link SCMNavigatorContext} that this {@link SCMNavigatorTrait} is applicable to.
*
* @return the type of {@link SCMNavigatorContext} that this {@link SCMNavigatorTrait} is applicable to.
*/
public Class<? extends SCMNavigatorContext> getContextClass() {
return SCMNavigatorContext.class;
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified type of {@link SCMNavigatorContext}.
*
* @param contextClass the type of {@link SCMSourceContext}.
* @return {@code true} if applicable to the specified type of {@link SCMSourceContext}.
*/
public boolean isApplicableToContext(@NonNull Class<? extends SCMNavigatorContext> contextClass) {
return true;
return getContextClass().isAssignableFrom(contextClass);
}

/**
Expand All @@ -97,13 +115,22 @@ public boolean isApplicableToContext(@NonNull SCMNavigatorContext context) {
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified {@link SCMSource}.
* Returns the type of {@link SCMSource} that this {@link SCMNavigatorTrait} is applicable to.
*
* @param source the {@link SCMSource}.
* @return {@code true} if applicable to the specified {@link SCMSource}.
* @return the type of {@link SCMSource} that this {@link SCMNavigatorTrait} is applicable to.
*/
public boolean isApplicableToSource(@NonNull SCMSource source) {
return isApplicableToSource(source.getDescriptor());
public Class<? extends SCMSource> getSourceClass() {
return SCMSource.class;
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified type of {@link SCMSource}.
*
* @param sourceClass the type of {@link SCMSource}.
* @return {@code true} if applicable to the specified type of {@link SCMSource}.
*/
public boolean isApplicableToSource(@NonNull Class<? extends SCMSource> sourceClass) {
return getSourceClass().isAssignableFrom(sourceClass);
}

/**
Expand All @@ -117,23 +144,32 @@ public boolean isApplicableToSource(@NonNull SCMSourceDescriptor descriptor) {
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified type of {@link SCMSource}.
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified {@link SCMSource}.
*
* @param sourceClass the type of {@link SCMSource}.
* @return {@code true} if applicable to the specified type of {@link SCMSource}.
* @param source the {@link SCMSource}.
* @return {@code true} if applicable to the specified {@link SCMSource}.
*/
public boolean isApplicableToSource(@NonNull Class<? extends SCMSource> sourceClass) {
return true;
public boolean isApplicableToSource(@NonNull SCMSource source) {
return isApplicableToSource(source.getDescriptor());
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified {@link SCMNavigator}.
* Returns the type of {@link SCMNavigator} that this {@link SCMNavigatorTrait} is applicable to.
*
* @param navigator the {@link SCMNavigator}.
* @return {@code true} if applicable to the specified {@link SCMNavigator}.
* @return the type of {@link SCMNavigator} that this {@link SCMNavigatorTrait} is applicable to.
*/
public boolean isApplicableTo(@NonNull SCMNavigator navigator) {
return isApplicableTo(navigator.getDescriptor());
public Class<? extends SCMNavigator> getNavigatorClass() {
return SCMNavigator.class;
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified type of {@link SCMNavigator}.
*
* @param navigatorClass the type of {@link SCMNavigator}.
* @return {@code true} if applicable to the specified type of {@link SCMNavigator}.
*/
public boolean isApplicableTo(@NonNull Class<? extends SCMNavigator> navigatorClass) {
return getNavigatorClass().isAssignableFrom(navigatorClass);
}

/**
Expand All @@ -147,13 +183,13 @@ public boolean isApplicableTo(@NonNull SCMNavigatorDescriptor descriptor) {
}

/**
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified type of {@link SCMNavigator}.
* Checks if the {@link SCMNavigatorTrait} is relevant to the specified {@link SCMNavigator}.
*
* @param navigatorClass the type of {@link SCMNavigator}.
* @return {@code true} if applicable to the specified type of {@link SCMNavigator}.
* @param navigator the {@link SCMNavigator}.
* @return {@code true} if applicable to the specified {@link SCMNavigator}.
*/
public boolean isApplicableTo(@NonNull Class<? extends SCMNavigator> navigatorClass) {
return true;
public boolean isApplicableTo(@NonNull SCMNavigator navigator) {
return isApplicableTo(navigator.getDescriptor());
}

}
51 changes: 39 additions & 12 deletions src/main/java/jenkins/scm/api/trait/SCMSourceTraitDescriptor.java
Expand Up @@ -54,14 +54,23 @@ protected SCMSourceTraitDescriptor() {
super();
}

/**
* Returns the type of {@link SCMBuilder} that this {@link SCMSourceTrait} is applicable to.
*
* @return the type of {@link SCMBuilder} that this {@link SCMSourceTrait} is applicable to.
*/
public Class<? extends SCMBuilder> getBuilderClass() {
return SCMBuilder.class;
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified type of {@link SCMBuilder}.
*
* @param builderClass the type of {@link SCMBuilder}.
* @return {@code true} if applicable to the specified type of {@link SCMBuilder}.
*/
public boolean isApplicableToBuilder(@NonNull Class<? extends SCMBuilder> builderClass) {
return true;
return getBuilderClass().isAssignableFrom(builderClass);
}

/**
Expand All @@ -74,14 +83,23 @@ public boolean isApplicableToBuilder(@NonNull SCMBuilder<?, ?> builder) {
return isApplicableToBuilder(builder.getClass()) && isApplicableToSCM(builder.scmClass());
}

/**
* Returns the type of {@link SCMSourceContext} that this {@link SCMSourceTrait} is applicable to.
*
* @return the type of {@link SCMSourceContext} that this {@link SCMSourceTrait} is applicable to.
*/
public Class<? extends SCMSourceContext> getContextClass() {
return SCMSourceContext.class;
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified type of {@link SCMSourceContext}.
*
* @param contextClass the type of {@link SCMSourceContext}.
* @return {@code true} if applicable to the specified type of {@link SCMSourceContext}.
*/
public boolean isApplicableToContext(@NonNull Class<? extends SCMSourceContext> contextClass) {
return true;
return getContextClass().isAssignableFrom(contextClass);
}

/**
Expand All @@ -95,13 +113,22 @@ public boolean isApplicableToContext(@NonNull SCMSourceContext context) {
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified {@link SCMSource}.
* Returns the type of {@link SCMSource} that this {@link SCMSourceTrait} is applicable to.
*
* @param source the {@link SCMSource}.
* @return {@code true} if applicable to the specified {@link SCMSource}.
* @return the type of {@link SCMSource} that this {@link SCMSourceTrait} is applicable to.
*/
public boolean isApplicableTo(@NonNull SCMSource source) {
return isApplicableTo(source.getDescriptor());
public Class<? extends SCMSource> getSourceClass() {
return SCMSource.class;
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified type of {@link SCMSource}.
*
* @param sourceClass the type of {@link SCMSource}.
* @return {@code true} if applicable to the specified type of {@link SCMSource}.
*/
public boolean isApplicableTo(@NonNull Class<? extends SCMSource> sourceClass) {
return getSourceClass().isAssignableFrom(sourceClass);
}

/**
Expand All @@ -115,13 +142,13 @@ public boolean isApplicableTo(@NonNull SCMSourceDescriptor descriptor) {
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified type of {@link SCMSource}.
* Checks if the {@link SCMSourceTrait} is relevant to the specified {@link SCMSource}.
*
* @param sourceClass the type of {@link SCMSource}.
* @return {@code true} if applicable to the specified type of {@link SCMSource}.
* @param source the {@link SCMSource}.
* @return {@code true} if applicable to the specified {@link SCMSource}.
*/
public boolean isApplicableTo(@NonNull Class<? extends SCMSource> sourceClass) {
return true;
public boolean isApplicableTo(@NonNull SCMSource source) {
return isApplicableTo(source.getDescriptor());
}

}
27 changes: 18 additions & 9 deletions src/main/java/jenkins/scm/api/trait/SCMTraitDescriptor.java
Expand Up @@ -57,23 +57,32 @@ public abstract class SCMTraitDescriptor<T extends SCMTrait<T>> extends Descript
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified {@link SCM}.
* Returns the type of {@link SCM} that this {@link SCMTrait} is applicable to.
*
* @param scm the {@link SCMDescriptor} for the type of {@link SCM}.
* @return {@code true} if applicable to the specified type of {@link SCM}.
* @return the type of {@link SCM} that this {@link SCMTrait} is applicable to.
*/
public boolean isApplicableToSCM(@NonNull SCMDescriptor<?> scm) {
return isApplicableToSCM(scm.getT());
public Class<? extends SCM> getScmClass() {
return SCM.class;
}

/**
* Checks if the {@link SCMSourceTrait} is relevant to the specified type of {@link SCMBuilder}.
* Checks if the {@link SCMTrait} is relevant to the specified type of {@link SCM}.
*
* @param scmClass the type of {@link SCMBuilder}.
* @return {@code true} if applicable to the specified type of {@link SCMBuilder}.
* @param scmClass the type of {@link SCM}.
* @return {@code true} if applicable to the specified type of {@link SCM}.
*/
public boolean isApplicableToSCM(@NonNull Class<? extends SCM> scmClass) {
return true;
return getScmClass().isAssignableFrom(scmClass);
}

/**
* Checks if the {@link SCMTrait} is relevant to the specified {@link SCM}.
*
* @param scm the {@link SCMDescriptor} for the type of {@link SCM}.
* @return {@code true} if applicable to the specified type of {@link SCM}.
*/
public boolean isApplicableToSCM(@NonNull SCMDescriptor<?> scm) {
return isApplicableToSCM(scm.getT());
}

}

0 comments on commit 5333774

Please sign in to comment.