o Enabled support and discovery of JSR-330 components

o Added Slf4j logger factory to support generic JSR-330 logging

o Exported Guice package for components that access Guice (or better it's injector) directly

Widen export of Guice packages (not ideal, need to look into ways to avoid this)

o use specific exports

o for now we will attempt to hide all of Guice in plugin realms and we'll do a bit of testing

closes #3

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1380105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2012-09-03 01:07:31 +00:00
parent 83436f27a7
commit 6e901c5797
7 changed files with 466 additions and 2 deletions

View File

@ -83,6 +83,10 @@
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -198,6 +198,26 @@ private void importMavenApi( Map<String, ClassLoader> imports )
imports.put( "org.codehaus.plexus.util.xml.pull.XmlPullParser", coreRealm );
imports.put( "org.codehaus.plexus.util.xml.pull.XmlPullParserException", coreRealm );
imports.put( "org.codehaus.plexus.util.xml.pull.XmlSerializer", coreRealm );
// javax.inject, sisu-inject (JSR-330)
imports.put( "javax.inject.*", coreRealm );
imports.put( "javax.enterprise.inject.*", coreRealm );
imports.put( "org.sonatype.inject.*", coreRealm );
imports.put( "org.slf4j.*", coreRealm );
// com.google
//
// We may potentially want to export these, but right now I'm not sure that anything Guice specific needs
// to be made available to plugin authors. If we find people are getting fancy and want to take advantage
// of Guice specifics we can expose that later. Really some testing needs to be done to see full hiding
// of Guice has any impact on what we may categorize as a standard JSR-330 based Tesla/Maven plugin.
//
// imports.put( "com.google.inject.*", coreRealm );
// imports.put( "com.google.inject.binder.*", coreRealm );
// imports.put( "com.google.inject.matcher.*", coreRealm );
// imports.put( "com.google.inject.name.*", coreRealm );
// imports.put( "com.google.inject.spi.*", coreRealm );
// imports.put( "com.google.inject.util.*", coreRealm );
}
/**

View File

@ -70,6 +70,10 @@
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-cipher</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- CLI -->
<dependency>
<groupId>commons-cli</groupId>

View File

@ -59,12 +59,14 @@
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.ILoggerFactory;
import org.sonatype.aether.transfer.TransferListener;
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
@ -72,6 +74,8 @@
import org.sonatype.plexus.components.sec.dispatcher.SecUtil;
import org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity;
import com.google.inject.AbstractModule;
// TODO: push all common bits back to plexus cli and prepare for transition to Guice. We don't need 50 ways to make CLIs
/**
@ -372,17 +376,29 @@ private PlexusContainer container( CliRequest cliRequest )
{
logger = setupLogger( cliRequest );
final MavenLoggerManager loggerManager = new MavenLoggerManager( logger ) ;
ContainerConfiguration cc = new DefaultContainerConfiguration()
.setClassWorld( cliRequest.classWorld )
.setRealm( setupContainerRealm( cliRequest ) )
.setClassPathScanning( PlexusConstants.SCANNING_INDEX )
.setAutoWiring( true )
.setName( "maven" );
container = new DefaultPlexusContainer( cc );
container = new DefaultPlexusContainer( cc, new AbstractModule()
{
protected void configure()
{
bind( ILoggerFactory.class ).toInstance( new PlexusLoggerFactory( loggerManager ) );
}
} );
// NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups
container.setLookupRealm( null );
container.setLoggerManager( new MavenLoggerManager( logger ) );
container.setLoggerManager( loggerManager );
customizeContainer( container );

View File

@ -0,0 +1,358 @@
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;
/**
* A Slf4j logger bridged onto a Plexus logger.
*/
class PlexusLogger
implements Logger
{
private final org.codehaus.plexus.logging.Logger logger;
public PlexusLogger( org.codehaus.plexus.logging.Logger logger )
{
this.logger = logger;
}
public String getName()
{
return logger.getName();
}
public boolean isTraceEnabled()
{
return isDebugEnabled();
}
public void trace( String msg )
{
debug( msg );
}
public void trace( String format, Object arg )
{
debug( format, arg );
}
public void trace( String format, Object arg1, Object arg2 )
{
debug( format, arg1, arg2 );
}
public void trace( String format, Object[] argArray )
{
debug( format, argArray );
}
public void trace( String msg, Throwable t )
{
debug( msg, t );
}
public boolean isTraceEnabled( Marker marker )
{
return isTraceEnabled();
}
public void trace( Marker marker, String msg )
{
trace( msg );
}
public void trace( Marker marker, String format, Object arg )
{
trace( format, arg );
}
public void trace( Marker marker, String format, Object arg1, Object arg2 )
{
trace( format, arg1, arg2 );
}
public void trace( Marker marker, String format, Object[] argArray )
{
trace( format, argArray );
}
public void trace( Marker marker, String msg, Throwable t )
{
trace( msg, t );
}
public boolean isDebugEnabled()
{
return logger.isDebugEnabled();
}
public void debug( String msg )
{
logger.debug( msg );
}
public void debug( String format, Object arg )
{
FormattingTuple ft = MessageFormatter.format( format, arg );
logger.debug( ft.getMessage(), ft.getThrowable() );
}
public void debug( String format, Object arg1, Object arg2 )
{
FormattingTuple ft = MessageFormatter.format( format, arg1, arg2 );
logger.debug( ft.getMessage(), ft.getThrowable() );
}
public void debug( String format, Object[] argArray )
{
FormattingTuple ft = MessageFormatter.arrayFormat( format, argArray );
logger.debug( ft.getMessage(), ft.getThrowable() );
}
public void debug( String msg, Throwable t )
{
logger.debug( msg, t );
}
public boolean isDebugEnabled( Marker marker )
{
return isDebugEnabled();
}
public void debug( Marker marker, String msg )
{
debug( msg );
}
public void debug( Marker marker, String format, Object arg )
{
debug( format, arg );
}
public void debug( Marker marker, String format, Object arg1, Object arg2 )
{
debug( format, arg1, arg2 );
}
public void debug( Marker marker, String format, Object[] argArray )
{
debug( format, argArray );
}
public void debug( Marker marker, String msg, Throwable t )
{
debug( msg, t );
}
public boolean isInfoEnabled()
{
return logger.isInfoEnabled();
}
public void info( String msg )
{
logger.info( msg );
}
public void info( String format, Object arg )
{
FormattingTuple ft = MessageFormatter.format( format, arg );
logger.info( ft.getMessage(), ft.getThrowable() );
}
public void info( String format, Object arg1, Object arg2 )
{
FormattingTuple ft = MessageFormatter.format( format, arg1, arg2 );
logger.info( ft.getMessage(), ft.getThrowable() );
}
public void info( String format, Object[] argArray )
{
FormattingTuple ft = MessageFormatter.arrayFormat( format, argArray );
logger.info( ft.getMessage(), ft.getThrowable() );
}
public void info( String msg, Throwable t )
{
logger.info( msg, t );
}
public boolean isInfoEnabled( Marker marker )
{
return isInfoEnabled();
}
public void info( Marker marker, String msg )
{
info( msg );
}
public void info( Marker marker, String format, Object arg )
{
info( format, arg );
}
public void info( Marker marker, String format, Object arg1, Object arg2 )
{
info( format, arg1, arg2 );
}
public void info( Marker marker, String format, Object[] argArray )
{
info( format, argArray );
}
public void info( Marker marker, String msg, Throwable t )
{
info( msg, t );
}
public boolean isWarnEnabled()
{
return logger.isWarnEnabled();
}
public void warn( String msg )
{
logger.warn( msg );
}
public void warn( String format, Object arg )
{
FormattingTuple ft = MessageFormatter.format( format, arg );
logger.warn( ft.getMessage(), ft.getThrowable() );
}
public void warn( String format, Object arg1, Object arg2 )
{
FormattingTuple ft = MessageFormatter.format( format, arg1, arg2 );
logger.warn( ft.getMessage(), ft.getThrowable() );
}
public void warn( String format, Object[] argArray )
{
FormattingTuple ft = MessageFormatter.arrayFormat( format, argArray );
logger.warn( ft.getMessage(), ft.getThrowable() );
}
public void warn( String msg, Throwable t )
{
logger.warn( msg, t );
}
public boolean isWarnEnabled( Marker marker )
{
return isWarnEnabled();
}
public void warn( Marker marker, String msg )
{
warn( msg );
}
public void warn( Marker marker, String format, Object arg )
{
warn( format, arg );
}
public void warn( Marker marker, String format, Object arg1, Object arg2 )
{
warn( format, arg1, arg2 );
}
public void warn( Marker marker, String format, Object[] argArray )
{
warn( format, argArray );
}
public void warn( Marker marker, String msg, Throwable t )
{
warn( msg, t );
}
public boolean isErrorEnabled()
{
return logger.isErrorEnabled();
}
public void error( String msg )
{
logger.error( msg );
}
public void error( String format, Object arg )
{
FormattingTuple ft = MessageFormatter.format( format, arg );
logger.error( ft.getMessage(), ft.getThrowable() );
}
public void error( String format, Object arg1, Object arg2 )
{
FormattingTuple ft = MessageFormatter.format( format, arg1, arg2 );
logger.error( ft.getMessage(), ft.getThrowable() );
}
public void error( String format, Object[] argArray )
{
FormattingTuple ft = MessageFormatter.arrayFormat( format, argArray );
logger.error( ft.getMessage(), ft.getThrowable() );
}
public void error( String msg, Throwable t )
{
logger.error( msg, t );
}
public boolean isErrorEnabled( Marker marker )
{
return isErrorEnabled();
}
public void error( Marker marker, String msg )
{
error( msg );
}
public void error( Marker marker, String format, Object arg )
{
error( format, arg );
}
public void error( Marker marker, String format, Object arg1, Object arg2 )
{
error( format, arg1, arg2 );
}
public void error( Marker marker, String format, Object[] argArray )
{
error( format, argArray );
}
public void error( Marker marker, String msg, Throwable t )
{
error( msg, t );
}
}

