Java Code Examples for org.eclipse.core.runtime.Path#fromOSString()

The following examples show how to use org.eclipse.core.runtime.Path#fromOSString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Arglets.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param cwd
 *          the current working directory of the compiler at its invocation
 * @see de.marw.cmake.cdt.lsp.IArglet#processArgument(IParseContext, IPath, String)
 */
protected final int processArgument(IParseContext parseContext, IPath cwd,
    String argsLine, NameOptionMatcher[] optionMatchers) {
  for (NameOptionMatcher oMatcher : optionMatchers) {
    final Matcher matcher = oMatcher.matcher;

    matcher.reset(argsLine);
    if (matcher.lookingAt()) {
      String name = matcher.group(oMatcher.nameGroup);
      // workaround for relative path by cmake bug
      // https://gitlab.kitware.com/cmake/cmake/issues/13894 : prepend cwd
      IPath path = Path.fromOSString(name);
      if (!path.isAbsolute()) {
        // prepend CWD
        name = cwd.append(path).toOSString();
      }

      final ICLanguageSettingEntry entry = CDataUtil.createCIncludePathEntry(name,
          ICSettingEntry.READONLY);
      parseContext.addSettingEntry(entry);
      final int end = matcher.end();
      return end;
    }
  }
  return 0;// no input consumed
}
 
Example 2
Source File: SARLPreferences.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the SARL output path for test in the global preferences.
 *
 * @return the output path for SARL compiler in the global preferences.
 * @since 0.8
 */
public static IPath getGlobalSARLTestOutputPath() {
	final Injector injector = LangActivator.getInstance().getInjector(LangActivator.IO_SARL_LANG_SARL);
	final IOutputConfigurationProvider configurationProvider =
			injector.getInstance(IOutputConfigurationProvider.class);
	final OutputConfiguration config = Iterables.find(
		configurationProvider.getOutputConfigurations(),
		it -> Objects.equals(it.getName(), SARLConfig.TEST_OUTPUT_CONFIGURATION));
	if (config != null) {
		final String path = config.getOutputDirectory();
		if (!Strings.isNullOrEmpty(path)) {
			final IPath pathObject = Path.fromOSString(path);
			if (pathObject != null) {
				return pathObject;
			}
		}
	}
	throw new IllegalStateException("No global preferences found for SARL."); //$NON-NLS-1$
}
 
Example 3
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void forcePathsOfChildren(List<MenuElement> children)
{
	if (children != null)
	{
		for (MenuElement child : children)
		{
			String childPath = child.getPath();
			IPath pathObj = Path.fromOSString(childPath);
			if (!pathObj.isAbsolute())
			{
				// Prepend the bundle directory.
				child.setPath(bundleDirectory.getAbsolutePath() + File.separator + childPath);
			}
			forcePathsOfChildren(child.getChildren());
		}
	}
}
 
Example 4
Source File: ShellExecutable.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static IPath getPreferenceShellPath()
{
	String pref = EclipseUtil.instanceScope().getNode(CorePlugin.PLUGIN_ID)
			.get(ICorePreferenceConstants.PREF_SHELL_EXECUTABLE_PATH, null);
	if (pref != null && !StringUtil.isEmpty(pref))
	{
		IPath path = Path.fromOSString(pref);
		if (path.toFile().isDirectory())
		{
			boolean isWin32 = Platform.OS_WIN32.equals(Platform.getOS());
			path = path.append(isWin32 ? SH_EXE : BASH);
		}
		if (ExecutableUtil.isExecutable(path))
		{
			return path;
		}
		IdeLog.logWarning(CorePlugin.getDefault(), "Shell executable path preference point to an invalid location"); //$NON-NLS-1$
	}
	return null;
}
 
