You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/01/13 16:17:03 UTC
[tomcat-jakartaee-migration] 02/03: Add a feature that updates the
MANIFEST version info during migration
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to tag 0.0.1
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
commit ca90f2ab5c6e9d01c2ff153198ec0a96c7d5a6fd
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 13 15:51:20 2020 +0000
Add a feature that updates the MANIFEST version info during migration
---
.../java/org/apache/tomcat/jakartaee/Info.java | 54 ++++++++++++++++++++++
.../org/apache/tomcat/jakartaee/Migration.java | 18 ++++++++
src/main/resources/info.properties | 16 +++++++
3 files changed, 88 insertions(+)
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Info.java b/src/main/java/org/apache/tomcat/jakartaee/Info.java
new file mode 100644
index 0000000..a8de1a0
--- /dev/null
+++ b/src/main/java/org/apache/tomcat/jakartaee/Info.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.tomcat.jakartaee;
+
+import java.io.IOException;
+import java.util.Properties;
+
+public class Info {
+
+ private static final String VERSION;
+
+ static {
+ Properties props = new Properties();
+
+ String version = null;
+ try {
+ props.load(Info.class.getClassLoader().getResourceAsStream("info.properties"));
+
+ version = props.getProperty("version");
+
+ } catch (IOException e) {
+ // Handled below
+ }
+
+ if (version == null) {
+ VERSION = "UNKNOWN";
+ } else {
+ VERSION = version;
+ }
+ }
+
+ public static String getVersion() {
+ return VERSION;
+ }
+
+
+ private Info() {
+ // Utility class. Hide default constructor.
+ }
+}
diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index 5950195..80fb2b1 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
@@ -97,6 +98,7 @@ public class Migration {
JarOutputStream jarOs = new JarOutputStream(new NonClosingOutputStream(dest))) {
Manifest manifest = jarIs.getManifest();
if (manifest != null) {
+ updateVersion(manifest);
JarEntry manifestEntry = new JarEntry(JarFile.MANIFEST_NAME);
jarOs.putNextEntry(manifestEntry);
manifest.write(jarOs);
@@ -129,6 +131,22 @@ public class Migration {
}
+ private void updateVersion(Manifest manifest) {
+ updateVersion(manifest.getMainAttributes());
+ for (Attributes attributes : manifest.getEntries().values()) {
+ updateVersion(attributes);
+ }
+ }
+
+
+ private void updateVersion(Attributes attributes) {
+ if (attributes.containsKey(Attributes.Name.IMPLEMENTATION_VERSION)) {
+ String newValue = attributes.get(Attributes.Name.IMPLEMENTATION_VERSION) + "-" + Info.getVersion();
+ attributes.put(Attributes.Name.IMPLEMENTATION_VERSION, newValue);
+ }
+ }
+
+
public static void main(String[] args) {
if (args.length != 2) {
usage();
diff --git a/src/main/resources/info.properties b/src/main/resources/info.properties
new file mode 100644
index 0000000..2ba48b9
--- /dev/null
+++ b/src/main/resources/info.properties
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+version=migrated-${project.version}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org