Package org.apache.maven.settings

Examples of org.apache.maven.settings.Settings


    /** {@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 );
            }
View Full Code Here


        {
            return null;
        }
       
        // Not a deep copy in M2.2.1 !!!
        Settings clone = SettingsUtils.copySettings( settings );

        List<Server> clonedServers = new ArrayList<Server>( settings.getServers().size() );
        for ( Server server : settings.getServers() )
        {
            Server clonedServer = new Server();
            clonedServer.setConfiguration( server.getConfiguration() );
            clonedServer.setDirectoryPermissions( server.getDirectoryPermissions() );
            clonedServer.setFilePermissions( server.getFilePermissions() );
            clonedServer.setId( server.getId() );
            clonedServer.setPassphrase( server.getPassphrase() );
            clonedServer.setPassword( server.getPassword() );
            clonedServer.setPrivateKey( server.getPrivateKey() );
            clonedServer.setSourceLevel( server.getSourceLevel() );
            clonedServer.setUsername( server.getUsername() );
           
            clonedServers.add( clonedServer );
        }
        clone.setServers( clonedServers );
       
        List<Proxy> clonedProxies = new ArrayList<Proxy>( settings.getProxies().size() );
        for ( Proxy proxy : settings.getProxies() )
        {
            Proxy clonedProxy = new Proxy();
            clonedProxy.setActive( proxy.isActive() );
            clonedProxy.setHost( proxy.getHost() );
            clonedProxy.setId( proxy.getId() );
            clonedProxy.setNonProxyHosts( proxy.getNonProxyHosts() );
            clonedProxy.setPassword( proxy.getPassword() );
            clonedProxy.setPort( proxy.getPort() );
            clonedProxy.setProtocol( proxy.getProtocol() );
            clonedProxy.setSourceLevel( proxy.getSourceLevel() );
            clonedProxy.setUsername( proxy.getUsername() );
           
            clonedProxies.add( clonedProxy );
        }
        clone.setProxies( clonedProxies );
       
        return clone;
    }
View Full Code Here

        throws Exception
    {
        InvokerMojo invokerMojo = new InvokerMojo();
        setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
        setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
        setVariableValueToObject( invokerMojo, "settings", new Settings() );
        Properties properties = new Properties();
        properties.put( "cleanProps", "clean" );
        properties.put( "version", "2.0-SNAPSHOT" );
        setVariableValueToObject( invokerMojo, "interpolationsProperties", properties );
        String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test"
View Full Code Here

        try
        {
            InvokerMojo invokerMojo = new InvokerMojo();
            setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
            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, "interpolationsProperties", properties );
            String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test"
View Full Code Here

        throws Exception
    {
        InvokerMojo invokerMojo = new InvokerMojo();
        setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
        setVariableValueToObject( invokerMojo, "profilesFile", "profiles.txt" );
        setVariableValueToObject( invokerMojo, "settings", new Settings() );
        String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
            + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
        List profiles = invokerMojo.getProfiles( new File( dirPath ) );
        assertEquals( 2, profiles.size() );
        assertTrue( profiles.contains( "foo" ) );
View Full Code Here

        InvokerMojo invokerMojo = new InvokerMojo();
        setVariableValueToObject( invokerMojo, "project", buildMavenProjectStub() );
        setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] { "zloug" } ) );
        setVariableValueToObject( invokerMojo, "profilesFile", "emptyProfiles.txt" );
        setVariableValueToObject( invokerMojo, "settings", new Settings() );
        String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
            + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
        List profiles = invokerMojo.getProfiles( new File( dirPath ) );
        assertFalse( profiles.contains( "zloug" ) );
        assertEquals( 0, profiles.size() );
View Full Code Here

    {

        InvokerMojo invokerMojo = new InvokerMojo();
        setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( new String[] { "zloug" } ) );
        setVariableValueToObject( invokerMojo, "profilesFile", "zorglubProfiles.txt" );
        setVariableValueToObject( invokerMojo, "settings", new Settings() );
        String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar
            + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file";
        List profiles = invokerMojo.getProfiles( new File( dirPath ) );
        assertTrue( profiles.contains( "zloug" ) );
        assertEquals( 1, profiles.size() );
View Full Code Here

        project.setTestClasspathElements( Collections.EMPTY_LIST );

        InvokerMojo invokerMojo = new InvokerMojo();
        setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
        setVariableValueToObject( invokerMojo, "project", project );
        setVariableValueToObject( invokerMojo, "settings", new Settings() );
        String dirPath = getBasedir() + "/src/test/resources/unit/goals-from-file/";
        List goals = invokerMojo.getGoals( new File( dirPath ) );
        assertEquals( 3, goals.size() );
    }
View Full Code Here

            Properties executionProperties = new Properties();
            Properties userProperties = new Properties();
            populateProperties( commandLine, executionProperties, userProperties );

            Settings settings;

            try
            {
                settings = buildSettings( commandLine );
            }
            catch ( SettingsConfigurationException e )
            {
                showError( "Error reading settings.xml: " + e.getMessage(), e, showErrors );

                return 1;
            }
            catch ( ComponentLookupException e )
            {
                showFatalError( "Unable to read settings.xml", e, showErrors );

                return 1;
            }

            DefaultSecDispatcher dispatcher;
            try
            {
                if ( commandLine.hasOption( CLIManager.ENCRYPT_MASTER_PASSWORD ) )
                {
                    String passwd = commandLine.getOptionValue( CLIManager.ENCRYPT_MASTER_PASSWORD );

                    DefaultPlexusCipher cipher = new DefaultPlexusCipher();

                    System.out.println( cipher.encryptAndDecorate( passwd,
                                                                   DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) );
                   
                    return 0;
                }
                else if ( commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
                {
                    String passwd = commandLine.getOptionValue( CLIManager.ENCRYPT_PASSWORD );
                   
                    dispatcher = (DefaultSecDispatcher) embedder.lookup( SecDispatcher.ROLE );
                    String configurationFile = dispatcher.getConfigurationFile();
                    if ( configurationFile.startsWith( "~" ) )
                    {
                        configurationFile = System.getProperty( "user.home" ) + configurationFile.substring( 1 );
                    }
                    String file = System.getProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile );
                    embedder.release( dispatcher );
                   
                    String master = null;
                   
                    SettingsSecurity sec = SecUtil.read( file, true );
                    if ( sec != null )
                    {
                        master = sec.getMaster();
                    }

                    if ( master == null )
                    {
                        System.err.println( "Master password is not set in the setting security file" );
                       
                        return 1;
                    }
                   
                    DefaultPlexusCipher cipher = new DefaultPlexusCipher();
                    String masterPasswd =
                        cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION );
                    System.out.println( cipher.encryptAndDecorate( passwd, masterPasswd ) );
                   
                    return 0;
                }
            }
            catch ( Exception e )
            {
                showFatalError( "Error encrypting password: " + e.getMessage(), e, showErrors );
               
                return 1;
            }
               
            Maven maven = null;

            MavenExecutionRequest request = null;

            LoggerManager loggerManager = null;

            try
            {
                // logger must be created first
                loggerManager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );

                if ( debug )
                {
                    loggerManager.setThreshold( Logger.LEVEL_DEBUG );
                }
                else if ( commandLine.hasOption( CLIManager.QUIET ) )
                {
                    // TODO: we need to do some more work here. Some plugins use sys out or log errors at info level.
                    // Ideally, we could use Warn across the board
                    loggerManager.setThreshold( Logger.LEVEL_ERROR );
                    // TODO:Additionally, we can't change the mojo level because the component key includes the version and it isn't known ahead of time. This seems worth changing.
                }

                ProfileManager profileManager = new DefaultProfileManager( embedder.getContainer(), executionProperties );

                if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
                {
                    String [] profileOptionValues = commandLine.getOptionValues( CLIManager.ACTIVATE_PROFILES );

                    if ( profileOptionValues != null )
                    {
                        for ( int i=0; i < profileOptionValues.length; ++i )
                        {
                            StringTokenizer profileTokens = new StringTokenizer( profileOptionValues[i], "," );

                            while ( profileTokens.hasMoreTokens() )
                            {
                                String profileAction = profileTokens.nextToken().trim();

                                if ( profileAction.startsWith( "-" ) || profileAction.startsWith( "!" ) )
                                {
                                    profileManager.explicitlyDeactivate( profileAction.substring( 1 ) );
                                }
                                else if ( profileAction.startsWith( "+" ) )
                                {
                                    profileManager.explicitlyActivate( profileAction.substring( 1 ) );
                                }
                                else
                                {
                                    profileManager.explicitlyActivate( profileAction );
                                }
                            }
                        }
                    }
                }

                request = createRequest( commandLine, settings, eventDispatcher, loggerManager, profileManager,
                                         executionProperties, userProperties, showErrors );

                setProjectFileOptions( commandLine, request );

                maven =
                    createMavenInstance( settings.isInteractiveMode(),
                                         loggerManager.getLoggerForComponent( WagonManager.ROLE ) );
            }
            catch ( ComponentLookupException e )
            {
                showFatalError( "Unable to configure the Maven application", e, showErrors );
View Full Code Here

        {
            String globalSettingsPath = commandLine.getOptionValue( CLIManager.ALTERNATE_GLOBAL_SETTINGS );
            System.setProperty( MavenSettingsBuilder.ALT_GLOBAL_SETTINGS_XML_LOCATION, globalSettingsPath );
        }

        Settings settings = null;

        MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );

        try
        {
            if ( userSettingsPath != null )
            {
                File userSettingsFile = new File( userSettingsPath );

                if ( userSettingsFile.exists() && !userSettingsFile.isDirectory() )
                {
                    settings = settingsBuilder.buildSettings( userSettingsFile );
                }
                else
                {
                    System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath +
                        " is invalid. Using default path." );
                }
            }

            if ( settings == null )
            {
                settings = settingsBuilder.buildSettings();
            }
        }
        catch ( IOException e )
        {
            throw new SettingsConfigurationException( "Error reading settings file", e );
        }
        catch ( XmlPullParserException e )
        {
            throw new SettingsConfigurationException( e.getMessage(), e, e.getLineNumber(),
                                                      e.getColumnNumber() );
        }

        // why aren't these part of the runtime info? jvz.

        if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
        {
            settings.setInteractiveMode( false );
        }

        if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_REGISTRY ) )
        {
            settings.setUsePluginRegistry( false );
        }

        // Create settings runtime info

        settings.setRuntimeInfo( createRuntimeInfo( commandLine, settings ) );

        return settings;
    }
View Full Code Here

TOP

Related Classes of org.apache.maven.settings.Settings

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.