Search in sources :

Example 86 with Xpp3Dom

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

the class XMLReport method createElement.

/**
 * Creates an XML element.
 * @param element the parent element
 * @param name the name of the element to create
 * @return the resulting XML tree.
 */
private Xpp3Dom createElement(Xpp3Dom element, String name) {
    Xpp3Dom component = new Xpp3Dom(name);
    element.addChild(component);
    return component;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 87 with Xpp3Dom

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

the class XMLReport method writeTestProblems.

/**
 * Utility method writing failed and in error test result in the report.
 * @param test the test
 * @param e the thrown error
 * @param name type of failure ("error" or "failure")
 * @param out the output messages printed during the test execution
 * @param err the error messages printed during the test execution
 * @param log the messages logged during the test execution
 */
private void writeTestProblems(Test test, Throwable e, String name, String out, String err, String log) {
    long runTime = m_endTime - m_startTime;
    Xpp3Dom testCase = createTestElement(test, runTime);
    Xpp3Dom element = createElement(testCase, name);
    String stackTrace = getStackTrace(test, e);
    Throwable t = e;
    if (t != null) {
        String message = t.getMessage();
        if (message != null) {
            element.setAttribute("message", message);
            element.setAttribute("type", stackTrace.indexOf(":") > -1 ? stackTrace.substring(0, stackTrace.indexOf(":")) : stackTrace);
        } else {
            element.setAttribute("type", new StringTokenizer(stackTrace).nextToken());
        }
    }
    if (stackTrace != null) {
        element.setValue(stackTrace);
    }
    addOutputStreamElement(out, "system-out", testCase);
    addOutputStreamElement(err, "system-err", testCase);
    if (log != null) {
        addOutputStreamElement(log, "log-service", testCase);
    }
    m_results.add(testCase);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) StringTokenizer(java.util.StringTokenizer)

Example 88 with Xpp3Dom

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

the class XMLReport method showProperties.

/**
 * Adds system properties to the XML report.
 * This method also adds installed bundles.
 * @param testSuite the XML element.
 * @param bc the bundle context
 * @param configuration the configuration of the underlying OSGi platform
 */
private void showProperties(Xpp3Dom testSuite, BundleContext bc, Map configuration) {
    Xpp3Dom properties = createElement(testSuite, "properties");
    Properties systemProperties = System.getProperties();
    if (systemProperties != null) {
        Enumeration propertyKeys = systemProperties.propertyNames();
        while (propertyKeys.hasMoreElements()) {
            String key = (String) propertyKeys.nextElement();
            String value = systemProperties.getProperty(key);
            if (value == null) {
                value = "null";
            }
            Xpp3Dom property = createElement(properties, "property");
            property.setAttribute("name", key);
            property.setAttribute("value", value);
        }
    }
    if (configuration != null) {
        Iterator it = configuration.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            Object obj = (Object) configuration.get(key);
            String value = null;
            if (obj == null) {
                value = "null";
            } else if (obj instanceof String) {
                value = (String) obj;
            } else {
                value = obj.toString();
            }
            Xpp3Dom property = createElement(properties, "property");
            property.setAttribute("name", key);
            property.setAttribute("value", value);
        }
    }
    Xpp3Dom bundle = createElement(properties, "property");
    Bundle[] bundles = bc.getBundles();
    for (int i = 0; i < bundles.length; i++) {
        String sn = bundles[i].getSymbolicName();
        String state = "UNKNOWN";
        switch(bundles[i].getState()) {
            case Bundle.ACTIVE:
                state = "ACTIVE";
                break;
            case Bundle.INSTALLED:
                state = "INSTALLED";
                break;
            case Bundle.RESOLVED:
                state = "RESOLVED";
                break;
            case Bundle.UNINSTALLED:
                state = "UNINSTALLED";
                break;
            default:
                break;
        }
        bundle.setAttribute("name", "bundle-" + sn);
        bundle.setAttribute("value", state);
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Enumeration(java.util.Enumeration) Bundle(org.osgi.framework.Bundle) Iterator(java.util.Iterator) Properties(java.util.Properties)

Example 89 with Xpp3Dom

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

the class XMLReport method createTestElement.

/**
 * Creates a XML test case element.
 * @param test the test
 * @param runTime the elapsed time to execute the test.
 * @return the XML element describing the given test.
 */
private Xpp3Dom createTestElement(Test test, long runTime) {
    Xpp3Dom testCase = new Xpp3Dom("testcase");
    testCase.setAttribute("name", getReportName(test));
    double time = (double) runTime / (double) 1000;
    testCase.setAttribute("time", Double.toString(time));
    testCase.setAttribute("classname", test.getClass().getName());
    return testCase;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 90 with Xpp3Dom

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

the class MeecrowaveRunMojoTest method run.

@Test
public void run() throws Exception {
    final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
    final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
    final File pom = new File(basedir, "pom.xml");
    final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(basedir);
    final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
    configuration.setRepositorySession(repositorySession);
    final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
    final MavenSession session = mojo.newMavenSession(project);
    final int port;
    try (final ServerSocket serverSocket = new ServerSocket(0)) {
        port = serverSocket.getLocalPort();
    }
    final MojoExecution execution = mojo.newMojoExecution("run");
    execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {

        {
            setValue(Integer.toString(port));
        }
    });
    final InputStream in = System.in;
    final CountDownLatch latch = new CountDownLatch(1);
    System.setIn(new InputStream() {

        // just to not return nothing
        private int val = 2;

        @Override
        public int read() throws IOException {
            try {
                latch.await();
            } catch (final InterruptedException e) {
                Thread.interrupted();
                fail(e.getMessage());
            }
            return val--;
        }
    });
    final Thread runner = new Thread() {

        @Override
        public void run() {
            try {
                mojo.executeMojo(session, project, execution);
            } catch (final Exception e) {
                fail(e.getMessage());
            }
        }
    };
    try {
        runner.start();
        for (int i = 0; i < 120; i++) {
            try {
                assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
                assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
                latch.countDown();
                break;
            } catch (final Exception | AssertionError e) {
                Thread.sleep(500);
            }
        }
    } finally {
        runner.join(TimeUnit.MINUTES.toMillis(1));
        System.setIn(in);
        if (runner.isAlive()) {
            runner.interrupt();
            fail("Runner didn't terminate properly");
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) InputStream(java.io.InputStream) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) URL(java.net.URL) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) SimpleLocalRepositoryManagerFactory(org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory) File(java.io.File) Test(org.junit.Test)

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