org.sonatype.plexus.components.sec.dispatcher.SecDispatcher Java Examples

The following examples show how to use org.sonatype.plexus.components.sec.dispatcher.SecDispatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlExecMojoTest.java    From sql-maven-plugin with Apache License 2.0 5 votes vote down vote up
public void setUp()
    throws Exception
{
    super.setUp();
    p = new Properties();
    p.load( getClass().getResourceAsStream( "/test.properties" ) );

    mojo = new SqlExecMojo();

    // populate parameters
    mojo.setDriver( p.getProperty( "driver" ) );
    mojo.setUsername( p.getProperty( "user" ) );
    mojo.setPassword( p.getProperty( "password" ) );
    mojo.setUrl( p.getProperty( "url" ) );
    mojo.setDriverProperties( p.getProperty( "driverProperties" ) );
    mojo.setSqlCommand( null );
    mojo.setDelimiter( SqlExecMojo.DEFAULT_DELIMITER );// This will simulate the defaultValue of @Parameter (...)
    mojo.setOnError( SqlExecMojo.ON_ERROR_ABORT );
    mojo.setDelimiterType( DelimiterType.NORMAL );
    mojo.setEscapeProcessing( true );

    MavenFileFilter filter =
        (MavenFileFilter) lookup( "org.apache.maven.shared.filtering.MavenFileFilter", "default" );
    mojo.setFileFilter( filter );

    SecDispatcher securityDispatcher =
        (SecDispatcher) lookup( "org.sonatype.plexus.components.sec.dispatcher.SecDispatcher", "default" );
    mojo.setSecurityDispatcher( securityDispatcher );

    MavenProject project = new MavenProjectStub();
    setVariableValueToObject( mojo, "project", project );
}
 
Example #2
Source File: AuthConfigFactoryTest.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Before
public void containerSetup() throws ComponentLookupException {
    final SecDispatcher secDispatcher = new MockSecDispatcher();
    new Expectations() {{
        container.lookup(SecDispatcher.ROLE, "maven"); minTimes = 0; result = secDispatcher;

    }};
    factory = new AuthConfigFactory(container);
    factory.setLog(log);

    gsonBuilder = new GsonBuilder();
}
 
Example #3
Source File: AbstractHelmMojo.java    From helm-maven-plugin with MIT License 4 votes vote down vote up
protected SecDispatcher getSecDispatcher() {
	if (securityDispatcher instanceof DefaultSecDispatcher) {
		((DefaultSecDispatcher) securityDispatcher).setConfigurationFile(getHelmSecurity());
	}
	return securityDispatcher;
}
 
Example #4
Source File: MojoExtension.java    From helm-maven-plugin with MIT License 4 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) throws ParameterResolutionException {
    try {

        // get descriptor

        Class<? extends AbstractHelmMojo> mojoType = (Class<AbstractHelmMojo>) parameterContext.getParameter().getType();
        MojoDescriptor descriptor = mojoDescriptors.get(mojoType);
        assertNotNull(descriptor, "Plugin descriptor for " + mojoType.getSimpleName() + " not found, run 'maven-plugin-plugin:descriptor'.");

        // create mojo with default values

        AbstractHelmMojo mojo = spy(mojoType);
        for (Parameter parameter : descriptor.getParameters()) {
            if (parameter.getDefaultValue() == null || !parameter.isEditable() || parameter.getType().equals("boolean")) {
                continue;
            }
            getField(mojoType, parameter.getName()).set(mojo, resolve(context, parameter.getDefaultValue()));
        }

        // read mojo values from annotations

        MojoProperty[] mojoProperties = ArrayUtils.addAll(
                context.getRequiredTestClass().getAnnotationsByType(MojoProperty.class),
                context.getRequiredTestMethod().getAnnotationsByType(MojoProperty.class));
        for (MojoProperty mojoProperty : mojoProperties) {
            getField(mojoType, mojoProperty.name()).set(mojo, resolve(context, mojoProperty.value()));
        }

        // settings

        getField(mojoType, "settings").set(mojo, new Settings());
        
        // plexus SecDispatcher

        SecDispatcher secDispatcher = spy(DefaultSecDispatcher.class);
        FieldSetter.setField(secDispatcher, DefaultSecDispatcher.class.getDeclaredField("_cipher"), new DefaultPlexusCipher());
        getField(mojoType, "securityDispatcher").set(mojo, secDispatcher);

        // validate that every parameter is set

        for (Parameter paramter : descriptor.getParameters()) {
            if (paramter.isRequired()) {
                assertNotNull(
                        getField(mojoType, paramter.getName()).get(mojo),
                        "Parameter '" + paramter.getName() + "' not set for mojo '" + mojoType.getSimpleName() + "'.");
            }
        }

        return mojo;
    } catch (ReflectiveOperationException | PlexusCipherException e) {
        throw new ParameterResolutionException("Failed to setup mockito.", e);
    }
}
 
Example #5
Source File: SqlExecMojo.java    From sql-maven-plugin with Apache License 2.0 4 votes vote down vote up
public void setSecurityDispatcher( SecDispatcher securityDispatcher )
{
    this.securityDispatcher = securityDispatcher;
}