提交 7b64118a 编写于 作者: Z zhourui

update version with git.

上级 5a6be422
......@@ -391,6 +391,10 @@
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
......@@ -812,7 +816,7 @@
<dependency>
<groupId>com.hankcs</groupId>
<artifactId>hanlp</artifactId>
<version>portable-1.7.4</version>
<version>portable-1.8.3</version>
</dependency>
<dependency>
<groupId>de.vandermeer</groupId>
......@@ -1104,6 +1108,11 @@
<artifactId>swagger-jaxrs2</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.2.0.202206071550-r</version>
</dependency>
</dependencies>
</dependencyManagement>
<!--repositories>
......
......@@ -2,33 +2,60 @@ package com.x.base.core.project.build;
import java.io.File;
import java.io.FileReader;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.eclipse.jgit.api.DescribeCommand;
import org.eclipse.jgit.api.Git;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.DefaultCharset;
public class CreateVersion {
public static void main(String... args) throws Exception {
File base = new File(args[0]);
File file = new File(base, "version.o2");
File pom = new File(base, "pom.xml");
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader(pom));
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put("version", model.getVersion() + "");
map.put("date", DateTools.format(new Date()));
Map<String, String> map = fromGit(base);
if (map.isEmpty()) {
map = fromMaven(base);
}
FileUtils.write(file, XGsonBuilder.toJson(map), StandardCharsets.UTF_8);
System.exit(0);
}
FileUtils.write(file, XGsonBuilder.toJson(map), DefaultCharset.charset_utf_8);
private static Map<String, String> fromGit(File base) {
Map<String, String> map = new LinkedHashMap<>();
File dir = base.getParentFile().getAbsoluteFile();
try (Git git = Git.init().setDirectory(dir).call()) {
DescribeCommand describeCommand = git.describe().setTags(true).setAlways(true);
String version = describeCommand.call();
map.put("version", version);
map.put("date", DateTools.format(new Date()));
return map;
} catch (Exception e) {
e.printStackTrace();
}
return new LinkedHashMap<>();
}
private static Map<String, String> fromMaven(File base) {
Map<String, String> map = new LinkedHashMap<>();
try {
File pom = new File(base, "pom.xml");
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader(pom));
map.put("version", model.getVersion() + "");
map.put("date", DateTools.format(new Date()));
return map;
} catch (Exception e) {
e.printStackTrace();
}
return new LinkedHashMap<>();
}
}
......@@ -25,47 +25,9 @@ public class PackageO2server {
public static void main(String... args) throws Exception {
File base = new File(args[0]).getParentFile();
createO2Version(base.getAbsolutePath());
CreateConfigSample.main(base.getAbsolutePath());
CreateLocalSample.main(base.getAbsolutePath());
CreateVersion.main(base.getAbsolutePath());
}
public static void compress(ZipOutputStream outputStream, String base, String path) throws Exception {
File file = new File(base, path);
if (!file.exists()) {
System.out.println("file or directory not exist:" + path + ".");
return;
}
if (file.isFile()) {
outputStream.putNextEntry(new ZipEntry(path));
byte[] bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
outputStream.write(bytes, 0, bytes.length);
} else if (file.isDirectory()) {
Path b = Paths.get(base);
Files.walkFileTree(Paths.get(file.getAbsolutePath()), new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) {
try {
Path p = b.relativize(file);
outputStream.putNextEntry(new ZipEntry(p.toString()));
byte[] bytes = Files.readAllBytes(file);
outputStream.write(bytes, 0, bytes.length);
} catch (IOException e) {
e.printStackTrace();
}
return FileVisitResult.CONTINUE;
}
});
}
}
public static void createO2Version(String base) throws Exception {
File file = new File(base, "version.o2");
FileUtils.write(file, DateTools.format(new Date(), DateTools.format_yyyyMMddHHmmss),
DefaultCharset.charset_utf_8);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册