diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java index 5434f50228b..d47416ad7e7 100644 --- a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java +++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java @@ -32,6 +32,7 @@ import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.License; import org.apache.maven.model.Model; +import org.apache.maven.model.Prerequisites; import org.apache.maven.model.Relocation; import org.apache.maven.model.Repository; import org.apache.maven.model.building.DefaultModelBuilderFactory; @@ -88,6 +89,7 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader, Service { + @SuppressWarnings( "unused" ) @Requirement private Logger logger = NullLogger.INSTANCE; @@ -195,6 +197,12 @@ public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession Map properties = new LinkedHashMap(); + Prerequisites prerequisites = model.getPrerequisites(); + if ( prerequisites != null ) + { + properties.put( "prerequisites.maven", prerequisites.getMaven() ); + } + List licenses = model.getLicenses(); properties.put( "license.count", Integer.valueOf( licenses.size() ) ); for ( int i = 0; i < licenses.size(); i++ ) diff --git a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java index d2623612424..5233fbcda60 100644 --- a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java +++ b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java @@ -22,17 +22,14 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; -import org.codehaus.plexus.util.IOUtil; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; +import org.codehaus.plexus.util.StringUtils; /** * Describes runtime information about the application. - * + * * @author Brett Porter * @version $Id$ */ @@ -41,9 +38,9 @@ public class DefaultRuntimeInformation implements RuntimeInformation, Initializable { - private static final String MAVEN_GROUPID = "org.apache.maven"; - private static final String MAVEN_PROPERTIES = "META-INF/maven/" + MAVEN_GROUPID + "/maven-core/pom.properties"; + @Requirement + private org.apache.maven.rtinfo.RuntimeInformation rtInfo; private ArtifactVersion applicationVersion; @@ -55,33 +52,14 @@ public ArtifactVersion getApplicationVersion() public void initialize() throws InitializationException { - InputStream resourceAsStream = null; - try - { - Properties properties = new Properties(); - resourceAsStream = getClass().getClassLoader().getResourceAsStream( MAVEN_PROPERTIES ); - - if ( resourceAsStream == null ) - { - throw new IllegalStateException( "Unable to find Maven properties in classpath: " + MAVEN_PROPERTIES ); - } - properties.load( resourceAsStream ); - - String property = properties.getProperty( "version" ); - if ( property == null ) - { - throw new InitializationException( "maven-core properties did not include the version" ); - } + String mavenVersion = rtInfo.getMavenVersion(); - applicationVersion = new DefaultArtifactVersion( property ); - } - catch ( IOException e ) - { - throw new InitializationException( "Unable to read properties file from maven-core", e ); - } - finally + if ( StringUtils.isEmpty( mavenVersion ) ) { - IOUtil.close( resourceAsStream ); + throw new InitializationException( "Unable to read Maven version from maven-core" ); } + + applicationVersion = new DefaultArtifactVersion( mavenVersion ); } + } diff --git a/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java index 85a87bed9aa..103b36f0600 100644 --- a/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java +++ b/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java @@ -24,9 +24,11 @@ /** * Describes runtime information about the application. * + * @deprecated Use {@link org.apache.maven.rtinfo.RuntimeInformation} instead. * @author Brett Porter * @version $Id$ */ +@Deprecated public interface RuntimeInformation { ArtifactVersion getApplicationVersion(); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 7ab5f897bcc..a66085fa0b4 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -27,10 +27,12 @@ import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.MissingProjectException; import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginIncompatibleException; import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; @@ -64,6 +66,9 @@ public class MojoExecutor @Requirement private BuildPluginManager pluginManager; + @Requirement + private MavenPluginManager mavenPluginManager; + @Requirement private LifecycleDependencyResolver lifeCycleDependencyResolver; @@ -156,6 +161,15 @@ private void execute( MavenSession session, MojoExecution mojoExecution, Project { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + try + { + mavenPluginManager.checkRequiredMavenVersion( mojoDescriptor.getPluginDescriptor() ); + } + catch ( PluginIncompatibleException e ) + { + throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); + } + if ( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() ) { Throwable cause = diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java index a38a1d03d39..96b82740be0 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginDescriptorCache.java @@ -72,7 +72,7 @@ public void put( Key cacheKey, PluginDescriptor pluginDescriptor ) descriptors.put( cacheKey, clone( pluginDescriptor ) ); } - private static PluginDescriptor clone( PluginDescriptor original ) + protected static PluginDescriptor clone( PluginDescriptor original ) { PluginDescriptor clone = null; @@ -88,6 +88,7 @@ private static PluginDescriptor clone( PluginDescriptor original ) clone.setName( original.getName() ); clone.setDescription( original.getDescription() ); + clone.setRequiredMavenVersion( original.getRequiredMavenVersion() ); clone.setPluginArtifact( ArtifactUtils.copyArtifactSafe( original.getPluginArtifact() ) ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java index 567aba67782..18ca9c9ab08 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginManager.java @@ -67,6 +67,14 @@ MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List repositories, RepositorySystemSession session ) @@ -134,11 +139,15 @@ public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, List imports, DependencyFilter filter ) throws PluginResolutionException, PluginContainerException diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java index d251483cc48..d9d91f86b27 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java @@ -19,7 +19,9 @@ * under the License. */ +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.apache.maven.ArtifactFilterManager; import org.apache.maven.RepositoryUtils; @@ -40,9 +42,13 @@ import org.sonatype.aether.graph.DependencyNode; import org.sonatype.aether.graph.DependencyVisitor; import org.sonatype.aether.repository.RemoteRepository; +import org.sonatype.aether.resolution.ArtifactDescriptorException; +import org.sonatype.aether.resolution.ArtifactDescriptorRequest; +import org.sonatype.aether.resolution.ArtifactDescriptorResult; import org.sonatype.aether.resolution.ArtifactRequest; import org.sonatype.aether.resolution.ArtifactResolutionException; import org.sonatype.aether.util.DefaultRepositorySystemSession; +import org.sonatype.aether.util.FilterRepositorySystemSession; import org.sonatype.aether.util.artifact.DefaultArtifact; import org.sonatype.aether.util.artifact.JavaScopes; import org.sonatype.aether.util.filter.AndDependencyFilter; @@ -86,6 +92,36 @@ public Artifact resolve( Plugin plugin, List repositories, Rep { Artifact pluginArtifact = toArtifact( plugin, session ); + try + { + RepositorySystemSession pluginSession = new FilterRepositorySystemSession( session ) + { + @Override + public boolean isIgnoreMissingArtifactDescriptor() + { + return false; + } + }; + + ArtifactDescriptorRequest request = + new ArtifactDescriptorRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT ); + ArtifactDescriptorResult result = repoSystem.readArtifactDescriptor( pluginSession, request ); + + pluginArtifact = result.getArtifact(); + + String requiredMavenVersion = (String) result.getProperties().get( "prerequisites.maven" ); + if ( requiredMavenVersion != null ) + { + Map props = new LinkedHashMap( pluginArtifact.getProperties() ); + props.put( "requiredMavenVersion", requiredMavenVersion ); + pluginArtifact = pluginArtifact.setProperties( props ); + } + } + catch ( ArtifactDescriptorException e ) + { + throw new PluginResolutionException( plugin, e ); + } + try { ArtifactRequest request = new ArtifactRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java index 0b62ed7e615..96cbc845590 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java @@ -22,14 +22,19 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeSet; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.repository.metadata.io.MetadataReader; import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MavenPluginManager; +import org.apache.maven.plugin.PluginResolutionException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.version.PluginVersionRequest; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolver; @@ -43,12 +48,15 @@ import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.repository.ArtifactRepository; -import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.resolution.MetadataRequest; import org.sonatype.aether.resolution.MetadataResult; import org.sonatype.aether.util.listener.DefaultRepositoryEvent; import org.sonatype.aether.util.metadata.DefaultMetadata; +import org.sonatype.aether.util.version.GenericVersionScheme; +import org.sonatype.aether.version.InvalidVersionSpecificationException; +import org.sonatype.aether.version.Version; +import org.sonatype.aether.version.VersionScheme; /** * Resolves a version for a plugin. @@ -72,6 +80,9 @@ public class DefaultPluginVersionResolver @Requirement private MetadataReader metadataReader; + @Requirement + private MavenPluginManager pluginManager; + public PluginVersionResult resolve( PluginVersionRequest request ) throws PluginVersionResolutionException { @@ -118,8 +129,6 @@ private PluginVersionResult resolveFromRepository( PluginVersionRequest request List results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests ); - LocalRepository localRepo = request.getRepositorySession().getLocalRepository(); - Versions versions = new Versions(); for ( MetadataResult res : results ) @@ -133,24 +142,137 @@ private PluginVersionResult resolveFromRepository( PluginVersionRequest request mergeMetadata( request.getRepositorySession(), versions, res.getMetadata(), repository ); } + selectVersion( result, request, versions ); + + return result; + } + + private void selectVersion( DefaultPluginVersionResult result, PluginVersionRequest request, Versions versions ) + throws PluginVersionResolutionException + { + String version = null; + ArtifactRepository repo = null; + if ( StringUtils.isNotEmpty( versions.releaseVersion ) ) { - result.setVersion( versions.releaseVersion ); - result.setRepository( ( versions.releaseRepository == null ) ? localRepo : versions.releaseRepository ); + version = versions.releaseVersion; + repo = versions.releaseRepository; } else if ( StringUtils.isNotEmpty( versions.latestVersion ) ) { - result.setVersion( versions.latestVersion ); - result.setRepository( ( versions.latestRepository == null ) ? localRepo : versions.latestRepository ); + version = versions.latestVersion; + repo = versions.latestRepository; + } + if ( version != null && !isCompatible( request, version ) ) + { + versions.versions.remove( version ); + version = null; + } + + if ( version == null ) + { + VersionScheme versionScheme = new GenericVersionScheme(); + + TreeSet releases = new TreeSet( Collections.reverseOrder() ); + TreeSet snapshots = new TreeSet( Collections.reverseOrder() ); + + for ( String ver : versions.versions.keySet() ) + { + try + { + Version v = versionScheme.parseVersion( ver ); + + if ( ver.endsWith( "-SNAPSHOT" ) ) + { + snapshots.add( v ); + } + else + { + releases.add( v ); + } + } + catch ( InvalidVersionSpecificationException e ) + { + continue; + } + } + + for ( Version v : releases ) + { + String ver = v.toString(); + if ( isCompatible( request, ver ) ) + { + version = ver; + repo = versions.versions.get( version ); + break; + } + } + + if ( version == null ) + { + for ( Version v : snapshots ) + { + String ver = v.toString(); + if ( isCompatible( request, ver ) ) + { + version = ver; + repo = versions.versions.get( version ); + break; + } + } + } + } + + if ( version != null ) + { + result.setVersion( version ); + result.setRepository( repo ); } else { - throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(), localRepo, + throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(), + request.getRepositorySession().getLocalRepository(), request.getRepositories(), "Plugin not found in any plugin repository" ); } + } - return result; + private boolean isCompatible( PluginVersionRequest request, String version ) + { + Plugin plugin = new Plugin(); + plugin.setGroupId( request.getGroupId() ); + plugin.setArtifactId( request.getArtifactId() ); + plugin.setVersion( version ); + + PluginDescriptor pluginDescriptor; + + try + { + pluginDescriptor = + pluginManager.getPluginDescriptor( plugin, request.getRepositories(), request.getRepositorySession() ); + } + catch ( PluginResolutionException e ) + { + logger.debug( "Ignoring unresolvable plugin version " + version, e ); + return false; + } + catch ( Exception e ) + { + // ignore for now and delay failure to higher level processing + return true; + } + + try + { + pluginManager.checkRequiredMavenVersion( pluginDescriptor ); + } + catch ( Exception e ) + { + logger.debug( "Ignoring incompatible plugin version " + version + ": " + e.getMessage() ); + return false; + } + + return true; } private void mergeMetadata( RepositorySystemSession session, Versions versions, @@ -209,6 +331,14 @@ private void mergeMetadata( Versions versions, Metadata source, ArtifactReposito versions.latestTimestamp = timestamp; versions.latestRepository = repository; } + + for ( String version : versioning.getVersions() ) + { + if ( !versions.versions.containsKey( version ) ) + { + versions.versions.put( version, repository ); + } + } } } @@ -266,6 +396,8 @@ static class Versions ArtifactRepository latestRepository; + Map versions = new LinkedHashMap(); + } } diff --git a/maven-core/src/main/java/org/apache/maven/rtinfo/RuntimeInformation.java b/maven-core/src/main/java/org/apache/maven/rtinfo/RuntimeInformation.java new file mode 100644 index 00000000000..5f5fe475a4c --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/rtinfo/RuntimeInformation.java @@ -0,0 +1,49 @@ +package org.apache.maven.rtinfo; + +/* + * 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. + */ + +/** + * Provides information about the current Maven runtime. + * + * @since 3.0.2 + */ +public interface RuntimeInformation +{ + + /** + * Retrieves the current Maven version, for example "3.0.2". + * + * @return The current Maven version or an empty string if unknown, never {@code null}. + */ + String getMavenVersion(); + + /** + * Checks whether the current Maven runtime matches the specified version range. A version range can either use the + * usual mathematical syntax "[2.0.10,2.1.0),[3.0,)" or use a single version "2.2.1". The latter is a short form for + * "[2.2.1,)", i.e. denotes the minimum version required. + * + * @param versionRange The version range to match the current Maven runtime against, must not be {@code null}. + * @return {@code true} if the current Maven runtime matches the specified version range, {@code false} otherwise. + * @throws IllegalArgumentException If the specified version range is {@code null}, empty or otherwise not a valid + * version specification. + */ + boolean isMavenVersion( String versionRange ); + +} diff --git a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java new file mode 100644 index 00000000000..04ec4fe3ca6 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java @@ -0,0 +1,149 @@ +package org.apache.maven.rtinfo.internal; + +/* + * 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 java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.maven.rtinfo.RuntimeInformation; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; +import org.sonatype.aether.util.version.GenericVersionScheme; +import org.sonatype.aether.version.InvalidVersionSpecificationException; +import org.sonatype.aether.version.Version; +import org.sonatype.aether.version.VersionConstraint; +import org.sonatype.aether.version.VersionScheme; + +/** + * Provides information about the current Maven runtime. + */ +@Component( role = RuntimeInformation.class ) +public class DefaultRuntimeInformation + implements RuntimeInformation +{ + + @Requirement + private Logger logger; + + private String mavenVersion; + + public String getMavenVersion() + { + if ( mavenVersion == null ) + { + Properties props = new Properties(); + + String resource = "META-INF/maven/org.apache.maven/maven-core/pom.properties"; + + InputStream is = DefaultRuntimeInformation.class.getResourceAsStream( "/" + resource ); + if ( is != null ) + { + try + { + props.load( is ); + } + catch ( IOException e ) + { + String msg = "Could not parse " + resource + ", Maven runtime information not available"; + if ( logger.isDebugEnabled() ) + { + logger.warn( msg, e ); + } + else + { + logger.warn( msg ); + } + } + finally + { + IOUtil.close( is ); + } + } + else + { + logger.warn( "Could not locate " + resource + " on classpath, Maven runtime information not available" ); + } + + String version = props.getProperty( "version", "" ).trim(); + + if ( !version.startsWith( "${" ) ) + { + mavenVersion = version; + } + else + { + mavenVersion = ""; + } + } + + return mavenVersion; + } + + public boolean isMavenVersion( String versionRange ) + { + VersionScheme versionScheme = new GenericVersionScheme(); + + if ( versionRange == null ) + { + throw new IllegalArgumentException( "Version range must not be null" ); + } + if ( StringUtils.isBlank( versionRange ) ) + { + throw new IllegalArgumentException( "Version range must not be empty" ); + } + + VersionConstraint constraint; + try + { + constraint = versionScheme.parseVersionConstraint( versionRange ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new IllegalArgumentException( e.getMessage(), e ); + } + + Version current; + try + { + String mavenVersion = getMavenVersion(); + if ( mavenVersion.length() <= 0 ) + { + throw new IllegalStateException( "Could not determine current Maven version" ); + } + + current = versionScheme.parseVersion( mavenVersion ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new IllegalStateException( "Could not parse current Maven version: " + e.getMessage(), e ); + } + + if ( constraint.getRanges().isEmpty() ) + { + return constraint.getVersion().compareTo( current ) <= 0; + } + return constraint.containsVersion( current ); + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java new file mode 100644 index 00000000000..71be9284c73 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformationTest.java @@ -0,0 +1,81 @@ +package org.apache.maven.rtinfo.internal; + +/* + * 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.apache.maven.rtinfo.RuntimeInformation; +import org.codehaus.plexus.PlexusTestCase; + +public class DefaultRuntimeInformationTest + extends PlexusTestCase +{ + + public void testGetMavenVersion() + throws Exception + { + RuntimeInformation rtInfo = lookup( RuntimeInformation.class ); + + String mavenVersion = rtInfo.getMavenVersion(); + assertNotNull( mavenVersion ); + assertTrue( mavenVersion.length() > 0 ); + } + + public void testIsMavenVersion() + throws Exception + { + RuntimeInformation rtInfo = lookup( RuntimeInformation.class ); + + assertTrue( rtInfo.isMavenVersion( "2.0" ) ); + assertFalse( rtInfo.isMavenVersion( "9.9" ) ); + + assertTrue( rtInfo.isMavenVersion( "[2.0.11,2.1.0),[3.0,)" ) ); + assertFalse( rtInfo.isMavenVersion( "[9.0,)" ) ); + + try + { + rtInfo.isMavenVersion( "[3.0," ); + fail( "Bad version range wasn't rejected" ); + } + catch ( IllegalArgumentException e ) + { + assertTrue( true ); + } + + try + { + rtInfo.isMavenVersion( "" ); + fail( "Bad version range wasn't rejected" ); + } + catch ( IllegalArgumentException e ) + { + assertTrue( true ); + } + + try + { + rtInfo.isMavenVersion( null ); + fail( "Bad version range wasn't rejected" ); + } + catch ( IllegalArgumentException e ) + { + assertTrue( true ); + } + } + +} diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index d9079c3a565..856893bc062 100644 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -79,6 +79,8 @@ public class PluginDescriptor private String description; + private String requiredMavenVersion; + private Plugin plugin; private Artifact pluginArtifact; @@ -89,7 +91,7 @@ public class PluginDescriptor // // ---------------------------------------------------------------------- - @SuppressWarnings( "unchecked" ) + @SuppressWarnings( { "unchecked", "rawtypes" } ) public List getMojos() { return (List) getComponents(); @@ -332,6 +334,16 @@ public String getDescription() return description; } + public void setRequiredMavenVersion( String requiredMavenVersion ) + { + this.requiredMavenVersion = requiredMavenVersion; + } + + public String getRequiredMavenVersion() + { + return requiredMavenVersion; + } + public void setPlugin( Plugin plugin ) { this.plugin = plugin;