Example usage for org.apache.maven.cli.transfer BatchModeMavenTransferListener BatchModeMavenTransferListener

List of usage examples for org.apache.maven.cli.transfer BatchModeMavenTransferListener BatchModeMavenTransferListener

Introduction

In this page you can find the example usage for org.apache.maven.cli.transfer BatchModeMavenTransferListener BatchModeMavenTransferListener.

Prototype

public BatchModeMavenTransferListener(PrintStream out) 

Source Link

Usage

From source file:hudson.maven.RedeployPublisher.java

License:Open Source License

/**
 * //from   w  w  w. j a  v a 2  s.c o  m
 * copy from MavenUtil but here we have to ignore localRepo path and setting as thoses paths comes
 * from the remote node and can not exist in master see http://issues.jenkins-ci.org/browse/JENKINS-8711
 * 
 */
private MavenEmbedder createEmbedder(TaskListener listener, AbstractBuild<?, ?> build)
        throws MavenEmbedderException, IOException, InterruptedException {
    MavenInstallation m = null;
    File settingsLoc = null, remoteGlobalSettingsFromConfig = null;
    String profiles = null;
    Properties systemProperties = null;
    String privateRepository = null;
    FilePath remoteSettingsFromConfig = null;

    File tmpSettings = File.createTempFile("jenkins", "temp-settings.xml");
    try {
        AbstractProject project = build.getProject();

        if (project instanceof MavenModuleSet) {
            MavenModuleSet mavenModuleSet = ((MavenModuleSet) project);
            profiles = mavenModuleSet.getProfiles();
            systemProperties = mavenModuleSet.getMavenProperties();

            // olamy see  
            // we have to take about the settings use for the project
            // order tru configuration 
            // TODO maybe in goals with -s,--settings last wins but not done in during pom parsing
            // or -Dmaven.repo.local
            // if not we must get ~/.m2/settings.xml then $M2_HOME/conf/settings.xml

            // TODO check if the remoteSettings has a localRepository configured and disabled it

            String altSettingsPath = SettingsProvider
                    .getSettingsRemotePath(((MavenModuleSet) project).getSettings(), build, listener);
            String remoteGlobalSettingsPath = GlobalSettingsProvider
                    .getSettingsRemotePath(((MavenModuleSet) project).getGlobalSettings(), build, listener);
            if (remoteGlobalSettingsPath != null) {
                remoteGlobalSettingsFromConfig = new File(remoteGlobalSettingsPath);
            }

            Node buildNode = build.getBuiltOn();

            if (buildNode == null) {
                // assume that build was made on master
                buildNode = Jenkins.getInstance();
            }

            if (StringUtils.isBlank(altSettingsPath)) {
                // get userHome from the node where job has been executed
                String remoteUserHome = build.getWorkspace().act(new GetUserHome());
                altSettingsPath = remoteUserHome + "/.m2/settings.xml";
            }

            // we copy this file in the master in a  temporary file 
            FilePath filePath = new FilePath(tmpSettings);
            FilePath remoteSettings = build.getWorkspace().child(altSettingsPath);
            if (!remoteSettings.exists()) {
                // JENKINS-9084 we finally use $M2_HOME/conf/settings.xml as maven does

                String mavenHome = ((MavenModuleSet) project).getMaven().forNode(buildNode, listener).getHome();
                String settingsPath = mavenHome + "/conf/settings.xml";
                remoteSettings = build.getWorkspace().child(settingsPath);
            }
            listener.getLogger()
                    .println("Maven RedeployPublisher use remote "
                            + (buildNode != null ? buildNode.getNodeName() : "local")
                            + " maven settings from : " + remoteSettings.getRemote());
            remoteSettings.copyTo(filePath);
            settingsLoc = tmpSettings;

        }

        MavenEmbedderRequest mavenEmbedderRequest = new MavenEmbedderRequest(listener,
                m != null ? m.getHomeDir() : null, profiles, systemProperties, privateRepository, settingsLoc);

        if (remoteGlobalSettingsFromConfig != null) {
            mavenEmbedderRequest.setGlobalSettings(remoteGlobalSettingsFromConfig);
        }

        mavenEmbedderRequest.setTransferListener(new BatchModeMavenTransferListener(listener.getLogger()));

        return MavenUtil.createEmbedder(mavenEmbedderRequest);
    } finally {
        if (tmpSettings != null) {
            tmpSettings.delete();
        }
    }
}

From source file:org.hudsonci.maven.eventspy_31.handler.MavenExecutionRequestHandler.java

License:Open Source License

public void handle(final MavenExecutionRequest event) throws Exception {
    log.debug("Execution request: {}", event);

    // Configure a batch listener unless a quiet listener is already added
    TransferListener listener = event.getTransferListener();
    if (!(listener instanceof QuietMavenTransferListener)) {
        event.setTransferListener(new BatchModeMavenTransferListener(System.out));
        log.debug("Configured batch mode transfer listener");
    }//from w ww  . j  a v a  2  s .  co  m

    ProfileLogger.logRequestProfiles(event); // TODO: is this needed anymore?

    configureToolChains(event);

    // TODO: See if we need to actually handle TransferEvent's via handlers too, or if the other aether events cover our needs.
}

From source file:org.sourcepit.common.maven.testing.EmbeddedMaven.java

License:Apache License

public void populateDefaults(final MavenExecutionRequest request)
        throws Exception, MavenExecutionRequestPopulationException {
    request.setExecutionListener(eventSpyDispatcher.chainListener(new ExecutionEventLogger(logger)));
    request.setTransferListener(new BatchModeMavenTransferListener(System.out));

    final SettingsBuildingResult settingsResult = buildSettings(null, request.getUserSettingsFile(),
            request.getSystemProperties(), request.getUserProperties());
    executionRequestPopulator.populateFromSettings(request, settingsResult.getEffectiveSettings());

    if (localRepo != null) {
        request.setLocalRepositoryPath(localRepo);
    }//from   w  w  w .  java  2  s .  co  m

    if (remoteRepo != null) {
        request.getRemoteRepositories().add(getRemoteRepository());
    }

    executionRequestPopulator.populateDefaults(request);
}