This is an automated email from the ASF dual-hosted git repository.
markt pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git. from a969108 Expand test cases. Remove debug logging. new 9e6f3b7 Add legacyAppBase property with default of "webapps-javaee" new e08dbf4 Integrate Java EE -> Jakarta EE migration with automatic deployment The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: build.properties.default | 12 +++ build.xml | 23 +++++ conf/catalina.properties | 1 + java/org/apache/catalina/Host.java | 24 +++++ .../apache/catalina/core/LocalStrings.properties | 1 + java/org/apache/catalina/core/StandardHost.java | 65 +++++++++--- .../apache/catalina/core/mbeans-descriptors.xml | 4 + java/org/apache/catalina/startup/HostConfig.java | 109 +++++++++++++++++++++ .../catalina/startup/LocalStrings.properties | 1 + test/org/apache/tomcat/unittest/TesterHost.java | 15 +++ webapps/docs/changelog.xml | 11 ++- 11 files changed, 250 insertions(+), 16 deletions(-) --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git commit 9e6f3b7328b89259a222e85c838e6104c9eb2a22 Author: Mark Thomas <[hidden email]> AuthorDate: Thu Feb 11 12:27:30 2021 +0000 Add legacyAppBase property with default of "webapps-javaee" --- build.xml | 1 + java/org/apache/catalina/Host.java | 24 ++++++++ .../apache/catalina/core/LocalStrings.properties | 1 + java/org/apache/catalina/core/StandardHost.java | 65 +++++++++++++++++----- .../apache/catalina/core/mbeans-descriptors.xml | 4 ++ test/org/apache/tomcat/unittest/TesterHost.java | 15 +++++ 6 files changed, 96 insertions(+), 14 deletions(-) diff --git a/build.xml b/build.xml index 455edf9..98d180e 100644 --- a/build.xml +++ b/build.xml @@ -808,6 +808,7 @@ <mkdir dir="${tomcat.build}/logs"/> <mkdir dir="${tomcat.build}/temp"/> <mkdir dir="${tomcat.build}/webapps"/> + <mkdir dir="${tomcat.build}/webapps-javaee"/> <!-- Property that determines if manifests need updating --> <uptodate property="manifests.uptodate" diff --git a/java/org/apache/catalina/Host.java b/java/org/apache/catalina/Host.java index 3659240..ba585f0 100644 --- a/java/org/apache/catalina/Host.java +++ b/java/org/apache/catalina/Host.java @@ -114,6 +114,30 @@ public interface Host extends Container { /** + * @return the legacy (Java EE) application root for this Host. This can be + * an absolute pathname, a relative pathname, or a URL. + */ + public String getLegacyAppBase(); + + + /** + * @return an absolute {@link File} for the legacy (Java EE) appBase of this + * Host. The file will be canonical if possible. There is no guarantee that + * that the appBase exists. + */ + public File getLegacyAppBaseFile(); + + + /** + * Set the legacy (Java EE) application root for this Host. This can be an + * absolute pathname, a relative pathname, or a URL. + * + * @param legacyAppBase The new legacy application root + */ + public void setLegacyAppBase(String legacyAppBase); + + + /** * @return the value of the auto deploy flag. If true, it indicates that * this host's child webapps should be discovered and automatically * deployed dynamically. diff --git a/java/org/apache/catalina/core/LocalStrings.properties b/java/org/apache/catalina/core/LocalStrings.properties index f1ede08..bcc97e2 100644 --- a/java/org/apache/catalina/core/LocalStrings.properties +++ b/java/org/apache/catalina/core/LocalStrings.properties @@ -248,6 +248,7 @@ standardHost.noContext=No Context configured to process this request standardHost.notContext=Child of a Host must be a Context standardHost.nullName=Host name is required standardHost.problematicAppBase=Using an empty string for appBase on host [{0}] will set it to CATALINA_BASE, which is a bad idea +standardHost.problematicLegacyAppBase=Using an empty string for legacyAppBase on host [{0}] will set it to CATALINA_BASE, which is a bad idea standardHostValue.customStatusFailed=Custom error page [{0}] could not be dispatched correctly diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java index bf8a096..31bdc94 100644 --- a/java/org/apache/catalina/core/StandardHost.java +++ b/java/org/apache/catalina/core/StandardHost.java @@ -90,6 +90,14 @@ public class StandardHost extends ContainerBase implements Host { private String appBase = "webapps"; private volatile File appBaseFile = null; + + /** + * The legacy (Java EE) application root for this Host. + */ + private String legacyAppBase = "webapps-javaee"; + private volatile File legacyAppBaseFile = null; + + /** * The XML root for this Host. */ @@ -209,19 +217,12 @@ public class StandardHost extends ContainerBase implements Host { } - /** - * Return the application root for this Host. This can be an absolute - * pathname, a relative pathname, or a URL. - */ @Override public String getAppBase() { return this.appBase; } - /** - * ({@inheritDoc} - */ @Override public File getAppBaseFile() { @@ -248,15 +249,8 @@ public class StandardHost extends ContainerBase implements Host { } - /** - * Set the application root for this Host. This can be an absolute - * pathname, a relative pathname, or a URL. - * - * @param appBase The new application root - */ @Override public void setAppBase(String appBase) { - if (appBase.trim().equals("")) { log.warn(sm.getString("standardHost.problematicAppBase", getName())); } @@ -267,6 +261,49 @@ public class StandardHost extends ContainerBase implements Host { } + @Override + public String getLegacyAppBase() { + return this.legacyAppBase; + } + + + @Override + public File getLegacyAppBaseFile() { + if (legacyAppBaseFile != null) { + return legacyAppBaseFile; + } + + File file = new File(getLegacyAppBase()); + + // If not absolute, make it absolute + if (!file.isAbsolute()) { + file = new File(getCatalinaBase(), file.getPath()); + } + + // Make it canonical if possible + try { + file = file.getCanonicalFile(); + } catch (IOException ioe) { + // Ignore + } + + this.legacyAppBaseFile = file; + return file; + } + + + @Override + public void setLegacyAppBase(String legacyAppBase) { + if (legacyAppBase.trim().equals("")) { + log.warn(sm.getString("standardHost.problematicLegacyAppBase", getName())); + } + String oldLegacyAppBase = this.legacyAppBase; + this.legacyAppBase = legacyAppBase; + support.firePropertyChange("legacyAppBase", oldLegacyAppBase, this.legacyAppBase); + this.legacyAppBaseFile = null; + } + + /** * ({@inheritDoc} */ diff --git a/java/org/apache/catalina/core/mbeans-descriptors.xml b/java/org/apache/catalina/core/mbeans-descriptors.xml index c02cff3..bcef191 100644 --- a/java/org/apache/catalina/core/mbeans-descriptors.xml +++ b/java/org/apache/catalina/core/mbeans-descriptors.xml @@ -1129,6 +1129,10 @@ type="java.lang.String" writeable="false" /> + <attribute name="legacyAppBase" + description="The legacy (Java EE) application root for this Host" + type="java.lang.String"/> + <attribute name="managedResource" description="The managed resource this MBean is associated with" type="java.lang.Object"/> diff --git a/test/org/apache/tomcat/unittest/TesterHost.java b/test/org/apache/tomcat/unittest/TesterHost.java index ae3379e..b194879 100644 --- a/test/org/apache/tomcat/unittest/TesterHost.java +++ b/test/org/apache/tomcat/unittest/TesterHost.java @@ -291,6 +291,21 @@ public class TesterHost implements Host { } @Override + public String getLegacyAppBase() { + return null; + } + + @Override + public File getLegacyAppBaseFile() { + return null; + } + + @Override + public void setLegacyAppBase(String legacyAppBase) { + // NO-OP + } + + @Override public boolean getAutoDeploy() { return false; } --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
In reply to this post by markt
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git commit e08dbf4559da7612c4060b68dfee8ce03560ce07 Author: Mark Thomas <[hidden email]> AuthorDate: Thu Feb 11 17:13:52 2021 +0000 Integrate Java EE -> Jakarta EE migration with automatic deployment --- build.properties.default | 12 +++ build.xml | 22 +++++ conf/catalina.properties | 1 + java/org/apache/catalina/startup/HostConfig.java | 109 +++++++++++++++++++++ .../catalina/startup/LocalStrings.properties | 1 + webapps/docs/changelog.xml | 11 ++- 6 files changed, 154 insertions(+), 2 deletions(-) diff --git a/build.properties.default b/build.properties.default index 7253e7a..6d4476b 100644 --- a/build.properties.default +++ b/build.properties.default @@ -303,3 +303,15 @@ osgi-annotations.checksum.value=153054f987534244f95a399539b11375|b6e802bceba0682 osgi-annotations.home=${base.path}/osgi-annotations-${osgi-annotations.version} osgi-annotations.jar=${osgi-annotations.home}/org.osgi.annotation.bundle-${osgi-annotations.version}.jar osgi-annotations.loc=${base-maven.loc}/org/osgi/org.osgi.annotation.bundle/${osgi-annotations.version}/org.osgi.annotation.bundle-${osgi-annotations.version}.jar + +# ----- Tomcat Migration Tool for Jakarta EE ----- +migration-lib.version=0.2.0 + +# checksums for jakartaee-migration-0.2.0-shaded.jar +migration-lib.checksum.enabled=true +migration-lib.checksum.algorithm=MD5|SHA-1 +migration-lib.checksum.value=c7dc838f46901157722ac2f49af854c8|73f53ba52e443f0e992a2aa57d42927d884709eb + +migration-lib.home=${base.path}/migration-${migration-lib.version} +migration-lib.jar=${migration-lib.home}/jakartaee-migration-${migration-lib.version}-shaded.jar +migration-lib.loc=${base-maven.loc}/org/apache/tomcat/jakartaee-migration/${migration-lib.version}/jakartaee-migration-${migration-lib.version}-shaded.jar diff --git a/build.xml b/build.xml index 98d180e..a4c9d05 100644 --- a/build.xml +++ b/build.xml @@ -240,6 +240,7 @@ <pathelement location="${jdt.jar}"/> <pathelement location="${jaxrpc-lib.jar}"/> <pathelement location="${wsdl4j-lib.jar}"/> + <pathelement location="${migration-lib.jar}"/> </path> <path id="tomcat.classpath"> @@ -1462,6 +1463,17 @@ </delete> <copy file="${jdt.jar}" todir="${tomcat.build}/lib"/> + <!-- Delete all other versions of Tomcat Migration Tool for Jakarta EE and copy the current one --> + <local name="migration.jar.filename" /> + <basename property="migration.jar.filename" file="${migration-lib.jar}"/> + <delete verbose="true"> + <fileset dir="${tomcat.build}/lib"> + <include name="jakartaee-migration-*.jar"/> + <exclude name="${migration-lib.jar.filename}"/> + </fileset> + </delete> + <copy file="${migration-lib.jar}" todir="${tomcat.build}/lib"/> + <!-- Add sources for examples --> <antcall target="examples-sources" /> </target> @@ -3125,6 +3137,16 @@ skip.installer property in build.properties" /> <param name="checksum.value" value="${wsdl4j-lib.checksum.value}"/> </antcall> + <!-- Tomcat Migration Tool for Jakarta EE --> + <antcall target="downloadfile"> + <param name="sourcefile" value="${migration-lib.loc}"/> + <param name="destfile" value="${migration-lib.jar}"/> + <param name="destdir" value="${migration-lib.home}"/> + <param name="checksum.enabled" value="${migration-lib.checksum.enabled}"/> + <param name="checksum.algorithm" value="${migration-lib.checksum.algorithm}"/> + <param name="checksum.value" value="${migration-lib.checksum.value}"/> + </antcall> + </target> <target name="download-test-compile" diff --git a/conf/catalina.properties b/conf/catalina.properties index cff2aa2..012d8fd 100644 --- a/conf/catalina.properties +++ b/conf/catalina.properties @@ -144,6 +144,7 @@ hamcrest-*.jar,\ hibernate*.jar,\ httpclient*.jar,\ icu4j-*.jar,\ +jakartaee-migration-*.jar,\ jasper-el.jar,\ jasper.jar,\ jaspic-api.jar,\ diff --git a/java/org/apache/catalina/startup/HostConfig.java b/java/org/apache/catalina/startup/HostConfig.java index 2079117..1aac2df 100644 --- a/java/org/apache/catalina/startup/HostConfig.java +++ b/java/org/apache/catalina/startup/HostConfig.java @@ -68,6 +68,7 @@ import org.apache.catalina.util.ContextName; import org.apache.catalina.util.IOTools; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.jakartaee.Migration; import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.buf.UriUtil; import org.apache.tomcat.util.digester.Digester; @@ -465,6 +466,8 @@ public class HostConfig implements LifecycleListener { * in our "application root" directory. */ protected void deployApps() { + // Migrate legacy Java EE apps from legacyAppBase + migrateLegacyApps(); File appBase = host.getAppBaseFile(); File configBase = host.getConfigBaseFile(); String[] filteredAppPaths = filterAppPaths(appBase.list()); @@ -1224,6 +1227,87 @@ public class HostConfig implements LifecycleListener { } + protected void migrateLegacyApps() { + File appBase = host.getAppBaseFile(); + File legacyAppBase = host.getLegacyAppBaseFile(); + if (!legacyAppBase.isDirectory()) { + return; + } + + ExecutorService es = host.getStartStopExecutor(); + List<Future<?>> results = new ArrayList<>(); + + String[] migrationCandidates = legacyAppBase.list(); + for (String migrationCandidate : migrationCandidates) { + File source = new File(legacyAppBase, migrationCandidate); + File destination = new File(appBase, migrationCandidate); + + ContextName cn; + if (source.lastModified() > destination.lastModified()) { + if (source.isFile() && source.getName().toLowerCase(Locale.ENGLISH).endsWith(".war")) { + cn = new ContextName(migrationCandidate, true); + } else if (source.isDirectory()) { + cn = new ContextName(migrationCandidate, false); + } else { + continue; + } + + if (tryAddServiced(cn.getBaseName())) { + try { + // MigrateApp will call removeServiced + results.add(es.submit(new MigrateApp(this, cn, source, destination))); + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + removeServiced(cn.getName()); + throw t; + } + } + } + } + + for (Future<?> result : results) { + try { + result.get(); + } catch (Exception e) { + log.error(sm.getString("hostConfig.migrateApp.threaded.error"), e); + } + } + } + + + protected void migrateLegacyApp(File source, File destination) { + File tempNew = null; + File tempOld = null; + try { + tempNew = File.createTempFile("new", null, host.getLegacyAppBaseFile()); + tempOld = File.createTempFile("old", null, host.getLegacyAppBaseFile()); + + // The use of defaults is deliberate here to avoid having to + // recreate every configuration option on the host. Better to change + // the defaults if necessary than to start adding configuration + // options. Users that need non-default options can convert manually + // via migration.[sh|bat] + Migration migration = new Migration(); + migration.setSource(source); + migration.setDestination(tempNew); + migration.execute(); + + // Use rename + destination.renameTo(tempOld); + tempNew.renameTo(destination); + ExpandWar.delete(tempOld); + + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + log.warn("Migration failure", t); + } finally { + if (tempNew != null && tempNew.exists()) { + ExpandWar.delete(tempNew); + } + } + } + + /** * Check if a webapp is already deployed in this host. * @@ -1930,6 +2014,31 @@ public class HostConfig implements LifecycleListener { } + private static class MigrateApp implements Runnable { + + private HostConfig config; + private ContextName cn; + private File source; + private File destination; + + public MigrateApp(HostConfig config, ContextName cn, File source, File destination) { + this.config = config; + this.cn = cn; + this.source = source; + this.destination = destination; + } + + @Override + public void run() { + try { + config.migrateLegacyApp(source, destination); + } finally { + config.removeServiced(cn.getName()); + } + } + } + + /* * The purpose of this class is to provide a way for HostConfig to get * a Context to delete an expanded WAR after the Context stops. This is to diff --git a/java/org/apache/catalina/startup/LocalStrings.properties b/java/org/apache/catalina/startup/LocalStrings.properties index 27c7c9b..e31a53f 100644 --- a/java/org/apache/catalina/startup/LocalStrings.properties +++ b/java/org/apache/catalina/startup/LocalStrings.properties @@ -136,6 +136,7 @@ hostConfig.ignorePath=Ignoring path [{0}] in appBase for automatic deployment hostConfig.illegalWarName=The war name [{0}] is invalid. The archive will be ignored. hostConfig.jmx.register=Register context [{0}] failed hostConfig.jmx.unregister=Unregister context [{0}] failed +hostConfig.migrateApp.threaded.error=Error waiting for multi-thread migration of legacy applications to complete hostConfig.reload=Reloading context [{0}] hostConfig.resourceNotAbsolute=Unable to remove resource from context [{0}] since [{1}] is not an absolute path hostConfig.start=HostConfig: Processing START diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6a2b77e..0d19158 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -121,12 +121,19 @@ of use in JMX descriptors. (remm) </fix> <update> - Allow the loader to directly use the JakartaEE migration tool as a - <code>ClassFileTransformer</code> using the + Allow the loader to directly use the Tomcat Migration Tool for JakartaEE + as a <code>ClassFileTransformer</code> using the <code>jakartaConverter</code> attribute. This only supports javax to jakarta conversion for classes, not for classloader resources or static files. (remm) </update> + <add> + Integrate the Tomcat Migration Tool for JakartaEE at deployment time. + Java EE web applications placed in the <code>webapps-ee</code> directory + will be migrated to Jakarta EE 9 and placed in the <code>webapps</code> + where it will be deployed (or not) based on the current settings for + automatic deployment. (markt) + </add> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
On 18/02/2021 20:56, [hidden email] wrote:
> This is an automated email from the ASF dual-hosted git repository. > > markt pushed a commit to branch master > in repository https://gitbox.apache.org/repos/asf/tomcat.git > > commit e08dbf4559da7612c4060b68dfee8ce03560ce07 > Author: Mark Thomas <[hidden email]> > AuthorDate: Thu Feb 11 17:13:52 2021 +0000 > > Integrate Java EE -> Jakarta EE migration with automatic deployment Functionally, I think this is there. What is lacking is documentatoion. I plan to work on that over the next few days. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Free forum by Nabble | Edit this page |