Search in sources :

Example 6 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method getFile.

protected IFile getFile(String fileName, String outputName) {
    OutputConfiguration configuration = getOutputConfig(outputName);
    IContainer container = getContainer(configuration);
    IFile result = container.getFile(new Path(fileName));
    syncIfNecessary(result);
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) IContainer(org.eclipse.core.resources.IContainer)

Example 7 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method generateFile.

public void generateFile(String fileName, String outputName, CharSequence contents) {
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    OutputConfiguration outputConfig = getOutputConfig(outputName);
    if (!ensureOutputConfigurationDirectoryExists(outputConfig))
        return;
    IFile file = getFile(fileName, outputName);
    IFile traceFile = getTraceFile(file);
    try {
        String encoding = getEncoding(file);
        CharSequence postProcessedContent = postProcess(fileName, outputName, contents, encoding);
        String contentsAsString = postProcessedContent.toString();
        if (file.exists()) {
            if (outputConfig.isOverrideExistingResources()) {
                StringInputStream newContent = getInputStream(contentsAsString, encoding);
                if (hasContentsChanged(file, newContent)) {
                    // reset to offset zero allows to reuse internal byte[]
                    // no need to convert the string twice
                    newContent.reset();
                    file.setContents(newContent, true, true, monitor);
                } else {
                    file.touch(getMonitor());
                }
                if (file.isDerived() != outputConfig.isSetDerivedProperty()) {
                    setDerived(file, outputConfig.isSetDerivedProperty());
                }
                if (traceFile != null)
                    updateTraceInformation(traceFile, postProcessedContent, outputConfig.isSetDerivedProperty());
                if (callBack != null)
                    callBack.afterFileUpdate(file);
            }
        } else {
            ensureParentExists(file);
            file.create(getInputStream(contentsAsString, encoding), true, monitor);
            if (outputConfig.isSetDerivedProperty()) {
                setDerived(file, true);
            }
            if (traceFile != null)
                updateTraceInformation(traceFile, postProcessedContent, outputConfig.isSetDerivedProperty());
            if (callBack != null)
                callBack.afterFileCreation(file);
        }
    } catch (CoreException e) {
        throw new RuntimeIOException(e);
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException)

Example 8 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project xtext-xtend by eclipse.

the class FileLocationsImpl method getTargetFolder.

@Override
public Path getTargetFolder(final Path path) {
    Path _xblockexpression = null;
    {
        final Path projectFolder = this.getProjectFolder(path);
        if ((projectFolder == null)) {
            return null;
        }
        final OutputConfiguration outputConfiguration = IterableExtensions.<OutputConfiguration>head(this.outputConfigurationProvider.getOutputConfigurations(this.context));
        final Path sourceFolder = this.getSourceFolder(path);
        String _xifexpression = null;
        if ((sourceFolder == null)) {
            _xifexpression = outputConfiguration.getOutputDirectory();
        } else {
            String _xblockexpression_1 = null;
            {
                final String projectRelativeSourceFolder = IterableExtensions.join(IterableExtensions.<String>tail(sourceFolder.getSegments()), "/");
                _xblockexpression_1 = outputConfiguration.getOutputDirectory(projectRelativeSourceFolder);
            }
            _xifexpression = _xblockexpression_1;
        }
        final String outputFolder = _xifexpression;
        _xblockexpression = projectFolder.append(outputFolder);
    }
    return _xblockexpression;
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration)

Example 9 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project xtext-xtend by eclipse.

the class TestBatchCompiler method testProjectConfigMultipleSourceDirs4.

@Test
public void testProjectConfigMultipleSourceDirs4() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("ws/prj1/src");
    _builder.append(File.pathSeparator);
    _builder.append("ws/prj1/dir1/src-gen");
    this.batchCompiler.setSourcePath(_builder.toString());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("ws/prj1/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-gen", it);
        Assert.assertEquals("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", it);
        Assert.assertEquals("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 10 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project xtext-xtend by eclipse.

the class TestBatchCompiler method testProjectConfigMultipleSourceDirs1.

@Test
public void testProjectConfigMultipleSourceDirs1() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("ws/prj1/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/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("src", it);
        Assert.assertEquals("bin", output.getOutputDirectory(it).toString());
    };
    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("bin", output.getOutputDirectory(it).toString());
    };
    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)

Aggregations

OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)29 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 Test (org.junit.Test)9 IgnoredBySmokeTest (org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest)7 FileProjectConfig (org.eclipse.xtext.workspace.FileProjectConfig)7 FileSourceFolder (org.eclipse.xtext.workspace.FileSourceFolder)6 IContainer (org.eclipse.core.resources.IContainer)4 IFile (org.eclipse.core.resources.IFile)4 File (java.io.File)3 IMarker (org.eclipse.core.resources.IMarker)3 IProject (org.eclipse.core.resources.IProject)3 CoreException (org.eclipse.core.runtime.CoreException)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 IOException (java.io.IOException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 URI (org.eclipse.emf.common.util.URI)2 BuildRequest (org.eclipse.xtext.build.BuildRequest)2 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)2