Example usage for org.apache.maven.cli.logging Slf4jLoggerManager Slf4jLoggerManager

List of usage examples for org.apache.maven.cli.logging Slf4jLoggerManager Slf4jLoggerManager

Introduction

In this page you can find the example usage for org.apache.maven.cli.logging Slf4jLoggerManager Slf4jLoggerManager.

Prototype

public Slf4jLoggerManager() 

Source Link

Usage

From source file:fr.jetoile.hadoopunit.HadoopStandaloneBootstrap.java

License:Apache License

/**
 * code from org.apache.maven.cli.MavenCli.container(CliRequest)
 * <p>//from w w w  . j av a2s  . c  om
 * cf also https://github.com/igor-suhorukov/mvn-classloader/blob/master/dropship/src/main/java/com/github/smreed/dropship/ClassLoaderBuilder.java
 */
private static PlexusContainer mvnContainer() {
    ILoggerFactory slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jLoggerManager plexusLoggerManager = new Slf4jLoggerManager();

    ClassWorld classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());

    DefaultPlexusContainer container = null;

    ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld(classWorld)
            .setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true).setName("maven");

    try {
        container = new DefaultPlexusContainer(cc, new AbstractModule() {
            protected void configure() {
                bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
            }
        });
    } catch (PlexusContainerException e) {
        LOGGER.error("unable to create PlexusContainer", e);
    }

    // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups
    container.setLookupRealm(null);

    container.setLoggerManager(plexusLoggerManager);
    Thread.currentThread().setContextClassLoader(container.getContainerRealm());

    return container;
}

From source file:hudson.maven.MavenUtil.java

License:Open Source License

/**
 * Creates a fresh {@link MavenEmbedder} instance.
 *
 *///from  www  . j a v a  2s.  c  om
@SuppressWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public static MavenEmbedder createEmbedder(MavenEmbedderRequest mer)
        throws MavenEmbedderException, IOException {

    MavenRequest mavenRequest = new MavenRequest();

    // make sure ~/.m2 exists to avoid http://www.nabble.com/BUG-Report-tf3401736.html
    File m2Home = new File(MavenEmbedder.userHome, ".m2");
    m2Home.mkdirs();
    if (!m2Home.exists())
        throw new AbortException("Failed to create " + m2Home);

    if (mer.getPrivateRepository() != null)
        mavenRequest.setLocalRepositoryPath(mer.getPrivateRepository());

    if (mer.getProfiles() != null) {
        mavenRequest.setProfiles(Arrays.asList(StringUtils.split(mer.getProfiles(), ",")));
    }

    if (mer.getAlternateSettings() != null) {
        mavenRequest.setUserSettingsFile(mer.getAlternateSettings().getAbsolutePath());
    } else {
        mavenRequest.setUserSettingsFile(new File(m2Home, "settings.xml").getAbsolutePath());
    }

    if (mer.getGlobalSettings() != null) {
        mavenRequest.setGlobalSettingsFile(mer.getGlobalSettings().getAbsolutePath());
    } else {
        mavenRequest.setGlobalSettingsFile(new File(mer.getMavenHome(), "conf/settings.xml").getAbsolutePath());
    }

    if (mer.getWorkspaceReader() != null) {
        mavenRequest.setWorkspaceReader(mer.getWorkspaceReader());
    }

    mavenRequest.setUpdateSnapshots(mer.isUpdateSnapshots());

    // TODO olamy check this sould be userProperties 
    mavenRequest.setSystemProperties(mer.getSystemProperties());

    if (mer.getTransferListener() != null) {
        if (debugMavenEmbedder) {
            mer.getListener().getLogger()
                    .println("use transfertListener " + mer.getTransferListener().getClass().getName());
        }
        mavenRequest.setTransferListener(mer.getTransferListener());
    }

    mavenRequest.setMavenLoggerManager(new Slf4jLoggerManager());

    //mavenRequest.setContainerClassPathScanning( PlexusConstants.SCANNING_OFF );

    //mavenRequest.setContainerComponentVisibility( PlexusConstants.GLOBAL_VISIBILITY );

    ClassLoader mavenEmbedderClassLoader = mer.getClassLoader();

    {// are we loading the right components.xml? (and not from Maven that's running Jetty, if we are running in "mvn hudson-dev:run" or "mvn hpi:run"?
        Enumeration<URL> e = mavenEmbedderClassLoader.getResources("META-INF/plexus/components.xml");
        while (e.hasMoreElements()) {
            URL url = e.nextElement();
            LOGGER.fine("components.xml from " + url);
        }
    }

    mavenRequest.setProcessPlugins(mer.isProcessPlugins());
    mavenRequest.setResolveDependencies(mer.isResolveDependencies());
    mavenRequest.setValidationLevel(mer.getValidationLevel());

    // TODO check this MaskingClassLoader with maven 3 artifacts
    MavenEmbedder maven = new MavenEmbedder(mavenEmbedderClassLoader, mavenRequest);

    return maven;
}

