Skip to content
This repository has been archived by the owner on Dec 27, 2021. It is now read-only.

Commit

Permalink
[#76] Improve reference location for Basic Classic.
Browse files Browse the repository at this point in the history
Use durable URI.
  • Loading branch information
peransin-obeo committed Nov 3, 2021
1 parent 750fd01 commit 46b4964
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public final class ImportingHelper {

private static final String BASIC_CLASSES_JAR_PATH = "org/eclipse/poosl/xtext/BasicClasses.poosl"; //$NON-NLS-1$

private static final String BASIC_CLASSES_PATH = Thread.currentThread().getContextClassLoader()
.getResource(BASIC_CLASSES_JAR_PATH).toString();
private static final URI BASIC_CLASSES_URI = URI
.createPlatformPluginURI("/org.eclipse.poosl.xtext/" + BASIC_CLASSES_JAR_PATH

, true);

private static final String ILLEGAL_ESCAPE = "Unsupported escape sequence on character {0} of string {1}.";

Expand Down Expand Up @@ -223,17 +225,19 @@ public static Poosl toPoosl(Resource resource) {
* @return The basic classes path
*/
public static URI getBasicClassesURI() {
String basicClassesLocation = BASIC_CLASSES_PATH;
IPreferencesService preferencesService = Platform.getPreferencesService();
if (preferencesService != null && !useDefaultBasicclasses()) {
if (!useDefaultBasicclasses(preferencesService)) {
String path = preferencesService.getString(GlobalConstants.PREFERENCE_PLUGIN_ID,
GlobalConstants.PREFERENCES_CUSTOM_BASIC_CLASS_PATH, BASIC_CLASSES_PATH, null);
if (!path.startsWith("platform")) { //$NON-NLS-1$
return URI.createFileURI(path);
GlobalConstants.PREFERENCES_CUSTOM_BASIC_CLASS_PATH, null, null);
if (path != null) {
try {
return URI.createFileURI(path);
} catch (IllegalArgumentException e) {
LOGGER.warn("Illegal basic classes path, fallback to default.", e);
}
}
basicClassesLocation = path;
}
return URI.createURI(basicClassesLocation);
return BASIC_CLASSES_URI;
}

public static String getBasicAbsoluteString() {
Expand All @@ -247,7 +251,13 @@ public static String getBasicAbsoluteString() {
}

public static boolean useDefaultBasicclasses() {
IPreferencesService preferencesService = Platform.getPreferencesService();
return useDefaultBasicclasses(Platform.getPreferencesService());
}

public static boolean useDefaultBasicclasses(IPreferencesService preferencesService) {
if (preferencesService == null) {
return true; // no path pref
}
String useBasicClasses = preferencesService.getString(GlobalConstants.PREFERENCE_PLUGIN_ID,
GlobalConstants.PREFERENCES_USE_DEFAULT_BASIC_CLASS,
GlobalConstants.PREFERENCES_BASIC_CLASSES_DEFAULT, null);
Expand Down

0 comments on commit 46b4964

Please sign in to comment.