in src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/GenerateMetadataMojo.java [669:752]
private String computeFilters(File vaultMetaDir) throws IOException, MojoExecutionException {
// backward compatibility: if implicit filter exists, use it. but check for conflicts
File filterFile = getGeneratedFilterFile(true);
if (filterFile.exists() && filterFile.lastModified() != 0) {
// if both, a inline filter and a implicit filter is present, the build fails.
if (!filters.getFilterSets().isEmpty()) {
getLog().error("Refuse to merge inline filters and non-sourced filter.xml. If this is intended, specify the filter.xml via the 'filterSource' property.");
throw new MojoExecutionException("Conflicting filters, look at above log for details.");
}
// load filters for further processing
try {
filters.load(filterFile);
} catch (ConfigurationException e) {
throw new IOException("Error loading filter file " + getProjectRelativeFilePath(filterFile) + "", e);
}
getLog().warn("The project is using a filter.xml provided via the resource plugin.");
getLog().warn("This is deprecated and might no longer be supported in future versions.");
getLog().warn("Use the 'filterSource' property to specify the filter or use inline filters.");
return null;
}
// if last modified of vault-work/META-INF/vault/filter.xml == 0 -> delete it
if (filterFile.exists() && filterFile.lastModified() == 0) {
try {
Files.delete(filterFile.toPath());
} catch (IOException e) {
getLog().error("Unable to delete previously generated filter.xml. re-run the goals with a clean setup.");
throw new MojoExecutionException("Unable to delete file.", e);
}
}
// check for filters file in vaultDir
if (vaultMetaDir != null) {
File metaFilterFile = new File(vaultMetaDir, "filter.xml");
if (metaFilterFile.exists()) {
if (filterSource != null && !filterSource.equals(metaFilterFile)) {
getLog().error("Project contains filter.xml in META-INF/vault but also specifies a filter source.");
throw new MojoExecutionException("Conflicting filters, look at above log for details.");
}
filterSource = metaFilterFile;
}
}
// if filterSource exists, read the filters into sourceFilters
DefaultWorkspaceFilter sourceFilters = new DefaultWorkspaceFilter();
if (filterSource != null && filterSource.exists()) {
getLog().info("Loading filter from " + filterSource.getPath());
try {
sourceFilters.load(filterSource);
} catch (ConfigurationException e) {
throw new IOException(e);
}
if (!filters.getFilterSets().isEmpty()) {
getLog().info("Merging inline filters.");
mergeFilters(sourceFilters, filters);
}
// now copy everything from sourceFilter to filters (as the latter is supposed to contain the final filter rules)!
// sourceFilters.resetSource();
// there is no suitable clone nor constructor, therefore use a serialization/deserialization approach
try (InputStream serializedFilters = sourceFilters.getSource()) {
filters.load(serializedFilters);
} catch (ConfigurationException e) {
throw new IllegalStateException("cloning filters failed.", e);
}
// reset source filters for later. this looks a bit complicated but is needed to keep the same
// filter order as in previous versions
sourceFilters = new DefaultWorkspaceFilter();
try {
sourceFilters.load(filterSource);
} catch (ConfigurationException e) {
throw new IOException("Error loading filter file " + getProjectRelativeFilePath(filterSource), e);
}
}
// if the prefix property is set, it should be used if no filter is set
if (filters.getFilterSets().isEmpty() && prefix.length() > 0) {
filters.add(new PathFilterSet(prefix));
}
return sourceFilters.getSourceAsString();
}