use of run.halo.app.exception.ThemePropertyMissingException in project halo by halo-dev.
the class ZipThemeFetcher method fetch.
@Override
public ThemeProperty fetch(Object source) {
final var themeZipLink = source.toString();
// build http request
final var request = HttpRequest.newBuilder().uri(URI.create(themeZipLink)).timeout(Duration.ofMinutes(2)).GET().build();
try {
// request from remote
log.info("Fetching theme from {}", themeZipLink);
var inputStreamResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
var inputStream = inputStreamResponse.body();
// unzip zip archive
try (var zipInputStream = new ZipInputStream(inputStream)) {
var tempDirectory = FileUtils.createTempDirectory();
log.info("Unzipping theme {} to {}", themeZipLink, tempDirectory);
unzip(zipInputStream, tempDirectory);
// resolve theme property
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(tempDirectory).orElseThrow(() -> new ThemePropertyMissingException("主题配置文件缺失!请确认后重试。"));
}
} catch (InterruptedException | IOException e) {
throw new RuntimeException("主题拉取失败!(" + e.getMessage() + ")", e);
}
}
use of run.halo.app.exception.ThemePropertyMissingException in project halo-plugin-experimental by guqing.
the class GitThemeFetcher method fetch.
@Override
public ThemeProperty fetch(Object source) {
final var repoUrl = source.toString();
try {
// create temp folder
final var tempDirectory = FileUtils.createTempDirectory();
// clone from git
log.info("Cloning git repo {} to {}", repoUrl, tempDirectory);
try (final var git = Git.cloneRepository().setTagOption(TagOpt.FETCH_TAGS).setNoCheckout(false).setDirectory(tempDirectory.toFile()).setCloneSubmodules(false).setURI(repoUrl).setRemote("upstream").call()) {
log.info("Cloned git repo {} to {} successfully", repoUrl, tempDirectory);
// find latest tag
final var latestTag = GitUtils.getLatestTag(git);
final var checkoutCommand = git.checkout().setName("halo").setCreateBranch(true);
if (latestTag != null) {
// checkout latest tag
checkoutCommand.setStartPoint(latestTag.getValue());
}
Ref haloBranch = checkoutCommand.call();
log.info("Checkout branch: {}", haloBranch.getName());
}
// locate theme property location
var themePropertyPath = ThemeMetaLocator.INSTANCE.locateProperty(tempDirectory).orElseThrow(() -> new ThemePropertyMissingException("主题配置文件缺失,请确认后重试!"));
// fetch property
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(themePropertyPath.getParent()).orElseThrow();
} catch (IOException | GitAPIException e) {
throw new RuntimeException("主题拉取失败!(" + e.getMessage() + ")", e);
}
}
use of run.halo.app.exception.ThemePropertyMissingException in project halo-plugin-experimental by guqing.
the class ZipThemeFetcher method fetch.
@Override
public ThemeProperty fetch(Object source) {
final var themeZipLink = source.toString();
// build http request
final var request = HttpRequest.newBuilder().uri(URI.create(themeZipLink)).timeout(Duration.ofMinutes(2)).GET().build();
try {
// request from remote
log.info("Fetching theme from {}", themeZipLink);
var inputStreamResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
var inputStream = inputStreamResponse.body();
// unzip zip archive
try (var zipInputStream = new ZipInputStream(inputStream)) {
var tempDirectory = FileUtils.createTempDirectory();
log.info("Unzipping theme {} to {}", themeZipLink, tempDirectory);
unzip(zipInputStream, tempDirectory);
// resolve theme property
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(tempDirectory).orElseThrow(() -> new ThemePropertyMissingException("主题配置文件缺失!请确认后重试。"));
}
} catch (InterruptedException | IOException e) {
throw new RuntimeException("主题拉取失败!(" + e.getMessage() + ")", e);
}
}
use of run.halo.app.exception.ThemePropertyMissingException in project halo by ruibaby.
the class GitThemeFetcher method fetch.
@Override
public ThemeProperty fetch(Object source) {
final var repoUrl = source.toString();
try {
// create temp folder
final var tempDirectory = FileUtils.createTempDirectory();
// clone from git
log.info("Cloning git repo {} to {}", repoUrl, tempDirectory);
try (final var git = Git.cloneRepository().setTagOption(TagOpt.FETCH_TAGS).setNoCheckout(false).setDirectory(tempDirectory.toFile()).setCloneSubmodules(false).setURI(repoUrl).setRemote("upstream").call()) {
log.info("Cloned git repo {} to {} successfully", repoUrl, tempDirectory);
// find latest tag
final var latestTag = GitUtils.getLatestTag(git);
final var checkoutCommand = git.checkout().setName("halo").setCreateBranch(true);
if (latestTag != null) {
// checkout latest tag
checkoutCommand.setStartPoint(latestTag.getValue());
}
Ref haloBranch = checkoutCommand.call();
log.info("Checkout branch: {}", haloBranch.getName());
}
// locate theme property location
var themePropertyPath = ThemeMetaLocator.INSTANCE.locateProperty(tempDirectory).orElseThrow(() -> new ThemePropertyMissingException("主题配置文件缺失,请确认后重试!"));
// fetch property
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(themePropertyPath.getParent()).orElseThrow();
} catch (IOException | GitAPIException e) {
throw new RuntimeException("主题拉取失败!(" + e.getMessage() + ")", e);
}
}
use of run.halo.app.exception.ThemePropertyMissingException in project halo by ruibaby.
the class MultipartZipFileThemeFetcher method fetch.
@Override
public ThemeProperty fetch(Object source) {
final var file = (MultipartFile) source;
try (var zis = new ZipInputStream(file.getInputStream())) {
final var tempDirectory = FileUtils.createTempDirectory();
log.info("Unzipping {} to path {}", file.getOriginalFilename(), tempDirectory);
unzip(zis, tempDirectory);
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(tempDirectory).orElseThrow(() -> new ThemePropertyMissingException("主题配置文件缺失!请确认后重试。"));
} catch (IOException e) {
throw new ServiceException("主题上传失败!", e);
}
}
Aggregations