Example 5
Source File: ResponseFileArglets.java    From cmake4eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public int process(IParserHandler parserHandler, String argsLine) {
  for (NameOptionMatcher oMatcher : optionMatchers) {
    final Matcher matcher = oMatcher.matcher;

    matcher.reset(argsLine);
    if (matcher.lookingAt()) {
      String fname = matcher.group(oMatcher.nameGroup);
      final int consumed = matcher.end();
      if("<<".equals(fname)) {
        // see https://github.com/15knots/cmake4eclipse/issues/94
        // Handle '@<< compiler-args <<' syntax: The file '<<' does not exist, arguments come from argsline.
        // so we just do not open the non-existing file
        return consumed;
      }

      IPath path = Path.fromOSString(fname);
      if (!path.isAbsolute()) {
        // relative path, prepend CWD
        fname = parserHandler.getCompilerWorkingDirectory().append(path).toOSString();
      }

      // parse file
      java.nio.file.Path fpath = Paths.get(fname);
      try {
        String args2 = new String(Files.readAllBytes(fpath));
        parserHandler.parseArguments(args2);
      } catch (IOException e) {
        // swallow exception for now
        e.printStackTrace();
      }
      return consumed;
    }
  }
  return 0;// no input consumed
}
 
Example 6
Source File: ResourceUtils.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将一个file集合转换成IFile集合	robert	2012-05-06
 * @param filePath
 * @return
 */
public static List<IFile> filesToIFiles(List<File> fileList){
	List<IFile> iFileList = new ArrayList<IFile>();
	for(File file : fileList){
		IPath path = Path.fromOSString(file.getAbsolutePath());
		iFileList.add(root.getFileForLocation(path));
	}
	return iFileList;
}
 
Example 7
Source File: AbstractJarDestinationWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void updateModel() {
	// destination
	String comboText= fDestinationNamesCombo.getText();
	IPath path= Path.fromOSString(comboText);

	if (path.segmentCount() > 0 && ensureTargetFileIsValid(path.toFile()) && path.getFileExtension() == null)
		// append .jar
		path= path.addFileExtension(JarPackagerUtil.JAR_EXTENSION);

	fJarPackage.setJarLocation(path);
}
 
Example 8
Source File: NodeListEditor.java    From depan with Apache License 2.0 5 votes vote down vote up
private IFile getSaveAsFile() {
  IFile infoFile = getInputFile();
  if (null != infoFile) {
    return infoFile;
  }

  IContainer parent = nodeListInfo.getReferenceLocation().getParent();
  String filebase = baseName + '.' + NodeListDocument.EXTENSION;
  String filename = PlatformTools.guessNewFilename(
      parent, filebase, 1, 10);

  IPath filePath = Path.fromOSString(filename);
  return parent.getFile(filePath);
}
 
Example 9
Source File: EditorInputFactory.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates an editor input for the passed file.
 *
 * If forceExternalFile is True, it won't even try to create a FileEditorInput, otherwise,
 * it will try to create it with the most suitable type it can
 * (i.e.: FileEditorInput, FileStoreEditorInput, PydevFileEditorInput, ...)
 */
public static IEditorInput create(File file, boolean forceExternalFile) {
    IPath path = Path.fromOSString(FileUtils.getFileAbsolutePath(file));

    if (!forceExternalFile) {
        //May call again to this method (but with forceExternalFile = true)
        IEditorInput input = new PySourceLocatorBase().createEditorInput(path, false, null, null);
        if (input != null) {
            return input;
        }
    }

    IPath zipPath = new Path("");
    while (path.segmentCount() > 0) {
        if (path.toFile().exists()) {
            break;
        }
        zipPath = new Path(path.lastSegment()).append(zipPath);
        path = path.uptoSegment(path.segmentCount() - 1);
    }

    if (zipPath.segmentCount() > 0 && path.segmentCount() > 0) {
        return new PydevZipFileEditorInput(new PydevZipFileStorage(path.toFile(), zipPath.toPortableString()));
    }

    try {
        URI uri = file.toURI();
        return new FileStoreEditorInput(EFS.getStore(uri));
    } catch (Throwable e) {
        //not always available! (only added in eclipse 3.3)
        return new PydevFileEditorInput(file);
    }
}
 
