Example usage for org.apache.maven.execution MavenSession getRequest

List of usage examples for org.apache.maven.execution MavenSession getRequest

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenSession getRequest.

Prototype

public MavenExecutionRequest getRequest() 

Source Link

Usage

From source file:co.leantechniques.maven.h2.H2TestRepository.java

License:Apache License

private long getBuildId(MavenSession session) {
    return session.getRequest().getStartTime().getTime();
}

From source file:co.leantechniques.maven.h2.H2TestRepository.java

License:Apache License

public void assertEndOfBuild(MavenSession session) {
    Date startTime = session.getRequest().getStartTime();

    int count = handle.createQuery("select count(1) from build where id =? and end_time is not null")
            .bind(0, startTime.getTime()).mapTo(Integer.class).first();

    assertEquals(1, count);/*w w w.  j  a  va  2s.c om*/
}

From source file:co.leantechniques.maven.h2.H2TestRepository.java

License:Apache License

public void assertMachineInfoStored(MavenSession session) {
    MavenExecutionRequest request = session.getRequest();
    Map<String, Object> machineInfo = handle.createQuery(
            "select * from machine_info mi inner join build b on mi.id = b.machine_info_id and b.id = ?")
            .bind(0, request.getStartTime().getTime()).first();
    assertNotNull("we did not find machine info for the build", machineInfo);
    Properties systemProperties = request.getSystemProperties();
    assertEquals(systemProperties.get("maven.version"), machineInfo.get("maven_version"));
    assertEquals(systemProperties.get("java.version"), machineInfo.get("java_version"));
    assertEquals(systemProperties.get("env.COMPUTERNAME"), machineInfo.get("computer_name"));
    assertEquals(systemProperties.get("os.name"), machineInfo.get("os"));
    assertEquals(systemProperties.get("user.name"), machineInfo.get("username"));
    assertEquals(systemProperties.get("os.arch"), machineInfo.get("os_arch"));
}

From source file:co.leantechniques.maven.h2.H2TestRepository.java

License:Apache License

public void assertCodeRevision(MavenSession session, CodeRevision codeRevision) {
    MavenExecutionRequest request = session.getRequest();
    Map<String, Object> build = handle.createQuery("select * from build where id = ?")
            .bind(0, request.getStartTime().getTime()).first();
    assertEquals(codeRevision.scm, build.get("scm"));
    assertEquals(codeRevision.revision, build.get("scm_revision"));
}

From source file:com.basistech.mext.VersionGeneratorLifecycleParticipant.java

License:Open Source License

@Override
public void afterSessionStart(MavenSession session) throws MavenExecutionException {
    File projectBase = new File(session.getRequest().getBaseDirectory());
    File policyFile = new File(projectBase, "version-policy.txt");
    if (policyFile.exists()) {
        String template;//from  w  w w  . j  a  v  a 2s . c  o  m
        try {
            template = fileContents(policyFile);
        } catch (IOException e) {
            throw new MavenExecutionException("Failed to read " + policyFile.getAbsolutePath(), e);
        }

        String[] bits = template.split("=");
        String prop = bits[0];
        String valueTemplate = bits[1];

        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = format.format(new Date());
        String rev = valueTemplate.replace("${timestamp}", timestamp);
        LOG.info("Setting {} to {}", prop, rev);
        session.getUserProperties().put(prop, rev);
    }
}

From source file:com.github.htfv.maven.plugins.buildconfigurator.core.configurators.propertyfiles.PropertyFileConfigurator.java

License:Apache License

/**
 * Reinterpolates all elements of the project model.
 *
 * @param ctx//w w  w.  j a  v a  2 s  . com
 *            The configuration context.
 * @param resultBuilder
 *            The result builder.
 */
private void reinterpolateProjectModel(final ConfigurationContext ctx, final Result.Builder resultBuilder) {
    //
    // Maven interpolates expressions when it loads the model. Since the
    // properties are loaded after the model, we have to interpolate
    // expressions again.
    //
    // It is actually not required for mojo parameters, because parameters
    // are interpolated before mojo is executed. However, it can be a
    // problem if mojo accesses model, like maven-resources-plugin accessing
    // project.build.resources.
    //
    // We take a conservative approach and only replace properties which
    // were loaded by the build configurator.
    //

    final ModelInterpolator interpolator = new ModelInterpolator(resultBuilder.newProperties());

    interpolator.interpolateModel(ctx.getProject().getModel());

    //
    // Maven interpolates mojo parameters before execution, but it skips
    // parameters of the PlexusConfiguration type. Updating the model now
    // has no effect, because execution plan is already calculated and mojo
    // configuration is copied to mojo execution. We cannot get access to
    // mojo execution, so we register a listener which will be called before
    // mojo is executed.
    //

    if (!ctx.getRequest().isConnectorRequest()) {
        final MavenSession mavenSession = ctx.getMavenSession();
        final MavenExecutionRequest executionRequest = mavenSession.getRequest();
        final ExecutionListener executionListener = executionRequest.getExecutionListener();

        executionRequest.setExecutionListener(new DelegatingExecutionListener(executionListener) {
            @Override
            public void mojoStarted(final ExecutionEvent event) {
                interpolator.interpolateDOM(event.getMojoExecution().getConfiguration());

                super.mojoStarted(event);
            }

            @Override
            public void projectFailed(final ExecutionEvent event) {
                event.getSession().getRequest().setExecutionListener(getDelegate());
                super.projectFailed(event);
            }

            @Override
            public void projectSucceeded(final ExecutionEvent event) {
                event.getSession().getRequest().setExecutionListener(getDelegate());
                super.projectSucceeded(event);
            }
        });
    }
}

