Java Code Examples for org.eclipse.core.runtime.Path

The following examples show how to use org.eclipse.core.runtime.Path. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ifml-editor   Source File: CoreModelWizard.java    License: MIT License 6 votes vote down vote up
/**
 * The framework calls this to see if the file is correct. <!--
 * begin-user-doc --> <!-- end-user-doc -->
 * 
 * @generated
 */
@Override
protected boolean validatePage() {
	if (super.validatePage()) {
		String extension = new Path(getFileName()).getFileExtension();
		if (extension == null || !FILE_EXTENSIONS.contains(extension)) {
			String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions"
					: "_WARN_FilenameExtension";
			setErrorMessage(IFMLMetamodelEditorPlugin.INSTANCE
					.getString(key,
							new Object[] { FORMATTED_FILE_EXTENSIONS }));
			return false;
		}
		return true;
	}
	return false;
}
 
Example 2
private IPath computeDestinationContainerPath(Path resourcePath) {
    IPath destinationContainerPath = fDestinationContainerPath;

    // We need to figure out the new destination path relative to the
    // selected "base" source directory.
    // Here for example, the selected source directory is /home/user
    if ((fImportOptionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
        // /home/user/bar/foo/trace -> /home/user/bar/foo
        IPath sourceContainerPath = resourcePath.removeLastSegments(1);
        if (fBaseSourceContainerPath.equals(resourcePath)) {
            // Use resourcePath directory if fBaseSourceContainerPath
            // points to a directory trace
            sourceContainerPath = resourcePath;
        }
        // /home/user/bar/foo, /home/user -> bar/foo
        IPath relativeContainerPath = sourceContainerPath.makeRelativeTo(fBaseSourceContainerPath);
        // project/Traces + bar/foo -> project/Traces/bar/foo
        destinationContainerPath = fDestinationContainerPath.append(relativeContainerPath);
    }
    return destinationContainerPath;
}
 
Example 3
Source Project: orion.server   Source File: GitTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected IPath createTempDir() throws CoreException {
	// get a temporary folder location, do not use /tmp
	File workspaceRoot = OrionConfiguration.getRootLocation().toLocalFile(EFS.NONE, null);
	File tmpDir = new File(workspaceRoot, SimpleMetaStoreUtil.ARCHIVE);
	if (!tmpDir.exists()) {
		tmpDir.mkdirs();
	}
	if (!tmpDir.exists() || !tmpDir.isDirectory()) {
		fail("Cannot find the default temporary-file directory: " + tmpDir.toString());
	}

	// get a temporary folder name
	SecureRandom random = new SecureRandom();
	long n = random.nextLong();
	n = (n == Long.MIN_VALUE) ? 0 : Math.abs(n);
	String tmpDirStr = Long.toString(n);
	File tempDir = new File(tmpDir, tmpDirStr);
	if (!tempDir.mkdir()) {
		fail("Cannot create a temporary directory at " + tempDir.toString());
	}
	return Path.fromOSString(tempDir.toString());
}
 
Example 4
Source Project: neoscada   Source File: RecipeModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The framework calls this to see if the file is correct.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
@Override
protected boolean validatePage ()
{
    if ( super.validatePage () )
    {
        final String extension = new Path ( getFileName () ).getFileExtension ();
        if ( extension == null || !FILE_EXTENSIONS.contains ( extension ) )
        {
            final String key = FILE_EXTENSIONS.size () > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; //$NON-NLS-1$ //$NON-NLS-2$
            setErrorMessage ( RecipeEditorPlugin.INSTANCE.getString ( key, new Object[] { FORMATTED_FILE_EXTENSIONS } ) );
            return false;
        }
        return true;
    }
    return false;
}
 
Example 5
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
	SubMonitor subMonitor = SubMonitor.convert(monitor, files.size());
	try {
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
		for (Map.Entry<String, CharSequence> fileEntry : files.entrySet()) {
			IFile file = workspace.getRoot().getFile(new Path(fileEntry.getKey()));
			file.create(new StringInputStream(fileEntry.getValue().toString()), true, subMonitor);
			if (firstFile == null) {
				firstFile = file;
			}
			subMonitor.worked(1);
		}
	} finally {
		subMonitor.done();
	}
}
 
