You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2010/09/23 17:08:18 UTC

svn commit: r1000491 - in /maven/shared/trunk/maven-plugin-enforcer: ./ src/main/java/org/apache/maven/util/pluginenforcer/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/maven/ src/test/java/org/apache/m...

Author: stephenc
Date: Thu Sep 23 15:08:18 2010
New Revision: 1000491

URL: http://svn.apache.org/viewvc?rev=1000491&view=rev
Log:
adding some unit tests

Added:
    maven/shared/trunk/maven-plugin-enforcer/src/test/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/
    maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java   (with props)
Modified:
    maven/shared/trunk/maven-plugin-enforcer/pom.xml
    maven/shared/trunk/maven-plugin-enforcer/src/main/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipant.java

Modified: maven/shared/trunk/maven-plugin-enforcer/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-enforcer/pom.xml?rev=1000491&r1=1000490&r2=1000491&view=diff
==============================================================================
--- maven/shared/trunk/maven-plugin-enforcer/pom.xml (original)
+++ maven/shared/trunk/maven-plugin-enforcer/pom.xml Thu Sep 23 15:08:18 2010
@@ -1,17 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-  <!--
-    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.
-  -->
+<!--
+  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.
+-->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
@@ -32,7 +32,8 @@
 
   <scm>
     <connection>scm:svn:http://svn.apache.org/repos/asf/maven/shared/trunk/maven/maven-plugin-enforcer</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/shared/trunk/maven/maven-plugin-enforcer</developerConnection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/shared/trunk/maven/maven-plugin-enforcer
+    </developerConnection>
     <url>http://svn.apache.org/viewcvs.cgi/maven/shared/trunk/maven/maven-plugin-enforcer</url>
   </scm>
 
@@ -52,7 +53,13 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.2</version>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <version>1.8.5</version>
       <scope>test</scope>
     </dependency>
   </dependencies>

Modified: maven/shared/trunk/maven-plugin-enforcer/src/main/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipant.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-enforcer/src/main/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipant.java?rev=1000491&r1=1000490&r2=1000491&view=diff
==============================================================================
--- maven/shared/trunk/maven-plugin-enforcer/src/main/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipant.java (original)
+++ maven/shared/trunk/maven-plugin-enforcer/src/main/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipant.java Thu Sep 23 15:08:18 2010
@@ -23,7 +23,6 @@ import org.apache.maven.MavenExecutionEx
 import org.apache.maven.artifact.ArtifactUtils;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Plugin;
-import org.apache.maven.model.ReportPlugin;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -71,6 +70,11 @@ public class PluginEnforcingMavenLifecyc
             String groupId = parts.length == 3 ? parts[0] : "org.apache.maven.plugins";
             String artifactId = parts[parts.length - 2];
             String version = parts[parts.length - 1];
+            if ( StringUtils.isEmpty( groupId ) || StringUtils.isEmpty( artifactId ) || StringUtils.isEmpty( version ) )
+            {
+                logger.warn( "\"" + forcePlugin + "\" does not match the format [groupId:]artifactId:version" );
+                continue;
+            }
             logger.info( "Forcing " + ArtifactUtils.versionlessKey( groupId, artifactId ) + " to " + version );
             logger.info( "" );
             for ( MavenProject project : session.getProjects() )

