Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Only touch the classpath if it's not already sorted.
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Sep 24, 2014
1 parent cd359c4 commit a3cf2a3
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,18 @@ protected IStatus run(IProgressMonitor monitor) {
try {
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();

List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(classpathEntries.length);
Collections.addAll(entries, classpathEntries);
Boolean sorted = true;
for (int i = 0; i < classpathEntries.length - 1; i++) {
if (comparator.compare(classpathEntries[i], classpathEntries[i+1]) > 0){sorted = false; break;}
}

if(!sorted) {
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(classpathEntries.length);
Collections.addAll(entries, classpathEntries);

Collections.sort(entries, comparator);
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
Collections.sort(entries, comparator);
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
}
return Status.OK_STATUS;
} catch(JavaModelException e) {
return Status.CANCEL_STATUS;
Expand Down

0 comments on commit a3cf2a3

Please sign in to comment.