Example 6
/**
 * Downloads a file from url, return the {@link File} on disk where it was saved.
 * 
 * @param url
 * @param monitor
 * @return
 * @throws CoreException
 */
private File download(URL url, String extension, IProgressMonitor monitor) throws CoreException
{
	DownloadManager manager = new DownloadManager();
	IPath path = Path.fromPortableString(url.getPath());
	String name = path.lastSegment();
	File f = new File(FileUtil.getTempDirectory().toFile(), name + extension);
	f.deleteOnExit();
	manager.addURL(url, f);
	IStatus status = manager.start(monitor);
	if (!status.isOK())
	{
		throw new CoreException(status);
	}
	List<IPath> locations = manager.getContentsLocations();
	return locations.get(0).toFile();
}
 
Example 7
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 6 votes vote down vote up
private static void createClasspath(IPath root, List<String> paths, IJavaProject javaProject,
    int javaLanguageLevel) throws CoreException {
  String name = root.lastSegment();
  IFolder base = javaProject.getProject().getFolder(name);
  if (!base.isLinked()) {
    base.createLink(root, IResource.NONE, null);
  }
  List<IClasspathEntry> list = new LinkedList<>();
  for (String path : paths) {
    IPath workspacePath = base.getFullPath().append(path);
    list.add(JavaCore.newSourceEntry(workspacePath));
  }
  list.add(JavaCore.newContainerEntry(new Path(BazelClasspathContainer.CONTAINER_NAME)));

  list.add(
      JavaCore.newContainerEntry(new Path(STANDARD_VM_CONTAINER_PREFIX + javaLanguageLevel)));
  IClasspathEntry[] newClasspath = list.toArray(new IClasspathEntry[0]);
  javaProject.setRawClasspath(newClasspath, null);
}
 
Example 8
Source Project: n4js   Source File: XpectCompareCommandHandler.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Display comparison view of test file with expected and actual xpect expectation
 */
private void displayComparisonView(ComparisonFailure cf, Description desc) {
	IXpectURIProvider uriProfider = XpectRunner.INSTANCE.getUriProvider();
	IFile fileTest = null;
	if (uriProfider instanceof N4IDEXpectTestURIProvider) {
		N4IDEXpectTestURIProvider fileCollector = (N4IDEXpectTestURIProvider) uriProfider;
		fileTest = ResourcesPlugin.getWorkspace().getRoot()
				.getFileForLocation(new Path(fileCollector.findRawLocation(desc)));
	}

	if (fileTest != null && fileTest.isAccessible()) {
		N4IDEXpectCompareEditorInput inp = new N4IDEXpectCompareEditorInput(fileTest, cf);
		CompareUI.openCompareEditor(inp);
	} else {
		throw new RuntimeException("paths in descriptions changed!");
	}
}
 
Example 9
Source Project: orion.server   Source File: Commit.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected URI createDiffLocation(String toRefId, String fromRefId, String path) throws URISyntaxException {
	IPath diffPath = new Path(GitServlet.GIT_URI).append(Diff.RESOURCE);

	// diff range format is [fromRef..]toRef
	String diffRange = ""; //$NON-NLS-1$
	if (fromRefId != null)
		diffRange = fromRefId + ".."; //$NON-NLS-1$
	diffRange += toRefId;
	diffPath = diffPath.append(diffRange);

	// clone location is of the form /gitapi/clone/file/{workspaceId}/{projectName}[/{path}]
	IPath clonePath = new Path(cloneLocation.getPath()).removeFirstSegments(2);
	if (path == null) {
		diffPath = diffPath.append(clonePath);
	} else if (isRoot) {
		diffPath = diffPath.append(clonePath).append(path);
	} else {
		// need to start from the project root
		// project path is of the form /file/{workspaceId}/{projectName}
		IPath projectRoot = clonePath.uptoSegment(3);
		diffPath = diffPath.append(projectRoot).append(path);
	}

	return new URI(cloneLocation.getScheme(), cloneLocation.getAuthority(), diffPath.toString(), null, null);
}
 
Example 10
/**
 * Builds the tree nodes for a set of modules and host pages.
 * 
 * @param modulesHostPages the set of modules along with their respective
 *          host pages
 * @return tree root nodes
 */
