Java Code Examples for org.codehaus.plexus.util.xml.Xpp3DomBuilder#build()

The following examples show how to use org.codehaus.plexus.util.xml.Xpp3DomBuilder#build() . 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: 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 2
Source File: BasePitMojoTest.java    From pitest with Apache License 2.0 6 votes vote down vote up
protected void configurePitMojo(final AbstractPitMojo pitMojo, final String config)
    throws Exception {
  final Xpp3Dom xpp3dom = Xpp3DomBuilder.build(new StringReader(config));
  final PlexusConfiguration pluginConfiguration = extractPluginConfiguration(
      "pitest-maven", xpp3dom);

  // default the report dir to something
  setVariableValueToObject(pitMojo, "reportsDirectory", new File("."));

  configureMojo(pitMojo, pluginConfiguration);

  final Map<String, Artifact> pluginArtifacts = new HashMap<>();
  setVariableValueToObject(pitMojo, "pluginArtifactMap", pluginArtifacts);

  setVariableValueToObject(pitMojo, "project", this.project);

  if (pitMojo.getAdditionalClasspathElements() == null) {
    ArrayList<String> elements = new ArrayList<>();
    setVariableValueToObject(pitMojo, "additionalClasspathElements", elements);
  }

}
 
Example 3
Source File: SchemaGeneratorMojoTest.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the schema-generator plugin as define the the given pom file
 *
 * @param pomFile The pom file
 * @throws Exception In case of problems
 */
private void executePom(File pomFile) throws Exception {
    // Get the maven pom file content
    Xpp3Dom pomDom = Xpp3DomBuilder.build(new FileReader(pomFile));
    PlexusConfiguration configuration = rule.extractPluginConfiguration("jsonschema-maven-plugin", pomDom);

    // Configure the Mojo
    SchemaGeneratorMojo myMojo = (SchemaGeneratorMojo) rule.lookupConfiguredMojo(new MavenProject(), "generate");
    myMojo = (SchemaGeneratorMojo) rule.configureMojo(myMojo, configuration);

    // And execute
    myMojo.execute();
}
 
Example 4
Source File: MojoConfigurationProcessor.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
Xpp3Dom convert(PlexusConfiguration c) throws ComponentConfigurationException {
  try {
    return Xpp3DomBuilder.build(new StringReader(c.toString()));
  } catch (Exception e) {
    throw new ComponentConfigurationException("Failure converting PlexusConfiguration to Xpp3Dom.", e);
  }
}
 
Example 5
Source File: DistributionEnforcingManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private Xpp3Dom getConfigXml( final Node node )
    throws ManipulationException
{
    final String config = galleyWrapper.toXML( node.getOwnerDocument(), false )
                                       .trim();

    try
    {
        return Xpp3DomBuilder.build( new StringReader( config ) );
    }
    catch ( final XmlPullParserException | IOException e )
    {
        throw new ManipulationException( "Failed to re-parse plugin configuration into Xpp3Dom: {}. Config was: {}", e.getMessage(), config, e );
    }
}
 
Example 6
Source File: RelocationManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private Xpp3Dom getConfigXml( final Node node ) throws ManipulationException
{
    final String config = galleyWrapper.toXML( node.getOwnerDocument(), false ).trim();

    try
    {
        return Xpp3DomBuilder.build( new StringReader( config ) );
    }
    catch ( final XmlPullParserException | IOException e )
    {
        throw new ManipulationException( "Failed to re-parse plugin configuration into Xpp3Dom: {}. Config was: {}", e.getMessage(), config, e );
    }
}
 
Example 7
Source File: Analyzer.java    From revapi with Apache License 2.0 5 votes vote down vote up
private void mergeXmlConfigFile(AnalysisContext.Builder ctxBld, ConfigurationFile configFile, Reader rdr)
        throws IOException, XmlPullParserException {
    XmlToJson<PlexusConfiguration> conv = new XmlToJson<>(revapi, PlexusConfiguration::getName,
            PlexusConfiguration::getValue, PlexusConfiguration::getAttribute, x -> Arrays.asList(x.getChildren()));

    PlexusConfiguration xml = new XmlPlexusConfiguration(Xpp3DomBuilder.build(rdr));

    String[] roots = configFile.getRoots();

    if (roots == null) {
        ctxBld.mergeConfiguration(conv.convert(xml));
    } else {
        roots:
        for (String r : roots) {
            PlexusConfiguration root = xml;
            boolean first = true;
            String[] rootPath = r.split("/");
            for (String name : rootPath) {
                if (first) {
                    first = false;
                    if (!name.equals(root.getName())) {
                        continue roots;
                    }
                } else {
                    root = root.getChild(name);
                    if (root == null) {
                        continue roots;
                    }
                }
            }

            ctxBld.mergeConfiguration(conv.convert(root));
        }
    }
}
 
