protected void setUp()

in maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java [128:163]


    protected void setUp() throws Exception {
        assertTrue(
                "Maven 3.2.4 or better is required",
                MAVEN_VERSION == null || new DefaultArtifactVersion("3.2.3").compareTo(MAVEN_VERSION) < 0);

        configurator = getContainer().lookup(ComponentConfigurator.class, "basic");
        Context context = container.getContext();
        Map<Object, Object> map = context.getContextData();

        try (InputStream is = getClass().getResourceAsStream("/" + getPluginDescriptorLocation());
                Reader reader = new BufferedReader(new XmlStreamReader(is));
                InterpolationFilterReader interpolationReader = new InterpolationFilterReader(reader, map, "${", "}")) {

            PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationReader);

            Artifact artifact = lookup(RepositorySystem.class)
                    .createArtifact(
                            pluginDescriptor.getGroupId(),
                            pluginDescriptor.getArtifactId(),
                            pluginDescriptor.getVersion(),
                            ".jar");

            artifact.setFile(getPluginArtifactFile());
            pluginDescriptor.setPluginArtifact(artifact);
            pluginDescriptor.setArtifacts(Arrays.asList(artifact));

            for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) {
                getContainer().addComponentDescriptor(desc);
            }

            mojoDescriptors = new HashMap<>();
            for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) {
                mojoDescriptors.put(mojoDescriptor.getGoal(), mojoDescriptor);
            }
        }
    }