Author: vsiveton Date: Tue Jan 11 13:28:29 2011 New Revision: 1057614 URL: http://svn.apache.org/viewvc?rev=1057614&view=rev Log: o moved interpolate() to DoapUtil and take care of array o using interpolate in doapOptions parameters o improved/added test cases
Modified: maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml Modified: maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java?rev=1057614&r1=1057613&r2=1057614&view=diff ============================================================================== --- maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java (original) +++ maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java Tue Jan 11 13:28:29 2011 @@ -52,7 +52,6 @@ import org.apache.maven.artifact.resolve import org.apache.maven.model.Contributor; import org.apache.maven.model.Developer; import org.apache.maven.model.License; -import org.apache.maven.model.Scm; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.doap.options.ASFExtOptions; @@ -72,11 +71,6 @@ import org.apache.maven.scm.repository.S import org.apache.maven.scm.repository.ScmRepositoryException; import org.apache.maven.settings.Settings; import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.interpolation.EnvarBasedValueSource; -import org.codehaus.plexus.interpolation.InterpolationException; -import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; -import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; -import org.codehaus.plexus.interpolation.RegexBasedInterpolator; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; @@ -645,7 +639,7 @@ public class DoapMojo if ( !added ) { messages.getWarnMessages().add( "The project's url defined from " + artifact.toConfiguration() - + " is empty or not valid, using <about/> parameter." ); + + " is empty or not a valid URL, using <about/> parameter." ); } } @@ -661,7 +655,7 @@ public class DoapMojo } catch ( MalformedURLException e ) { - messages.addMessage( new String[] { "about" }, null, UserMessages.INVALID_URL ); + messages.addMessage( new String[] { "about" }, about, UserMessages.INVALID_URL ); } added = true; } @@ -741,15 +735,7 @@ public class DoapMojo // Developers @SuppressWarnings( "unchecked" ) List<Contributor> developers = project.getDevelopers(); - if ( developers == null || developers.isEmpty() ) - { - messages.addMessage( new String[] { "project", "developers" }, null, - UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); - } - else - { - writeContributors( writer, developers ); - } + writeContributors( writer, developers ); // Contributors @SuppressWarnings( "unchecked" ) @@ -833,23 +819,20 @@ public class DoapMojo */ private void writeName( XMLWriter writer, MavenProject project ) { - String name = interpolate( doapOptions.getName(), project, settings ); + String name = DoapUtil.interpolate( doapOptions.getName(), project, settings ); if ( StringUtils.isEmpty( name ) ) { - messages.addMessage( new String[] { "doapOptions", "name" }, null, UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); + messages.addMessage( new String[] { "doapOptions", "name" }, null, + UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); return; } DoapUtil.writeComment( writer, "A name of something." ); - - if ( asfExtOptions.isIncluded() && !name.toLowerCase( Locale.ENGLISH ).startsWith( "apache" ) ) - { - DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "name", "Apache " + name ); - } - else + if ( ASFExtOptionsUtil.isASFProject( project ) && !name.toLowerCase( Locale.ENGLISH ).startsWith( "apache" ) ) { - DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "name", name ); + name = "Apache " + name; } + DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "name", name ); } /** @@ -863,7 +846,7 @@ public class DoapMojo private void writeDescription( XMLWriter writer, MavenProject project ) { boolean addComment = false; - String description = interpolate( doapOptions.getDescription(), project, settings ); + String description = DoapUtil.interpolate( doapOptions.getDescription(), project, settings ); if ( StringUtils.isEmpty( description ) ) { messages.addMessage( new String[] { "doapOptions", "description" }, null, @@ -877,7 +860,7 @@ public class DoapMojo } String comment = "Short plain text description of a project."; - String shortdesc = interpolate( doapOptions.getShortdesc(), project, settings ); + String shortdesc = DoapUtil.interpolate( doapOptions.getShortdesc(), project, settings ); if ( StringUtils.isEmpty( shortdesc ) ) { messages.addMessage( new String[] { "doapOptions", "shortdesc" }, null, @@ -917,7 +900,7 @@ public class DoapMojo */ private void writeCreated( XMLWriter writer, MavenProject project ) { - String created = interpolate( doapOptions.getCreated(), project, settings ); + String created = DoapUtil.interpolate( doapOptions.getCreated(), project, settings ); if ( StringUtils.isEmpty( created ) ) { messages.addMessage( new String[] { "doapOptions", "created" }, null, @@ -949,7 +932,7 @@ public class DoapMojo */ private void writeHomepage( XMLWriter writer, MavenProject project ) { - String homepage = interpolate( doapOptions.getHomepage(), project, settings ); + String homepage = DoapUtil.interpolate( doapOptions.getHomepage(), project, settings ); if ( StringUtils.isEmpty( homepage ) ) { messages.addMessage( new String[] { "doapOptions", "homepage" }, null, @@ -972,7 +955,7 @@ public class DoapMojo if ( StringUtils.isNotEmpty( doapOptions.getOldHomepage() ) ) { - String oldHomepage = interpolate( doapOptions.getOldHomepage(), project, settings ); + String oldHomepage = DoapUtil.interpolate( doapOptions.getOldHomepage(), project, settings ); if ( StringUtils.isEmpty( oldHomepage ) ) { return; @@ -987,7 +970,8 @@ public class DoapMojo } catch ( MalformedURLException e ) { - messages.addMessage( new String[] { "doapOptions", "oldHomepage" }, oldHomepage, UserMessages.INVALID_URL ); + messages.addMessage( new String[] { "doapOptions", "oldHomepage" }, oldHomepage, + UserMessages.INVALID_URL ); } } } @@ -1195,7 +1179,7 @@ public class DoapMojo */ private void writeDownloadPage( XMLWriter writer, MavenProject project ) { - String downloadPage = interpolate( doapOptions.getDownloadPage(), project, settings ); + String downloadPage = DoapUtil.interpolate( doapOptions.getDownloadPage(), project, settings ); if ( StringUtils.isEmpty( downloadPage ) ) { messages.addMessage( new String[] { "doapOptions", "downloadPage" }, null, @@ -1253,16 +1237,17 @@ public class DoapMojo */ private void writeOS( XMLWriter writer, MavenProject project ) { - if ( StringUtils.isEmpty( doapOptions.getOs() ) ) + String os = DoapUtil.interpolate( doapOptions.getOs(), project, settings ); + if ( StringUtils.isEmpty( os ) ) { return; } DoapUtil.writeComment( writer, "Operating system that a project is limited to." ); - String[] oses = StringUtils.split( doapOptions.getOs(), "," ); - for ( String os : oses ) + String[] oses = StringUtils.split( os, "," ); + for ( String os_ : oses ) { - DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "os", os.trim() ); + DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "os", os_.trim() ); } } @@ -1275,12 +1260,13 @@ public class DoapMojo */ private void writeScreenshots( XMLWriter writer, MavenProject project ) { - if ( StringUtils.isEmpty( doapOptions.getScreenshots() ) ) + String screenshots = DoapUtil.interpolate( doapOptions.getScreenshots(), project, settings ); + if ( StringUtils.isEmpty( screenshots ) ) { return; } - String screenshots = doapOptions.getScreenshots().trim(); + screenshots = screenshots.trim(); try { new URL( screenshots ); @@ -1304,12 +1290,13 @@ public class DoapMojo */ private void writeWiki( XMLWriter writer, MavenProject project ) { - if ( StringUtils.isEmpty( doapOptions.getWiki() ) ) + String wiki = DoapUtil.interpolate( doapOptions.getWiki(), project, settings ); + if ( StringUtils.isEmpty( wiki ) ) { return; } - String wiki = doapOptions.getWiki().trim(); + wiki = wiki.trim(); try { new URL( wiki ); @@ -1333,36 +1320,55 @@ public class DoapMojo */ private void writeLicenses( XMLWriter writer, MavenProject project ) { - if ( project.getLicenses() == null || project.getLicenses().isEmpty() ) - { - messages.addMessage( new String[] { "project", "licenses" }, null, UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); - return; - } - - DoapUtil.writeComment( writer, "The URI of the license the software is distributed under." ); - // TODO: how to map to usefulinc site, or if this is necessary, the OSI page might - // be more appropriate. - @SuppressWarnings( "unchecked" ) - List<License> licenses = project.getLicenses(); - for ( License license : licenses ) + String license = DoapUtil.interpolate( doapOptions.getLicense(), project, settings ); + if ( StringUtils.isEmpty( license ) ) { - if ( StringUtils.isEmpty( license.getUrl() ) ) + boolean added = false; + @SuppressWarnings( "unchecked" ) + List<License> licenses = project.getLicenses(); + if ( licenses.size() > 1 ) { - continue; - } + for ( int i = 1; i < licenses.size(); i++ ) + { + if ( StringUtils.isEmpty( licenses.get( i ).getUrl() ) ) + { + continue; + } - String licenseUrl = license.getUrl().trim(); - try - { - new URL( licenseUrl ); + String licenseUrl = licenses.get( i ).getUrl().trim(); + try + { + new URL( licenseUrl ); - DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "license", licenseUrl ); + DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "license", licenseUrl ); + added = true; + } + catch ( MalformedURLException e ) + { + messages.addMessage( new String[] { "project", "licenses", "license", "url" }, licenseUrl, + UserMessages.INVALID_URL ); + } + } } - catch ( MalformedURLException e ) + + if ( !added ) { - messages.addMessage( new String[] { "project", "licenses", "license", "url" }, licenseUrl, - UserMessages.INVALID_URL ); + messages.addMessage( new String[] { "doapOptions", "license" }, null, + UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); } + return; + } + + try + { + new URL( license ); + + DoapUtil.writeComment( writer, "The URI of the license the software is distributed under." ); + DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "license", license ); + } + catch ( MalformedURLException e ) + { + messages.addMessage( new String[] { "doapOptions", "license" }, license, UserMessages.INVALID_URL ); } } @@ -1375,27 +1381,25 @@ public class DoapMojo */ private void writeBugDatabase( XMLWriter writer, MavenProject project ) { - if ( project.getIssueManagement() == null || StringUtils.isEmpty( project.getIssueManagement().getUrl() ) ) + String bugDatabase = DoapUtil.interpolate( doapOptions.getBugDatabase(), project, settings ); + if ( StringUtils.isEmpty( bugDatabase ) ) { - messages.addMessage( new String[] { "project", "issueManagement" }, null, + messages.addMessage( new String[] { "doapOptions", "bugDatabase" }, null, UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); return; } - String issueManagementUrl = project.getIssueManagement().getUrl().trim(); try { - new URL( issueManagementUrl ); + new URL( bugDatabase ); + + DoapUtil.writeComment( writer, "Bug database." ); + DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "bug-database", bugDatabase ); } catch ( MalformedURLException e ) { - messages.addMessage( new String[] { "project", "issueManagement", "url" }, issueManagementUrl, - UserMessages.INVALID_URL ); - return; + messages.addMessage( new String[] { "doapOptions", "bugDatabase" }, bugDatabase, UserMessages.INVALID_URL ); } - - DoapUtil.writeComment( writer, "Bug database." ); - DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "bug-database", issueManagementUrl ); } /** @@ -1408,7 +1412,7 @@ public class DoapMojo */ private void writeMailingList( XMLWriter writer, MavenProject project ) { - String ml = interpolate( doapOptions.getMailingList(), project, settings ); + String ml = DoapUtil.interpolate( doapOptions.getMailingList(), project, settings ); if ( StringUtils.isEmpty( ml ) ) { messages.addMessage( new String[] { "doapOptions", "mailingList" }, null, @@ -1425,7 +1429,7 @@ public class DoapMojo } catch ( MalformedURLException e ) { - messages.addMessage( new String[] { "project", "mailingList" }, ml, UserMessages.INVALID_URL ); + messages.addMessage( new String[] { "doapOptions", "mailingList" }, ml, UserMessages.INVALID_URL ); } } @@ -1473,8 +1477,8 @@ public class DoapMojo if ( metadata.getMetadata().getVersioning() == null ) { - messages.getWarnMessages().add( "No versioning was found for " + artifact.getGroupId() + ":" + artifact.getArtifactId() - + ". Ignored DOAP <release/> tag." ); + messages.getWarnMessages().add( "No versioning was found for " + artifact.getGroupId() + ":" + + artifact.getArtifactId() + ". Ignored DOAP <release/> tag." ); return; } @@ -1571,25 +1575,56 @@ public class DoapMojo */ private void writeSourceRepositories( XMLWriter writer, MavenProject project ) { - Scm scm = project.getScm(); - if ( scm == null ) + String anonymousConnection = DoapUtil.interpolate( doapOptions.getScmAnonymous(), project, settings ); + if ( StringUtils.isEmpty( anonymousConnection ) ) { - messages.addMessage( new String[] { "project", "scm" }, null, UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); - return; + messages.addMessage( new String[] { "doapOptions", "scmAnonymousConnection" }, null, + UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); } - - String anonymousConnection = scm.getConnection(); - if ( StringUtils.isNotEmpty( anonymousConnection ) ) + else { - DoapUtil.writeComment( writer, "Anonymous Source Repository" ); - writeSourceRepository( writer, project, anonymousConnection ); + DoapUtil.writeComment( writer, "Anonymous Source Repository." ); + + try + { + new URL( anonymousConnection ); + + DoapUtil.writeStartElement( writer, doapOptions.getXmlnsPrefix(), "repository" ); + DoapUtil.writeStartElement( writer, doapOptions.getXmlnsPrefix(), "Repository" ); + DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "location", anonymousConnection ); + writer.endElement(); // Repository + writer.endElement(); // repository + } + catch ( MalformedURLException e ) + { + writeSourceRepository( writer, project, anonymousConnection ); + } } - String developerConnection = scm.getDeveloperConnection(); - if ( StringUtils.isNotEmpty( developerConnection ) ) + String devConnection = DoapUtil.interpolate( doapOptions.getScmDeveloper(), project, settings ); + if ( StringUtils.isEmpty( devConnection ) ) { - DoapUtil.writeComment( writer, "Developer Source Repository" ); - writeSourceRepository( writer, project, developerConnection ); + messages.addMessage( new String[] { "doapOptions", "scmDeveloperConnection" }, null, + UserMessages.REQUIRED_BY_ASF_OR_RECOMMENDED ); + } + else + { + DoapUtil.writeComment( writer, "Developer Source Repository." ); + + try + { + new URL( devConnection ); + + DoapUtil.writeStartElement( writer, doapOptions.getXmlnsPrefix(), "repository" ); + DoapUtil.writeStartElement( writer, doapOptions.getXmlnsPrefix(), "Repository" ); + DoapUtil.writeRdfResourceElement( writer, doapOptions.getXmlnsPrefix(), "location", devConnection ); + writer.endElement(); // Repository + writer.endElement(); // repository + } + catch ( MalformedURLException e ) + { + writeSourceRepository( writer, project, devConnection ); + } } } @@ -1669,18 +1704,17 @@ public class DoapMojo { if ( contributors == null || contributors.isEmpty() ) { - // no msg there, only dev are req return; } boolean isDeveloper = Developer.class.isAssignableFrom( contributors.get( 0 ).getClass() ); if ( isDeveloper ) { - DoapUtil.writeComment( writer, "Main committers" ); + DoapUtil.writeComment( writer, "Main committers." ); } else { - DoapUtil.writeComment( writer, "Contributed persons" ); + DoapUtil.writeComment( writer, "Contributed persons." ); } List<Contributor> maintainers = DoapUtil.getContributorsWithMaintainerRole( i18n, contributors ); @@ -1917,10 +1951,10 @@ public class DoapMojo return; } - DoapUtil.writeComment( writer, "ASF extension" ); + DoapUtil.writeComment( writer, "ASF extension." ); // asfext:pmc - String pmc = interpolate( asfExtOptions.getPmc(), project, settings ); + String pmc = DoapUtil.interpolate( asfExtOptions.getPmc(), project, settings ); if ( StringUtils.isNotEmpty( pmc ) ) { DoapUtil.writeRdfResourceElement( writer, asfExtOptions.getXmlnsPrefix(), "pmc", pmc ); @@ -1931,7 +1965,7 @@ public class DoapMojo } // asfext:name - String name = interpolate( asfExtOptions.getName(), project, settings ); + String name = DoapUtil.interpolate( asfExtOptions.getName(), project, settings ); if ( StringUtils.isNotEmpty( name ) ) { if ( !name.toLowerCase( Locale.ENGLISH ).trim().startsWith( "apache" ) ) @@ -1945,7 +1979,7 @@ public class DoapMojo messages.addMessage( new String[] { "asfExtOptions", "name" }, null, UserMessages.REQUIRED_BY_ASF ); } - String homepage = interpolate( doapOptions.getHomepage(), project, settings ); + String homepage = DoapUtil.interpolate( doapOptions.getHomepage(), project, settings ); if ( StringUtils.isNotEmpty( homepage ) ) { try @@ -2068,16 +2102,17 @@ public class DoapMojo if ( StringUtils.isNotEmpty( standard.getUrl() ) ) { + String standardUrl = standard.getUrl().trim(); try { - new URL( standard.getUrl().trim() ); + new URL( standardUrl ); - DoapUtil.writeElement( writer, asfExtOptions.getXmlnsPrefix(), "url", standard.getUrl().trim() ); + DoapUtil.writeElement( writer, asfExtOptions.getXmlnsPrefix(), "url", standardUrl ); } catch ( MalformedURLException e ) { - messages.addMessage( new String[] { "asfExtOptions", "standards", "url" }, - standard.getUrl().trim(), UserMessages.INVALID_URL ); + messages.addMessage( new String[] { "asfExtOptions", "standards", "url" }, standardUrl, + UserMessages.INVALID_URL ); } } @@ -2147,13 +2182,14 @@ public class DoapMojo */ private void writeAudience( XMLWriter writer ) { - if ( StringUtils.isEmpty( doapOptions.getAudience() ) ) + String audience = DoapUtil.interpolate( doapOptions.getAudience(), project, settings ); + if ( StringUtils.isEmpty( audience ) ) { return; } DoapUtil.writeComment( writer, "Audience." ); - DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "audience", doapOptions.getAudience().trim() ); + DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "audience", audience ); } /** @@ -2165,12 +2201,13 @@ public class DoapMojo */ private void writeBlog( XMLWriter writer ) { + String blog = DoapUtil.interpolate( doapOptions.getBlog(), project, settings ); if ( StringUtils.isEmpty( doapOptions.getBlog() ) ) { return; } - String blog = doapOptions.getBlog().trim(); + blog = blog.trim(); try { new URL( blog ); @@ -2199,8 +2236,12 @@ public class DoapMojo return; } - DoapUtil.writeComment( writer, "Plateform." ); - DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "plateform", doapOptions.getPlatform().trim() ); + DoapUtil.writeComment( writer, "Platform." ); + String[] platforms = StringUtils.split( doapOptions.getPlatform(), "," ); + for ( String platform : platforms ) + { + DoapUtil.writeElement( writer, doapOptions.getXmlnsPrefix(), "platform", platform.trim() ); + } } /** @@ -2213,7 +2254,7 @@ public class DoapMojo */ private void writeVendor( XMLWriter writer, MavenProject project ) { - String vendor = interpolate( doapOptions.getVendor(), project, settings ); + String vendor = DoapUtil.interpolate( doapOptions.getVendor(), project, settings ); if ( StringUtils.isEmpty( vendor ) ) { return; @@ -2245,7 +2286,8 @@ public class DoapMojo if ( Arrays.binarySearch( Locale.getISOLanguages(), language ) < 0 ) { - messages.addMessage( new String[] { "doapOptions", "languages" }, language, UserMessages.INVALID_ISO_DATE ); + messages.addMessage( new String[] { "doapOptions", "languages" }, language, + UserMessages.INVALID_ISO_DATE ); continue; } @@ -2267,12 +2309,13 @@ public class DoapMojo */ private void writeServiceEndpoint( XMLWriter writer ) { - if ( StringUtils.isEmpty( doapOptions.getServiceEndpoint() ) ) + String serviceEndpoint = DoapUtil.interpolate( doapOptions.getServiceEndpoint(), project, settings ); + if ( StringUtils.isEmpty( serviceEndpoint ) ) { return; } - String serviceEndpoint = doapOptions.getServiceEndpoint().trim(); + serviceEndpoint = serviceEndpoint.trim(); try { new URL( serviceEndpoint ); @@ -2339,7 +2382,7 @@ public class DoapMojo continue; } - String interpolatedValue = interpolate( value, project, settings ); + String interpolatedValue = DoapUtil.interpolate( value, project, settings ); if ( interpolatedValue == null ) { continue; @@ -2416,62 +2459,6 @@ public class DoapMojo } /** - * Interpolate a string with project and settings. - * - * @param value not null - * @param project not null - * @param settings not null - * @return the value trimmed and interpolated or null if interpolation doesn't work. - * @since 1.1 - */ - private static String interpolate( String value, MavenProject project, Settings settings ) - { - if ( StringUtils.isEmpty( value ) || project == null ) - { - throw new IllegalArgumentException( "parameters are required" ); - } - - if ( !value.contains( "${" ) ) - { - return value.trim(); - } - - RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); - try - { - interpolator.addValueSource( new EnvarBasedValueSource() ); - } - catch ( IOException e ) - { - } - - interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) ); - interpolator.addValueSource( new PropertiesBasedValueSource( project.getProperties() ) ); - interpolator.addValueSource( new PrefixedObjectValueSource( "project", project ) ); - interpolator.addValueSource( new PrefixedObjectValueSource( "pom", project ) ); - if ( settings != null ) - { - interpolator.addValueSource( new PrefixedObjectValueSource( "settings", settings ) ); - } - - String interpolatedValue = value; - try - { - interpolatedValue = interpolator.interpolate( value ); - } - catch ( InterpolationException e ) - { - } - - if ( interpolatedValue.contains( "${" ) ) - { - return null; - } - - return interpolatedValue.trim(); - } - - /** * Sort Contributor by name or Developer by id. * * @param contributors not null Modified: maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java?rev=1057614&r1=1057613&r2=1057614&view=diff ============================================================================== --- maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java (original) +++ maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java Tue Jan 11 13:28:29 2011 @@ -23,17 +23,21 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.SocketTimeoutException; import java.net.URL; import java.text.DateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.StringTokenizer; +import java.util.WeakHashMap; import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -50,13 +54,21 @@ import org.apache.commons.httpclient.met import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.maven.model.Contributor; +import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.proxy.ProxyUtils; import org.codehaus.plexus.i18n.I18N; +import org.codehaus.plexus.interpolation.EnvarBasedValueSource; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.interpolation.ObjectBasedValueSource; +import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; +import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.introspection.ClassMap; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; @@ -583,6 +595,84 @@ public class DoapUtil } } + /** + * Interpolate a string with project and settings. + * + * @param value could be null + * @param project not null + * @param settings could be null + * @return the value trimmed and interpolated or null if the interpolation doesn't work. + * @since 1.1 + */ + public static String interpolate( String value, final MavenProject project, Settings settings ) + { + if ( project == null ) + { + throw new IllegalArgumentException( "project is required" ); + } + + if ( value == null ) + { + return value; + } + + if ( !value.contains( "${" ) ) + { + return value.trim(); + } + + RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); + try + { + interpolator.addValueSource( new EnvarBasedValueSource() ); + } + catch ( IOException e ) + { + } + interpolator.addValueSource( new PropertiesBasedValueSource( System.getProperties() ) ); + interpolator.addValueSource( new PropertiesBasedValueSource( project.getProperties() ) ); + interpolator.addValueSource( new PrefixedObjectValueSource( "project", project ) ); + interpolator.addValueSource( new PrefixedObjectValueSource( "pom", project ) ); + interpolator.addValueSource( new ObjectBasedValueSource( project ) + { + @Override + public Object getValue( String expression ) + { + try + { + return ReflectionValueExtractor.evaluate( expression, project, true ); + } + catch ( Exception e ) + { + addFeedback( "Failed to extract \'" + expression + "\' from: " + project, e ); + } + + return null; + } + } ); + + if ( settings != null ) + { + interpolator.addValueSource( new PrefixedObjectValueSource( "settings", settings ) ); + } + + String interpolatedValue = value; + try + { + interpolatedValue = interpolator.interpolate( value ).trim(); + } + catch ( InterpolationException e ) + { + } + + if ( interpolatedValue.startsWith( "${" ) ) + { + return null; + } + + return interpolatedValue; + } + // ---------------------------------------------------------------------- // Private methods // ---------------------------------------------------------------------- @@ -731,4 +821,130 @@ public class DoapUtil IOUtil.close( is ); } } + + /** + * Fork of {...@link org.codehaus.plexus.interpolation.reflection.ReflectionValueExtractor} to care of list or arrays. + */ + static class ReflectionValueExtractor + { + @SuppressWarnings( "rawtypes" ) + private static final Class[] CLASS_ARGS = new Class[0]; + + private static final Object[] OBJECT_ARGS = new Object[0]; + + /** + * Use a WeakHashMap here, so the keys (Class objects) can be garbage collected. This approach prevents permgen + * space overflows due to retention of discarded classloaders. + */ + @SuppressWarnings( "rawtypes" ) + private static final Map<Class,ClassMap> classMaps = new WeakHashMap<Class,ClassMap>(); + + private ReflectionValueExtractor() + { + } + + public static Object evaluate( String expression, Object root ) + throws Exception + { + return evaluate( expression, root, true ); + } + + // TODO: don't throw Exception + public static Object evaluate( String expression, Object root, boolean trimRootToken ) + throws Exception + { + // if the root token refers to the supplied root object parameter, remove it. + if ( trimRootToken ) + { + expression = expression.substring( expression.indexOf( '.' ) + 1 ); + } + + Object value = root; + + // ---------------------------------------------------------------------- + // Walk the dots and retrieve the ultimate value desired from the + // MavenProject instance. + // ---------------------------------------------------------------------- + + StringTokenizer parser = new StringTokenizer( expression, "." ); + + while ( parser.hasMoreTokens() ) + { + String token = parser.nextToken(); + if ( value == null ) + { + return null; + } + + StringTokenizer parser2 = new StringTokenizer( token, "[]" ); + int index = -1; + if ( parser2.countTokens() > 1 ) + { + token = parser2.nextToken(); + try + { + index = Integer.valueOf( parser2.nextToken() ).intValue(); + } + catch ( NumberFormatException e ) + { + } + } + + final ClassMap classMap = getClassMap( value.getClass() ); + + final String methodBase = StringUtils.capitalizeFirstLetter( token ); + + String methodName = "get" + methodBase; + + Method method = classMap.findMethod( methodName, CLASS_ARGS ); + + if ( method == null ) + { + // perhaps this is a boolean property?? + methodName = "is" + methodBase; + + method = classMap.findMethod( methodName, CLASS_ARGS ); + } + + if ( method == null ) + { + return null; + } + + value = method.invoke( value, OBJECT_ARGS ); + if ( value == null ) + { + return null; + } + if ( Collection.class.isAssignableFrom( value.getClass() ) ) + { + ClassMap classMap2 = getClassMap( value.getClass() ); + + Method method2 = classMap2.findMethod( "toArray", CLASS_ARGS ); + + value = method2.invoke( value, OBJECT_ARGS ); + } + if ( value.getClass().isArray() ) + { + value = ( (Object[]) value )[index]; + } + } + + return value; + } + + private static ClassMap getClassMap( Class<? extends Object> clazz ) + { + ClassMap classMap = classMaps.get( clazz ); + + if ( classMap == null ) + { + classMap = new ClassMap( clazz ); + + classMaps.put( clazz, classMap ); + } + + return classMap; + } + } } Modified: maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java?rev=1057614&r1=1057613&r2=1057614&view=diff ============================================================================== --- maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java (original) +++ maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java Tue Jan 11 13:28:29 2011 @@ -24,6 +24,7 @@ import java.io.FileReader; import java.io.IOException; import org.apache.maven.plugin.doap.options.DoapArtifact; +import org.apache.maven.plugin.doap.options.DoapOptions; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.IOUtil; @@ -85,13 +86,37 @@ public class DoapMojoTest assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" " + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">" ) ); - if ( StringUtils.isNotEmpty( mavenProject.getUrl() ) ) - { - assertTrue( readed.contains( "<Project rdf:about=\"" + mavenProject.getUrl() + "\">" ) ); - assertTrue( readed.contains( "<homepage rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) ); - } + assertTrue( readed.contains( "<Project rdf:about=\"" + mavenProject.getUrl() + "\">" ) ); + assertTrue( readed.contains( "<description xml:lang=\"en\">Test the DOAP plugin</description>" ) ); + assertTrue( readed.contains( "<shortdesc xml:lang=\"en\">Test the DOAP plugin</shortdesc>" ) ); + assertTrue( readed.contains( "<homepage rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) ); + assertTrue( readed.contains( "<category>library</category>" ) ); + assertTrue( readed.contains( "<created>2008-01-01</created>" ) ); assertTrue( readed.contains( "<name>" + mavenProject.getName() + "</name>" ) ); - assertTrue( readed.contains( "<programming-language>java</programming-language>" ) ); + assertTrue( readed.contains( "<download-page rdf:resource=\"http://foo.org/download.html\"/>" ) ); + assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) ); + assertTrue( readed.contains( "<bug-database rdf:resource=\"http://jira.codehaus.org/browse/MDOAPTEST\"/>" ) ); + assertTrue( readed.contains( "<license rdf:resource=\"http://www.apache.org/licenses/LICENSE-2.0.txt\"/>" ) ); + assertTrue( readed.contains( "<SVNRepository>" ) ); + assertTrue( readed.contains( "<location rdf:resource=\"http://svn.foo.org/repos/asf/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration\"/>" ) ); + assertTrue( readed.contains( "<browse rdf:resource=\"http://svn.foo.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration\"/>" ) ); + assertTrue( readed.contains( "<location rdf:resource=\"https://svn.foo.org/repos/asf/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration\"/>" ) ); + + // conf + assertTrue( readed.contains( "<audience>developers</audience>" ) ); + assertTrue( readed.contains( "<blog rdf:resource=\"http://myblog.foo.org\"/>" ) ); + assertTrue( readed.contains( "<implements>JSR-foo</implements>" ) ); + assertTrue( readed.contains( "<language>en</language>" ) ); + assertTrue( readed.contains( "<language>fr</language>" ) ); + assertTrue( readed.contains( "<old-homepage rdf:resource=\"http://old.foo.org\"/>" ) ); + assertTrue( readed.contains( "<os>windows</os>" ) ); + assertTrue( readed.contains( "<os>linux</os>" ) ); + assertTrue( readed.contains( "<os>mac</os>" ) ); + assertTrue( readed.contains( "<platform>java</platform>" ) ); + assertTrue( readed.contains( "<platform>firefox</platform>" ) ); + assertTrue( readed.contains( "<screenshots rdf:resource=\"" + mavenProject.getUrl() +"/screenshots.html\"/>" ) ); + assertTrue( readed.contains( "<service-endpoint rdf:resource=\"http://webservice.foo.org\"/>" ) ); + assertTrue( readed.contains( "<wiki rdf:resource=\"http://wiki.foo.org\"/>" ) ); // ASF ext assertFalse( readed.contains( "<asfext:pmc rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) ); @@ -109,10 +134,9 @@ public class DoapMojoTest /** * @throws Exception if any */ - public void testLangParameters() + public void testLangParameter() throws Exception { - File pluginXmlFile = new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" ); DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile ); @@ -181,6 +205,11 @@ public class DoapMojoTest // Set some Mojo parameters setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() ); setVariableValueToObject( mojo, "about", mavenProject.getUrl() ); + DoapOptions doapOptions = (DoapOptions)getVariableValueFromObject( mojo, "doapOptions" ); + doapOptions.setDescription( "Common Utilities" ); + doapOptions.setShortdesc( "Common Utilities" ); + doapOptions.setDownloadPage( "http://plexus.codehaus.org/download-binaries.html" ); + setVariableValueToObject( mojo, "doapOptions", doapOptions ); DoapArtifact artifact = new DoapArtifact(); artifact.setGroupId( "org.codehaus.plexus" ); @@ -202,7 +231,111 @@ public class DoapMojoTest assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" " + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">" ) ); + assertTrue( readed.contains( "<Project rdf:about=\"http://plexus.codehaus.org/plexus-utils\">" ) ); assertTrue( readed.contains( "<name>Plexus Common Utilities</name>" ) ); + assertTrue( readed.contains( "<description xml:lang=\"en\">Common Utilities</description>" ) ); + assertTrue( readed.contains( "<shortdesc xml:lang=\"en\">Common Utilities</shortdesc>" ) ); + assertTrue( readed.contains( "<created>2001-01-01</created>" ) ); + assertTrue( readed.contains( "<download-page rdf:resource=\"http://plexus.codehaus.org/download-binaries.html\"/>" ) ); + assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) ); + assertTrue( readed.contains( "<bug-database rdf:resource=\"http://jira.codehaus.org/browse/PLXUTILS\"/>" ) ); + assertTrue( readed.contains( "<license rdf:resource=\"http://www.apache.org/licenses/LICENSE-2.0.txt\"/>" ) ); + assertTrue( readed.contains( "<SVNRepository>" ) ); + assertTrue( readed.contains( "<location rdf:resource=\"http://svn.codehaus.org/plexus/plexus-utils/tags/plexus-utils-1.5.5\"/>" ) ); + assertTrue( readed.contains( "<browse rdf:resource=\"http://fisheye.codehaus.org/browse/plexus/plexus-utils/tags/plexus-utils-1.5.5\"/>" ) ); + + // conf + assertTrue( readed.contains( "<audience>developers</audience>" ) ); + assertTrue( readed.contains( "<blog rdf:resource=\"http://myblog.foo.org\"/>" ) ); + assertTrue( readed.contains( "<implements>JSR-foo</implements>" ) ); + assertTrue( readed.contains( "<language>en</language>" ) ); + assertTrue( readed.contains( "<language>fr</language>" ) ); + assertTrue( readed.contains( "<old-homepage rdf:resource=\"http://old.foo.org\"/>" ) ); + assertTrue( readed.contains( "<os>windows</os>" ) ); + assertTrue( readed.contains( "<os>linux</os>" ) ); + assertTrue( readed.contains( "<os>mac</os>" ) ); + assertTrue( readed.contains( "<platform>java</platform>" ) ); + assertTrue( readed.contains( "<screenshots rdf:resource=\"http://plexus.codehaus.org/plexus-utils/screenshots.html\"/>" ) ); + assertTrue( readed.contains( "<service-endpoint rdf:resource=\"http://webservice.foo.org\"/>" ) ); + assertTrue( readed.contains( "<wiki rdf:resource=\"http://wiki.foo.org\"/>" ) ); + } + + /** + * Verify the generation of a DOAP file from a minimalist artifact. + * + * @throws Exception if any + */ + public void testGeneratedDoapArtifactMinimalist() + throws Exception + { + File pluginXmlFile = + new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" ); + DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile ); + assertNotNull( "Mojo found.", mojo ); + + MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" ); + assertNotNull( mavenProject ); + + // Set some Mojo parameters + setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() ); + setVariableValueToObject( mojo, "about", "foo" ); + DoapOptions doapOptions = new DoapOptions(); + doapOptions.setName( "XStream" ); + doapOptions.setDescription( "XStream is a simple library to serialize objects to XML and back again." ); + doapOptions.setShortdesc( "XML Serializer" ); + doapOptions.setHomepage( "http://xstream.codehaus.org/" ); + doapOptions.setDownloadPage( "http://xstream.codehaus.org/download.html" ); + doapOptions.setBugDatabase( "http://jira.codehaus.org/browse/XSTR" ); + doapOptions.setLicense( "http://xstream.codehaus.org/license.html" ); + doapOptions.setScmDeveloper( "http://svn.codehaus.org/xstream/trunk/xstream" ); + doapOptions.setMailingList( "http://xstream.codehaus.org/list-user.html" ); + doapOptions.setCreated( "2000-01-01"); + setVariableValueToObject( mojo, "doapOptions", doapOptions ); + + DoapArtifact artifact = new DoapArtifact(); + artifact.setGroupId( "xstream" ); + artifact.setArtifactId( "xstream" ); + artifact.setVersion( "1.1" ); + setVariableValueToObject( mojo, "artifact", artifact ); + setVariableValueToObject( mojo, "outputDirectory", "target/test/unit/doap-configuration/" ); + + mojo.execute(); + + File doapFile = new File( getBasedir(), "target/test/unit/doap-configuration/doap_xstream.rdf" ); + assertTrue( "Doap File was not generated!", doapFile.exists() ); + + String readed = readFile( doapFile ); + + // Validate + + // Pure DOAP + assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" " + + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " + + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">" ) ); + assertTrue( readed.contains( "<Project>" ) ); + assertTrue( readed.contains( "<name>XStream</name>" ) ); + assertTrue( readed.contains( "<description xml:lang=\"en\">XStream is a simple library to serialize objects to XML and back again.</description>" ) ); + assertTrue( readed.contains( "<shortdesc xml:lang=\"en\">XML Serializer</shortdesc>" ) ); + assertTrue( readed.contains( "<created>2000-01-01</created>" ) ); + assertTrue( readed.contains( "<download-page rdf:resource=\"http://xstream.codehaus.org/download.html\"/>" ) ); + assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) ); + assertTrue( readed.contains( "<bug-database rdf:resource=\"http://jira.codehaus.org/browse/XSTR\"/>" ) ); + assertTrue( readed.contains( "<license rdf:resource=\"http://xstream.codehaus.org/license.html\"/>" ) ); + assertTrue( readed.contains( "<Repository>" ) ); + assertTrue( readed.contains( "<location rdf:resource=\"http://svn.codehaus.org/xstream/trunk/xstream\"/>" ) ); + assertTrue( readed.contains( "<mailing-list rdf:resource=\"http://xstream.codehaus.org/list-user.html\"/>" ) ); + + // conf + assertFalse( readed.contains( "<audience>" ) ); + assertFalse( readed.contains( "<blog rdf:resource=" ) ); + assertFalse( readed.contains( "<implements>" ) ); + assertFalse( readed.contains( "<language>" ) ); + assertFalse( readed.contains( "<old-homepage rdf:resource=" ) ); + assertFalse( readed.contains( "<os>" ) ); + assertFalse( readed.contains( "<platform>" ) ); + assertFalse( readed.contains( "<screenshots rdf:resource=" ) ); + assertFalse( readed.contains( "<service-endpoint rdf:resource=" ) ); + assertFalse( readed.contains( "<wiki rdf:resource=" ) ); } /** @@ -246,10 +379,13 @@ public class DoapMojoTest } assertTrue( readed.contains( "<name>Apache " + mavenProject.getName() + "</name>" ) ); assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) ); + assertTrue( readed.contains( "<category rdf:resource=\"http://projects.apache.org/category/library\"/>" ) ); // ASF ext assertTrue( readed.contains( "<asfext:pmc rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) ); assertTrue( readed.contains( "<asfext:name>Apache " + mavenProject.getName() + "</asfext:name>" ) ); + assertTrue( readed.contains( "<asfext:charter>" ) ); + assertTrue( readed.contains( "<asfext:chair>" ) ); } /** Modified: maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java?rev=1057614&r1=1057613&r2=1057614&view=diff ============================================================================== --- maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java (original) +++ maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java Tue Jan 11 13:28:29 2011 @@ -22,10 +22,13 @@ package org.apache.maven.plugin.doap; import java.io.File; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.maven.model.Contributor; import org.apache.maven.model.Developer; +import org.apache.maven.model.License; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; @@ -201,4 +204,47 @@ public class DoapUtilTest File doapFile = new File( getBasedir(), "src/test/resources/generated-doap-1.0.rdf" ); assertFalse( DoapUtil.validate( doapFile ).isEmpty() ); } + + /** + * Test method for: + * {...@link DoapUtil#interpolate(String, MavenProject, org.apache.maven.settings.Settings)} + * + * @throws Exception if any + */ + public void testInterpolate() + throws Exception + { + License license = new License(); + license.setName( "licenseName" ); + license.setUrl( "licenseUrl" ); + + List<Developer> developers = new ArrayList<Developer>(); + Developer developer1 = new Developer(); + developer1.setId( "id1" ); + developer1.setName( "developerName1" ); + developers.add( developer1 ); + Developer developer2 = new Developer(); + developer2.setId( "id1" ); + developer2.setName( "developerName2" ); + developers.add( developer2 ); + + MavenProject project = new MavenProject(); + project.setName( "projectName" ); + project.setDescription( "projectDescription" ); + project.setLicenses( Collections.singletonList( license ) ); + project.setDevelopers( developers ); + project.getProperties().put( "myKey", "myValue" ); + + assertEquals( DoapUtil.interpolate( "${project.name}", project, null ), "projectName" ); + assertEquals( DoapUtil.interpolate( "my name is ${project.name}", project, null ), "my name is projectName" ); + assertEquals( DoapUtil.interpolate( "my name is ${project.invalid}", project, null ), "my name is ${project.invalid}" ); + assertEquals( DoapUtil.interpolate( "${pom.description}", project, null ), "projectDescription" ); + assertNull( DoapUtil.interpolate( "${project.licenses.name}", project, null ) ); + assertEquals( DoapUtil.interpolate( "${project.licenses[0].name}", project, null ), "licenseName" ); + assertNull( DoapUtil.interpolate( "${project.licenses[1].name}", project, null ) ); + assertNotNull( DoapUtil.interpolate( "${project.developers}", project, null ) ); + assertEquals( DoapUtil.interpolate( "${project.developers[0].name}", project, null ), "developerName1" ); + assertEquals( DoapUtil.interpolate( "${project.developers[1].name}", project, null ), "developerName2" ); + assertEquals( DoapUtil.interpolate( "${myKey}", project, null ), "myValue" ); + } } Modified: maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml?rev=1057614&r1=1057613&r2=1057614&view=diff ============================================================================== --- maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml (original) +++ maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml Tue Jan 11 13:28:29 2011 @@ -92,15 +92,13 @@ under the License. <doapOptions> <audience>developers</audience> <blog>http://myblog.foo.org</blog> - <category>library</category> <downloadMirror>http://mirror.foo.org</downloadMirror> <implementations>JSR-foo</implementations> <language>en,fr</language> <oldHomepage>http://old.foo.org</oldHomepage> <os>windows,linux,mac</os> - <platform>java</platform> - <programmingLanguage>java</programmingLanguage> - <screenshots>http://screenshot.foo.org</screenshots> + <platform>java,firefox</platform> + <screenshots>${project.url}/screenshots.html</screenshots> <serviceEndpoint>http://webservice.foo.org</serviceEndpoint> <wiki>http://wiki.foo.org</wiki> </doapOptions>