SdkPathVariableProvider.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2018 Intel Corporation. //
  3. // //
  4. // All rights reserved. This program and the accompanying materials //
  5. // are made available under the terms of the Eclipse Public License v1.0 //
  6. // which accompanies this distribution, and is available at //
  7. // http://www.eclipse.org/legal/epl-v10.html //
  8. // //
  9. // Contributors: //
  10. // Intel Corporation - initial implementation and documentation //
  11. ///////////////////////////////////////////////////////////////////////////
  12. package com.intel.sgx;
  13. import java.io.File;
  14. import org.eclipse.core.resources.IResource;
  15. import org.eclipse.core.resources.variableresolvers.PathVariableResolver;
  16. import org.eclipse.core.runtime.IPath;
  17. import org.eclipse.core.runtime.Path;
  18. import org.eclipse.jface.preference.IPreferenceStore;
  19. import com.intel.sgx.preferences.PreferenceConstants;
  20. import com.intel.sgx.preferences.SGXPreferencePage;
  21. public class SdkPathVariableProvider extends PathVariableResolver {
  22. public SdkPathVariableProvider() {
  23. super();
  24. }
  25. @Override
  26. public String[] getVariableNames(String variable, IResource resource) {
  27. String variableNames[] = {"SGX_SDK_DIR_PATH"};
  28. return (variableNames);
  29. }
  30. @Override
  31. public String getValue(String variable, IResource resource) {
  32. if(variable.equals("SGX_SDK_DIR_PATH")) {
  33. IPreferenceStore store = Activator.getDefault().getPreferenceStore();
  34. String SDKPath = store.getString(PreferenceConstants.SDK_PATH);
  35. IPath SDKCanonicalPath= new Path(SDKPath);
  36. return(SDKCanonicalPath.append("Include").toOSString());
  37. }
  38. return null;
  39. }
  40. public static String getSGXSdkLocation() {
  41. return Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.SDK_PATH);
  42. }
  43. public static boolean isSGXSdkLocationValid() {
  44. String location = getSGXSdkLocation();
  45. if (location.length() == 0)
  46. return false;
  47. return isValidSGXSdkLocation(location);
  48. }
  49. public static boolean isValidSGXSdkLocation(String location) {
  50. File dir = new File(location);
  51. if (!dir.isDirectory())
  52. return false;
  53. return new PreferenceConstants.SGXSDK64Descriptor(dir).getSignerPath().canExecute()
  54. || new PreferenceConstants.SGXSDK32Descriptor(dir).getSignerPath().canExecute();
  55. }
  56. }