org.codehaus.plexus.util.xml.Xpp3Dom Java Examples

The following examples show how to use org.codehaus.plexus.util.xml.Xpp3Dom. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MojoToReportOptionsConverter.java    From pitest with Apache License 2.0 7 votes vote down vote up
private ReportOptions updateFromSurefire(ReportOptions option) {
  Collection<Plugin> plugins = lookupPlugin("org.apache.maven.plugins:maven-surefire-plugin");
  if (!this.mojo.isParseSurefireConfig()) {
    return option;
  } else if (plugins.isEmpty()) {
    this.log.warn("Could not find surefire configuration in pom");
    return option;
  }

  Plugin surefire = plugins.iterator().next();
  if (surefire != null) {
    return this.surefireConverter.update(option,
        (Xpp3Dom) surefire.getConfiguration());
  } else {
    return option;
  }

}
 
Example #2
Source File: MavenConfigurationExtractor.java    From jkube with Eclipse Public License 2.0 7 votes vote down vote up
private static Map<String, Object> getElement(Xpp3Dom element) {

        final Map<String, Object> conf = new HashMap<>();

        final Xpp3Dom[] currentElements = element.getChildren();

        for (Xpp3Dom currentElement: currentElements) {
            if (isSimpleType(currentElement)) {

                if (isAListOfElements(conf, currentElement)) {
                    addAsList(conf, currentElement);
                } else {
                    conf.put(currentElement.getName(), currentElement.getValue());
                }
            } else {
                conf.put(currentElement.getName(), getElement(currentElement));
            }
        }

        return conf;

    }
 
Example #3
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class RequirePropertyDiverges.
 */
@Test
public void testExecuteInParentWithConfigurationInExecution() throws EnforcerRuleException
{
    RequirePropertyDiverges mockInstance = createMockRule();
    final MavenProject project = createMavenProject( "company", "company-parent-pom" );
    final Build build = new Build();
    build.setPluginManagement( new PluginManagement() );
    final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0" );
    final Xpp3Dom configuration = createPluginConfiguration();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setConfiguration( configuration );
    plugin.addExecution( pluginExecution );
    build.addPlugin( plugin );
    project.getOriginalModel().setBuild( build );
    setUpHelper(project, "parentValue");
    mockInstance.execute( helper );
}
 
Example #4
Source File: AnnotationProcessingTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testLastRound_typeIndex() throws Exception {
  // apparently javac can't resolve "forward" references to types generated during apt last round
  Assume.assumeTrue(CompilerJdt.ID.equals(compilerId));

  Xpp3Dom processors = newProcessors("processor.ProcessorLastRound_typeIndex");
  File basedir = procCompile("compile-proc/multiround-type-index", Proc.proc, processors);
  File target = new File(basedir, "target");
  mojos.assertBuildOutputs(target, //
      "generated-sources/annotations/generated/TypeIndex.java", //
      "generated-sources/annotations/generated/TypeIndex2.java", //
      "classes/generated/TypeIndex.class", //
      "classes/generated/TypeIndex2.class", //
      "classes/typeindex/Annotated.class", //
      "classes/typeindex/Consumer.class" //
  );
}
 
Example #5
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_return_empty_template_dirs() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("template_dirs")
            .addChild("dir", "")
            .parent()
            .addChild("dir", null)
            .build();

    // when
    SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, emptyOptions, emptyAttributes);

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example #6
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_multiple_requires() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("requires")
            .addChild("require", "gem_1", "gem_2", "gem_3")
            .build();

    // when
    SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, emptyOptions, emptyAttributes);

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires())
            .containsExactlyInAnyOrder("gem_1", "gem_2", "gem_3");
}
 
Example #7
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_simple_single_requires() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("requires")
            .addChild("require", "gem")
            .build();

    // when
    SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, emptyOptions, emptyAttributes);

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires())
            .containsExactly("gem");
}
 
