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-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to