-
Notifications
You must be signed in to change notification settings - Fork 9
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
Script order #70
Script order #70
Conversation
Nit: Comma after "Before" in commit message. |
* A comparator that orders path names. Files in the same directory are ordered alphabetically, and always come before | ||
* files in subdirectories. Subdirectories are also ordered alphabetically. | ||
*/ | ||
class PathComparator implements Comparator<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this code instead which is a bit shorter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is not sorting folders alphabetically, you can see in the example output that /games/snake
comes after /usr/local
, with more files and more folders this would become a total mess.
class PathComparator implements Comparator<String> { | ||
@Override | ||
int compare(String o1, String o2) { | ||
def tokens1 = o1.tokenize('/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use File.separator
for portability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to revert this as it fails on Windows.
e6580b7
to
1ccc493
Compare
def tokens1 = o1.tokenize('/') | ||
def tokens2 = o2.tokenize('/') | ||
for (int i = 0; i < Math.max(tokens1.size(), tokens2.size()); i++) { | ||
def hasNext1 = tokens1.size() > i + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe i + 1 < tokens1.size()
is more readable?
int compare(String o1, String o2) { | ||
def tokens1 = o1.tokenize('/') | ||
def tokens2 = o2.tokenize('/') | ||
for (int i = 0; i < Math.max(tokens1.size(), tokens2.size()); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Prefer pre-increment in for loops, ++i
.
int compare(String o1, String o2) { | ||
def tokens1 = o1.tokenize(File.separatorChar) | ||
def tokens2 = o2.tokenize(File.separatorChar) | ||
for (int i = 0; i < Math.max(tokens1.size(), tokens2.size()); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Prefer prefix-increment in for
-loops, ++i
.
def tokens1 = o1.tokenize(File.separatorChar) | ||
def tokens2 = o2.tokenize(File.separatorChar) | ||
for (int i = 0; i < Math.max(tokens1.size(), tokens2.size()); i++) { | ||
def hasNext1 = tokens1.size() > i + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe i + 1 < tokens1.size()
reads better?
Before, the Job DSL scripts were processed in whatever order they were returned from the source set. This made the behaviour unpredictable in situations were order matters. Therefore define a sorting order for Job DSL scripts. Job DSL scripts from the same folder are now executed in alphabetical order, and before all scripts from subfolders. Subfolders are also processed in alphabetical order.
1ccc493
to
3c99d2d
Compare
No description provided.