Bug 434737 - Sorting of coordinates in Model Repositories view a bit naive
Summary: Sorting of coordinates in Model Repositories view a bit naive
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Recommenders (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2014-05-13 08:14 EDT by Andreas Sewe CLA
Modified: 2019-07-24 14:36 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Sewe CLA 2014-05-13 08:14:43 EDT
Currently, the coordinate

  org.eclipse:osgi:3.0.0

comes after

  org.eclipse.zest:org.eclipse.zest.core:1.0.0

The sorting should be at least lexicographic, sorting first by groupId, then by artifactId, then by version. (More smarts in each group are also possible, but the above symptom would already be covered by sorting by groupId first, then by artifactId.)
Comment 1 Johannes Dorn CLA 2014-05-13 08:18:45 EDT
I would like the sorting to be case insensitive, so that

   A:A:1.0.0

comes before

   b:b:1.0.0
Comment 2 Andreas Sewe CLA 2014-07-21 03:17:21 EDT
Unless we get external contributions on this one, we have to postpone it for 2.3.0.
Comment 3 varun gupta CLA 2014-11-11 11:45:54 EST
this is my first bug, please assign this bug to me
Comment 4 Andreas Sewe CLA 2014-11-11 11:51:08 EST
(In reply to varun gupta from comment #3)
> this is my first bug, please assign this bug to me

You can do so yourself. Just change "Assigned to" and change the bug's status.

Anyhow, we are looking forward to see your contributions in Gerrit. Please don't hesitate to ask a question about this feature (in Bugzilla) or the general committer workflow (on the recommenders-dev mailing list).
Comment 5 varun gupta CLA 2014-11-11 16:47:17 EST
please could you give me the link from where I could find the code for the feature
Comment 6 varun gupta CLA 2014-11-11 16:49:43 EST
org.eclipse.zest:org.eclipse.zest.core:1.0.0

please verify
org.eclipse.zest is groupId
org.eclipse.zest is artifactId
1.0.0 is version
Comment 7 Andreas Sewe CLA 2014-11-12 03:10:52 EST
(In reply to varun gupta from comment #6)
> org.eclipse.zest:org.eclipse.zest.core:1.0.0
> 
> please verify
> org.eclipse.zest is groupId
> org.eclipse.zest is artifactId

org.eclipse.zest.core (the second part) is artifactId

> 1.0.0 is version

Aside from that, the above is correct.
Comment 8 Andreas Sewe CLA 2014-11-12 03:28:36 EST
(In reply to varun gupta from comment #5)
> please could you give me the link from where I could find the code for the
> feature

The class to look for is ModelRepositoriesView. Start by looking at the treeViewer field and how it is set up. (I hope you are somewhat familiar with the JFace viewer framework; if not, please read some documentation/tutorials first.)
Comment 9 varun gupta CLA 2014-11-12 20:50:19 EST
i have read the treeViewer field from the link 

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fviewers%2FTreeViewer.html

but i could not find the  ModelRepositoriesView
Comment 10 Andreas Sewe CLA 2014-11-24 02:57:22 EST
(In reply to varun gupta from comment #9)
> i have read the treeViewer field from the link 
> 
> http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.
> isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fviewers%2FTreeViewer.html
> 
> but i could not find the  ModelRepositoriesView

Hi Varun. Did you check out the code of Eclipse Code Recommenders as described at [1]. You should then have a ModelRepositoriesView in your workspace (in project org.eclipse.recommenders.models.rcp).

Hope this helps.

[1] <https://git.eclipse.org/c/recommenders/org.eclipse.recommenders.git/about/>
Comment 11 varun gupta CLA 2014-12-02 06:31:41 EST
org.eclipse.recommenders.internal.models.rcp.ModelRepositoriesView

this is the class which u want me to look at
Comment 12 Andreas Sewe CLA 2014-12-02 06:58:37 EST
(In reply to varun gupta from comment #11)
> org.eclipse.recommenders.internal.models.rcp.ModelRepositoriesView
> 
> this is the class which u want me to look at

Exactly. Try to find our where the sorting happens and then change the comparison logic to take the structure (groupId:artifactId:version) into account.
Comment 13 varun gupta CLA 2014-12-02 14:46:32 EST
could u briefly explain to me what this class does, because when i read the code its not easy to understand.
Comment 14 Andreas Sewe CLA 2014-12-03 02:59:53 EST
(In reply to varun gupta from comment #13)
> could u briefly explain to me what this class does, because when i read the
> code its not easy to understand.

OK, the class is responsible for the UI of the Model Repositories view. In particular, the view shows KnownCoordinate objects. Now, one tiny part of this is fixing a sort order for the KnownCoordinates can be found in the createCoordiantes (note the type) method:

  return Ordering.natural().onResultOf(toStringRepresentation).sortedCopy(coordinates);

If you don't understand what this line does, have a look at the Google Guava library and its Ordering class.

Hope that helps.
Comment 15 varun gupta CLA 2014-12-03 09:29:17 EST
createCoordiantes method has a string url as a parameter, what is it for because the pc variable already has the groupid, artifactid and version
Comment 16 Andreas Sewe CLA 2014-12-03 10:20:28 EST
(In reply to varun gupta from comment #15)
> createCoordiantes method has a string url as a parameter, what is it for
> because the pc variable already has the groupid, artifactid and version

It is the URL of the repository in which the project coordinate was found. For the sorting, it's value should not matter; only groupId, artifactId, and version need to be taken into account.
Comment 17 varun gupta CLA 2014-12-03 14:17:31 EST
what does ModelCoordinate parameter contain?
our multimap coordinatesGroupedByProjectCoordinate has project coordinate which maps with ModelCoordinate so could u tell me how are the related?
Comment 18 varun gupta CLA 2014-12-03 14:18:06 EST
what does ModelCoordinate parameter contain?
our multimap coordinatesGroupedByProjectCoordinate has project coordinate which maps with ModelCoordinate so could u tell me how are the related?
Comment 19 varun gupta CLA 2014-12-04 10:45:36 EST
is the ProjectCoordinate a string which is like this notation "groupid:artifactid:version"?
and is the colon included
Comment 20 Andreas Sewe CLA 2014-12-04 10:46:59 EST
(In reply to varun gupta from comment #19)
> is the ProjectCoordinate a string which is like this notation
> "groupid:artifactid:version"?
> and is the colon included

A ProjectCoordinate is a ProjectCoordinate, that is an object with multiple fields, through of which are groupId, artifactId, and version.
Comment 21 varun gupta CLA 2014-12-05 08:56:32 EST
sir, could u also explain the Known coordinate class that is what r the fields it has and how it is mapped with a string
Comment 22 varun gupta CLA 2014-12-06 03:49:40 EST
sir, we could use a comparable interface for our KnownCoordinate class and implement a compareTo function and there we can specify the order that is groupid:artifactId:version and then we could simply apply Collection.sort to sort the list of all KnownCoordinate class objects
Comment 23 Marcel Bruch CLA 2014-12-06 04:19:04 EST
Varun,

I think it's time that you write some code. At some point all your questions will get answered when you start writing the code and start looking into the details yourself - best with the aid of a debugger. This is what your should do anyways to figure out how things actually work. 

Please start writing a java.util.Comparator that takes the example coordinates given in comment 0 and comment 1 and write a unit test that verifies that the order meets your expectations. then commit it to gerrit so that we can review your code there.

Please take your time to read through the documentation provided in the wiki and contributor guides. Familiarize yourself with the code (follow the contributor guide to see how to setup an Eclipse with the code in it) and write code. At some point you need to try out things :)

Thanks and bye,
Marcel
Comment 24 varun gupta CLA 2014-12-07 22:11:58 EST
sir, 
i have written the code as a temporary class implementing the comparator interface,could u tell me how to commit the code
Comment 25 Marcel Bruch CLA 2014-12-08 01:44:55 EST
Please consult the last paragraph of [1]. You may also find the egit/gerrit user guide in the Eclipse wiki helpful.


[1] https://git.eclipse.org/c/recommenders/org.eclipse.recommenders.git/about/
Comment 26 varun gupta CLA 2014-12-08 08:39:20 EST
are comments in the code i have wriiten or somewhere else
Comment 27 Marcel Bruch CLA 2014-12-08 09:00:02 EST
whatever you prefer. normally we use gerrit for comments. The code would  certainly require several iterations and the comments in code will be removed over time. So start with whatever you have. Thanks.
Comment 28 varun gupta CLA 2014-12-08 09:34:25 EST
sir what i have done is it somewhat right
Comment 29 Johannes Dorn CLA 2014-12-08 09:36:00 EST
You can see the comments in gerrit https://git.eclipse.org/r/#/c/37734/
Comment 30 varun gupta CLA 2014-12-08 20:00:44 EST
sir i want to know what do u mean by Please make the Comparator into its own class, distinct from KnownCoordinate
Comment 31 Andreas Sewe CLA 2014-12-09 02:59:42 EST
(In reply to varun gupta from comment #30)
> sir i want to know what do u mean by Please make the Comparator into its own
> class, distinct from KnownCoordinate

First of all, please discuss comments somebody made in Gerrit in Gerrit, not in Bugzilla.

Anyway, what I meant is this: Please create a new class KnownCoordianteComparator implementing Comparator<KnownCoordinate>. Making KnownCoordinate itself implement Comparator is a bad idea.
Comment 32 varun gupta CLA 2014-12-12 05:40:38 EST
sir,i wanted to know exactly what i should do in  the JUnit test and as t have to check the comparator function "compare",so i need object of KnownCoordinate but should i make the url field and mcs field as anything because i only need the pc field
Comment 33 Andreas Sewe CLA 2014-12-12 05:51:21 EST
(In reply to varun gupta from comment #32)
> sir,i wanted to know exactly what i should do in  the JUnit test and as t
> have to check the comparator function "compare",so i need object of
> KnownCoordinate but should i make the url field and mcs field as anything
> because i only need the pc field

Maybe you can write a Comparator for ProjectCoordinate first. We the help of Guava's Ordering.onResultOf [1] you can then turn the Comparator<ProjectCoordinate> into a Comparator<KnownCoordinate>.

Hope this helps.

[1] <http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Ordering.html>
Comment 34 varun gupta CLA 2014-12-12 07:49:15 EST
sir last time  i implemented the KnownCoordinate comparator itself so it was working(i think so it was) so should i use the ordering thing or just use the previous one
Comment 35 varun gupta CLA 2014-12-14 05:27:57 EST
sir,i am not able to understand the utility of the Ordering class.
we could simply write a comparator of our own and use Collections.sort() method.The ordering class used also returns a comparator when we use from() method and we can use that comparator to sort our list again by Collections.sort()
Comment 36 Michael Kutschke CLA 2014-12-17 16:03:04 EST
Ordering class is only there to make things easier. The reason to have a ProjectCoordinateComparator instead of a KnownCoordinateComparator is that it is more generic, and might be useful elsewhere in the project.

Then, with a Function object that takes a KnownCoordinate and outputs its pc field, this can be turned in a Comparator for KnownCoordinate using the Ordering.onResultOf.





My advise is to start refactoring the code you have, making an own Comparator<KnownCoordinate> class with the code you already have. Afterwards you can still turn this into a Comparator<ProjectCoordinate> later.





The Ordering class is there to combine Comparators or turn simple Comparators into more complex ones. It is not "needed", it is just convenient (for you and for us).
Comment 37 varun gupta CLA 2014-12-18 06:36:19 EST
sir, i had committed on git three days ago and no one has reviewed my code so i could make changes(as the built failed),please look into it and tell me any problem you find
Comment 38 varun gupta CLA 2014-12-18 06:36:42 EST
sir, i had committed on gerrit three days ago and no one has reviewed my code so i could make changes(as the built failed),please look into it and tell me any problem you find
Comment 39 Michael Kutschke CLA 2014-12-18 09:48:13 EST
Hi Varun,

I see now. It would help if you amended your commits when you change them, instead of making a new commit. That way there is only one change in Gerrit that needs to be followed. Gerrit identifies the changes through the Change-Id, so when you locally amend your commit, keeping the Change-Id the same, Gerrit will associate the new change with the old one. Obviously once we have submitted your code to the codebase, you no longer amend that change ;-)

Also, to see why the build failed, you should check what Hudson said, by clicking on the link for the build. You should do this shortly after, as by now the result is no longer available. It is possible to re-run the build, but I forgot how.

Anyway, I am reviewing your change now.
Comment 40 varun gupta CLA 2014-12-20 16:27:42 EST
hi,i have been committing my code on gerrit with the new line as you said but now my code is not getting commited
Comment 41 varun gupta CLA 2015-01-02 07:09:53 EST
about the Junit test can you tell me what input should I use for the objects of KnownCoordinate class ?
Comment 42 varun gupta CLA 2015-02-13 05:50:54 EST
can you provide me with a proper constraint of the values for the version field.
example version a.b.c
constraints for a, b and c;
Comment 43 Michael Kutschke CLA 2015-02-13 07:31:52 EST
Hi varun,

as per http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom-syntax.html

the format for versions is:

<major version>.<minor version>.<incremental version>-<qualifier>

where major, minor, and incremental version are numbers, and the qualifier can be any string, basically. From the examples given, I would say there are following things that you should be aware of:

- The qualifier can be missing (and often is), in that case the dash won't be there, either.

- The incremental version can  be missing, then the last dot is missing, too:

>  For example, the version "1.3-beta-01" has a major version of 1, a minor version of 3, no incremental version and a qualifier of "beta-01".

- it is legal to have some non-standard version (so basically forget all I said before):

> If your version release number does not fit the standard introduced in this section, then your versions will be compared as strings; "1.0.1b" will be compared to "1.2.0b" using a String comparison.


So, after all this, I think you should compare like this:

Lexicographically, compare major version, then minor, then incremental, then qualifier. When these are numbers, compare as numbers, otherwise as strings. A missing something is always before the not-missing thing, except for the classifier: A missing classifier is later than an existing classifier. Makes sense?

An additional gotcha is mentioned on the site I linked:

> One gotcha for release version numbers is the ordering of the qualifiers. Take the version release numbers “1.2.3-alpha-2” and “1.2.3-alpha-10,” where the “alpha-2” build corresponds to the 2nd alpha build, and the “alpha-10” build corresponds to the 10th alpha build. Even though “alpha-10” should be considered more recent than “alpha-2,” Maven is going to sort “alpha-10” before “alpha-2” due to a known issue in the way Maven handles version numbers.

>Maven is supposed to treat the number after the qualifier as a build number. In other words, the qualifier should be "alpha", and the build number should be 2. Even though Maven has been designed to separate the build number from the qualifier, this parsing is currently broken. As a result, "alpha-2" and "alpha-10" are compared using a String comparison, and "alpha-10" comes before "alpha-2" alphabetically. To get around this limitation, you will need to left-pad your qualified build numbers. If you use "alpha-02" and "alpha-10" this problem will go away, and it will continue to work once Maven properly parses the version build number.

*Basically, read the site I linked.*
Comment 44 Andreas Sewe CLA 2015-02-13 07:57:41 EST
(In reply to Michael Kutschke from comment #43)
> as per
> http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-pom-
> syntax.html
> 
> the format for versions is:
> 
> <major version>.<minor version>.<incremental version>-<qualifier>

This is true of Maven version numbers, but not of the versions that are part of a ModelCoordinate or ProjectCoordinate. There, the version is always

  <major version>.<minor version>.<incremental version>

There is no <qualifier> and none of the three numbers is optional.
Comment 45 varun gupta CLA 2015-02-16 10:48:19 EST
i have commited a new patch but I am not able to attach the header files due to problem with my setup of gerrit .
Comment 46 varun gupta CLA 2015-09-21 09:37:36 EDT
For versions I need a little more clarity about the format.
version1= x.y.z
version2= a.b.c

then are the types of a and x same, same for b and y and z and c.

If the types are different that is one is a string and the other is an integer then how do you want the sorting to work?
Comment 47 Andreas Sewe CLA 2015-09-21 09:50:33 EDT
(In reply to varun gupta from comment #46)
> For versions I need a little more clarity about the format.
> version1= x.y.z
> version2= a.b.c
> 
> then are the types of a and x same, same for b and y and z and c.
> 
> If the types are different that is one is a string and the other is an
> integer then how do you want the sorting to work?

All strings are larger or lower (I don't care which way) than all numbers. For numbers: 1 < 2 < 10 < 20.
Comment 48 varun gupta CLA 2015-09-21 09:55:15 EDT
(In reply to Andreas Sewe from comment #47)
> (In reply to varun gupta from comment #46)
> > For versions I need a little more clarity about the format.
> > version1= x.y.z
> > version2= a.b.c
> > 
> > then are the types of a and x same, same for b and y and z and c.
> > 
> > If the types are different that is one is a string and the other is an
> > integer then how do you want the sorting to work?
> 
> All strings are larger or lower (I don't care which way) than all numbers.
> For numbers: 1 < 2 < 10 < 20.

Example: 1.2.3 and 1.2.beta,
how can such versions be compared , when the type for the last field are different
Comment 49 Andreas Sewe CLA 2015-09-21 09:56:42 EDT
(In reply to varun gupta from comment #48)
> (In reply to Andreas Sewe from comment #47)
> > (In reply to varun gupta from comment #46)
> > > For versions I need a little more clarity about the format.
> > > version1= x.y.z
> > > version2= a.b.c
> > > 
> > > then are the types of a and x same, same for b and y and z and c.
> > > 
> > > If the types are different that is one is a string and the other is an
> > > integer then how do you want the sorting to work?
> > 
> > All strings are larger or lower (I don't care which way) than all numbers.
> > For numbers: 1 < 2 < 10 < 20.
> 
> Example: 1.2.3 and 1.2.beta,
> how can such versions be compared , when the type for the last field are
> different

All strings are larger than all numbers. For example:

  1 < 2 < 10 < 20 < alpha < beta < xyz
Comment 50 varun gupta CLA 2015-09-21 11:21:44 EDT
I have made the changes please have a look at the new commit
Comment 51 varun gupta CLA 2015-09-22 15:15:02 EDT
For a JUnit Test Case for the KnownCoordinateComparator Class, I would be needing to create the object for the KnownCoordinate Class, for which I would have to create one for the outer class that is the ModelReposioriesView class.
So can i just set some default values for the constructor to ModelReposioriesView class and then send the fields that concern the KnownCoordinate class constructor.
Comment 52 varun gupta CLA 2015-09-22 15:15:21 EDT
For a JUnit Test Case for the KnownCoordinateComparator Class, I would be needing to create the object for the KnownCoordinate Class, for which I would have to create one for the outer class that is the ModelReposioriesView class.
So can i just set some default values for the constructor to ModelReposioriesView class and then send the fields that concern the KnownCoordinate class constructor.
Comment 53 varun gupta CLA 2015-09-28 23:17:23 EDT
For the Model Repositories View class , can you please explain me what the parameters of the constructors are to be considered for the JUnit Test

For creating the object of inner class KnownCoordinate , I need  to invoke the constructor of Model Repositories View ,so i needed to know which parameters should I consider as I dont need any of them for the test case, all I require is the Known Coordinate for the Junit test.