static LegacyGWTHostPageSelectionTreeItem[] buildTree(
    Map<String, Set<String>> modulesHostPages) {
  List<LegacyGWTHostPageSelectionTreeItem> treeItems = new ArrayList<LegacyGWTHostPageSelectionTreeItem>();
  for (String moduleName : modulesHostPages.keySet()) {
    LegacyGWTHostPageSelectionTreeItem moduleItem = new LegacyGWTHostPageSelectionTreeItem(
        Path.fromPortableString(moduleName.replace('.', '/')));
    treeItems.add(moduleItem);
    for (String hostPage : modulesHostPages.get(moduleName)) {
      new LegacyGWTHostPageSelectionTreeItem(
          Path.fromPortableString(hostPage), moduleItem);
    }
  }

  return treeItems.toArray(new LegacyGWTHostPageSelectionTreeItem[0]);
}
 
Example 11
private void readParticipantsIndexNamesFile() {
	SimpleLookupTable containers = new SimpleLookupTable(3);
	try {
		char[] participantIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.participantIndexNamesFile, null);
		if (participantIndexNames.length > 0) {
			char[][] names = CharOperation.splitOn('\n', participantIndexNames);
			if (names.length >= 3) {
				// First line is DiskIndex signature  (see writeParticipantsIndexNamesFile())
				if (DiskIndex.SIGNATURE.equals(new String(names[0]))) {					
					for (int i = 1, l = names.length-1 ; i < l ; i+=2) {
						IndexLocation indexLocation = new FileIndexLocation(new File(new String(names[i])), true);
						containers.put(indexLocation, new Path(new String(names[i+1])));
					}
				}				
			}
		}	
	} catch (IOException ignored) {
		if (VERBOSE)
			Util.verbose("Failed to read participant index file names"); //$NON-NLS-1$
	}
	this.participantsContainers = containers;
	return;
}
 
Example 12
Source Project: xtext-eclipse   Source File: XtextProjectCreator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void configurePlainProject(ProjectDescriptor descriptor, ProjectFactory factory) {
	factory.setProjectName(descriptor.getName());
	factory.setLocation(new Path(descriptor.getLocation()));
	factory.setProjectDefaultCharset(projectInfo.getEncoding().toString());
	factory.addWorkingSets(Lists.newArrayList(projectInfo.getWorkingSets()));
	factory.addContributor(new DescriptorBasedContributor(descriptor));
	if (needsM2eIntegration(descriptor)) {
		factory.addProjectNatures("org.eclipse.m2e.core.maven2Nature");
		factory.addBuilderIds("org.eclipse.m2e.core.maven2Builder");
	}
	if (needsBuildshipIntegration(descriptor)) {
		factory.addProjectNatures("org.eclipse.buildship.core.gradleprojectnature");
		factory.addBuilderIds("org.eclipse.buildship.core.gradleprojectbuilder");
		factory.addEarlyContributor(new GradleContributor(descriptor));
	}
}
 
Example 13
Source Project: RADL   Source File: RadlNewWizardPage.java    License: Apache License 2.0 6 votes vote down vote up
private void validateInput() {
  if (getFolderName().length() == 0) {
    updateStatus("Folder must be specified");
    return;
  }
  IResource resource = root.findMember(new Path(getFolderName()));
  if (resource != null && resource.exists() && !(resource instanceof IFolder)) {
    updateStatus("Invalid folder");
    return;
  }
  String serviceName = getServiceName();
  if (serviceName.isEmpty()) {
    updateStatus("Service name must be specified");
    return;
  }
  updateStatus(null);
}
 
Example 14
Source Project: Pydev   Source File: RefactoringRenameTestBase.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void setUpConfigWorkspaceFiles() throws Exception {
    projectStub = new org.python.pydev.shared_core.resource_stubs.ProjectStub(
            new File(TestDependent.TEST_COM_REFACTORING_PYSRC_LOC),
            natureRefactoring);
    TextEditCreation.createWorkspaceFile = new ICallback<IFile, File>() {

        @Override
        public IFile call(File file) {
            return new FileStub(projectStub, file) {
                @Override
                public IPath getFullPath() {
                    return Path.fromOSString(this.file.getAbsolutePath());
                }

            };
        }
    };
}
 
