mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GT-2865: Incorporating release name into setting directory name.
This commit is contained in:
parent
1340268ffa
commit
dfd5e26376
17 changed files with 373 additions and 71 deletions
|
@ -0,0 +1,157 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.framework;
|
||||
|
||||
/**
|
||||
* Class to represent an application's unique identifier. An application identifier is made up
|
||||
* of an application name, an application version, and an application release name.
|
||||
* <pre>
|
||||
* The identifier format is (\.+) - \d\.\d(\.\d)?(\-.+)? _ (\.+)
|
||||
* name version release name
|
||||
* </pre>
|
||||
* Application names will be converted to all lowercase and application release names will be
|
||||
* converted to all uppercase.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <li>ghidra-7.4_DEV
|
||||
*/
|
||||
public class ApplicationIdentifier {
|
||||
|
||||
private String applicationName;
|
||||
private ApplicationVersion applicationVersion;
|
||||
private String applicationReleaseName;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ApplicationIdentifier} object from an {@link ApplicationProperties}.
|
||||
*
|
||||
* @param applicationProperties An {@link ApplicationProperties}.
|
||||
* @throws IllegalArgumentException if required elements from the {@link ApplicationProperties}
|
||||
* were missing or otherwise failed to parse. The exception's message has more detailed
|
||||
* information about why it failed.
|
||||
*/
|
||||
public ApplicationIdentifier(ApplicationProperties applicationProperties)
|
||||
throws IllegalArgumentException {
|
||||
applicationName = applicationProperties.getApplicationName().toLowerCase();
|
||||
if (applicationName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Application name is undefined.");
|
||||
}
|
||||
|
||||
applicationVersion = new ApplicationVersion(applicationProperties.getApplicationVersion());
|
||||
|
||||
applicationReleaseName = applicationProperties.getApplicationReleaseName().toUpperCase();
|
||||
if (applicationReleaseName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Application release name is undefined.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ApplicationIdentifier} object from the given string.
|
||||
*
|
||||
* @param identifier An identifier string.
|
||||
* @throws IllegalArgumentException if the identifier string failed to parse. The
|
||||
* exception's message has more detailed information about why it failed.
|
||||
*/
|
||||
public ApplicationIdentifier(String identifier) throws IllegalArgumentException {
|
||||
parse(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application name.
|
||||
*
|
||||
* @return The application name.
|
||||
*/
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ApplicationVersion application version}.
|
||||
*
|
||||
* @return The {@link ApplicationVersion application version}.
|
||||
*/
|
||||
public ApplicationVersion getApplicationVersion() {
|
||||
return applicationVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application release name.
|
||||
*
|
||||
* @return The application release name.
|
||||
*/
|
||||
public String getApplicationReleaseName() {
|
||||
return applicationReleaseName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return applicationName + "_" + applicationVersion + "_" + applicationReleaseName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (applicationName + applicationReleaseName).hashCode() *
|
||||
applicationVersion.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ApplicationIdentifier other = (ApplicationIdentifier) obj;
|
||||
if (!applicationName.equals(other.applicationName)) {
|
||||
return false;
|
||||
}
|
||||
if (!applicationReleaseName.equals(other.applicationReleaseName)) {
|
||||
return false;
|
||||
}
|
||||
if (!applicationVersion.equals(other.applicationVersion)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses application identifier components out of the given version string.
|
||||
*
|
||||
* @param identifier An identifier string.
|
||||
* @throws IllegalArgumentException if the identifier string failed to parse. The
|
||||
* exception's message has more detailed information about why it failed.
|
||||
*/
|
||||
private void parse(String identifier) throws IllegalArgumentException {
|
||||
if (identifier == null) {
|
||||
throw new IllegalArgumentException("Identifier is null");
|
||||
}
|
||||
|
||||
String[] identifierParts = identifier.split("_");
|
||||
if (identifierParts.length >= 3) {
|
||||
applicationName = identifierParts[0].toLowerCase();
|
||||
applicationVersion = new ApplicationVersion(identifierParts[1]);
|
||||
applicationReleaseName = identifierParts[2].toUpperCase();
|
||||
// Ignore any parts after the release name...they are not part of the identifier
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Identifier has " + identifierParts.length + " parts but 3 are required");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -105,16 +105,6 @@ public class ApplicationProperties extends Properties {
|
|||
public static final String TEST_RELEASE_PROPERTY = "application.test.release";
|
||||
public static final String RELEASE_SOURCE_PROPERTY = "application.release.source";
|
||||
|
||||
/**
|
||||
* The default application name to use if {@link #APPLICATION_NAME_PROPERTY} is undefined.
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_NAME = "NO_APP_NAME_DEFINED";
|
||||
|
||||
/**
|
||||
* The default version to use if {@link #APPLICATION_VERSION_PROPERTY} is undefined.
|
||||
*/
|
||||
private static final String DEFAULT_APPLICATION_VERSION = "0.1";
|
||||
|
||||
/**
|
||||
* Attempts to create an instance of this class by looking for the a properties file
|
||||
* with the give name in the current working directory.
|
||||
|
@ -233,12 +223,12 @@ public class ApplicationProperties extends Properties {
|
|||
/**
|
||||
* Gets the application's name.
|
||||
*
|
||||
* @return The application's name.
|
||||
* @return The application's name (empty string if undefined).
|
||||
*/
|
||||
public String getApplicationName() {
|
||||
String appName = getProperty(ApplicationProperties.APPLICATION_NAME_PROPERTY);
|
||||
if (appName == null) {
|
||||
return DEFAULT_APPLICATION_NAME;
|
||||
if (appName == null || appName.trim().isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return appName;
|
||||
}
|
||||
|
@ -246,15 +236,28 @@ public class ApplicationProperties extends Properties {
|
|||
/**
|
||||
* Gets the application's version.
|
||||
*
|
||||
* @return The application's version.
|
||||
* @return The application's version (empty string if undefined).
|
||||
*/
|
||||
public String getApplicationVersion() {
|
||||
String appVersion = getProperty(ApplicationProperties.APPLICATION_VERSION_PROPERTY);
|
||||
if (appVersion == null) {
|
||||
return DEFAULT_APPLICATION_VERSION;
|
||||
if (appVersion == null || appVersion.trim().isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return appVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application's release name.
|
||||
*
|
||||
* @return The application's release name (empty string if undefined).
|
||||
*/
|
||||
public String getApplicationReleaseName() {
|
||||
String appReleaseName = getProperty(ApplicationProperties.RELEASE_NAME_PROPERTY);
|
||||
if (appReleaseName == null || appReleaseName.trim().isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return appReleaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application's build date.
|
||||
|
@ -263,8 +266,8 @@ public class ApplicationProperties extends Properties {
|
|||
*/
|
||||
public String getApplicationBuildDate() {
|
||||
String appBuildDate = getProperty(ApplicationProperties.BUILD_DATE_PROPERTY);
|
||||
if (appBuildDate == null) {
|
||||
// Use today if property is not found
|
||||
if (appBuildDate == null || appBuildDate.trim().isEmpty()) {
|
||||
// Use today if property is not defined
|
||||
appBuildDate = new SimpleDateFormat("yyyy-MMM-dd").format(new Date());
|
||||
}
|
||||
return appBuildDate;
|
||||
|
|
|
@ -20,16 +20,20 @@ package ghidra.framework;
|
|||
* <p>
|
||||
* The version format is \d\.\d(\.\d)?(\-.+)?
|
||||
* <p>
|
||||
* Note: this class has a natural ordering that is inconsistent with equals (the <code>tag</code>
|
||||
* part of the version is disregarded in the {@link #compareTo(ApplicationVersion)} method).
|
||||
* <p>
|
||||
* Examples:
|
||||
* <li>7.4
|
||||
* <li>7.4.1
|
||||
* <li>7.4.1-DEV
|
||||
* <li>7.4.1-BETA
|
||||
*/
|
||||
public class ApplicationVersion implements Comparable<ApplicationVersion> {
|
||||
|
||||
private int major;
|
||||
private int minor;
|
||||
private int patch;
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ApplicationVersion} object from the given version string.
|
||||
|
@ -69,12 +73,30 @@ public class ApplicationVersion implements Comparable<ApplicationVersion> {
|
|||
return patch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tag.
|
||||
*
|
||||
* @return The tag. Could be the empty string.
|
||||
*/
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (patch == 0) {
|
||||
return String.format("%d.%d", major, minor);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(major);
|
||||
builder.append(".");
|
||||
builder.append(minor);
|
||||
if (patch > 0) {
|
||||
builder.append(".");
|
||||
builder.append(patch);
|
||||
}
|
||||
return String.format("%d.%d.%d", major, minor, patch);
|
||||
if (!tag.isEmpty()) {
|
||||
builder.append("-");
|
||||
builder.append(tag);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,6 +129,7 @@ public class ApplicationVersion implements Comparable<ApplicationVersion> {
|
|||
result = prime * result + major;
|
||||
result = prime * result + minor;
|
||||
result = prime * result + patch;
|
||||
result += tag.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -131,11 +154,14 @@ public class ApplicationVersion implements Comparable<ApplicationVersion> {
|
|||
if (patch != other.patch) {
|
||||
return false;
|
||||
}
|
||||
if (!tag.equals(other.tag)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the major, minor, and optional patch integers out of the given version string.
|
||||
* Parses the major, minor, patch, and tag components out of the given version string.
|
||||
*
|
||||
* @param version A version string.
|
||||
* @throws IllegalArgumentException if the version string failed to parse. The
|
||||
|
@ -146,8 +172,12 @@ public class ApplicationVersion implements Comparable<ApplicationVersion> {
|
|||
throw new IllegalArgumentException("Version is null");
|
||||
}
|
||||
|
||||
tag = "";
|
||||
int dashIndex = version.indexOf('-');
|
||||
if (dashIndex != -1) {
|
||||
if (dashIndex + 1 < version.length()) {
|
||||
tag = version.substring(dashIndex + 1);
|
||||
}
|
||||
version = version.substring(0, dashIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
|
||||
import generic.jar.ResourceFile;
|
||||
import ghidra.framework.ApplicationProperties;
|
||||
import ghidra.framework.OperatingSystem;
|
||||
import ghidra.framework.*;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.SystemUtilities;
|
||||
|
||||
|
@ -68,8 +67,7 @@ public class ApplicationUtilities {
|
|||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
Msg.error(ApplicationUtilities.class, "Invalid class path entry: " + pathEntry,
|
||||
e);
|
||||
Msg.error(ApplicationUtilities.class, "Invalid class path entry: " + pathEntry, e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -181,23 +179,25 @@ public class ApplicationUtilities {
|
|||
public static File getDefaultUserSettingsDir(ApplicationProperties applicationProperties,
|
||||
ResourceFile installationDirectory) throws FileNotFoundException {
|
||||
|
||||
String userSettingsDir = System.getProperty("user.home");
|
||||
if (userSettingsDir == null || userSettingsDir.isEmpty()) {
|
||||
String homedir = System.getProperty("user.home");
|
||||
if (homedir == null || homedir.isEmpty()) {
|
||||
throw new FileNotFoundException("System property \"user.home\" is not set!");
|
||||
}
|
||||
|
||||
String prefix =
|
||||
"." + applicationProperties.getApplicationName().replaceAll("\\s", "").toLowerCase();
|
||||
ApplicationIdentifier applicationIdentifier =
|
||||
new ApplicationIdentifier(applicationProperties);
|
||||
|
||||
File applicationParentDir = new File(userSettingsDir, prefix);
|
||||
String suffix = applicationProperties.getApplicationVersion();
|
||||
File userSettingsParentDir =
|
||||
new File(homedir, "." + applicationIdentifier.getApplicationName());
|
||||
|
||||
String userSettingsDirName = "." + applicationIdentifier;
|
||||
|
||||
if (SystemUtilities.isInDevelopmentMode()) {
|
||||
// Add the appication's installation directory name to this variable, so that each
|
||||
// Add the application's installation directory name to this variable, so that each
|
||||
// branch's project user directory is unique.
|
||||
suffix += "_location_" + installationDirectory.getName();
|
||||
userSettingsDirName += "_location_" + installationDirectory.getName();
|
||||
}
|
||||
|
||||
return new File(applicationParentDir, prefix + "-" + suffix);
|
||||
return new File(userSettingsParentDir, userSettingsDirName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue