org.eclipse.xtext.workspace.IProjectConfig Java Examples

The following examples show how to use org.eclipse.xtext.workspace.IProjectConfig. 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: ProjectStateHolder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Updates the index state, file hashes and validation issues */
public void updateProjectState(XBuildRequest request, XBuildResult result, IProjectConfig projectConfig) {
	HashMap<URI, HashedFileContent> newFileContents = new HashMap<>(uriToHashedFileContents);
	for (Delta delta : result.getAffectedResources()) {
		URI uri = delta.getUri();
		storeHash(newFileContents, uri);
	}
	for (URI deletedFile : request.getResultDeleteFiles()) {
		newFileContents.remove(deletedFile);
	}

	setIndexState(result.getIndexState());
	mergeValidationIssues(request.getResultIssues());
	uriToHashedFileContents = newFileContents;

	if (request.isGeneratorEnabled() && !result.getAffectedResources().isEmpty()) {
		writeProjectState(projectConfig);
	}
}
 
Example #2
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param workspaceConfig
 *            the new workspace configuration.
 */
synchronized protected void setWorkspaceConfig(IWorkspaceConfig workspaceConfig) {
	if (this.workspaceConfig != null && workspaceConfig != null &&
			this.workspaceConfig == workspaceConfig) {
		return;
	}

	// clean up old projects
	Collection<XProjectManager> pmCopy = new ArrayList<>(getProjectManagers());
	for (XProjectManager projectManager : pmCopy) {
		removeProject(projectManager);
	}
	projectName2ProjectManager.clear();
	fullIndex.removeAllContainers();

	// init projects
	this.workspaceConfig = workspaceConfig;
	for (IProjectConfig projectConfig : getWorkspaceConfig().getProjects()) {
		addProject(projectConfig);
	}
}
 
Example #3
Source File: EclipseBasedShouldGenerate.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
	URI uri = resource.getURI();
	if (uri == null || !uri.isPlatformResource()) {
		return false;
	}

	IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(uri.toPlatformString(true)));
	if (member != null && member.getType() == IResource.FILE) {
		ProjectConfigAdapter projectConfigAdapter = ProjectConfigAdapter.findInEmfObject(resource.getResourceSet());
		if (projectConfigAdapter != null) {
			IProjectConfig projectConfig = projectConfigAdapter.getProjectConfig();
			if (projectConfig != null && Objects.equals(member.getProject().getName(), projectConfig.getName())) {
				try {
					return member.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE) != IMarker.SEVERITY_ERROR;
				} catch (CoreException e) {
					LOG.error("The resource " + member.getName() + " does not exist", e);
					return false;
				}
			}
		}
	}
	return false;
}
 
Example #4
Source File: WorkspaceChanges.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Merges the given changes into this instance */
public void merge(WorkspaceChanges changes) {
	this.namesOrDependenciesChanged |= changes.namesOrDependenciesChanged;
	this.removedURIs = newArrayList(concat(this.removedURIs, changes.removedURIs));
	this.addedURIs = newArrayList(concat(this.addedURIs, changes.addedURIs));
	this.changedURIs = newArrayList(concat(this.changedURIs, changes.changedURIs));
	this.removedSourceFolders = newArrayList(concat(this.removedSourceFolders, changes.removedSourceFolders));
	this.addedSourceFolders = newArrayList(concat(this.addedSourceFolders, changes.addedSourceFolders));
	this.removedProjects = newArrayList(concat(this.removedProjects, changes.removedProjects));
	this.addedProjects = newArrayList(concat(this.addedProjects, changes.addedProjects));
	this.projectsWithChangedDependencies = newArrayList(concat(this.projectsWithChangedDependencies,
			changes.projectsWithChangedDependencies));

	// ensure consistency of 'projectsWithChangedDependencies'
	Set<String> addedRemovedProjects = IterableExtensions
			.toSet(Iterables.transform(concat(this.removedProjects, this.addedProjects), IProjectConfig::getName));
	this.projectsWithChangedDependencies.removeIf(pc -> addedRemovedProjects.contains(pc.getName()));
}
 
