PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/eclipse-plugin/plugins/com.google.test.metric.eclipse.ui/src/main/java/com/google/test/metric/eclipse/ui/internal/compilation/TestabilityCompilationParticipant.java

http://testability-explorer.googlecode.com/
Java | 65 lines | 38 code | 7 blank | 20 comment | 2 complexity | 743c4b7ee1d0b1e7f43dfa315ec49b96 MD5 | raw file
 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 */
16package com.google.test.metric.eclipse.ui.internal.compilation;
17
18import com.google.test.metric.eclipse.internal.util.Logger;
19import com.google.test.metric.eclipse.internal.util.TestabilityConstants;
20import com.google.test.metric.eclipse.internal.util.TestabilityLaunchConfigurationHelper;
21
22import org.eclipse.core.runtime.CoreException;
23import org.eclipse.debug.core.ILaunch;
24import org.eclipse.debug.core.ILaunchConfiguration;
25import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
26import org.eclipse.jdt.core.IJavaProject;
27import org.eclipse.jdt.core.compiler.CompilationParticipant;
28
29/**
30 * Runs the testability explorer once compilation / build is finished.
31 * 
32 * @author shyamseshadri@google.com (Shyam Seshadri)
33 */
34public class TestabilityCompilationParticipant extends CompilationParticipant {
35
36  private Logger logger = new Logger();
37  private TestabilityLaunchConfigurationHelper configurationHelper =
38      new TestabilityLaunchConfigurationHelper();
39
40  public TestabilityCompilationParticipant() {
41  }
42
43  @Override
44  public boolean isActive(IJavaProject project) {
45    return configurationHelper.isExistingLaunchConfigurationWithRunOnBuild(
46        project.getElementName());
47  }
48
49  @Override
50  public void buildFinished(IJavaProject project) {
51    super.buildFinished(project);
52    ILaunchConfiguration launchConfiguration =
53        configurationHelper.getLaunchConfiguration(project.getElementName());
54    if (launchConfiguration != null) {
55      try {
56        ILaunchConfigurationWorkingCopy workingCopy = launchConfiguration.getWorkingCopy();
57        workingCopy.setAttribute(
58            TestabilityConstants.CONFIGURATION_ATTR_RUNNING_IN_COMPILATION_MODE, true);
59        ILaunch launch = workingCopy.launch(TestabilityConstants.TESTABILITY_MODE, null);
60      } catch (CoreException e) {
61        logger.logException(e);
62      }
63    }
64  }
65}