Merge branch 'GT-2865_ryanmkurtz_settingsdir'

This commit is contained in:
Ryan Kurtz 2019-05-23 11:52:45 -04:00
commit f190ad3635
17 changed files with 373 additions and 71 deletions

View file

@ -711,12 +711,12 @@ public class Application {
}
/**
* Returns the Release name for this build or null if unknown.
* Returns the release name for this build.
* @return the application release name.
*/
public static String getApplicationReleaseName() {
checkAppInitialized();
return app.layout.getApplicationProperties().getProperty(
ApplicationProperties.RELEASE_NAME_PROPERTY);
return app.layout.getApplicationProperties().getApplicationReleaseName();
}
/**

View file

@ -155,21 +155,32 @@ public class GenericRunInfo {
/**
* This is the same as {@link #getUserSettingsDirsByTime()} except that it doesn't include the
* current installation.
* current installation or installations with different release names.
*/
public static List<File> getPreviousApplicationSettingsDirsByTime() {
List<File> allApplicationDirs = getUserSettingsDirsByTime();
if (allApplicationDirs.isEmpty()) {
return allApplicationDirs;
}
List<File> applicationSettiingsDirs = new ArrayList<>();
File file = allApplicationDirs.get(0);
if (Application.getUserSettingsDirectory().getAbsolutePath().equals(
file.getAbsolutePath())) {
// remove the current application settings dir from the results
return allApplicationDirs.subList(1, allApplicationDirs.size());
ApplicationIdentifier myIdentifier = new ApplicationIdentifier(
Application.getApplicationLayout().getApplicationProperties());
for (File dir : getUserSettingsDirsByTime()) {
String dirName = dir.getName();
if (dirName.startsWith(".")) {
dirName = dirName.substring(1);
}
try {
ApplicationIdentifier identifier = new ApplicationIdentifier(dirName);
if (!identifier.equals(myIdentifier) &&
identifier.getApplicationReleaseName().equalsIgnoreCase(
myIdentifier.getApplicationReleaseName())) {
applicationSettiingsDirs.add(dir);
}
}
catch (IllegalArgumentException e) {
// The directory name didn't contain a valid application identifier...skip it
}
}
return allApplicationDirs;
return applicationSettiingsDirs;
}
/**

View file

@ -0,0 +1,74 @@
/* ###
* 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;
import static org.junit.Assert.*;
import org.junit.Test;
import generic.test.AbstractGenericTest;
public class ApplicationIdentifierTest extends AbstractGenericTest {
@Test
public void testApplicationPropertiesIdentifier() {
// We should be able to create an ApplicationIdentifier object from the application info
// defined in the application properties file without an exception being thrown.
new ApplicationIdentifier(Application.getApplicationLayout().getApplicationProperties());
}
@Test
public void testApplicationVersionParsing() {
ApplicationIdentifier id = new ApplicationIdentifier("Ghidra_9.0.1_public_05212019");
assertEquals(id.getApplicationName(), "ghidra");
assertEquals(id.getApplicationVersion(), new ApplicationVersion("9.0.1"));
assertEquals(id.getApplicationReleaseName(), "PUBLIC");
assertEquals(id.toString(), "ghidra_9.0.1_PUBLIC");
try {
new ApplicationIdentifier("ghidra");
fail(
"Should not be able to parse only a name...a version and release name are required.");
}
catch (IllegalArgumentException e) {
// Getting here indicates success
}
try {
new ApplicationIdentifier("ghidra_9.0.1");
fail(
"Should not be able to parse only a name and version...a release name is required.");
}
catch (IllegalArgumentException e) {
// Getting here indicates success
}
}
@Test
public void testApplicationIdentifierEquals() {
ApplicationIdentifier id1 = new ApplicationIdentifier("ghidra_9.0_public");
ApplicationIdentifier id2 = new ApplicationIdentifier("Ghidra_9.0.0_PUBLIC");
assertEquals(id1, id2);
id1 = new ApplicationIdentifier("ghidra_9.0_public");
id2 = new ApplicationIdentifier("Ghidra_9.0.1_PUBLIC");
assertNotEquals(id1, id2);
id1 = new ApplicationIdentifier("ghidra_9.0_DEV");
id2 = new ApplicationIdentifier("ghidra_9.0_PUBLIC");
assertNotEquals(id1, id2);
}
}

View file

@ -35,11 +35,11 @@ public class ApplicationVersionTest extends AbstractGenericTest {
public void testApplicationVersionParsing() {
assertEquals(new ApplicationVersion("9.0").toString(), "9.0");
assertEquals(new ApplicationVersion("9.0.0").toString(), "9.0");
assertEquals(new ApplicationVersion("9.0.0-DEV").toString(), "9.0");
assertEquals(new ApplicationVersion("9.0.0-BETA").toString(), "9.0-BETA");
assertEquals(new ApplicationVersion("9.1").toString(), "9.1");
assertEquals(new ApplicationVersion("9.1.1").toString(), "9.1.1");
assertEquals(new ApplicationVersion("9.1.1-DEV").toString(), "9.1.1");
assertEquals(new ApplicationVersion("9.1.1-BETA").toString(), "9.1.1-BETA");
try {
new ApplicationVersion("9");
@ -52,16 +52,35 @@ public class ApplicationVersionTest extends AbstractGenericTest {
@Test
public void testApplicationVersionGetters() {
ApplicationVersion applicationVersion = new ApplicationVersion("9.0.1-DEV");
ApplicationVersion applicationVersion = new ApplicationVersion("9.0.1-BETA");
assertEquals(applicationVersion.getMajor(), 9);
assertEquals(applicationVersion.getMinor(), 0);
assertEquals(applicationVersion.getPatch(), 1);
}
@Test
public void testApplicationVersionEquals() {
ApplicationVersion applicationVersion1 = new ApplicationVersion("9.0");
ApplicationVersion applicationVersion2 = new ApplicationVersion("9.0.0");
assertTrue(applicationVersion1.equals(applicationVersion2));
applicationVersion1 = new ApplicationVersion("9.0");
applicationVersion2 = new ApplicationVersion("9.0.0-BETA");
assertFalse(applicationVersion1.equals(applicationVersion2));
applicationVersion1 = new ApplicationVersion("9.0.0");
applicationVersion2 = new ApplicationVersion("9.0.1");
assertFalse(applicationVersion1.equals(applicationVersion2));
applicationVersion1 = new ApplicationVersion("9.0");
applicationVersion2 = new ApplicationVersion("10.0");
assertNotEquals(applicationVersion1, applicationVersion2);
}
@Test
public void testApplicationVersionCompare() {
ApplicationVersion applicationVersion1 = new ApplicationVersion("9.0");
ApplicationVersion applicationVersion2 = new ApplicationVersion("9.0.0-DEV");
ApplicationVersion applicationVersion2 = new ApplicationVersion("9.0.0-BETA");
assertTrue(applicationVersion1.compareTo(applicationVersion2) == 0);
applicationVersion1 = new ApplicationVersion("9.0");