Example #5
Source File: ProjectStatePersister.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Read the index state as it was written to disk for the given project.
 *
 * @param project
 *            the project
 */
public PersistedState readProjectState(IProjectConfig project) {
	File file = getDataFile(project);
	try {
		if (file.isFile()) {
			try (InputStream nativeIn = Files.asByteSource(file).openBufferedStream()) {
				PersistedState result = readProjectState(nativeIn, N4JSLanguageUtils.getLanguageVersion());
				if (result == null && file.isFile()) {
					file.delete();
				}
				return result;
			}
		}
	} catch (IOException | ClassNotFoundException e) {
		e.printStackTrace();
		if (file.isFile()) {
			file.delete();
		}
	}
	return null;
}
 
Example #6
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Mark the given document as saved. */
public XBuildManager.XBuildable didSave(URI uri) {
	WorkspaceChanges notifiedChanges = WorkspaceChanges.createUrisChanged(ImmutableList.of(uri));
	WorkspaceChanges workspaceChanges = ((XIWorkspaceConfig) getWorkspaceConfig()).update(uri,
			projectName -> projectName2ProjectManager.get(projectName).getProjectDescription());

	Map<String, ImmutableSet<String>> dependencyChanges = new HashMap<>();
	for (IProjectConfig pc : workspaceChanges.getProjectsWithChangedDependencies()) {
		XProjectManager pm = projectName2ProjectManager.get(pc.getName());
		ProjectDescription pd = pm != null ? pm.getProjectDescription() : null;
		if (pd != null) {
			dependencyChanges.put(pd.getName(), ImmutableSet.copyOf(pd.getDependencies()));
		}
	}
	if (!dependencyChanges.isEmpty()) {
		fullIndex.setVisibleContainers(dependencyChanges);
	}

	workspaceChanges.merge(notifiedChanges);
	return getIncrementalGenerateBuildable(workspaceChanges);
}
 
Example #7
Source File: IncrementalBuilder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public URIBasedFileSystemAccess newFileSystemAccess(Resource resource, BuildRequest request) {
	URIBasedFileSystemAccess uriBasedFileSystemAccess = new URIBasedFileSystemAccess();
	uriBasedFileSystemAccess.setOutputConfigurations(IterableExtensions.toMap(
			outputConfigurationProvider.getOutputConfigurations(resource), OutputConfiguration::getName));
	uriBasedFileSystemAccess.setPostProcessor(postProcessor);
	if (encodingProvider != null) {
		uriBasedFileSystemAccess.setEncodingProvider(encodingProvider);
	}
	uriBasedFileSystemAccess.setTraceFileNameProvider(traceFileNameProvider);
	uriBasedFileSystemAccess.setTraceRegionSerializer(traceRegionSerializer);
	uriBasedFileSystemAccess.setGenerateTraces(true);
	uriBasedFileSystemAccess.setBaseDir(request.getBaseDir());
	if (projectConfigProvider != null) {
		IProjectConfig projectConfig = projectConfigProvider.getProjectConfig(resource.getResourceSet());
		if (projectConfig != null) {
			ISourceFolder sourceFolder = projectConfig.findSourceFolderContaining(resource.getURI());
			if (sourceFolder != null) {
				uriBasedFileSystemAccess.setCurrentSource(sourceFolder.getName());
			}
		}
	}
	uriBasedFileSystemAccess.setConverter(resource.getResourceSet().getURIConverter());
	return uriBasedFileSystemAccess;
}
 
Example #8
Source File: WorkspaceChanges.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Constructor */
public WorkspaceChanges(boolean namesOrDependenciesChanged,
		List<URI> removedURIs, List<URI> addedURIs, List<URI> changedURIs,
		List<ISourceFolder> removedSourceFolders, List<ISourceFolder> addedSourceFolders,
		List<IProjectConfig> removedProjects, List<IProjectConfig> addedProjects,
		List<IProjectConfig> projectsWithChangedDependencies) {

	this.namesOrDependenciesChanged = namesOrDependenciesChanged;
	this.removedURIs = removedURIs;
	this.addedURIs = addedURIs;
	this.changedURIs = changedURIs;
	this.removedSourceFolders = removedSourceFolders;
	this.addedSourceFolders = addedSourceFolders;
	this.removedProjects = removedProjects;
	this.addedProjects = addedProjects;
	this.projectsWithChangedDependencies = projectsWithChangedDependencies;
}
 
