Java Code Examples for org.eclipse.xtext.workspace.ProjectConfigAdapter

The following examples show how to use org.eclipse.xtext.workspace.ProjectConfigAdapter. 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 check out the related API usage on the sidebar.
Example 1
@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 2
/**
 * creates a fresh resource set with the given resources
 * 
 * @param resources - pairs of file names and their contents 
 * @return a ResourceSet, containing the given resources.
 * @throws IOException if the resource loading fails 
 */
@SuppressWarnings("unchecked")
public ResourceSet resourceSet(Pair<String,? extends CharSequence> ...resources ) throws IOException {
	XtextResourceSet result = newResourceSetWithUTF8Encoding();
	FileProjectConfig projectConfig = new FileProjectConfig(new File(workspaceRoot,PROJECT_NAME), PROJECT_NAME);
	projectConfig.addSourceFolder("src");
	ProjectConfigAdapter.install(result, projectConfig);
	for (Pair<String, ? extends CharSequence> entry : resources) {
		URI uri = copyToWorkspace(getSourceFolderPath()+"/"+entry.getKey(), entry.getValue());
		Resource resource = result.createResource(uri);
		if (resource == null)
			throw new IllegalStateException("Couldn't create resource for URI "+uri+". Resource.Factory not registered?");
		resource.load(result.getLoadOptions());
	}
	return result;
}
 
Example 3
Source Project: n4js   Source File: XProjectManager.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** Create and configure a new resource set for this project. */
protected XtextResourceSet createNewResourceSet(ResourceDescriptionsData newIndex) {
	XtextResourceSet result = resourceSetProvider.get();
	result.setURIResourceMap(uriResourceMap);
	projectDescription.attachToEmfObject(result);
	ProjectConfigAdapter.install(result, projectConfig);
	attachWorkspaceResourceLocator(result);

	ChunkedResourceDescriptions index = fullIndex.toDescriptions(result);
	index.setContainer(projectDescription.getName(), newIndex);
	return result;
}
 
Example 4
/**
 * creates a fresh resource set with the given resources
 * 
 * @param resources - pairs of file names and their contents 
 * @return a ResourceSet, containing the given resources.
 * @throws IOException if the resource loading fails 
 */
public ResourceSet resourceSet(@SuppressWarnings("unchecked") Pair<String,? extends CharSequence> ...resources ) throws IOException {
	XtextResourceSet result = newResourceSetWithUTF8Encoding();
	FileProjectConfig projectConfig = new FileProjectConfig(new File(workspaceRoot,PROJECT_NAME), PROJECT_NAME);
	projectConfig.addSourceFolder("src");
	ProjectConfigAdapter.install(result, projectConfig);
	for (Pair<String, ? extends CharSequence> entry : resources) {
		URI uri = copyToWorkspace(getSourceFolderPath()+"/"+entry.getKey(), entry.getValue());
		Resource resource = result.createResource(uri);
		if (resource == null)
			throw new IllegalStateException("Couldn't create resource for URI "+uri+". Resource.Factory not registered?");
		resource.load(result.getLoadOptions());
	}
	return result;
}
 
Example 5
@Override
public ResourceSet get(IProject project) {
	XtextResourceSet set = resourceSetProvider.get();
	if (project != null) {
		ProjectConfigAdapter.install(set, projectConfigProvider.createProjectConfig(project));	
	}
	for(int i = 0; i < initializers.size(); i++) {
		initializers.get(i).initialize(set, project);
	}
	return set;
}
 