View File

@ -0,0 +1,50 @@
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.codehaus.plexus.logging.LoggerManager;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
/**
* A Slf4j logger factory bridged onto a Plexus logger manager.
*/
public class PlexusLoggerFactory
implements ILoggerFactory
{
private LoggerManager loggerManager;
public PlexusLoggerFactory( LoggerManager loggerManager )
{
this.loggerManager = loggerManager;
}
public void setLoggerManager( LoggerManager loggerManager )
{
this.loggerManager = loggerManager;
}
public Logger getLogger( String name )
{
return new PlexusLogger( loggerManager.getLoggerForComponent( name, null ) );
}
}

12
pom.xml
View File

@ -56,6 +56,7 @@
<modelloVersion>1.4.1</modelloVersion>
<jxpathVersion>1.3</jxpathVersion>
<aetherVersion>1.13.1</aetherVersion>
<slf4jVersion>1.6.1</slf4jVersion>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
<!-- Control the name of the distribution and information output by mvn -->
<distributionId>apache-maven</distributionId>
@ -203,6 +204,17 @@
<artifactId>plexus-interpolation</artifactId>
<version>${plexusInterpolationVersion}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4jVersion}</version>
<scope>runtime</scope>
</dependency>
<!-- Wagon -->
<dependency>
<groupId>org.apache.maven.wagon</groupId>