private static <T extends BuildWrapper> BuildWrapperItem<T> findItemWithBuildWrapper(final AbstractItem buildItem, Class<T> buildWrapperClass) { if (buildItem == null) { return null; } if (buildItem instanceof BuildableItemWithBuildWrappers) { BuildableItemWithBuildWrappers buildWrapper = (BuildableItemWithBuildWrappers) buildItem; DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappersList = buildWrapper.getBuildWrappersList(); if (buildWrappersList != null && !buildWrappersList.isEmpty()) { return new BuildWrapperItem<T>(buildWrappersList.get(buildWrapperClass), buildItem); } } if (buildItem.getParent() instanceof AbstractItem) { return findItemWithBuildWrapper((AbstractItem) buildItem.getParent(), buildWrapperClass); } return null; }