Example 15
Source Project: tesb-studio-se   Source File: RouteResourcesHelper.java    License: Apache License 2.0 6 votes vote down vote up
private static String getFileName(Item item) {
	String label = item.getProperty().getLabel();
	String selectedVersion = item.getProperty().getVersion();

	if ("Latest".equals(selectedVersion)) {
		return label;
	}

	IPath path = new Path(label);
	String fileExtension = path.getFileExtension();
	String fileName = path.removeFileExtension().toPortableString();
	fileName = fileName + "_" + selectedVersion;
	if (fileExtension != null && !fileExtension.isEmpty()) {
		fileName = fileName + "." + fileExtension;
	}
	return fileName;
}
 
Example 16
public NativeLibrariesConfigurationBlock(IStatusChangeListener listener, Shell parent, String nativeLibPath, IClasspathEntry parentEntry) {
	fListener= listener;
	fEntry= parentEntry;

	NativeLibrariesAdapter adapter= new NativeLibrariesAdapter();

	fPathField= new StringDialogField();
	fPathField.setLabelText(NewWizardMessages.NativeLibrariesDialog_location_label);
	fPathField.setDialogFieldListener(adapter);

	fBrowseWorkspace= new SelectionButtonDialogField(SWT.PUSH);
	fBrowseWorkspace.setLabelText(NewWizardMessages.NativeLibrariesDialog_workspace_browse);
	fBrowseWorkspace.setDialogFieldListener(adapter);

	fBrowseExternal= new SelectionButtonDialogField(SWT.PUSH);
	fBrowseExternal.setLabelText(NewWizardMessages.NativeLibrariesDialog_external_browse);
	fBrowseExternal.setDialogFieldListener(adapter);

	if (nativeLibPath != null) {
		fPathField.setText(Path.fromPortableString(nativeLibPath).toString());
		fOrginalValue= nativeLibPath;
	} else {
		fOrginalValue= ""; //$NON-NLS-1$
	}
}
 
Example 17
Source Project: aCute   Source File: DotnetRunTab.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void updateProjectPath() {
	frameworkViewer.getList().removeAll();
	IPath projectFilePath = ProjectFileAccessor.getProjectFile(projectContainer);
	if (projectFilePath == null) {
		frameworkViewer.add(Messages.DotnetRunTab_noFrameworks);
		frameworkViewer.getList().setEnabled(false);
		return;
	}

	frameworkViewer.getList().deselectAll();
	frameworkViewer.add(Messages.DotnetRunTab_loadingFrameworks);
	frameworkViewer.getList().setEnabled(false);
	targetFrameworks = ProjectFileAccessor.getTargetFrameworks(
			new Path(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsolutePath().toString()
					+ projectFilePath.toString()));
	frameworkViewer.getList().removeAll();
	if (targetFrameworks.length > 0) {
		frameworkViewer.add(targetFrameworks);
		frameworkViewer.getList().select(0);
		frameworkViewer.getList().setEnabled(true);
	} else {
		frameworkViewer.add(Messages.DotnetRunTab_noFrameworks);
		frameworkViewer.getList().setEnabled(false);
	}
}
 
Example 18
Source Project: orion.server   Source File: WorkspaceServlet.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	traceRequest(req);
	String pathString = req.getPathInfo();
	IPath path = new Path(pathString == null ? "" : pathString); //$NON-NLS-1$
	if (path.segmentCount() > 0) {
		try {
			WorkspaceInfo workspace = OrionConfiguration.getMetaStore().readWorkspace(path.segment(0));
			if (workspaceResourceHandler.handleRequest(req, resp, workspace))
				return;
		} catch (CoreException e) {
			handleException(resp, "Error reading workspace metadata", e);
			return;
		}
	}
	super.doDelete(req, resp);
}
 
Example 19
Source Project: ice   Source File: PreviousAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * <p>
 * The constructor
 * </p>
 * 
 * @param parent
 *            <p>
 *            The ViewPart to whom the object of this class belongs.
 *            </p>
 */
public PreviousAction(PlayableViewPart parent) {

	// Set the calling class to the local ViewPart field
	viewer = parent;

	// Set the "hover" text
	this.setText("Previous");

	// Set the button image
	Bundle bundle = FrameworkUtil.getBundle(getClass());
	Path imagePath = new Path("icons" + System.getProperty("file.separator")
			+ "previous.gif");
	URL imageURL = FileLocator.find(bundle, imagePath, null);
	ImageDescriptor imageDescriptor = ImageDescriptor
			.createFromURL(imageURL);
	this.setImageDescriptor(imageDescriptor);

	return;
}
 