Example #8
Source File: DevMojo.java    From ci.maven with Apache License 2.0 6 votes vote down vote up
private boolean restartForLibertyMojoConfigChanged(Xpp3Dom config, Xpp3Dom oldConfig) {
    if (!Objects.equals(config.getChild("bootstrapProperties"),
            oldConfig.getChild("bootstrapProperties"))) {
        return true;
    } else if (!Objects.equals(config.getChild("bootstrapPropertiesFile"),
            oldConfig.getChild("bootstrapPropertiesFile"))) {
        return true;
    } else if (!Objects.equals(config.getChild("jvmOptions"),
            oldConfig.getChild("jvmOptions"))) {
        return true;
    } else if (!Objects.equals(config.getChild("jvmOptionsFile"),
            oldConfig.getChild("jvmOptionsFile"))) {
        return true;
    } else if (!Objects.equals(config.getChild("serverEnv"),
            oldConfig.getChild("serverEnv"))) {
        return true;
    } else if (!Objects.equals(config.getChild("serverEnvFile"),
            oldConfig.getChild("serverEnvFile"))) {
        return true;
    } else if (!Objects.equals(config.getChild("configDirectory"),
            oldConfig.getChild("configDirectory"))) {
        return true;
    }
    return false;
}
 
Example #9
Source File: MavenProjectConfigurator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save the settings for the GWT nature in the application GWT preferences.
 *
 * @param project
 * @param mavenProject
 * @param mavenConfig
 * @throws BackingStoreException
 */
private void persistGwtNatureSettings(IProject project, MavenProject mavenProject, Xpp3Dom mavenConfig)
    throws BackingStoreException {
  IPath warOutDir = getWarOutDir(project, mavenProject);

  WebAppProjectProperties.setWarSrcDir(project, getWarSrcDir(mavenProject, mavenConfig)); // src/main/webapp
  WebAppProjectProperties.setWarSrcDirIsOutput(project, getLaunchFromHere(mavenConfig)); // false

  // TODO the extension should be used, from WarArgProcessor
  WebAppProjectProperties.setLastUsedWarOutLocation(project, warOutDir);

  WebAppProjectProperties.setGwtMavenModuleName(project, getGwtModuleName(mavenProject));
  WebAppProjectProperties.setGwtMavenModuleShortName(project, getGwtModuleShortName(mavenProject));

  String message = "MavenProjectConfiguratior Maven: Success with setting up GWT Nature\n";
  message += "\tartifactId=" + mavenProject.getArtifactId() + "\n";
  message += "\tversion=" + mavenProject.getVersion() + "\n";
  message += "\twarOutDir=" + warOutDir;
  Activator.log(message);
}
 
Example #10
Source File: MavenProjectConfigurator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the GWT Maven plugin 2 <moduleName/>.
 *
 * @param mavenProject
 * @return the moduleName from configuration
 */
private String getGwtModuleName(MavenProject mavenProject) {
  if (!isGwtMavenPlugin2(mavenProject)) {
    return null;
  }

  Plugin gwtPlugin2 = getGwtMavenPlugin2(mavenProject);
  if (gwtPlugin2 == null) {
    return null;
  }

  Xpp3Dom gwtPluginConfig = (Xpp3Dom) gwtPlugin2.getConfiguration();
  if (gwtPluginConfig == null) {
    return null;
  }

  String moduleName = null;
  for (Xpp3Dom child : gwtPluginConfig.getChildren()) {
    if (child != null && GWT_MAVEN_MODULENAME.equals(child.getName())) {
      moduleName = child.getValue().trim();
    }
  }
  return moduleName;
}
 