From source file:com.sumologic.maven.stats.SumoLogicProfilingParticipant.java

License:Apache License

private void ensureInstalled(MavenSession session) {
    if (!installed) {
        synchronized (this) {
            if (!installed) { // Double lock makes this thread safe and does not repeat the work
                MavenExecutionRequest request = session.getRequest();
                ExecutionListener currentListener = request.getExecutionListener();

                String sumoEndpoint = session.getCurrentProject().getProperties()
                        .getProperty("sumologic.http.endpoint");
                ProfilingSerializer serializer = new JsonProfilingSerializer();
                ProfilingPublisher profilingPublisher = new SumoLogicProfilingPublisher(logger, sumoEndpoint,
                        serializer);//from  ww w .  jav a  2s.  co m
                ExecutionListener profilingListener = new ProfilePublishingExecutionListener(
                        profilingPublisher);

                ExecutionListener chainedListener = ChainedExecutionListener.buildFrom(currentListener,
                        profilingListener);
                request.setExecutionListener(chainedListener);

                installed = true;
            }
        }
    }
}

From source file:com.wielgolaski.maven.profiling.ProfilingLifecycleParticipant.java

License:Apache License

@Override
public void afterSessionStart(MavenSession session) throws MavenExecutionException {
    // TODO make it conditional
    ExecutionListenerChain chain = new ExecutionListenerChain();
    chain.addListener(new ProfilingExecutionListener());
    chain.addListener(session.getRequest().getExecutionListener());
    session.getRequest().setExecutionListener(chain);
}

From source file:fr.brouillard.oss.jgitver.JGitverConfigurationComponent.java

License:Apache License

@Override
public Configuration getConfiguration() throws MavenExecutionException {
    if (configuration == null) {
        synchronized (this) {
            if (configuration == null) {
                MavenSession mavenSession = legacySupport.getSession();
                final File rootDirectory = mavenSession.getRequest().getMultiModuleProjectDirectory();

                logger.debug("using " + JGitverUtils.EXTENSION_PREFIX + " on directory: " + rootDirectory);

                configuration = ConfigurationLoader.loadFromRoot(rootDirectory, logger);
                initFromRootDirectory(rootDirectory, configuration.exclusions);
            }/*from   w  w w  .  j  a  v  a  2s .  c o  m*/
        }
    }

    return configuration;
}

From source file:fr.brouillard.oss.jgitver.JGitverModelProcessor.java

License:Apache License

private void calculateVersionIfNecessary() throws Exception {
    if (workingConfiguration == null) {
        synchronized (this) {
            if (workingConfiguration == null) {
                logger.info("jgitver-maven-plugin is about to change project(s) version(s)");

                MavenSession mavenSession = legacySupport.getSession();
                final File rootDirectory = mavenSession.getRequest().getMultiModuleProjectDirectory();

                logger.debug("using " + JGitverUtils.EXTENSION_PREFIX + " on directory: " + rootDirectory);

                Configuration cfg = ConfigurationLoader.loadFromRoot(rootDirectory, logger);

                try (GitVersionCalculator gitVersionCalculator = GitVersionCalculator.location(rootDirectory)) {
                    gitVersionCalculator.setMavenLike(cfg.mavenLike)
                            .setAutoIncrementPatch(cfg.autoIncrementPatch).setUseDirty(cfg.useDirty)
                            .setUseDistance(cfg.useCommitDistance).setUseGitCommitId(cfg.useGitCommitId)
                            .setGitCommitIdLength(cfg.gitCommitIdLength)
                            .setNonQualifierBranches(cfg.nonQualifierBranches);

                    JGitverVersion jGitverVersion = new JGitverVersion(gitVersionCalculator);
                    JGitverUtils.fillPropertiesFromMetadatas(mavenSession.getUserProperties(), jGitverVersion,
                            logger);/*  w w  w  .  ja  v  a2s.co m*/

                    workingConfiguration = new JGitverModelProcessorWorkingConfiguration(
                            jGitverVersion.getCalculatedVersion(), rootDirectory);
                }
            }
        }
    }
}