Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: Add mechanism to sort compilation units #1938

Merged
merged 12 commits into from
Apr 9, 2018

Conversation

surli
Copy link
Collaborator

@surli surli commented Mar 30, 2018

This PR should fix #1929

@surli surli changed the title Add mechanism to sort compilation units review: Add mechanism to sort compilation units Mar 30, 2018
@Override
public int compare(CompilationUnitDeclaration o1, CompilationUnitDeclaration o2) {
int seed = 0;
if (System.getenv("SPOON_SEED_CU_COMPARATOR") != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from javadoc of System#getenv
If a security manager exists, its checkPermission method is called with a RuntimePermission("getenv."+name) permission. This may result in a SecurityException being thrown.

It would be cleaner to try catch security exception here.

@@ -430,8 +430,11 @@ protected boolean buildUnitsAndModel(JDTBuilder jdtBuilder, SpoonFolder sourcesF

protected void buildModel(CompilationUnitDeclaration[] units) {
JDTTreeBuilder builder = new JDTTreeBuilder(factory);
List<CompilationUnitDeclaration> unitList = Arrays.asList(units);
unitList.sort(new CompilationUnitComparator());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that this sort sorts the origin units array? It actually modifies the array sent from outside. I have checked who actually calls it and it looks like it is actually no problem, but it would be safer to sort a copy of that array.
WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right: I wasn't aware that Arrays.asList was keeping up the link with the original array. Good thing to know 👍

@pvojtechovsky
Copy link
Collaborator

Java code is OK for me.
@monperrus please check the CI stuff ... I do not know that.

@monperrus
Copy link
Collaborator

Interesting.

Two comments:

  • AFIAU, we do fixed order by default, I thought you wanted to do random order by default.
  • I propose to put the variation point outside the comparator, ie having a RandomizeCompilationUnitOrderComparator and FixedOrderBasedOnFileNameCompilationUnitComparator

@surli
Copy link
Collaborator Author

surli commented Apr 4, 2018

we do fixed order by default, I thought you wanted to do random order by default.

No as I said in #1929 that we should have always the same order but we should test that we are not dependent of the order: a way to do that is to randomize the order when testing.

I propose to put the variation point outside the comparator

OK with that change, I'll do it

@surli
Copy link
Collaborator Author

surli commented Apr 4, 2018

I propose to put the variation point outside the comparator

Before I do the change, just to be clear, you want me to integrate my test with getenv inside JDTBasedSpoonCompiler then? It looks a bit ugly...

@monperrus
Copy link
Collaborator

Yes. We can add a method JDTBasedSpoonCompiler#orderCompilationUnits to make it less ugly.

It seems to me that adding a new Travis job for such a specific need and rare bug is somehow overkill, because it is run on all PRs. You suggested a Jenkins job which I tend to prefer. WDYT?

@surli
Copy link
Collaborator Author

surli commented Apr 5, 2018

We can add a method

OK I'll do it that way

You suggested a Jenkins job which I tend to prefer. WDYT?

Jenkins does not provide an immediate feedback, however I agree it's overkill to run this test on all PRs commits: a middle way might be to put it only for commits on master.

@monperrus
Copy link
Collaborator

monperrus commented Apr 5, 2018 via email

@surli
Copy link
Collaborator Author

surli commented Apr 5, 2018

I changed the chore script in db939a1 so it's executed in Travis only for master commits.

@monperrus
Copy link
Collaborator

what about adding a test case?

@@ -328,6 +328,7 @@ public void testSpecPackage() throws Exception {
officialPackages.add("spoon.reflect.visitor");
officialPackages.add("spoon.reflect");
officialPackages.add("spoon.support.comparator");
officialPackages.add("spoon.support.comparator.cu");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems overkill to add a new package for those two small classes? spoon.support.comparator would be enough?

@surli
Copy link
Collaborator Author

surli commented Apr 9, 2018

@monperrus it's ready for me.

@monperrus monperrus merged commit 52bdec2 into INRIA:master Apr 9, 2018
@monperrus
Copy link
Collaborator

thanks!

@surli surli mentioned this pull request Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discussion: buildModel and CompilationUnits order
3 participants