mirror of https://github.com/halo-dev/halo
Fix incorrectly non-git folder opening and fix start panic when no themes found (#1479)
parent
a046f3edca
commit
0059668a76
|
@ -1,6 +1,5 @@
|
|||
package run.halo.app.core;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -26,18 +25,18 @@ public class CommonResultControllerAdvice implements ResponseBodyAdvice<Object>
|
|||
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType,
|
||||
@NotNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
@NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
return AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public final Object beforeBodyWrite(@Nullable Object body,
|
||||
@NotNull MethodParameter returnType,
|
||||
@NotNull MediaType contentType,
|
||||
@NotNull Class<? extends HttpMessageConverter<?>> converterType,
|
||||
@NotNull ServerHttpRequest request,
|
||||
@NotNull ServerHttpResponse response) {
|
||||
@NonNull MethodParameter returnType,
|
||||
@NonNull MediaType contentType,
|
||||
@NonNull Class<? extends HttpMessageConverter<?>> converterType,
|
||||
@NonNull ServerHttpRequest request,
|
||||
@NonNull ServerHttpResponse response) {
|
||||
MappingJacksonValue container = getOrCreateContainer(body);
|
||||
// The contain body will never be null
|
||||
beforeBodyWriteInternal(container, contentType, returnType, request, response);
|
||||
|
|
|
@ -167,12 +167,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
// Create theme folder
|
||||
Path themePath = themeService.getBasePath();
|
||||
|
||||
// Fix the problem that the project cannot start after moving to a new server
|
||||
if (Files.notExists(themePath) || !isInstalled) {
|
||||
if (themeService.fetchThemePropertyBy(HaloConst.DEFAULT_THEME_ID).isEmpty()) {
|
||||
FileUtils.copyFolder(source, themePath);
|
||||
log.debug("Copied theme folder from [{}] to [{}]", source, themePath);
|
||||
} else {
|
||||
log.debug("Skipped copying theme folder due to existence of theme folder");
|
||||
log.info("Copied theme folder from [{}] to [{}]", source, themePath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e instanceof FileNotFoundException) {
|
||||
|
|
|
@ -98,10 +98,6 @@ public class ThemeRepositoryImpl
|
|||
|
||||
@Override
|
||||
public Optional<ThemeProperty> fetchThemePropertyByThemeId(String themeId) {
|
||||
if (StringUtils.equals(themeId, getActivatedThemeId())) {
|
||||
return Optional.of(getActivatedThemeProperty());
|
||||
}
|
||||
|
||||
return ThemePropertyScanner.INSTANCE.scan(getThemeRootPath(), null)
|
||||
.stream()
|
||||
.filter(property -> Objects.equals(themeId, property.getId()))
|
||||
|
|
|
@ -27,11 +27,13 @@ import run.halo.app.exception.BadRequestException;
|
|||
import run.halo.app.exception.ForbiddenException;
|
||||
import run.halo.app.exception.NotFoundException;
|
||||
import run.halo.app.exception.ServiceException;
|
||||
import run.halo.app.exception.ThemeNotFoundException;
|
||||
import run.halo.app.exception.ThemeNotSupportException;
|
||||
import run.halo.app.exception.ThemePropertyMissingException;
|
||||
import run.halo.app.exception.ThemeUpdateException;
|
||||
import run.halo.app.handler.theme.config.ThemeConfigResolver;
|
||||
import run.halo.app.handler.theme.config.support.Group;
|
||||
import run.halo.app.handler.theme.config.support.Option;
|
||||
import run.halo.app.handler.theme.config.support.ThemeProperty;
|
||||
import run.halo.app.model.support.HaloConst;
|
||||
import run.halo.app.model.support.ThemeFile;
|
||||
|
@ -131,7 +133,7 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
Path themePath = Paths.get(themeProperty.getThemePath());
|
||||
try (Stream<Path> pathStream = Files.list(themePath)) {
|
||||
return pathStream.filter(path ->
|
||||
StringUtils.startsWithIgnoreCase(path.getFileName().toString(), prefix))
|
||||
StringUtils.startsWithIgnoreCase(path.getFileName().toString(), prefix))
|
||||
.map(path -> {
|
||||
// Remove prefix
|
||||
final var customTemplate = StringUtils
|
||||
|
@ -315,13 +317,17 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
@Override
|
||||
@NonNull
|
||||
public ThemeProperty getActivatedTheme() {
|
||||
return fetchActivatedTheme().orElseThrow();
|
||||
return themeRepository.getActivatedThemeProperty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Optional<ThemeProperty> fetchActivatedTheme() {
|
||||
return Optional.of(themeRepository.getActivatedThemeProperty());
|
||||
try {
|
||||
return Optional.of(themeRepository.getActivatedThemeProperty());
|
||||
} catch (ThemeNotFoundException tne) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,7 +76,7 @@ public class GitThemeUpdater implements ThemeUpdater {
|
|||
|
||||
final var oldThemePath = Paths.get(oldThemeProperty.getThemePath());
|
||||
// open old git repo
|
||||
try (final var oldGit = Git.open(oldThemePath.toFile())) {
|
||||
try (final var oldGit = Git.init().setDirectory(oldThemePath.toFile()).call()) {
|
||||
// 0. commit old repo
|
||||
commitAutomatically(oldGit);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.vladsch.flexmark.util.ast.Document;
|
|||
import com.vladsch.flexmark.util.ast.Node;
|
||||
import com.vladsch.flexmark.util.ast.ReferencingNode;
|
||||
import com.vladsch.flexmark.util.sequence.BasedSequence;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import run.halo.app.utils.footnotes.internal.FootnoteRepository;
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ public class Footnote extends Node implements DelimitedNode, DoNotDecorate, Link
|
|||
|
||||
protected int referenceOrdinal;
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public BasedSequence getReference() {
|
||||
return text;
|
||||
|
@ -80,14 +80,14 @@ public class Footnote extends Node implements DelimitedNode, DoNotDecorate, Link
|
|||
this.footnoteBlock = footnoteBlock;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public BasedSequence[] getSegments() {
|
||||
return new BasedSequence[] {openingMarker, text, closingMarker};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAstExtra(@NotNull StringBuilder out) {
|
||||
public void getAstExtra(@NonNull StringBuilder out) {
|
||||
out.append(" ordinal: ")
|
||||
.append(footnoteBlock != null ? footnoteBlock.getFootnoteOrdinal() : 0).append(" ");
|
||||
delimitedSegmentSpanChars(out, openingMarker, text, closingMarker, "text");
|
||||
|
|
|
@ -10,8 +10,8 @@ import com.vladsch.flexmark.util.data.DataHolder;
|
|||
import com.vladsch.flexmark.util.sequence.BasedSequence;
|
||||
import com.vladsch.flexmark.util.sequence.SequenceUtils;
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import run.halo.app.utils.footnotes.internal.FootnoteRepository;
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ public class FootnoteBlock extends Block
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public Footnote getReferencingNode(@NotNull Node node) {
|
||||
public Footnote getReferencingNode(@NonNull Node node) {
|
||||
return node instanceof Footnote ? (Footnote) node : null;
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class FootnoteBlock extends Block
|
|||
}
|
||||
|
||||
@Override
|
||||
public void getAstExtra(@NotNull StringBuilder out) {
|
||||
public void getAstExtra(@NonNull StringBuilder out) {
|
||||
out.append(" ordinal: ").append(footnoteOrdinal).append(" ");
|
||||
segmentSpan(out, openingMarker, "open");
|
||||
segmentSpan(out, text, "text");
|
||||
|
@ -82,7 +82,7 @@ public class FootnoteBlock extends Block
|
|||
segmentSpan(out, footnote, "footnote");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public BasedSequence[] getSegments() {
|
||||
return new BasedSequence[] {openingMarker, text, closingMarker, footnote};
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.vladsch.flexmark.util.data.DataKey;
|
|||
import com.vladsch.flexmark.util.data.MutableDataHolder;
|
||||
import com.vladsch.flexmark.util.format.options.ElementPlacement;
|
||||
import com.vladsch.flexmark.util.format.options.ElementPlacementSort;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import run.halo.app.utils.footnotes.internal.FootnoteBlockParser;
|
||||
import run.halo.app.utils.footnotes.internal.FootnoteLinkRefProcessor;
|
||||
import run.halo.app.utils.footnotes.internal.FootnoteNodeFormatter;
|
||||
|
@ -63,8 +63,8 @@ public class FootnoteExtension
|
|||
}
|
||||
|
||||
@Override
|
||||
public void extend(@NotNull HtmlRenderer.Builder htmlRendererBuilder,
|
||||
@NotNull String rendererType) {
|
||||
public void extend(@NonNull HtmlRenderer.Builder htmlRendererBuilder,
|
||||
@NonNull String rendererType) {
|
||||
if (htmlRendererBuilder.isRendererType("HTML")) {
|
||||
htmlRendererBuilder.nodeRendererFactory(new FootnoteNodeRenderer.Factory());
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class FootnoteExtension
|
|||
}
|
||||
|
||||
@Override
|
||||
public void rendererOptions(@NotNull MutableDataHolder options) {
|
||||
public void rendererOptions(@NonNull MutableDataHolder options) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ import com.vladsch.flexmark.util.sequence.BasedSequence;
|
|||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import run.halo.app.utils.footnotes.FootnoteBlock;
|
||||
import run.halo.app.utils.footnotes.FootnoteExtension;
|
||||
|
||||
|
@ -115,9 +115,9 @@ public class FootnoteBlockParser extends AbstractBlockParser {
|
|||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public BlockParserFactory apply(@NotNull DataHolder options) {
|
||||
public BlockParserFactory apply(@NonNull DataHolder options) {
|
||||
return new BlockFactory(options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.vladsch.flexmark.util.ast.Document;
|
|||
import com.vladsch.flexmark.util.ast.Node;
|
||||
import com.vladsch.flexmark.util.data.DataHolder;
|
||||
import com.vladsch.flexmark.util.sequence.BasedSequence;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import run.halo.app.utils.footnotes.Footnote;
|
||||
import run.halo.app.utils.footnotes.FootnoteBlock;
|
||||
import run.halo.app.utils.footnotes.FootnoteExtension;
|
||||
|
@ -33,14 +33,14 @@ public class FootnoteLinkRefProcessor implements LinkRefProcessor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(@NotNull BasedSequence nodeChars) {
|
||||
public boolean isMatch(@NonNull BasedSequence nodeChars) {
|
||||
return nodeChars.length() >= 3 && nodeChars.charAt(0) == '[' && nodeChars.charAt(1) == '^'
|
||||
&& nodeChars.endCharAt(1) == ']';
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public Node createNode(@NotNull BasedSequence nodeChars) {
|
||||
public Node createNode(@NonNull BasedSequence nodeChars) {
|
||||
BasedSequence footnoteId = nodeChars.midSequence(2, -1).trim();
|
||||
FootnoteBlock footnoteBlock =
|
||||
footnoteId.length() > 0 ? footnoteRepository.get(footnoteId.toString()) : null;
|
||||
|
@ -55,39 +55,39 @@ public class FootnoteLinkRefProcessor implements LinkRefProcessor {
|
|||
return footnote;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public BasedSequence adjustInlineText(@NotNull Document document, @NotNull Node node) {
|
||||
public BasedSequence adjustInlineText(@NonNull Document document, @NonNull Node node) {
|
||||
assert node instanceof Footnote;
|
||||
return ((Footnote) node).getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowDelimiters(@NotNull BasedSequence chars, @NotNull Document document,
|
||||
@NotNull Node node) {
|
||||
public boolean allowDelimiters(@NonNull BasedSequence chars, @NonNull Document document,
|
||||
@NonNull Node node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNodeElements(@NotNull Document document, @NotNull Node node) {
|
||||
public void updateNodeElements(@NonNull Document document, @NonNull Node node) {
|
||||
|
||||
}
|
||||
|
||||
public static class Factory implements LinkRefProcessorFactory {
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public LinkRefProcessor apply(@NotNull Document document) {
|
||||
public LinkRefProcessor apply(@NonNull Document document) {
|
||||
return new FootnoteLinkRefProcessor(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getWantExclamationPrefix(@NotNull DataHolder options) {
|
||||
public boolean getWantExclamationPrefix(@NonNull DataHolder options) {
|
||||
return WANT_EXCLAMATION_PREFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBracketNestingLevel(@NotNull DataHolder options) {
|
||||
public int getBracketNestingLevel(@NonNull DataHolder options) {
|
||||
return BRACKET_NESTING_LEVEL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import run.halo.app.utils.footnotes.Footnote;
|
||||
import run.halo.app.utils.footnotes.FootnoteBlock;
|
||||
import run.halo.app.utils.footnotes.FootnoteExtension;
|
||||
|
@ -100,9 +100,9 @@ public class FootnoteNodeFormatter
|
|||
|
||||
public static class Factory implements NodeFormatterFactory {
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public NodeFormatter create(@NotNull DataHolder options) {
|
||||
public NodeFormatter create(@NonNull DataHolder options) {
|
||||
return new FootnoteNodeFormatter(options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.HashSet;
|
|||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import run.halo.app.utils.footnotes.Footnote;
|
||||
import run.halo.app.utils.footnotes.FootnoteBlock;
|
||||
import run.halo.app.utils.footnotes.FootnoteExtension;
|
||||
|
@ -53,8 +53,8 @@ public class FootnoteNodeRenderer implements PhasedNodeRenderer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderDocument(@NotNull NodeRendererContext context, @NotNull HtmlWriter html,
|
||||
@NotNull Document document, @NotNull RenderingPhase phase) {
|
||||
public void renderDocument(@NonNull NodeRendererContext context, @NonNull HtmlWriter html,
|
||||
@NonNull Document document, @NonNull RenderingPhase phase) {
|
||||
if (phase == RenderingPhase.BODY_TOP) {
|
||||
if (recheckUndefinedReferences) {
|
||||
// need to see if have undefined footnotes that were defined after parsing
|
||||
|
@ -171,9 +171,9 @@ public class FootnoteNodeRenderer implements PhasedNodeRenderer {
|
|||
|
||||
public static class Factory implements NodeRendererFactory {
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public NodeRenderer apply(@NotNull DataHolder options) {
|
||||
public NodeRenderer apply(@NonNull DataHolder options) {
|
||||
return new FootnoteNodeRenderer(options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
import run.halo.app.utils.footnotes.Footnote;
|
||||
import run.halo.app.utils.footnotes.FootnoteBlock;
|
||||
import run.halo.app.utils.footnotes.FootnoteExtension;
|
||||
|
@ -79,19 +79,19 @@ public class FootnoteRepository extends NodeRepository<FootnoteBlock> {
|
|||
super(FootnoteExtension.FOOTNOTES_KEEP.get(options));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public DataKey<FootnoteRepository> getDataKey() {
|
||||
return FootnoteExtension.FOOTNOTES;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public DataKey<KeepType> getKeepDataKey() {
|
||||
return FootnoteExtension.FOOTNOTES_KEEP;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNull
|
||||
@Override
|
||||
public Set<FootnoteBlock> getReferencedElements(Node parent) {
|
||||
HashSet<FootnoteBlock> references = new HashSet<>();
|
||||
|
|
Loading…
Reference in New Issue