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);
}
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;
}
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);
}
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);
}
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;
}
Aggregations