Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added VersionUtil class and utility method for obtaining file version information #562

Merged
merged 1 commit into from
Dec 14, 2015
Merged

Conversation

mlfreeman2
Copy link
Contributor

It obtains the 'major', 'minor', 'revision', and 'build' version from a given file.
Added unit test for it - it does not require any new Win32 mappings for Version.dll

* version info could be obtained.
*/
public static int[] getFileVersionNumbers(String filePath) {
IntByReference dwDummy = new IntByReference();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning an int[], return a class - e.g.:

public class VersionInfo implements Serializable, Cloneable, Comparable<VersionInfo> {
    private static final long serialVersionUID = ...generate it via the IDE...;

    private int major = -1;
    private int minor = -1;
    private int buildNumber = -1;
    private int revision = -1;

    public VersionInfo() {
          super();
    }

    public VersionInfo(int major, int minor, int buildNumber, int release) {
        this.minor/major/build/release = ...respective parameter...
    }

    public int getMajor/Minor/BuildNumber/Release() { 
        return ...respective member...
    }

    public void setMajor/Minor/BuildNumber/Release(int value) {
        this..minor/major/build/release = value;
    }

   @Override
    public int hashCode() {
        ...
    }

   @Override
    public boolean equals(Object o) {
        ...check if null, this == o and getClass() == o.getClass()...
       return compare((VersionInfo) o) == 0;
    }

    @Override
    public int compare(VersionInfo other) {
        ..check if other is null or this...
       ...compare major/minor/build/release - in this order...
    }

    @Override
    public VersionInfo clone() {
        try {
            return getClass().cast(super.clone());
        } catch(CloneNotSupportedException e) { // unexpected
            throw new RuntimeException("Failed to clone: " + toString(), e);
        }
    }

   @Override
    public String toString() {
        return getMajor() + "." + getMinor() + "." + getBuildNumber() + "." + getRevision();
    }

}

This way one does not need to remember which index in the array is the major/minor/build/revision...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sound as an option?

  1. Change the method name to getFileVersionInfo()
  2. Return the VS_FIXEDFILEINFO that I already have in the function.
  3. Add the following four getters to VS_FIXEDFILEINFO:
        public int getFileVersionMajor() {
            return dwFileVersionMS.intValue() >>> 16;
        }

        public int getFileVersionMinor() {
            return dwFileVersionMS.intValue() & 0xffff;
        }

        public int getFileVersionRevision() {
            return dwFileVersionLS.intValue() >>> 16;
        }

        public int getFileVersionBuild() {
            return dwFileVersionLS.intValue() & 0xffff;
        }

@dblock
Copy link
Member

dblock commented Dec 14, 2015

This is great. Feel free to address @lgoldstein's minor test comments and please fix that period! (very important :)).

@mlfreeman2
Copy link
Contributor Author

@dblock, @lgoldstein - feedback should be addressed.

dblock added a commit that referenced this pull request Dec 14, 2015
added VersionUtil class and utility method for obtaining file version information
@dblock dblock merged commit 4e0388c into java-native-access:master Dec 14, 2015
@dblock
Copy link
Member

dblock commented Dec 14, 2015

Merged.

mstyura pushed a commit to mstyura/jna that referenced this pull request Sep 9, 2024
Motivation:

There are new releases of java.

Modifications:

Upgrade java versions to latest release

Result:

Use latest versions on the CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants