use of org.codelibs.fess.exception.PluginException in project fess by codelibs.
the class PluginHelper method install.
protected void install(final Artifact artifact) {
final String fileName = artifact.getFileName();
final String url = artifact.getUrl();
if (StringUtil.isBlank(url)) {
throw new PluginException("url is blank: " + artifact.getName());
}
if (url.startsWith("http:") || url.startsWith("https:")) {
try (final CurlResponse response = createCurlRequest(url).execute()) {
if (response.getHttpStatusCode() != 200) {
throw new PluginException("HTTP Status " + response.getHttpStatusCode() + " : failed to get the artifact from " + url);
}
try (final InputStream in = response.getContentAsStream()) {
CopyUtil.copy(in, ResourceUtil.getPluginPath(fileName).toFile());
}
} catch (final Exception e) {
throw new PluginException("Failed to install the artifact " + artifact.getName(), e);
}
} else {
try (final InputStream in = new FileInputStream(url)) {
CopyUtil.copy(in, ResourceUtil.getPluginPath(fileName).toFile());
} catch (final Exception e) {
throw new PluginException("Failed to install the artifact " + artifact.getName(), e);
}
}
}
use of org.codelibs.fess.exception.PluginException in project fess by codelibs.
the class PluginHelper method deleteInstalledArtifact.
public void deleteInstalledArtifact(final Artifact artifact) {
final String fileName = artifact.getFileName();
final Path jarPath = Paths.get(ResourceUtil.getPluginPath().toString(), fileName);
if (!Files.exists(jarPath)) {
throw new PluginException(fileName + " does not exist.");
}
switch(artifact.getType()) {
case THEME:
ComponentUtil.getThemeHelper().uninstall(artifact);
uninstall(fileName, jarPath);
break;
default:
uninstall(fileName, jarPath);
break;
}
}
use of org.codelibs.fess.exception.PluginException in project fess by codelibs.
the class PluginHelper method loadArtifactsFromRepository.
protected List<Artifact> loadArtifactsFromRepository(final String url) {
final String content = getRepositoryContent(url);
final ObjectMapper objectMapper = new YAMLMapper();
try {
@SuppressWarnings("unchecked") final List<Map<?, ?>> result = objectMapper.readValue(content, List.class);
if (result != null) {
return result.stream().map(o -> new Artifact((String) o.get("name"), (String) o.get("version"), (String) o.get("url"))).collect(Collectors.toList());
}
return Collections.emptyList();
} catch (final Exception e) {
throw new PluginException("Failed to access " + url, e);
}
}
Aggregations