Example #11
Source File: CompileJdtClasspathVisibilityTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testReference_testCompile_internal() throws Exception {
  File basedir = resources.getBasedir("compile-jdt-classpath-visibility/reference");

  MavenProject project = mojos.readMavenProject(basedir);
  addDependency(project, "dependency", DEPENDENCY);

  MavenSession session = mojos.newMavenSession(project);

  Xpp3Dom[] params = new Xpp3Dom[] {param("compilerId", "jdt"), //
      param("transitiveDependencyReference", "error"), //
      param("privatePackageReference", "error")};

  mojos.executeMojo(session, project, "compile", params);

  // make all main classes internal
  File exportsFile = new File(basedir, "target/classes/" + ExportPackageMojo.PATH_EXPORT_PACKAGE);
  exportsFile.getParentFile().mkdirs();
  new FileOutputStream(exportsFile).close();

  mojos.executeMojo(session, project, "testCompile", params);
}
 
Example #12
Source File: AnnotationProcessingTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
protected void processAnnotations(MavenSession session, MavenProject project, String goal, File processor, Proc proc, Xpp3Dom... parameters) throws Exception {
  MojoExecution execution = mojos.newMojoExecution(goal);

  addDependency(project, "processor", new File(processor, "target/classes"));

  Xpp3Dom configuration = execution.getConfiguration();

  if (proc != null) {
    configuration.addChild(newParameter("proc", proc.name()));
  }
  if (parameters != null) {
    for (Xpp3Dom parameter : parameters) {
      configuration.addChild(parameter);
    }
  }

  mojos.executeMojo(session, project, execution);
}
 
Example #13
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the ancestor project which defines the rule.
 *
 * @param project to inspect
 * @return the defining ancestor project.
 */
final MavenProject findDefiningParent( final MavenProject project )
{
    final Xpp3Dom invokingRule = createInvokingRuleDom();
    MavenProject parent = project;
    while ( parent != null )
    {
        final Model model = parent.getOriginalModel();
        final Build build = model.getBuild();
        if ( build != null )
        {
            final List<Xpp3Dom> rules = getRuleConfigurations( build );
            if ( isDefiningProject( rules, invokingRule ) )
            {
                break;
            }
        }
        parent = parent.getParent();
    }
    return parent;
}
 
Example #14
Source File: AbstractGcloudMojo.java    From gcloud-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @return the java version used the pom (target) and 1.7 if not present.
 */
protected String getJavaVersion() {
  String javaVersion = "1.7";
  Plugin p = maven_project.getPlugin("org.apache.maven.plugins:maven-compiler-plugin");
  if (p != null) {
    Xpp3Dom config = (Xpp3Dom) p.getConfiguration();
    if (config == null) {
      return javaVersion;
    }
    Xpp3Dom domVersion = config.getChild("target");
    if (domVersion != null) {
      javaVersion = domVersion.getValue();
    }
  }
  return javaVersion;
}
 
Example #15
Source File: MavenConfigurationExtractorTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private Plugin createFakePlugin(String config) {
    Plugin plugin = new Plugin();
    plugin.setArtifactId("jkube-maven-plugin");
    plugin.setGroupId("org.eclipse.jkube");
    String content = "<configuration>"
        + config
        + "</configuration>";
    Xpp3Dom dom;
    try {
        dom = Xpp3DomBuilder.build(new StringReader(content));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    plugin.setConfiguration(dom);

    return plugin;
}
 
Example #16
Source File: MavenConfigurationExtractorTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void should_parse_list_of_mixed_elements() {

    // Given
    final Plugin fakePlugin = createFakePlugin("<a>"
        + "<b>"
        + "<c>c1</c><d>d1</d><c>c2</c>"
        + "</b>"
        + "</a>");

    // When
    final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration());

    // Then
    final Map<String, Object> expectedC = new HashMap<>();
    expectedC.put("c", Arrays.asList("c1", "c2"));
    expectedC.put("d", "d1");
    final Map<String, Object> expected = new HashMap<>();
    expected.put("b", expectedC);

    assertTrue(config.containsKey("a"));
    assertEquals(expected, config.get("a"));
}
 
