Search in sources :

Example 1 with ThemeUpdateException

use of run.halo.app.exception.ThemeUpdateException in project halo by halo-dev.

the class ThemeServiceImpl method update.

@Override
public ThemeProperty update(String themeId) {
    final var themeUpdater = new GitThemeUpdater(themeRepository, fetcherComposite);
    Assert.hasText(themeId, "Theme id must not be blank");
    try {
        final var themeProperty = themeUpdater.update(themeId);
    } catch (Exception e) {
        if (e instanceof ThemeNotSupportException) {
            throw (ThemeNotSupportException) e;
        }
        throw new ThemeUpdateException("主题更新失败!", e).setErrorData(themeId);
    }
    eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
    return getThemeOfNonNullBy(themeId);
}
Also used : ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) ThemeNotSupportException(run.halo.app.exception.ThemeNotSupportException) GitThemeUpdater(run.halo.app.theme.GitThemeUpdater) ThemeUpdatedEvent(run.halo.app.event.theme.ThemeUpdatedEvent) NotFoundException(run.halo.app.exception.NotFoundException) ServiceException(run.halo.app.exception.ServiceException) ThemeNotFoundException(run.halo.app.exception.ThemeNotFoundException) ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) ThemeNotSupportException(run.halo.app.exception.ThemeNotSupportException) ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) IOException(java.io.IOException) ForbiddenException(run.halo.app.exception.ForbiddenException) BadRequestException(run.halo.app.exception.BadRequestException)

Example 2 with ThemeUpdateException

use of run.halo.app.exception.ThemeUpdateException in project halo-plugin-experimental by guqing.

the class GitThemeUpdater method merge.

public ThemeProperty merge(ThemeProperty oldThemeProperty, ThemeProperty newThemeProperty) throws IOException {
    final var oldThemePath = Paths.get(oldThemeProperty.getThemePath());
    // open old git repo
    try (final var oldGit = Git.init().setDirectory(oldThemePath.toFile()).call()) {
        // 0. commit old repo
        commitAutomatically(oldGit);
        final var newThemePath = Paths.get(newThemeProperty.getThemePath());
        // trying to open new git repo
        try (final var ignored = Git.open(newThemePath.toFile())) {
            // remove remote
            removeRemoteIfExists(oldGit, "newTheme");
            // add this new git to remote for old repo
            final var addedRemoteConfig = oldGit.remoteAdd().setName("newTheme").setUri(new URIish(newThemePath.toString())).call();
            log.info("git remote add newTheme {} {}", addedRemoteConfig.getName(), addedRemoteConfig.getURIs());
            // fetch remote data
            final var remote = "newTheme/halo";
            log.info("git fetch newTheme/halo");
            final var fetchResult = oldGit.fetch().setRemote("newTheme").call();
            log.info("Fetch result: {}", fetchResult.getMessages());
            // rebase upstream
            log.info("git rebase newTheme");
            final var rebaseResult = oldGit.rebase().setUpstream(remote).call();
            log.info("Rebase result: {}", rebaseResult.getStatus());
            logCommit(rebaseResult.getCurrentCommit());
            // check rebase result
            if (!rebaseResult.getStatus().isSuccessful()) {
                if (oldGit.getRepository().getRepositoryState() != RepositoryState.SAFE) {
                    // if rebasing stopped or failed, you can get back to the original state by
                    // running it
                    // with setOperation(RebaseCommand.Operation.ABORT)
                    final var abortRebaseResult = oldGit.rebase().setUpstream(remote).setOperation(RebaseCommand.Operation.ABORT).call();
                    log.error("Aborted rebase with state: {} : {}", abortRebaseResult.getStatus(), abortRebaseResult.getConflicts());
                }
                throw new ThemeUpdateException("无法自动合并最新文件!请尝试删除主题并重新拉取。");
            }
        }
    } catch (URISyntaxException | GitAPIException e) {
        throw new ServiceException("合并主题失败!请确认该主题支持在线更新。", e);
    }
    return newThemeProperty;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ServiceException(run.halo.app.exception.ServiceException) URISyntaxException(java.net.URISyntaxException)

Example 3 with ThemeUpdateException

use of run.halo.app.exception.ThemeUpdateException in project halo-plugin-experimental by guqing.

the class ThemeServiceImpl method update.

@Override
public ThemeProperty update(String themeId) {
    final var themeUpdater = new GitThemeUpdater(themeRepository, fetcherComposite);
    Assert.hasText(themeId, "Theme id must not be blank");
    try {
        final var themeProperty = themeUpdater.update(themeId);
    } catch (Exception e) {
        if (e instanceof ThemeNotSupportException) {
            throw (ThemeNotSupportException) e;
        }
        throw new ThemeUpdateException("主题更新失败!", e).setErrorData(themeId);
    }
    eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
    return getThemeOfNonNullBy(themeId);
}
Also used : ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) ThemeNotSupportException(run.halo.app.exception.ThemeNotSupportException) GitThemeUpdater(run.halo.app.theme.GitThemeUpdater) ThemeUpdatedEvent(run.halo.app.event.theme.ThemeUpdatedEvent) ThemeNotFoundException(run.halo.app.exception.ThemeNotFoundException) NotFoundException(run.halo.app.exception.NotFoundException) ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) ThemeNotSupportException(run.halo.app.exception.ThemeNotSupportException) ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) IOException(java.io.IOException) ForbiddenException(run.halo.app.exception.ForbiddenException) BadRequestException(run.halo.app.exception.BadRequestException) ServiceException(run.halo.app.exception.ServiceException)

