org.eclipse.xtext.resource.impl.ProjectDescription Java Examples

The following examples show how to use org.eclipse.xtext.resource.impl.ProjectDescription. 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: ProjectBuildOrderInfo.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** Computes the build order of all projects in the workspace */
protected void computeOrder(ProjectDescription pd, LinkedHashSet<String> orderedProjects,
		LinkedHashSet<String> projectStack) {

	String pdName = pd.getName();
	if (projectStack.contains(pdName)) {
		for (String cyclicPD : projectStack) {
			reportDependencyCycle(cyclicPD);
		}
	} else {
		projectStack.add(pdName);

		for (String depName : pd.getDependencies()) {
			XProjectManager pm = workspaceManager.getProjectManager(depName);
			if (pm != null) { // can be null if project not on disk
				ProjectDescription depPd = pm.getProjectDescription();
				computeOrder(depPd, orderedProjects, projectStack);
			}
		}

		orderedProjects.add(pdName);
		projectStack.remove(pdName);
	}
}
 
Example #2
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 #3
Source File: XBuildManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Run a full build on the workspace
 *
 * @return the delta.
 */
public List<IResourceDescription.Delta> doInitialBuild(List<ProjectDescription> projects,
		CancelIndicator indicator) {

	lspLogger.log("Initial build ...");

	ProjectBuildOrderInfo projectBuildOrderInfo = projectBuildOrderInfoProvider.get();
	ProjectBuildOrderIterator pboIterator = projectBuildOrderInfo.getIterator(projects);
	printBuildOrder();

	List<IResourceDescription.Delta> result = new ArrayList<>();

	while (pboIterator.hasNext()) {
		ProjectDescription description = pboIterator.next();
		String projectName = description.getName();
		XProjectManager projectManager = workspaceManager.getProjectManager(projectName);
		XBuildResult partialresult = projectManager.doInitialBuild(indicator);
		result.addAll(partialresult.getAffectedResources());
	}

	lspLogger.log("... initial build done.");

	return result;
}
 
Example #4
Source File: AbstractIncrementalBuilderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected BuildRequest newBuildRequest(Procedure1<? super BuildRequest> init) {
	BuildRequest result = new BuildRequest();
	ResourceDescriptionsData newIndex = indexState.getResourceDescriptions().copy();
	result.setBaseDir(uri(""));
	XtextResourceSet rs = resourceSetProvider.get();
	rs.getURIConverter().getURIHandlers().clear();
	rs.getURIConverter().getURIHandlers().add(inMemoryURIHandler);
	rs.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
	ProjectDescription projectDescription = new ProjectDescription();
	projectDescription.setName("test-project");
	projectDescription.attachToEmfObject(rs);
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), rs);
	index.setContainer(projectDescription.getName(), newIndex);
	result.setResourceSet(rs);
	result.setDirtyFiles(new ArrayList<>());
	result.setDeletedFiles(new ArrayList<>());
	result.setAfterValidate((uri, issues) -> {
		Iterables.addAll(this.issues, issues);
		return Iterables.isEmpty(issues);
	});
	result.setAfterDeleteFile(f -> deleted.add(f));
	result.setAfterGenerateFile((source, target) -> generated.put(source, target));
	result.setState(new IndexState(newIndex, indexState.getFileMappings().copy()));
	init.apply(result);
	return result;
}
 
Example #5
Source File: ProjectBuildOrderInfo.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** @return the set of projects that may contain resources that need to be rebuild given the list of changes */
protected Set<ProjectDescription> getAffectedProjects(List<IResourceDescription.Delta> changes) {
	Set<String> changedProjectsNames = new HashSet<>();
	for (IResourceDescription.Delta change : changes) {
		XProjectManager projectManager = workspaceManager.getProjectManager(change.getUri());
		ProjectDescription pd = projectManager.getProjectDescription();
		changedProjectsNames.add(pd.getName());
	}

	Set<ProjectDescription> affectedProjects = new HashSet<>();
	for (String changedProjectName : changedProjectsNames) {
		affectedProjects.addAll(inversedDependencies.get(changedProjectName));
	}

	return affectedProjects;
}
 
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: BuildManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Run an initial build
 *
 * @return the delta.
 */
public List<IResourceDescription.Delta> doInitialBuild(List<ProjectDescription> projects,
		CancelIndicator indicator) {
	List<ProjectDescription> sortedDescriptions = sortByDependencies(projects);
	List<IResourceDescription.Delta> result = new ArrayList<>();
	for (ProjectDescription description : sortedDescriptions) {
		IncrementalBuilder.Result partialresult = workspaceManager.getProjectManager(description.getName())
				.doInitialBuild(indicator);
		result.addAll(partialresult.getAffectedResources());
	}
	return result;
}
 