Example #17
Source File: MavenConfigurationExtractorTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void should_parse_list_of_elements() {

    // Given
    final Plugin fakePlugin = createFakePlugin("<a>"
        + "<b>"
        + "<c>c1</c><c>c2</c>"
        + "</b>"
        + "</a>");

    // When
    final Map<String, Object> config = MavenConfigurationExtractor.extract((Xpp3Dom) fakePlugin.getConfiguration());

    // Then
    final Map<String, Object> expectedC = new HashMap<>();
    expectedC.put("c", Arrays.asList("c1", "c2"));
    final Map<String, Object> expected = new HashMap<>();
    expected.put("b", expectedC);

    assertEquals(expected, config.get("a"));

}
 
Example #18
Source File: RequirePropertyDivergesTest.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class RequirePropertyDiverges.
 */
@Test
public void testExecuteInParentWithConfigurationInPluginManagement() throws EnforcerRuleException
{
    RequirePropertyDiverges mockInstance = createMockRule();
    final MavenProject project = createMavenProject( "company", "company-parent-pom" );
    final Build build = new Build();
    // create pluginManagement
    final Plugin pluginInManagement = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0");
    final Xpp3Dom configuration = createPluginConfiguration();
    pluginInManagement.setConfiguration( configuration );
    final PluginManagement pluginManagement = new PluginManagement();
    pluginManagement.addPlugin( pluginInManagement );
    build.setPluginManagement( pluginManagement );
    // create plugins
    final Plugin pluginInPlugins = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0");
    build.addPlugin( pluginInPlugins );
    // add build
    project.getOriginalModel().setBuild( build );
    //project.getOriginalModel().setBuild( build );
    setUpHelper( project, "parentValue" );
    mockInstance.execute( helper );
}
 
Example #19
Source File: CreateMavenDataServicePom.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
/**
 * Avoid clean control-bundle file in target folde, in case of using mvn clean package, TESB-22296
 *
 * @return plugin
 */
private Plugin addSkipMavenCleanPlugin() {
    Plugin plugin = new Plugin();

    plugin.setGroupId("org.apache.maven.plugins");
    plugin.setArtifactId("maven-clean-plugin");
    plugin.setVersion("3.0.0");

    Xpp3Dom configuration = new Xpp3Dom("configuration");
    Xpp3Dom skipClean = new Xpp3Dom("skip");
    skipClean.setValue("true");
    configuration.addChild(skipClean);
    plugin.setConfiguration(configuration);

    return plugin;
}
 
Example #20
Source File: AnnotationProcessingTest.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Ignore("Neither javac nor jdt support secondary types on sourcepath")
public void testSourcepathSecondatytype() throws Exception {
  File processor = compileAnnotationProcessor();
  File basedir = resources.getBasedir("compile-proc/proc-sourcepath-secondarytype");

  File dependencyBasedir = new File(basedir, "dependency");
  File projectBasedir = new File(basedir, "project");

  Xpp3Dom processors = newProcessors("processor.Processor");
  Xpp3Dom sourcepath = newParameter("sourcepath", "reactorDependencies");

  MavenProject dependency = mojos.readMavenProject(dependencyBasedir);
  MavenProject project = mojos.readMavenProject(projectBasedir);

  mojos.newDependency(new File(dependencyBasedir, "target/classes")) //
      .setGroupId(dependency.getGroupId()) //
      .setArtifactId(dependency.getArtifactId()) //
      .setVersion(dependency.getVersion()) //
      .addTo(project);

  MavenSession session = mojos.newMavenSession(project);
  session.setProjects(Arrays.asList(project, dependency));

  processAnnotations(session, project, "compile", processor, Proc.only, processors, sourcepath);
}
 
Example #21
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_return_default_configuration_when_asciidoc_xml_is_null() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.siteNode()
            .build();
    // when
    SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, emptyOptions, emptyAttributes);

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES);
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
    assertThat(configuration.getRequires()).isEmpty();
}
 
