Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.pdark</groupId>
<artifactId>decentxml</artifactId>
<version>1.4</version>
<groupId>eu.maveniverse.maven.domtrip</groupId>
<artifactId>domtrip-maven</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.bcel</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import java.util.Set;
import java.util.stream.Stream;

import de.pdark.decentxml.Document;
import de.pdark.decentxml.Element;
import de.pdark.decentxml.XMLIOSource;
import de.pdark.decentxml.XMLParser;
import de.pdark.decentxml.XMLWriter;
import eu.maveniverse.domtrip.Document;
import eu.maveniverse.domtrip.Element;

import eu.maveniverse.domtrip.Serializer;

/**
* This allows to enhance the ECJ logfile with additional warnings/problem if needed
Expand All @@ -56,8 +55,8 @@ public Stream<Source> sources() {
Document document = documentEntry.getValue();
Element statsElement = getStatsElement(document);
File file = documentEntry.getKey();
return document.getRootElement().getChildren("sources").stream()
.flatMap(sources -> sources.getChildren("source").stream())
return document.root().children("sources")
.flatMap(sources -> sources.children("source"))
.map(source -> new Source(source, statsElement, () -> needsUpdate.add(file)));
});
}
Expand All @@ -73,8 +72,8 @@ public static EcJLogFileEnhancer create(File logDirectory) throws IOException {
}

private static Element getStatsElement(Document document) {
for (Element stats : document.getRootElement().getChildren("stats")) {
for (Element problem_summary : stats.getChildren("problem_summary")) {
for (Element stats : document.root().children("stats")) {
for (Element problem_summary : stats.children("problem_summary").toList()) {
return problem_summary;
}
}
Expand All @@ -83,8 +82,8 @@ private static Element getStatsElement(Document document) {

private static void incrementAttribute(Element element, String attribute, int increment) {
if (increment > 0) {
int current = Integer.parseInt(element.getAttributeValue(attribute));
element.setAttribute(attribute, Integer.toString(current + increment));
int current = Integer.parseInt(element.attribute(attribute));
element.attribute(attribute, Integer.toString(current + increment));
}
}

Expand All @@ -103,8 +102,8 @@ private static Map<File, Document> readDocuments(File logDirectory) throws IOExc
XMLParser parser = new XMLParser();
Map<File, Document> documents = new HashMap<>();
for (File child : logDirectory.listFiles()) {
if (child.getName().toLowerCase().endsWith(".xml")) {
documents.put(child, parser.parse(new XMLIOSource(child)));
if (child.name().toLowerCase().endsWith(".xml")) {
documents.put(child, Document.of(child));
}
}
return documents;
Expand All @@ -113,11 +112,11 @@ private static Map<File, Document> readDocuments(File logDirectory) throws IOExc
private static Element getProblemsElement(Element source) {
Element element = source.getChild(ELEMENT_PROBLEMS);
if (element == null) {
element = new Element(ELEMENT_PROBLEMS);
element.setAttribute(ATTRIBUTES_ERRORS, "0");
element.setAttribute(ATTRIBUTES_INFOS, "0");
element.setAttribute(ATTRIBUTES_PROBLEMS, "0");
element.setAttribute(ATTRIBUTES_WARNINGS, "0");
element = Element.of(ELEMENT_PROBLEMS);
element.attribute(ATTRIBUTES_ERRORS, "0");
element.attribute(ATTRIBUTES_INFOS, "0");
element.attribute(ATTRIBUTES_PROBLEMS, "0");
element.attribute(ATTRIBUTES_WARNINGS, "0");
source.addNode(0, element);
}
return element;
Expand All @@ -136,30 +135,30 @@ public static class Source {
}

public String getPath() {
return source.getAttributeValue("path");
return source.attribute("path");
}

public String getOutputDirectory() {
return source.getAttributeValue("output");
return source.attribute("output");
}

public String getPackage() {
return source.getAttributeValue("package");
return source.attribute("package");
}

public void addProblem(String severity, int lineNumber, int charStart, int charEnd, int categoryId,
int problemId, String message) {
Element problemsElement = getProblemsElement(source);
Element element = new Element("problem");
element.setAttribute("line", Integer.toString(lineNumber));
element.setAttribute("severity", severity);
element.setAttribute("id", Integer.toString(problemId));
element.setAttribute("charStart", Integer.toString(charStart));
element.setAttribute("charEnd", Integer.toString(charEnd));
element.setAttribute("categoryID", Integer.toString(categoryId));
element.setAttribute("problemID", Integer.toString(problemId));
Element messageElement = new Element("message");
messageElement.setAttribute("value", message);
Element element = Element.of("problem");
element.attribute("line", Integer.toString(lineNumber));
element.attribute("severity", severity);
element.attribute("id", Integer.toString(problemId));
element.attribute("charStart", Integer.toString(charStart));
element.attribute("charEnd", Integer.toString(charEnd));
element.attribute("categoryID", Integer.toString(categoryId));
element.attribute("problemID", Integer.toString(problemId));
Element messageElement = Element.of("message");
messageElement.attribute("value", message);
element.addNode(messageElement);
incrementAttribute(problemsElement, ATTRIBUTES_PROBLEMS, 1);
if (SEVERITY_ERROR.equals(severity)) {
Expand All @@ -182,7 +181,7 @@ public void addProblem(String severity, int lineNumber, int charStart, int charE
}

public boolean hasClass(String classFile) {
return source.getChildren("classfile").stream().map(elem -> elem.getAttributeValue("path"))
return source.children("classfile").stream().map(elem -> elem.attribute("path"))
.filter(Objects::nonNull).anyMatch(path -> path.endsWith(classFile));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.eclipse.tycho.p2resolver.TargetDefinitionVariableResolver;
import org.eclipse.tycho.targetplatform.TargetDefinition;

import de.pdark.decentxml.Element;
import eu.maveniverse.domtrip.Element;

/**
* Updater for installable units
Expand All @@ -75,16 +75,16 @@ boolean update(Element iuLocation, UpdateTargetMojo context)
Log log = context.getLog();
ResolvedRepository location = getResolvedLocation(iuLocation);
log.info("Check " + location.getLocation() + " for updates...");
List<IU> units = iuLocation.getChildren("unit").stream()
.map(unit -> new IU(unit.getAttributeValue("id"), getUnitVersion(unit), unit)).toList();
List<IU> units = iuLocation.children("unit").stream()
.map(unit -> new IU(unit.attribute("id"), getUnitVersion(unit), unit)).toList();
IMetadataRepositoryManager repositoryManager = agent.getService(IMetadataRepositoryManager.class);
URI currentLocation = new URI(location.location());
IMetadataRepository currentRepository = null;
MetadataRepositoryUpdate updateRepository = getMetadataRepository(location, context, units, repositoryManager);
boolean updated = updateRepository.updateLocation(location);
List<VersionUpdate> updates = new ArrayList<>();
for (Element unit : iuLocation.getChildren("unit")) {
String id = unit.getAttributeValue("id");
for (Element unit : iuLocation.children("unit").toList()) {
String id = unit.attribute("id");
String currentVersion = getUnitVersion(unit);
if (isVersionRange(currentVersion)) {
//we can't update version ranges (yet)
Expand Down Expand Up @@ -119,7 +119,7 @@ boolean update(Element iuLocation, UpdateTargetMojo context)
+ newVersion);
updates.add(update);
updated = true;
unit.setAttribute("version", newVersion);
unit.attribute("version", newVersion);
}
}
} else {
Expand Down Expand Up @@ -153,7 +153,7 @@ private boolean isVersionRange(String version) {
}

private String getUnitVersion(Element unit) {
String value = unit.getAttributeValue("version");
String value = unit.attribute("version");
if (value == null || value.isBlank()) {
return EMPTY_VERSION;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ private MetadataRepositoryUpdate findBestLocation(UpdateTargetMojo context, List
// But this currently fails the PGP mojo using org.bouncycastle.openpgp.PGPPublicKey
// private static Collection<URI> getChildren(IMetadataRepository repository) {
// if (repository instanceof ICompositeRepository<?> composite) {
// return composite.getChildren();
// return composite.children();
// }
// return List.of();
// }
Expand Down Expand Up @@ -377,9 +377,9 @@ private static List<IU> findBestUnits(List<IU> units, IMetadataRepositoryManager

private ResolvedRepository getResolvedLocation(Element iuLocation) {
Element element = iuLocation.getChild("repository");
String attribute = element.getAttributeValue("location");
String attribute = element.attribute("location");
String resolved = varResolver.resolve(attribute);
return new ResolvedRepository(element.getAttributeValue("id"), resolved, element);
return new ResolvedRepository(element.attribute("id"), resolved, element);
}

private static final record ResolvedRepository(String id, String location, Element element)
Expand All @@ -396,7 +396,7 @@ public String getId() {
}

public void setLocation(URI uri) {
element().setAttribute("location", uri.toString());
element().attribute("location", uri.toString());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.p2maven.tmp.BundlesAction;

import de.pdark.decentxml.Element;
import eu.maveniverse.domtrip.Element;

/**
* Supports updating of maven target locations
Expand All @@ -66,7 +66,7 @@ List<MavenVersionUpdate> update(Element mavenLocation, UpdateTargetMojo context)
Element dependencies = mavenLocation.getChild("dependencies");
List<MavenVersionUpdate> updates = new ArrayList<>();
if (dependencies != null) {
for (Element dependency : dependencies.getChildren("dependency")) {
for (Element dependency : dependencies.children("dependency").toList()) {
Dependency mavenDependency = getDependency(dependency);
Artifact dependencyArtifact = helper.createDependencyArtifact(mavenDependency);
ArtifactVersions versions = helper.lookupArtifactVersions(dependencyArtifact, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@
import org.eclipse.tycho.targetplatform.TargetPlatformArtifactResolver;
import org.eclipse.tycho.targetplatform.TargetResolveException;

import de.pdark.decentxml.Document;
import de.pdark.decentxml.Element;
import de.pdark.decentxml.XMLIOSource;
import de.pdark.decentxml.XMLParser;
import de.pdark.decentxml.XMLWriter;
import eu.maveniverse.domtrip.Document;
import eu.maveniverse.domtrip.Element;

import eu.maveniverse.domtrip.Serializer;

/**
* This allows to update a target file to use newer version of specified items, e.g. IUs from
Expand Down Expand Up @@ -180,10 +179,10 @@ protected void doUpdate(File file) throws Exception {
getLog().info("Update target file " + file);
//we use the descent xml parser here because we need to retain the formating of the original file
XMLParser parser = new XMLParser();
Document target = parser.parse(new XMLIOSource(file));
Document target = Document.of(file);
boolean changed = false;
builder = new MarkdownBuilder(reportFileName);
builder.h2("The content of the target `" + file.getName() + "` was updated");
builder.h2("The content of the target `" + file.name() + "` was updated");
if (reportPreamble != null && !reportPreamble.isBlank()) {
builder.add(reportPreamble);
builder.newLine();
Expand All @@ -199,7 +198,7 @@ protected void doUpdate(File file) throws Exception {
}
}
if (changed) {
String enc = target.getEncoding() != null ? target.getEncoding() : "UTF-8";
String enc = target.encoding() != null ? target.encoding() : "UTF-8";
try (Writer w = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), enc);
XMLWriter xw = new XMLWriter(w)) {
try {
Expand Down Expand Up @@ -227,14 +226,14 @@ protected void doUpdate(File file) throws Exception {
static void setElementValue(String name, String value, Element root) {
Element child = root.getChild(name);
if (child != null) {
child.setText(value);
child.textContent(value);
}
}

static String getElementValue(String name, Element root) {
Element child = root.getChild(name);
if (child != null) {
String text = child.getText().trim();
String text = child.textContent().trim();
if (text.isBlank()) {
return null;
}
Expand All @@ -244,9 +243,9 @@ static String getElementValue(String name, Element root) {
}

private List<Element> getLocations(String type, Document target) {
Element locations = target.getRootElement().getChild("locations");
Element locations = target.root().getChild("locations");
if (locations != null) {
return locations.getChildren().stream().filter(elem -> type.equals(elem.getAttributeValue("type")))
return locations.children().stream().filter(elem -> type.equals(elem.attribute("type")))
.toList();
}
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
import org.apache.maven.it.Verifier;
import org.junit.Test;

import de.pdark.decentxml.Document;
import de.pdark.decentxml.Element;
import de.pdark.decentxml.XMLIOSource;
import de.pdark.decentxml.XMLParser;
import eu.maveniverse.domtrip.Document;
import eu.maveniverse.domtrip.Element;

public class P2ExtrasPlugin extends AbstractTychoIntegrationTest {

Expand Down Expand Up @@ -157,21 +155,21 @@ public void testPublishFeaturesAndBundles_noUnpack() throws Exception {

private static Element extractUnitFromContentXml(Path contentXml, String unitName) throws IOException {
XMLParser parser = new XMLParser();
Document document = parser.parse(new XMLIOSource(contentXml.toFile()));
Document document = Document.of(contentXml.toFile());
Element unitElement = document.getChild("repository/units");
List<Element> units = unitElement.getChildren("unit");
List<Element> units = unitElement.children("unit");
Optional<Element> extractedUnit = units.stream()
.filter(element -> unitName.equals(element.getAttribute("id").getValue())).findFirst();
.filter(element -> unitName.equals(element.attributeObject("id").getValue())).findFirst();
assertTrue(String.format("Unit with name '%s' not found in content.xml with units: %s", unitName, units),
extractedUnit.isPresent());
return extractedUnit.get();
}

private static boolean hasChildWithZippedAttribute(Element element) {
if ("zipped".equals(element.getAttributeValue("key"))) {
if ("zipped".equals(element.attribute("key"))) {
return true;
}
return element.getChildren().stream().anyMatch(P2ExtrasPlugin::hasChildWithZippedAttribute);
return element.children().stream().anyMatch(P2ExtrasPlugin::hasChildWithZippedAttribute);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import org.junit.Assert;
import org.junit.Test;

import de.pdark.decentxml.Document;
import de.pdark.decentxml.Element;
import de.pdark.decentxml.XMLIOSource;
import de.pdark.decentxml.XMLParser;
import eu.maveniverse.domtrip.Document;
import eu.maveniverse.domtrip.Element;

public class RepositoryCategoriesTest extends AbstractTychoIntegrationTest {

Expand All @@ -46,13 +44,13 @@ public void testDeployableFeature() throws Exception {
Document document = null;
try (ZipFile contentJar = new ZipFile(content)) {
ZipEntry contentXmlEntry = contentJar.getEntry("content.xml");
document = parser.parse(new XMLIOSource(contentJar.getInputStream(contentXmlEntry)));
document = Document.of(contentJar.getInputStream(contentXmlEntry));
}
Element repository = document.getRootElement();
all_units: for (Element unit : repository.getChild("units").getChildren("unit")) {
for (Element property : unit.getChild("properties").getChildren("property")) {
if ("org.eclipse.equinox.p2.type.category".equals(property.getAttributeValue("name"))
&& Boolean.parseBoolean(property.getAttributeValue("value"))) {
Element repository = document.root();
all_units: for (Element unit : repository.getChild("units").children("unit")) {
for (Element property : unit.getChild("properties").children("property")) {
if ("org.eclipse.equinox.p2.type.category".equals(property.attribute("name"))
&& Boolean.parseBoolean(property.attribute("value"))) {
found = true;
break all_units;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.eclipse.tycho.test.util.ResourceUtil;
import org.junit.Test;

import de.pdark.decentxml.Document;
import de.pdark.decentxml.XMLParser;
import eu.maveniverse.domtrip.Document;

public class ApiToolsTest extends AbstractTychoIntegrationTest {
@Test
Expand All @@ -39,7 +38,7 @@ public void testGenerate() throws Exception {
File descriptionFile = new File(verifier.getBasedir(), "bundle1/target/.api_description");
assertTrue(descriptionFile.getAbsoluteFile() + " not found", descriptionFile.isFile());
Document document = XMLParser.parse(descriptionFile);
assertEquals("api-bundle-1_0.0.1-SNAPSHOT", document.getRootElement().getAttribute("name").getValue());
assertEquals("api-bundle-1_0.0.1-SNAPSHOT", document.root().attributeObject("name").getValue());
// TODO enhance project and assert more useful things...
}

Expand Down
Loading