in src/main/java/org/apache/sling/feature/maven/Preprocessor.java [288:351]
protected void readProjectFeatures(
final Logger logger, final FeatureProjectInfo info, final FeatureProjectConfig config) {
// feature files first:
final File dir = new File(info.project.getBasedir(), config.getFeaturesDir());
if (dir.exists()) {
final List<File> files = new ArrayList<>();
ProjectHelper.scan(files, dir, config.getIncludes(), config.getExcludes());
for (final File file : files) {
logger.debug("Reading feature file " + file + " in project " + info.project.getId());
// if the feature is in the root of the configured directory
// and the feature is named "feature.json"
// and the feature is not a test feature, this is the main feature
// which does not get a classifier
final String suggestedClassifier;
if (config.isTestConfig()
|| !file.getName().equals("feature.json")
|| !file.getParentFile()
.getAbsolutePath()
.equals(new File(info.project.getBasedir(), config.getFeaturesDir())
.getAbsolutePath())) {
final int lastDot = file.getName().lastIndexOf('.');
suggestedClassifier = file.getName().substring(0, lastDot);
} else {
suggestedClassifier = null;
}
final String readJson = ProjectHelper.readFeatureFile(
info.project,
file,
suggestedClassifier,
config.isEnableLegacyVariableReplacement(),
config.isEnableProjectVariableReplacement(),
config.getReplacePropertyVariables());
final String json = preprocessFeature(info.project, config.isValidate(), file, readJson);
try (final Reader reader = new StringReader(json)) {
final Feature feature = FeatureJSONReader.read(reader, file.getAbsolutePath());
ProjectHelper.checkFeatureId(info.project, feature);
// Extension handling
JSONFeatures.handleExtensions(feature, file);
// Default metadata
JSONFeatures.handleDefaultMetadata(feature, ProjectHelper.getDefaultMetadata(info.project));
ProjectHelper.setFeatureInfo(info.project, feature);
this.postProcessReadFeature(feature);
(config.isTestConfig() ? info.testFeatures : info.features)
.put(file.toPath().normalize().toFile().getAbsolutePath(), feature);
} catch (final IOException io) {
throw new RuntimeException("Unable to read feature " + file.getAbsolutePath(), io);
}
}
} else {
logger.debug("Feature directory " + config.getFeaturesDir() + " does not exist in project "
+ info.project.getId());
}
}