Added: maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java?rev=1000491&view=auto
==============================================================================
--- maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java (added)
+++ maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java Thu Sep 23 15:08:18 2010
@@ -0,0 +1,135 @@
+package org.apache.maven.util.pluginenforcer;
+/*
+* 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.execution.MavenSession;
+import org.codehaus.plexus.logging.Logger;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * Unit tests of {@link org.apache.maven.util.pluginenforcer.PluginEnforcingMavenLifecycleParticipant}.
+ *
+ * @author Stephen Connolly
+ * @since Sep 23, 2010 3:30:12 PM
+ */
+public class PluginEnforcingMavenLifecycleParticipantTest
+{
+
+    private PluginEnforcingMavenLifecycleParticipant newInstance( Logger logger )
+        throws NoSuchFieldException, IllegalAccessException
+    {
+        PluginEnforcingMavenLifecycleParticipant instance = new PluginEnforcingMavenLifecycleParticipant();
+        final Field loggerField = PluginEnforcingMavenLifecycleParticipant.class.getDeclaredField( "logger" );
+        loggerField.setAccessible( true );
+        loggerField.set( instance, logger );
+        return instance;
+    }
+
+    @Test
+    public void nothingToDo()
+        throws Exception
+    {
+        MavenSession session = mock( MavenSession.class );
+        Logger logger = mock( Logger.class );
+        PluginEnforcingMavenLifecycleParticipant instance = newInstance( logger );
+        when( session.getUserProperties() ).thenReturn( new Properties() );
+        instance.afterProjectsRead( session );
+        verify( logger ).info( contains( "Nothing to do" ) );
+    }
+
+    @Test
+    public void malformedTooSmall()
+        throws Exception
+    {
+        MavenSession session = mock( MavenSession.class );
+        Logger logger = mock( Logger.class );
+        PluginEnforcingMavenLifecycleParticipant instance = newInstance( logger );
+        final Properties properties = new Properties();
+        properties.setProperty( "force.plugins", "true" );
+        when( session.getUserProperties() ).thenReturn( properties );
+        instance.afterProjectsRead( session );
+        verify( logger, times(1) ).warn( contains( "does not match the format" ) );
+    }
+
+    @Test
+    public void malformedTooBig()
+        throws Exception
+    {
+        MavenSession session = mock( MavenSession.class );
+        Logger logger = mock( Logger.class );
+        PluginEnforcingMavenLifecycleParticipant instance = newInstance( logger );
+        final Properties properties = new Properties();
+        properties.setProperty( "force.plugins", "g:a:v:c" );
+        when( session.getUserProperties() ).thenReturn( properties );
+        instance.afterProjectsRead( session );
+        verify( logger, times(1) ).warn( contains( "does not match the format" ) );
+    }
+
+    @Test
+    public void malformedEmpty()
+        throws Exception
+    {
+        MavenSession session = mock( MavenSession.class );
+        Logger logger = mock( Logger.class );
+        PluginEnforcingMavenLifecycleParticipant instance = newInstance( logger );
+        final Properties properties = new Properties();
+        properties.setProperty( "force.plugins", "g::v" );
+        when( session.getUserProperties() ).thenReturn( properties );
+        instance.afterProjectsRead( session );
+        verify( logger, times( 1 ) ).warn( contains( "does not match the format" ) );
+    }
+
+    @Test
+    public void parseSingle()
+        throws Exception
+    {
+        MavenSession session = mock( MavenSession.class );
+        Logger logger = mock( Logger.class );
+        PluginEnforcingMavenLifecycleParticipant instance = newInstance( logger );
+        final Properties properties = new Properties();
+        properties.setProperty( "force.plugins", "org.mytest:myplugin:1.0" );
+        when( session.getUserProperties() ).thenReturn( properties );
+        instance.afterProjectsRead( session );
+        verify( logger, atLeastOnce() ).info( matches( "^(.(?!([fF]orcing)))*$" ) );
+        verify( logger, times( 1 ) ).info( contains( "Forcing org.mytest:myplugin to 1.0" ) );
+    }
+
+    @Test
+    public void parseMultiple()
+        throws Exception
+    {
+        MavenSession session = mock( MavenSession.class );
+        Logger logger = mock( Logger.class );
+        PluginEnforcingMavenLifecycleParticipant instance = newInstance( logger );
+        final Properties properties = new Properties();
+        properties.setProperty( "force.plugins", "org.mytest:myplugin:1.0,org.mytest.some:foobar:3.0" );
+        when( session.getUserProperties() ).thenReturn( properties );
+        instance.afterProjectsRead( session );
+        verify( logger, atLeastOnce() ).info( matches( "^(.(?!([fF]orcing)))*$" ) );
+        verify( logger, times( 1 ) ).info( contains( "Forcing org.mytest:myplugin to 1.0" ) );
+        verify( logger, times( 1 ) ).info( contains( "Forcing org.mytest.some:foobar to 3.0" ) );
+    }
+
+
+}

Propchange: maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-plugin-enforcer/src/test/java/org/apache/maven/util/pluginenforcer/PluginEnforcingMavenLifecycleParticipantTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain