Java Code Examples for org.eclipse.xtext.workspace.IProjectConfig#getPath()

The following examples show how to use org.eclipse.xtext.workspace.IProjectConfig#getPath() . 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: XStatefulIncrementalBuilder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isResourceInOutputDirectory(Resource resource, IResourceServiceProvider serviceProvider) {
	XWorkspaceManager workspaceManager = serviceProvider.get(XWorkspaceManager.class);
	if (workspaceManager == null) {
		return false;
	}
	OutputConfigurationProvider outputConfProvider = serviceProvider.get(OutputConfigurationProvider.class);
	URI resourceUri = resource.getURI();
	IProjectConfig projectConfig = workspaceManager.getProjectConfig(resourceUri);
	Set<OutputConfiguration> outputConfigurations = outputConfProvider.getOutputConfigurations(resource);
	URI projectBaseUri = projectConfig.getPath();
	Path resourcePath = URIUtils.toPath(resourceUri);

	for (OutputConfiguration outputConf : outputConfigurations) {
		for (String outputDir : outputConf.getOutputDirectories()) {
			URI outputUri = projectBaseUri.appendSegment(outputDir);
			Path outputPath = URIUtils.toPath(outputUri);
			if (resourcePath.startsWith(outputPath)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 2
Source File: N4jscCompiler.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void verbosePrintAllProjects() {
	if (options.isVerbose()) {
		Set<? extends IProjectConfig> projects = workspaceManager.getWorkspaceConfig().getProjects();
		int maxPrjNameLength = projects.stream()
				.filter(p -> p.getName() != null)
				.mapToInt(p -> p.getName().length())
				.max().orElse(10);
		String prjNameWithPadding = "%-" + maxPrjNameLength + "s";

		if (!projects.isEmpty()) {
			Path workspace = options.getDirs().get(0).toPath();

			SortedMap<String, String> projectNameList = new TreeMap<>();
			for (IProjectConfig prj : projects) {
				String prjName = prj.getName() == null ? "[no_name]" : prj.getName();
				String locationStr = null;
				if (prj.getPath() == null) {
					locationStr = "[no_location]";
				} else {
					locationStr = workspace.relativize(URIUtils.toPath(prj.getPath())).toString();
					if (locationStr.isBlank()) {
						locationStr = ".";
					}
				}
				String outputLine = String.format(prjNameWithPadding + " at %s", prjName, locationStr);
				projectNameList.put(locationStr, outputLine);
			}

			LOG.info(projects.size() + " projects: \n   " + String.join("\n   ", projectNameList.values()));
		}
	}
}
 
Example 3
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the project that contains the given URI.
 *
 * @param uri
 *            the contained uri
 * @return the project base uri.
 */
public URI getProjectBaseDir(URI uri) {
	IProjectConfig projectConfig = getProjectConfig(uri);
	if (projectConfig != null) {
		return projectConfig.getPath();
	}
	return null;
}
 
Example 4
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected URI getURI(final Path path) {
  if (((path == null) || Objects.equal(path, Path.ROOT))) {
    return null;
  }
  final IProjectConfig projectConfig = this.projectConfigProvider.getProjectConfig(this.context);
  if ((projectConfig == null)) {
    return null;
  }
  final URI projectURI = projectConfig.getPath();
  final String projectName = IterableExtensions.<String>head(path.getSegments());
  String _name = projectConfig.getName();
  boolean _notEquals = (!Objects.equal(projectName, _name));
  if (_notEquals) {
    return null;
  }
  final Iterable<String> segments = IterableExtensions.<String>tail(path.getSegments());
  boolean _isEmpty = IterableExtensions.isEmpty(segments);
  if (_isEmpty) {
    return projectURI;
  }
  final URI relativeURI = URI.createURI(IterableExtensions.<String>head(segments)).appendSegments(((String[])Conversions.unwrapArray(IterableExtensions.<String>tail(segments), String.class)));
  final URI uri = relativeURI.resolve(projectURI);
  Boolean _isFolder = this.isFolder(uri);
  if ((_isFolder).booleanValue()) {
    return UriUtil.toFolderURI(uri);
  }
  return uri;
}
 
Example 5
Source File: ProjectManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void initialize(ProjectDescription description, IProjectConfig projectConfig,
		Procedure2<? super URI, ? super Iterable<Issue>> acceptor,
		IExternalContentSupport.IExternalContentProvider openedDocumentsContentProvider,
		Provider<Map<String, ResourceDescriptionsData>> indexProvider, CancelIndicator cancelIndicator) {
	this.projectDescription = description;
	this.projectConfig = projectConfig;
	this.baseDir = projectConfig.getPath();
	this.issueAcceptor = acceptor;
	this.openedDocumentsContentProvider = openedDocumentsContentProvider;
	this.indexProvider = indexProvider;
}
 
Example 6
Source File: WorkspaceManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the project that contains the given URI.
 *
 * @param uri
 *            the contained uri
 * @return the project base uri.
 */
public URI getProjectBaseDir(URI uri) {
	IProjectConfig projectConfig = getProjectConfig(uri);
	if (projectConfig != null) {
		return projectConfig.getPath();
	}
	return null;
}
 
Example 7
Source File: ProjectStatePersister.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/** @return the file URI of the persisted index */
public URI getFileName(IProjectConfig project) {
	URI rootPath = project.getPath();
	return new FileURI(rootPath).appendSegment(FILENAME).toURI();
}