Modified: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenLog.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenLog.java?rev=1338189&r1=1338188&r2=1338189&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenLog.java (original) +++ felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenLog.java Mon May 14 13:21:02 2012 @@ -18,144 +18,154 @@ */ package org.apache.felix.scrplugin.mojo; - import org.apache.felix.scrplugin.Log; - /** * The <code>MavenLog</code> class implements the {@link Log} interface using * the Maven logger created on instantiation. */ -public class MavenLog implements Log -{ +public class MavenLog implements Log { private final org.apache.maven.plugin.logging.Log mavenLog; - - MavenLog( org.apache.maven.plugin.logging.Log mavenLog ) - { + MavenLog(final org.apache.maven.plugin.logging.Log mavenLog) { this.mavenLog = mavenLog; } - - public void debug( String content, Throwable error ) - { - mavenLog.debug( content, error ); + /** + * @see org.apache.felix.scrplugin.Log#debug(java.lang.String, + * java.lang.Throwable) + */ + public void debug(final String content, final Throwable error) { + mavenLog.debug(content, error); } - - public void debug( String content ) - { - mavenLog.debug( content ); + /** + * @see org.apache.felix.scrplugin.Log#debug(java.lang.String) + */ + public void debug(final String content) { + mavenLog.debug(content); } - - public void debug( Throwable error ) - { - mavenLog.debug( error ); + /** + * @see org.apache.felix.scrplugin.Log#debug(java.lang.Throwable) + */ + public void debug(final Throwable error) { + mavenLog.debug(error); } - - public void error( String content, Throwable error ) - { - mavenLog.error( content, error ); + /** + * @see org.apache.felix.scrplugin.Log#error(java.lang.String, java.lang.Throwable) + */ + public void error(final String content, final Throwable error) { + mavenLog.error(content, error); } - - public void error( String content, String location, int lineNumber ) - { - if ( isErrorEnabled() ) - { - final String message = formatMessage( content, location, lineNumber ); - mavenLog.error( message ); - } + /** + * @see org.apache.felix.scrplugin.Log#error(java.lang.String, java.lang.String, int) + */ + public void error(final String content, + final String location, + final int lineNumber) { + final String message = formatMessage(content, location, lineNumber); + mavenLog.error(message); } - - public void error( String content ) - { - mavenLog.error( content ); + /** + * @see org.apache.felix.scrplugin.Log#error(java.lang.String) + */ + public void error(final String content) { + mavenLog.error(content); } - - public void error( Throwable error ) - { - mavenLog.error( error ); + /** + * @see org.apache.felix.scrplugin.Log#error(java.lang.Throwable) + */ + public void error(final Throwable error) { + mavenLog.error(error); } - - public void info( String content, Throwable error ) - { - mavenLog.info( content, error ); + /** + * @see org.apache.felix.scrplugin.Log#info(java.lang.String, java.lang.Throwable) + */ + public void info(final String content, final Throwable error) { + mavenLog.info(content, error); } - - public void info( String content ) - { - mavenLog.info( content ); + /** + * @see org.apache.felix.scrplugin.Log#info(java.lang.String) + */ + public void info(final String content) { + mavenLog.info(content); } - - public void info( Throwable error ) - { - mavenLog.info( error ); + /** + * @see org.apache.felix.scrplugin.Log#info(java.lang.Throwable) + */ + public void info(final Throwable error) { + mavenLog.info(error); } - - public boolean isDebugEnabled() - { + /** + * @see org.apache.felix.scrplugin.Log#isDebugEnabled() + */ + public boolean isDebugEnabled() { return mavenLog.isDebugEnabled(); } - - public boolean isErrorEnabled() - { + /** + * @see org.apache.felix.scrplugin.Log#isErrorEnabled() + */ + public boolean isErrorEnabled() { return mavenLog.isErrorEnabled(); } - - public boolean isInfoEnabled() - { + /** + * @see org.apache.felix.scrplugin.Log#isInfoEnabled() + */ + public boolean isInfoEnabled() { return mavenLog.isInfoEnabled(); } - - public boolean isWarnEnabled() - { + /** + * @see org.apache.felix.scrplugin.Log#isWarnEnabled() + */ + public boolean isWarnEnabled() { return mavenLog.isWarnEnabled(); } - - public void warn( String content, Throwable error ) - { - mavenLog.warn( content, error ); - } - - - public void warn( String content, String location, int lineNumber ) - { - if ( isWarnEnabled() ) - { - final String message = formatMessage( content, location, lineNumber ); - mavenLog.warn( message ); - } - } - - - public void warn( String content ) - { - mavenLog.warn( content ); + /** + * @see org.apache.felix.scrplugin.Log#warn(java.lang.String, java.lang.Throwable) + */ + public void warn(final String content, final Throwable error) { + mavenLog.warn(content, error); + } + + /** + * @see org.apache.felix.scrplugin.Log#warn(java.lang.String, java.lang.String, int) + */ + public void warn(final String content, final String location, + final int lineNumber) { + final String message = formatMessage(content, location, lineNumber); + mavenLog.warn(message); + } + + /** + * @see org.apache.felix.scrplugin.Log#warn(java.lang.String) + */ + public void warn(final String content) { + mavenLog.warn(content); + } + + /** + * @see org.apache.felix.scrplugin.Log#warn(java.lang.Throwable) + */ + public void warn(final Throwable error) { + mavenLog.warn(error); } - - public void warn( Throwable error ) - { - mavenLog.warn( error ); - } - - - private String formatMessage( String content, String location, int lineNumber ) - { + private String formatMessage(final String content, final String location, + final int lineNumber) { return content + " at " + location + ":" + lineNumber; } }
Added: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java?rev=1338189&view=auto ============================================================================== --- felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java (added) +++ felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java Mon May 14 13:21:02 2012 @@ -0,0 +1,163 @@ +/* + * 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. + */ +package org.apache.felix.scrplugin.mojo; + + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.felix.scrplugin.Log; +import org.apache.felix.scrplugin.helper.StringUtils; +import org.apache.felix.scrplugin.scanner.Source; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.DirectoryScanner; + + +public class MavenProjectScanner { + + private final MavenProject project; + + private final String includeString; + + private final String excludeString; + + private final Log log; + + public MavenProjectScanner( final MavenProject project, + final String includeString, + final String excludeString, + final Log log) { + this.project = project; + this.includeString = includeString; + this.excludeString = excludeString; + this.log = log; + } + + /** + * Return all sources. + */ + public Collection<Source> getSources() { + final ArrayList<Source> files = new ArrayList<Source>(); + + @SuppressWarnings("unchecked") + final Iterator<String> i = project.getCompileSourceRoots().iterator(); + + // FELIX-509: check for excludes + String[] includes = new String[] { "**/*.java" }; + if ( includeString != null ) { + includes = StringUtils.split( includeString, "," ); + } + + final String[] excludes; + if ( excludeString != null ) { + excludes = StringUtils.split( excludeString, "," ); + } else { + excludes = null; + } + + while ( i.hasNext() ) { + final String tree = i.next(); + final File directory = new File( tree ); + if ( !directory.exists() ) { + log.warn("Source tree does not exist. Ignoring " + tree); + continue; + } + log.debug( "Scanning source tree " + tree ); + final DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( directory ); + + if ( excludes != null && excludes.length > 0 ) { + scanner.setExcludes( excludes ); + } + scanner.addDefaultExcludes(); + scanner.setIncludes( includes ); + + scanner.scan(); + + for ( final String fileName : scanner.getIncludedFiles() ) { + files.add( new Source() { + + public File getFile() { + return new File(directory, fileName); + } + + public String getClassName() { + // remove ".java" + String name = fileName.substring(0, fileName.length() - 5); + return name.replace(File.separatorChar, '/').replace('/', '.'); + } + }); + } + } + + return files; + } + + /** + * Return all dependencies + */ + public List<File> getDependencies() { + final ArrayList<File> dependencies = new ArrayList<File>(); + + @SuppressWarnings("unchecked") + final Iterator<Artifact> it = project.getArtifacts().iterator(); + while ( it.hasNext() ) { + final Artifact declared = it.next(); + this.log.debug( "Checking artifact " + declared ); + if ( this.isJavaArtifact( declared ) ) { + if ( Artifact.SCOPE_COMPILE.equals( declared.getScope() ) + || Artifact.SCOPE_RUNTIME.equals( declared.getScope() ) + || Artifact.SCOPE_PROVIDED.equals( declared.getScope() ) + || Artifact.SCOPE_SYSTEM.equals( declared.getScope() ) ) { + this.log.debug( "Resolving artifact " + declared ); + if ( declared.getFile() != null ) { + dependencies.add( declared.getFile() ); + } else { + this.log.debug( "Unable to resolve artifact " + declared ); + } + } else { + this.log.debug( "Artifact " + declared + " has not scope compile or runtime, but " + + declared.getScope() ); + } + } else { + this.log.debug( "Artifact " + declared + " is not a java artifact, type is " + declared.getType() ); + } + } + + return dependencies; + } + + + /** + * Check if the artifact is a java artifact (jar or bundle) + */ + private boolean isJavaArtifact( Artifact artifact ) { + if ( "jar".equals( artifact.getType() ) ) { + return true; + } + if ( "bundle".equals( artifact.getType() ) ) { + return true; + } + return false; + } +} Propchange: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/MavenProjectScanner.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java?rev=1338189&r1=1338188&r2=1338189&view=diff ============================================================================== --- felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java (original) +++ felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java Mon May 14 13:21:02 2012 @@ -22,14 +22,25 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; -import java.util.*; - -import org.apache.felix.scrplugin.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.felix.scrplugin.Options; +import org.apache.felix.scrplugin.Project; +import org.apache.felix.scrplugin.SCRDescriptorException; +import org.apache.felix.scrplugin.SCRDescriptorFailureException; +import org.apache.felix.scrplugin.SCRDescriptorGenerator; +import org.apache.felix.scrplugin.description.SpecVersion; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.model.Resource; -import org.apache.maven.plugin.*; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; @@ -67,7 +78,7 @@ public class SCRDescriptorMojo extends A * * @see #checkAnnotationArtifact(Artifact) */ - private static final ArtifactVersion SCR_ANN_MIN_VERSION = new DefaultArtifactVersion("1.5.1"); + private static final ArtifactVersion SCR_ANN_MIN_VERSION = new DefaultArtifactVersion("1.6.0"); /** * @parameter expression="${project.build.directory}/scr-plugin-generated" @@ -125,14 +136,14 @@ public class SCRDescriptorMojo extends A */ protected boolean strictMode; - + /** * The comma separated list of tokens to include when processing sources. - * + * * @parameter alias="includes" */ private String sourceIncludes; - + /** * The comma separated list of tokens to exclude when processing sources. * @@ -149,14 +160,12 @@ public class SCRDescriptorMojo extends A /** * Allows to define additional implementations of the interface - * {@link org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider} - * that provide mappings from custom annotations to - * {@link org.apache.felix.scrplugin.tags.JavaTag} implementations. - * List of full qualified class file names. + * {@link org.apache.felix.scrplugin.AnnotationProcessor} + * that provide mappings from custom annotations to descriptions. * * @parameter */ - private String[] annotationTagProviders = {}; + private String[] annotationProcessors = {}; /** * The version of the DS spec this plugin generates a descriptor for. @@ -166,41 +175,47 @@ public class SCRDescriptorMojo extends A private String specVersion; - public void execute() throws MojoExecutionException, MojoFailureException - { - try - { - final org.apache.felix.scrplugin.Log scrLog = new MavenLog( getLog() ); - - final ClassLoader classLoader = new URLClassLoader( getClassPath(), this.getClass().getClassLoader() ); - final JavaClassDescriptorManager jManager = new MavenJavaClassDescriptorManager( project, scrLog, - classLoader, this.annotationTagProviders, this.sourceIncludes, this.sourceExcludes, this.parseJavadoc, - this.processAnnotations ); + public void execute() throws MojoExecutionException, MojoFailureException { + // create the log for the generator + final org.apache.felix.scrplugin.Log scrLog = new MavenLog( getLog() ); + // create the class loader + final ClassLoader classLoader = new URLClassLoader( getClassPath(), this.getClass().getClassLoader() ); + + // create project + final MavenProjectScanner scanner = new MavenProjectScanner(this.project, this.sourceIncludes, this.sourceExcludes, scrLog); + + final Project project = new Project(); + project.setClassLoader(classLoader); + project.setDependencies(scanner.getDependencies()); + project.setSources(scanner.getSources()); + + // create options + final Options options = new Options(); + options.setGenerateAccessors( generateAccessors ); + options.setStrictMode( strictMode ); + options.setProperties( properties ); + options.setSpecVersion( SpecVersion.fromName(specVersion) ); + options.setAnnotationProcessors(annotationProcessors); + try { final SCRDescriptorGenerator generator = new SCRDescriptorGenerator( scrLog ); // setup from plugin configuration generator.setOutputDirectory( outputDirectory ); - generator.setDescriptorManager( jManager ); + generator.setOptions(options); + generator.setProject(project); generator.setFinalName( finalName ); generator.setMetaTypeName( metaTypeName ); - generator.setGenerateAccessors( generateAccessors ); - generator.setStrictMode( strictMode ); - generator.setProperties( properties ); - generator.setSpecVersion( specVersion ); - if ( generator.execute() ) - { + if ( generator.execute() ) { setServiceComponentHeader(); addResources(); } + } - catch ( SCRDescriptorException sde ) - { + catch ( final SCRDescriptorException sde ) { throw new MojoExecutionException( sde.getMessage(), sde.getCause() ); - } - catch ( SCRDescriptorFailureException sdfe ) - { + } catch ( SCRDescriptorFailureException sdfe ) { throw ( MojoFailureException ) new MojoFailureException( sdfe.getMessage() ).initCause( sdfe ); } } @@ -210,12 +225,9 @@ public class SCRDescriptorMojo extends A List<Artifact> artifacts = this.project.getCompileArtifacts(); ArrayList<URL> path = new ArrayList<URL>(); - try - { + try { path.add(new File( this.project.getBuild().getOutputDirectory() ).toURI().toURL()); - } - catch ( IOException ioe ) - { + } catch ( final IOException ioe ) { throw new MojoFailureException( "Unable to add target directory to classloader."); } @@ -247,8 +259,7 @@ public class SCRDescriptorMojo extends A * @throws MojoFailureException If the artifact refers to the SCR Annotation * library with a version less than {@link #SCR_ANN_MIN_VERSION} */ - private void assertMinScrAnnotationArtifactVersion(Artifact a) throws MojoFailureException - { + private void assertMinScrAnnotationArtifactVersion(Artifact a) throws MojoFailureException { if (SCR_ANN_ARTIFACTID.equals(a.getArtifactId()) && SCR_ANN_GROUPID.equals(a.getGroupId())) { // assert minimal version number