Example #9
Source File: N4JSProjectDescriptionFactory.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ProjectDescription getProjectDescription(IProjectConfig config) {
	ProjectDescription projectDescription = super.getProjectDescription(config);
	N4JSProjectConfig casted = (N4JSProjectConfig) config;
	IN4JSProject project = casted.toProject();
	if (project.getProjectType() == ProjectType.PLAINJS) {
		return projectDescription;
	}
	FluentIterable
			.from(project.getSortedDependencies())
			.transform(IN4JSProject::getProjectName)
			.transform(N4JSProjectName::getRawName)
			.copyInto(projectDescription.getDependencies());
	if (project.getProjectType() == ProjectType.DEFINITION) {
		projectDescription.getDependencies().add(project.getDefinesPackageName().getRawName());
	}
	return projectDescription;
}
 
Example #10
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Perform a build on all projects
 *
 * @param cancelIndicator
 *            cancellation support
 */
public void doInitialBuild(CancelIndicator cancelIndicator) {
	List<ProjectDescription> newProjects = new ArrayList<>();
	for (IProjectConfig projectConfig : getWorkspaceConfig().getProjects()) {
		ProjectDescription projectDescription = projectDescriptionFactory.getProjectDescription(projectConfig);
		newProjects.add(projectDescription);
	}
	List<Delta> deltas = buildManager.doInitialBuild(newProjects, cancelIndicator);
	afterBuild(deltas);
}
 
Example #11
Source File: DefaultTraceURIConverter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public SourceRelativeURI getURIForTrace(IProjectConfig projectConfig, AbsoluteURI absoluteURI) {
	SourceRelativeURI result = absoluteURI.deresolve(projectConfig);
	if (result == null) {
		return getURIForTrace(absoluteURI.getURI());
	}
	return result;
}
 
Example #12
Source File: ProjectStatePersister.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void asyncWriteProjectState(IProjectConfig project, XIndexState state,
		Collection<? extends HashedFileContent> files, Multimap<URI, LSPIssue> validationIssues) {

	writer.submit(() -> {
		File file = getDataFile(project);
		try (OutputStream nativeOut = Files.asByteSink(file).openBufferedStream()) {
			writeProjectState(nativeOut, N4JSLanguageUtils.getLanguageVersion(), state, files, validationIssues);
		} catch (IOException e) {
			e.printStackTrace();
			if (file.isFile()) {
				file.delete();
			}
		}
	});
}
 
Example #13
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Adds a project to the workspace */
synchronized public void addProject(IProjectConfig projectConfig) {
	XProjectManager projectManager = projectManagerProvider.get();
	ProjectDescription projectDescription = projectDescriptionFactory.getProjectDescription(projectConfig);
	projectManager.initialize(projectDescription, projectConfig, fullIndex, issueRegistry);
	projectName2ProjectManager.put(projectDescription.getName(), projectManager);
	fullIndex.setVisibleContainers(projectDescription.getName(), projectDescription.getDependencies());
}
 
Example #14
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Removes a project from the workspace */
synchronized public void removeProject(IProjectConfig projectConfig) {
	String projectName = projectConfig.getName();
	XProjectManager projectManager = getProjectManager(projectName);
	XtextResourceSet resourceSet = projectManager.getResourceSet();
	boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		resourceSet.getResources().clear();
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
	projectName2ProjectManager.remove(projectName);
	fullIndex.removeContainer(projectName);
}
 
Example #15
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 #16
Source File: XWorkspaceManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param uri
 *            the contained uri
 * @return the project manager.
 */
public XProjectManager getProjectManager(URI uri) {
	IProjectConfig projectConfig = getProjectConfig(uri);
	String name = null;
	if (projectConfig != null) {
		name = projectConfig.getName();
	}
	return getProjectManager(name);
}
 
