Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 213786 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/internal/junit/model/JUnitModel.java (-1 / +34 lines)
Lines 14-19 Link Here
14
import java.io.File;
14
import java.io.File;
15
import java.io.FileOutputStream;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.io.InputStream;
17
import java.io.OutputStream;
18
import java.io.OutputStream;
18
import java.util.ArrayList;
19
import java.util.ArrayList;
19
import java.util.HashSet;
20
import java.util.HashSet;
Lines 389-394 Link Here
389
	}
390
	}
390
	
391
	
391
	/**
392
	/**
393
	 * Imports a test run session from the given input stream.
394
	 * 
395
	 * @param contents an input stream containing a test run session transcript
396
	 * @param absoluteFileName absolute location of the file being imported
397
	 * @return the imported test run session
398
	 * @throws CoreException if the import failed
399
	 */
400
	public static TestRunSession importTestRunSession(InputStream contents, String absoluteFileName) throws CoreException {
401
		try {
402
			SAXParserFactory parserFactory= SAXParserFactory.newInstance();
403
//			parserFactory.setValidating(true); // TODO: add DTD and debug flag
404
			SAXParser parser= parserFactory.newSAXParser();
405
			TestRunHandler handler= new TestRunHandler();
406
			parser.parse(contents, handler);
407
			TestRunSession session= handler.getTestRunSession();
408
			JUnitPlugin.getModel().addTestRunSession(session);
409
			return session;
410
		} catch (ParserConfigurationException e) {
411
			throwImportError(absoluteFileName, e);
412
		} catch (SAXException e) {
413
			throwImportError(absoluteFileName, e);
414
		} catch (IOException e) {
415
			throwImportError(absoluteFileName, e);
416
		}
417
		return null; // does not happen
418
	}
419
	
420
	/**
392
	 * Imports a test run session from the given file.
421
	 * Imports a test run session from the given file.
393
	 * 
422
	 * 
394
	 * @param file a file containing a test run session transcript
423
	 * @param file a file containing a test run session transcript
Lines 493-501 Link Here
493
	}
522
	}
494
523
495
	private static void throwImportError(File file, Exception e) throws CoreException {
524
	private static void throwImportError(File file, Exception e) throws CoreException {
525
		throwImportError(file.getAbsolutePath(), e);
526
	}
527
	
528
	private static void throwImportError(String absoluteFileName, Exception e) throws CoreException {
496
		throw new CoreException(new org.eclipse.core.runtime.Status(IStatus.ERROR,
529
		throw new CoreException(new org.eclipse.core.runtime.Status(IStatus.ERROR,
497
				JUnitPlugin.getPluginId(),
530
				JUnitPlugin.getPluginId(),
498
				Messages.format(ModelMessages.JUnitModel_could_not_read, file.getAbsolutePath()),
531
				Messages.format(ModelMessages.JUnitModel_could_not_read, absoluteFileName),
499
				e));
532
				e));
500
	}
533
	}
501
	
534
	
(-)plugin.xml (+27 lines)
Lines 160-165 Link Here
160
               id="updateTestSuite">
160
               id="updateTestSuite">
161
         </action>
161
         </action>
162
      </objectContribution>
162
      </objectContribution>
163
      <objectContribution
164
            adaptable="false"
165
            id="org.eclipse.jdt.junit.TestRunFile"
166
            objectClass="org.eclipse.core.resources.IFile">
167
         <action
168
               class="org.eclipse.jdt.internal.junit.ui.ImportTestRunAction"
169
               enablesFor="1"
170
               id="org.eclipse.jdt.junit.action1"
171
               label="Import Test Run">
172
         </action>
173
         <visibility>
174
            <objectState
175
                  name="contentTypeId"
176
                  value="org.eclipse.jdt.junit.testRun">
177
            </objectState></visibility>
178
      </objectContribution>
163
   </extension>
179
   </extension>
164
   <extension
180
   <extension
165
         point="org.eclipse.ui.actionSets">
181
         point="org.eclipse.ui.actionSets">
Lines 487-491 Link Here
487
         <!-- END : do we need these? -->
503
         <!-- END : do we need these? -->
488
      </kind>
504
      </kind>
489
   </extension>
505
   </extension>
506
   <extension
507
         point="org.eclipse.core.runtime.contentTypes">
508
      <content-type
509
            base-type="org.eclipse.core.runtime.xml"
510
            describer="org.eclipse.core.runtime.content.XMLRootElementContentDescriber:testrun"
511
            file-extensions="xml"
512
            id="org.eclipse.jdt.junit.testRun"
513
            name="JUnit Test Run File"
514
            priority="normal">
515
      </content-type>
516
   </extension>
490
   
517
   
491
</plugin>
518
</plugin>
(-)src/org/eclipse/jdt/internal/junit/ui/ImportTestRunAction.java (+66 lines)
Added Link Here
1
package org.eclipse.jdt.internal.junit.ui;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
6
import org.eclipse.core.runtime.CoreException;
7
8
import org.eclipse.core.resources.IFile;
9
10
import org.eclipse.jface.action.IAction;
11
import org.eclipse.jface.dialogs.ErrorDialog;
12
import org.eclipse.jface.viewers.ISelection;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
15
import org.eclipse.ui.IObjectActionDelegate;
16
import org.eclipse.ui.IWorkbenchPart;
17
18
import org.eclipse.jdt.internal.junit.model.JUnitModel;
19
20
public final class ImportTestRunAction implements IObjectActionDelegate {
21
22
	private IWorkbenchPart fTargetPart;
23
	private IFile fSelectedFile;
24
25
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
26
		this.fTargetPart= targetPart;
27
	}
28
29
	public void run(IAction action) {
30
		if (fSelectedFile == null) {
31
			return;
32
		}
33
		
34
		InputStream fileContents = null;
35
		try {
36
			fileContents = fSelectedFile.getContents();
37
			JUnitModel.importTestRunSession(fileContents, fSelectedFile.getFullPath().toOSString());
38
		} catch (CoreException e) {
39
			JUnitPlugin.log(e);
40
			ErrorDialog.openError(fTargetPart.getSite().getShell(), JUnitMessages.TestRunnerViewPart_ImportTestRunSessionAction_error_title, e.getStatus().getMessage(), e.getStatus());
41
		} finally {
42
			if (fileContents != null) {
43
				try {
44
					fileContents.close();
45
				} catch (IOException e) {
46
				}
47
			}
48
		}
49
50
	}
51
52
	public void selectionChanged(IAction action, ISelection selection) {
53
		fSelectedFile = null;
54
		
55
		if (selection != null) {
56
			if (selection instanceof IStructuredSelection) {
57
				Object selectedObject = ((IStructuredSelection)selection).getFirstElement();
58
				
59
				if (selectedObject instanceof IFile) {
60
					fSelectedFile = (IFile) selectedObject;
61
				}
62
			}
63
		}
64
	}
65
66
}

Return to bug 213786