fix #2210 add plugin.version.filter

This commit is contained in:
Shinsuke Sugaya 2019-08-17 15:13:31 +09:00
parent 23ba279574
commit 927aee3828
6 changed files with 67 additions and 11 deletions

View file

@ -59,7 +59,7 @@ public class PluginHelper {
private static final Logger logger = LoggerFactory.getLogger(PluginHelper.class);
protected LoadingCache<ArtifactType, Artifact[]> availableArtifacts = CacheBuilder.newBuilder().maximumSize(10)
.expireAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader<ArtifactType, Artifact[]>() {
.expireAfterWrite(5, TimeUnit.MINUTES).build(new CacheLoader<ArtifactType, Artifact[]>() {
public Artifact[] load(ArtifactType key) {
final List<Artifact> 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()]);
}

View file

@ -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)

View file

@ -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'. <br>
* The value is, e.g. <br>
* @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}. <br>
* The value is, e.g. <br>
* @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<String, String> prepareGeneratedDefaultMap() {
java.util.Map<String, String> 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");

View file

@ -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();
}
}

View file

@ -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=

View file

@ -56,6 +56,10 @@ public class PluginHelperTest extends UnitFessTestCase {
}
throw new FessSystemException("unknown");
}
protected boolean isTargetPluginVersion(final String version) {
return true;
}
};
}