Search in sources :

Example 16 with Settings

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;
}
Also used : Settings(org.apache.maven.settings.Settings)

Example 17 with Settings

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;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) IOException(java.io.IOException) File(java.io.File) Settings(org.apache.maven.settings.Settings) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 18 with Settings

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);
    }
}
Also used : InvokerMojo(org.apache.maven.plugins.invoker.InvokerMojo) Reader(java.io.Reader) Properties(java.util.Properties) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Example 19 with Settings

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);
}
Also used : MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) Settings(org.apache.maven.settings.Settings)

Example 20 with Settings

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());
    }
}
Also used : StringWriter(java.io.StringWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) XMLWriter(org.codehaus.plexus.util.xml.XMLWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) Settings(org.apache.maven.settings.Settings)

Aggregations

Settings (org.apache.maven.settings.Settings)27 File (java.io.File)15 Proxy (org.apache.maven.settings.Proxy)6 IOException (java.io.IOException)5 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)5 MavenProject (org.apache.maven.project.MavenProject)4 Server (org.apache.maven.settings.Server)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 SettingsBuildingRequest (org.apache.maven.settings.building.SettingsBuildingRequest)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 MavenSession (org.apache.maven.execution.MavenSession)3 AbstractMojo (org.apache.maven.plugin.AbstractMojo)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SiteMavenProjectStub (org.apache.maven.plugins.site.stubs.SiteMavenProjectStub)3 SettingsDecryptionResult (org.apache.maven.settings.crypto.SettingsDecryptionResult)3 StringWriter (java.io.StringWriter)2 Properties (java.util.Properties)2 Maven2Gradle (org.gradle.buildinit.plugins.internal.maven.Maven2Gradle)2 MavenConversionException (org.gradle.buildinit.plugins.internal.maven.MavenConversionException)2