Example 20
public MultiModuleMoveRefactoringRequest(List<ModuleRenameRefactoringRequest> requests, IContainer target)
        throws MisconfigurationException, TargetNotInPythonpathException {
    super(requests.toArray(new RefactoringRequest[requests.size()]));
    PythonNature nature = PythonNature.getPythonNature(target);
    File file = target.getLocation().toFile();
    this.target = target;
    this.initialName = nature.resolveModule(file);
    IPath fullPath = target.getFullPath();
    if (this.initialName == null) {
        //Check if it's a source folder...
        try {
            Set<String> projectSourcePathSet = nature.getPythonPathNature().getProjectSourcePathSet(true);
            for (String string : projectSourcePathSet) {
                if (new Path(string).equals(fullPath)) {
                    this.initialName = "";
                    break;
                }
            }
        } catch (CoreException e) {
            Log.log(e);
        }
    }
    if (this.initialName == null) {
        throw new TargetNotInPythonpathException("Unable to resolve file as a python module: " + fullPath);
    }
}
 
Example 21
Source Project: neoscada   Source File: DetailViewModelWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The framework calls this to see if the file is correct.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
protected boolean validatePage ()
{
    if ( super.validatePage () )
    {
        String extension = new Path ( getFileName () ).getFileExtension ();
        if ( extension == null || !FILE_EXTENSIONS.contains ( extension ) )
        {
            String key = FILE_EXTENSIONS.size () > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; //$NON-NLS-1$ //$NON-NLS-2$
            setErrorMessage ( DetailViewEditorPlugin.INSTANCE.getString ( key, new Object[] { FORMATTED_FILE_EXTENSIONS } ) );
            return false;
        }
        return true;
    }
    return false;
}
 
Example 22
protected EclipseProcessLauncher getValidLaunchInfo(
		ILaunchConfiguration configuration, CompositeBuildTargetSettings buildTargetSettings)
		throws CommonException, CoreException {
	
	IProject project = buildTargetSettings.getBuildTargetSupplier().getValidProject();
	
	String workingDirectoryString = evaluateStringVars(
		configuration.getAttribute(LaunchConstants.ATTR_WORKING_DIRECTORY, (String) null));

	IPath workingDirectory = workingDirectoryString == null ? 
			project.getLocation() : 
			new Path(workingDirectoryString);
	
	Location programLoc = buildTarget.getValidExecutableLocation(); // not null
	
	String programArguments = configuration.getAttribute(LaunchConstants.ATTR_PROGRAM_ARGUMENTS, "");
	String commandLine = programLoc.toString() + " " + programArguments;
	
	Map<String, String> configEnv = configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, 
		new HashMap<>(0));
	boolean appendEnv = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);
	
	CommandInvocation programInvocation = new CommandInvocation(commandLine, new HashMap2<>(configEnv), appendEnv);
	
	return new EclipseProcessLauncher(
		project, 
		programLoc,
		workingDirectory, 
		programInvocation,
		LaunchConstants.PROCESS_TYPE_ID
	);
}
 
Example 23
Source Project: Pydev   Source File: EditorInputFactory.java    License: 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 24
Source Project: birt   Source File: NewReportProjectWizard.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private IClasspathEntry[] getClassPathEntries( IProject project )
{
	IClasspathEntry[] internalClassPathEntries = getInternalClassPathEntries( project );
	IClasspathEntry[] entries = new IClasspathEntry[internalClassPathEntries.length + 1];
	System.arraycopy( internalClassPathEntries,
			0,
			entries,
			0,
			internalClassPathEntries.length );
	entries[entries.length - 1] = JavaCore.newContainerEntry( new Path( "org.eclipse.jdt.launching.JRE_CONTAINER" ) ); //$NON-NLS-1$
	return entries;
}
 
Example 25
@Override
public String getName()
{
	String name = super.getName();
	if (name != null)
	{
		return name;
	}
	return Path.fromPortableString(getURI().getPath()).lastSegment();
}
 
Example 26
Source Project: Pydev   Source File: PythonRunner.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Actually creates the process (and create the encoding config file)
 */