Example 8
Source File: MavenHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Parse the given string for extracting an XML tree.
 *
 * @param content the text to parse.
 * @param logger the logger to use for printing out the parsing errors. May be {@code null}.
 * @return the XML tree, or {@code null} if empty.
 * @since 0.8
 */
@SuppressWarnings("static-method")
public Xpp3Dom toXpp3Dom(String content, Log logger) {
	if (content != null && !content.isEmpty()) {
		try (StringReader sr = new StringReader(content)) {
			return Xpp3DomBuilder.build(sr);
		} catch (Exception exception) {
			if (logger != null) {
				logger.debug(exception);
			}
		}
	}
	return null;
}
 
Example 9
Source File: MavenModels.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses input into {@link Xpp3Dom}, returns {@code null} if input not parsable. Passed in {@link InputStream} is
 * closed always on return.
 */
public static Xpp3Dom parseDom(final InputStream is) throws IOException {
  try (InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
    return Xpp3DomBuilder.build(reader);
  }
  catch (XmlPullParserException e) {
    log.debug("Could not parse XML into Xpp3Dom", e);
    throw new IOException("Could not parse XML into Xpp3Dom", e);
  }
}
 
Example 10
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 11
Source File: MojoExecutionServiceTest.java    From docker-maven-plugin with Apache License 2.0 4 votes vote down vote up
private MojoDescriptor createPluginDescriptor() throws XmlPullParserException, IOException {
    MojoDescriptor descriptor = new MojoDescriptor();
    PlexusConfiguration config = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new StringReader("<config name='test'><test>1</test></config>")));
    descriptor.setMojoConfiguration(config);
    return descriptor;
}
 
Example 12
Source File: SurefireConfigConverterTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
private Xpp3Dom makeConfig(String s) throws Exception {
  String xml = "<configuration>" + s + "</configuration>";
  InputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
  return Xpp3DomBuilder.build(stream, "UTF-8");
}
 
Example 13
Source File: GenerateMojo.java    From karaf-boot with Apache License 2.0 4 votes vote down vote up
public void execute() throws MojoExecutionException {
    try {
        //
        // Felix Bundle plugin
        //

        Map<String, String> instructions = new LinkedHashMap<>();
        // Starters supplied instructions
        File bndInst = new File(mavenProject.getBasedir(), "target/classes/META-INF/org.apache.karaf.boot.bnd");
        if (bndInst.isFile()) {
            complete(instructions, bndInst);
            bndInst.delete();
        }
        // Verify and use defaults
        if (instructions.containsKey("Import-Package")) {
            instructions.put("Import-Package", instructions.get("Import-Package") + ",*");
        }
        // Build config
        StringBuilder config = new StringBuilder();
        config.append("<configuration>" +
                "<finalName>${project.build.finalName}</finalName>" +
                "<outputDirectory>${project.build.outputDirectory}</outputDirectory>" +
                "<m_mavenSession>${session}</m_mavenSession>" +
                "<project>${project}</project>" +
                "<buildDirectory>${project.build.directory}</buildDirectory>" +
                "<supportedProjectTypes>" +
                "<supportedProjectType>jar</supportedProjectType>" +
                "<supportedProjectType>bundle</supportedProjectType>" +
                "<supportedProjectType>war</supportedProjectType>" +
                "</supportedProjectTypes>" +
                "<instructions>" +
                "<_include>-bnd.bnd</_include>"); // include user bnd file if present
        for (Map.Entry<String, String> entry : instructions.entrySet()) {
            config.append("<").append(entry.getKey()).append(">")
                    .append(entry.getValue())
                    .append("</").append(entry.getKey()).append(">");
        }
        config.append("</instructions>" +
                "</configuration>");
        Xpp3Dom configuration = Xpp3DomBuilder.build(new StringReader(config.toString()));
        // Invoke plugin
        getLog().info("Invoking maven-bundle-plugin");
        Plugin felixBundlePlugin = new Plugin();
        felixBundlePlugin.setGroupId("org.apache.felix");
        felixBundlePlugin.setArtifactId("maven-bundle-plugin");
        felixBundlePlugin.setVersion("3.0.0");
        felixBundlePlugin.setInherited(true);
        felixBundlePlugin.setExtensions(true);
        PluginDescriptor felixBundlePluginDescriptor = pluginManager.loadPlugin(felixBundlePlugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession());
        MojoDescriptor felixBundleMojoDescriptor = felixBundlePluginDescriptor.getMojo("bundle");
        MojoExecution execution = new MojoExecution(felixBundleMojoDescriptor, configuration);
        pluginManager.executeMojo(mavenSession, execution);

    } catch (Exception e) {
        throw new MojoExecutionException("karaf-boot-maven-plugin failed", e);
    }
}
 
