diff --git a/src/main/java/org/codelibs/fess/helper/PluginHelper.java b/src/main/java/org/codelibs/fess/helper/PluginHelper.java index 303432826..e106034c7 100644 --- a/src/main/java/org/codelibs/fess/helper/PluginHelper.java +++ b/src/main/java/org/codelibs/fess/helper/PluginHelper.java @@ -59,7 +59,7 @@ public class PluginHelper { private static final Logger logger = LoggerFactory.getLogger(PluginHelper.class); protected LoadingCache availableArtifacts = CacheBuilder.newBuilder().maximumSize(10) - .expireAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader() { + .expireAfterWrite(5, TimeUnit.MINUTES).build(new CacheLoader() { public Artifact[] load(ArtifactType key) { final List list = new ArrayList<>(); for (final String url : getRepositories()) { @@ -98,16 +98,20 @@ public class PluginHelper { final NodeList nodeList = document.getElementsByTagName("version"); for (int i = 0; i < nodeList.getLength(); i++) { final String version = nodeList.item(i).getTextContent(); - if (version.endsWith("SNAPSHOT")) { - final String snapshotVersion = getSnapshotActualVersion(builder, pluginUrl, version); - if (StringUtil.isNotBlank(snapshotVersion)) { - String actualVersion = version.replace("SNAPSHOT", snapshotVersion); - list.add(new Artifact(name, actualVersion, pluginUrl + version + "/" + name + "-" + actualVersion + ".jar")); - } else if (logger.isDebugEnabled()) { - logger.debug("Snapshot name is not found: " + name + "/" + version); + if (isTargetPluginVersion(version)) { + if (version.endsWith("SNAPSHOT")) { + final String snapshotVersion = getSnapshotActualVersion(builder, pluginUrl, version); + if (StringUtil.isNotBlank(snapshotVersion)) { + String actualVersion = version.replace("SNAPSHOT", snapshotVersion); + list.add(new Artifact(name, actualVersion, pluginUrl + version + "/" + name + "-" + actualVersion + ".jar")); + } else if (logger.isDebugEnabled()) { + logger.debug("Snapshot name is not found: " + name + "/" + version); + } + } else { + list.add(new Artifact(name, version, pluginUrl + version + "/" + name + "-" + version + ".jar")); } - } else { - list.add(new Artifact(name, version, pluginUrl + version + "/" + name + "-" + version + ".jar")); + } else if (logger.isDebugEnabled()) { + logger.debug(name + ":" + version + " is ignored."); } } } catch (final Exception e) { @@ -117,6 +121,10 @@ public class PluginHelper { return list; } + protected boolean isTargetPluginVersion(final String version) { + return ComponentUtil.getFessConfig().isTargetPluginVersion(version); + } + protected String getSnapshotActualVersion(final DocumentBuilder builder, final String pluginUrl, final String version) throws SAXException, IOException { String timestamp = null; @@ -144,6 +152,9 @@ public class PluginHelper { } protected String getRepositoryContent(final String url) { + if (logger.isDebugEnabled()) { + logger.debug("Loading " + url); + } try (final CurlResponse response = Curl.get(url).execute()) { return response.getContentAsString(); } catch (final IOException e) { @@ -157,6 +168,7 @@ public class PluginHelper { for (final File file : jarFiles) { list.add(getArtifactFromFileName(artifactType, file.getName())); } + list.sort((a, b) -> a.getName().compareTo(b.getName())); return list.toArray(new Artifact[list.size()]); } diff --git a/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java b/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java index c62110c19..adec89c36 100644 --- a/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java +++ b/src/main/java/org/codelibs/fess/mylasta/action/FessLabels.java @@ -2978,7 +2978,7 @@ public class FessLabels extends UserMessages { /** The key of the message: Install */ public static final String LABELS_crud_button_install = "{labels.crud_button_install}"; - + /** * Assert the property is not null. * @param property The value of the property. (NotNull) diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java index 81657a1cc..e479e3de1 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java @@ -1433,6 +1433,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** The key of the configuration. e.g. https://repo.maven.apache.org/maven2/org/codelibs/fess/,https://oss.sonatype.org/content/repositories/snapshots/org/codelibs/fess/ */ String PLUGIN_REPOSITORIES = "plugin.repositories"; + /** The key of the configuration. e.g. */ + String PLUGIN_VERSION_FILTER = "plugin.version.filter"; + /** * Get the value of property as {@link String}. * @param propertyKey The key of the property. (NotNull) @@ -5942,6 +5945,21 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction */ String getPluginRepositories(); + /** + * Get the value for the key 'plugin.version.filter'.
+ * The value is, e.g.
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getPluginVersionFilter(); + + /** + * Get the value for the key 'plugin.version.filter' as {@link Integer}.
+ * The value is, e.g.
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + * @throws NumberFormatException When the property is not integer. + */ + Integer getPluginVersionFilterAsInteger(); + /** * The simple implementation for configuration. * @author FreeGen @@ -8315,6 +8333,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction return get(FessConfig.PLUGIN_REPOSITORIES); } + public String getPluginVersionFilter() { + return get(FessConfig.PLUGIN_VERSION_FILTER); + } + + public Integer getPluginVersionFilterAsInteger() { + return getAsInteger(FessConfig.PLUGIN_VERSION_FILTER); + } + @Override protected java.util.Map prepareGeneratedDefaultMap() { java.util.Map defaultMap = super.prepareGeneratedDefaultMap(); @@ -8752,6 +8778,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction defaultMap .put(FessConfig.PLUGIN_REPOSITORIES, "https://repo.maven.apache.org/maven2/org/codelibs/fess/,https://oss.sonatype.org/content/repositories/snapshots/org/codelibs/fess/"); + defaultMap.put(FessConfig.PLUGIN_VERSION_FILTER, ""); defaultMap.put(FessConfig.lasta_di_SMART_DEPLOY_MODE, "hot"); defaultMap.put(FessConfig.DEVELOPMENT_HERE, "true"); defaultMap.put(FessConfig.ENVIRONMENT_TITLE, "Local Development"); diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java index eb8452cb5..e75d55da3 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java @@ -2010,4 +2010,16 @@ public interface FessProp { } return Runtime.getRuntime().availableProcessors(); } + + String getPluginVersionFilter(); + + default boolean isTargetPluginVersion(final String version) { + final Pattern pattern; + if (StringUtil.isBlank(getPluginVersionFilter())) { + pattern = Pattern.compile("^" + Pattern.quote(ComponentUtil.getSystemHelper().getProductVersion()) + ".*"); + } else { + pattern = Pattern.compile(getPluginVersionFilter()); + } + return pattern.matcher(version).matches(); + } } diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index 0248e1890..bd4ab05ed 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -706,3 +706,4 @@ ldap.attr.homeDirectory=homeDirectory # Scheduler # ------ plugin.repositories=https://repo.maven.apache.org/maven2/org/codelibs/fess/,https://oss.sonatype.org/content/repositories/snapshots/org/codelibs/fess/ +plugin.version.filter= diff --git a/src/test/java/org/codelibs/fess/helper/PluginHelperTest.java b/src/test/java/org/codelibs/fess/helper/PluginHelperTest.java index 15eeed478..a5f80ece6 100644 --- a/src/test/java/org/codelibs/fess/helper/PluginHelperTest.java +++ b/src/test/java/org/codelibs/fess/helper/PluginHelperTest.java @@ -56,6 +56,10 @@ public class PluginHelperTest extends UnitFessTestCase { } throw new FessSystemException("unknown"); } + + protected boolean isTargetPluginVersion(final String version) { + return true; + } }; }