Example 6
@Before
public void setUp() {
  try {
    WorkspaceConfig _workspaceConfig = new WorkspaceConfig();
    this.workspaceConfig = _workspaceConfig;
    ProjectConfig _projectConfig = new ProjectConfig("foo", this.workspaceConfig);
    this.fooProject = _projectConfig;
    ProjectConfig _projectConfig_1 = new ProjectConfig("bar", this.workspaceConfig);
    this.barProject = _projectConfig_1;
    final XtextResourceSet rs0 = this.resourceSetProvider.get();
    this.fooURI = IterableExtensions.<SourceFolder>head(this.fooProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("foo.livecontainertestlanguage");
    this.barURI = IterableExtensions.<SourceFolder>head(this.barProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("bar.livecontainertestlanguage");
    ResourceDescriptionsData _createResourceDescriptionData = this.createResourceDescriptionData(this._parseHelper.parse("foo", this.fooURI, rs0).eResource());
    Pair<String, ResourceDescriptionsData> _mappedTo = Pair.<String, ResourceDescriptionsData>of("foo", _createResourceDescriptionData);
    ResourceDescriptionsData _createResourceDescriptionData_1 = this.createResourceDescriptionData(this._parseHelper.parse("bar", this.barURI, rs0).eResource());
    Pair<String, ResourceDescriptionsData> _mappedTo_1 = Pair.<String, ResourceDescriptionsData>of("bar", _createResourceDescriptionData_1);
    final Map<String, ResourceDescriptionsData> chunks = Collections.<String, ResourceDescriptionsData>unmodifiableMap(CollectionLiterals.<String, ResourceDescriptionsData>newHashMap(_mappedTo, _mappedTo_1));
    this.rs1 = this.resourceSetProvider.get();
    new ChunkedResourceDescriptions(chunks, this.rs1);
    ProjectConfigAdapter.install(this.rs1, this.fooProject);
    this.liveShadowedChunkedResourceDescriptions = this.provider.get();
    this.liveShadowedChunkedResourceDescriptions.setContext(this.rs1);
    LiveShadowedChunkedContainer _liveShadowedChunkedContainer = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "foo");
    this.fooContainer = _liveShadowedChunkedContainer;
    LiveShadowedChunkedContainer _liveShadowedChunkedContainer_1 = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "bar");
    this.barContainer = _liveShadowedChunkedContainer_1;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source Project: xtext-core   Source File: ProjectManager.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create and configure a new resource set for this project.
 */
public XtextResourceSet createNewResourceSet(ResourceDescriptionsData newIndex) {
	XtextResourceSet result = resourceSetProvider.get();
	projectDescription.attachToEmfObject(result);
	ProjectConfigAdapter.install(result, projectConfig);
	ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(indexProvider.get(), result);
	index.setContainer(projectDescription.getName(), newIndex);
	externalContentSupport.configureResourceSet(result, openedDocumentsContentProvider);
	return result;
}
 
Example 8
@Override
public ResourceSet get(IProject project) {
	XtextResourceSet xtextResourceSet = resourceSetProvider.get();
	ProjectConfigAdapter.install(xtextResourceSet, projectConfigProvider.createProjectConfig(project));
	return xtextResourceSet;
}
 
Example 9
@Override
public IProjectConfig getProjectConfig(ResourceSet context) {
	ProjectConfigAdapter projectConfigAdapter = ProjectConfigAdapter.findInEmfObject(context);
	return projectConfigAdapter != null ? projectConfigAdapter.getProjectConfig() : null;
}
 
Example 10
public void installProjectConfig(IProject eclipseProject, ResourceSet resourceSet) {
	EclipseProjectConfig config = createProjectConfig(eclipseProject);
	ProjectConfigAdapter.install(resourceSet, config);
}
 
Example 11
Source Project: xtext-xtend   Source File: XtendBatchCompiler.java    License: Eclipse Public License 2.0 4 votes vote down vote up
private boolean configureWorkspace(ResourceSet resourceSet) {
	List<File> sourceFileList = getSourcePathFileList();
	File outputFile = getOutputPathFile();
	if (sourceFileList == null || outputFile == null) {
		return false;
	}

	File commonRoot = determineCommonRoot(outputFile, sourceFileList);

	// We don't want to use root ("/") as a workspace folder, didn't we?
	if (commonRoot == null || commonRoot.getParent() == null || commonRoot.getParentFile().getParent() == null) {
		log.error("All source folders and the output folder should have "
				+ "a common parent non-top level folder (like project folder)");
		for (File sourceFile : sourceFileList) {
			log.error("(Source folder: '" + sourceFile + "')");
		}
		log.error("(Output folder: '" + outputFile + "')");
		return false;
	}
	projectConfig = new FileProjectConfig(commonRoot, commonRoot.getName());

	java.net.URI commonURI = commonRoot.toURI();
	java.net.URI relativizedTarget = commonURI.relativize(outputFile.toURI());
	if (relativizedTarget.isAbsolute()) {
		log.error("Target folder '" + outputFile + "' must be a child of the project folder '" + commonRoot + "'");
		return false;
	}
	CharMatcher slash = CharMatcher.is('/');
	String relativeTargetFolder = slash.trimTrailingFrom(relativizedTarget.getPath());
	outputConfiguration = Iterables.getOnlyElement(outputConfigurationProvider.getOutputConfigurations());
	outputConfiguration.setOutputDirectory(relativeTargetFolder);
	for (File source : sourceFileList) {
		java.net.URI relativizedSrc = commonURI.relativize(source.toURI());
		if (relativizedSrc.isAbsolute()) {
			log.error("Source folder '" + source + "' must be a child of the project folder '" + commonRoot + "'");
			return false;
		}
		projectConfig.addSourceFolder(slash.trimTrailingFrom(relativizedSrc.getPath()));
	}
	Map<String, Set<OutputConfiguration>> outputConfigurations = newHashMap();
	outputConfigurations.put(languageName, newHashSet(outputConfiguration));
	ProjectConfigAdapter.install(resourceSet, projectConfig);
	resourceSet.eAdapters().add(new OutputConfigurationAdapter(outputConfigurations));
	return true;
}