Skip to content

Commit

Permalink
Add methods to identify the current OS to the class Platform
Browse files Browse the repository at this point in the history
Move them from the class 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 committed Sep 20, 2023
1 parent df661fe commit dd6a150
Show file tree
Hide file tree
Showing 23 changed files with 116 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;
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(Platform.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;
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(Platform.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(Platform.isWindows());

/* look for the adequate environment */
String[] devices = findAvailableDevices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
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(Platform.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(Platform.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;
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 (Platform.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 (Platform.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;
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 (Platform.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 (Platform.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 @@ -198,7 +198,7 @@ public void testInvalidProjectNames() {
}
//do some tests with invalid names
names = new String[0];
if (isWindows()) {
if (Platform.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 +221,7 @@ public void testInvalidProjectNames() {
}

//do some tests with valid names that are *almost* invalid
if (isWindows()) {
if (Platform.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 +615,7 @@ public void testProjectCreationInvalidLocation() {
* Tests creating a project whose location already exists with different case
*/
public void testProjectCreationLocationExistsWithDifferentCase() {
if (isWindows()) {
if (Platform.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;
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(Platform.isWindows());

IProject project = getWorkspace().getRoot().getProject("testFindFilesNonCanonicalPath");
ensureExistsInWorkspace(project, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ public void testValidateName() {
/* normal name */
assertTrue("1.1", getWorkspace().validateName("abcdef", IResource.FILE).isOK());
/* invalid characters (windows only) */
if (isWindows()) {
if (Platform.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 +903,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 = Platform.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 +963,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 = Platform.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;
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 (Platform.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 (!Platform.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 (Platform.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;
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 (!Platform.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 (!Platform.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 (!Platform.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;
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 (!(Platform.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 (!(Platform.isLinux() && isReadOnlySupported())) {
return;
}

Expand Down Expand Up @@ -206,7 +207,7 @@ public void testDeleteOpenProjectLinux() {
* Works only for Windows.
*/
public void testDeleteClosedProjectWindows() {
if (!isWindows()) {
if (!Platform.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 (!Platform.isLinux()) {
return;
}

Expand Down Expand Up @@ -358,7 +359,7 @@ public void testDeleteClosedProjectLinux() {
* Works only for Windows.
*/
public void testDeleteFolderWindows() {
if (!isWindows()) {
if (!Platform.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 (!Platform.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;
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 (!Platform.isWindows()) {
return;
}
IPathVariableManager pvm = getWorkspace().getPathVariableManager();
Expand Down
Loading

0 comments on commit dd6a150

Please sign in to comment.