Search in sources :

Example 56 with Document

use of org.dom4j.Document in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method execute.

/**
   * Run the mojo.
   */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if ("pom".equals(packaging)) {
        getLog().debug("Skipping execution for packaging \"" + packaging + "\"");
        return;
    }
    // Check directory existence first.
    if (!dir.isDirectory() || !tempDir.isDirectory()) {
        getLog().warn("Location does not exist or is not a directory: " + dir.getAbsolutePath());
        skipTests = true;
    }
    if (skipTests) {
        return;
    }
    validateParameters();
    // Ant project setup.
    final Project antProject = new Project();
    antProject.init();
    antProject.setBaseDir(dir);
    antProject.addBuildListener(new MavenListenerAdapter(getLog()));
    // Generate JUnit4 ANT task model and generate a synthetic ANT file.
    Document doc = DocumentFactory.getInstance().createDocument();
    try {
        populateJUnitElement(createDocumentSkeleton(doc));
        File tempAntFile = createTemporaryAntFile(doc);
        ProjectHelper.configureProject(antProject, tempAntFile);
        try {
            antProject.executeTarget(DEFAULT_TARGET);
        } finally {
            if (!leaveTemporary) {
                tempAntFile.delete();
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("An I/O error occurred: " + e.getMessage(), e);
    } catch (BuildException e) {
        throw new MojoExecutionException(e.getMessage(), e.getCause());
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Project(org.apache.tools.ant.Project) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) Document(org.dom4j.Document) File(java.io.File)

Example 57 with Document

use of org.dom4j.Document in project hudson-2.x by hudson.

the class SuiteResult method parse.

/**
     * Parses the JUnit XML file into {@link SuiteResult}s.
     * This method returns a collection, as a single XML may have multiple <testsuite>
     * elements wrapped into the top-level <testsuites>.
     */
static List<SuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException {
    List<SuiteResult> r = new ArrayList<SuiteResult>();
    // parse into DOM
    SAXReader saxReader = new SAXReader();
    // install EntityResolver for resolving DTDs, which are in files created by TestNG.
    XMLEntityResolver resolver = new XMLEntityResolver();
    saxReader.setEntityResolver(resolver);
    Document result = saxReader.read(xmlReport);
    Element root = result.getRootElement();
    getTestSuites(root, r, xmlReport, keepLongStdio);
    return r;
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Document(org.dom4j.Document)

Example 58 with Document

use of org.dom4j.Document in project hibernate-orm by hibernate.

the class AdditionalJaxbMappingProducerImpl method produceAdditionalMappings.

@Override
public Collection<MappingDocument> produceAdditionalMappings(final MetadataImplementor metadata, IndexView jandexIndex, final MappingBinder mappingBinder, final MetadataBuildingContext buildingContext) {
    final ServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
    final EnversService enversService = serviceRegistry.getService(EnversService.class);
    if (!enversService.isEnabled()) {
        // short-circuit if envers integration has been disabled.
        return Collections.emptyList();
    }
    final ArrayList<MappingDocument> additionalMappingDocuments = new ArrayList<>();
    // atm we do not have distinct origin info for envers
    final Origin origin = new Origin(SourceType.OTHER, "envers");
    //		final DOMWriter writer = new DOMWriter();
    final MappingCollector mappingCollector = new MappingCollector() {

        @Override
        public void addDocument(Document document) throws DocumentException {
            dump(document);
            // while the commented-out code here is more efficient (well, understanding that
            // this whole process is un-efficient)  it leads to un-decipherable messages when
            // we get mapping mapping errors from envers output.
            //				final DOMSource domSource = new DOMSource( writer.write( document ) );
            //				domSource.setSystemId( "envers" );
            //				final Binding jaxbBinding = mappingBinder.bind( domSource, origin );
            // this form at least allows us to get better error messages
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                final Writer w = new BufferedWriter(new OutputStreamWriter(baos, "UTF-8"));
                final XMLWriter xw = new XMLWriter(w, new OutputFormat(" ", true));
                xw.write(document);
                w.flush();
            } catch (IOException e) {
                throw new HibernateException("Unable to bind Envers-generated XML", e);
            }
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            BufferedInputStream bis = new BufferedInputStream(bais);
            final Binding jaxbBinding = mappingBinder.bind(bis, origin);
            final JaxbHbmHibernateMapping jaxbRoot = (JaxbHbmHibernateMapping) jaxbBinding.getRoot();
            additionalMappingDocuments.add(new MappingDocument(jaxbRoot, origin, buildingContext));
        }
    };
    enversService.initialize(metadata, mappingCollector);
    return additionalMappingDocuments;
}
Also used : Origin(org.hibernate.boot.jaxb.Origin) Binding(org.hibernate.boot.jaxb.spi.Binding) HibernateException(org.hibernate.HibernateException) MappingDocument(org.hibernate.boot.model.source.internal.hbm.MappingDocument) ArrayList(java.util.ArrayList) OutputFormat(org.dom4j.io.OutputFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(org.dom4j.Document) MappingDocument(org.hibernate.boot.model.source.internal.hbm.MappingDocument) XMLWriter(org.dom4j.io.XMLWriter) BufferedWriter(java.io.BufferedWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) OutputStreamWriter(java.io.OutputStreamWriter) ServiceRegistry(org.hibernate.service.ServiceRegistry) MappingCollector(org.hibernate.envers.configuration.internal.MappingCollector) XMLWriter(org.dom4j.io.XMLWriter) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) JaxbHbmHibernateMapping(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping)

Example 59 with Document

use of org.dom4j.Document in project hibernate-orm by hibernate.

the class EntitiesConfigurator method configure.

public EntitiesConfigurations configure(MetadataImplementor metadata, ServiceRegistry serviceRegistry, ReflectionManager reflectionManager, MappingCollector mappingCollector, GlobalConfiguration globalConfiguration, AuditEntitiesConfiguration auditEntitiesConfiguration, AuditStrategy auditStrategy, Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
    // Creating a name register to capture all audit entity names created.
    final AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister();
    // Sorting the persistent class topologically - superclass always beforeQuery subclass
    final Iterator<PersistentClass> classes = GraphTopologicalSort.sort(new PersistentClassGraphDefiner(metadata)).iterator();
    final ClassesAuditingData classesAuditingData = new ClassesAuditingData();
    final Map<PersistentClass, EntityXmlMappingData> xmlMappings = new HashMap<>();
    // Reading metadata from annotations
    while (classes.hasNext()) {
        final PersistentClass pc = classes.next();
        // Ensure we're in POJO, not dynamic model, mapping.
        if (pc.getClassName() != null) {
            // Collecting information from annotations on the persistent class pc
            final AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader(globalConfiguration, reflectionManager, pc);
            final ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
            classesAuditingData.addClassAuditingData(pc, auditData);
        }
    }
    // Now that all information is read we can update the calculated fields.
    classesAuditingData.updateCalculatedFields();
    final AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(metadata, serviceRegistry, globalConfiguration, auditEntitiesConfiguration, auditStrategy, revisionInfoRelationMapping, auditEntityNameRegister);
    // First pass
    for (Map.Entry<PersistentClass, ClassAuditingData> pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
        final PersistentClass pc = pcDatasEntry.getKey();
        final ClassAuditingData auditData = pcDatasEntry.getValue();
        final EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
        if (auditData.isAudited()) {
            if (!StringTools.isEmpty(auditData.getAuditTable().value())) {
                auditEntitiesConfiguration.addCustomAuditTableName(pc.getEntityName(), auditData.getAuditTable().value());
            }
            auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, true);
        } else {
            auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, false);
        }
        xmlMappings.put(pc, xmlMappingData);
    }
    // Second pass
    for (Map.Entry<PersistentClass, ClassAuditingData> pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
        final EntityXmlMappingData xmlMappingData = xmlMappings.get(pcDatasEntry.getKey());
        if (pcDatasEntry.getValue().isAudited()) {
            auditMetaGen.generateSecondPass(pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData);
            try {
                mappingCollector.addDocument(xmlMappingData.getMainXmlMapping());
                for (Document additionalMapping : xmlMappingData.getAdditionalXmlMappings()) {
                    mappingCollector.addDocument(additionalMapping);
                }
            } catch (DocumentException e) {
                throw new MappingException(e);
            }
        }
    }
    // Only if there are any versioned classes
    if (auditMetaGen.getEntitiesConfigurations().size() > 0) {
        try {
            if (revisionInfoXmlMapping != null) {
                mappingCollector.addDocument(revisionInfoXmlMapping);
            }
        } catch (DocumentException e) {
            throw new MappingException(e);
        }
    }
    return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations(), auditMetaGen.getNotAuditedEntitiesConfigurations());
}
Also used : AuditMetadataGenerator(org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator) HashMap(java.util.HashMap) EntityXmlMappingData(org.hibernate.envers.configuration.internal.metadata.EntityXmlMappingData) Document(org.dom4j.Document) AuditEntityNameRegister(org.hibernate.envers.configuration.internal.metadata.AuditEntityNameRegister) MappingException(org.hibernate.MappingException) AnnotationsMetadataReader(org.hibernate.envers.configuration.internal.metadata.reader.AnnotationsMetadataReader) ClassAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData) DocumentException(org.dom4j.DocumentException) HashMap(java.util.HashMap) Map(java.util.Map) PersistentClass(org.hibernate.mapping.PersistentClass) EntitiesConfigurations(org.hibernate.envers.internal.entities.EntitiesConfigurations)

