chore: remove deprecated code. (#1334)

pull/1335/head
Ryan Wang 2021-03-29 16:57:21 +08:00 committed by GitHub
parent 359c01c361
commit 9ba9dc40cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 37 additions and 1011 deletions

View File

@ -18,9 +18,6 @@ checkstyle {
repositories {
mavenLocal()
// maven {
// url "https://maven.aliyun.com/nexus/content/groups/public"
// }
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
jcenter()
@ -99,13 +96,11 @@ ext {
annotationsVersion = "3.0.1u2"
zxingVersion = "3.4.0"
huaweiObsVersion = "3.19.7"
githubApiVersion = "1.84"
templateInheritanceVersion = "0.4.RELEASE"
jsoupVersion = "1.13.1"
}
dependencies {
implementation "org.kohsuke:github-api:$githubApiVersion"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-web"

View File

@ -16,7 +16,6 @@ import run.halo.app.annotation.DisableOnCondition;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.model.dto.EnvironmentDTO;
import run.halo.app.model.dto.LoginPreCheckDTO;
import run.halo.app.model.dto.StatisticDTO;
import run.halo.app.model.entity.User;
import run.halo.app.model.enums.MFAType;
import run.halo.app.model.params.LoginParam;
@ -100,13 +99,6 @@ public class AdminController {
return adminService.refreshToken(refreshToken);
}
@GetMapping("counts")
@ApiOperation("Gets count info")
@Deprecated
public StatisticDTO getCount() {
return adminService.getCount();
}
@GetMapping("environments")
@ApiOperation("Gets environments info")
public EnvironmentDTO getEnvironments() {

View File

@ -190,43 +190,6 @@ public class ThemeController {
return themeService.fetch(uri);
}
@PostMapping(value = {"fetchingBranches", "/fetching/git/branches"})
@ApiOperation("Fetches all branches")
@Deprecated(since = "1.4.2", forRemoval = true)
public List<ThemeProperty> fetchBranches(@RequestParam("uri") String uri) {
return themeService.fetchBranches(uri);
}
@PostMapping("fetchingReleases")
@ApiOperation("Fetches all releases")
@Deprecated(since = "1.4.2", forRemoval = true)
public List<ThemeProperty> fetchReleases(@RequestParam("uri") String uri) {
return themeService.fetchReleases(uri);
}
@GetMapping("fetchingRelease")
@ApiOperation("Fetches a specific release")
@Deprecated(since = "1.4.2", forRemoval = true)
public ThemeProperty fetchRelease(@RequestParam("uri") String uri,
@RequestParam("tag") String tagName) {
return themeService.fetchRelease(uri, tagName);
}
@GetMapping("fetchBranch")
@ApiOperation("Fetch specific branch")
@Deprecated(since = "1.4.2", forRemoval = true)
public ThemeProperty fetchBranch(@RequestParam("uri") String uri,
@RequestParam("branch") String branchName) {
return themeService.fetchBranch(uri, branchName);
}
@GetMapping("fetchLatestRelease")
@ApiOperation("Fetch latest release")
@Deprecated(since = "1.4.2", forRemoval = true)
public ThemeProperty fetchLatestRelease(@RequestParam("uri") String uri) {
return themeService.fetchLatestRelease(uri);
}
@PutMapping("fetching/{themeId:.+}")
@ApiOperation("Upgrades theme from remote")
public ThemeProperty updateThemeByFetching(@PathVariable("themeId") String themeId) {

View File

@ -18,9 +18,6 @@ public class StatisticDTO {
private Long categoryCount;
@Deprecated
private Long attachmentCount;
private Long tagCount;
private Long journalCount;

View File

@ -3,7 +3,6 @@ package run.halo.app.service;
import org.springframework.lang.NonNull;
import run.halo.app.model.dto.EnvironmentDTO;
import run.halo.app.model.dto.LoginPreCheckDTO;
import run.halo.app.model.dto.StatisticDTO;
import run.halo.app.model.entity.User;
import run.halo.app.model.params.LoginParam;
import run.halo.app.model.params.ResetPasswordParam;
@ -64,15 +63,6 @@ public interface AdminService {
*/
void resetPasswordByCode(@NonNull ResetPasswordParam param);
/**
* Get system counts.
*
* @return count dto
*/
@NonNull
@Deprecated
StatisticDTO getCount();
/**
* Get system environments
*

View File

@ -1,6 +1,5 @@
package run.halo.app.service;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
@ -19,19 +18,6 @@ import run.halo.app.model.support.ThemeFile;
*/
public interface ThemeService {
/**
* Theme property file name.
*/
@Deprecated
String THEME_PROPERTY_FILE_NAME = "theme.yaml";
/**
* Theme property file name.
*/
@Deprecated
String[] THEME_PROPERTY_FILE_NAMES = {"theme.yaml", "theme.yml"};
/**
* Configuration file name.
*/
@ -42,34 +28,11 @@ public interface ThemeService {
*/
String[] CAN_EDIT_SUFFIX = {".ftl", ".css", ".js", ".yaml", ".yml", ".properties"};
/**
* These file names cannot be displayed.
*/
String[] FILTER_FILES =
{".git", ".DS_Store", "theme.yaml", "theme.yml", "settings.yaml", "settings.yml"};
/**
* Theme folder location.
*/
String THEME_FOLDER = "templates/themes";
/**
* Theme screenshots name.
*/
@Deprecated
String THEME_SCREENSHOTS_NAME = "screenshot";
/**
* Render template.
*/
String RENDER_TEMPLATE = "themes/%s/%s";
/**
* Render template with suffix.
*/
String RENDER_TEMPLATE_SUFFIX = "themes/%s/%s.ftl";
/**
* Theme cache key.
*/
@ -85,26 +48,6 @@ public interface ThemeService {
*/
String CUSTOM_POST_PREFIX = "post_";
/**
* Theme provider remote name.
*/
String THEME_PROVIDER_REMOTE_NAME = "origin";
/**
* Default remote branch name.
*/
String DEFAULT_REMOTE_BRANCH = "master";
/**
* Key to access the zip file url which is in the http response
*/
String ZIP_FILE_KEY = "zipball_url";
/**
* Key to access the tag name which is in the http response
*/
String TAG_KEY = "tag_name";
/**
* Get theme property by theme id.
*
@ -140,16 +83,6 @@ public interface ThemeService {
@NonNull
List<ThemeFile> listThemeFolderBy(@NonNull String themeId);
/**
* Lists a set of custom template, such as sheet_xxx.ftl, and xxx will be template name
*
* @param themeId theme id must not be blank
* @return a set of templates
*/
@Deprecated
@NonNull
List<String> listCustomTemplates(@NonNull String themeId);
/**
* Lists a set of custom template, such as sheet_xxx.ftl/post_xxx.ftl, and xxx will be
* template name
@ -296,17 +229,6 @@ public interface ThemeService {
@NonNull
ThemeProperty upload(@NonNull MultipartFile file);
/**
* Adds a new theme.
*
* @param themeTmpPath theme temporary path must not be null
* @return theme property
* @throws IOException IOException
*/
@NonNull
@Deprecated
ThemeProperty add(@NonNull Path themeTmpPath) throws IOException;
/**
* Fetches a new theme.
*
@ -316,58 +238,6 @@ public interface ThemeService {
@NonNull
ThemeProperty fetch(@NonNull String uri);
/**
* Fetches the latest release
*
* @param uri theme remote uri must not be null
* @return theme property
*/
@NonNull
@Deprecated(since = "1.4.2", forRemoval = true)
ThemeProperty fetchLatestRelease(@NonNull String uri);
/**
* Fetches all the branches info
*
* @param uri theme remote uri must not be null
* @return list of theme properties
*/
@NonNull
@Deprecated(since = "1.4.2", forRemoval = true)
List<ThemeProperty> fetchBranches(@NonNull String uri);
/**
* Fetches all the release info
*
* @param uri theme remote uri must not be null
* @return list of theme properties
*/
@NonNull
@Deprecated(since = "1.4.2", forRemoval = true)
List<ThemeProperty> fetchReleases(@NonNull String uri);
/**
* Fetches a specific release
*
* @param uri theme remote uri must not be null
* @param tagName release tag name must not be null
* @return theme property
*/
@NonNull
@Deprecated(since = "1.4.2", forRemoval = true)
ThemeProperty fetchRelease(@NonNull String uri, @NonNull String tagName);
/**
* Fetches a specific branch (clone)
*
* @param uri theme remote uri must not be null
* @param branchName wanted branch must not be null
* @return theme property
*/
@NonNull
@Deprecated(since = "1.4.2", forRemoval = true)
ThemeProperty fetchBranch(@NonNull String uri, @NonNull String branchName);
/**
* Reloads themes
*/

View File

@ -16,7 +16,6 @@ import run.halo.app.service.base.CrudService;
*/
public interface ThemeSettingService extends CrudService<ThemeSetting, Integer> {
/**
* Saves theme setting.
*

View File

@ -28,14 +28,6 @@ import run.halo.app.model.vo.CommentWithHasChildrenVO;
public interface BaseCommentService<COMMENT extends BaseComment>
extends CrudService<COMMENT, Long> {
/**
* %d: parent commentator id
* %s: parent commentator author name
* %s: comment content
*/
@Deprecated
String COMMENT_TEMPLATE = "<a href='#comment-id-%d'>@%s</a> %s";
/**
* Lists comments by post id.
*

View File

@ -20,7 +20,6 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;
import run.halo.app.cache.AbstractStringCacheStore;
import run.halo.app.config.properties.HaloProperties;
import run.halo.app.event.logger.LogEvent;
@ -30,12 +29,9 @@ import run.halo.app.exception.ServiceException;
import run.halo.app.mail.MailService;
import run.halo.app.model.dto.EnvironmentDTO;
import run.halo.app.model.dto.LoginPreCheckDTO;
import run.halo.app.model.dto.StatisticDTO;
import run.halo.app.model.entity.User;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.enums.LogType;
import run.halo.app.model.enums.MFAType;
import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.params.LoginParam;
import run.halo.app.model.params.ResetPasswordParam;
import run.halo.app.model.properties.EmailProperties;
@ -45,14 +41,7 @@ import run.halo.app.security.context.SecurityContextHolder;
import run.halo.app.security.token.AuthToken;
import run.halo.app.security.util.SecurityUtils;
import run.halo.app.service.AdminService;
import run.halo.app.service.AttachmentService;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.LinkService;
import run.halo.app.service.OptionService;
import run.halo.app.service.PostCommentService;
import run.halo.app.service.PostService;
import run.halo.app.service.SheetCommentService;
import run.halo.app.service.SheetService;
import run.halo.app.service.UserService;
import run.halo.app.utils.HaloUtils;
import run.halo.app.utils.TwoFactorAuthUtils;
@ -68,60 +57,29 @@ import run.halo.app.utils.TwoFactorAuthUtils;
@Service
public class AdminServiceImpl implements AdminService {
private final PostService postService;
private final SheetService sheetService;
private final AttachmentService attachmentService;
private final PostCommentService postCommentService;
private final SheetCommentService sheetCommentService;
private final JournalCommentService journalCommentService;
private final OptionService optionService;
private final UserService userService;
private final LinkService linkService;
private final MailService mailService;
private final AbstractStringCacheStore cacheStore;
private final RestTemplate restTemplate;
private final HaloProperties haloProperties;
private final ApplicationEventPublisher eventPublisher;
public AdminServiceImpl(PostService postService,
SheetService sheetService,
AttachmentService attachmentService,
PostCommentService postCommentService,
SheetCommentService sheetCommentService,
JournalCommentService journalCommentService,
public AdminServiceImpl(
OptionService optionService,
UserService userService,
LinkService linkService,
MailService mailService,
AbstractStringCacheStore cacheStore,
RestTemplate restTemplate,
HaloProperties haloProperties,
ApplicationEventPublisher eventPublisher) {
this.postService = postService;
this.sheetService = sheetService;
this.attachmentService = attachmentService;
this.postCommentService = postCommentService;
this.sheetCommentService = sheetCommentService;
this.journalCommentService = journalCommentService;
this.optionService = optionService;
this.userService = userService;
this.linkService = linkService;
this.mailService = mailService;
this.cacheStore = cacheStore;
this.restTemplate = restTemplate;
this.haloProperties = haloProperties;
this.eventPublisher = eventPublisher;
}
@ -290,48 +248,21 @@ public class AdminServiceImpl implements AdminService {
cacheStore.delete("code");
}
@Override
@NonNull
public StatisticDTO getCount() {
StatisticDTO statisticDTO = new StatisticDTO();
statisticDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED)
+ sheetService.countByStatus(PostStatus.PUBLISHED));
statisticDTO.setAttachmentCount(attachmentService.count());
// Handle comment count
long postCommentCount = postCommentService.countByStatus(CommentStatus.PUBLISHED);
long sheetCommentCount = sheetCommentService.countByStatus(CommentStatus.PUBLISHED);
long journalCommentCount = journalCommentService.countByStatus(CommentStatus.PUBLISHED);
statisticDTO.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount);
long birthday = optionService.getBirthday();
long days = (System.currentTimeMillis() - birthday) / (1000 * 24 * 3600);
statisticDTO.setEstablishDays(days);
statisticDTO.setBirthday(birthday);
statisticDTO.setLinkCount(linkService.count());
statisticDTO.setVisitCount(postService.countVisit() + sheetService.countVisit());
statisticDTO.setLikeCount(postService.countLike() + sheetService.countLike());
return statisticDTO;
}
@Override
@NonNull
public EnvironmentDTO getEnvironments() {
EnvironmentDTO environmentDTO = new EnvironmentDTO();
EnvironmentDTO environmentDto = new EnvironmentDTO();
// Get application start time.
environmentDTO.setStartTime(ManagementFactory.getRuntimeMXBean().getStartTime());
environmentDto.setStartTime(ManagementFactory.getRuntimeMXBean().getStartTime());
environmentDTO.setDatabase(DATABASE_PRODUCT_NAME);
environmentDto.setDatabase(DATABASE_PRODUCT_NAME);
environmentDTO.setVersion(HaloConst.HALO_VERSION);
environmentDto.setVersion(HaloConst.HALO_VERSION);
environmentDTO.setMode(haloProperties.getMode());
environmentDto.setMode(haloProperties.getMode());
return environmentDTO;
return environmentDto;
}
@Override
@ -398,7 +329,7 @@ public class AdminServiceImpl implements AdminService {
List<String> linesArray = new ArrayList<>();
StringBuilder result = new StringBuilder();
final StringBuilder result = new StringBuilder();
if (!file.exists()) {
return StringUtils.EMPTY;

View File

@ -6,13 +6,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.exception.AlreadyExistsException;
import run.halo.app.model.dto.MenuDTO;
import run.halo.app.model.entity.Menu;
import run.halo.app.model.params.MenuParam;
@ -40,14 +38,16 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
}
@Override
public @NonNull List<MenuDTO> listDtos(@NonNull Sort sort) {
public @NonNull
List<MenuDTO> listDtos(@NonNull Sort sort) {
Assert.notNull(sort, "Sort info must not be null");
return convertTo(listAll(sort));
}
@Override
public @NonNull List<MenuTeamVO> listTeamVos(@NonNull Sort sort) {
public @NonNull
List<MenuTeamVO> listTeamVos(@NonNull Sort sort) {
Assert.notNull(sort, "Sort info must not be null");
// List all menus
@ -101,7 +101,8 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
}
@Override
public @NonNull Menu createBy(@NonNull MenuParam menuParam) {
public @NonNull
Menu createBy(@NonNull MenuParam menuParam) {
Assert.notNull(menuParam, "Menu param must not be null");
// Create an return
@ -141,12 +142,14 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
}
@Override
public @NonNull Menu create(@NonNull Menu menu) {
public @NonNull
Menu create(@NonNull Menu menu) {
return super.create(menu);
}
@Override
public @NonNull Menu update(@NonNull Menu menu) {
public @NonNull
Menu update(@NonNull Menu menu) {
return super.update(menu);
}
@ -215,23 +218,4 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
.map(menu -> (MenuDTO) new MenuDTO().convertFrom(menu))
.collect(Collectors.toList());
}
@Deprecated
private void nameMustNotExist(@NonNull Menu menu) {
Assert.notNull(menu, "Menu must not be null");
boolean exist = false;
if (ServiceUtils.isEmptyId(menu.getId())) {
// Create action
exist = menuRepository.existsByName(menu.getName());
} else {
// Update action
exist = menuRepository.existsByIdNotAndName(menu.getId(), menu.getName());
}
if (exist) {
throw new AlreadyExistsException("菜单 " + menu.getName() + " 已存在");
}
}
}

View File

@ -620,17 +620,5 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
return new OptionSimpleDTO().convertFrom(option);
}
@Deprecated
private void cleanCache() {
cacheStore.delete(OPTIONS_KEY);
}
@Deprecated
private void publishOptionUpdatedEvent() {
flush();
cleanCache();
eventPublisher.publishEvent(new OptionUpdatedEvent(this));
}
}

View File

@ -78,42 +78,42 @@ public class StatisticServiceImpl implements StatisticService {
@Override
public StatisticDTO getStatistic() {
StatisticDTO statisticDTO = new StatisticDTO();
statisticDTO.setPostCount(postService.countByStatus(PostStatus.PUBLISHED));
StatisticDTO statisticDto = new StatisticDTO();
statisticDto.setPostCount(postService.countByStatus(PostStatus.PUBLISHED));
// Handle comment count
long postCommentCount = postCommentService.countByStatus(CommentStatus.PUBLISHED);
long sheetCommentCount = sheetCommentService.countByStatus(CommentStatus.PUBLISHED);
long journalCommentCount = journalCommentService.countByStatus(CommentStatus.PUBLISHED);
statisticDTO.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount);
statisticDTO.setTagCount(tagService.count());
statisticDTO.setCategoryCount(categoryService.count());
statisticDTO.setJournalCount(journalService.count());
statisticDto.setCommentCount(postCommentCount + sheetCommentCount + journalCommentCount);
statisticDto.setTagCount(tagService.count());
statisticDto.setCategoryCount(categoryService.count());
statisticDto.setJournalCount(journalService.count());
long birthday = optionService.getBirthday();
long days = (System.currentTimeMillis() - birthday) / (1000 * 24 * 3600);
statisticDTO.setEstablishDays(days);
statisticDTO.setBirthday(birthday);
statisticDto.setEstablishDays(days);
statisticDto.setBirthday(birthday);
statisticDTO.setLinkCount(linkService.count());
statisticDTO.setVisitCount(postService.countVisit() + sheetService.countVisit());
statisticDTO.setLikeCount(postService.countLike() + sheetService.countLike());
return statisticDTO;
statisticDto.setLinkCount(linkService.count());
statisticDto.setVisitCount(postService.countVisit() + sheetService.countVisit());
statisticDto.setLikeCount(postService.countLike() + sheetService.countLike());
return statisticDto;
}
@Override
public StatisticWithUserDTO getStatisticWithUser() {
StatisticDTO statisticDTO = getStatistic();
StatisticDTO statisticDto = getStatistic();
StatisticWithUserDTO statisticWithUserDTO = new StatisticWithUserDTO();
statisticWithUserDTO.convertFrom(statisticDTO);
StatisticWithUserDTO statisticWithUserDto = new StatisticWithUserDTO();
statisticWithUserDto.convertFrom(statisticDto);
User user =
userService.getCurrentUser().orElseThrow(() -> new ServiceException("未查询到博主信息"));
statisticWithUserDTO.setUser(new UserDTO().convertFrom(user));
statisticWithUserDto.setUser(new UserDTO().convertFrom(user));
return statisticWithUserDTO;
return statisticWithUserDto;
}
}

View File

@ -1,24 +1,17 @@
package run.halo.app.service.impl;
import static run.halo.app.utils.FileUtils.copyFolder;
import static run.halo.app.utils.FileUtils.deleteFolderQuietly;
import static run.halo.app.utils.VersionUtil.compareVersion;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
@ -30,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile;
import run.halo.app.config.properties.HaloProperties;
import run.halo.app.event.theme.ThemeActivatedEvent;
import run.halo.app.event.theme.ThemeUpdatedEvent;
import run.halo.app.exception.AlreadyExistsException;
import run.halo.app.exception.BadRequestException;
import run.halo.app.exception.ForbiddenException;
import run.halo.app.exception.NotFoundException;
@ -55,9 +47,6 @@ import run.halo.app.theme.ThemeFileScanner;
import run.halo.app.theme.ThemePropertyScanner;
import run.halo.app.theme.ZipThemeFetcher;
import run.halo.app.utils.FileUtils;
import run.halo.app.utils.GitUtils;
import run.halo.app.utils.GithubUtils;
import run.halo.app.utils.HaloUtils;
/**
* Theme service implementation.
@ -134,12 +123,6 @@ public class ThemeServiceImpl implements ThemeService {
.orElse(Collections.emptyList());
}
@Override
@NonNull
public List<String> listCustomTemplates(@NonNull String themeId) {
return listCustomTemplates(themeId, CUSTOM_SHEET_PREFIX);
}
@Override
@NonNull
public List<String> listCustomTemplates(@NonNull String themeId, @NonNull String prefix) {
@ -365,54 +348,6 @@ public class ThemeServiceImpl implements ThemeService {
return this.themeRepository.attemptToAdd(newThemeProperty);
}
@Override
@NonNull
@Deprecated
public ThemeProperty add(@NonNull Path themeTmpPath) throws IOException {
Assert.notNull(themeTmpPath, "Theme temporary path must not be null");
Assert.isTrue(Files.isDirectory(themeTmpPath), "Theme temporary path must be a directory");
if (log.isTraceEnabled()) {
log.trace("Children path of [{}]:", themeTmpPath);
try (Stream<Path> pathStream = Files.list(themeTmpPath)) {
pathStream.forEach(path -> log.trace(path.toString()));
}
}
// Check property config
ThemeProperty tmpThemeProperty = getProperty(themeTmpPath);
// Check theme existence
boolean isExist = getThemes().stream()
.anyMatch(themeProperty -> themeProperty.getId()
.equalsIgnoreCase(tmpThemeProperty.getId()));
if (isExist) {
throw new AlreadyExistsException("当前安装的主题已存在");
}
// Not support current halo version.
if (StringUtils.isNotEmpty(tmpThemeProperty.getRequire())
&& !compareVersion(HaloConst.HALO_VERSION, tmpThemeProperty.getRequire())) {
throw new ThemeNotSupportException(
"当前主题仅支持 Halo " + tmpThemeProperty.getRequire() + " 以上的版本");
}
// Copy the temporary path to current theme folder
Path targetThemePath = themeWorkDir.resolve(tmpThemeProperty.getId());
copyFolder(themeTmpPath, targetThemePath);
// Get property again
ThemeProperty property = getProperty(targetThemePath);
// Clear theme cache
this.eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
// Delete cache
return property;
}
@Override
public ThemeProperty fetch(@NonNull String uri) {
Assert.hasText(uri, "Theme remote uri must not be blank");
@ -421,114 +356,6 @@ public class ThemeServiceImpl implements ThemeService {
return this.themeRepository.attemptToAdd(themeProperty);
}
@Override
public ThemeProperty fetchBranch(String uri, String branchName) {
Assert.hasText(uri, "Theme remote uri must not be blank");
Path tmpPath = null;
try {
// Create temp path
tmpPath = FileUtils.createTempDirectory();
// Create temp path
Path themeTmpPath = tmpPath.resolve(HaloUtils.randomUUIDWithoutDash());
String repoUrl = StringUtils.appendIfMissingIgnoreCase(uri, ".git", ".git");
GitUtils.cloneFromGit(repoUrl, themeTmpPath, branchName);
return add(themeTmpPath);
} catch (IOException | GitAPIException e) {
throw new ServiceException("主题拉取失败 " + uri + "。" + e.getMessage(), e);
} finally {
deleteFolderQuietly(tmpPath);
}
}
@Override
public ThemeProperty fetchRelease(@NonNull String uri, @NonNull String tagName) {
Assert.hasText(uri, "Theme remote uri must not be blank");
Assert.hasText(tagName, "Theme remote tagName must not be blank");
Path tmpPath = null;
try {
tmpPath = FileUtils.createTempDirectory();
Path themeTmpPath = tmpPath.resolve(HaloUtils.randomUUIDWithoutDash());
Map<String, Object> releaseInfo = GithubUtils.getRelease(uri, tagName);
if (releaseInfo == null) {
throw new ServiceException("主题拉取失败" + uri);
}
String zipUrl = (String) releaseInfo.get(ZIP_FILE_KEY);
downloadZipAndUnzip(zipUrl, themeTmpPath);
// find root theme folder
Path themeRootPath = getThemeRootPath(themeTmpPath);
log.debug("Got theme root path: [{}]", themeRootPath);
return add(themeRootPath);
} catch (IOException e) {
throw new ServiceException("主题拉取失败 " + uri, e);
} finally {
deleteFolderQuietly(tmpPath);
}
}
@Override
public ThemeProperty fetchLatestRelease(@NonNull String uri) {
Assert.hasText(uri, "Theme remote uri must not be blank");
Map<String, Object> releaseInfo = GithubUtils.getLatestRelease(uri);
if (releaseInfo == null) {
throw new ServiceException("主题拉取失败" + uri);
}
String zipUrl = (String) releaseInfo.get(ZIP_FILE_KEY);
final var themeProperty = this.fetcherComposite.fetch(zipUrl);
return this.themeRepository.attemptToAdd(themeProperty);
}
@Override
public List<ThemeProperty> fetchBranches(String uri) {
Assert.hasText(uri, "Theme remote uri must not be blank");
String repoUrl = StringUtils.appendIfMissingIgnoreCase(uri, ".git", ".git");
List<String> branches = GitUtils.getAllBranchesFromRemote(repoUrl);
List<ThemeProperty> themeProperties = new ArrayList<>();
branches.forEach(branch -> {
ThemeProperty themeProperty = new ThemeProperty();
themeProperty.setBranch(branch);
themeProperties.add(themeProperty);
});
return themeProperties;
}
@Override
public List<ThemeProperty> fetchReleases(@NonNull String uri) {
Assert.hasText(uri, "Theme remote uri must not be blank");
List<String> releases = GithubUtils.getReleases(uri);
List<ThemeProperty> themeProperties = new ArrayList<>();
if (releases == null) {
throw new ServiceException("主题拉取失败!可能原因:当前服务器无法链接到对方服务器或连接超时。");
}
releases.forEach(tagName -> {
ThemeProperty themeProperty = new ThemeProperty();
themeProperty.setBranch(tagName);
themeProperties.add(themeProperty);
});
return themeProperties;
}
@Override
public void reload() {
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
@ -630,21 +457,4 @@ public class ThemeServiceImpl implements ThemeService {
.orElseThrow(() -> new ThemePropertyMissingException(themePath + " 没有说明文件")
.setErrorData(themePath));
}
/**
* Get theme root path.
*
* @param themePath theme folder path
* @return real theme root path
* @throws IOException IO exception
*/
@NonNull
@Deprecated(since = "1.4.2", forRemoval = true)
private Path getThemeRootPath(@NonNull Path themePath) throws IOException {
return FileUtils.findRootPath(themePath,
path -> StringUtils.equalsAny(path.getFileName().toString(),
"theme.yaml", "theme.yml"))
.orElseThrow(() ->
new BadRequestException("无法准确定位到主题根目录,请确认主题目录中包含 theme.ymltheme.yaml。"));
}
}

View File

@ -1,29 +0,0 @@
//package run.halo.app.service.impl;
//
//import org.springframework.boot.actuate.trace.http.HttpTrace;
//import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
//import org.springframework.stereotype.Service;
//import run.halo.app.service.TraceService;
//
//import java.util.List;
//
///**
// * TraceService implementation class.
// *
// * @author johnniang
// * @date 2019-06-18
// */
//@Service
//public class TraceServiceImpl implements TraceService {
//
// private final HttpTraceRepository httpTraceRepository;
//
// public TraceServiceImpl(HttpTraceRepository httpTraceRepository) {
// this.httpTraceRepository = httpTraceRepository;
// }
//
// @Override
// public List<HttpTrace> listHttpTraces() {
// return httpTraceRepository.findAll();
// }
//}

View File

@ -11,7 +11,6 @@ import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.cache.AbstractStringCacheStore;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.event.logger.LogEvent;
import run.halo.app.event.user.UserUpdatedEvent;
@ -41,16 +40,12 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
private final UserRepository userRepository;
private final AbstractStringCacheStore stringCacheStore;
private final ApplicationEventPublisher eventPublisher;
public UserServiceImpl(UserRepository userRepository,
AbstractStringCacheStore stringCacheStore,
ApplicationEventPublisher eventPublisher) {
super(userRepository);
this.userRepository = userRepository;
this.stringCacheStore = stringCacheStore;
this.eventPublisher = eventPublisher;
}

View File

@ -1,10 +1,8 @@
package run.halo.app.utils;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
@ -23,7 +21,6 @@ import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
@ -38,24 +35,6 @@ public class GitUtils {
private GitUtils() {
}
@Deprecated(since = "1.4.2", forRemoval = true)
public static void cloneFromGit(@NonNull String repoUrl, @NonNull Path targetPath,
@NonNull String branchName) throws GitAPIException {
Assert.hasText(repoUrl, "Repository remote url must not be blank");
Assert.notNull(targetPath, "Target path must not be null");
try (
Git ignored = Git.cloneRepository()
.setURI(repoUrl)
.setDirectory(targetPath.toFile())
.setBranchesToClone(Collections.singletonList("refs/heads/" + branchName))
.setCloneSubmodules(true)
.setBranch("refs/heads/" + branchName)
.call()) {
// empty block placeholder
}
}
public static List<String> getAllBranchesFromRemote(@NonNull String repoUrl) {
List<String> branches = new ArrayList<>();
try {

View File

@ -1,384 +0,0 @@
package run.halo.app.utils;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHRelease;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.HttpException;
import run.halo.app.service.ThemeService;
/**
* GithubUtils send request to api.github.com
*
* @author bigbang019
* @date 2020-05-31
*/
@Slf4j
public class GithubUtils {
/**
* The prefix need to remove
*/
static final String PREFIX = "https://github.com/";
/**
* Get latest release
*
* @param uri repository url must not be null
* @return the map object containning tagname and zipfile url
*/
public static Map<String, Object> getLatestRelease(String uri) {
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
try {
GithubLatestRelease githubLatestRelease = new GithubLatestRelease(repoUrl);
Thread thread = new Thread(githubLatestRelease);
thread.start();
thread.join(10 * 1000);
return githubLatestRelease.result;
} catch (InterruptedException e) {
log.warn("Interrupted", e);
}
return null;
}
/**
* Get release information
*
* @param uri repository url must not be null
* @return list of tagname of releases
*/
public static List<String> getReleases(String uri) {
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
try {
GithubReleases githubReleases = new GithubReleases(repoUrl);
Thread thread = new Thread(githubReleases);
thread.start();
thread.join(10 * 1000);
return githubReleases.result;
} catch (InterruptedException e) {
log.warn("Getting releases from github interrupted", e);
}
return null;
}
/**
* Get release information
*
* @param uri repository url must not be null
* @param tagName tag must not be null
* @return the map object containning tagname and zipfile url
*/
public static Map<String, Object> getRelease(String uri, String tagName) {
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
try {
GithubRelease githubRelease = new GithubRelease(repoUrl, tagName);
Thread thread = new Thread(githubRelease);
thread.start();
thread.join(10 * 1000);
return githubRelease.result;
} catch (InterruptedException e) {
log.warn("Interrupted", e);
}
return null;
}
/**
* Get the content of theme.yaml/theme.yml
*
* @param uri repository url must not be null
* @param branch branch must not be null
* @return content of the file
*/
public static String accessThemeProperty(String uri, String branch) {
String repoUrl = StringUtils.removeStartIgnoreCase(uri, PREFIX);
try {
GithubFile githubFile = new GithubFile(repoUrl, branch);
Thread thread = new Thread(githubFile);
thread.start();
thread.join(10 * 1000);
return githubFile.result;
} catch (InterruptedException e) {
log.warn("Interrupted", e);
}
return null;
}
private static class GithubRelease implements Runnable {
/**
* should be in format of "username/reponame"
*/
private final String repoUrl;
/**
* repository tag name
*/
private final String tagName;
/**
* The return result is zip url and tag name etc.
*/
private HashMap<String, Object> result;
public GithubRelease(String repoUrl, String tagName) {
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
this.tagName = tagName;
result = null;
}
@Override
public void run() {
while (true) {
try {
GitHub gitHub = GitHub.connectAnonymously();
GHRepository ghRepository = gitHub.getRepository(repoUrl);
List<GHRelease> ghReleaseList = ghRepository.getReleases();
if (ghReleaseList.size() == 0) {
break;
}
Optional<GHRelease> res = ghReleaseList.stream()
.filter(
release -> StringUtils.equalsIgnoreCase(release.getTagName(), tagName))
.findFirst();
if (res.isPresent()) {
GHRelease ghRelease = res.get();
result = new HashMap<String, Object>() {
{
put(ThemeService.ZIP_FILE_KEY, ghRelease.getZipballUrl());
put(ThemeService.TAG_KEY, ghRelease.getTagName());
}
};
}
break;
} catch (Exception e) {
if (e instanceof HttpException) {
int code = ((HttpException) e).getResponseCode();
if (code != -1) {
break;
}
} else {
break;
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
break;
}
}
}
}
private static class GithubReleases implements Runnable {
private final String repoUrl;
private List<String> result;
public GithubReleases(String repoUrl) {
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
}
@Override
public void run() {
while (true) {
try {
GitHub gitHub = GitHub.connectAnonymously();
GHRepository ghRepository = gitHub.getRepository(repoUrl);
List<GHRelease> ghReleaseList = ghRepository.getReleases();
result = new ArrayList<>();
for (GHRelease ghRelease : ghReleaseList) {
result.add(ghRelease.getTagName());
}
break;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("Failed to react with github.", e);
}
if (e instanceof HttpException) {
int code = ((HttpException) e).getResponseCode();
if (code != -1) {
break;
}
} else {
break;
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
break;
}
}
}
}
private static class GithubLatestRelease implements Runnable {
/**
* should be in format of "username/reponame"
*/
private final String repoUrl;
/**
* The return result is zip url and tag name etc.
*/
private HashMap<String, Object> result;
public GithubLatestRelease(String repoUrl) {
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
result = null;
}
@Override
public void run() {
while (true) {
try {
GitHub gitHub = GitHub.connectAnonymously();
GHRepository ghRepository = gitHub.getRepository(repoUrl);
List<GHRelease> ghReleaseList = ghRepository.getReleases();
if (ghReleaseList.size() == 0) {
break;
}
GHRelease ghRelease = ghReleaseList.get(0);
result = new HashMap<String, Object>() {
{
put(ThemeService.ZIP_FILE_KEY, ghRelease.getZipballUrl());
put(ThemeService.TAG_KEY, ghRelease.getTagName());
}
};
break;
} catch (Exception e) {
if (e instanceof HttpException) {
int code = ((HttpException) e).getResponseCode();
if (code != -1) {
break;
}
} else {
break;
}
}
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
break;
}
}
}
}
private static class GithubFile implements Runnable {
/**
* should be in format of "username/reponame"
*/
private final String repoUrl;
/**
* the branch name
*/
private final String branch;
/**
* result is file content
*/
private String result;
public GithubFile(String repoUrl, String branch) {
this.repoUrl = StringUtils.removeEndIgnoreCase(repoUrl, ".git");
this.branch = branch;
result = null;
}
@Override
public void run() {
while (true) {
try {
GitHub gitHub = GitHub.connectAnonymously();
GHRepository ghRepository = gitHub.getRepository(repoUrl);
GHContent ghContent = null;
for (String themePropertyFile : ThemeService.THEME_PROPERTY_FILE_NAMES) {
try {
ghContent = ghRepository.getFileContent(themePropertyFile, branch);
} catch (FileNotFoundException ignored) {
// ignore this exception
}
}
if (ghContent == null) {
break;
}
result = ghContent.getContent();
break;
} catch (Exception e) {
if (e instanceof HttpException) {
int code = ((HttpException) e).getResponseCode();
if (code != -1) {
break;
}
} else {
break;
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
// ignore this exception
}
}
}
}
}

View File

@ -23,7 +23,7 @@ import run.halo.app.security.service.OneTimeTokenService;
@AutoConfigureMockMvc
class OneTimeTokenTest {
static final String REQUEST_URI = "/api/admin/counts";
static final String REQUEST_URI = "/api/admin/statistics";
@Autowired
MockMvc mvc;

View File

@ -1,46 +0,0 @@
package run.halo.app.utils;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@Slf4j
@Disabled("Dut to time-consumption")
class GithubUtilsTest {
@Test
void getLatestReleasesWithValidURL() {
Map<String, Object> map =
GithubUtils.getLatestRelease("https://github.com/halo-dev/halo-theme-hux");
}
@Test
void getLatestReleasesWithInvalidURL() {
Map<String, Object> map =
GithubUtils.getLatestRelease("https://github.com/halo-dev/halo-theme-hu");
assertNull(map);
}
@Test
void accessThemePropertyWithValidURL() {
String content =
GithubUtils.accessThemeProperty("https://github.com/halo-dev/halo-theme-hux", "master");
}
@Test
void accessThemePropertyWithInvalidURL() {
String content =
GithubUtils.accessThemeProperty("https://github.com/halo-dev/halo-theme-hu", "master");
assertNull(content);
}
@Test
void getReleasesTest() {
List<String> list = GithubUtils.getReleases("https://github.com/halo-dev/halo-theme-hux");
}
}