Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.plugins.help;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 
 import java.util.List;
Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance of the global settings into the user-level settings.

Version:
$Id: EffectiveSettingsMojo.java 1446806 2013-02-15 23:07:28Z rfscholte $
Since:
2.0
 
 @Mojo( name = "effective-settings", requiresProject = false )
 public class EffectiveSettingsMojo
     extends AbstractEffectiveMojo
 {
     // ----------------------------------------------------------------------
     // Mojo parameters
     // ----------------------------------------------------------------------
 
    
The system settings for Maven. This is the instance resulting from merging global and user-level settings files.
 
     @Component
     private Settings settings;

    
For security reasons, all passwords are hidden by default. Set this to true to show all passwords.

Since:
2.1
 
     @Parameter( property = "showPasswords", defaultValue = "false" )
     private boolean showPasswords;
 
     // ----------------------------------------------------------------------
     // Public methods
     // ----------------------------------------------------------------------
 
    
 
     public void execute()
         throws MojoExecutionException
     {
         Settings copySettings;
         if (  )
         {
             copySettings = ;
         }
         else
         {
             copySettings = copySettings );
             hidePasswordscopySettings );
         }
 
         StringWriter w = new StringWriter();
         XMLWriter writer =
             new PrettyPrintXMLWriterw, StringUtils.repeat" ". ),
                                       copySettings.getModelEncoding(), null );
 
         writeHeaderwriter );
        writeEffectiveSettingscopySettingswriter );
        String effectiveSettings = w.toString();
        if (  != null )
        {
            try
            {
                writeXmlFileeffectiveSettingscopySettings.getModelEncoding() );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException"Cannot write effective-settings to output: " + e );
            }
            if ( getLog().isInfoEnabled() )
            {
                getLog().info"Effective-settings written to: " +  );
            }
        }
        else
        {
            StringBuilder message = new StringBuilder();
            message.append"\nEffective user-specific configuration settings:\n\n" );
            message.appendeffectiveSettings );
            message.append"\n" );
            if ( getLog().isInfoEnabled() )
            {
                getLog().infomessage.toString() );
            }
        }
    }
    // ----------------------------------------------------------------------
    // Private methods
    // ----------------------------------------------------------------------

    
Hide proxy and server passwords.

Parameters:
aSettings not null
    private static void hidePasswordsSettings aSettings )
    {
        List<Proxyproxies = aSettings.getProxies();
        for ( Proxy proxy : proxies )
        {
            if ( StringUtils.isNotEmptyproxy.getPassword() ) )
            {
                proxy.setPassword"***" );
            }
        }
        List<Serverservers = aSettings.getServers();
        for ( Server server : servers )
        {
            // Password
            if ( StringUtils.isNotEmptyserver.getPassword() ) )
            {
                server.setPassword"***" );
            }
            // Passphrase
            if ( StringUtils.isNotEmptyserver.getPassphrase() ) )
            {
                server.setPassphrase"***" );
            }
        }
    }

    

Parameters:
settings could be null
Returns:
a new instance of settings or null if settings was null.
    private static Settings copySettingsSettings settings )
    {
        if ( settings == null )
        {
            return null;
        }
        
        // Not a deep copy in M2.2.1 !!!
        Settings clone = SettingsUtils.copySettingssettings );
        List<ServerclonedServers = new ArrayList<Server>( settings.getServers().size() );
        for ( Server server : settings.getServers() )
        {
            Server clonedServer = new Server();
            clonedServer.setConfigurationserver.getConfiguration() );
            clonedServer.setDirectoryPermissionsserver.getDirectoryPermissions() );
            clonedServer.setFilePermissionsserver.getFilePermissions() );
            clonedServer.setIdserver.getId() );
            clonedServer.setPassphraseserver.getPassphrase() );
            clonedServer.setPasswordserver.getPassword() );
            clonedServer.setPrivateKeyserver.getPrivateKey() );
            clonedServer.setSourceLevelserver.getSourceLevel() );
            clonedServer.setUsernameserver.getUsername() );
            
            clonedServers.addclonedServer );
        }
        clone.setServersclonedServers );
        
        List<ProxyclonedProxies = new ArrayList<Proxy>( settings.getProxies().size() );
        for ( Proxy proxy : settings.getProxies() )
        {
            Proxy clonedProxy = new Proxy();
            clonedProxy.setActiveproxy.isActive() );
            clonedProxy.setHostproxy.getHost() );
            clonedProxy.setIdproxy.getId() );
            clonedProxy.setNonProxyHostsproxy.getNonProxyHosts() );
            clonedProxy.setPasswordproxy.getPassword() );
            clonedProxy.setPortproxy.getPort() );
            clonedProxy.setProtocolproxy.getProtocol() );
            clonedProxy.setSourceLevelproxy.getSourceLevel() );
            clonedProxy.setUsernameproxy.getUsername() );
            
            clonedProxies.addclonedProxy );
        }
        clone.setProxiesclonedProxies );
        
        return clone;
    }

    
Method for writing the effective settings informations.

Parameters:
settings the settings, not null.
writer the XML writer used, not null.
Throws:
org.apache.maven.plugin.MojoExecutionException if any
    private static void writeEffectiveSettingsSettings settingsXMLWriter writer )
        throws MojoExecutionException
    {
        cleanSettingssettings );
        String effectiveSettings;
        StringWriter sWriter = new StringWriter();
        SettingsXpp3Writer settingsWriter = new SettingsXpp3Writer();
        try
        {
            settingsWriter.writesWritersettings );
        }
        catch ( IOException e )
        {
            throw new MojoExecutionException"Cannot serialize Settings to XML."e );
        }
        effectiveSettings = addMavenNamespacesWriter.toString(), false );
        writeCommentwriter"Effective Settings for '" + getUserName() + "' on '" + getHostName() + "'" );
        writer.writeMarkupeffectiveSettings );
    }

    
Apply some logic to clean the model before writing it.

Parameters:
settings not null
    private static void cleanSettingsSettings settings )
    {
        List<Profileprofiles = settings.getProfiles();
        for ( Profile profile : profiles )
        {
            Properties properties = new SortedProperties();
            properties.putAllprofile.getProperties() );
            profile.setPropertiesproperties );
        }
    }

    

Returns:
the current host name or unknown if error
See also:
java.net.InetAddress.getLocalHost()
    private static String getHostName()
    {
        try
        {
            return InetAddress.getLocalHost().getHostName();
        }
        catch ( UnknownHostException e )
        {
            return "unknown";
        }
    }

    

Returns:
the user name or unknown if user.name is not a system property.
    private static String getUserName()
    {
        String userName = System.getProperty"user.name" );
        if ( StringUtils.isEmptyuserName ) )
        {
            return "unknown";
        }
        return userName;
    }
New to GrepCode? Check out our FAQ X