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);
}
}
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;
}
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;
}
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());
}
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;
}
Aggregations