Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: making createMojo return Mojo objects (was previously restricted to SetMojo) #658

Merged
merged 1 commit into from
Aug 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.codehaus.mojo.versions.SetMojo;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

Expand Down Expand Up @@ -58,11 +58,11 @@ public abstract class BaseMojoTestCase extends AbstractMojoTestCase
* @return a Mojo instance
* @throws Exception thrown if mojo lookup fails
*/
protected SetMojo createMojo( String goal, String pomFilePath ) throws Exception
protected <T extends Mojo> T createMojo( String goal, String pomFilePath ) throws Exception
{
File pomFile = new File( pomFilePath );
SetMojo mojo = (SetMojo) lookupMojo( goal, pomFile );
mojo.setProject( new TestProjectStub( pomFile ) );
T mojo = (T) lookupMojo( goal, pomFile );
setVariableValueToObject( mojo, "project", new TestProjectStub( pomFile ) );
return mojo;
}

Expand Down