PageRenderTime 35ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/eclipse-plugin/plugins/com.google.test.metric.eclipse.core/src/main/java/com/google/test/metric/eclipse/internal/util/TestabilityLaunchConfigurationHelper.java

http://testability-explorer.googlecode.com/
Java | 94 lines | 69 code | 5 blank | 20 comment | 10 complexity | 2ecc9dbe237760018bc13c4944deccc8 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright 2009 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.test.metric.eclipse.internal.util;
  17. import org.eclipse.core.runtime.CoreException;
  18. import org.eclipse.debug.core.DebugPlugin;
  19. import org.eclipse.debug.core.ILaunchConfiguration;
  20. import org.eclipse.debug.core.ILaunchConfigurationType;
  21. import org.eclipse.debug.core.ILaunchManager;
  22. /**
  23. * Helper methods relevant to {@link ILaunchConfiguration} for testability.
  24. *
  25. * @author shyamseshadri@google.com (Shyam Seshadri)
  26. */
  27. public class TestabilityLaunchConfigurationHelper {
  28. private Logger logger = new Logger();
  29. public ILaunchConfiguration getLaunchConfiguration(String projectName) {
  30. try {
  31. ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  32. ILaunchConfigurationType type = launchManager
  33. .getLaunchConfigurationType(TestabilityConstants.TESTABILITY_LAUNCH_CONFIGURATION_TYPE);
  34. ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(type);
  35. for (ILaunchConfiguration launchConfiguration : launchConfigurations) {
  36. String configProjectName =
  37. launchConfiguration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_PROJECT_NAME,
  38. "");
  39. if (configProjectName.equals(projectName)
  40. && isValidToRun(projectName, launchConfiguration)) {
  41. return launchConfiguration;
  42. }
  43. }
  44. } catch (CoreException e) {
  45. logger.logException(e);
  46. }
  47. return null;
  48. }
  49. public boolean isExistingLaunchConfigWithRunOnBuildOtherThanCurrent(
  50. String projectName, String launchConfigName) {
  51. try {
  52. ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  53. ILaunchConfigurationType type = launchManager
  54. .getLaunchConfigurationType(TestabilityConstants.TESTABILITY_LAUNCH_CONFIGURATION_TYPE);
  55. ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(type);
  56. for (ILaunchConfiguration launchConfiguration : launchConfigurations) {
  57. String configProjectName =
  58. launchConfiguration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_PROJECT_NAME,
  59. "");
  60. boolean runOnEveryBuild =
  61. launchConfiguration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_RUN_ON_BUILD,
  62. false);
  63. String configName = launchConfiguration.getName();
  64. boolean isProjectNameEqual = configProjectName.equals(projectName);
  65. boolean isLaunchConfigNameEqual = launchConfigName.equals(configName);
  66. if (isProjectNameEqual && runOnEveryBuild && !isLaunchConfigNameEqual) {
  67. return true;
  68. }
  69. }
  70. } catch (CoreException e) {
  71. logger.logException(e);
  72. }
  73. return false;
  74. }
  75. public boolean isExistingLaunchConfigurationWithRunOnBuild(String projectName) {
  76. return getLaunchConfiguration(projectName) != null;
  77. }
  78. private boolean isValidToRun(String projectName, ILaunchConfiguration launchConfiguration) throws CoreException {
  79. boolean runOnEveryBuild =
  80. launchConfiguration.getAttribute(TestabilityConstants.CONFIGURATION_ATTR_RUN_ON_BUILD,
  81. false);
  82. if (runOnEveryBuild
  83. && !isExistingLaunchConfigWithRunOnBuildOtherThanCurrent(projectName,
  84. launchConfiguration.getName())) {
  85. return true;
  86. }
  87. return false;
  88. }
  89. }