DESCRIPTION

Add ICommitMessageProvider2 for caret positioning in commit messages

The caret in the CommitMessageComponent is placed according to the
value of getDesiredCaretPosition() of the first implementation of
ICommitMessageProvider2 that provides caret position. In case there
are multiple implementations available that provide a defined caret
position the second and subsequent positions are ignored.

Commit messages are not trimmed anymore to ensure consistency between
a provided message and the provided caret position.

Includes unit and UI tests.

Bug: 516867
Change-Id: I1b0ffd33ef37196d53077d09774672c2b033835f
Signed-off-by: James Mcgee xxx@xxx.xxx
Signed-off-by: Alayna Houston xxx@xxx.xxx

COMMENTS

author: James Mcgee
date: 2017-06-15 13:00:10.000000000

Uploaded patch set 20.

-------------------------------------
author: Brenden Conley
date: 2017-06-15 13:00:15.000000000

Patch Set 20:

Build Started https://hudson.eclipse.org/egit/job/egit.gerrit/9938/

-------------------------------------
author: Brenden Conley
date: 2017-06-15 13:24:36.000000000

Patch Set 20: Verified+1

Build Successful 

https://hudson.eclipse.org/egit/job/egit.gerrit/9938/ : SUCCESS

-------------------------------------
author: Alayna Houston
date: 2017-06-15 13:33:39.000000000

Patch Set 20: Code-Review+1

(3 comments)

> INSTANCE does not yet accept a list.
 > Just wanted to know, if I added the second provider within the same
 > <extension> element according to your idea.

Yes, that was the idea.

I've described my idea with a list in INSTANCE in in-line comments. However, your approach also works and is probably good enough for a test for now, so unless you absolutely want to, there's no need to change the code again as far as I'm concerned.

Let's see what Matthias thinks. Code looks fine for me; but we'll have to file a CQ since it's more than 1000 changed lines.

Line:84, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/CommitMessageComponentTest.java -> Then you'd do here

  provider1 = ...
  provider2 = ...
  TestCommitMessageProviderExtensionFactory.INSTANCE
    .setCommitMessageProviders(provider1, provider2);

(Assuming something like

  public void setCommitMessageProviders(ICommitMessageProvider... providers);

)

INSTANCE would be something like

  private List<ICommitMessageProviders> providers = new ArrayList<>();

  private int nofCalls = 0;

  public Object create() {
    if (nofCalls < providers.size()) {
      ICommitMessageProvider p = providers.get(nofCalls++);
      if (p != null) {
        return p;
      }
    }
    return emptyProvider;
  }

  public void reset() { // To be called xxx@xxx.xxx
    providers.clear();
    nofCalls = 0;
  }

  public void setCommitMessageProviders(ICommitMessageProvider... newProviders) {
    providers.clear();
    for (ICommitMessageProvider p : newProviders) {
      providers.add(p);
    }
    nofCalls = 0;
  }

Or maybe use a queue (linked list) and pop the front element on each create(). Then we don't need the count.

Line:75, org.eclipse.egit.ui.test/fragment.xml -> Not needed. Just use TestCommitMessageProviderExtensionFactory again!

Line:14, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderExtensionFactory2.java -> Not needed. Just specify the same factory class again in fragment.xml. The framework will instantiate the factory twice. Both instances will use the same INSTANCE variable, though. Then change that INSTANCE to accept a list of providers, and make it return successive elements from that list on successive calls to create(). (And return emptyProvider if more calls to create() occur than there are elements in the list.)

-------------------------------------
author: Douglas Trujillo
date: 2017-06-15 16:44:16.000000000

Patch Set 20: Code-Review-1

(16 comments)

Line:34, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> I think this is rather a builder than a calculator

Line:72, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> this should return the interface ICommitMessageProvider2 instead of an implementation class

Line:72, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> call this build() ?

Line:80, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> this should be just ICommitMessageProvider2, the implementation class is part of the respective provider implementation

Line:85, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> I think this null check should be done before the previous statement in line 82

Line:91, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> you are doing nothing more than concatenation, keep track of the number of messages being concatenated in the internal state of this class. I'd call this method append(String message)

Line:127, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> updateCaretPosition ?

Line:171, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> this method could be declared private

Line:172, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> fix warning

The local variable providers is hiding a field from type CommitMessageCalculator

Line:209, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> fix warnings:

Null type safety: The expression of type 'Repository' needs unchecked conversion to conform to xxx@xxx.xxx Repository'	

Null type safety: The expression of type 'String' needs unchecked conversion to conform to xxx@xxx.xxx String'

Line:1, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderFactory.java -> missing license header

File Comment: org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculatorTest.java -> I don't understand why this class was renamed, it still tests CommitMessageComponent

Line:11, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculatorTest.java -> we don't use wildcard imports

