Skip to content

Commit

Permalink
Merge branch 'master' into snyk-upgrade-3ab4f8e61d8cde8ca937cd4edd3af583
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekryd committed Jan 29, 2023
2 parents 54a0337 + 24af1ab commit e2d7433
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 117 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
docker:
- image: cimg/openjdk:18.0
<<: *shared
jdk19:
docker:
- image: cimg/openjdk:19.0
<<: *shared
jdk11:
docker:
- image: cimg/openjdk:11.0
Expand All @@ -51,6 +55,9 @@ workflows:
- jdk18:
requires:
- jdk17
- jdk19:
requires:
- jdk17
- jdk11:
filters: # using regex filters requires the entire branch to match
branches:
Expand All @@ -59,4 +66,5 @@ workflows:
requires:
- jdk17
- jdk18
- jdk19

2 changes: 1 addition & 1 deletion maven-plugin/src/it/sort-executions/expected_pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/src/it/sort-executions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/src/it/sort-order-file/expected/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.6</version>
<version>3.8.7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
Expand Down
3 changes: 2 additions & 1 deletion misc/welcome.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
* mvn clean install (compile without signing the jar-file) *
* *
* mvn clean install (to deploy new version of the plugin) *
* echo "test" | gpg --clearsign (test the gpg first) *
* mvn release:clean *
* mvn release:prepare *
* mvn release:perform *
* *
* mvn versions:display-dependency-updates *
* mvn versions:display-plugin-updates *
* mvn versions:display-dependency-updates *
* *
******************************************************************************
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand All @@ -20,7 +20,7 @@
<properties>
<compileSource>11</compileSource>
<junit.jupiter.version>5.9.2</junit.jupiter.version>
<mockito.version>5.0.0</mockito.version>
<mockito.version>5.1.0</mockito.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j.version>2.0.6</slf4j.version>
</properties>
Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.3</version>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -114,12 +114,12 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.3.2</version>
<version>2.0.1</version>
</plugin>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
<configuration>
<createBackupFile>false</createBackupFile>
<predefinedSortOrder>custom_1</predefinedSortOrder>
Expand Down
54 changes: 0 additions & 54 deletions sorter/src/main/java/sortpom/output/PatchedXMLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
import org.dom4j.Attribute;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.ProcessingInstruction;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dom4j.tree.DefaultText;
import org.dom4j.tree.NamespaceStack;
import sortpom.content.NewlineText;
import sortpom.exception.FailureException;

/** Overriding XMLWriter to be able to handle SortPom formatting options */
class PatchedXMLWriter extends XMLWriter {
Expand All @@ -24,7 +19,6 @@ class PatchedXMLWriter extends XMLWriter {
private final boolean indentBlankLines;
private final boolean indentSchemaLocation;
private final boolean spaceBeforeCloseEmptyElement;
private final NamespaceStack parentNamespaceStack;

public PatchedXMLWriter(
Writer writer,
Expand All @@ -37,18 +31,6 @@ public PatchedXMLWriter(
this.indentBlankLines = indentBlankLines;
this.indentSchemaLocation = indentSchemaLocation;
this.spaceBeforeCloseEmptyElement = spaceBeforeCloseEmptyElement;
this.parentNamespaceStack = findParentNamespaceStack();
}

private NamespaceStack findParentNamespaceStack() {
try {
Field field = XMLWriter.class.getDeclaredField("namespaceStack");
field.setAccessible(true);
return (NamespaceStack) field.get(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new FailureException(
"Internal error: Cannot access internal namespace stack in XMLWriter", e);
}
}

/** Handle spaceBeforeCloseEmptyElement option */
Expand Down Expand Up @@ -110,42 +92,6 @@ private void writeTrimmedText(Node node) throws IOException {
}
}

/**
* Support for indentSchemaLocation, where the original method really should call the
* writeAttribute method
*/
@Override
protected void writeAttributes(Element element) throws IOException {
for (int i = 0, size = element.attributeCount(); i < size; i++) {
Attribute attribute = element.attribute(i);
Namespace ns = attribute.getNamespace();

if ((ns != null) && (ns != Namespace.NO_NAMESPACE) && (ns != Namespace.XML_NAMESPACE)) {
String prefix = ns.getPrefix();
String uri = parentNamespaceStack.getURI(prefix);

if (!ns.getURI().equals(uri)) {
writeNamespace(ns);
parentNamespaceStack.push(ns);
}
}

String attName = attribute.getName();

if (attName.startsWith("xmlns:")) {
String prefix = attName.substring(6);

if (parentNamespaceStack.getNamespaceForPrefix(prefix) == null) {
String uri = attribute.getValue();
parentNamespaceStack.push(prefix, uri);
writeNamespace(prefix, uri);
}
} else if (!attName.equals("xmlns")) {
writeAttribute(attribute);
}
}
}

/** Handle indentSchemaLocation option */
@Override
protected void writeAttribute(Attribute attribute) throws IOException {
Expand Down
46 changes: 0 additions & 46 deletions sorter/src/test/java/sortpom/output/XmlOutputGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import static org.mockito.Mockito.when;
import static sortpom.sort.XmlFragment.createXmlFragment;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import org.dom4j.Document;
import org.dom4j.tree.DefaultAttribute;
import org.dom4j.tree.DefaultElement;
Expand Down Expand Up @@ -118,45 +113,4 @@ void attributeCalledXmlnsShouldNotBePrinted() {
assertThat(
sortedXml, is(equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Gurka></Gurka>\n")));
}

@Test
void simulateNamespaceStackNotFound() throws Exception {
var classloader =
new URLClassLoader(
new URL[] {
new File("target/classes").toURI().toURL(),
new File("target/test-classes").toURI().toURL(),
// Contains the dummy XMLWriter class that does not have the namespace stack field
new File("src/test/resources/mock").toURI().toURL()
}) {

protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (name.equals("org.dom4j.io.XMLWriter")) {
return findClass(name);
// With no fallback to parent classloader
}
try {
return findClass(name);
} catch (ClassNotFoundException e) {
// Could not find the class so load it from the parent
return super.loadClass(name, resolve);
}
}
};

Class<?> clazz = classloader.loadClass("sortpom.output.PatchedXMLWriter");
Constructor<?> constructor = clazz.getConstructors()[0];
constructor.setAccessible(true);

var exception =
assertThrows(
InvocationTargetException.class,
() -> constructor.newInstance(null, null, false, false, false));

var cause = exception.getCause();
assertThat(cause.getClass().getName(), is("sortpom.exception.FailureException"));
assertThat(
cause.getMessage(),
is("Internal error: Cannot access internal namespace stack in XMLWriter"));
}
}
2 changes: 1 addition & 1 deletion sorter/src/test/resources/MultilineContent_expected.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=concurrent
Expand Down
2 changes: 1 addition & 1 deletion sorter/src/test/resources/MultilineContent_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=concurrent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down Expand Up @@ -96,7 +96,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down
4 changes: 2 additions & 2 deletions sorter/src/test/resources/SortExec_input_complexWithPhase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down Expand Up @@ -98,7 +98,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
<configuration>
<message>Hi!</message>
</configuration>
Expand Down

0 comments on commit e2d7433

Please sign in to comment.