Search in sources :

Example 1 with OutputConfigurationAdapter

use of org.eclipse.xtext.generator.OutputConfigurationAdapter in project xtext-core by eclipse.

the class AbstractIncrementalBuilderTest method withOutputConfig.

protected void withOutputConfig(final BuildRequest it, final Procedure1<? super OutputConfiguration> init) {
    final OutputConfiguration config = IterableExtensions.<OutputConfiguration>head(this.configurationProvider.getOutputConfigurations());
    init.apply(config);
    Pair<String, Set<OutputConfiguration>> _mappedTo = Pair.<String, Set<OutputConfiguration>>of(this.languageName, Collections.<OutputConfiguration>unmodifiableSet(CollectionLiterals.<OutputConfiguration>newHashSet(config)));
    final OutputConfigurationAdapter adapter = new OutputConfigurationAdapter(Collections.<String, Set<OutputConfiguration>>unmodifiableMap(CollectionLiterals.<String, Set<OutputConfiguration>>newHashMap(_mappedTo)));
    EList<Adapter> _eAdapters = it.getResourceSet().eAdapters();
    _eAdapters.add(adapter);
}
Also used : Set(java.util.Set) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) Adapter(org.eclipse.emf.common.notify.Adapter) OutputConfigurationAdapter(org.eclipse.xtext.generator.OutputConfigurationAdapter) OutputConfigurationAdapter(org.eclipse.xtext.generator.OutputConfigurationAdapter)

Example 2 with OutputConfigurationAdapter

use of org.eclipse.xtext.generator.OutputConfigurationAdapter 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)

Aggregations

Set (java.util.Set)2 OutputConfigurationAdapter (org.eclipse.xtext.generator.OutputConfigurationAdapter)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 CharMatcher (com.google.common.base.CharMatcher)1 File (java.io.File)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)1 FileProjectConfig (org.eclipse.xtext.workspace.FileProjectConfig)1