1.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGExecutionManager.java Mon Jan 02 17:02:55 2012 +0100
1.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGExecutionManager.java Mon Jan 02 21:24:09 2012 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 *
1.7 - * Copyright © 2009-2011 Oracle and/or its affiliates. All rights reserved.
1.8 + * Copyright © 2009-2012 Oracle and/or its affiliates. All rights reserved.
1.9 *
1.10 * The contents of this file are subject to the terms of either the GNU
1.11 * General Public License Version 2 only ("GPL") or the Common
1.12 @@ -39,11 +39,18 @@
1.13 package org.netbeans.modules.contrib.testng.output;
1.14
1.15 import java.io.File;
1.16 +import java.io.IOException;
1.17 import java.util.Properties;
1.18 import java.util.Set;
1.19 +import java.util.logging.Level;
1.20 +import java.util.logging.Logger;
1.21 import javax.swing.event.ChangeListener;
1.22 import org.apache.tools.ant.module.spi.AntSession;
1.23 import org.netbeans.api.project.Project;
1.24 +import org.netbeans.modules.contrib.testng.actions.TestConfigAccessor;
1.25 +import org.netbeans.modules.contrib.testng.api.TestNGSupport;
1.26 +import org.netbeans.modules.contrib.testng.spi.TestConfig;
1.27 +import org.netbeans.modules.contrib.testng.spi.TestNGSupportImplementation;
1.28 import org.netbeans.modules.gsf.testrunner.api.RerunHandler;
1.29 import org.netbeans.modules.gsf.testrunner.api.RerunType;
1.30 import org.netbeans.modules.gsf.testrunner.api.TestSession;
1.31 @@ -67,6 +74,8 @@
1.32 private TestSession testSession;
1.33 private Lookup lookup = Lookup.EMPTY;
1.34
1.35 + private static final Logger LOGGER = Logger.getLogger(TestNGExecutionManager.class.getName());
1.36 +
1.37 public TestNGExecutionManager(AntSession session, TestSession testSession, Properties props) {
1.38 this.testSession = testSession;
1.39 this.properties = props;
1.40 @@ -115,6 +124,7 @@
1.41 }
1.42 }
1.43 } catch (Exception e) {
1.44 + LOGGER.log(Level.SEVERE, null, e);
1.45 }
1.46 }
1.47
1.48 @@ -125,43 +135,59 @@
1.49 }
1.50
1.51 public void rerun(Set<Testcase> tests) {
1.52 - //not implemented yet
1.53 + Project p = testSession.getProject();
1.54 + TestNGSupportImplementation.TestExecutor exec = TestNGSupport.findTestNGSupport(p).createExecutor(p);
1.55 + TestConfig conf = TestConfigAccessor.getDefault().createTestConfig(p.getProjectDirectory(), true, null, null, null);
1.56 + try {
1.57 + exec.execute(TestNGSupport.Action.RUN_FAILED, conf);
1.58 + } catch (IOException ex) {
1.59 + LOGGER.log(Level.SEVERE, null, ex);
1.60 + }
1.61 }
1.62
1.63 public boolean enabled(RerunType type) {
1.64 switch (type){
1.65 - case ALL: return true;
1.66 - case CUSTOM: return false;
1.67 - default: return false;
1.68 + case ALL:
1.69 + return true;
1.70 + case CUSTOM:
1.71 + Project p = testSession.getProject();
1.72 + if (TestNGSupport.isActionSupported(TestNGSupport.Action.RUN_FAILED, p)) {
1.73 + return TestNGSupport.findTestNGSupport(p).createExecutor(p).hasFailedTests();
1.74 + }
1.75 + return false;
1.76 + default:
1.77 + return false;
1.78 }
1.79 }
1.80
1.81 - public boolean enabled() {
1.82 - if ((scriptFile == null) || (targets == null) || (targets.length == 0)) {
1.83 - return false;
1.84 - }
1.85 +// public boolean enabled() {
1.86 +// if ((scriptFile == null) || (targets == null) || (targets.length == 0)) {
1.87 +// return false;
1.88 +// }
1.89 +//
1.90 +// Project project = testSession.getProject();
1.91 +// ActionProvider actionProvider = project.getLookup().lookup(ActionProvider.class);
1.92 +// if (actionProvider != null) {
1.93 +// boolean runSupported = false;
1.94 +// for (String action : actionProvider.getSupportedActions()) {
1.95 +// if (action.equals(targets[0])) {
1.96 +// runSupported = true;
1.97 +// break;
1.98 +// }
1.99 +// }
1.100 +// if (runSupported && actionProvider.isActionEnabled(targets[0], lookup)) {
1.101 +// return true;
1.102 +// }
1.103 +// }
1.104 +//
1.105 +// return false;
1.106 +// }
1.107
1.108 - Project project = testSession.getProject();
1.109 - ActionProvider actionProvider = project.getLookup().lookup(ActionProvider.class);
1.110 - if (actionProvider != null) {
1.111 - boolean runSupported = false;
1.112 - for (String action : actionProvider.getSupportedActions()) {
1.113 - if (action.equals(targets[0])) {
1.114 - runSupported = true;
1.115 - break;
1.116 - }
1.117 - }
1.118 - if (runSupported && actionProvider.isActionEnabled(targets[0], lookup)) {
1.119 - return true;
1.120 - }
1.121 - }
1.122 -
1.123 - return false;
1.124 - }
1.125 -
1.126 + @Override
1.127 public void addChangeListener(ChangeListener listener) {
1.128 }
1.129
1.130 + @Override
1.131 public void removeChangeListener(ChangeListener listener) {
1.132 }
1.133 }