Skip to content

Commit

Permalink
Use Platform.getOS/getArch() in LocalFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Apr 22, 2024
1 parent 16fb526 commit 1012283
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

import java.io.UnsupportedEncodingException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.service.environment.Constants;

public class Convert {

/** Indicates the default native encoding on this platform */
private static String defaultEncoding = Platform.getSystemCharset().name();

/** Indicates if we are running on windows */
private static final boolean isWindows = Constants.OS_WIN32.equals(LocalFileSystem.getOS());
private static final boolean IS_WINDOWS = Platform.OS.isWindows();

private static final String WIN32_FILE_PREFIX = "\\\\?\\"; //$NON-NLS-1$
private static final String WIN32_UNC_FILE_PREFIX = "\\\\?\\UNC"; //$NON-NLS-1$
Expand Down Expand Up @@ -126,8 +125,9 @@ public static byte[] toPlatformBytes(String target) {
*/
public static char[] toPlatformChars(String target) {
//Windows use special prefix to handle long filenames
if (!isWindows)
if (!IS_WINDOWS) {
return target.toCharArray();
}
//convert UNC path of form \\server\path to unicode form \\?\UNC\server\path
if (target.startsWith("\\\\")) { //$NON-NLS-1$
int nameLength = target.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.core.internal.filesystem.local.nio.PosixHandler;
import org.eclipse.core.internal.filesystem.local.unix.UnixFileHandler;
import org.eclipse.core.internal.filesystem.local.unix.UnixFileNatives;
import org.eclipse.osgi.service.environment.Constants;
import org.eclipse.core.runtime.Platform;

/**
* <p>Dispatches methods backed by native code to the appropriate platform specific
Expand Down Expand Up @@ -59,7 +59,7 @@ public static void reset() {
*/
public static boolean setUsingNative(boolean useNatives) {
boolean nativesAreUsed;
boolean isWindowsOS = Constants.OS_WIN32.equals(LocalFileSystem.getOS());
boolean isWindowsOS = Platform.OS.isWindows();

if (useNatives && !isWindowsOS && UnixFileNatives.isUsingNatives()) {
HANDLER = new UnixFileHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.core.filesystem.IFileSystem;
import org.eclipse.core.filesystem.provider.FileSystem;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.service.environment.Constants;

/**
Expand All @@ -34,12 +35,12 @@ public class LocalFileSystem extends FileSystem {
/**
* Cached constant indicating if the current OS is Mac OSX
*/
static final boolean MACOSX = LocalFileSystem.getOS().equals(Constants.OS_MACOSX);
static final boolean MACOSX = Platform.OS.isMac();

/**
* Whether the current file system is case sensitive
*/
private static final boolean caseSensitive = MACOSX ? false : new java.io.File("a").compareTo(new java.io.File("A")) != 0; //$NON-NLS-1$ //$NON-NLS-2$
private static final boolean CASE_SENSITIVE = !MACOSX && new java.io.File("a").compareTo(new java.io.File("A")) != 0; //$NON-NLS-1$ //$NON-NLS-2$

/**
* The attributes of this file system. The initial value of -1 is used
Expand All @@ -60,25 +61,11 @@ public static IFileSystem getInstance() {
return INSTANCE;
}

/**
* Returns the current OS. This is equivalent to Platform.getOS(), but
* is tolerant of the platform runtime not being present.
*/
static String getOS() {
return System.getProperty("osgi.os", ""); //$NON-NLS-1$ //$NON-NLS-2$
}

/**
* Creates a new local file system.
*/
public LocalFileSystem() {
super();
}

@Override
public int attributes() {
if (attributes != -1)
if (attributes != -1) {
return attributes;
}
attributes = 0;

//try to query supported attributes from native lib impl
Expand All @@ -93,14 +80,14 @@ public int attributes() {
attributes |= EFS.ATTRIBUTE_READ_ONLY;

// this must be kept in sync with functionality of previous libs not implementing nativeAttributes method
String os = getOS();
String arch = System.getProperty("osgi.arch", ""); //$NON-NLS-1$ //$NON-NLS-2$
if (os.equals(Constants.OS_WIN32))
String os = Platform.getOS();
if (Constants.OS_WIN32.equals(os)) {
attributes |= EFS.ATTRIBUTE_ARCHIVE | EFS.ATTRIBUTE_HIDDEN;
else if (os.equals(Constants.OS_LINUX) || (os.equals(Constants.OS_SOLARIS) && arch.equals(Constants.ARCH_SPARC)))
} else if (Constants.OS_LINUX.equals(os) || (Constants.OS_SOLARIS.equals(os) && Constants.ARCH_SPARC.equals(Platform.getOSArch()))) {
attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET;
else if (os.equals(Constants.OS_MACOSX) || os.equals(Constants.OS_HPUX) || os.equals(Constants.OS_QNX))
} else if (Constants.OS_MACOSX.equals(os) || Constants.OS_HPUX.equals(os) || Constants.OS_QNX.equals(os)) {
attributes |= EFS.ATTRIBUTE_EXECUTABLE;
}
return attributes;
}

Expand Down Expand Up @@ -131,6 +118,6 @@ public IFileStore getStore(URI uri) {

@Override
public boolean isCaseSensitive() {
return caseSensitive;
return CASE_SENSITIVE;
}
}

0 comments on commit 1012283

Please sign in to comment.