Know what beans can autowire from which extended class

I'm working on a new Build Feature, and I really need to get at which VCS Roots are attached to this build at the time the Build Feature is being added.

Let's say I have the below code...  How do I know, particularly from looking in the documentation, which classes I can wire into the constructor?

In this case I would like to be able to use SBuildType#getVcsRootInstances()  When I add SBuildType into this constructor I get an error like 

No qualifying bean of type [jetbrains.buildServer.serverSide.SBuildType] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
public class RequireProtectedBranchBuildFeature extends BuildFeature {

public RequireProtectedBranchBuildFeature(
@NotNull final RequireProtectedBranchBean featureBean,
@NotNull final PluginDescriptor descriptor,
@NotNull final ServerPaths serverPaths) {

// some construction...
}
4 comments
Comment actions Permalink

Side note, I probably worded some of that incorrectly.  Not a Java dev ; )

0
Comment actions Permalink

Hi Chuck,

unfortunately our documentation doesn't describe whether the class can be acquired as a dependency in a bean, sorry. You cannot get SBuildType as a dependency, but you can ask for ProjectManager (http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/ProjectManager.html) and find buildType by id (if you have one). 

Could you please describe what your build feature should do? Taking VCS roots from buildType in the moment when build feature is added doesn't sound right, because VCS roots can be changed in a future. Maybe there is a better way to do what you want.

0
Comment actions Permalink

The goal here is to enforce that the build is using a 'jetbrains.git' vcs root (only one) and that the branch being built is a Protected Branch.

On the server side, when the feature is being added, I just want to check that there is a github vcs or else throw that as an invalid parameter when trying to save the feature.

I also check the vcs on the agent side at AgentLifecycleAdapter:buildStarted() in case it changed, and at this time I actually check which branch is being built etc.

I don't have to check it on the server side I guess, but it would be nice that the feature tell you there is no github vcs as it requires one, or the feature will fail the build.

Hmm, not being able to tell what classes can be acquired as a dep seems to be one of the hardest parts about plugin development in the last few that I have done.

I appreciate the help and any advice on getting build vcs roots at the time a feature is added.  Thanks!

0
Comment actions Permalink

I think you can make all checks on the server. You can define a build feature and subscribe to the BuildServerListener.changesLoaded()[1] event to get notified when changes are collected for a build and its branch is known. In the event handler you can check VCS roots used in build, their revisions and branch of the build and you can add a build problem if some condition is met. You can use a commit-status-publisher plugin [2] as an example. It does a similar thing: it publishes a status of the commit to external systems. E.g. when build starts,the plugin publishes the 'started' status to github. 2 classes which might be interesting for you are: the build feature [3] and the listener [4]. Hope it helps.

[1] http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/BuildServerListener.html#changesLoaded(jetbrains.buildServer.serverSide.SRunningBuild)
[2] https://github.com/JetBrains/commit-status-publisher
[3] https://github.com/JetBrains/commit-status-publisher/blob/master/commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/CommitStatusPublisherFeature.java
[4] https://github.com/JetBrains/commit-status-publisher/blob/master/commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/CommitStatusPublisherListener.java#L39

0

Please sign in to leave a comment.