Search in sources :

Example 1 with ThemePropertyMissingException

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);
    }
}
Also used : ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) ZipInputStream(java.util.zip.ZipInputStream) IOException(java.io.IOException)

Example 2 with ThemePropertyMissingException

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);
    }
}
Also used : ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) IOException(java.io.IOException)

Example 3 with ThemePropertyMissingException

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);
    }
}
Also used : ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) ZipInputStream(java.util.zip.ZipInputStream) IOException(java.io.IOException)

Example 4 with ThemePropertyMissingException

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);
    }
}
Also used : ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) IOException(java.io.IOException)

Example 5 with ThemePropertyMissingException

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);
    }
}
Also used : ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) ServiceException(run.halo.app.exception.ServiceException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)9 ThemePropertyMissingException (run.halo.app.exception.ThemePropertyMissingException)9 ZipInputStream (java.util.zip.ZipInputStream)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ref (org.eclipse.jgit.lib.Ref)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 ServiceException (run.halo.app.exception.ServiceException)3