PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/bamboo/plugin/dotnet/ncover/NCoverBuildWebItemCondition.java

https://bitbucket.org/atlassian/bamboo-dotnet-plugin/
Java | 65 lines | 38 code | 14 blank | 13 comment | 7 complexity | 11e33e375ba76709a8bec66adb28cfed MD5 | raw file
Possible License(s): BSD-3-Clause
  1. package com.atlassian.bamboo.plugin.dotnet.ncover;
  2. import com.atlassian.bamboo.plan.PlanKeys;
  3. import com.atlassian.bamboo.plan.cache.CachedPlanManager;
  4. import com.atlassian.bamboo.plan.cache.ImmutableBuildable;
  5. import com.atlassian.plugin.PluginParseException;
  6. import com.atlassian.plugin.web.Condition;
  7. import org.apache.commons.lang3.StringUtils;
  8. import java.util.Map;
  9. /**
  10. * Contains logic to control whether a 'NCover' tab is displayed on the Build
  11. * results page.
  12. *
  13. * @author Ross Rowe
  14. *
  15. */
  16. public class NCoverBuildWebItemCondition implements Condition {
  17. @Override
  18. public void init(Map map) throws PluginParseException {
  19. }
  20. public void setCachedPlanManager(CachedPlanManager cachedPlanManager) {
  21. this.cachedPlanManager = cachedPlanManager;
  22. }
  23. private CachedPlanManager cachedPlanManager;
  24. /**
  25. * Only display the NCover tab item if the appropriate configuration
  26. * settings have been set.
  27. *
  28. * @return boolean indicating whether NCover tab item should be displayed
  29. */
  30. @Override
  31. public boolean shouldDisplay(Map context) {
  32. String buildKey = (String) context.get(NCoverBuildProcessor.BUILD_KEY);
  33. if (buildKey == null)
  34. {
  35. return false;
  36. }
  37. ImmutableBuildable build = cachedPlanManager.getPlanByKeyIfOfType(PlanKeys.getPlanKey(buildKey), ImmutableBuildable.class);
  38. if (build != null)
  39. {
  40. Map<String, String> customConfiguration = build.getBuildDefinition().getCustomConfiguration();
  41. if (customConfiguration != null)
  42. {
  43. if (StringUtils.isNotEmpty(customConfiguration.get(NCoverBuildProcessor.NCOVER_EXISTS)))
  44. {
  45. return true;
  46. }
  47. }
  48. }
  49. return false;
  50. }
  51. }