Example #17
Source File: ProjectStatePersister.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Write the index state and a hash of the project state to disk in order to allow loading it again.
 *
 * @param project
 *            the project
 * @param state
 *            the state to be written
 * @param validationIssues
 *            map of source files to issues
 */
public void writeProjectState(IProjectConfig project, XIndexState state,
		Collection<? extends HashedFileContent> files, Multimap<URI, LSPIssue> validationIssues) {

	XIndexState indexCopy = new XIndexState(state.getResourceDescriptions().copy(), state.getFileMappings().copy());

	asyncWriteProjectState(project,
			indexCopy,
			ImmutableList.copyOf(files),
			ImmutableListMultimap.copyOf(validationIssues));
}
 
Example #18
Source File: WorkspaceManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param uri
 *            the contained uri
 * @return the project manager.
 */
public ProjectManager getProjectManager(URI uri) {
	IProjectConfig projectConfig = getProjectConfig(uri);
	String name = null;
	if (projectConfig != null) {
		name = projectConfig.getName();
	}
	return getProjectManager(name);
}
 
Example #19
Source File: CharSequenceTraceWrapper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public CharSequence wrapWithTraceData(CharSequence sequence, EObject origin) {
	ITextRegionWithLineInformation location = (ITextRegionWithLineInformation) locationInFileProvider.getSignificantTextRegion(origin);
	AbsoluteURI absoluteURI = new AbsoluteURI(origin.eResource().getURI());
	IProjectConfig projectConfig = projectConfigProvider.getProjectConfig(EcoreUtil2.getResourceSet(origin));
	SourceRelativeURI sourceRelativeURI = absoluteURI.deresolve(projectConfig);
	return wrapWithTraceData(sequence, sourceRelativeURI, location.getOffset(), location.getLength(), location.getLineNumber(), location.getEndLineNumber());
}
 
Example #20
Source File: LiveShadowedChunkedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setContext(Notifier ctx) {
	ResourceSetBasedResourceDescriptions localDescriptions = (ResourceSetBasedResourceDescriptions) getLocalDescriptions();
	localDescriptions.setContext(ctx);
	localDescriptions.setData(null);
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(ctx);
	setGlobalDescriptions(ChunkedResourceDescriptions.findInEmfObject(resourceSet));
	if (projectConfigProvider == null) {
		workspaceConfig = null;
	} else {
		IProjectConfig projectConfig = projectConfigProvider.getProjectConfig(resourceSet);
		workspaceConfig = projectConfig == null ? null : projectConfig.getWorkspaceConfig();
	}
}
 
Example #21
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected Path getPath(final URI uri, final ResourceSet context) {
  final IProjectConfig projectConfig = this.projectConfigProvider.getProjectConfig(context);
  if ((projectConfig == null)) {
    return null;
  }
  return this.getPath(uri, projectConfig.getPath(), Path.ROOT.append(projectConfig.getName()));
}
 
Example #22
Source File: XProjectManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Initialize this project. */
@SuppressWarnings("hiding")
public void initialize(ProjectDescription description, IProjectConfig projectConfig,
		ConcurrentChunkedIndex fullIndex, ConcurrentIssueRegistry issueRegistry) {

	this.projectDescription = description;
	this.projectConfig = projectConfig;
	this.fullIndex = fullIndex;
	this.issueRegistry = issueRegistry;
	this.resourceSet = createNewResourceSet(new XIndexState().getResourceDescriptions());
}
 
Example #23
Source File: BatchLinkableResourceStorageFacade.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected URI getSourceContainerURI(StorageAwareResource resource) {
	URI uri = resource.getURI();
	IProjectConfig mainProject = projectConfigProvider.getProjectConfig(resource.getResourceSet());
	if (mainProject != null) {
		IProjectConfig project = mainProject.getWorkspaceConfig().findProjectContaining(uri);
		if (project != null) {
			ISourceFolder sourceFolder = project.findSourceFolderContaining(uri);
			if (sourceFolder != null) {
				return sourceFolder.getPath();
			}
		}
	}
	return super.getSourceContainerURI(resource);
}
 