Example #22
Source File: MavenUtil.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns a list of {@link Plugin}
 *
 * @param project Maven project
 * @return list of plugins
 */
public static List<Plugin> getPlugins(MavenProject project) {
    List<Plugin> projectPlugins = new ArrayList<>();
    for (org.apache.maven.model.Plugin plugin : project.getBuildPlugins()) {
        Plugin.PluginBuilder jkubeProjectPluginBuilder = Plugin.builder();

        jkubeProjectPluginBuilder.groupId(plugin.getGroupId())
                .artifactId(plugin.getArtifactId())
                .version(plugin.getVersion());

        if (plugin.getExecutions() != null && !plugin.getExecutions().isEmpty()) {
            jkubeProjectPluginBuilder.executions(getPluginExecutionsAsList(plugin));
        }

        jkubeProjectPluginBuilder.configuration(MavenConfigurationExtractor.extract((Xpp3Dom)plugin.getConfiguration()));
        projectPlugins.add(jkubeProjectPluginBuilder.build());
    }
    return projectPlugins;
}
 
Example #23
Source File: ByteBuddyMojo.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a best effort of locating the configured Java target version.
 *
 * @param project The relevant Maven project.
 * @return The Java version string of the configured build target version or {@code null} if no explicit configuration was detected.
 */
private static String findJavaVersionString(MavenProject project) {
    while (project != null) {
        String target = project.getProperties().getProperty("maven.compiler.target");
        if (target != null) {
            return target;
        }
        for (org.apache.maven.model.Plugin plugin : CompoundList.of(project.getBuildPlugins(), project.getPluginManagement().getPlugins())) {
            if ("maven-compiler-plugin".equals(plugin.getArtifactId())) {
                if (plugin.getConfiguration() instanceof Xpp3Dom) {
                    Xpp3Dom node = ((Xpp3Dom) plugin.getConfiguration()).getChild("target");
                    if (node != null) {
                        return node.getValue();
                    }
                }
            }
        }
        project = project.getParent();
    }
    return null;
}
 
