Skip to content

Commit

Permalink
[MPLUGIN-376] Drop legacy dependencies (#42)
Browse files Browse the repository at this point in the history
Plugin used a lot of legacy code, misused Mojo test case
and used old Junit 3.x TestCase, and missed some
dependencies (junit mostly).

Changes:
* drop use of Junit 3 TestCase, use Junit4 everywhere
* fix misuses of AbstractMojoTestCase when it is NOT mojo being tested
* add missing junit test dep where missing
* drop legacy p-c-d, sisu using exclusions/replacements
* align JavaMojoDescriptorExtractorTest.java for semantic difference: current Shim returns empty list instead of null when no components (for null safety). Assers updated but semantic is same: "there are no components discovered".
  • Loading branch information
cstamas authored Oct 21, 2021
1 parent 6d3d92e commit d57eaff
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 49 deletions.
32 changes: 22 additions & 10 deletions maven-plugin-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>${doxiaVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
Expand All @@ -120,19 +126,24 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<!-- TODO: make this provided once 3.6.2+ maven-plugin-plugin is in use -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<scope>provided</scope>
</dependency>

<!-- shared -->
Expand All @@ -148,19 +159,13 @@
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<version>1.4.2</version>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<exclusions>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- for m2e support: https://www.eclipse.org/m2e/documentation/m2e-making-maven-plugins-compat.html -->
Expand All @@ -169,7 +174,14 @@
<artifactId>plexus-build-api</artifactId>
<version>0.0.7</version>
</dependency>


<!-- tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- needed for it tests -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down
5 changes: 0 additions & 5 deletions maven-plugin-tools-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions maven-plugin-tools-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<version>1.4.2</version>
</dependency>

<!-- test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
*/

import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* @author jdcasey
*/
public class PluginUtilsTest
extends AbstractMojoTestCase
{
@Test
public void testShouldTrimArtifactIdToFindPluginId()
{
assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-artifactId-plugin" ) );
Expand All @@ -38,6 +40,7 @@ public void testShouldTrimArtifactIdToFindPluginId()
assertEquals( "plugin", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-plugin" ) );
}

@Test
public void testShouldFindTwoScriptsWhenNoExcludesAreGiven()
{
String testScript = "test.txt";
Expand All @@ -50,6 +53,7 @@ public void testShouldFindTwoScriptsWhenNoExcludesAreGiven()
assertEquals( 2, files.length );
}

@Test
public void testShouldFindOneScriptsWhenAnExcludeIsGiven()
{
String testScript = "test.txt";
Expand Down
19 changes: 12 additions & 7 deletions maven-plugin-tools-generators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<exclusions>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- other -->
Expand All @@ -93,11 +87,22 @@
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>2.1</version>
<version>3.0.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@
*/

import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.xml.CompactXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import org.junit.Test;

import java.io.StringWriter;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* @author jdcasey
*/
public class GeneratorUtilsTest
extends AbstractMojoTestCase
{
@Test
public void testShouldWriteDependencies()
throws Exception
{
Expand Down Expand Up @@ -62,6 +66,7 @@ public void testShouldWriteDependencies()
assertEquals( pattern, output );
}

@Test
public void testMakeHtmlValid()
{
String javadoc = null;
Expand Down Expand Up @@ -94,6 +99,7 @@ public void testMakeHtmlValid()
assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
}

@Test
public void testDecodeJavadocTags()
{
String javadoc = null;
Expand Down Expand Up @@ -148,6 +154,7 @@ public void testDecodeJavadocTags()
assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
}

@Test
public void testToText()
throws Exception
{
Expand Down Expand Up @@ -179,6 +186,7 @@ public void testToText()
assertEquals( "Generates something for the project.", GeneratorUtils.toText( javadoc ) );
}

@Test
public void testIsMavenReport()
throws Exception
{
Expand All @@ -194,7 +202,7 @@ public void testIsMavenReport()
String impl = "org.apache.maven.tools.plugin.generator.stubs.MavenReportStub";

MavenProjectStub stub = new MavenProjectStub();
stub.setCompileSourceRoots( Collections.singletonList( getBasedir() + "/target/classes" ) );
stub.setCompileSourceRoots( Collections.singletonList( System.getProperty( "basedir" ) + "/target/classes" ) );

assertTrue( GeneratorUtils.isMavenReport( impl, stub ) );

Expand Down
12 changes: 6 additions & 6 deletions maven-plugin-tools-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- misc -->
Expand All @@ -72,6 +66,12 @@
<artifactId>qdox</artifactId>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void testAnnotationInPlugin()
{
List<MojoDescriptor> results = extract( "source3" );

assertNull( results );
assertTrue( results.isEmpty() );
}

/**
Expand Down Expand Up @@ -253,7 +253,7 @@ public void testMethodReferenceInEnumConstructor()
{
List<MojoDescriptor> results = extract( "MPLUGIN-320" );

assertNull( results );
assertTrue( results.isEmpty() );
}

@Test
Expand All @@ -262,7 +262,7 @@ public void testEnumWithRegexPattern()
{
List<MojoDescriptor> results = extract( "MPLUGIN-290" );

assertNull( results );
assertTrue( results.isEmpty() );
}

}
5 changes: 0 additions & 5 deletions maven-script/maven-plugin-tools-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions maven-script/maven-script-ant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-ant-factory</artifactId>
<version>1.0-alpha-2.1</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand Down
6 changes: 6 additions & 0 deletions maven-script/maven-script-beanshell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-bsh-factory</artifactId>
<version>1.0-alpha-7</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>bsh</groupId>
Expand Down
22 changes: 19 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
<properties>
<surefire.version>2.22.2</surefire.version>
<javaVersion>7</javaVersion>
<pluginTestingHarnessVersion>1.3</pluginTestingHarnessVersion>
<mavenVersion>3.2.2</mavenVersion>
<pluginTestingHarnessVersion>3.3.0</pluginTestingHarnessVersion>
<mavenVersion>3.2.5</mavenVersion>
<antVersion>1.7.1</antVersion>
<sisuVersion>0.3.5</sisuVersion>
<mavenInvokerPluginVersion>3.2.2</mavenInvokerPluginVersion>
<maven.site.path>plugin-tools-archives/plugin-tools-LATEST</maven.site.path>
<asmVersion>9.1</asmVersion>
Expand Down Expand Up @@ -171,6 +172,11 @@
</dependency>

<!-- plexus -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>${sisuVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand All @@ -196,6 +202,16 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
<exclusion>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- other -->
Expand Down Expand Up @@ -237,7 +253,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit d57eaff

Please sign in to comment.