use of io.jenkins.blueocean.rest.model.BlueExtensionClassContainer in project blueocean-plugin by jenkinsci.
the class JenkinsJSExtensions method refreshCache.
private static synchronized void refreshCache(List<PluginWrapper> latestPlugins) {
if (!latestPlugins.equals(pluginCache)) {
pluginCache.clear();
pluginCache.addAll(latestPlugins);
refreshCache(pluginCache);
}
for (PluginWrapper pluginWrapper : pluginCache) {
//skip if not active
if (!pluginWrapper.isActive()) {
continue;
}
//skip probing plugin if already read
if (jsExtensionCache.get(pluginWrapper.getLongName()) != null) {
continue;
}
try {
Enumeration<URL> dataResources = pluginWrapper.classLoader.getResources("jenkins-js-extension.json");
boolean hasDefinedExtensions = false;
while (dataResources.hasMoreElements()) {
URL dataRes = dataResources.nextElement();
LOGGER.debug("Reading 'jenkins-js-extension.json' from '{}'.", dataRes);
try (InputStream dataResStream = dataRes.openStream()) {
Map<String, Object> extensionData = mapper.readValue(dataResStream, Map.class);
String pluginId = getGav(extensionData);
if (pluginId != null) {
// future/past iteration of this loop.
if (!pluginId.equals(pluginWrapper.getShortName())) {
continue;
}
} else {
LOGGER.error(String.format("Plugin %s JS extension has missing hpiPluginId", pluginWrapper.getLongName()));
continue;
}
List<Map> extensions = (List<Map>) extensionData.get(PLUGIN_EXT);
if (extensions != null) {
for (Map extension : extensions) {
try {
String type = (String) extension.get("type");
if (type != null) {
BlueExtensionClassContainer extensionClassContainer = Jenkins.getInstance().getExtensionList(BlueExtensionClassContainer.class).get(0);
Map classInfo = (Map) mergeObjects(extensionClassContainer.get(type));
List classInfoClasses = (List) classInfo.get("_classes");
classInfoClasses.add(0, type);
extension.put("_class", type);
extension.put("_classes", classInfoClasses);
}
} catch (Exception e) {
LOGGER.error("An error occurred when attempting to read type information from jenkins-js-extension.json from: " + dataRes, e);
}
}
}
extensionData.put(PLUGIN_VER, pluginWrapper.getVersion());
jsExtensionCache.put(pluginId, mergeObjects(extensionData));
hasDefinedExtensions = true;
}
}
if (!hasDefinedExtensions) {
// Manufacture an entry for all plugins that do not have any defined
// extensions. This adds some info about the plugin that the UI might
// need access to e.g. the plugin version.
Map<String, Object> extensionData = new LinkedHashMap<>();
extensionData.put(PLUGIN_ID, pluginWrapper.getShortName());
extensionData.put(PLUGIN_VER, pluginWrapper.getVersion());
extensionData.put(PLUGIN_EXT, Collections.emptyList());
jsExtensionCache.put(pluginWrapper.getShortName(), mergeObjects(extensionData));
}
} catch (IOException e) {
LOGGER.error(String.format("Error locating jenkins-js-extension.json for plugin %s", pluginWrapper.getLongName()));
}
}
}
Aggregations