Example #24
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 #25
Source File: TraceForStorageProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IProjectConfig getProjectConfig(IFile sourceFile) {
	AbsoluteURI location = getAbsoluteLocation(sourceFile);
	IResourceServiceProvider resourceServiceProvider = getServiceProvider(location);
	if (resourceServiceProvider != null) {
		EclipseProjectConfigProvider projectConfigProvider = resourceServiceProvider.get(EclipseProjectConfigProvider.class);
		return projectConfigProvider.createProjectConfig(sourceFile.getProject());
	} else {
		LOG.error("No trace available for source file "+sourceFile.getFullPath()+", since no resource service provider could be determined.");
		return null;
	}
}
 
Example #26
Source File: WorkspaceChanges.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return a list of all removed source folders including those inside {@link #removedProjects} */
public List<ISourceFolder> getAllRemovedSourceFolders() {
	List<ISourceFolder> sourceFolders = new ArrayList<>(removedSourceFolders);
	for (IProjectConfig project : removedProjects) {
		sourceFolders.addAll(project.getSourceFolders());
	}
	return sourceFolders;
}
 
Example #27
Source File: WorkspaceChanges.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return a list of all added source folders including those inside {@link #addedProjects} */
public List<ISourceFolder> getAllAddedSourceFolders() {
	List<ISourceFolder> sourceFolders = new ArrayList<>(addedSourceFolders);
	for (IProjectConfig project : addedProjects) {
		sourceFolders.addAll(project.getSourceFolders());
	}
	return sourceFolders;
}
 
Example #28
Source File: N4JSWorkspaceConfig.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IProjectConfig findProjectByName(String name) {
	IN4JSProject project = delegate.findProject(new N4JSProjectName(name)).orNull();
	if (project != null) {
		return new N4JSProjectConfig(this, project);
	}
	return null;
}
 
Example #29
Source File: N4JSWorkspaceConfig.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<? extends IProjectConfig> getProjects() {
	Set<IProjectConfig> pConfigs = new HashSet<>();
	for (IN4JSProject project : delegate.findAllProjects()) {
		pConfigs.add(new N4JSProjectConfig(this, project));
	}
	return pConfigs;
}
 
Example #30
Source File: N4JSWorkspaceConfig.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private WorkspaceChanges detectAddedRemovedProjects(Set<? extends IProjectConfig> oldProjects) {

		// update all projects
		((N4JSRuntimeCore) delegate).deregisterAll();

		ProjectDiscoveryHelper projectDiscoveryHelper = ((N4JSRuntimeCore) delegate).getProjectDiscoveryHelper();
		Path baseDir = new FileURI(getPath()).toFile().toPath();
		LinkedHashSet<Path> newProjectPaths = projectDiscoveryHelper.collectAllProjectDirs(baseDir);
		for (Path newProjectPath : newProjectPaths) {
			((N4JSRuntimeCore) delegate).registerProject(newProjectPath.toFile());
		}

		// detect changes
		Map<URI, IProjectConfig> oldProjectsMap = getProjectsMap(oldProjects);
		Map<URI, IProjectConfig> newProjectsMap = getProjectsMap(getProjects());
		List<IProjectConfig> addedProjects = new ArrayList<>();
		List<IProjectConfig> removedProjects = new ArrayList<>();
		for (URI uri : Sets.union(oldProjectsMap.keySet(), newProjectsMap.keySet())) {
			boolean isOld = oldProjectsMap.containsKey(uri);
			boolean isNew = newProjectsMap.containsKey(uri);
			if (isOld && !isNew) {
				removedProjects.add(oldProjectsMap.get(uri));
			} else if (!isOld && isNew) {
				addedProjects.add(newProjectsMap.get(uri));
			}
		}

		boolean dependenciesChanged = !addedProjects.isEmpty() || !removedProjects.isEmpty();
		return new WorkspaceChanges(dependenciesChanged, emptyList(), emptyList(), emptyList(), emptyList(),
				emptyList(), removedProjects, addedProjects, emptyList());
	}