Commit 11fdd8b9 authored by Marco Konersmann's avatar Marco Konersmann

Ordered execution of inter-profile transformations

parent c7237d35
......@@ -2,6 +2,7 @@ package org.codeling.interprofile.internal;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
......@@ -115,7 +116,7 @@ public class LanguageMatcher {
// Add transformations for "activating" missing profiles, that e.g. just add
// "ArchitectureWithDeployments" etc.
addTransformationsIfSourcesMisses(possiblyMissingProfiles.toArray(new Profiles[0]), result);
orderTransformationsByDependency(result);
return result;
}
......@@ -127,6 +128,29 @@ public class LanguageMatcher {
}
}
/**
* Orders the transformation URIs by dependencies. Currently hard coded. A
* dependency declaration might be considered when the number of profiles
* increases significantly.
*/
private void orderTransformationsByDependency(List<URI> result) {
result.sort(new Comparator<URI>() {
public int compare(URI o1, URI o2) {
// Shortens from http://abc.de/.../1.0 to http://abc.de/...
String shortenedO1 = o1.toString().substring(0, o1.toString().lastIndexOf("/"));
String shortenedO2 = o2.toString().substring(0, o1.toString().lastIndexOf("/"));
if(shortenedO1.contains(shortenedO2))
return 1;
else if(shortenedO1.contains(shortenedO2))
return -1;
else
// Order alphabetically
return shortenedO1.compareTo(shortenedO2);
};
});
}
private boolean addTransformationIfApplicable(Profiles sourceProfile, Profiles[] possibleTargets,
List<URI> result) {
boolean changed = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment