From 70bc40c54c9269ae1e3d357d8bab8a07b715a98e Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 29 Mar 2023 16:04:58 +0900 Subject: [PATCH 1/3] update settings --- .github/workflows/codeql-analysis.yml | 17 +--- .github/workflows/maven.yml | 23 ++++-- README.md | 5 ++ build.xml | 88 --------------------- pom.xml | 108 ++++++++++++++++++++++++-- 5 files changed, 126 insertions(+), 115 deletions(-) delete mode 100644 build.xml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 00010b4..b0e4833 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -30,20 +30,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -54,7 +45,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # ℹ️ Command-line programs to run using the OS shell. # πŸ“š https://git.io/JvXDl @@ -68,4 +59,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c8aeb3a..e117fc8 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -15,10 +15,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Build with Maven - run: mvn -B package --file pom.xml + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check w/o SNAPSHOT when "bump version" + if: ${{ contains(github.event.head_commit.message, 'bump version') }} + run: grep "" pom.xml | head -1 | grep -v SNAPSHOT + + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/README.md b/README.md index 55069cc..e43fa1e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ [![Release](https://jitpack.io/v/umjammer/vavi-apps-xed.svg)](https://jitpack.io/#umjammer/vavi-apps-xed) +[![Java CI](https://github.com/umjammer/vavi-apps-xed/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-apps-xed/actions/workflows/maven.yml) +[![CodeQL](https://github.com/umjammer/vavi-apps-xed/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-apps-xed/actions/workflows/codeql-analysis.yml) +![Java](https://img.shields.io/badge/Java-8-b07219) # XED XML EDitor +a command line xml editor. + ## Goal * sort by tag diff --git a/build.xml b/build.xml deleted file mode 100644 index 86f36a5..0000000 --- a/build.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 362fc73..c3377af 100644 --- a/pom.xml +++ b/pom.xml @@ -10,23 +10,107 @@ vavi-apps-xed 1.1.0 - Xml EDitor Application + XED Xml EDitor - vavi inc. + vavi https://github.com/umjammer/vavi-apps-xed - + a command line xml editor + + + + run + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + + split + + + + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + run + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins maven-compiler-plugin + 3.10.1 1.8 1.8 UTF-8 + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + + + -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties + + false + + @@ -37,11 +121,23 @@ + + + + org.junit + junit-bom + 5.9.2 + pom + import + + + + net.sf.saxon Saxon-HE - 9.7.0-3 + 11.5 com.github.umjammer @@ -51,19 +147,17 @@ com.github.umjammer vavi-commons - 1.0.8 + 1.1.9 org.junit.jupiter junit-jupiter-api - 5.3.0 test org.junit.jupiter junit-jupiter-engine - 5.3.0 test From 37cfe2b9b0853b454cc115f8be68920a7f8c43ab Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 29 Mar 2023 16:05:27 +0900 Subject: [PATCH 2/3] follow ide advices --- src/main/java/vavi/apps/xed/Command.java | 2 +- .../java/vavi/apps/xed/command/Editor.java | 17 +++++++------- .../java/vavi/apps/xed/command/Sorter.java | 22 +++++++++---------- .../java/vavi/apps/xed/command/Splitter.java | 9 ++++---- src/test/java/Test1.java | 9 ++++---- src/test/java/Test2.java | 3 +-- src/test/resources/logging.properties | 6 +++++ 7 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 src/test/resources/logging.properties diff --git a/src/main/java/vavi/apps/xed/Command.java b/src/main/java/vavi/apps/xed/Command.java index 8193836..c7029c5 100644 --- a/src/main/java/vavi/apps/xed/Command.java +++ b/src/main/java/vavi/apps/xed/Command.java @@ -24,7 +24,7 @@ public interface Command { void exec(Document document); /** TODO */ - static XPath xPath = XPathFactory.newInstance().newXPath(); + XPath xPath = XPathFactory.newInstance().newXPath(); } /* */ diff --git a/src/main/java/vavi/apps/xed/command/Editor.java b/src/main/java/vavi/apps/xed/command/Editor.java index 7fa09fb..87ff140 100644 --- a/src/main/java/vavi/apps/xed/command/Editor.java +++ b/src/main/java/vavi/apps/xed/command/Editor.java @@ -47,14 +47,14 @@ public class Editor implements Command, Binder { /** js expression, $$ in string replaced by child nodes of sourceXPath */ String destinationExpression; - /* */ + @Override public String toString() { return "targetXPath: " + targetXPath + ", sourceXPath: " + sourceXPath + ", destinationExpression: " + destinationExpression; } - /* */ + @Override public void bind(App bean, String[] args, Context context) { bean.editor = new Editor(); bean.editor.targetXPath = args[0]; @@ -98,13 +98,14 @@ public void bind(App bean, String[] args, Context context) { * </foo> * * - * @param document + * @param document target to edit */ + @Override public void exec(Document document) { try { Object nodeSet = xPath.evaluate(targetXPath, document, XPathConstants.NODESET); - NodeList nodeList = NodeList.class.cast(nodeSet); + NodeList nodeList = (NodeList) nodeSet; //System.err.println("nodeList: " + nodeList.getLength()); List nodes = new ArrayList<>(); @@ -136,14 +137,14 @@ public void exec(Document document) { } } - /** */ + /** function for javascript */ public String function_xpath(String xpath, Node node) throws XPathExpressionException { String replacement = (String) xPath.evaluate(xpath, node, XPathConstants.STRING); //System.err.println("replacement: " + replacement); return replacement; } - /** */ + /** function for javascript */ public String function_xpath_sdf(String xpath, String format1, String format2, Node node) throws XPathExpressionException { String datetime = (String) xPath.evaluate(xpath, node, XPathConstants.STRING); String replacement; @@ -157,7 +158,7 @@ public String function_xpath_sdf(String xpath, String format1, String format2, N return replacement; } - /** */ + /** exec javascript */ private void process_script(String expression, Node node, Node sourceNode, Document document) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); @@ -183,7 +184,7 @@ private void process_script(String expression, Node node, Node sourceNode, Docum private void process_$$(String expression, Node sourceNode, Document document) { List sourceNodes = new ArrayList<>(); - // foursquare γŒγ‚’γƒ›γͺε‡ΊεŠ›γ™γ‚‹γ‹γ‚‰ + // cause foursquare's weired outputs for (int j = 0; j < sourceNode.getChildNodes().getLength(); j++) { Node childNode = sourceNode.getChildNodes().item(j); //System.err.println("i:" + childNode); diff --git a/src/main/java/vavi/apps/xed/command/Sorter.java b/src/main/java/vavi/apps/xed/command/Sorter.java index 87d171f..ead1a5a 100644 --- a/src/main/java/vavi/apps/xed/command/Sorter.java +++ b/src/main/java/vavi/apps/xed/command/Sorter.java @@ -9,7 +9,6 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Comparator; import java.util.Date; import java.util.Locale; import java.util.SortedMap; @@ -38,6 +37,7 @@ public class Sorter implements Command, Binder { enum Type { datetime { + @Override int compareTo(String o1, String o2, Sorter sorter) { try { DateFormat sdf = new SimpleDateFormat(sorter.option, Locale.ENGLISH); // "http://d.hatena.ne.jp/rudi/20101201/1291214680" TODO locale @@ -50,6 +50,7 @@ int compareTo(String o1, String o2, Sorter sorter) { } }, string { + @Override int compareTo(String o1, String o2, Sorter sorter) { return sorter.ascend ? o1.compareTo(o2) : o2.compareTo(o1); } @@ -72,7 +73,7 @@ int compareTo(String o1, String o2, Sorter sorter) { /** datetime: author time format @see {@link java.text.DateFormat} */ String option; - /* */ + @Override public String toString() { return "targetXPath: " + targetXPath + ", keyXPath: " + keyXPath + @@ -81,12 +82,12 @@ public String toString() { ", option: " + option; } - /* */ + @Override public void bind(App bean, String[] args, Context context) { bean.sorter = new Sorter(); bean.sorter.targetXPath = args[0]; bean.sorter.keyXPath = args[1]; - bean.sorter.ascend = args.length > 2 ? args[2].equals("desc") ? false : true : true; + bean.sorter.ascend = args.length == 2 || !args[2].equals("desc"); bean.sorter.type = args.length > 3 ? args[3].equals("datetime") ? Sorter.Type.datetime : Sorter.Type.string : Sorter.Type.string; bean.sorter.option = args.length > 4 ? args[4] : null; } @@ -119,20 +120,17 @@ public void bind(App bean, String[] args, Context context) { * </foo> * * - * @param document + * @param document target to edit */ + @Override public void exec(Document document) { try { Object nodeSet = xPath.evaluate(targetXPath, document, XPathConstants.NODESET); - NodeList nodeList = NodeList.class.cast(nodeSet); + NodeList nodeList = (NodeList) nodeSet; //System.err.println("nodeList: " + nodeList.getLength()); - SortedMap nodes = new TreeMap<>(new Comparator() { - public int compare(String o1, String o2) { - return type.compareTo(o1, o2, Sorter.this); - } - }); + SortedMap nodes = new TreeMap<>((o1, o2) -> type.compareTo(o1, o2, Sorter.this)); Node parent = null; @@ -143,7 +141,7 @@ public int compare(String o1, String o2) { parent = node.getParentNode(); } - String key = (String) xPath.evaluate(keyXPath, node, XPathConstants.STRING); // removeChild γ—γ¦γ‚‹γ‹γ‚‰γ†γΎγθ‘Œγ£γ¦γ‚‹ + String key = (String) xPath.evaluate(keyXPath, node, XPathConstants.STRING); // works well cause "removeChild" before. nodes.put(key, node); diff --git a/src/main/java/vavi/apps/xed/command/Splitter.java b/src/main/java/vavi/apps/xed/command/Splitter.java index 126f110..7f8102d 100644 --- a/src/main/java/vavi/apps/xed/command/Splitter.java +++ b/src/main/java/vavi/apps/xed/command/Splitter.java @@ -36,13 +36,13 @@ public class Splitter implements Command, Binder { /** max number for splitting node */ int maxNumber; - /* */ + @Override public String toString() { return "targetXPath: " + targetXPath + ", sourceXPath: " + maxNumber; } - /* */ + @Override public void bind(App bean, String[] args, Context context) { bean.splitter = new Splitter(); bean.splitter.targetXPath = args[0]; @@ -90,13 +90,14 @@ public void bind(App bean, String[] args, Context context) { * <!-- 9 --> * * - * @param document + * @param document target to edit */ + @Override public void exec(Document document) { try { Object nodeSet = xPath.evaluate(targetXPath, document, XPathConstants.NODESET); - NodeList nodeList = NodeList.class.cast(nodeSet); + NodeList nodeList = (NodeList) nodeSet; System.err.println("nodeList: " + nodeList.getLength()); Queue nodes = new LinkedList<>(); diff --git a/src/test/java/Test1.java b/src/test/java/Test1.java index 268a1c8..8ec0e8c 100644 --- a/src/test/java/Test1.java +++ b/src/test/java/Test1.java @@ -49,9 +49,10 @@ public void parse(Reader inputHandler, String xpath) throws IOException { Object nodeSet = xPath.evaluate(xpath, in, XPathConstants.NODESET); - if (List.class.isInstance(nodeSet)) { + if (nodeSet instanceof List) { - List nodeList = List.class.cast(nodeSet); + @SuppressWarnings("unchecked") + List nodeList = (List) nodeSet; //System.err.println("nodeList: " + nodeList.size()); for (int i = 0; i < nodeList.size(); i++) { System.out.println("[" + i + "]------------------ "); @@ -59,9 +60,9 @@ public void parse(Reader inputHandler, String xpath) throws IOException { PrettyPrinter pp = new PrettyPrinter(System.out); pp.print(NodeOverNodeInfo.wrap(nodeList.get(i))); } - } else if (NodeList.class.isInstance(nodeSet)) { + } else if (nodeSet instanceof NodeList) { - NodeList nodeList = NodeList.class.cast(nodeSet); + NodeList nodeList = (NodeList) nodeSet; //System.err.println("nodeList: " + nodeList.getLength()); for (int i = 0; i < nodeList.getLength(); i++) { diff --git a/src/test/java/Test2.java b/src/test/java/Test2.java index 5085ab8..a336b9f 100644 --- a/src/test/java/Test2.java +++ b/src/test/java/Test2.java @@ -35,7 +35,7 @@ public void test1() throws Exception { matcher1.appendReplacement(sb, replacement); } matcher1.appendTail(sb); -System.err.println(sb.toString()); +System.err.println(sb); } @Test @@ -83,7 +83,6 @@ public void test3() throws Exception { System.err.println(result); } - } /* */ diff --git a/src/test/resources/logging.properties b/src/test/resources/logging.properties new file mode 100644 index 0000000..3b2a8ba --- /dev/null +++ b/src/test/resources/logging.properties @@ -0,0 +1,6 @@ +handlers=java.util.logging.ConsoleHandler +.level=INFO +java.util.logging.ConsoleHandler.level=ALL +java.util.logging.ConsoleHandler.formatter=vavi.util.logging.VaviFormatter + +#vavi.util.level=FINE From 48867274db0b7acf9d585e14c29afe5163943d59 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 29 Mar 2023 16:05:36 +0900 Subject: [PATCH 3/3] bump version --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c3377af..ba8fe0a 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ vavi vavi-apps-xed - 1.1.0 + 1.1.1 XED Xml EDitor @@ -21,9 +21,9 @@ run - - - + + + org.apache.maven.plugins maven-antrun-plugin