org.eclipse.xtext.workspace.FileProjectConfig Java Examples

The following examples show how to use org.eclipse.xtext.workspace.FileProjectConfig. 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: CompilationTestHelper.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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 #2
Source File: TestBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testProjectConfig() {
  try {
    this.batchCompiler.compile();
    final FileProjectConfig project = this.batchCompiler.getProjectConfig();
    final String projectPath = new File(".").getCanonicalFile().getName();
    Assert.assertEquals(projectPath, project.getName());
    final OutputConfiguration output = this.batchCompiler.getOutputConfiguration();
    final String src = IterableExtensions.<FileSourceFolder>head(project.getSourceFolders()).getName();
    Assert.assertEquals("batch-compiler-data/test data", src.toString());
    final String target = output.getOutputDirectory(src);
    Assert.assertEquals("test-result", target.toString());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #3
Source File: XProjectWorkspaceConfigFactory.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find all projects at the given location. By default, only the a single project at the workspace root is created.
 */
protected IProjectConfig createProjectConfig(XWorkspaceConfig workspaceConfig, URI location) {
	if (location != null) {
		FileProjectConfig project = new FileProjectConfig(location, workspaceConfig);
		project.addSourceFolder(".");
		workspaceConfig.addProject(project);
		return project;
	}
	return null;
}
 
Example #4
Source File: CompilationTestHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  try {
    final File tempDir = this.temporaryFolder.newFolder();
    JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
    final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
      final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
        File _file = new File(tempDir, "foo");
        FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
        final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
          it_2.addSourceFolder("src");
        };
        return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
      };
      it.setProjectConfigProvider(_function_1);
      IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
      it.setEncodingProvider(_runtime);
      XtextResourceSet _xtextResourceSet = new XtextResourceSet();
      it.setContext(_xtextResourceSet);
    };
    JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
    this.fs = _doubleArrow;
    this.createProject("foo");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #6
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  try {
    final File tempDir = this.temporaryFolder.newFolder();
    JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
    final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
      final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
        File _file = new File(tempDir, "foo");
        FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
        final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
          it_2.addSourceFolder("src");
        };
        return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
      };
      it.setProjectConfigProvider(_function_1);
      IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
      it.setEncodingProvider(_runtime);
      XtextResourceSet _xtextResourceSet = new XtextResourceSet();
      it.setContext(_xtextResourceSet);
    };
    JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
    this.fs = _doubleArrow;
    this.createProject("foo");
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: IndexOnlyProjectTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public com.google.inject.Module getServerModule() {
  ServerModule _serverModule = new ServerModule();
  final com.google.inject.Module _function = (Binder it) -> {
    AnnotatedBindingBuilder<IMultiRootWorkspaceConfigFactory> _bind = it.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class);
    _bind.toInstance(new MultiRootWorkspaceConfigFactory() {
      @Override
      public void addProjectsForWorkspaceFolder(final WorkspaceConfig workspaceConfig, final WorkspaceFolder workspaceFolder, final Set<String> existingNames) {
        String _uri = null;
        if (workspaceFolder!=null) {
          _uri=workspaceFolder.getUri();
        }
        boolean _tripleNotEquals = (_uri != null);
        if (_tripleNotEquals) {
          URI _uri_1 = this.getUriExtensions().toUri(workspaceFolder.getUri());
          String _uniqueProjectName = this.getUniqueProjectName(workspaceFolder.getName(), existingNames);
          final FileProjectConfig project = new FileProjectConfig(_uri_1, _uniqueProjectName) {
            @Override
            public boolean isIndexOnly() {
              return true;
            }
          };
          project.addSourceFolder(".");
          workspaceConfig.addProject(project);
        }
      }
    });
  };
  return Modules2.mixin(_serverModule, _function);
}
 
Example #8
Source File: MultiProjectWorkspaceConfigFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void findProjects(WorkspaceConfig workspaceConfig, URI uri) {
	if (uri == null) {
		return;
	}
	File baseFile = new File(uri.toFileString());
	if (!baseFile.isDirectory()) {
		return;
	}
	for (File dir : baseFile.listFiles(File::isDirectory)) {
		FileProjectConfig project = new FileProjectConfig(dir, workspaceConfig);
		project.addSourceFolder(".");
		workspaceConfig.addProject(project);
	}
}
 
Example #9
Source File: MultiRootWorkspaceConfigFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
	if (workspaceFolder != null && workspaceFolder.getUri() != null) {
		FileProjectConfig project = new FileProjectConfig(uriExtensions.toUri(workspaceFolder.getUri()), getUniqueProjectName(workspaceFolder.getName(), existingNames));
		project.addSourceFolder(".");
		workspaceConfig.addProject(project);
	}
}
 
Example #10
Source File: XtendBatchCompiler.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @noreference Only for testing
 */
public FileProjectConfig getProjectConfig() {
	return projectConfig;
}
 
Example #11
Source File: XtendBatchCompiler.java    From xtext-xtend with 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;
}
 
Example #12
Source File: SourceFolderCustomImplTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public CustomFileSourceFolder(FileProjectConfig parent, String name) {
	super(parent, name);
}