Search in sources :

Example 1 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project intellij-community by JetBrains.

the class Maven2ModelConverter method xppToElement.

private static Element xppToElement(Xpp3Dom xpp) throws RemoteException {
    Element result;
    try {
        result = new Element(xpp.getName());
    } catch (IllegalNameException e) {
        Maven2ServerGlobals.getLogger().info(e);
        return null;
    }
    Xpp3Dom[] children = xpp.getChildren();
    if (children == null || children.length == 0) {
        result.setText(xpp.getValue());
    } else {
        for (Xpp3Dom each : children) {
            Element child = xppToElement(each);
            if (child != null)
                result.addContent(child);
        }
    }
    return result;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Element(org.jdom.Element) IllegalNameException(org.jdom.IllegalNameException)

Example 2 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project asterixdb by apache.

the class SupplementalModelHelper method loadSupplements.

static Map<String, Model> loadSupplements(Log log, String[] models) throws MojoExecutionException {
    if (models == null) {
        log.debug("Supplemental data models won't be loaded.  " + "No models specified.");
        return Collections.emptyMap();
    }
    List<Supplement> supplements = new ArrayList<>();
    for (String set : models) {
        log.debug("Preparing ruleset: " + set);
        try {
            File f = new File(set);
            if (!f.exists()) {
                throw new MojoExecutionException("Cold not resolve " + set);
            }
            if (!f.canRead()) {
                throw new MojoExecutionException("Supplemental data models won't be loaded. " + "File " + f.getAbsolutePath() + " cannot be read, check permissions on the file.");
            }
            log.debug("Loading supplemental models from " + f.getAbsolutePath());
            SupplementalDataModelXpp3Reader reader = new SupplementalDataModelXpp3Reader();
            try (FileInputStream fis = new FileInputStream(f);
                Reader fileReader = new InputStreamReader(fis)) {
                SupplementalDataModel supplementalModel = reader.read(fileReader);
                supplements.addAll(supplementalModel.getSupplement());
            }
        } catch (Exception e) {
            String msg = "Error loading supplemental data models: " + e.getMessage();
            log.error(msg, e);
            throw new MojoExecutionException(msg, e);
        }
    }
    log.debug("Loading supplements complete.");
    Map<String, Model> supplementMap = new HashMap<>();
    for (Supplement sd : supplements) {
        Xpp3Dom dom = (Xpp3Dom) sd.getProject();
        Model m = getSupplement(log, dom);
        supplementMap.put(generateSupplementMapKey(m.getGroupId(), m.getArtifactId()), m);
    }
    return supplementMap;
}
Also used : SupplementalDataModelXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SupplementalDataModelXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileInputStream(java.io.FileInputStream) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Supplement(org.apache.maven.plugin.resources.remote.Supplement) SupplementalDataModel(org.apache.maven.plugin.resources.remote.SupplementalDataModel) Model(org.apache.maven.model.Model) SupplementalDataModel(org.apache.maven.plugin.resources.remote.SupplementalDataModel) File(java.io.File)

Example 3 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.

the class XMLReport method generateReport.

/**
 * Generates the XML reports.
 * @param test the test
 * @param tr the test result
 * @param reportsDirectory the directory in which reports are created.
 * @param bc the bundle context (to get installed bundles)
 * @param configuration the Felix configuration
 * @throws Exception when the XML report cannot be generated correctly
 */
public void generateReport(Test test, TestResult tr, File reportsDirectory, BundleContext bc, Map configuration) throws Exception {
    long runTime = this.m_endTime - this.m_startTime;
    Xpp3Dom testSuite = createTestSuiteElement(test, runTime);
    showProperties(testSuite, bc, configuration);
    testSuite.setAttribute("tests", String.valueOf(tr.runCount()));
    testSuite.setAttribute("errors", String.valueOf(tr.errorCount()));
    testSuite.setAttribute("failures", String.valueOf(tr.failureCount()));
    for (Iterator i = m_results.iterator(); i.hasNext(); ) {
        Xpp3Dom testcase = (Xpp3Dom) i.next();
        testSuite.addChild(testcase);
    }
    File reportFile = new File(reportsDirectory, "TEST-" + getReportName(test).replace(' ', '_') + ".xml");
    File reportDir = reportFile.getParentFile();
    reportDir.mkdirs();
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(reportFile), "UTF-8")));
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + NL);
        Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), testSuite);
    } catch (UnsupportedEncodingException e) {
        throw new Exception("Unable to use UTF-8 encoding", e);
    } catch (FileNotFoundException e) {
        throw new Exception("Unable to create file: " + e.getMessage(), e);
    } finally {
        IOUtil.close(writer);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) PrettyPrintXMLWriter(org.codehaus.plexus.util.xml.PrettyPrintXMLWriter) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 4 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.

the class XMLReport method testSucceeded.

/**
 * A test ends successfully.
 * @param test the test executed successfully.
 */
public void testSucceeded(Test test) {
    super.testSucceeded();
    long runTime = this.m_endTime - this.m_startTime;
    Xpp3Dom testCase = createTestElement(test, runTime);
    m_results.add(testCase);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 5 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.

the class SCRDescriptorMojo method getBundlePluginConfiguration.

private String getBundlePluginConfiguration(final String key) {
    String value = null;
    Plugin bundlePlugin = this.getBundlePlugin();
    if (bundlePlugin != null) {
        final Xpp3Dom config = (Xpp3Dom) bundlePlugin.getConfiguration();
        if (config != null) {
            final Xpp3Dom instructionsConfig = config.getChild(BUNDLE_PLUGIN_INSTRUCTIONS);
            if (instructionsConfig != null) {
                final Xpp3Dom keyConfig = instructionsConfig.getChild(key);
                if (keyConfig != null) {
                    return keyConfig.getValue();
                }
            }
        }
    }
    return value;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Plugin(org.apache.maven.model.Plugin)

Aggregations

Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)156 Plugin (org.apache.maven.model.Plugin)39 File (java.io.File)26 ArrayList (java.util.ArrayList)18 PluginExecution (org.apache.maven.model.PluginExecution)18 IOException (java.io.IOException)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 MavenSession (org.apache.maven.execution.MavenSession)10 MavenProject (org.apache.maven.project.MavenProject)10 Model (org.apache.maven.model.Model)9 Reader (java.io.Reader)8 Build (org.apache.maven.model.Build)8 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)8 BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)8 MojoExecution (org.apache.maven.plugin.MojoExecution)7 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)7 Map (java.util.Map)6 Dependency (org.apache.maven.model.Dependency)6 StringReader (java.io.StringReader)5