in src/main/java/org/apache/jackrabbit/filevault/maven/packaging/mojo/VaultMojo.java [464:598]
public void execute() throws MojoExecutionException, MojoFailureException {
final File finalFile = getZipFile(outputDirectory, finalName, classifier);
try {
MavenResourcesExecution mavenResourcesExecution = setupMavenResourcesExecution();
ContentPackageArchiver contentPackageArchiver = new ContentPackageArchiver();
contentPackageArchiver.setEncoding(resourceEncoding);
if (metaInfDirectory != null) {
if (metaInfDirectory.exists() && metaInfDirectory.isDirectory()) {
DefaultFileSet fileSet = createFileSet(metaInfDirectory, Constants.META_INF + "/",
Collections.singletonList(Constants.VAULT_DIR));
addFileSetToArchive(mavenResourcesExecution, contentPackageArchiver, fileSet);
getLog().info("Include additional META-INF files/folders from " + getProjectRelativeFilePath(metaInfDirectory) + " in package.");
} else {
getLog().warn("Given metaInfDirectory " + getProjectRelativeFilePath(metaInfDirectory) + " does not exist or is no directory. It won't be included in the package.");
}
}
// find the meta-inf/vault source directory
File metaInfVaultDirectory = getMetaInfVaultSourceDirectory();
// retrieve filters
Filters filters = loadGeneratedFilterFile();
Map<String, File> embeddedFiles = getEmbeddedFilesMap();
File workDirectory = getWorkDirectory(false);
// A map with key = relative file in zip and value = absolute source file name)
Map<File, File> duplicateFiles = new HashMap<>();
contentPackageArchiver.setIncludeEmptyDirs(true);
if (metaInfVaultDirectory != null) {
if (metaInfVaultDirectory.getAbsoluteFile().toPath().normalize().startsWith(workDirectory.getAbsoluteFile().toPath().normalize())) {
throw new MojoFailureException("metaInfVaultDirectory ("+metaInfVaultDirectory+") must be outside of workDirectory ("+ workDirectory + ")!");
}
// first add the metadata from the metaInfDirectory (they should take precedence over the generated ones from workDirectory,
// except for the filter.xml, which should always come from the work directory)
DefaultFileSet fileSet = createFileSet(metaInfVaultDirectory, Constants.META_DIR + "/",
Collections.singletonList(Constants.FILTER_XML));
duplicateFiles.putAll(getOverwrittenProtectedFiles(fileSet, true));
addFileSetToArchive(mavenResourcesExecution, contentPackageArchiver, fileSet);
}
// then add all files from the workDirectory (they might overlap with the ones from metaInfDirectory, but the duplicates are
// just ignored in the package)
DefaultFileSet fileSet = createFileSet(workDirectory, "");
// issue warning in case of overlaps
Map<File, File> overwrittenWorkFiles = getOverwrittenProtectedFiles(fileSet, true);
for (Entry<File, File> entry : overwrittenWorkFiles.entrySet()) {
String message = "Found duplicate file '" + entry.getKey() + "' from sources " + getProjectRelativeFilePath(protectedFiles.get(entry.getKey()))
+ " and " + getProjectRelativeFilePath(entry.getValue()) + ".";
// INFO for the static ones all others warn
if (STATIC_META_INF_FILES.contains(entry.getKey())) {
getLog().info(message);
} else {
getLog().warn(message);
}
}
addFileSetToArchive(mavenResourcesExecution, contentPackageArchiver, fileSet);
// add embedded files
for (Map.Entry<String, File> entry : embeddedFiles.entrySet()) {
protectedFiles.put(new File(entry.getKey()), entry.getValue());
addFileToArchive(mavenResourcesExecution, contentPackageArchiver, entry.getValue(), entry.getKey());
}
// find the source directory
final File jcrSourceDirectory = getJcrSourceDirectory();
// include content from build only if it exists
if (jcrSourceDirectory != null && jcrSourceDirectory.exists()) {
if (jcrSourceDirectory.getAbsoluteFile().toPath().normalize().startsWith(workDirectory.getAbsoluteFile().toPath().normalize())) {
throw new MojoFailureException("jcrSourceDirectory ("+jcrSourceDirectory+") must be outside of workDirectory ("+ workDirectory + ")!");
}
getLog().info("Packaging content from " + getProjectRelativeFilePath(jcrSourceDirectory));
Map<File, File> overwrittenFiles = addSourceDirectory(mavenResourcesExecution, contentPackageArchiver, jcrSourceDirectory, filters, embeddedFiles);
duplicateFiles.putAll(overwrittenFiles);
if (!duplicateFiles.isEmpty()) {
for (Entry<File, File> entry : duplicateFiles.entrySet()) {
String message = "Found duplicate file '" + entry.getKey() + "' from sources " + getProjectRelativeFilePath(protectedFiles.get(entry.getKey()))
+ " and " + getProjectRelativeFilePath(entry.getValue()) + ".";
if (failOnDuplicateEntries) {
getLog().error(message);
} else {
getLog().warn(message);
}
}
if (failOnDuplicateEntries) {
throw new MojoFailureException(
"Found " + duplicateFiles.size() + " duplicate file(s) in content package, see above errors for details.");
}
}
// check for uncovered files (i.e. files from the source which are not even added to the content package)
Collection<File> uncoveredFiles = getUncoveredFiles(jcrSourceDirectory, excludes, prefix,
contentPackageArchiver.getFiles().keySet());
if (!uncoveredFiles.isEmpty()) {
for (File uncoveredFile : uncoveredFiles) {
String message = "File " + getProjectRelativeFilePath(uncoveredFile)
+ " not covered by a filter rule and therefore not contained in the resulting package";
if (failOnUncoveredSourceFiles) {
getLog().error(message);
} else {
getLog().warn(message);
}
}
if (failOnUncoveredSourceFiles) {
throw new MojoFailureException("The following files are not covered by a filter rule: \n"
+ StringUtils.join(uncoveredFiles.iterator(), ",\n"));
}
}
}
// add mandatory jcr_root folder
if (!contentPackageArchiver.getFiles().containsKey(Constants.ROOT_DIR + "/")) {
contentPackageArchiver.addResource(new PlexusIoNonExistingDirectoryResource(Constants.ROOT_DIR), Constants.ROOT_DIR, 0);
}
MavenArchiver mavenArchiver = new MavenArchiver();
mavenArchiver.setArchiver(contentPackageArchiver);
mavenArchiver.setOutputFile(finalFile);
mavenArchiver.configureReproducible(outputTimestamp);
mavenArchiver.createArchive(null, project, getMavenArchiveConfiguration(getGeneratedManifestFile(false)));
if (StringUtils.isNotEmpty(classifier)) {
projectHelper.attachArtifact(project, PACKAGE_TYPE, classifier, finalFile);
} else {
// set the file for the project's artifact and ensure the
// artifact is correctly handled with the "zip" handler
// (workaround for MNG-1682)
final Artifact projectArtifact = project.getArtifact();
projectArtifact.setFile(finalFile);
projectArtifact.setArtifactHandler(artifactHandlerManager.getArtifactHandler(PACKAGE_TYPE));
}
} catch (IllegalStateException | ManifestException | IOException | DependencyResolutionRequiredException | ConfigurationException | MavenFilteringException e) {
throw new MojoExecutionException(e.toString(), e);
}
}