Browse Source

Issue-#428: Read product version from .properties resource, which reflects the value defined in pom.xml.

pull/432/head
Hiroshi Ukai 1 year ago
parent
commit
a119c87857
3 changed files with 25 additions and 7 deletions
  1. 7
    1
      pom.xml
  2. 17
    6
      src/main/java/javassist/CtClass.java
  3. 1
    0
      src/main/resources/.properties

+ 7
- 1
pom.xml View File

@@ -7,7 +7,7 @@
Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation
simple. It is a class library for editing bytecodes in Java.
</description>
<version>3.29.2-GA</version>
<version>3.29.3-GA-SNAPSHOT</version>
<name>Javassist</name>
<url>http://www.javassist.org/</url>

@@ -138,6 +138,12 @@
</snapshotRepository>
</distributionManagement>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

+ 17
- 6
src/main/java/javassist/CtClass.java View File

@@ -26,6 +26,7 @@ import java.io.OutputStream;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Collection;
import java.util.Properties;

import javassist.bytecode.ClassFile;
import javassist.bytecode.Descriptor;
@@ -69,7 +70,7 @@ public abstract class CtClass {
/**
* The version number of this release.
*/
public static final String version = "3.29.2-GA";
public static final String version = readProductVersion();

/**
* Prints the version number and the copyright notice.
@@ -583,7 +584,7 @@ public abstract class CtClass {
* For decoding, use <code>javassist.Modifier</code>.
*
* <p>If the class is a static nested class (a.k.a. static inner class),
* the returned modifiers include <code>Modifier.STATIC</code>.
* the returned modifiers include <code>Modifier.STATIC</code>.
*
* @see Modifier
*/
@@ -785,7 +786,7 @@ public abstract class CtClass {
/**
* Returns the immediately enclosing method of this class.
* This method works only with JDK 1.5 or later.
*
*
* @return null if this class is not a local class or an anonymous
* class.
* @deprecated The enclosing method might be a constructor.
@@ -818,7 +819,7 @@ public abstract class CtClass {
/**
* Makes a new public nested class. If this method is called,
* the <code>CtClass</code>, which encloses the nested class, is modified
* since a class file includes a list of nested classes.
* since a class file includes a list of nested classes.
*
* <p>The current implementation only supports a static nested class.
* <code>isStatic</code> must be true.
@@ -1443,7 +1444,7 @@ public abstract class CtClass {
* <p>If <code>ClassPool.doPruning</code> is true, the automatic pruning
* is on by default. Otherwise, it is off. The default value of
* <code>ClassPool.doPruning</code> is false.
*
*
* @param stop disallow pruning if true. Otherwise, allow.
* @return the previous status of pruning. true if pruning is already stopped.
*
@@ -1467,7 +1468,7 @@ public abstract class CtClass {
*
* <p><code>toBytecode()</code>, <code>writeFile()</code>, and
* <code>toClass()</code> internally call this method if
* automatic pruning is on.
* automatic pruning is on.
*
* <p>According to some experiments, pruning does not really reduce
* memory consumption. Only about 20%. Since pruning takes time,
@@ -1685,4 +1686,14 @@ public abstract class CtClass {
* This method is overridden by CtClassType.
*/
void compress() {}

private static String readProductVersion() {
try {
final Properties properties = new Properties();
properties.load(CtClass.class.getClassLoader().getResourceAsStream(".properties"));
return properties.getProperty("product.version");
} catch (IOException e) {
throw new RuntimeException("Failed to a resource '.properties' from the classpath. (Packaging issue)", e);
}
}
}

+ 1
- 0
src/main/resources/.properties View File

@@ -0,0 +1 @@
product.version=${project.version}

Loading…
Cancel
Save