Example 10
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the location is a syntactically correct path.
 *
 * @param location the location to test.
 * @return the project path.
 * @throws ValidationException if the location has invalid syntax.
 */
@SuppressWarnings("synthetic-access")
private IPath checkLocationSyntax(String location) throws ValidationException {
	// check whether location is empty
	if (location.length() == 0) {
		throw new ValidationException(
				NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation,
				null);
	}

	if (!Path.EMPTY.isValidPath(location)) {
		throw new ValidationException(
				null,
				NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory);
	}

	IPath projectPath = null;
	if (!MainProjectWizardPage.this.locationGroup.isUseDefaultSelected()) {
		projectPath = Path.fromOSString(location);
		if (!projectPath.toFile().exists()) {
			// check non-existing external location
			if (!canCreate(projectPath.toFile())) {
				throw new ValidationException(
						null,
						NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation);
			}
		}
	}
	return projectPath;
}
 
Example 11
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**
 * Stores the widget values in the JAR package.
 */
@Override
protected void updateModel() {
	super.updateModel();

	String comboText= fAntScriptNamesCombo.getText();
	IPath path= Path.fromOSString(comboText);
	if (path.segmentCount() > 0 && ensureAntScriptFileIsValid(path.toFile()) && path.getFileExtension() == null)
		path= path.addFileExtension(ANTSCRIPT_EXTENSION);

	fAntScriptLocation= getAbsoluteLocation(path);
}
 
Example 12
Source File: SimpleWebServer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the documentRoot
 */
public IPath getDocumentRootPath()
{
	URI rootUri = getDocumentRoot();
	if (rootUri == null)
	{
		return null;
	}
	File docRoot = new File(rootUri);
	return Path.fromOSString(docRoot.getAbsolutePath());
}
 
Example 13
Source File: AbstractSyntaxProjectsManagerBasedTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
protected IPath getWorkingTestPath(String path) throws IOException {
	return Path.fromOSString(new File(getWorkingProjectDirectory(), path).getAbsolutePath());
}
 
Example 14
Source File: SARLRuntimeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void isUnpackedSREIPath_packed_jarJar() throws Exception {
	File file = getPackedJAR();
	IPath path = Path.fromOSString(file.getAbsolutePath());
	assertFalse(SARLRuntime.isUnpackedSRE(path));
}
 
Example 15
Source File: PyOpenEditor.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public static IEditorPart doOpenEditor(File file) {
    String absPath = FileUtils.getFileAbsolutePath(file);
    IPath path = Path.fromOSString(absPath);
    return PyOpenEditor.doOpenEditor(path, null);
}
 
Example 16
Source File: KbdMacroFileHandler.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
protected IPath getKbdMacroPath() {
	return (kbdMacroDirectory.length() != 0 ? Path.fromOSString(kbdMacroDirectory) : 
		EmacsPlusActivator.getDefault().getStateLocation().append(KBD_SUBDIR));
}
 
Example 17
Source File: SARLRuntimeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void isPackedSREIPath_packed_jarJar() throws Exception {
	File file = getPackedJAR();
	IPath path = Path.fromOSString(file.getAbsolutePath());
	assertFalse(SARLRuntime.isPackedSRE(path));
}
 
Example 18
Source File: FolderStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IPath getLocation() {
    return Path.fromOSString(FileUtils.getFileAbsolutePath(this.folder));
}
 
Example 19
Source File: SARLRuntimeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void isPackedSREIPath_packed_sreJar() throws Exception {
	File file = getPackedSRE();
	IPath path = Path.fromOSString(file.getAbsolutePath());
	assertTrue(SARLRuntime.isPackedSRE(path));
}
 
Example 20
Source File: PlatformTools.java    From depan with Apache License 2.0 2 votes vote down vote up
/**
 * Do all string to path conversions here, to ensure consistency throughout
 * DepAn.
 */
public static IPath buildPath(String pathText) {
  return Path.fromOSString(pathText);
}