You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2020/10/18 13:30:35 UTC
[tapestry-5] branch java9modules updated: TAP5-2641: partial
implementation of tapestry-version-migrator
This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch java9modules
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/java9modules by this push:
new f6abd1f TAP5-2641: partial implementation of tapestry-version-migrator
f6abd1f is described below
commit f6abd1fce9eee29fe490b2843aa7df39bee23697
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sun Oct 18 10:30:20 2020 -0300
TAP5-2641: partial implementation of tapestry-version-migrator
---
settings.gradle | 2 +-
tapestry-version-migrator/build.gradle | 14 +++
.../org/apache/tapestry5/versionmigrator/Main.java | 122 +++++++++++++++++++++
.../tapestry5/versionmigrator/TapestryVersion.java | 59 ++++++++++
4 files changed, 196 insertions(+), 1 deletion(-)
diff --git a/settings.gradle b/settings.gradle
index ea133d0..9921957 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -4,5 +4,5 @@ include "tapestry-beanvalidator", "tapestry-jpa", "tapestry-kaptcha"
include "tapestry-javadoc", "quickstart", "tapestry-clojure", "tapestry-mongodb"
include "tapestry-test-data", 'tapestry-internal-test', "tapestry-ioc-junit"
include "tapestry-webresources", "tapestry-runner", "tapestry-test-constants"
-include "tapestry-ioc-jcache", "beanmodel", "commons", "genericsresolver-guava"
+include "tapestry-ioc-jcache", "beanmodel", "commons", "genericsresolver-guava", "tapestry-version-migrator"
// include "tapestry-cdi"
diff --git a/tapestry-version-migrator/build.gradle b/tapestry-version-migrator/build.gradle
new file mode 100644
index 0000000..50ffffe
--- /dev/null
+++ b/tapestry-version-migrator/build.gradle
@@ -0,0 +1,14 @@
+description = "Tool to help migrate source code using Tapestry from one version to another. Initially built for 5.7.0"
+
+dependencies {
+}
+
+test {
+ useJUnit()
+}
+
+/*jar {
+ manifest {
+ attributes 'Tapestry-Module-Classes': 'org.apache.tapestry5.json.modules.JSONModule'
+ }
+}*/
diff --git a/tapestry-version-migrator/src/main/java/org/apache/tapestry5/versionmigrator/Main.java b/tapestry-version-migrator/src/main/java/org/apache/tapestry5/versionmigrator/Main.java
new file mode 100644
index 0000000..b1b07dc
--- /dev/null
+++ b/tapestry-version-migrator/src/main/java/org/apache/tapestry5/versionmigrator/Main.java
@@ -0,0 +1,122 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.versionmigrator;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+public class Main
+{
+
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ printHelp();
+ }
+ else
+ {
+ switch (args[0])
+ {
+ case "generate":
+ createVersionFile(args[1]);
+ break;
+
+ default:
+ printHelp();
+ }
+ }
+ }
+
+ private static void printHelp() {
+ // TODO Auto-generated method stub
+
+ }
+
+ private static void createVersionFile(String versionNumber)
+ {
+ final TapestryVersion tapestryVersion = Arrays.stream(TapestryVersion.values())
+ .filter(v -> versionNumber.equals(v.getNumber()))
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException("Unknown Tapestry version: " + versionNumber + ". "));
+ createVersionFile(tapestryVersion);
+ }
+
+ private static void createVersionFile(TapestryVersion version)
+ {
+ final String commandLine = String.format("git diff --summary %s %s",
+ version.getPreviousVersionGitHash(), version.getVersionGitHash());
+ final Process process;
+ final Map<String, String> renames = new HashMap<>();
+
+ System.out.printf("Running command line '%s'\n", commandLine);
+ List<String> lines = new ArrayList<>();
+ try
+ {
+ process = Runtime.getRuntime().exec(commandLine);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ try (
+ final InputStream inputStream = process.getInputStream();
+ final InputStreamReader isr = new InputStreamReader(inputStream);
+ final BufferedReader reader = new BufferedReader(isr))
+ {
+ String line = reader.readLine();
+ while (line != null)
+ {
+ lines.add(line);
+ line = reader.readLine();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ process(lines, renames);
+ }
+
+ private static void process(List<String> lines, Map<String, String> renames) {
+ lines = lines.stream()
+ .map(s -> s.trim())
+ .filter(s -> s.startsWith("rename"))
+ .filter(s -> !s.contains("test"))
+ .filter(s -> !s.contains("package-info"))
+ .map(s -> s.replaceFirst("rename", "").trim())
+ .collect(Collectors.toList());
+
+ for (String line : lines) {
+ if (line.startsWith("{")) {
+
+ }
+ else {
+ Pattern pattern = Pattern.compile("([^/]*)" + Pattern.quote("/") + "(.*)" + Pattern.quote("{") + "(.*)\\s=>\\s(.*)" + Pattern.quote("}/") + "([^\\.]*).*");
+
+ final Matcher matcher = pattern.matcher(line);
+ if (matcher.matches()) {
+ System.out.printf("%s %s %s %s %s\n", matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5));
+ }
+ }
+ }
+ }
+
+}
diff --git a/tapestry-version-migrator/src/main/java/org/apache/tapestry5/versionmigrator/TapestryVersion.java b/tapestry-version-migrator/src/main/java/org/apache/tapestry5/versionmigrator/TapestryVersion.java
new file mode 100644
index 0000000..ea316b7
--- /dev/null
+++ b/tapestry-version-migrator/src/main/java/org/apache/tapestry5/versionmigrator/TapestryVersion.java
@@ -0,0 +1,59 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.versionmigrator;
+
+/**
+ * Represents a Tapestry version that needs a migration due to names that moved from
+ * one package to another.
+ */
+public enum TapestryVersion
+{
+
+ TAPESTRY_5_7_0("5.7.0", "HEAD", "39041bfa2c6c030f2f2e55d1c88c3ed836ff758b" /* 5.6.1 */);
+
+ final private String number;
+ final private String previousVersionGitHash;
+ final private String versionGitHash;
+
+ private TapestryVersion(String number, String versionGitHash, String previousVersionGitHash)
+ {
+ this.number = number;
+ this.versionGitHash = versionGitHash;
+ this.previousVersionGitHash = previousVersionGitHash;
+ }
+
+ /**
+ * Returns the version number.
+ */
+ public String getNumber()
+ {
+ return number;
+ }
+
+ /**
+ * Returns the Git hash or tag representing the version previous to this one.
+ */
+ public String getPreviousVersionGitHash()
+ {
+ return previousVersionGitHash;
+ }
+
+ /**
+ * Represents the Git hash or tag representing this version.
+ * @return
+ */
+ public String getVersionGitHash()
+ {
+ return versionGitHash;
+ }
+
+}
\ No newline at end of file