Example 14
Source File: DistributionEnforcingManipulatorTest.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
private Object simpleSkipConfig( final boolean enabled )
    throws Exception
{
    return Xpp3DomBuilder.build( new StringReader( "<configuration><skip>" + enabled + "</skip></configuration>" ) );
}
 
Example 15
Source File: ClasspathWorkspaceReader.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
private Artifact createFoundArtifact(final File pomFile)
{
   try
   {
      if (log.isLoggable(Level.FINE))
      {
         log.fine("Processing " + pomFile.getAbsolutePath() + " for classpath artifact resolution");
      }
      Xpp3Dom dom = null;
      try (FileReader reader = new FileReader(pomFile))
      {
         dom = Xpp3DomBuilder.build(reader);
      }
      Xpp3Dom groupIdNode = dom.getChild("groupId");
      String groupId = (groupIdNode == null) ? null : groupIdNode.getValue();
      String artifactId = dom.getChild("artifactId").getValue();
      Xpp3Dom packaging = dom.getChild("packaging");
      String type = (packaging == null) ? "jar" : packaging.getValue();
      Xpp3Dom versionNode = dom.getChild("version");
      String version = (versionNode == null) ? null : versionNode.getValue();

      if (groupId == null || groupId.isEmpty())
      {
         groupId = dom.getChild("parent").getChild("groupId").getValue();
      }
      if (type == null || type.isEmpty())
      {
         type = "jar";
      }
      if (version == null || version.isEmpty())
      {
         version = dom.getChild("parent").getChild("version").getValue();
      }

      final Artifact foundArtifact = new DefaultArtifact(groupId, artifactId, type, version);
      foundArtifact.setFile(pomFile);
      return foundArtifact;
   }
   catch (final Exception e)
   {
      throw new RuntimeException("Could not parse pom.xml: " + pomFile, e);
   }
}
 
Example 16
Source File: ClasspathWorkspaceReader.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
private List<File> createFoundModules(final File pomFile)
{
   try
   {
      List<File> result = new ArrayList<>();
      if (log.isLoggable(Level.FINE))
      {
         log.fine("Processing " + pomFile.getAbsolutePath() + " for classpath module resolution");
      }
      Xpp3Dom dom = null;
      try (FileReader reader = new FileReader(pomFile))
      {
         dom = Xpp3DomBuilder.build(reader);
      }
      Xpp3Dom modules = dom.getChild("modules");
      if (modules != null)
      {
         for (Xpp3Dom module : modules.getChildren())
         {
            result.add(new File(pomFile.getParent(), module.getValue()));
         }
      }

      if (result.isEmpty())
      {
         Xpp3Dom parent = dom.getChild("parent");
         if (parent != null)
         {
            Xpp3Dom relativePathNode = parent.getChild("relativePath");
            String relativePath = (relativePathNode == null) ? "../pom.xml" : relativePathNode.getValue();
            if (relativePath != null)
            {
                File parentPom = pomFile.getParentFile().toPath().resolve(relativePath).toFile();
                if (parentPom.isFile())
                    result = createFoundModules(parentPom);
            }
         }
      }

      return result;
   }
   catch (final Exception e)
   {
      throw new RuntimeException("Could not parse pom.xml: " + pomFile, e);
   }
}
 
Example 17
Source File: XmlUtilTest.java    From revapi with Apache License 2.0 3 votes vote down vote up
@Test
public void testPrettyPrintingXml() throws Exception {
    String text = "<a><b><c>asdf</c><d/></b></a>";

    XmlPlexusConfiguration xml = new XmlPlexusConfiguration(Xpp3DomBuilder.build(new StringReader(text)));

    StringWriter wrt = new StringWriter();

    XmlUtil.toIndentedString(xml, 2, 0, wrt);

    String pretty = wrt.toString();

    assertEquals("<a>\n  <b>\n    <c>asdf</c>\n    <d/>\n  </b>\n</a>", pretty);
}