forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support theme require halo version. (halo-dev#544)
* feat: support theme require halo version. * fix: com.sun.xml.internal.ws.util does not exist error. * fix: com.sun.xml.internal.ws.util does not exist error again. * Update ThemeServiceImpl.java
- Loading branch information
Showing
7 changed files
with
175 additions
and
24 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/run/halo/app/exception/ThemeNotSupportException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package run.halo.app.exception; | ||
|
||
/** | ||
* Theme not support exception. | ||
* | ||
* @author ryanwang | ||
* @date 2020-02-03 | ||
*/ | ||
public class ThemeNotSupportException extends BadRequestException { | ||
|
||
public ThemeNotSupportException(String message) { | ||
super(message); | ||
} | ||
|
||
public ThemeNotSupportException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package run.halo.app.utils; | ||
|
||
import cn.hutool.core.util.StrUtil; | ||
|
||
import java.util.StringTokenizer; | ||
|
||
/** | ||
* @author ryanwang | ||
* @date 2020-02-03 | ||
* @see com.sun.xml.internal.ws.util.VersionUtil | ||
*/ | ||
public class VersionUtil { | ||
|
||
public VersionUtil() { | ||
} | ||
|
||
public static int[] getCanonicalVersion(String version) { | ||
int[] canonicalVersion = new int[]{1, 1, 0, 0}; | ||
StringTokenizer tokenizer = new StringTokenizer(version, "."); | ||
String token = tokenizer.nextToken(); | ||
canonicalVersion[0] = Integer.parseInt(token); | ||
token = tokenizer.nextToken(); | ||
StringTokenizer subTokenizer; | ||
if (!token.contains(StrUtil.UNDERLINE)) { | ||
canonicalVersion[1] = Integer.parseInt(token); | ||
} else { | ||
subTokenizer = new StringTokenizer(token, "_"); | ||
canonicalVersion[1] = Integer.parseInt(subTokenizer.nextToken()); | ||
canonicalVersion[3] = Integer.parseInt(subTokenizer.nextToken()); | ||
} | ||
|
||
if (tokenizer.hasMoreTokens()) { | ||
token = tokenizer.nextToken(); | ||
if (!token.contains(StrUtil.UNDERLINE)) { | ||
canonicalVersion[2] = Integer.parseInt(token); | ||
if (tokenizer.hasMoreTokens()) { | ||
canonicalVersion[3] = Integer.parseInt(tokenizer.nextToken()); | ||
} | ||
} else { | ||
subTokenizer = new StringTokenizer(token, "_"); | ||
canonicalVersion[2] = Integer.parseInt(subTokenizer.nextToken()); | ||
canonicalVersion[3] = Integer.parseInt(subTokenizer.nextToken()); | ||
} | ||
} | ||
|
||
return canonicalVersion; | ||
} | ||
|
||
public static int compare(String version1, String version2) { | ||
int[] canonicalVersion1 = getCanonicalVersion(version1); | ||
int[] canonicalVersion2 = getCanonicalVersion(version2); | ||
if (canonicalVersion1[0] < canonicalVersion2[0]) { | ||
return -1; | ||
} else if (canonicalVersion1[0] > canonicalVersion2[0]) { | ||
return 1; | ||
} else if (canonicalVersion1[1] < canonicalVersion2[1]) { | ||
return -1; | ||
} else if (canonicalVersion1[1] > canonicalVersion2[1]) { | ||
return 1; | ||
} else if (canonicalVersion1[2] < canonicalVersion2[2]) { | ||
return -1; | ||
} else if (canonicalVersion1[2] > canonicalVersion2[2]) { | ||
return 1; | ||
} else if (canonicalVersion1[3] < canonicalVersion2[3]) { | ||
return -1; | ||
} else { | ||
return canonicalVersion1[3] > canonicalVersion2[3] ? 1 : 0; | ||
} | ||
} | ||
|
||
/** | ||
* Compare version. | ||
* | ||
* @param current current version. | ||
* @param require require version. | ||
* @return true or false. | ||
*/ | ||
public static boolean compareVersion(String current, String require) { | ||
return compare(current, require) >= 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package run.halo.app.utils; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author ryanwang | ||
* @date 2020-02-03 | ||
*/ | ||
public class VersionUtilTest { | ||
|
||
@Test | ||
public void compareVersion() { | ||
Assert.assertTrue(VersionUtil.compareVersion("1.2.0", "1.1.1")); | ||
|
||
Assert.assertTrue(VersionUtil.compareVersion("1.2.1", "1.2.0")); | ||
|
||
Assert.assertTrue(VersionUtil.compareVersion("1.2.0", "1.1.1.0")); | ||
|
||
Assert.assertTrue(VersionUtil.compareVersion("1.2.0", "0.4.4")); | ||
|
||
Assert.assertFalse(VersionUtil.compareVersion("1.1.1", "1.2.0")); | ||
|
||
Assert.assertFalse(VersionUtil.compareVersion("0.0.1", "1.2.0")); | ||
} | ||
} |