Line:39, org.eclipse.egit.ui/src/org/eclipse/egit/ui/ICommitMessageProvider2.java -> I think this is a broken abstraction, the super interface already exposes the message so this interface should just add another method to access the caret position. Otherwise these interfaces expose the commit message twice

Line:45, org.eclipse.egit.ui/src/org/eclipse/egit/ui/ICommitMessageProvider2.java -> I think an interface should not contain an implementation class

Line:70, org.eclipse.egit.ui.test/fragment.xml -> fix warning

Access to extension point 'org.eclipse.egit.ui.commitMessageProvider' is discouraged

-------------------------------------
author: Alayna Houston
date: 2017-06-15 16:56:24.000000000

Patch Set 20: -Code-Review

(4 comments)

Line:80, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> I don't understand this comment.  CommitMessageWithCaretPosition is the DTO class returned by an ICommitMessageProvider2.

Line:172, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> That comes from your previous suggestion to rename this variable to "providers". But with some minor refactoring, we don't need the field at all (it's used in exactly one place only).

Line:39, org.eclipse.egit.ui/src/org/eclipse/egit/ui/ICommitMessageProvider2.java -> But then you need a stateful commit message provider.

Line:70, org.eclipse.egit.ui.test/fragment.xml -> Do we really want to make it public API now? Until now it was an unofficial thing,and in theory we're still free to introduce breaking changes. Compare https://git.eclipse.org/r/#/c/8115/ ... one comment there was "Maybe we also want to revisit the interface".

In particular I'm slightly worried that the interfaces use IResource: when a commit contains only files not in the Eclipse workspace, the ICommitMessageProvider will be given an empty list.

-------------------------------------
author: Douglas Trujillo
date: 2017-06-15 17:18:55.000000000

Patch Set 20:

(4 comments)

Line:80, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> ok, agreed

Line:172, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> my bad, I didn't see the warning when I reviewed PS 18 in the Gerrit WebUI, now I had another look in Eclipse which shows the warning

Line:39, org.eclipse.egit.ui/src/org/eclipse/egit/ui/ICommitMessageProvider2.java -> ok, got it, then keep it like it is

Line:70, org.eclipse.egit.ui.test/fragment.xml -> you are right, let's keep it internal

-------------------------------------
author: James Mcgee
date: 2017-06-16 10:42:32.000000000

Patch Set 20:

(13 comments)

Line:34, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> I don't mind, which name to choose.
I just took the name from the original method "calculateCommitMessage()".
I am going to rename it...

Line:72, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> Done

Line:85, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> Done

Line:91, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> Done

Line:127, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> Done

Line:171, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> Unfortunately not. It is visible for testing.

Line:209, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculator.java -> Done

Line:1, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/TestCommitMessageProviderFactory.java -> Done

File Comment: org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculatorTest.java -> You are right. I moved the existing tests back to CommitMessageComponentTest and kept the new tests in CommitMessageCalculatorTest.

Line:11, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageCalculatorTest.java -> Done

Line:84, org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/CommitMessageComponentTest.java -> I change the code, according to your suggestion.

Line:45, org.eclipse.egit.ui/src/org/eclipse/egit/ui/ICommitMessageProvider2.java -> Ok. I moved it to a separate file within the same package.

Line:75, org.eclipse.egit.ui.test/fragment.xml -> Done.
But I don't actually understand, how this works now. I am configuring the Factory once within the test cases. It is probably instantiated twice by the runtime, since it es configured twice here.
Does CommitMessageBuilder.getCommitMessageProviders() find two instances of TestCommitMessageProviderFactory now? Does each instance return the same providers?
Anyway, the test pass...

-------------------------------------
author: James Mcgee
date: 2017-06-19 07:39:27.000000000

Patch Set 20:

(7 comments)

-------------------------------------
author: Alayna Houston
date: 2017-06-16 11:06:07.000000000

MISMATCHED INLINE COMMENT
Line:75, org.eclipse.egit.ui.test/fragment.xml -> We have one INSTANCE, right? It's static final.
The framework creates two factories.

So we have

  T1.create()---+
                |
                +---> INSTANCE.create()
                |
  T2.create()---+

In our tests, we only ever configure INSTANCE. And no matter how many T instances (of type TestCommitMessageProviderExtensionFactory) the framework creates, they all delegate to our single INSTANCE.

That's why I had put that comment there about this indirection being needed. Our tests don't know and cannot configure the dynamically created T instances, but they do know and can configure the singleton INSTANCE the Ts all delegate to.

So, yes, CommitMessageBuilder.getCommitMessageProviders() does find 2 instances, T1, and T2. They do not return the same providers. One will return the first provider we configured on INSTANCE and the other will return the second provider we configured there.

Actually I think even during tests, CommitMessageBuilder.getCommitMessageProviders() will find and call a third provider: the one contributed by Mylyn. Luckily we have no Mylyn tasks associated in our tests, and so it always returns an empty string.

-------------------------------------