Example #24
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void writePluginExecution(PluginExecution pluginExecution, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if ((pluginExecution.getId() != null) && !pluginExecution.getId().equals("default")) {
        writeValue(serializer, "id", pluginExecution.getId(), pluginExecution);
    }
    if (pluginExecution.getPhase() != null) {
        writeValue(serializer, "phase", pluginExecution.getPhase(), pluginExecution);
    }
    if ((pluginExecution.getGoals() != null) && (pluginExecution.getGoals().size() > 0)) {
        serializer.startTag(NAMESPACE, "goals");
        flush(serializer);
        int start2 = b.length();
        int index = 0;
        InputLocation tracker = pluginExecution.getLocation("goals");

        for (Iterator iter = pluginExecution.getGoals().iterator(); iter.hasNext();) {
            String goal = (String) iter.next();
            writeValue(serializer, "goal", goal, tracker, index);
            index = index + 1;
        }
        serializer.endTag(NAMESPACE, "goals").flush();
        logLocation(pluginExecution, "goals", start2, b.length());
    }
    if (pluginExecution.getInherited() != null) {
        writeValue(serializer, "inherited", pluginExecution.getInherited(), pluginExecution);
    }
    if (pluginExecution.getConfiguration() != null) {
        writeXpp3DOM(serializer, (Xpp3Dom)pluginExecution.getConfiguration(), pluginExecution);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(pluginExecution, "", start, b.length());
}
 
Example #25
Source File: MavenNbModuleImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Xpp3Dom getModuleDom() throws UnsupportedEncodingException, IOException, XmlPullParserException {
    //TODO convert to FileOBject and have the IO stream from there..
    File file = getModuleXmlLocation();
    if (!file.exists()) {
        return null;
    }
    FileInputStream is = new FileInputStream(file);
    Reader reader = new InputStreamReader(is, "UTF-8"); //NOI18N
    try {
        return Xpp3DomBuilder.build(reader);
    } finally {
        IOUtil.close(reader);
    }
}
 
Example #26
Source File: SiteConversionConfigurationParserTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_template_dirs_when_defined_as_templateDirs_dir() {
    // given
    final MavenProject project = fakeProject();
    OptionsBuilder emptyOptions = OptionsBuilder.options();
    AttributesBuilder emptyAttributes = AttributesBuilder.attributes();
    Xpp3Dom siteConfig = Xpp3DoomBuilder.asciidocNode()
            .addChild("templateDirs")
            .addChild("dir", "path")
            .parent()
            .addChild("dir", "path2")
            .build();

    // when
    SiteConversionConfiguration configuration = new SiteConversionConfigurationParser(project)
            .processAsciiDocConfig(siteConfig, emptyOptions, emptyAttributes);

    // then
    final Map<String, Object> optionsMap = configuration.getOptions().map();
    assertThat(optionsMap).containsOnlyKeys(ATTRIBUTES, TEMPLATE_DIRS);
    assertThat(optionsMap.get(TEMPLATE_DIRS))
            .isEqualTo(Arrays.asList(
                    new File("path").getAbsolutePath(),
                    new File("path2").getAbsolutePath()
            ));
    assertThat((Map) optionsMap.get(ATTRIBUTES)).isEmpty();
}
 
Example #27
Source File: TestPropertiesMojoTest.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
private MojoExecution newMojoExecution(Xpp3Dom... parameters) throws IOException {
  MojoExecution execution = mojos.newMojoExecution("testProperties", parameters);
  PluginDescriptor pluginDescriptor = execution.getMojoDescriptor().getPluginDescriptor();

  ArtifactHandler handler = new DefaultArtifactHandler("jar");
  DefaultArtifact workspaceResolver = new DefaultArtifact("io.takari.m2e.workspace", "org.eclipse.m2e.workspace.cli", "1", Artifact.SCOPE_COMPILE, ".jar", null, handler);
  workspaceResolver.setFile(new File("target/workspaceResolver.jar").getCanonicalFile());

  List<Artifact> pluginArtifacts = new ArrayList<>(pluginDescriptor.getArtifacts());
  pluginArtifacts.add(workspaceResolver);
  pluginDescriptor.setArtifacts(pluginArtifacts);

  return execution;
}
 
Example #28
Source File: IteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Taken from MojoExecutor of Don Brown. Converts PlexusConfiguration to a Xpp3Dom.
 * 
 * @param config the PlexusConfiguration. Must not be {@code null}.
 * @return the Xpp3Dom representation of the PlexusConfiguration
 */
public Xpp3Dom toXpp3Dom( PlexusConfiguration config )
{
    Xpp3Dom result = new Xpp3Dom( config.getName() );
    result.setValue( config.getValue( null ) );
    for ( String name : config.getAttributeNames() )
    {
        result.setAttribute( name, config.getAttribute( name ) );
    }
    for ( PlexusConfiguration child : config.getChildren() )
    {
        result.addChild( toXpp3Dom( child ) );
    }
    return result;
}
 
Example #29
Source File: MultiStartMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin(THORNTAIL_MAVEN_PLUGIN);

    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);

    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);

    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);

    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(THORNTAIL_PROCESS);

    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(THORNTAIL_PROCESS);

    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put(THORNTAIL_PROCESS, procs);
    }

    procs.addAll(launched);

    mavenSession.setCurrentProject(this.project);
}
 
Example #30
Source File: MultiStartMojo.java    From wildfly-swarm with Apache License 2.0 5 votes vote down vote up
protected Xpp3Dom getProcessConfiguration(XmlPlexusConfiguration process) {
    Xpp3Dom config = new Xpp3Dom("configuration");

    config.addChild(convert(process.getChild("properties")));
    config.addChild(convert(process.getChild("environment")));
    config.addChild(convert(process.getChild("jvmArguments")));

    return config;
}