You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by ahardy42 <ad...@cyberspaceroad.com> on 2017/08/01 14:28:31 UTC

Re: maven-plugin-testing-harness

On 26/07/17 11:49, ahardy42 wrote:
> Is there life is in this testing harness still?
>
> I'm looking at
> https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/

Hi All,
while I've made a lot of progress with my plugin testing with the
maven-plugin-testing-harness, I'm stumped now because the setup and startup
I've put in place isn't causing maven to set up the test project's classpath
properly, so my resources from the test project (in the actual project's
src/test/resources/my-test-project/src/main/resources dir) are missing.

Does that sound fixable?

Here's what I'm doing in my test:

        MojoRule mojoRule = new MojoRule(this);
        ClassLoader classLoader = getClass().getClassLoader();
        URL url = classLoader.getResource(TEST_POM);
        if (url == null) {
            throw new MojoExecutionException(String.format(
                    "Cannot locate %s", TEST_POM));
        }
        File pom = new File(url.getFile());
        MavenSettingsBuilder mavenSettingsBuilder = (MavenSettingsBuilder)
                getContainer().lookup(MavenSettingsBuilder.ROLE);
        Settings settings = mavenSettingsBuilder.buildSettings();
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        request.setPom(pom);
        request.setLocalRepositoryPath(settings.getLocalRepository());
        MavenExecutionRequestPopulator populator =
                getContainer().lookup(MavenExecutionRequestPopulator.class);
        populator.populateDefaults(request);
        DefaultMaven maven = (DefaultMaven)
getContainer().lookup(Maven.class);
        DefaultRepositorySystemSession repoSession =
                (DefaultRepositorySystemSession)
                    maven.newRepositorySession(request);
        LocalRepository localRepository = new LocalRepository(
                request.getLocalRepository().getBasedir());
        SimpleLocalRepositoryManagerFactory factory =
                new SimpleLocalRepositoryManagerFactory();
        LocalRepositoryManager localRepositoryManager =
                factory.newInstance(repoSession, localRepository);
        repoSession.setLocalRepositoryManager(localRepositoryManager);
        ProjectBuildingRequest buildingRequest =
                request.getProjectBuildingRequest()
                        .setRepositorySession(repoSession)
                        .setResolveDependencies(true);
        ProjectBuilder projectBuilder =
mojoRule.lookup(ProjectBuilder.class);
        MavenProject project =
                projectBuilder.build(pom, buildingRequest).getProject();
        MavenSession session = mojoRule.newMavenSession(project);
        session.setCurrentProject(project);
        session.setProjects(Collections.singletonList(project));
        request.setSystemProperties(System.getProperties());
        testMojo = (GenerateConfig) lookupConfiguredMojo(session,
                mojoRule.newMojoExecution("configure"));






--
View this message in context: http://maven.40175.n5.nabble.com/maven-plugin-testing-harness-tp5911556p5911817.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-plugin-testing-harness

Posted by ahardy42 <ad...@cyberspaceroad.com>.
maven-invoker-plugin looks very useful, but it just adds to the frustration
that the maven website guided me down this path with
maven-plugin-testing-harness without a single mention of
maven-invoker-plugin.

you might want to put a link in there in the "my first mojo resources"
section.

I'll try it out when we upgrade maven and my tests break. 





--
View this message in context: http://maven.40175.n5.nabble.com/maven-plugin-testing-harness-tp5911556p5913035.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-plugin-testing-harness

Posted by Olivier Lamy <ol...@apache.org>.
Hi
IMHO using the maven invoker plugin is a better way as you can easily test
your plugin with different core versions.
but it's only my POV :-)

On 23 August 2017 at 18:03, ahardy42 <ad...@cyberspaceroad.com> wrote:

> After a concentrated stint of experimentation, I have setup my tests using
> the maven-plugin-testing-harness so that the tests run with a live remote
> repository and have all the resources provided in the target/test-classes
> directory.
>
> The solution is here:
> https://stackoverflow.com/questions/45241317/hard-time-
> mojo-testing-with-maven-plugin-testing-harness/45833419#answer-45833419
>
> Sorry if the question title betrays my frustration. The limited feedback I
> got here on this user list was also surprising. Obviously with no feedback
> to speak of, I have no idea why no-one from the maven community wanted to
> communicate on this subject. I would of course be grateful now to get some
> feedback of any kind. I'm not asking for anyone to spend more than a minute
> to write a reply - I have essentially finished my work with the testing
> harness.
>
> Why was it so difficult? Are the inner workings all in the process of
> re-development for maven 4?
>
>
>
> --
> View this message in context: http://maven.40175.n5.nabble.
> com/maven-plugin-testing-harness-tp5911556p5912964.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Olivier Lamy
http://twitter.com/olamy | http://linkedin.com/in/olamy

Re: maven-plugin-testing-harness

Posted by ahardy42 <ad...@cyberspaceroad.com>.
After a concentrated stint of experimentation, I have setup my tests using
the maven-plugin-testing-harness so that the tests run with a live remote
repository and have all the resources provided in the target/test-classes
directory.

The solution is here:
https://stackoverflow.com/questions/45241317/hard-time-mojo-testing-with-maven-plugin-testing-harness/45833419#answer-45833419

Sorry if the question title betrays my frustration. The limited feedback I
got here on this user list was also surprising. Obviously with no feedback
to speak of, I have no idea why no-one from the maven community wanted to
communicate on this subject. I would of course be grateful now to get some
feedback of any kind. I'm not asking for anyone to spend more than a minute
to write a reply - I have essentially finished my work with the testing
harness. 

Why was it so difficult? Are the inner workings all in the process of
re-development for maven 4?



--
View this message in context: http://maven.40175.n5.nabble.com/maven-plugin-testing-harness-tp5911556p5912964.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org