Skip to content

Commit

Permalink
Feat: Support Version
Browse files Browse the repository at this point in the history
  • Loading branch information
LinShunKang committed Aug 9, 2020
1 parent 8293482 commit a5cbb5e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 97 deletions.
31 changes: 9 additions & 22 deletions MyPerf4J-ASM/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<index>true</index>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Premain-Class>cn.myperf4j.asm.PreMain</Premain-Class>
<Specification-Version>${project.version}</Specification-Version>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
Expand Down
2 changes: 0 additions & 2 deletions MyPerf4J-ASM/src/main/resources/META-INF/MANIFEST.MF

This file was deleted.

36 changes: 0 additions & 36 deletions MyPerf4J-Base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,4 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
33 changes: 33 additions & 0 deletions MyPerf4J-Base/src/main/java/cn/myperf4j/base/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cn.myperf4j.base;

import cn.myperf4j.base.util.Logger;
import cn.myperf4j.base.util.StrUtils;

/**
* Created by LinShunkang on 2020/08/09
*/
public final class Version {

private static final String VERSION = getVersion(Version.class, "");

public static String getVersion() {
return VERSION;
}

public static String getVersion(Class<?> cls, String defaultVersion) {
try {
String version = cls.getPackage().getImplementationVersion();
if (StrUtils.isBlank(version)) {
version = cls.getPackage().getSpecificationVersion();
}
return StrUtils.isBlank(version) ? defaultVersion : version;
} catch (Throwable e) {
Logger.error("Version.getVersion(" + cls + ", " + defaultVersion + "): catch Exception ", e);
return defaultVersion;
}
}

private Version() {
//empty
}
}
36 changes: 0 additions & 36 deletions MyPerf4J-Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,4 @@
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.myperf4j.core;

import cn.myperf4j.base.Version;
import cn.myperf4j.base.config.BasicConfig;
import cn.myperf4j.base.config.FilterConfig;
import cn.myperf4j.base.config.InfluxDbConfig;
Expand Down Expand Up @@ -420,6 +421,6 @@ private void printBannerText() {
" / /|_/ / / / / /_/ / _ \\/ ___/ /_/ // /___ / / " + LINE_SEPARATOR +
" / / / / /_/ / ____/ __/ / / __/__ __/ /_/ / " + LINE_SEPARATOR +
"/_/ /_/\\__, /_/ \\___/_/ /_/ /_/ \\____/ " + LINE_SEPARATOR +
" /____/ " + LINE_SEPARATOR);
" /____/ v" + Version.getVersion() + LINE_SEPARATOR);
}
}

0 comments on commit a5cbb5e

Please sign in to comment.