mirror of https://github.com/halo-dev/halo
Enable code style check available (#590)
* Add check style plugin and remove halo code style * Reformat codes for whole project * Resolve conflicts due to provided checkstyle.xmlpull/593/head
parent
c224b68fbc
commit
e8db12a93d
|
@ -1,7 +1,7 @@
|
|||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.2.RELEASE'
|
||||
id "io.freefair.lombok" version "3.6.6"
|
||||
// id 'war'
|
||||
id 'checkstyle'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://checkstyle.org/dtds/configuration_1_3.dtd">
|
||||
<!--Refer http://checkstyle.sourceforge.net/reports/google-java-style.html#s2.2-file-encoding -->
|
||||
<module name="Checker">
|
||||
|
||||
<property name="localeLanguage" value="en"/>
|
||||
|
||||
<!--To configure the check to report on the first instance in each file-->
|
||||
<module name="FileTabCharacter"/>
|
||||
|
||||
<module name="RegexpSingleline">
|
||||
<property name="format" value="System\.out"/>
|
||||
<property name="message" value="Prohibit invoking System.out in source code !"/>
|
||||
</module>
|
||||
|
||||
<module name="FileLength">
|
||||
<property name="max" value="3000"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="RedundantImport"/>
|
||||
|
||||
<!--Checks that classes that override equals() also override hashCode()-->
|
||||
<module name="EqualsHashCode"/>
|
||||
<!--Checks for over-complicated boolean expressions. Currently finds code like if (topic == true), topic || true, !false, etc.-->
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<module name="OneStatementPerLine"/>
|
||||
<module name="UnnecessaryParentheses"/>
|
||||
<!--Checks for over-complicated boolean return statements. For example the following code-->
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
|
||||
<!--Check that the default is after all the cases in producerGroup switch statement-->
|
||||
<module name="DefaultComesLast"/>
|
||||
<!--Detects empty statements (standalone ";" semicolon)-->
|
||||
<module name="EmptyStatement"/>
|
||||
<!--Checks that long constants are defined with an upper ell-->
|
||||
<module name="UpperEll"/>
|
||||
<module name="ConstantName">
|
||||
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)|(^logger)"/>
|
||||
</module>
|
||||
<!--Checks that local, non-final variable names conform to producerGroup format specified by the format property-->
|
||||
<module name="LocalVariableName"/>
|
||||
<!--Validates identifiers for local, final variables, including catch parameters-->
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<!--Validates identifiers for non-static fields-->
|
||||
<module name="MemberName"/>
|
||||
<!--Validates identifiers for class type parameters-->
|
||||
<module name="ClassTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)"/>
|
||||
</module>
|
||||
<!--Validates identifiers for method type parameters-->
|
||||
<module name="MethodTypeParameterName">
|
||||
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)"/>
|
||||
</module>
|
||||
<module name="PackageName">
|
||||
<property name="format" value="^run\.halo(\.[a-zA-Z][a-zA-Z0-9]*)+$"/>
|
||||
</module>
|
||||
<module name="ParameterName"/>
|
||||
<module name="StaticVariableName">
|
||||
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)"/>
|
||||
</module>
|
||||
<module name="TypeName">
|
||||
<property name="format" value="(^[A-Z][a-zA-Z0-9]*$)|(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)"/>
|
||||
</module>
|
||||
|
||||
<!--whitespace-->
|
||||
<module name="GenericWhitespace"/>
|
||||
<module name="NoWhitespaceBefore"/>
|
||||
<module name="NoWhitespaceAfter"/>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors" value="true"/>
|
||||
<property name="allowEmptyMethods" value="true"/>
|
||||
</module>
|
||||
<module name="Indentation"/>
|
||||
<module name="MethodParamPad"/>
|
||||
<module name="ParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
<module name="TypecastParenPad"/>
|
||||
|
||||
</module>
|
||||
|
||||
</module>
|
|
@ -1,26 +0,0 @@
|
|||
<code_scheme name="halo" version="173">
|
||||
<DBN-PSQL>
|
||||
<case-options enabled="true">
|
||||
<option name="KEYWORD_CASE" value="lower" />
|
||||
<option name="FUNCTION_CASE" value="lower" />
|
||||
<option name="PARAMETER_CASE" value="lower" />
|
||||
<option name="DATATYPE_CASE" value="lower" />
|
||||
<option name="OBJECT_CASE" value="preserve" />
|
||||
</case-options>
|
||||
<formatting-settings enabled="false" />
|
||||
</DBN-PSQL>
|
||||
<DBN-SQL>
|
||||
<case-options enabled="true">
|
||||
<option name="KEYWORD_CASE" value="lower" />
|
||||
<option name="FUNCTION_CASE" value="lower" />
|
||||
<option name="PARAMETER_CASE" value="lower" />
|
||||
<option name="DATATYPE_CASE" value="lower" />
|
||||
<option name="OBJECT_CASE" value="preserve" />
|
||||
</case-options>
|
||||
<formatting-settings enabled="false">
|
||||
<option name="STATEMENT_SPACING" value="one_line" />
|
||||
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
|
||||
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
||||
</formatting-settings>
|
||||
</DBN-SQL>
|
||||
</code_scheme>
|
|
@ -25,14 +25,14 @@ import run.halo.app.repository.base.BaseRepositoryImpl;
|
|||
@EnableJpaRepositories(basePackages = "run.halo.app.repository", repositoryBaseClass = BaseRepositoryImpl.class)
|
||||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
private static ConfigurableApplicationContext CONTEXT;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Customize the spring config location
|
||||
System.setProperty("spring.config.additional-location", "file:${user.home}/.halo/,file:${user.home}/halo-dev/");
|
||||
|
||||
// Run application
|
||||
context = SpringApplication.run(Application.class, args);
|
||||
CONTEXT = SpringApplication.run(Application.class, args);
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,11 +40,11 @@ public class Application extends SpringBootServletInitializer {
|
|||
* Restart Application.
|
||||
*/
|
||||
public static void restart() {
|
||||
ApplicationArguments args = context.getBean(ApplicationArguments.class);
|
||||
ApplicationArguments args = CONTEXT.getBean(ApplicationArguments.class);
|
||||
|
||||
Thread thread = new Thread(() -> {
|
||||
context.close();
|
||||
context = SpringApplication.run(Application.class, args.getSourceArgs());
|
||||
CONTEXT.close();
|
||||
CONTEXT = SpringApplication.run(Application.class, args.getSourceArgs());
|
||||
});
|
||||
|
||||
thread.setDaemon(false);
|
||||
|
|
|
@ -28,8 +28,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
*/
|
||||
private final static long PERIOD = 60 * 1000;
|
||||
|
||||
private static DB leveldb;
|
||||
|
||||
private static DB LEVEL_DB;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
|
@ -38,7 +37,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
if (leveldb != null) return;
|
||||
if (LEVEL_DB != null) return;
|
||||
try {
|
||||
//work path
|
||||
File folder = new File(haloProperties.getWorkDir() + ".leveldb");
|
||||
|
@ -46,7 +45,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
Options options = new Options();
|
||||
options.createIfMissing(true);
|
||||
//open leveldb store folder
|
||||
leveldb = factory.open(folder, options);
|
||||
LEVEL_DB = factory.open(folder, options);
|
||||
timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new CacheExpiryCleaner(), 0, PERIOD);
|
||||
} catch (Exception ex) {
|
||||
|
@ -60,7 +59,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
try {
|
||||
leveldb.close();
|
||||
LEVEL_DB.close();
|
||||
timer.cancel();
|
||||
} catch (IOException e) {
|
||||
log.error("close leveldb error ", e);
|
||||
|
@ -70,7 +69,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
@Override
|
||||
Optional<CacheWrapper<String>> getInternal(String key) {
|
||||
Assert.hasText(key, "Cache key must not be blank");
|
||||
byte[] bytes = leveldb.get(stringToBytes(key));
|
||||
byte[] bytes = LEVEL_DB.get(stringToBytes(key));
|
||||
if (bytes != null) {
|
||||
String valueJson = bytesToString(bytes);
|
||||
return StringUtils.isEmpty(valueJson) ? Optional.empty() : jsonToCacheWrapper(valueJson);
|
||||
|
@ -88,7 +87,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
Assert.hasText(key, "Cache key must not be blank");
|
||||
Assert.notNull(cacheWrapper, "Cache wrapper must not be null");
|
||||
try {
|
||||
leveldb.put(
|
||||
LEVEL_DB.put(
|
||||
stringToBytes(key),
|
||||
stringToBytes(JsonUtils.objectToJson(cacheWrapper))
|
||||
);
|
||||
|
@ -102,7 +101,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
|
||||
@Override
|
||||
public void delete(String key) {
|
||||
leveldb.delete(stringToBytes(key));
|
||||
LEVEL_DB.delete(stringToBytes(key));
|
||||
log.debug("cache remove key: [{}]", key);
|
||||
}
|
||||
|
||||
|
@ -132,9 +131,9 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
@Override
|
||||
public void run() {
|
||||
//batch
|
||||
WriteBatch writeBatch = leveldb.createWriteBatch();
|
||||
WriteBatch writeBatch = LEVEL_DB.createWriteBatch();
|
||||
|
||||
DBIterator iterator = leveldb.iterator();
|
||||
DBIterator iterator = LEVEL_DB.iterator();
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<byte[], byte[]> next = iterator.next();
|
||||
|
@ -156,7 +155,7 @@ public class LevelCacheStore extends StringCacheStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
leveldb.write(writeBatch);
|
||||
LEVEL_DB.write(writeBatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ public class WebMvcAutoConfiguration extends WebMvcConfigurationSupport {
|
|||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.stream()
|
||||
.filter(c -> c instanceof MappingJackson2HttpMessageConverter)
|
||||
.findFirst().ifPresent(converter -> {
|
||||
.findFirst()
|
||||
.ifPresent(converter -> {
|
||||
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = (MappingJackson2HttpMessageConverter) converter;
|
||||
Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
|
||||
JsonComponentModule module = new JsonComponentModule();
|
||||
|
|
|
@ -72,7 +72,7 @@ public class LinkController {
|
|||
}
|
||||
|
||||
@GetMapping("teams")
|
||||
@ApiOperation(("Lists all link teams"))
|
||||
@ApiOperation("Lists all link teams")
|
||||
public List<String> teams() {
|
||||
return linkService.listAllTeams();
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class MenuController {
|
|||
}
|
||||
|
||||
@GetMapping("teams")
|
||||
@ApiOperation(("Lists all menu teams"))
|
||||
@ApiOperation("Lists all menu teams")
|
||||
public List<String> teams() {
|
||||
return menuService.listAllTeams();
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class CommonResultControllerAdvice implements ResponseBodyAdvice<Object>
|
|||
* additional serialization instructions) or simply cast it if already wrapped.
|
||||
*/
|
||||
private MappingJacksonValue getOrCreateContainer(Object body) {
|
||||
return (body instanceof MappingJacksonValue ? (MappingJacksonValue) body : new MappingJacksonValue(body));
|
||||
return body instanceof MappingJacksonValue ? (MappingJacksonValue) body : new MappingJacksonValue(body);
|
||||
}
|
||||
|
||||
private void beforeBodyWriteInternal(MappingJacksonValue bodyContainer,
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Map;
|
|||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@RestControllerAdvice({"run.halo.app.controller.admin.api", "run.halo.app.controller.content.api"})
|
||||
@RestControllerAdvice(value = {"run.halo.app.controller.admin.api", "run.halo.app.controller.content.api"})
|
||||
@Slf4j
|
||||
public class ControllerExceptionHandler {
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class LogFilter extends OncePerRequestFilter {
|
|||
// Do filter
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
log.debug("Ending url: [{}], method: [{}], ip: [{}], status: [{}], usage: [{}] ms", request.getRequestURL(), request.getMethod(), remoteAddr, response.getStatus(), (System.currentTimeMillis() - startTime));
|
||||
log.debug("Ending url: [{}], method: [{}], ip: [{}], status: [{}], usage: [{}] ms", request.getRequestURL(), request.getMethod(), remoteAddr, response.getStatus(), System.currentTimeMillis() - startTime);
|
||||
log.debug("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.springframework.lang.Nullable;
|
|||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import run.halo.app.exception.FileOperationException;
|
||||
import run.halo.app.model.enums.AttachmentType;
|
||||
import run.halo.app.model.support.UploadResult;
|
||||
|
||||
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.handler.file;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -189,7 +190,8 @@ public class SmmsFileHandler implements FileHandler {
|
|||
|
||||
private SmmsResponseData data;
|
||||
|
||||
private String RequestId;
|
||||
@JsonProperty("RequestId")
|
||||
private String requestId;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.lang.annotation.*;
|
|||
* @author guqing
|
||||
* @date 2020-1-19 13:51
|
||||
*/
|
||||
@Target({ElementType.FIELD, ElementType.TYPE})
|
||||
@Target(value = {ElementType.FIELD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface PropertyMappingTo {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class YamlThemeConfigResolverImpl implements ThemeConfigResolver {
|
|||
return;
|
||||
}
|
||||
|
||||
Map tabMap = ((Map) tabYaml);
|
||||
Map tabMap = (Map) tabYaml;
|
||||
|
||||
Group group = new Group();
|
||||
|
||||
|
|
|
@ -29,15 +29,10 @@ import java.util.concurrent.Executors;
|
|||
public abstract class AbstractMailService implements MailService {
|
||||
|
||||
private static final int DEFAULT_POOL_SIZE = 5;
|
||||
|
||||
private JavaMailSender cachedMailSender;
|
||||
|
||||
private MailProperties cachedMailProperties;
|
||||
|
||||
private String cachedFromName;
|
||||
|
||||
protected final OptionService optionService;
|
||||
|
||||
private JavaMailSender cachedMailSender;
|
||||
private MailProperties cachedMailProperties;
|
||||
private String cachedFromName;
|
||||
@Nullable
|
||||
private ExecutorService executorService;
|
||||
|
||||
|
@ -45,10 +40,6 @@ public abstract class AbstractMailService implements MailService {
|
|||
this.optionService = optionService;
|
||||
}
|
||||
|
||||
public void setExecutorService(ExecutorService executorService) {
|
||||
this.executorService = executorService;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ExecutorService getExecutorService() {
|
||||
if (this.executorService == null) {
|
||||
|
@ -57,6 +48,10 @@ public abstract class AbstractMailService implements MailService {
|
|||
return executorService;
|
||||
}
|
||||
|
||||
public void setExecutorService(ExecutorService executorService) {
|
||||
this.executorService = executorService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connection with email server.
|
||||
*/
|
||||
|
|
|
@ -34,15 +34,15 @@ public class MailProperties extends org.springframework.boot.autoconfigure.mail.
|
|||
properties.put(key, value);
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final String lineSuffix = ",\n";
|
||||
|
|
|
@ -56,7 +56,7 @@ public class MailServiceImpl extends AbstractMailService implements ApplicationL
|
|||
|
||||
@Override
|
||||
public void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachFilePath) {
|
||||
sendMailTemplate(true, (messageHelper) -> {
|
||||
sendMailTemplate(true, messageHelper -> {
|
||||
messageHelper.setSubject(subject);
|
||||
messageHelper.setTo(to);
|
||||
Path attachmentPath = Paths.get(attachFilePath);
|
||||
|
|
|
@ -13,8 +13,7 @@ public enum BanStatusEnum {
|
|||
/**
|
||||
* 封禁状态
|
||||
*/
|
||||
NORMAL(0),
|
||||
;
|
||||
NORMAL(0);
|
||||
|
||||
private int status;
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ public enum CommentViolationTypeEnum {
|
|||
/**
|
||||
* 频繁
|
||||
*/
|
||||
FREQUENTLY(1),
|
||||
;
|
||||
FREQUENTLY(1);
|
||||
|
||||
private int type;
|
||||
|
||||
|
|
|
@ -20,40 +20,6 @@ import java.util.Map;
|
|||
public interface PropertyEnum extends ValueEnum<String> {
|
||||
|
||||
|
||||
/**
|
||||
* Get property type.
|
||||
*
|
||||
* @return property type
|
||||
*/
|
||||
Class<?> getType();
|
||||
|
||||
/**
|
||||
* Default value.
|
||||
*
|
||||
* @return default value
|
||||
*/
|
||||
@Nullable
|
||||
String defaultValue();
|
||||
|
||||
/**
|
||||
* Default value with given type.
|
||||
*
|
||||
* @param propertyType property type must not be null
|
||||
* @param <T> property type
|
||||
* @return default value with given type
|
||||
*/
|
||||
@Nullable
|
||||
default <T> T defaultValue(Class<T> propertyType) {
|
||||
// Get default value
|
||||
String defaultValue = defaultValue();
|
||||
if (defaultValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Convert to the given type
|
||||
return PropertyEnum.convertTo(defaultValue, propertyType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to value with corresponding type
|
||||
*
|
||||
|
@ -160,8 +126,10 @@ public interface PropertyEnum extends ValueEnum<String> {
|
|||
* @return true if supports; false else
|
||||
*/
|
||||
static boolean isSupportedType(Class<?> type) {
|
||||
return type != null && (
|
||||
type.isAssignableFrom(String.class)
|
||||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
return type.isAssignableFrom(String.class)
|
||||
|| type.isAssignableFrom(Number.class)
|
||||
|| type.isAssignableFrom(Integer.class)
|
||||
|| type.isAssignableFrom(Long.class)
|
||||
|
@ -171,8 +139,7 @@ public interface PropertyEnum extends ValueEnum<String> {
|
|||
|| type.isAssignableFrom(Double.class)
|
||||
|| type.isAssignableFrom(Float.class)
|
||||
|| type.isAssignableFrom(Enum.class)
|
||||
|| type.isAssignableFrom(ValueEnum.class)
|
||||
);
|
||||
|| type.isAssignableFrom(ValueEnum.class);
|
||||
}
|
||||
|
||||
static Map<String, PropertyEnum> getValuePropertyEnumMap() {
|
||||
|
@ -209,4 +176,38 @@ public interface PropertyEnum extends ValueEnum<String> {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property type.
|
||||
*
|
||||
* @return property type
|
||||
*/
|
||||
Class<?> getType();
|
||||
|
||||
/**
|
||||
* Default value.
|
||||
*
|
||||
* @return default value
|
||||
*/
|
||||
@Nullable
|
||||
String defaultValue();
|
||||
|
||||
/**
|
||||
* Default value with given type.
|
||||
*
|
||||
* @param propertyType property type must not be null
|
||||
* @param <T> property type
|
||||
* @return default value with given type
|
||||
*/
|
||||
@Nullable
|
||||
default <T> T defaultValue(Class<T> propertyType) {
|
||||
// Get default value
|
||||
String defaultValue = defaultValue();
|
||||
if (defaultValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Convert to the given type
|
||||
return PropertyEnum.convertTo(defaultValue, propertyType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package run.halo.app.model.support;
|
||||
|
||||
import javax.validation.GroupSequence;
|
||||
|
||||
/**
|
||||
* All check for hibernate validation.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-28
|
||||
*/
|
||||
@GroupSequence({CreateCheck.class, UpdateCheck.class})
|
||||
public interface AllCheck {
|
||||
}
|
|
@ -31,9 +31,9 @@ public class AuthenticationArgumentResolver implements HandlerMethodArgumentReso
|
|||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> parameterType = parameter.getParameterType();
|
||||
return (Authentication.class.isAssignableFrom(parameterType) ||
|
||||
UserDetail.class.isAssignableFrom(parameterType) ||
|
||||
User.class.isAssignableFrom(parameterType));
|
||||
return Authentication.class.isAssignableFrom(parameterType)
|
||||
|| UserDetail.class.isAssignableFrom(parameterType)
|
||||
|| User.class.isAssignableFrom(parameterType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -89,7 +89,6 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
|||
*
|
||||
* @param postId post id must not be null
|
||||
* @param pageable page info must not be null
|
||||
* @param status status must not be null
|
||||
* @return a page of comment vo
|
||||
*/
|
||||
@NonNull
|
||||
|
@ -153,12 +152,12 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
|||
/**
|
||||
* Creates a comment by comment.
|
||||
*
|
||||
* @param COMMENT comment must not be null
|
||||
* @param comment comment must not be null
|
||||
* @return created comment
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
COMMENT create(@NonNull COMMENT COMMENT);
|
||||
COMMENT create(@NonNull COMMENT comment);
|
||||
|
||||
/**
|
||||
* Creates a comment by comment param.
|
||||
|
|
|
@ -51,7 +51,7 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
|||
|
||||
private final OptionService optionService;
|
||||
|
||||
private final Pattern SUMMARY_PATTERN = Pattern.compile("\\s*|\t|\r|\n");
|
||||
private final Pattern summaryPattern = Pattern.compile("\\s*|\t|\r|\n");
|
||||
|
||||
public BasePostServiceImpl(BasePostRepository<POST> basePostRepository,
|
||||
OptionService optionService) {
|
||||
|
@ -468,7 +468,7 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
|||
|
||||
String text = HaloUtils.cleanHtmlTag(htmlContent);
|
||||
|
||||
Matcher matcher = SUMMARY_PATTERN.matcher(text);
|
||||
Matcher matcher = summaryPattern.matcher(text);
|
||||
text = matcher.replaceAll("");
|
||||
|
||||
// Get summary length
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.Optional;
|
|||
@Service
|
||||
@Slf4j
|
||||
public class CommentBlackListServiceImpl extends AbstractCrudService<CommentBlackList, Long> implements CommentBlackListService {
|
||||
private static ZoneId zoneId = ZoneId.of("Asia/Shanghai");
|
||||
private static final ZoneId ZONE_ID = ZoneId.of("Asia/Shanghai");
|
||||
private final CommentBlackListRepository commentBlackListRepository;
|
||||
private final PostCommentRepository postCommentRepository;
|
||||
private final OptionService optionService;
|
||||
|
@ -50,10 +50,10 @@ public class CommentBlackListServiceImpl extends AbstractCrudService<CommentBlac
|
|||
*/
|
||||
Optional<CommentBlackList> blackList = commentBlackListRepository.findByIpAddress(ipAddress);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Date endTime = new Date(now.atZone(zoneId).toInstant().toEpochMilli());
|
||||
Date endTime = new Date(now.atZone(ZONE_ID).toInstant().toEpochMilli());
|
||||
Integer banTime = optionService.getByPropertyOrDefault(CommentProperties.COMMENT_BAN_TIME, Integer.class, 10);
|
||||
Date startTime = new Date(now.minusMinutes(banTime)
|
||||
.atZone(zoneId).toInstant().toEpochMilli());
|
||||
.atZone(ZONE_ID).toInstant().toEpochMilli());
|
||||
Integer range = optionService.getByPropertyOrDefault(CommentProperties.COMMENT_RANGE, Integer.class, 30);
|
||||
boolean isPresent = postCommentRepository.countByIpAndTime(ipAddress, startTime, endTime) >= range;
|
||||
if (isPresent && blackList.isPresent()) {
|
||||
|
@ -79,6 +79,6 @@ public class CommentBlackListServiceImpl extends AbstractCrudService<CommentBlac
|
|||
}
|
||||
|
||||
private Date getBanTime(LocalDateTime localDateTime, Integer banTime) {
|
||||
return new Date(localDateTime.plusMinutes(banTime).atZone(zoneId).toInstant().toEpochMilli());
|
||||
return new Date(localDateTime.plusMinutes(banTime).atZone(ZONE_ID).toInstant().toEpochMilli());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,8 +87,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
PostCategoryService postCategoryService,
|
||||
PostCommentService postCommentService,
|
||||
ApplicationEventPublisher eventPublisher,
|
||||
PostMetaService postMetaService,
|
||||
OptionService optionService1) {
|
||||
PostMetaService postMetaService) {
|
||||
super(basePostRepository, optionService);
|
||||
this.postRepository = postRepository;
|
||||
this.tagService = tagService;
|
||||
|
@ -98,7 +97,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
this.postCommentService = postCommentService;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.postMetaService = postMetaService;
|
||||
this.optionService = optionService1;
|
||||
this.optionService = optionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -280,7 +279,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
Calendar calendar = DateUtils.convertTo(post.getCreateTime());
|
||||
|
||||
yearMonthPostMap.computeIfAbsent(calendar.get(Calendar.YEAR), year -> new HashMap<>())
|
||||
.computeIfAbsent((calendar.get(Calendar.MONTH) + 1),
|
||||
.computeIfAbsent(calendar.get(Calendar.MONTH) + 1,
|
||||
month -> new LinkedList<>())
|
||||
.add(post);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
@ -30,6 +31,7 @@ import java.util.stream.Stream;
|
|||
* @date 2019-12-06
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class StaticStorageServiceImpl implements StaticStorageService {
|
||||
|
||||
private final Path staticDir;
|
||||
|
@ -90,7 +92,7 @@ public class StaticStorageServiceImpl implements StaticStorageService {
|
|||
Assert.notNull(relativePath, "Relative path must not be null");
|
||||
|
||||
Path path = Paths.get(staticDir.toString(), relativePath);
|
||||
System.out.println(path.toString());
|
||||
log.debug(path.toString());
|
||||
|
||||
try {
|
||||
if (path.toFile().isDirectory()) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ServletUtils {
|
|||
public static Optional<HttpServletRequest> getCurrentRequest() {
|
||||
return Optional.ofNullable(RequestContextHolder.getRequestAttributes())
|
||||
.filter(requestAttributes -> requestAttributes instanceof ServletRequestAttributes)
|
||||
.map(requestAttributes -> ((ServletRequestAttributes) requestAttributes))
|
||||
.map(requestAttributes -> (ServletRequestAttributes) requestAttributes)
|
||||
.map(ServletRequestAttributes::getRequest);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ public class VersionUtil {
|
|||
}
|
||||
|
||||
public static int[] getCanonicalVersion(String version) {
|
||||
int[] canonicalVersion = new int[]{1, 1, 0, 0};
|
||||
int[] canonicalVersion = new int[] {1, 1, 0, 0};
|
||||
StringTokenizer tokenizer = new StringTokenizer(version, ".");
|
||||
String token = tokenizer.nextToken();
|
||||
canonicalVersion[0] = Integer.parseInt(token);
|
||||
|
|
|
@ -14,10 +14,10 @@ spring:
|
|||
password: 123456
|
||||
|
||||
# MySQL database configuration.
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
# username: root
|
||||
# password: 123456
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
# username: root
|
||||
# password: 123456
|
||||
|
||||
# H2 database console configuration.
|
||||
h2:
|
||||
|
|
|
@ -30,14 +30,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@AutoConfigureMockMvc
|
||||
class DisableOnConditionAspectTest {
|
||||
|
||||
static final String REQUEST_URI = "/api/admin/test/disableOnCondition";
|
||||
@Autowired
|
||||
MockMvc mvc;
|
||||
|
||||
@Autowired
|
||||
OptionService optionService;
|
||||
|
||||
static final String REQUEST_URI = "/api/admin/test/disableOnCondition";
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
optionService.saveProperty(PrimaryProperties.IS_INSTALLED, "true");
|
||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.handler.theme;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import run.halo.app.handler.theme.config.support.ThemeProperty;
|
||||
|
||||
|
@ -11,6 +12,7 @@ import java.io.IOException;
|
|||
* @author johnniang
|
||||
* @date 4/11/19
|
||||
*/
|
||||
@Slf4j
|
||||
public class YamlThemePropertyResolverTest {
|
||||
|
||||
private final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
|
||||
|
@ -29,6 +31,6 @@ public class YamlThemePropertyResolverTest {
|
|||
|
||||
ThemeProperty themeProperty = yamlMapper.readValue(yaml, ThemeProperty.class);
|
||||
|
||||
System.out.println(themeProperty);
|
||||
log.debug("[{}]", themeProperty);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package run.halo.app.model;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import run.halo.app.service.support.HaloMediaType;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.*;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package run.halo.app.model.enums;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Data type test.
|
||||
|
@ -11,12 +12,13 @@ import static org.junit.Assert.*;
|
|||
* @author johnniang
|
||||
* @date 19-4-21
|
||||
*/
|
||||
@Slf4j
|
||||
public class DataTypeTest {
|
||||
|
||||
@Test
|
||||
public void typeOf() {
|
||||
DataType type = DataType.typeOf("bool");
|
||||
System.out.println(type);
|
||||
log.debug("[{}]", type);
|
||||
assertThat(type, equalTo(DataType.BOOL));
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package run.halo.app.model.params;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import run.halo.app.model.support.AllCheck;
|
||||
import run.halo.app.model.support.CreateCheck;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package run.halo.app.repository;
|
||||
|
||||
import run.halo.app.model.entity.Sheet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import run.halo.app.model.entity.Sheet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,6 +20,7 @@ import java.util.List;
|
|||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
@Slf4j
|
||||
public class SheetRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -27,6 +29,6 @@ public class SheetRepositoryTest {
|
|||
@Test
|
||||
public void listAllTest() {
|
||||
List<Sheet> allSheets = sheetRepository.findAll();
|
||||
System.out.println(allSheets);
|
||||
log.debug("{}", allSheets);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,14 +21,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@AutoConfigureMockMvc
|
||||
class OneTimeTokenTest {
|
||||
|
||||
static final String REQUEST_URI = "/api/admin/counts";
|
||||
@Autowired
|
||||
MockMvc mvc;
|
||||
|
||||
@Autowired
|
||||
OneTimeTokenService oneTimeTokenService;
|
||||
|
||||
static final String REQUEST_URI = "/api/admin/counts";
|
||||
|
||||
@Test
|
||||
void provideNonExistOneTimeTokenTest() throws Exception {
|
||||
mvc.perform(get(REQUEST_URI + "?ott={ott}", "one-time-token-value"))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
@Slf4j
|
||||
public class PostServiceImplTest {
|
||||
|
||||
private String standardMdContent = "---\n" +
|
||||
|
@ -42,7 +44,7 @@ public class PostServiceImplTest {
|
|||
@Ignore
|
||||
public void getContent() {
|
||||
String exportMarkdown = postService.exportMarkdown(18);
|
||||
System.out.println(exportMarkdown);
|
||||
log.debug(exportMarkdown);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -9,11 +10,12 @@ import org.junit.Test;
|
|||
* @author johnniang
|
||||
* @date 3/28/19
|
||||
*/
|
||||
@Slf4j
|
||||
public class BcryptTest {
|
||||
|
||||
@Test
|
||||
public void cryptTest() {
|
||||
String cryptPassword = BCrypt.hashpw("opentest", BCrypt.gensalt());
|
||||
System.out.println("Crypt password: " + cryptPassword);
|
||||
log.debug("Crypt password: [{}]", cryptPassword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ package run.halo.app.utils;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* BeanUtils test.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import run.halo.app.exception.ForbiddenException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
|
@ -14,6 +14,7 @@ import java.nio.file.Paths;
|
|||
* @author johnniang
|
||||
* @date 4/9/19
|
||||
*/
|
||||
@Slf4j
|
||||
public class DirectoryAttackTest {
|
||||
|
||||
private String userHome = System.getProperty("user.home");
|
||||
|
@ -25,8 +26,8 @@ public class DirectoryAttackTest {
|
|||
|
||||
Path testPath = Paths.get(userHome + "/../../etc/passwd");
|
||||
|
||||
System.out.println("Work directory path: " + workDirPath);
|
||||
System.out.println("Test path: " + testPath);
|
||||
log.debug("Work directory path: [{}]", workDirPath);
|
||||
log.debug("Test path: [{}]", testPath);
|
||||
|
||||
Assert.assertFalse(testPath.startsWith(workDirPath));
|
||||
Assert.assertFalse(workDirPath.startsWith(testPath));
|
||||
|
@ -38,8 +39,8 @@ public class DirectoryAttackTest {
|
|||
|
||||
Path testPath = Paths.get(userHome + "/halo-test/test.txt");
|
||||
|
||||
System.out.println("Work directory path: " + workDirPath);
|
||||
System.out.println("Test path: " + testPath);
|
||||
log.debug("Work directory path: [{}]", workDirPath);
|
||||
log.debug("Test path: [{}]", testPath);
|
||||
|
||||
Assert.assertTrue(testPath.startsWith(workDirPath));
|
||||
Assert.assertFalse(workDirPath.startsWith(testPath));
|
||||
|
@ -52,8 +53,8 @@ public class DirectoryAttackTest {
|
|||
|
||||
Path testPath = Paths.get("/etc/passwd");
|
||||
|
||||
System.out.println("Work directory path: " + workDirPath);
|
||||
System.out.println("Test path: " + testPath);
|
||||
log.debug("Work directory path: [{}]", workDirPath);
|
||||
log.debug("Test path: [{}]", testPath);
|
||||
|
||||
Assert.assertTrue(testPath.startsWith(workDirPath));
|
||||
Assert.assertFalse(workDirPath.startsWith(testPath));
|
||||
|
@ -64,10 +65,10 @@ public class DirectoryAttackTest {
|
|||
String pathname = "/home/test/../../etc/";
|
||||
Path path = Paths.get(pathname);
|
||||
|
||||
System.out.println("Path: " + path);
|
||||
System.out.println("Absolute path: " + path.toAbsolutePath());
|
||||
System.out.println("Name count: " + path.getNameCount());
|
||||
System.out.println("Normalized path: " + path.normalize());
|
||||
log.debug("Path: [{}]", path);
|
||||
log.debug("Absolute path: [{}]", path.toAbsolutePath());
|
||||
log.debug("Name count: [{}]", path.getNameCount());
|
||||
log.debug("Normalized path: [{}]", path.normalize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -37,25 +37,25 @@ public class FileUtilsTest {
|
|||
|
||||
try (Stream<Path> pathStream = Files.walk(tempDirectory)) {
|
||||
List<Path> walkList = pathStream.collect(Collectors.toList());
|
||||
walkList.forEach(System.out::println);
|
||||
walkList.forEach(path -> log.debug(path.toString()));
|
||||
Assert.assertThat(walkList.size(), equalTo(4));
|
||||
}
|
||||
|
||||
try (Stream<Path> pathStream = Files.walk(tempDirectory, 1)) {
|
||||
List<Path> walkList = pathStream.collect(Collectors.toList());
|
||||
walkList.forEach(System.out::println);
|
||||
walkList.forEach(path -> log.debug(path.toString()));
|
||||
Assert.assertThat(walkList.size(), equalTo(2));
|
||||
}
|
||||
|
||||
try (Stream<Path> pathStream = Files.list(tempDirectory)) {
|
||||
List<Path> walkList = pathStream.collect(Collectors.toList());
|
||||
walkList.forEach(System.out::println);
|
||||
walkList.forEach(path -> log.debug(path.toString()));
|
||||
Assert.assertThat(walkList.size(), equalTo(1));
|
||||
}
|
||||
|
||||
try (Stream<Path> pathStream = Files.list(testPath)) {
|
||||
List<Path> walkList = pathStream.collect(Collectors.toList());
|
||||
walkList.forEach(System.out::println);
|
||||
walkList.forEach(path -> log.debug(path.toString()));
|
||||
Assert.assertThat(walkList.size(), equalTo(0));
|
||||
}
|
||||
|
||||
|
@ -103,9 +103,9 @@ public class FileUtilsTest {
|
|||
randomAccessFile.seek(2283640);
|
||||
byte[] buffer = new byte[1024];
|
||||
int count = randomAccessFile.read(buffer, 0, buffer.length);
|
||||
System.out.println("Count: " + count);
|
||||
log.debug("Count: [{}]", count);
|
||||
String bufString = new String(buffer);
|
||||
System.out.println("Buffer String: " + bufString);
|
||||
log.debug("Buffer String: [{}]", bufString);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,14 +7,16 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
|||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.transport.RemoteConfig;
|
||||
import org.eclipse.jgit.transport.URIish;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Git test.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -11,7 +12,6 @@ import run.halo.app.exception.BadRequestException;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -25,14 +25,12 @@ import java.util.Map;
|
|||
* @date 19-5-21
|
||||
*/
|
||||
@Ignore
|
||||
@Slf4j
|
||||
public class GithubTest {
|
||||
|
||||
private final Path tempPath;
|
||||
|
||||
private final static String API_URL = "https://api.github.com/repos/halo-dev/halo-admin/releases/latest";
|
||||
|
||||
private final static String HALO_ADMIN_REGEX = "halo-admin-\\d+\\.\\d+(\\.\\d+)?(-\\S*)?\\.zip";
|
||||
|
||||
private final Path tempPath;
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public GithubTest() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
|
||||
|
@ -44,10 +42,10 @@ public class GithubTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void getLatestReleaseTest() throws Throwable {
|
||||
ResponseEntity<Map> responseEntity = restTemplate.getForEntity(API_URL, Map.class);
|
||||
System.out.println("Response: " + responseEntity);
|
||||
log.debug("Response: " + responseEntity);
|
||||
Object assetsObject = responseEntity.getBody().get("assets");
|
||||
System.out.println("Assets class: " + assetsObject.getClass());
|
||||
System.out.println("Assets: " + assetsObject);
|
||||
log.debug("Assets class: " + assetsObject.getClass());
|
||||
log.debug("Assets: " + assetsObject);
|
||||
if (assetsObject instanceof List) {
|
||||
List assets = (List) assetsObject;
|
||||
Map assetMap = (Map) assets.stream().filter(aAsset -> {
|
||||
|
@ -65,11 +63,11 @@ public class GithubTest {
|
|||
Object browserDownloadUrl = assetMap.getOrDefault("browser_download_url", "");
|
||||
// Download the assets
|
||||
ResponseEntity<byte[]> downloadResponseEntity = restTemplate.getForEntity(browserDownloadUrl.toString(), byte[].class);
|
||||
System.out.println("Download response entity status: " + downloadResponseEntity.getStatusCode());
|
||||
log.debug("Download response entity status: " + downloadResponseEntity.getStatusCode());
|
||||
|
||||
Path downloadedPath = Files.write(tempPath.resolve(name.toString()), downloadResponseEntity.getBody());
|
||||
|
||||
System.out.println("Downloaded path: " + downloadedPath.toString());
|
||||
log.debug("Downloaded path: " + downloadedPath.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
@ -10,14 +11,15 @@ import java.net.UnknownHostException;
|
|||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Slf4j
|
||||
public class InetAddressTest {
|
||||
|
||||
@Test
|
||||
public void getMachaineAddressTest() throws UnknownHostException {
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
System.out.println("Localhost: " + localHost.getHostAddress());
|
||||
log.debug("Localhost: " + localHost.getHostAddress());
|
||||
|
||||
InetAddress loopbackAddress = InetAddress.getLoopbackAddress();
|
||||
System.out.println("Loopback: " + loopbackAddress.getHostAddress());
|
||||
log.debug("Loopback: " + loopbackAddress.getHostAddress());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ public class LocalDateTimeTest {
|
|||
LocalDateTime dateTime = LocalDateTime.now();
|
||||
log.debug(dateTime.toString());
|
||||
log.debug(dateTime.toLocalDate().toString());
|
||||
String DATE_FORMATTER = "yyyy-MM-dd-HH-mm-ss-";
|
||||
log.debug(dateTime.format(DateTimeFormatter.ofPattern(DATE_FORMATTER)));
|
||||
String dateFormatter = "yyyy-MM-dd-HH-mm-ss-";
|
||||
log.debug(dateTime.format(DateTimeFormatter.ofPattern(dateFormatter)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -14,6 +15,7 @@ import java.nio.file.Paths;
|
|||
* @author johnniang
|
||||
* @date 19-5-20
|
||||
*/
|
||||
@Slf4j
|
||||
public class PathTest {
|
||||
|
||||
@Test(expected = FileSystemNotFoundException.class)
|
||||
|
@ -22,6 +24,6 @@ public class PathTest {
|
|||
URI uri = new URI(file);
|
||||
Path path = Paths.get(uri);
|
||||
|
||||
System.out.println("Path: " + path.toString());
|
||||
log.debug("Path: " + path.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package run.halo.app.utils;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import run.halo.app.model.dto.base.InputConverter;
|
||||
import run.halo.app.model.params.BaseCommentParam;
|
||||
import run.halo.app.model.params.JournalCommentParam;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -9,6 +10,7 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
* @author johnniang
|
||||
* @date 3/20/19
|
||||
*/
|
||||
@Slf4j
|
||||
public class SlugUtilsTest {
|
||||
|
||||
@Test
|
||||
|
@ -29,6 +31,6 @@ public class SlugUtilsTest {
|
|||
public void nullSlugTest() {
|
||||
String slug = SlugUtils.slug("+/~!@#$%^&*()_+");
|
||||
|
||||
System.out.println("slug:" + slug);
|
||||
log.debug("slug:" + slug);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -10,13 +11,14 @@ import java.util.concurrent.TimeUnit;
|
|||
* @author johnniang
|
||||
* @date 19-4-29
|
||||
*/
|
||||
@Slf4j
|
||||
public class TimeUnitTest {
|
||||
|
||||
@Test
|
||||
public void convertTest() {
|
||||
Long millis = TimeUnit.DAYS.toMillis(30);
|
||||
|
||||
System.out.println(millis);
|
||||
System.out.println(millis.intValue());
|
||||
log.debug("" + millis);
|
||||
log.debug("" + millis.intValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -11,12 +12,13 @@ import java.net.URISyntaxException;
|
|||
* @author johnniang
|
||||
* @date 3/26/19
|
||||
*/
|
||||
@Slf4j
|
||||
public class URITest {
|
||||
|
||||
@Test
|
||||
public void createURITest() throws URISyntaxException {
|
||||
String homeDir = System.getProperty("user.home");
|
||||
URI uri = new URI(homeDir);
|
||||
System.out.println(uri);
|
||||
log.debug("[{}]", uri);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import run.halo.app.handler.migrate.converter.Converter;
|
||||
|
@ -20,25 +21,24 @@ import java.util.List;
|
|||
* @author guqing
|
||||
* @date 2020-01-18 14:02
|
||||
*/
|
||||
@Slf4j
|
||||
public class XmlMigrateUtilsTest {
|
||||
|
||||
@Test
|
||||
void testXmlMigrateUtils() throws IOException, URISyntaxException {
|
||||
JSONObject json = readXml();
|
||||
System.out.println("WordPress blog json data:" + json);
|
||||
log.debug("WordPress blog json data:" + json);
|
||||
Rss rss = json.getObject("rss", Rss.class);
|
||||
// System.out.println(rss);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWordPressConvert() throws IOException, URISyntaxException {
|
||||
JSONObject json = readXml();
|
||||
Rss rss = json.getObject("rss", Rss.class);
|
||||
// System.out.println("WordPress blog rss data:" + rss);
|
||||
Converter<Rss, List<PostVO>> converter = new WordPressConverter();
|
||||
List<PostVO> postVoList = converter.convertFrom(rss);
|
||||
|
||||
System.out.println(postVoList);
|
||||
log.debug("{}", postVoList);
|
||||
}
|
||||
|
||||
private JSONObject readXml() throws IOException, URISyntaxException {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package run.halo.app.utils;
|
||||
|
||||
import org.junit.Test;
|
||||
import run.halo.app.handler.theme.config.support.Group;
|
||||
import run.halo.app.handler.theme.config.impl.YamlThemeConfigResolverImpl;
|
||||
import run.halo.app.handler.theme.config.support.Group;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0"
|
||||
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
|
||||
<rss xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:wp="http://wordpress.org/export/1.2/"
|
||||
version="2.0"
|
||||
>
|
||||
<channel>
|
||||
<title>WordPress Demo</title>
|
||||
|
|
Loading…
Reference in New Issue