Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 280114 - [JUnit] Leverage AbstractJavaLaunchConfigurationDelegate.getMainTypeName in JUnitLaunchConfigurationDelegate
Summary: [JUnit] Leverage AbstractJavaLaunchConfigurationDelegate.getMainTypeName in J...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Robert Konigsberg CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-12 13:28 EDT by Robert Konigsberg CLA
Modified: 2009-08-08 15:31 EDT (History)
3 users (show)

See Also:


Attachments
Uses parent class's getTypeName method. (1.72 KB, patch)
2009-08-03 15:07 EDT, Robert Konigsberg CLA
markus.kell.r: review-
Details | Diff
Uses parent class's getTypeName method. (attempt 2) (1.78 KB, patch)
2009-08-03 15:40 EDT, Robert Konigsberg CLA
markus.kell.r: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Konigsberg CLA 2009-06-12 13:28:25 EDT
JUnitLaunchConfigurationDelegate.getTestTarget looks like this:

private final IJavaElement getTestTarget(ILaunchConfiguration configuration, IJavaProject javaProject) throws CoreException {
  ...
  String testTypeName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "");
  if (testTypeName.length() != 0) {
    testTypeName= performStringSubstitution(testTypeName);
    ...
  }
  ...
}

private final String performStringSubstitution(String testTypeName) throws CoreException {
  return VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(testTypeName);
}

The problem with this is that if I want to write a special version of JUnit Launch Configurations that determines main types an alternate way, I can't get to this private method.

Alternatively, I recommend replacing all that boilerplate by calling this method from its parent AbstractJavaLaunchConfigurationDelegate:

public String getMainTypeName(ILaunchConfiguration configuration) throws CoreException {
  String mainType = configuration.getAttribute(
    IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
    (String) null);
  if (mainType == null) {
    return null;
  }
  return VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(mainType);
}

Please? :-]
Comment 1 Robert Konigsberg CLA 2009-07-17 13:54:21 EDT
Update: I have the same request for TESTNAME.
Comment 2 Michael Rennie CLA 2009-07-17 14:21:40 EDT
moving to JDT UI as well :)
Comment 3 Markus Keller CLA 2009-07-30 10:09:52 EDT
(In reply to comment #0)
> Alternatively, I recommend replacing all that boilerplate by calling this
> method from its parent AbstractJavaLaunchConfigurationDelegate:
> 
> public String getMainTypeName(ILaunchConfiguration configuration) throws

Sounds good, can you attach a patch for this?


(In reply to comment #1)
> Update: I have the same request for TESTNAME.

You mean a new protected method String getTestMethodName(ILaunchConfiguration)? Would be OK for me (in the same patch ;-).
Comment 4 Robert Konigsberg CLA 2009-07-30 14:01:09 EDT
Yeah, I can do that. :)
Comment 5 Robert Konigsberg CLA 2009-08-03 15:07:43 EDT
Created attachment 143312 [details]
Uses parent class's getTypeName method.
Comment 6 Markus Keller CLA 2009-08-03 15:28:20 EDT
Comment on attachment 143312 [details]
Uses parent class's getTypeName method.

That's not completely correct, since super.getMainTypeName(..) may return null, which leads to an NPE with your patch.
Comment 7 Robert Konigsberg CLA 2009-08-03 15:40:01 EDT
Created attachment 143320 [details]
Uses parent class's getTypeName method. (attempt 2)
Comment 8 Markus Keller CLA 2009-08-03 16:07:24 EDT
Thanks, released for next I-build.
Comment 9 Markus Keller CLA 2009-08-06 05:17:15 EDT
Actually, your patch wouldn't even work for your scenario, since super.getMainTypeName(configuration) always executes the implementation in AbstractJavaLaunchConfigurationDelegate even if you overrode it in your subclass. I've fixed that for M2. Didn't you test your patch?
Comment 10 Robert Konigsberg CLA 2009-08-07 09:57:00 EDT
Mea culpa. I admit it.

I could swear I left a comment asking where I could put a test, which, by the way, is no excuse. But worse, I can't find the comment! Arghghg.

I'm really sorry, this is not the way I like to work. But seriously, where do tests for this plug-in go?
Comment 11 Markus Keller CLA 2009-08-08 15:31:46 EDT
> I'm really sorry, this is not the way I like to work.

Not a big deal, I just thought you already had client code that would use this.

> But seriously, where do tests for this plug-in go?

They are in the org.eclipse.jdt.ui.tests plug-in in the org.eclipse.jdt.junit.tests package. But I don't really need an automated test for this (the code is already executed by existing tests).