use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class AbstractInvokerMojo method cloneSettings.
private Settings cloneSettings() {
Settings recessiveSettings = SettingsUtils.copySettings(this.settings);
// MINVOKER-133: reset sourceLevelSet
resetSourceLevelSet(recessiveSettings);
for (org.apache.maven.settings.Mirror mirror : recessiveSettings.getMirrors()) {
resetSourceLevelSet(mirror);
}
for (org.apache.maven.settings.Server server : recessiveSettings.getServers()) {
resetSourceLevelSet(server);
}
for (org.apache.maven.settings.Proxy proxy : recessiveSettings.getProxies()) {
resetSourceLevelSet(proxy);
}
for (org.apache.maven.settings.Profile profile : recessiveSettings.getProfiles()) {
resetSourceLevelSet(profile);
}
return recessiveSettings;
}
use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class AbstractInvokerMojo method mergeSettings.
/**
* Merge the settings file
*
* @param interpolatedSettingsFile The interpolated settings file.
* @return The merged settings file.
* @throws MojoExecutionException Fail the build in case the merged settings file can't be created.
*/
private File mergeSettings(File interpolatedSettingsFile) throws MojoExecutionException {
File mergedSettingsFile;
Settings mergedSettings = this.settings;
if (mergeUserSettings) {
if (interpolatedSettingsFile != null) {
// Have to merge the specified settings file (dominant) and the one of the invoking Maven process
try {
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setGlobalSettingsFile(interpolatedSettingsFile);
Settings dominantSettings = settingsBuilder.build(request).getEffectiveSettings();
Settings recessiveSettings = cloneSettings();
SettingsUtils.merge(dominantSettings, recessiveSettings, TrackableBase.USER_LEVEL);
mergedSettings = dominantSettings;
getLog().debug("Merged specified settings file with settings of invoking process");
} catch (SettingsBuildingException e) {
throw new MojoExecutionException("Could not read specified settings file", e);
}
}
}
if (this.settingsFile != null && !mergeUserSettings) {
mergedSettingsFile = interpolatedSettingsFile;
} else {
try {
mergedSettingsFile = writeMergedSettingsFile(mergedSettings);
} catch (IOException e) {
throw new MojoExecutionException("Could not create temporary file for invoker settings.xml", e);
}
}
return mergedSettingsFile;
}
use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class InterpolationTest method testPomInterpolation.
public void testPomInterpolation() throws Exception {
Reader reader = null;
File interpolatedPomFile;
try {
InvokerMojo invokerMojo = new InvokerMojo();
setVariableValueToObject(invokerMojo, "project", buildMavenProjectStub());
setVariableValueToObject(invokerMojo, "settings", new Settings());
Properties properties = new Properties();
properties.put("foo", "bar");
properties.put("version", "2.0-SNAPSHOT");
setVariableValueToObject(invokerMojo, "filterProperties", properties);
String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar + "interpolation";
interpolatedPomFile = new File(getBasedir(), "target/interpolated-pom.xml");
invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile);
reader = ReaderFactory.newXmlReader(interpolatedPomFile);
String content = IOUtil.toString(reader);
assertTrue(content.indexOf("<interpolateValue>bar</interpolateValue>") > 0);
reader.close();
reader = null;
// recreate it to test delete if exists before creation
invokerMojo.buildInterpolatedFile(new File(dirPath, "pom.xml"), interpolatedPomFile);
reader = ReaderFactory.newXmlReader(interpolatedPomFile);
content = IOUtil.toString(reader);
assertTrue(content.indexOf("<interpolateValue>bar</interpolateValue>") > 0);
reader.close();
reader = null;
} finally {
IOUtil.close(reader);
}
}
use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class EvaluateMojoTest method setUpMojo.
private void setUpMojo(EvaluateMojo mojo, InputHandler inputHandler, ExpressionEvaluator expressionEvaluator) throws IllegalAccessException {
setVariableValueToObject(mojo, "inputHandler", inputHandler);
setVariableValueToObject(mojo, "log", interceptingLogger);
setVariableValueToObject(mojo, "settings", new Settings());
setVariableValueToObject(mojo, "project", new MavenProjectStub());
setVariableValueToObject(mojo, "evaluator", expressionEvaluator);
}
use of org.apache.maven.settings.Settings in project maven-plugins by apache.
the class EffectiveSettingsMojo method execute.
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
Settings copySettings;
if (showPasswords) {
copySettings = settings;
} else {
copySettings = copySettings(settings);
hidePasswords(copySettings);
}
StringWriter w = new StringWriter();
XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), copySettings.getModelEncoding(), null);
writeHeader(writer);
writeEffectiveSettings(copySettings, writer);
String effectiveSettings = w.toString();
if (output != null) {
try {
writeXmlFile(output, effectiveSettings, copySettings.getModelEncoding());
} catch (IOException e) {
throw new MojoExecutionException("Cannot write effective-settings to output: " + output, e);
}
getLog().info("Effective-settings written to: " + output);
} else {
StringBuilder message = new StringBuilder();
message.append(LS).append("Effective user-specific configuration settings:").append(LS).append(LS);
message.append(effectiveSettings);
message.append(LS);
getLog().info(message.toString());
}
}
Aggregations