Search in sources :

Example 36 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getAuthenticationInfo.

private AuthenticationInfo getAuthenticationInfo(String id) {
    MavenSession session = legacySupport.getSession();
    if (session != null && id != null) {
        MavenExecutionRequest request = session.getRequest();
        if (request != null) {
            List<Server> servers = request.getServers();
            if (servers != null) {
                for (Server server : servers) {
                    if (id.equalsIgnoreCase(server.getId())) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server));
                        server = result.getServer();
                        AuthenticationInfo authInfo = new AuthenticationInfo();
                        authInfo.setUserName(server.getUsername());
                        authInfo.setPassword(server.getPassword());
                        authInfo.setPrivateKey(server.getPrivateKey());
                        authInfo.setPassphrase(server.getPassphrase());
                        return authInfo;
                    }
                }
            }
        }
    }
    // empty one to prevent NPE
    return new AuthenticationInfo();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Server(org.apache.maven.settings.Server) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo)

Example 37 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getMirror.

private Mirror getMirror(String repoId) {
    MavenSession session = legacySupport.getSession();
    MavenExecutionRequest request = session.getRequest();
    if (request != null) {
        return getMirror(repoId, request.getMirrors());
    }
    return null;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest)

Example 38 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class AssemblyInterpolatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.

public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final Properties props = new Properties();
    props.setProperty("groupId", "other.id");
    model.setProperties(props);
    final Assembly assembly = new Assembly();
    assembly.setId("assembly.${groupId}");
    final EasyMockSupport mm = new EasyMockSupport();
    final MavenSession session = mm.createMock(MavenSession.class);
    final Properties execProps = new Properties();
    execProps.setProperty("groupId", "still.another.id");
    expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final PojoConfigSource cs = new PojoConfigSource();
    final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
    cs.setLocalRepository(lr);
    cs.setMavenSession(session);
    cs.setRootInterpolator(FixedStringSearchInterpolator.create());
    cs.setEnvironmentInterpolator(FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(execProps)));
    cs.setEnvInterpolator(FixedStringSearchInterpolator.empty());
    expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
    mm.replayAll();
    final MavenProject project = new MavenProject(model);
    cs.setMavenProject(project);
    final Assembly result = roundTripInterpolation(assembly, cs);
    assertEquals("assembly.still.another.id", result.getId());
    mm.verifyAll();
    mm.resetAll();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 39 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class AbstractAssemblyMojo method createCommandLinePropertiesInterpolator.

private FixedStringSearchInterpolator createCommandLinePropertiesInterpolator() {
    Properties commandLineProperties = System.getProperties();
    final MavenSession session = getMavenSession();
    if (session != null) {
        commandLineProperties = new Properties();
        commandLineProperties.putAll(session.getSystemProperties());
        commandLineProperties.putAll(session.getUserProperties());
    }
    PropertiesBasedValueSource cliProps = new PropertiesBasedValueSource(commandLineProperties);
    return FixedStringSearchInterpolator.create(cliProps);
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) Properties(java.util.Properties) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.fixed.PropertiesBasedValueSource)

Example 40 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-plugins by apache.

the class AssemblyFormatUtilsTest method verifyEvalFileNameMapping.

private void verifyEvalFileNameMapping(final String expression, final String classifier, final String extension, final MavenProject mainProject, final MavenProject moduleProject, final MavenProject artifactProject, final String checkValue) throws AssemblyFormattingException {
    final ArtifactMock artifactMock = new ArtifactMock(mockManager, artifactProject.getGroupId(), artifactProject.getArtifactId(), artifactProject.getVersion(), extension, classifier, false, null);
    final ArtifactMock moduleArtifactMock = new ArtifactMock(mockManager, moduleProject.getGroupId(), moduleProject.getArtifactId(), moduleProject.getVersion(), "jar", false, null);
    final MavenSession session = mockManager.createMock(MavenSession.class);
    expect(session.getExecutionProperties()).andReturn(System.getProperties()).anyTimes();
    expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
    final AssemblerConfigurationSource cs = mockManager.createMock(AssemblerConfigurationSource.class);
    expect(cs.getMavenSession()).andReturn(session).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(cs, mainProject);
    mockManager.replayAll();
    final String result = AssemblyFormatUtils.evaluateFileNameMapping(expression, artifactMock.getArtifact(), mainProject, moduleArtifactMock.getArtifact(), cs, AssemblyFormatUtils.moduleProjectInterpolator(moduleProject), AssemblyFormatUtils.artifactProjectInterpolator(artifactProject));
    /*
                final String result =
            AssemblyFormatUtils.evaluateFileNameMapping( expression,
                                                         moduleArtifactInterpolator( moduleArtifactMock.getArtifact() ),
                                                         moduleProjectInterpolator( moduleProject ),
                                                         artifactInterpolator( artifactMock.getArtifact() ),
                                                         artifactProjectInterpolator( artifactProject ),
                                                         mainArtifactPropsOnly( mainProject ),
                                                         classifierRules( artifactMock.getArtifact() ),
                                                         FixedStringSearchInterpolator.create( new
                                                         PropertiesBasedValueSource( System.getProperties()  )) );

         */
    assertEquals(checkValue, result);
    mockManager.verifyAll();
    // clear out for next call.
    mockManager.resetAll();
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) Properties(java.util.Properties)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)117 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)19 Properties (java.util.Properties)18 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)11 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6