Skip to content

Commit

Permalink
Add methods to identify the OS in a new internal class: Platform.OS
Browse files Browse the repository at this point in the history
Remove the 3 methods "isXYZ()"  from
org.eclipse.core.tests.resources.ResourceTest
to stop fostering inheritance just to be able to reuse these methods.

Contributes to
#448
  • Loading branch information
fedejeanne authored and HeikoKlare committed Sep 29, 2023
1 parent 113cae1 commit 6b9f8a0
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileSystem;
import org.eclipse.core.tests.resources.ResourceTest;
import org.junit.Assume;
Expand Down Expand Up @@ -263,7 +264,7 @@ public void testBug156082() throws CoreException {
*/
@Test
public void testBug198571() {
Assume.assumeTrue(isWindows());
Assume.assumeTrue(OS.isWindows());

/* look for the adequate environment */
String[] devices = findAvailableDevices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;
import org.junit.Assume;
import org.junit.Test;
Expand All @@ -49,7 +50,7 @@ public String[] defineHierarchy() {
*/
@Test
public void testMoveFileAcrossVolumes() {
Assume.assumeTrue(isWindows());
Assume.assumeTrue(OS.isWindows());

/* look for the adequate environment */
String[] devices = findAvailableDevices();
Expand Down Expand Up @@ -171,7 +172,7 @@ public void testMoveFileBetweenProjects() throws Exception {
*/
@Test
public void testMoveFolderAcrossVolumes() {
Assume.assumeTrue(isWindows());
Assume.assumeTrue(OS.isWindows());

/* look for the adequate environment */
String[] devices = findAvailableDevices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.resources.ResourceTest;
import org.xml.sax.InputSource;

public class ModelObjectReaderWriterTest extends ResourceTest {
static final IPath LONG_LOCATION = IPath.fromOSString("/eclipse/dev/i0218/eclipse/pffds/fds//fds///fdsfsdfsd///fdsfdsf/fsdfsdfsd/lugi/dsds/fsd//f/ffdsfdsf/fsdfdsfsd/fds//fdsfdsfdsf/fdsfdsfds/fdsfdsfdsf/fdsfdsfdsds/ns/org.eclipse.help.ui_2.1.0/contexts.xml").setDevice(isWindows() ? "D:" : null);
static final IPath LONG_LOCATION = IPath.fromOSString("/eclipse/dev/i0218/eclipse/pffds/fds//fds///fdsfsdfsd///fdsfdsf/fsdfsdfsd/lugi/dsds/fsd//f/ffdsfdsf/fsdfdsfsd/fds//fdsfdsfdsf/fdsfdsfds/fdsfdsfdsf/fdsfdsfdsds/ns/org.eclipse.help.ui_2.1.0/contexts.xml").setDevice(OS.isWindows() ? "D:" : null);
static final URI LONG_LOCATION_URI = LONG_LOCATION.toFile().toURI();
private static final String PATH_STRING = IPath.fromOSString("/abc/def").setDevice(isWindows() ? "D:" : null).toString();
private static final String PATH_STRING = IPath.fromOSString("/abc/def").setDevice(OS.isWindows() ? "D:" : null).toString();

private HashMap<String, ProjectDescription> buildBaselineDescriptors() {
HashMap<String, ProjectDescription> result = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.harness.FussyProgressMonitor;
import org.junit.Test;
Expand Down Expand Up @@ -1019,7 +1020,7 @@ public void testInvalidFileNames() {

//do some tests with invalid names
names = new String[0];
if (isWindows()) {
if (OS.isWindows()) {
//invalid windows names
names = new String[] {"a ", "foo::bar", "prn", "nul", "con", "aux", "clock$", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "AUX", "con.foo", "LPT4.txt", "*", "?", "\"", "<", ">", "|"};
} else {
Expand All @@ -1041,7 +1042,7 @@ public void testInvalidFileNames() {
}

//do some tests with valid names that are *almost* invalid
if (isWindows()) {
if (OS.isWindows()) {
//these names are valid on windows
names = new String[] {" a", "hello.prn.txt", "null", "con3", "foo.aux", "lpt0", "com0", "com10", "lpt10", ",", "'", ";", "clock$.class"};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;

public class IFolderTest extends ResourceTest {
Expand Down Expand Up @@ -315,7 +316,7 @@ public void testInvalidFolderNames() {

//do some tests with invalid names
String[] names = new String[0];
if (isWindows()) {
if (OS.isWindows()) {
//invalid windows names
names = new String[] {"prn", "nul", "con", "aux", "clock$", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "AUX", "con.foo", "LPT4.txt", "*", "?", "\"", "<", ">", "|"};
} else {
Expand All @@ -336,7 +337,7 @@ public void testInvalidFolderNames() {
}

//do some tests with valid names that are *almost* invalid
if (isWindows()) {
if (OS.isWindows()) {
//these names are valid on windows
names = new String[] {"hello.prn.txt", "null", "con3", "foo.aux", "lpt0", "com0", "com10", "lpt10", ",", "'", ";"};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.tests.harness.FussyProgressMonitor;
Expand Down Expand Up @@ -198,7 +199,7 @@ public void testInvalidProjectNames() {
}
//do some tests with invalid names
names = new String[0];
if (isWindows()) {
if (OS.isWindows()) {
//invalid windows names
names = new String[] {"foo:bar", "prn", "nul", "con", "aux", "clock$", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", "AUX", "con.foo", "LPT4.txt", "*", "?", "\"", "<", ">", "|", "::"};
}
Expand All @@ -221,7 +222,7 @@ public void testInvalidProjectNames() {
}

//do some tests with valid names that are *almost* invalid
if (isWindows()) {
if (OS.isWindows()) {
//these names are valid on windows
names = new String[] {"hello.prn.txt", "null", "con3", "foo.aux", "lpt0", "com0", "com10", "lpt10", ",", "'", ";"};
} else {
Expand Down Expand Up @@ -615,7 +616,7 @@ public void testProjectCreationInvalidLocation() {
* Tests creating a project whose location already exists with different case
*/
public void testProjectCreationLocationExistsWithDifferentCase() {
if (isWindows()) {
if (OS.isWindows()) {
String projectName = getUniqueString() + "a";
IProject project = getWorkspace().getRoot().getProject(projectName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.tests.internal.filesystem.wrapper.WrapperFileSystem;
import org.junit.Assume;
Expand All @@ -46,7 +47,7 @@ public class IWorkspaceRootTest extends ResourceTest {
@Test
public void testFindFilesNonCanonicalPath() {
// this test is for windows only
Assume.assumeTrue(isWindows());
Assume.assumeTrue(OS.isWindows());

IProject project = getWorkspace().getRoot().getProject("testFindFilesNonCanonicalPath");
ensureExistsInWorkspace(project, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Platform.OS;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
Expand Down Expand Up @@ -822,7 +823,7 @@ public void testValidateName() {
/* normal name */
assertTrue("1.1", getWorkspace().validateName("abcdef", IResource.FILE).isOK());
/* invalid characters (windows only) */
if (isWindows()) {
if (OS.isWindows()) {
assertFalse("2.1", getWorkspace().validateName("dsa:sf", IResource.FILE).isOK());
assertFalse("2.2", getWorkspace().validateName("*dsasf", IResource.FILE).isOK());
assertFalse("2.3", getWorkspace().validateName("?dsasf", IResource.FILE).isOK());
Expand Down Expand Up @@ -903,7 +904,7 @@ public void testValidatePath() {
assertTrue("1.1", getWorkspace().validatePath("/one/two/three/four/", IResource.FILE | IResource.FOLDER).isOK());

/* invalid characters (windows only) */
final boolean WINDOWS = isWindows();
final boolean WINDOWS = OS.isWindows();
if (WINDOWS) {
assertFalse("2.1", (getWorkspace().validatePath("\\dsa:sf", IResource.FILE).isOK()));
assertFalse("2.2", (getWorkspace().validatePath("/abc/*dsasf", IResource.FILE).isOK()));
Expand Down Expand Up @@ -963,7 +964,7 @@ public void testValidateProjectLocation() {
assertTrue("1.1", workspace.validateProjectLocation(project, IPath.fromOSString("/one/two/three/four/")).isOK());

/* invalid characters (windows only) */
final boolean WINDOWS = isWindows();
final boolean WINDOWS = OS.isWindows();
if (WINDOWS) {
assertFalse("2.1", workspace.validateProjectLocation(project, IPath.fromOSString("d:\\dsa:sf")).isOK());
assertFalse("2.2", workspace.validateProjectLocation(project, IPath.fromOSString("/abc/*dsasf")).isOK());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.harness.CancelingProgressMonitor;
import org.eclipse.core.tests.harness.FussyProgressMonitor;

Expand Down Expand Up @@ -203,7 +204,7 @@ public void testAllowMissingLocal() {
}

//try to create with local path that can never exist
if (isWindows()) {
if (OS.isWindows()) {
location = IPath.fromOSString("b:\\does\\not\\exist");
} else {
location = IPath.fromOSString("/dev/null/does/not/exist");
Expand Down Expand Up @@ -1022,7 +1023,7 @@ public void testDeleteFolderWithLinks() {
*/
public void testFindFilesForLocationCaseVariant() {
//this test only applies to file systems with a device in the path
if (!isWindows()) {
if (!OS.isWindows()) {
return;
}
IFolder link = nonExistingFolderInExistingProject;
Expand Down Expand Up @@ -1455,7 +1456,7 @@ public void testValidateEmptyLinkLocation() {
*/
public void testLocationWithColon() {
//windows does not allow a location with colon in the name
if (isWindows()) {
if (OS.isWindows()) {
return;
}
IFolder folder = nonExistingFolderInExistingProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,35 +159,6 @@ protected static boolean isCaseSensitive(IResource resource) {
return ((Resource) resource).getStore().getFileSystem().isCaseSensitive();
}

/**
* Returns whether the current platform is windows.
* @return <code>true</code> if this platform is windows, and
* <code>false</code> otherwise.
*/
protected static boolean isWindows() {
return Platform.getOS().equals(Platform.OS_WIN32);
}

/**
* Returns whether the current platform is linux.
*
* @return <code>true</code> if this platform is linux, and <code>false</code>
* otherwise.
*/
protected static boolean isLinux() {
return Platform.getOS().equals(Platform.OS_LINUX);
}

/**
* Returns whether the current platform is mac OSX.
*
* @return <code>true</code> if this platform is mac OSX, and <code>false</code>
* otherwise.
*/
protected static boolean isMacOSX() {
return Platform.getOS().equals(Platform.OS_MACOSX);
}

/**
* Convenience method to copy contents from one stream to another.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.InputStream;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.resources.ResourceTest;

/**
Expand All @@ -31,7 +32,7 @@ public class Bug_025457 extends ResourceTest {

public void testFile() {
//this test only works on windows
if (!isWindows()) {
if (!OS.isWindows()) {
return;
}
IProject source = getWorkspace().getRoot().getProject("project");
Expand Down Expand Up @@ -77,7 +78,7 @@ public void testFile() {
public void testFolder() {
//this test only works on windows
//native code must also be present so move can detect the case change
if (!isWindows() || !isReadOnlySupported()) {
if (!OS.isWindows() || !isReadOnlySupported()) {
return;
}
IProject source = getWorkspace().getRoot().getProject("SourceProject");
Expand Down Expand Up @@ -120,7 +121,7 @@ public void testFolder() {

public void testProject() {
//this test only works on windows
if (!isWindows()) {
if (!OS.isWindows()) {
return;
}
IProject source = getWorkspace().getRoot().getProject("project");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.tests.resources.ResourceTest;

/**
Expand All @@ -37,7 +38,7 @@ public class Bug_026294 extends ResourceTest {
* Works only for Windows.
*/
public void testDeleteOpenProjectWindows() {
if (!(isWindows())) {
if (!(OS.isWindows())) {
return;
}

Expand Down Expand Up @@ -138,7 +139,7 @@ public void testDeleteOpenProjectWindows() {
* Works only for Linux with natives.
*/
public void testDeleteOpenProjectLinux() {
if (!(isLinux() && isReadOnlySupported())) {
if (!(OS.isLinux() && isReadOnlySupported())) {
return;
}

Expand Down Expand Up @@ -206,7 +207,7 @@ public void testDeleteOpenProjectLinux() {
* Works only for Windows.
*/
public void testDeleteClosedProjectWindows() {
if (!isWindows()) {
if (!OS.isWindows()) {
return;
}

Expand Down Expand Up @@ -286,7 +287,7 @@ public void testDeleteClosedProjectWindows() {
* TODO: enable this test once bug 48321 is fixed.
*/
public void testDeleteClosedProjectLinux() {
if (!isLinux()) {
if (!OS.isLinux()) {
return;
}

Expand Down Expand Up @@ -358,7 +359,7 @@ public void testDeleteClosedProjectLinux() {
* Works only for Windows.
*/
public void testDeleteFolderWindows() {
if (!isWindows()) {
if (!OS.isWindows()) {
return;
}

Expand Down Expand Up @@ -423,7 +424,7 @@ public void testDeleteFolderWindows() {
* Works only for Linux with natives.
*/
public void testDeleteFolderLinux() {
if (!isLinux()) {
if (!OS.isLinux()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.core.resources.IPathVariableManager;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform.OS;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.tests.resources.ResourceTest;

Expand Down Expand Up @@ -55,7 +56,7 @@ private void clearPathVariablesProperties() {

public void testBug() {
//this bug is only relevant on Windows
if (!isWindows()) {
if (!OS.isWindows()) {
return;
}
IPathVariableManager pvm = getWorkspace().getPathVariableManager();
Expand Down
Loading

0 comments on commit 6b9f8a0

Please sign in to comment.