in src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java [458:515]
public static int compare(final TaskResource a, final TaskResource b) {
int result = 0;
// check entity id first
final String aId = a.getEntityId();
final String bId = b.getEntityId();
if(aId != null && bId != null) {
result = aId.compareTo(bId);
}
boolean hasVersion = false;
if ( result == 0 ) {
// compare versions
boolean isSnapshot = false;
// Order by version
final Version va = a.getVersion();
final Version vb = b.getVersion();
if ( va != null && vb != null ) {
hasVersion = true;
isSnapshot = va.toString().contains("SNAPSHOT");
// higher version has more priority, must come first so invert comparison
result = vb.compareTo(va);
}
// Then by priority, higher values first
if (result == 0) {
result = Integer.valueOf(b.getPriority()).compareTo(a.getPriority());
}
if (result == 0 && isSnapshot) {
// higher digest has more priority, must come first so invert comparison
result = b.getDigest().compareTo(a.getDigest());
}
}
if ( result == 0 && a.getState() != b.getState() ) {
if ( a.getState() == ResourceState.INSTALLED ) {
return -1;
} else if ( b.getState() == ResourceState.INSTALLED ) {
return 1;
} else if ( a.getState() == ResourceState.INSTALL ) {
return -1;
} else if ( b.getState() == ResourceState.INSTALL ) {
return 1;
}
}
if ( result == 0 ) {
// finally use url and then digest
result = a.getURL().compareTo(b.getURL());
if ( result == 0 && !hasVersion ) {
// higher digest has more priority, must come first so invert comparison
result = b.getDigest().compareTo(a.getDigest());
}
}
return result;
}