fix #2474 load jar file on web app
This commit is contained in:
parent
60f5732278
commit
49fe8c0cec
3 changed files with 83 additions and 12 deletions
|
@ -19,10 +19,12 @@ package org.codelibs.fess;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.Host;
|
||||
import org.apache.catalina.core.StandardHost;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.tomcat.valve.SuppressErrorReportValve;
|
||||
import org.codelibs.fess.tomcat.webresources.FessWebResourceRoot;
|
||||
import org.dbflute.tomcat.TomcatBoot;
|
||||
|
||||
public class FessBoot extends TomcatBoot {
|
||||
|
@ -125,4 +127,10 @@ public class FessBoot extends TomcatBoot {
|
|||
protected static String getTomcatConfigPath() {
|
||||
return System.getProperty(TOMCAT_CONFIG_PATH);
|
||||
}
|
||||
|
||||
protected void setupWebappContext() {
|
||||
super.setupWebappContext();
|
||||
Context context = (Context) server.getHost().findChild(StringUtil.EMPTY);
|
||||
context.setResources(new FessWebResourceRoot(context));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,6 +242,18 @@ public class PluginHelper {
|
|||
}
|
||||
|
||||
public void installArtifact(final Artifact artifact) {
|
||||
switch (artifact.getType()) {
|
||||
case THEME:
|
||||
install(artifact);
|
||||
ComponentUtil.getThemeHelper().install(artifact);
|
||||
break;
|
||||
default:
|
||||
install(artifact);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void install(final Artifact artifact) {
|
||||
final String fileName = artifact.getFileName();
|
||||
final String url = artifact.getUrl();
|
||||
if (StringUtil.isBlank(url)) {
|
||||
|
@ -264,16 +276,6 @@ public class PluginHelper {
|
|||
throw new PluginException("Failed to install the artifact " + artifact.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
switch (artifact.getType()) {
|
||||
case DATA_STORE:
|
||||
break;
|
||||
case THEME:
|
||||
ComponentUtil.getThemeHelper().install(artifact);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected CurlRequest createCurlRequest(final String url) {
|
||||
|
@ -293,15 +295,18 @@ public class PluginHelper {
|
|||
}
|
||||
|
||||
switch (artifact.getType()) {
|
||||
case DATA_STORE:
|
||||
break;
|
||||
case THEME:
|
||||
ComponentUtil.getThemeHelper().uninstall(artifact);
|
||||
uninstall(fileName, jarPath);
|
||||
break;
|
||||
default:
|
||||
uninstall(fileName, jarPath);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void uninstall(final String fileName, final Path jarPath) {
|
||||
try {
|
||||
Files.delete(jarPath);
|
||||
} catch (final IOException e) {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2012-2020 CodeLibs Project and the Others.
|
||||
*
|
||||
* 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.codelibs.fess.tomcat.webresources;
|
||||
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.WebResource;
|
||||
import org.apache.catalina.webresources.StandardRoot;
|
||||
import org.codelibs.core.jar.JarFileUtil;
|
||||
|
||||
public class FessWebResourceRoot extends StandardRoot {
|
||||
private static final Logger logger = Logger.getLogger(FessWebResourceRoot.class.getName());
|
||||
|
||||
public FessWebResourceRoot(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
protected void processWebInfLib() throws LifecycleException {
|
||||
super.processWebInfLib();
|
||||
|
||||
WebResource[] possibleJars = listResources("/WEB-INF/plugin", false);
|
||||
|
||||
for (WebResource possibleJar : possibleJars) {
|
||||
if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
|
||||
try (final JarFile jarFile = JarFileUtil.create(possibleJar.getCanonicalPath())) {
|
||||
final Manifest manifest = jarFile.getManifest();
|
||||
if (manifest != null && manifest.getEntries() != null) {
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
if (attributes != null && attributes.get("Fess-WebAppJar") != null) {
|
||||
createWebResourceSet(ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", possibleJar.getURL(), "/");
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.log(Level.WARNING, "Failed to read " + possibleJar, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue