diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java
index d8624381da6..b39125f4c33 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.debug;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager;
import static org.junit.Assert.assertNotNull;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java
index a648b17af79..a1e089e7a81 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.debug;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/StackTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/StackTests.java
index 89ae97599c0..9e61cbbba42 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/StackTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/StackTests.java
@@ -14,6 +14,7 @@
package org.eclipse.ant.tests.ui.debug;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
import org.eclipse.ant.internal.launching.debug.model.AntThread;
import org.eclipse.core.resources.IFile;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/AntEditorTests.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/AntEditorTests.java
index 0aaf216162f..8a042ad86ae 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/AntEditorTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/AntEditorTests.java
@@ -14,6 +14,7 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.editor;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/CodeCompletionTest.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/CodeCompletionTest.java
index 96bd789c9b9..a7f4ba9d962 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/CodeCompletionTest.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/CodeCompletionTest.java
@@ -20,6 +20,8 @@
import static java.util.function.Function.identity;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/OccurrencesFinderTests.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/OccurrencesFinderTests.java
index 8711efd63f7..ff2db995077 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/OccurrencesFinderTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/OccurrencesFinderTests.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.editor;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getIFile;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlDocumentFormatterTest.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlDocumentFormatterTest.java
index c72fe0dc22c..736ff966792 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlDocumentFormatterTest.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlDocumentFormatterTest.java
@@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.editor.formatter;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getReaderContentAsString;
import static org.junit.Assert.assertEquals;
import java.nio.file.Files;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java
index 979c5a3cf40..18b699ee305 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java
@@ -15,8 +15,6 @@
package org.eclipse.ant.tests.ui;
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.console.IHyperlink;
import org.junit.Rule;
public abstract class AbstractAntUIBuildTest extends AbstractAntUITest {
@@ -24,8 +22,4 @@ public abstract class AbstractAntUIBuildTest extends AbstractAntUITest {
@Rule
public RunInSeparateThreadRule runInSeparateThread = new RunInSeparateThreadRule();
- protected void activateLink(final IHyperlink link) {
- Display.getDefault().asyncExec(() -> link.linkActivated());
- }
-
}
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java
index 0871c5be535..686ad962938 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java
@@ -15,6 +15,7 @@
package org.eclipse.ant.tests.ui;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntViewTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntViewTests.java
index 21c82299bde..38341206357 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntViewTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntViewTests.java
@@ -17,7 +17,9 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
@@ -25,6 +27,7 @@
import org.eclipse.ant.internal.ui.preferences.FileFilter;
import org.eclipse.ant.internal.ui.views.actions.AddBuildFilesAction;
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
@@ -108,4 +111,54 @@ boolean canAccept(String extn) {
}
}
+ /**
+ * This is to help in increasing the test coverage by enabling access to fields
+ * and execution of methods irrespective of their Java language access
+ * permissions.
+ *
+ * More accessor methods can be added to this on a need basis
+ */
+ private static abstract class TypeProxy {
+
+ Object master = null;
+
+ protected TypeProxy(Object obj) {
+ master = obj;
+ }
+
+ /**
+ * Gets the method with the given method name and argument types.
+ *
+ * @param methodName the method name
+ * @param types the argument types
+ * @return the method
+ */
+ protected Method get(String methodName, Class>[] types) {
+ Method method = null;
+ try {
+ method = master.getClass().getDeclaredMethod(methodName, types);
+ } catch (SecurityException | NoSuchMethodException e) {
+ fail();
+ }
+ Assert.isNotNull(method);
+ method.setAccessible(true);
+ return method;
+ }
+
+ /**
+ * Invokes the given method with the given arguments.
+ *
+ * @param method the given method
+ * @param arguments the method arguments
+ * @return the method return value
+ */
+ protected Object invoke(Method method, Object[] arguments) {
+ try {
+ return method.invoke(master, arguments);
+ } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
+ fail();
+ }
+ return null;
+ }
+ }
}
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java
index 561dafa9deb..33d68422bb8 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java
@@ -14,8 +14,13 @@
package org.eclipse.ant.tests.ui;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.activateLink;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getColorAtOffset;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getHyperlink;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launch;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java
index 527b039e0af..e45d14937e9 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java
@@ -14,9 +14,13 @@
package org.eclipse.ant.tests.ui.separateVM;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.activateLink;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getColorAtOffset;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getHyperlink;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getJavaProject;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launch;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -36,7 +40,6 @@
import org.eclipse.ant.launching.IAntLaunchConstants;
import org.eclipse.ant.tests.ui.AbstractAntUIBuildTest;
import org.eclipse.ant.tests.ui.debug.TestAgainException;
-import org.eclipse.ant.tests.ui.testplugin.AntUITestUtil;
import org.eclipse.ant.tests.ui.testplugin.ConsoleLineTracker;
import org.eclipse.ant.tests.ui.testplugin.ProjectHelper;
import org.eclipse.core.resources.IFile;
@@ -311,7 +314,7 @@ public void testFailInputHandler() throws CoreException {
assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config); //$NON-NLS-1$ //$NON-NLS-2$
ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
copy.setAttribute(IAntUIConstants.SET_INPUTHANDLER, false);
- AntUITestUtil.launch(copy);
+ launch(copy);
String message = ConsoleLineTracker.getMessage(1);
assertNotNull("There must be a message", message); //$NON-NLS-1$
assertTrue("Incorrect message. Should start with Message:. Message: " + message, message.startsWith("echo1")); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java b/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java
index 83b4af606ea..baf1e1e8264 100644
--- a/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java
+++ b/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.externaltools;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject;
import static org.junit.Assert.assertFalse;
@@ -384,7 +385,8 @@ public void testConfigureTriggers10() throws Exception {
*/
@Test
public void testIsUnmigratedConfig1() throws Exception {
- ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE);
+ ILaunchConfigurationType type = getLaunchManager()
+ .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE);
if (type != null) {
ILaunchConfigurationWorkingCopy config = type.newInstance(BuilderCoreUtils.getBuilderFolder(getProject(), true), "testIsUnmigratedConfig1"); //$NON-NLS-1$
assertTrue("should be considered 'unmigrated'", BuilderCoreUtils.isUnmigratedConfig(config)); //$NON-NLS-1$
diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java
index 1d7c6723a40..3ad95a4c4b0 100644
--- a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java
+++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java
@@ -14,47 +14,23 @@
package org.eclipse.ant.tests.ui.testplugin;
import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.assertProject;
-import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration;
-import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getBuildFile;
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.nio.file.Files;
-import org.eclipse.ant.internal.ui.AntUIPlugin;
import org.eclipse.ant.internal.ui.model.AntModel;
import org.eclipse.ant.tests.ui.editor.support.TestLocationProvider;
import org.eclipse.ant.tests.ui.editor.support.TestProblemRequestor;
-import org.eclipse.core.externaltools.internal.IExternalToolConstants;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.ui.console.IHyperlink;
-import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition;
-import org.eclipse.ui.internal.console.IOConsolePartition;
import org.junit.Before;
import org.junit.Rule;
/**
* Abstract Ant UI test class
*/
-@SuppressWarnings("restriction")
public abstract class AbstractAntUITest {
public static final String ANT_EDITOR_ID = "org.eclipse.ant.ui.internal.editor.AntEditor"; //$NON-NLS-1$
@@ -64,26 +40,6 @@ public abstract class AbstractAntUITest {
@Rule
public TestAgainExceptionRule testAgainRule = new TestAgainExceptionRule(5);
- /**
- * Returns the {@link IFile} for the given build file name
- *
- * @return the associated {@link IFile} for the given build file name
- */
- protected IFile getIFile(String buildFileName) {
- return AntUITestUtil.getProject().getFolder("buildfiles").getFile(buildFileName); //$NON-NLS-1$
- }
-
- /**
- * Returns the {@link File} for the given build file name
- *
- * @return the {@link File} for the given build file name
- */
- protected File getBuildFile(String buildFileName) {
- IFile file = getIFile(buildFileName);
- assertTrue("Could not find build file named: " + buildFileName, file.exists()); //$NON-NLS-1$
- return file.getLocation().toFile();
- }
-
@Before
public void setUp() throws Exception {
assertProject();
@@ -105,32 +61,6 @@ protected IDocument getDocument(String fileName) {
}
}
- /**
- * Returns the contents of the given {@link BufferedReader} as a {@link String}
- *
- * @return the contents of the given {@link BufferedReader} as a {@link String}
- */
- protected String getReaderContentAsString(BufferedReader bufferedReader) {
- StringBuilder result = new StringBuilder();
- try {
- String line = bufferedReader.readLine();
-
- while (line != null) {
- if (result.length() != 0) {
- result.append(System.lineSeparator());
- }
- result.append(line);
- line = bufferedReader.readLine();
- }
- }
- catch (IOException e) {
- AntUIPlugin.log(e);
- return null;
- }
-
- return result.toString();
- }
-
/**
* Returns the {@link AntModel} for the given file name
*
@@ -138,7 +68,8 @@ protected String getReaderContentAsString(BufferedReader bufferedReader) {
*/
protected AntModel getAntModel(String fileName) {
currentDocument = getDocument(fileName);
- AntModel model = new AntModel(currentDocument, new TestProblemRequestor(), new TestLocationProvider(getBuildFile(fileName)));
+ AntModel model = new AntModel(currentDocument, new TestProblemRequestor(),
+ new TestLocationProvider(getBuildFile(fileName)));
model.reconcile();
return model;
}
@@ -157,132 +88,5 @@ public void setCurrentDocument(IDocument currentDocument) {
this.currentDocument = currentDocument;
}
- /**
- * Launches the Ant build with the build file name (no extension).
- *
- * @param buildFileName
- * the ant build file name
- */
- protected void launch(String buildFileName) throws CoreException {
- ILaunchConfiguration config = getLaunchConfiguration(buildFileName);
- assertNotNull("Could not locate launch configuration for " + buildFileName, config); //$NON-NLS-1$
- launchAndTerminate(config, 20000);
- }
-
- /**
- * Launches the Ant build with the build file name (no extension).
- *
- * @param buildFileName
- * the build file
- * @param arguments
- * the ant arguments
- */
- protected void launch(String buildFileName, String arguments) throws CoreException {
- ILaunchConfiguration config = getLaunchConfiguration(buildFileName);
- assertNotNull("Could not locate launch configuration for " + buildFileName, config); //$NON-NLS-1$
- ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
- copy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
- launchAndTerminate(copy, 20000);
- }
-
- /**
- * Returns the {@link IHyperlink} at the given offset on the given document, or null if there is no {@link IHyperlink} at that offset
- * on the document.
- *
- * @return the {@link IHyperlink} at the given offset on the given document or null
- */
- protected IHyperlink getHyperlink(int offset, IDocument doc) {
- if (offset >= 0 && doc != null) {
- Position[] positions = null;
- try {
- positions = doc.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY);
- }
- catch (BadPositionCategoryException ex) {
- // no links have been added
- return null;
- }
- for (Position position : positions) {
- if (offset >= position.getOffset() && offset <= (position.getOffset() + position.getLength())) {
- return ((ConsoleHyperlinkPosition) position).getHyperLink();
- }
- }
- }
- return null;
- }
- /**
- * Returns the {@link Color} at the given offset on the given document, or null if there is no {@link Color} at that offset on the
- * document.
- *
- * @return the {@link Color} at the given offset on the given document or null
- */
- protected Color getColorAtOffset(int offset, IDocument document) throws BadLocationException {
- if (document != null) {
- IDocumentPartitioner partitioner = document.getDocumentPartitioner();
- if (partitioner != null) {
- ITypedRegion[] regions = partitioner.computePartitioning(offset, document.getLineInformationOfOffset(offset).getLength());
- if (regions.length > 0) {
- IOConsolePartition partition = (IOConsolePartition) regions[0];
- return partition.getColor();
- }
- }
- }
- return null;
- }
-
- /**
- * This is to help in increasing the test coverage by enabling access to fields and execution of methods irrespective of their Java language
- * access permissions.
- *
- * More accessor methods can be added to this on a need basis
- */
- protected static abstract class TypeProxy {
-
- Object master = null;
-
- protected TypeProxy(Object obj) {
- master = obj;
- }
-
- /**
- * Gets the method with the given method name and argument types.
- *
- * @param methodName
- * the method name
- * @param types
- * the argument types
- * @return the method
- */
- protected Method get(String methodName, Class>[] types) {
- Method method = null;
- try {
- method = master.getClass().getDeclaredMethod(methodName, types);
- }
- catch (SecurityException | NoSuchMethodException e) {
- fail();
- }
- Assert.isNotNull(method);
- method.setAccessible(true);
- return method;
- }
-
- /**
- * Invokes the given method with the given arguments.
- *
- * @param method
- * the given method
- * @param arguments
- * the method arguments
- * @return the method return value
- */
- protected Object invoke(Method method, Object[] arguments) {
- try {
- return method.invoke(master, arguments);
- }
- catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
- fail();
- }
- return null;
- }
- }
}
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java
index 7daa8207324..4064260f7fb 100644
--- a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java
+++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java
@@ -10,8 +10,10 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.testplugin;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -19,6 +21,7 @@
import org.eclipse.ant.internal.ui.AntUIPlugin;
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
import org.eclipse.ant.tests.ui.debug.TestAgainException;
+import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -30,10 +33,22 @@
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.Position;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.console.IHyperlink;
+import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition;
+import org.eclipse.ui.internal.console.IOConsolePartition;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
@@ -193,4 +208,131 @@ public static ILaunchManager getLaunchManager() {
public static IProject getProject() {
return ResourcesPlugin.getWorkspace().getRoot().getProject(ProjectHelper.PROJECT_NAME);
}
+
+ /**
+ * Launches the Ant build with the build file name (no extension).
+ *
+ * @param buildFileName
+ * the build file
+ * @param arguments
+ * the ant arguments
+ */
+ public static void launch(String buildFileName, String arguments) throws CoreException {
+ ILaunchConfiguration config = getLaunchConfiguration(buildFileName);
+ assertNotNull("Could not locate launch configuration for " + buildFileName, config); //$NON-NLS-1$
+ ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
+ copy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
+ launchAndTerminate(copy, 20000);
+ }
+
+ /**
+ * Launches the Ant build with the build file name (no extension).
+ *
+ * @param buildFileName
+ * the ant build file name
+ */
+ public static void launch(String buildFileName) throws CoreException {
+ ILaunchConfiguration config = getLaunchConfiguration(buildFileName);
+ assertNotNull("Could not locate launch configuration for " + buildFileName, config); //$NON-NLS-1$
+ launchAndTerminate(config, 20000);
+ }
+
+ /**
+ * Returns the {@link IFile} for the given build file name
+ *
+ * @return the associated {@link IFile} for the given build file name
+ */
+ public static IFile getIFile(String buildFileName) {
+ return getProject().getFolder("buildfiles").getFile(buildFileName); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the {@link File} for the given build file name
+ *
+ * @return the {@link File} for the given build file name
+ */
+ public static File getBuildFile(String buildFileName) {
+ IFile file = getIFile(buildFileName);
+ assertTrue("Could not find build file named: " + buildFileName, file.exists()); //$NON-NLS-1$
+ return file.getLocation().toFile();
+ }
+
+ /**
+ * Returns the contents of the given {@link BufferedReader} as a {@link String}
+ *
+ * @return the contents of the given {@link BufferedReader} as a {@link String}
+ */
+ public static String getReaderContentAsString(BufferedReader bufferedReader) {
+ StringBuilder result = new StringBuilder();
+ try {
+ String line = bufferedReader.readLine();
+
+ while (line != null) {
+ if (result.length() != 0) {
+ result.append(System.lineSeparator());
+ }
+ result.append(line);
+ line = bufferedReader.readLine();
+ }
+ }
+ catch (IOException e) {
+ AntUIPlugin.log(e);
+ return null;
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Returns the {@link Color} at the given offset on the given document, or
+ * null if there is no {@link Color} at that offset on the
+ * document.
+ *
+ * @return the {@link Color} at the given offset on the given document or
+ * null
+ */
+ public static Color getColorAtOffset(int offset, IDocument document) throws BadLocationException {
+ if (document != null) {
+ IDocumentPartitioner partitioner = document.getDocumentPartitioner();
+ if (partitioner != null) {
+ ITypedRegion[] regions = partitioner.computePartitioning(offset,
+ document.getLineInformationOfOffset(offset).getLength());
+ if (regions.length > 0) {
+ IOConsolePartition partition = (IOConsolePartition) regions[0];
+ return partition.getColor();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the {@link IHyperlink} at the given offset on the given document, or
+ * null if there is no {@link IHyperlink} at that offset on the
+ * document.
+ *
+ * @return the {@link IHyperlink} at the given offset on the given document or
+ * null
+ */
+ public static IHyperlink getHyperlink(int offset, IDocument doc) {
+ if (offset >= 0 && doc != null) {
+ Position[] positions = null;
+ try {
+ positions = doc.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY);
+ } catch (BadPositionCategoryException ex) {
+ // no links have been added
+ return null;
+ }
+ for (Position position : positions) {
+ if (offset >= position.getOffset() && offset <= (position.getOffset() + position.getLength())) {
+ return ((ConsoleHyperlinkPosition) position).getHyperLink();
+ }
+ }
+ }
+ return null;
+ }
+
+ public static void activateLink(final IHyperlink link) {
+ Display.getDefault().asyncExec(() -> link.linkActivated());
+ }
}