@SuppressWarnings("deprecation")
private static Process createProcess(ILaunch launch, String[] envp, String[] cmdLine, File workingDirectory)
        throws CoreException {
    Map<String, String> arrayAsMapEnv = ProcessUtils.getArrayAsMapEnv(envp);
    arrayAsMapEnv.put("PYTHONUNBUFFERED", "1");
    arrayAsMapEnv.put("PYDEV_COMPLETER_PYTHONPATH", CorePlugin.getBundleInfo().getRelativePath(new Path("pysrc"))
            .toString());

    //Not using DebugPlugin.ATTR_CONSOLE_ENCODING to provide backward compatibility for eclipse 3.2
    String encoding = launch.getAttribute(IDebugUIConstants.ATTR_CONSOLE_ENCODING);
    if (encoding != null && encoding.trim().length() > 0) {
        arrayAsMapEnv.put("PYDEV_CONSOLE_ENCODING", encoding);

        //In Python 3.0, we can use the PYTHONIOENCODING.
        //Note that we always replace it, because this is really the encoding of the allocated console view,
        //so, if we had something different put, the encoding from the Python side would differ from the encoding
        //on the java side (which would make things garbled anyways).
        arrayAsMapEnv.put("PYTHONIOENCODING", encoding);
    }
    envp = ProcessUtils.getMapEnvAsArray(arrayAsMapEnv);
    Process p = DebugPlugin.exec(cmdLine, workingDirectory, envp);
    if (p == null) {
        throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Could not execute python process.",
                null));
    }
    PythonRunnerCallbacks.afterCreatedProcess.call(p);
    return p;
}
 
Example 27
Source Project: dsl-devkit   Source File: CheckJavaValidatorUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the workspace member.
 *
 * @param name
 *          the name
 * @return the workspace member
 */
private IResource getWorkspaceMember(final String name) {
  IWorkspaceRoot workspaceRoot = EcorePlugin.getWorkspaceRoot();
  if (workspaceRoot == null) {
    return null;
  }
  return workspaceRoot.findMember(new Path(name));
}
 
Example 28
Source Project: eclipse.jdt.ls   Source File: JDTUtils.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static String getPackageName(IJavaProject javaProject, URI uri) {
	try {
		File file = ResourceUtils.toFile(uri);
		//FIXME need to determine actual charset from file
		String content = Files.toString(file, Charsets.UTF_8);
		if (content.isEmpty() && javaProject != null && ProjectsManager.DEFAULT_PROJECT_NAME.equals(javaProject.getProject().getName())) {
			java.nio.file.Path path = Paths.get(uri);
			java.nio.file.Path parent = path;
			while (parent.getParent() != null && parent.getParent().getNameCount() > 0) {
				parent = parent.getParent();
				String name = parent.getName(parent.getNameCount() - 1).toString();
				if (SRC.equals(name)) {
					String pathStr = path.getParent().toString();
					if (pathStr.length() > parent.toString().length()) {
						pathStr = pathStr.substring(parent.toString().length() + 1);
						pathStr = pathStr.replace(PATH_SEPARATOR, PERIOD);
						return pathStr;
					}
				}
			}
		} else {
			return getPackageName(javaProject, content);
		}
	} catch (IOException e) {
		JavaLanguageServerPlugin.logException("Failed to read package name from "+uri, e);
	}
	return "";
}
 
Example 29
Source Project: orion.server   Source File: GitTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static void assertRemoteUri(String remoteUri) {
	URI uri = URI.create(toRelativeURI(remoteUri));
	IPath path = new Path(uri.getPath());
	// /git/remote/file/{path}
	assertTrue(path.segmentCount() > 3);
	assertEquals(GitServlet.GIT_URI.substring(1), path.segment(0));
	assertEquals(Remote.RESOURCE, path.segment(1));
	assertEquals("file", path.segment(2));
}
 
Example 30
Source Project: gama   Source File: FileUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static String findOutsideWorkspace(final String fp, final URI modelBase, final boolean mustExist) {
	if (!mustExist) { return fp; }
	final IFileStore file = FILE_SYSTEM.getStore(new Path(fp));
	final IFileInfo info = file.fetchInfo();
	if (info.exists()) {
		final IFile linkedFile = createLinkToExternalFile(fp, modelBase);
		if (linkedFile == null) { return fp; }
		return linkedFile.getLocation().toFile().getAbsolutePath();
	}
	return null;
}