Example #8
Source File: BuildOrderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void assertEquals(final List<ProjectDescription> expected, final List<ProjectDescription> actual) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Expected: ");
  String _asString = this.asString(expected);
  _builder.append(_asString);
  _builder.append(" but was ");
  String _asString_1 = this.asString(actual);
  _builder.append(_asString_1);
  Assert.assertEquals(_builder.toString(), expected, actual);
}
 
Example #9
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 #10
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc,
		IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	if (descriptions == null)
		throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
	ProjectDescription projectDescription = ProjectDescription.findInEmfObject(descriptions.getResourceSet());
	List<IContainer> allContainers = new ArrayList<>();
	allContainers.add(createContainer(resourceDescriptions, descriptions, projectDescription.getName()));
	for (String name : projectDescription.getDependencies())
		allContainers.add(createContainer(resourceDescriptions, descriptions, name));
	return allContainers;
}
 
Example #11
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 #12
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	if (descriptions == null)
		throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
	return createContainer(resourceDescriptions, descriptions,
			ProjectDescription.findInEmfObject(descriptions.getResourceSet()).getName());
}
 
Example #13
Source File: IndexedJvmTypeAccessTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetIndexedJvmTypeByURI() throws ClassNotFoundException {
	ProjectDescription projectDescription = new ProjectDescription();
	projectDescription.setName("test-project");
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), resourceSet);
	ResourceDescriptionsData data = new ResourceDescriptionsData(new ArrayList<>());
	index.setContainer(projectDescription.getName(), data);
	ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(resourceSet, data);

	Resource resource = resourceSet.createResource(URI.createURI("test.typesRefactoring"));

	BinaryClass binaryClass = BinaryClass.forName("testdata.Outer", getClass().getClassLoader());
	JvmDeclaredType outerType = declaredTypeFactory.createType(binaryClass);
	resource.getContents().add(outerType);
	JvmDeclaredType innerType = findType(outerType, "Inner");
	JvmDeclaredType innerMostType = findType(outerType, "InnerMost");

	IResourceServiceProvider serviceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resource.getURI());
	IResourceDescription description = serviceProvider.getResourceDescriptionManager().getResourceDescription(resource);
	data.addDescription(description.getURI(), description);

	URI javaObjectURI = EcoreUtil.getURI(getOperation(outerType, "getOuter").getReturnType().getType());
	EObject outerTypeFromIndex = indexedJvmTypeAccess.getIndexedJvmType(javaObjectURI , resourceSet);
	assertSame(outerType, outerTypeFromIndex);

	javaObjectURI = EcoreUtil.getURI(getOperation(outerType, "getInner").getReturnType().getType());
	EObject innerTypeFromIndex = indexedJvmTypeAccess.getIndexedJvmType(javaObjectURI , resourceSet);
	assertSame(innerType, innerTypeFromIndex);

	javaObjectURI = EcoreUtil.getURI(getOperation(outerType, "getInnerMost").getReturnType().getType());
	EObject innerMostTypeFromIndex = indexedJvmTypeAccess.getIndexedJvmType(javaObjectURI , resourceSet);
	assertSame(innerMostType, innerMostTypeFromIndex);
}
 
Example #14
Source File: ReusedTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	if (ReusedTypeProviderTest.typeProvider == null) {
		String pathToSources = "/org/eclipse/xtext/common/types/testSetups";
		List<String> files = ReusedTypeProviderTest.readResource(pathToSources + "/files.list");
		ResourceDescriptionsData part = new ResourceDescriptionsData(Collections.emptySet());
		XtextResourceSet resourceSet = resourceSetProvider.get();
		ProjectDescription projectDesc = new ProjectDescription();
		projectDesc.setName("my-test-project");
		projectDesc.attachToEmfObject(resourceSet);
		ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(Collections.emptyMap(), resourceSet);
		index.setContainer(projectDesc.getName(), part);
		resourceSet.setClasspathURIContext(ReusedTypeProviderTest.class.getClassLoader());

		typeProviderFactory.createTypeProvider(resourceSet);
		BuildRequest buildRequest = new BuildRequest();
		for (String file : files) {
			if (file != null) {
				String fullPath = pathToSources + "/" + file;
				URL url = ReusedTypeProviderTest.class.getResource(fullPath);
				buildRequest.getDirtyFiles().add(URI.createURI(url.toExternalForm()));
			}
		}
		buildRequest.setResourceSet(resourceSet);
		buildRequest.setState(new IndexState(part, new Source2GeneratedMapping()));
		builder.build(buildRequest, (URI it) -> {
			return resourceServiceProviderRegistry.getResourceServiceProvider(it);
		});
		ReusedTypeProviderTest.typeProvider = typeProviderFactory.findTypeProvider(resourceSet);
	}
}
 
