Search in sources :

Example 6 with FileProjectConfig

use of org.eclipse.xtext.workspace.FileProjectConfig in project xtext-xtend by eclipse.

the class TestBatchCompiler method testProjectConfigMultipleSourceDirs3.

@Test
public void testProjectConfigMultipleSourceDirs3() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("ws/prj1/dir1/src");
    _builder.append(File.pathSeparator);
    _builder.append("ws/prj1/src-gen");
    this.batchCompiler.setSourcePath(_builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("ws/prj1/dir2/bin");
    this.batchCompiler.setOutputPath(_builder_1.toString());
    this.batchCompiler.compile();
    final FileProjectConfig project = this.batchCompiler.getProjectConfig();
    Assert.assertEquals("prj1", project.getName());
    final OutputConfiguration output = this.batchCompiler.getOutputConfiguration();
    Assert.assertEquals(2, project.getSourceFolders().size());
    final Function1<FileSourceFolder, String> _function = (FileSourceFolder it) -> {
        return it.getName();
    };
    final List<String> keyPaths = IterableExtensions.<String>sort(IterableExtensions.<FileSourceFolder, String>map(project.getSourceFolders(), _function));
    String _get = keyPaths.get(0);
    final Procedure1<String> _function_1 = (String it) -> {
        Assert.assertEquals("dir1/src", it);
        Assert.assertEquals("dir2/bin", output.getOutputDirectory(it));
    };
    ObjectExtensions.<String>operator_doubleArrow(_get, _function_1);
    String _get_1 = keyPaths.get(1);
    final Procedure1<String> _function_2 = (String it) -> {
        Assert.assertEquals("src-gen", it);
        Assert.assertEquals("dir2/bin", output.getOutputDirectory(it));
    };
    ObjectExtensions.<String>operator_doubleArrow(_get_1, _function_2);
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) FileSourceFolder(org.eclipse.xtext.workspace.FileSourceFolder) IgnoredBySmokeTest(org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest) Test(org.junit.Test)

Example 7 with FileProjectConfig

use of org.eclipse.xtext.workspace.FileProjectConfig in project xtext-core by eclipse.

the class MultiProjectWorkspaceConfigFactory method findProjects.

@Override
public void findProjects(final WorkspaceConfig workspaceConfig, final URI uri) {
    if ((uri == null)) {
        return;
    }
    String _fileString = uri.toFileString();
    final File baseFile = new File(_fileString);
    boolean _isDirectory = baseFile.isDirectory();
    boolean _not = (!_isDirectory);
    if (_not) {
        return;
    }
    final Function1<File, Boolean> _function = (File it) -> {
        return Boolean.valueOf(it.isDirectory());
    };
    Iterable<File> _filter = IterableExtensions.<File>filter(((Iterable<File>) Conversions.doWrapArray(baseFile.listFiles())), _function);
    for (final File file : _filter) {
        {
            final FileProjectConfig project = new FileProjectConfig(file, workspaceConfig);
            project.addSourceFolder(".");
            workspaceConfig.addProject(project);
        }
    }
}
Also used : FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) File(java.io.File)

Example 8 with FileProjectConfig

use of org.eclipse.xtext.workspace.FileProjectConfig in project xtext-xtend by eclipse.

the class JavaIoFileSystemTest method setUp.

@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);
    }
}
Also used : JavaIOFileSystemSupport(org.eclipse.xtend.core.macro.JavaIOFileSystemSupport) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider) IProjectConfigProvider(org.eclipse.xtext.workspace.IProjectConfigProvider) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 9 with FileProjectConfig

use of org.eclipse.xtext.workspace.FileProjectConfig in project xtext-xtend by eclipse.

the class XtendBatchCompiler method configureWorkspace.

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;
}
Also used : Set(java.util.Set) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CharMatcher(com.google.common.base.CharMatcher) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) OutputConfigurationAdapter(org.eclipse.xtext.generator.OutputConfigurationAdapter) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) File(java.io.File)

Example 10 with FileProjectConfig

use of org.eclipse.xtext.workspace.FileProjectConfig in project xtext-xtend by eclipse.

the class TestBatchCompiler method testProjectConfig.

@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);
    }
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) File(java.io.File) IgnoredBySmokeTest(org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest) Test(org.junit.Test)

Aggregations

FileProjectConfig (org.eclipse.xtext.workspace.FileProjectConfig)13 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)7 IgnoredBySmokeTest (org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest)7 Test (org.junit.Test)7 File (java.io.File)6 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 FileSourceFolder (org.eclipse.xtext.workspace.FileSourceFolder)6 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 JavaIOFileSystemSupport (org.eclipse.xtend.core.macro.JavaIOFileSystemSupport)2 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 IEncodingProvider (org.eclipse.xtext.parser.IEncodingProvider)2 IProjectConfigProvider (org.eclipse.xtext.workspace.IProjectConfigProvider)2 Before (org.junit.Before)2 CharMatcher (com.google.common.base.CharMatcher)1 Set (java.util.Set)1 URI (org.eclipse.emf.common.util.URI)1 DelegatingClassloader (org.eclipse.xtend.core.tests.macro.DelegatingClassloader)1 OutputConfigurationAdapter (org.eclipse.xtext.generator.OutputConfigurationAdapter)1 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)1