From source file:org.jvnet.hudson.maven3.launcher.Maven31Launcher.java

License:Apache License

public static int main(String[] args) throws Exception {
    ClassLoader orig = Thread.currentThread().getContextClassLoader();
    try {// ww  w.  j a v a 2s. co  m

        ClassRealm containerRealm = (ClassRealm) Thread.currentThread().getContextClassLoader();

        ContainerConfiguration cc = new DefaultContainerConfiguration().setName("maven")
                .setRealm(containerRealm).setClassPathScanning(PlexusConstants.SCANNING_INDEX)
                .setAutoWiring(true);

        DefaultPlexusContainer container = new DefaultPlexusContainer(cc);
        Slf4jLoggerManager mavenLoggerManager = new Slf4jLoggerManager();
        container.setLoggerManager(mavenLoggerManager);

        Maven maven = (Maven) container.lookup("org.apache.maven.Maven", "default");

        EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);

        if (eventSpiesList != null && !eventSpiesList.isEmpty()) {
            List<EventSpy> eventSpies = eventSpyDispatcher.getEventSpies();
            if (eventSpies == null) {
                eventSpies = new ArrayList<EventSpy>(1);
            }
            eventSpies.addAll(eventSpiesList);

            // get event spies added with plexus components
            // see Maven31Maven addPlexusComponents
            // PlexusModuleContributor extension
            List<EventSpy> spies = container.lookupList(EventSpy.class);
            if (spies != null && !spies.isEmpty()) {
                eventSpies.addAll(spies);
            }

            eventSpyDispatcher.setEventSpies(eventSpies);
        }

        MavenExecutionRequest request = getMavenExecutionRequest(args, container);

        MavenExecutionResult result = maven.execute(request);
        hudsonMavenExecutionResult = new HudsonMavenExecutionResult(result);

        // we don't care about cli mavenExecutionResult will be study in the the plugin
        return 0;// cli.doMain( args, null );
    } catch (ComponentLookupException e) {
        throw new Exception(e.getMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(orig);
    }
}

From source file:org.jvnet.hudson.maven3.launcher.Maven35Launcher.java

License:Apache License