Example 4 with ThemeUpdateException

use of run.halo.app.exception.ThemeUpdateException in project halo by ruibaby.

the class ThemeServiceImpl method update.

@Override
public ThemeProperty update(String themeId) {
    final var themeUpdater = new GitThemeUpdater(themeRepository, fetcherComposite);
    Assert.hasText(themeId, "Theme id must not be blank");
    try {
        final var themeProperty = themeUpdater.update(themeId);
    } catch (Exception e) {
        if (e instanceof ThemeNotSupportException) {
            throw (ThemeNotSupportException) e;
        }
        throw new ThemeUpdateException("主题更新失败!", e).setErrorData(themeId);
    }
    eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
    return getThemeOfNonNullBy(themeId);
}
Also used : ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) ThemeNotSupportException(run.halo.app.exception.ThemeNotSupportException) GitThemeUpdater(run.halo.app.theme.GitThemeUpdater) ThemeUpdatedEvent(run.halo.app.event.theme.ThemeUpdatedEvent) NotFoundException(run.halo.app.exception.NotFoundException) ServiceException(run.halo.app.exception.ServiceException) ThemeNotFoundException(run.halo.app.exception.ThemeNotFoundException) ThemePropertyMissingException(run.halo.app.exception.ThemePropertyMissingException) ThemeNotSupportException(run.halo.app.exception.ThemeNotSupportException) ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) IOException(java.io.IOException) ForbiddenException(run.halo.app.exception.ForbiddenException) BadRequestException(run.halo.app.exception.BadRequestException)

Example 5 with ThemeUpdateException

use of run.halo.app.exception.ThemeUpdateException in project halo by ruibaby.

the class GitThemeUpdater method merge.

public ThemeProperty merge(ThemeProperty oldThemeProperty, ThemeProperty newThemeProperty) throws IOException {
    final var oldThemePath = Paths.get(oldThemeProperty.getThemePath());
    // open old git repo
    try (final var oldGit = Git.init().setDirectory(oldThemePath.toFile()).call()) {
        // 0. commit old repo
        commitAutomatically(oldGit);
        final var newThemePath = Paths.get(newThemeProperty.getThemePath());
        // trying to open new git repo
        try (final var ignored = Git.open(newThemePath.toFile())) {
            // remove remote
            removeRemoteIfExists(oldGit, "newTheme");
            // add this new git to remote for old repo
            final var addedRemoteConfig = oldGit.remoteAdd().setName("newTheme").setUri(new URIish(newThemePath.toString())).call();
            log.info("git remote add newTheme {} {}", addedRemoteConfig.getName(), addedRemoteConfig.getURIs());
            // fetch remote data
            final var remote = "newTheme/halo";
            log.info("git fetch newTheme/halo");
            final var fetchResult = oldGit.fetch().setRemote("newTheme").call();
            log.info("Fetch result: {}", fetchResult.getMessages());
            // rebase upstream
            log.info("git rebase newTheme");
            final var rebaseResult = oldGit.rebase().setUpstream(remote).call();
            log.info("Rebase result: {}", rebaseResult.getStatus());
            logCommit(rebaseResult.getCurrentCommit());
            // check rebase result
            if (!rebaseResult.getStatus().isSuccessful()) {
                if (oldGit.getRepository().getRepositoryState() != RepositoryState.SAFE) {
                    // if rebasing stopped or failed, you can get back to the original state by
                    // running it
                    // with setOperation(RebaseCommand.Operation.ABORT)
                    final var abortRebaseResult = oldGit.rebase().setUpstream(remote).setOperation(RebaseCommand.Operation.ABORT).call();
                    log.error("Aborted rebase with state: {} : {}", abortRebaseResult.getStatus(), abortRebaseResult.getConflicts());
                }
                throw new ThemeUpdateException("无法自动合并最新文件!请尝试删除主题并重新拉取。");
            }
        }
    } catch (URISyntaxException | GitAPIException e) {
        throw new ServiceException("合并主题失败!请确认该主题支持在线更新。", e);
    }
    return newThemeProperty;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ThemeUpdateException(run.halo.app.exception.ThemeUpdateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ServiceException(run.halo.app.exception.ServiceException) URISyntaxException(java.net.URISyntaxException)

Aggregations

ServiceException (run.halo.app.exception.ServiceException)6 ThemeUpdateException (run.halo.app.exception.ThemeUpdateException)6 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 URIish (org.eclipse.jgit.transport.URIish)3 ThemeUpdatedEvent (run.halo.app.event.theme.ThemeUpdatedEvent)3 BadRequestException (run.halo.app.exception.BadRequestException)3 ForbiddenException (run.halo.app.exception.ForbiddenException)3 NotFoundException (run.halo.app.exception.NotFoundException)3 ThemeNotFoundException (run.halo.app.exception.ThemeNotFoundException)3 ThemeNotSupportException (run.halo.app.exception.ThemeNotSupportException)3 ThemePropertyMissingException (run.halo.app.exception.ThemePropertyMissingException)3 GitThemeUpdater (run.halo.app.theme.GitThemeUpdater)3