Example #15
Source File: N4JSProjectConfig.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Bring the given project description up-to-date with the receiving project configuration's internal state. */
public void updateProjectDescription(ProjectDescription projectDescriptionToUpdate) {
	String currName = ((N4JSProject) delegate).getProjectName().getRawName();
	List<String> currDeps = ((N4JSProject) delegate).getAllDependenciesAndImplementedApiNames();
	projectDescriptionToUpdate.setName(currName);
	projectDescriptionToUpdate.setDependencies(currDeps);
}
 
Example #16
Source File: N4JSOutputConfigurationProvider.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<OutputConfiguration> getOutputConfigurations(ResourceSet context) {
	EList<Resource> resources = context.getResources();
	if (resources.isEmpty()) {
		ProjectDescription description = ProjectDescription.findInEmfObject(context);
		IN4JSProject project = n4jsCore.findProject(new N4JSProjectName(description.getName())).orNull();
		return getOutputConfigurationSet(project);
	}
	return getOutputConfigurations(resources.get(0));
}
 
Example #17
Source File: TopologicalSorter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public List<ProjectDescription> sortByDependencies(Iterable<ProjectDescription> descriptions,
		Procedure1<? super ProjectDescription> cyclicAcceptor) {
	this.cyclicAcceptor = cyclicAcceptor::apply;
	name2entry = new LinkedHashMap<>();
	for (ProjectDescription project : descriptions) {
		Entry entry = new TopologicalSorter.Entry(project);
		name2entry.put(entry.description.getName(), entry);
	}
	result = new LinkedHashSet<>();
	name2entry.values().forEach(it -> visit(it));
	return Lists.newArrayList(result);
}
 
Example #18
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 #19
Source File: XBuildManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Prints build order */
protected void printBuildOrder() {
	if (LOG.isInfoEnabled()) {
		ProjectBuildOrderInfo projectBuildOrderInfo = projectBuildOrderInfoProvider.get();
		ProjectBuildOrderIterator visitAll = projectBuildOrderInfo.getIterator().visitAll();
		String output = "Project build order:\n  "
				+ IteratorExtensions.join(visitAll, "\n  ", ProjectDescription::getName);
		LOG.info(output);
	}
}
 
Example #20
Source File: XBuildManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private Map<ProjectDescription, Set<URI>> computeProjectToUriMap(Collection<URI> uris) {
	Map<ProjectDescription, Set<URI>> project2uris = new HashMap<>();
	for (URI uri : uris) {
		XProjectManager projectManager = workspaceManager.getProjectManager(uri);
		if (projectManager == null) {
			continue; // happens when editing a package.json file in a newly created project
		}
		ProjectDescription projectDescription = projectManager.getProjectDescription();
		if (!project2uris.containsKey(projectDescription)) {
			project2uris.put(projectDescription, new HashSet<>());
		}
		project2uris.get(projectDescription).add(uri);
	}
	return project2uris;
}
 
Example #21
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 #22
Source File: ProjectBuildOrderInfo.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Creates a new instance of {@link ProjectBuildOrderIterator}. The given set of projects will be visited only. */
@Override
public ProjectBuildOrderIterator getIterator(Collection<ProjectDescription> projectDescriptions) {
	ProjectBuildOrderIterator iterator = getIterator();
	iterator.visit(projectDescriptions);
	return iterator;
}
 
Example #23
Source File: ProjectBuildOrderInfo.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public ProjectBuildOrderIterator visit(Collection<ProjectDescription> projectDescriptions) {
	for (ProjectDescription prj : projectDescriptions) {
		visitProjectNames.add(prj.getName());
	}
	return this;
}
 
Example #24
Source File: IOrderInfo.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/** Creates a new instance of {@link IOrderIterator}. The given set of projects will be visited only. */
public IOrderIterator<T> getIterator(Collection<ProjectDescription> elements);
 
Example #25
Source File: DefaultProjectDescriptionFactory.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ProjectDescription getProjectDescription(IProjectConfig config) {
	ProjectDescription result = new ProjectDescription();
	result.setName(config.getName());
	return result;
}
 
Example #26
Source File: XDefaultProjectDescriptionFactory.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ProjectDescription getProjectDescription(IProjectConfig config) {
	ProjectDescription result = new ProjectDescription();
	result.setName(config.getName());
	return result;
}
 
Example #27
Source File: TopologicalSorter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Entry(ProjectDescription description) {
	this.description = description;
}
 
Example #28
Source File: ProjectManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ProjectDescription getProjectDescription() {
	return projectDescription;
}
 
Example #29
Source File: BuildManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Get a sorted list of projects to be build.
 */
protected List<ProjectDescription> sortByDependencies(Iterable<ProjectDescription> projectDescriptions) {
	return sorterProvider.get().sortByDependencies(projectDescriptions, (it) -> {
		reportDependencyCycle(workspaceManager.getProjectManager(it.getName()));
	});
}
 
Example #30
Source File: ProjectBuildOrderInfo.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ProjectDescription next() {
	return iteratorDelegate.next();
}