public static int main(String[] args, ClassWorld classWorld) throws Exception {
    ClassLoader orig = Thread.currentThread().getContextClassLoader();
    try {// w w  w. j ava2  s. c  o  m

        ClassRealm containerRealm = (ClassRealm) Thread.currentThread().getContextClassLoader();

        ContainerConfiguration cc = new DefaultContainerConfiguration().setName("maven")
                .setRealm(containerRealm).setClassPathScanning(PlexusConstants.SCANNING_INDEX)
                .setAutoWiring(true);

        DefaultPlexusContainer container = new DefaultPlexusContainer(cc);
        Slf4jLoggerManager mavenLoggerManager = new Slf4jLoggerManager();
        container.setLoggerManager(mavenLoggerManager);

        Maven maven = (Maven) container.lookup("org.apache.maven.Maven", "default");

        EventSpyDispatcher eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);

        if (eventSpiesList != null && !eventSpiesList.isEmpty()) {
            List<EventSpy> eventSpies = eventSpyDispatcher.getEventSpies();
            if (eventSpies == null) {
                eventSpies = new ArrayList<EventSpy>(1);
            }
            eventSpies.addAll(eventSpiesList);

            // get event spies added with plexus components
            // see Maven31Maven addPlexusComponents
            // PlexusModuleContributor extension
            List<EventSpy> spies = container.lookupList(EventSpy.class);
            if (spies != null && !spies.isEmpty()) {
                eventSpies.addAll(spies);
            }

            eventSpyDispatcher.setEventSpies(eventSpies);
        }

        MavenExecutionRequest request = getMavenExecutionRequest(args, container);

        MavenExecutionResult result = maven.execute(request);
        hudsonMavenExecutionResult = new HudsonMavenExecutionResult(result);

        // we don't care about cli mavenExecutionResult will be study in the the plugin
        return 0;// cli.doMain( args, null );
    } catch (ComponentLookupException e) {
        throw new Exception(e.getMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(orig);
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFMavenCli.java

License:Apache License

protected void logging(AFCliRequest cliRequest) {
    cliRequest.setDebug(cliRequest.getCommandLine().hasOption(CLIManager.DEBUG));
    cliRequest.setQuiet(!cliRequest.isDebug() && cliRequest.getCommandLine().hasOption(CLIManager.QUIET));
    cliRequest.setShowErrors(cliRequest.isDebug() || cliRequest.getCommandLine().hasOption(CLIManager.ERRORS));

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);

    if (cliRequest.isDebug()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.isQuiet()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }/*from   ww  w . j  a v a 2s  .  c om*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.getCommandLine().getOptionValue(CLIManager.LOG_FILE).trim());
        logFile = resolveFile(logFile, cliRequest.getWorkingDirectory()); //@MAX

        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.AFMavenCli.java

License:Apache License

protected void logging(AFCliRequest cliRequest) {
    cliRequest.setDebug(cliRequest.getCommandLine().hasOption(CLIManager.DEBUG));
    cliRequest.setQuiet(!cliRequest.isDebug() && cliRequest.getCommandLine().hasOption(CLIManager.QUIET));
    cliRequest.setShowErrors(cliRequest.isDebug() || cliRequest.getCommandLine().hasOption(CLIManager.ERRORS));

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
    if (cliRequest.isDebug()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.isQuiet()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }/*from   w  w  w .  j a  v a 2  s  .  c o m*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.getCommandLine().getOptionValue(CLIManager.LOG_FILE).trim());
        logFile = resolveFile(logFile, cliRequest.getWorkingDirectory());

        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java

License:Apache License

protected void logging(AFCliRequest cliRequest) {
    cliRequest.setDebug(cliRequest.getCommandLine().hasOption(CLIManager.DEBUG));
    cliRequest.setQuiet(!cliRequest.isDebug() && cliRequest.getCommandLine().hasOption(CLIManager.QUIET));
    cliRequest.setShowErrors(cliRequest.isDebug() || cliRequest.getCommandLine().hasOption(CLIManager.ERRORS));

    slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
    Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory);
    if (cliRequest.isDebug()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.DEBUG);
    } else if (cliRequest.isQuiet()) {
        cliRequest.getRequest().setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_ERROR);
        slf4jConfiguration.setRootLoggerLevel(Slf4jConfiguration.Level.ERROR);
    }/*  w ww .  j  a v  a 2 s.co m*/

    if (cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) {
        File logFile = new File(cliRequest.getCommandLine().getOptionValue(CLIManager.LOG_FILE).trim());
        logFile = resolveFile(logFile, cliRequest.getWorkingDirectory());

        try {
            PrintStream ps = new PrintStream(new FileOutputStream(logFile));
            System.setOut(ps);
            System.setErr(ps);
        } catch (FileNotFoundException e) {
            logger.error(e.getMessage());
        }
    }

    slf4jConfiguration.activate();

    plexusLoggerManager = new Slf4jLoggerManager();
    reusableSlf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());
}