in tooling/camel-upgrade/src/main/java/org/apache/camel/karaf/tooling/upgrade/FeatureHandler.java [52:83]
private static String getFeaturesWithComponent(String features, String component) {
int start = features.indexOf("<!-- the following features are sorted A..Z -->");
if (start == -1) {
throw new IllegalStateException("Unable to find the start position in the features files");
}
Matcher matcher = FEATURE_IN_FEATURES_XML.matcher(features);
StringBuilder result = new StringBuilder();
boolean added = false;
while (matcher.find(start)) {
String feature = matcher.group(1);
if (feature.equals(component)) {
// Already in the features
return features;
} else if (feature.compareTo(component) > 0) {
result.append(features, 0, matcher.start());
result.append(FEATURE_FORMAT.replace("#{camel-component-id}", component));
result.append(" ");
added = true;
start = matcher.start();
break;
}
start = matcher.end();
}
if (!added) {
start = nextLineIndex(features, features.lastIndexOf("</feature>"));
result.append(features, 0, start);
result.append(" ");
result.append(FEATURE_FORMAT.replace("#{camel-component-id}", component));
}
result.append(features, start, features.length());
return result.toString();
}