use of org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator in project maven-plugins by apache.
the class DefaultAssemblyReader method readAssembly.
public Assembly readAssembly(Reader reader, final String locationDescription, final File assemblyDir, final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
Assembly assembly;
final MavenProject project = configSource.getProject();
try {
InterpolationState is = new InterpolationState();
final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(InterpolationConstants.PROJECT_PREFIXES, true);
is.setRecursionInterceptor(interceptor);
FixedStringSearchInterpolator interpolator = AssemblyInterpolator.fullInterpolator(project, createProjectInterpolator(project), configSource);
AssemblyXpp3Reader.ContentTransformer transformer = AssemblyInterpolator.assemblyInterpolator(interpolator, is, getLogger());
final AssemblyXpp3Reader r = new AssemblyXpp3Reader(transformer);
assembly = r.read(reader);
ComponentXpp3Reader.ContentTransformer ctrans = AssemblyInterpolator.componentInterpolator(interpolator, is, getLogger());
mergeComponentsWithMainAssembly(assembly, assemblyDir, configSource, ctrans);
debugPrintAssembly("After assembly is interpolated:", assembly);
AssemblyInterpolator.checkErrors(AssemblyId.createAssemblyId(assembly), is, getLogger());
reader.close();
reader = null;
} catch (final IOException e) {
throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
} catch (final XmlPullParserException e) {
throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
} finally {
IOUtil.close(reader);
}
if (assembly.isIncludeSiteDirectory()) {
includeSiteInAssembly(assembly, configSource);
}
return assembly;
}
use of org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator in project maven-plugins by apache.
the class AssemblyFormatUtils method evaluateFileNameMapping.
/**
* ORDER OF INTERPOLATION PRECEDENCE:
* <ol>
* <li>prefixed with "module.", if moduleProject != null
* <ol>
* <li>Artifact instance for module, if moduleArtifact != null</li>
* <li>ArtifactHandler instance for module, if moduleArtifact != null</li>
* <li>MavenProject instance for module</li>
* </ol>
* </li>
* <li>prefixed with "artifact."
* <ol>
* <li>Artifact instance</li>
* <li>ArtifactHandler instance for artifact</li>
* <li>MavenProject instance for artifact</li>
* </ol>
* </li>
* <li>prefixed with "pom." or "project."
* <ol>
* <li>MavenProject instance from current build</li>
* </ol>
* </li>
* <li>no prefix, using main project instance
* <ol>
* <li>MavenProject instance from current build</li>
* </ol>
* </li>
* <li>Support for special expressions, like ${dashClassifier?}</li>
* <li>user-defined properties from the command line</li>
* <li>properties from main project</li>
* <li>system properties, from the MavenSession instance (to support IDEs)</li>
* <li>environment variables.</li>
* </ol>
*/
public static String evaluateFileNameMapping(final String expression, @Nonnull final Artifact artifact, @Nullable final MavenProject mainProject, @Nullable final Artifact moduleArtifact, @Nonnull final AssemblerConfigurationSource configSource, FixedStringSearchInterpolator moduleProjectInterpolator, FixedStringSearchInterpolator artifactProjectInterpolator) throws AssemblyFormattingException {
String value = expression;
final FixedStringSearchInterpolator interpolator = FixedStringSearchInterpolator.create(moduleArtifactInterpolator(moduleArtifact), moduleProjectInterpolator, artifactInterpolator(artifact), artifactProjectInterpolator, mainProjectOnlyInterpolator(mainProject), classifierRules(artifact), executionPropertiesInterpolator(configSource), configSource.getMainProjectInterpolator(), configSource.getCommandLinePropsInterpolator(), configSource.getEnvInterpolator());
value = interpolator.interpolate(value);
value = StringUtils.replace(value, "//", "/");
value = StringUtils.replace(value, "\\\\", "\\");
value = fixRelativeRefs(value);
return value;
}
use of org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator in project maven-plugins by apache.
the class ModuleSetAssemblyPhase method createFileSet.
@Nonnull
FileSet createFileSet(@Nonnull final FileSet fileSet, @Nonnull final ModuleSources sources, @Nonnull final MavenProject moduleProject, @Nonnull final AssemblerConfigurationSource configSource) throws AssemblyFormattingException {
final FileSet fs = new FileSet();
String sourcePath = fileSet.getDirectory();
final File moduleBasedir = moduleProject.getBasedir();
if (sourcePath != null) {
final File sourceDir = new File(sourcePath);
if (!sourceDir.isAbsolute()) {
sourcePath = new File(moduleBasedir, sourcePath).getAbsolutePath();
}
} else {
sourcePath = moduleBasedir.getAbsolutePath();
}
fs.setDirectory(sourcePath);
fs.setDirectoryMode(fileSet.getDirectoryMode());
final List<String> excludes = new ArrayList<String>();
final List<String> originalExcludes = fileSet.getExcludes();
if ((originalExcludes != null) && !originalExcludes.isEmpty()) {
excludes.addAll(originalExcludes);
}
if (sources.isExcludeSubModuleDirectories()) {
final List<String> modules = moduleProject.getModules();
for (final String moduleSubPath : modules) {
excludes.add(moduleSubPath + "/**");
}
}
fs.setExcludes(excludes);
fs.setFiltered(fileSet.isFiltered());
fs.setFileMode(fileSet.getFileMode());
fs.setIncludes(fileSet.getIncludes());
fs.setLineEnding(fileSet.getLineEnding());
FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(moduleProject);
String destPathPrefix = "";
if (sources.isIncludeModuleDirectory()) {
destPathPrefix = AssemblyFormatUtils.evaluateFileNameMapping(sources.getOutputDirectoryMapping(), moduleProject.getArtifact(), configSource.getProject(), moduleProject.getArtifact(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
if (!destPathPrefix.endsWith("/")) {
destPathPrefix += "/";
}
}
String destPath = fileSet.getOutputDirectory();
if (destPath == null) {
destPath = destPathPrefix;
} else {
destPath = destPathPrefix + destPath;
}
destPath = AssemblyFormatUtils.getOutputDirectory(destPath, configSource.getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
fs.setOutputDirectory(destPath);
getLogger().debug("module source directory is: " + sourcePath);
getLogger().debug("module dest directory is: " + destPath + " (assembly basedir may be prepended)");
return fs;
}
use of org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator in project maven-plugins by apache.
the class AddDependencySetsTask method addNonArchiveDependency.
private void addNonArchiveDependency(final Artifact depArtifact, final MavenProject depProject, final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException {
final File source = depArtifact.getFile();
String outputDirectory = dependencySet.getOutputDirectory();
FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(depProject);
outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory, depProject.getBuild().getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
final String destName = AssemblyFormatUtils.evaluateFileNameMapping(dependencySet.getOutputFileNameMapping(), depArtifact, configSource.getProject(), moduleArtifact, configSource, moduleProjectInterpolator, artifactProjectInterpolator);
String target;
// omit the last char if ends with / or \\
if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
target = outputDirectory + destName;
} else {
target = outputDirectory + "/" + destName;
}
try {
final int mode = TypeConversionUtils.modeToInt(dependencySet.getFileMode(), logger);
if (mode > -1) {
archiver.addFile(source, target, mode);
} else {
archiver.addFile(source, target);
}
} catch (final ArchiverException e) {
throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
}
}
use of org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator in project maven-plugins by apache.
the class AssemblyFormatUtils method getOutputDirectory.
/**
* ORDER OF INTERPOLATION PRECEDENCE:
* <ol>
* <li>Support for special expressions, like ${finalName} (use the assembly plugin configuration not the build
* config)</li>
* <li>prefixed with "module." if moduleProject is non-null
* <ol>
* <li>MavenProject instance for module being assembled</li>
* </ol>
* </li>
* <li>prefixed with "artifact." if artifactProject is non-null
* <ol>
* <li>MavenProject instance for artifact</li>
* </ol>
* </li>
* <li>user-defined properties from the command line</li>
* <li>prefixed with "pom." or "project.", or no prefix at all
* <ol>
* <li>MavenProject instance from current build</li>
* </ol>
* </li>
* <li>properties from main project</li>
* <li>system properties, from the MavenSession instance (to support IDEs)</li>
* <li>environment variables.</li>
* </ol>
*/
public static String getOutputDirectory(final String output, final String finalName, final AssemblerConfigurationSource configSource, FixedStringSearchInterpolator moduleProjectIntrpolator, FixedStringSearchInterpolator artifactProjectInterpolator) throws AssemblyFormattingException {
String value = output;
if (value == null) {
value = "";
}
final FixedStringSearchInterpolator interpolator = FixedStringSearchInterpolator.create(finalNameInterpolator(finalName), moduleProjectIntrpolator, artifactProjectInterpolator, executionPropertiesInterpolator(configSource), configSource.getMainProjectInterpolator(), configSource.getCommandLinePropsInterpolator(), configSource.getEnvInterpolator());
value = interpolator.interpolate(value);
if ((value.length() > 0) && !value.endsWith("/") && !value.endsWith("\\")) {
value += "/";
}
if ((value.length() > 0) && (value.startsWith("/") || value.startsWith("\\"))) {
value = value.substring(1);
}
value = StringUtils.replace(value, "//", "/");
value = StringUtils.replace(value, "\\\\", "\\");
value = fixRelativeRefs(value);
return value;
}
Aggregations