in src/main/java/org/apache/sling/feature/maven/ProjectHelper.java [99:136]
private static Map<String, Feature> getFeatures(final MavenProject project, final String key) {
final String cacheKey = key + "-cache";
Map<String, Feature> result = null;
try {
result = (Map<String, Feature>) project.getContextValue(cacheKey);
if (result != null && !result.isEmpty() ) {
final Feature f = result.values().iterator().next();
f.getId();
}
} catch ( final Exception e) {
// if we get a class cast exception, we read again
result = null;
}
if ( result == null ) {
result = new TreeMap<>();
final Integer size = (Integer)project.getContextValue(key);
if ( size != null ) {
for(int i=0; i<size;i++) {
final String text = (String)project.getContextValue(key + "_" + String.valueOf(i));
if ( text == null ) {
throw new RuntimeException("Unable to get feature from internal store.");
}
final String file = (String)project.getContextValue(key + "_" + String.valueOf(i) + "f");
if ( file == null ) {
throw new RuntimeException("Unable to get feature from internal store.");
}
try ( final StringReader r = new StringReader(text) ) {
final Feature feature = FeatureJSONReader.read(r, project.getId());
result.put(file, feature);
} catch ( final IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe);
}
}
}
project.setContextValue(cacheKey, result);
}
return result;
}