Example 60 with Document

use of org.dom4j.Document in project hibernate-orm by hibernate.

the class RevisionInfoConfiguration method generateRevisionInfoRelationMapping.

private Element generateRevisionInfoRelationMapping() {
    final Document document = globalCfg.getEnversService().getXmlHelper().getDocumentFactory().createDocument();
    final Element revRelMapping = document.addElement("key-many-to-one");
    revRelMapping.addAttribute("type", revisionPropType);
    revRelMapping.addAttribute("class", revisionInfoEntityName);
    if (revisionPropSqlType != null) {
        // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
        MetadataTools.addColumn(revRelMapping, "*", null, null, null, revisionPropSqlType, null, null, false);
    }
    return revRelMapping;
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document)

Aggregations

Document (org.dom4j.Document)288 Element (org.dom4j.Element)192 SAXReader (org.dom4j.io.SAXReader)143 Test (org.junit.Test)102 StringReader (java.io.StringReader)88 File (java.io.File)57 ArrayList (java.util.ArrayList)47 List (java.util.List)40 IOException (java.io.IOException)27 DocumentException (org.dom4j.DocumentException)25 XMLWriter (org.dom4j.io.XMLWriter)22 HashMap (java.util.HashMap)19 Map (java.util.Map)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 LinkedList (java.util.LinkedList)16 Attribute (org.dom4j.Attribute)15 Node (org.dom4j.Node)14 FileOutputStream (java.io.FileOutputStream)11 DavException (com.zimbra.cs.dav.DavException)10 OutputFormat (org.dom4j.io.OutputFormat)9