Search in sources :

Example 16 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project mechanoid by robotoworks.

the class MechanoidBuilderParticipant method ensureSourceFolders.

private void ensureSourceFolders(IBuildContext context, EclipseResourceFileSystemAccess2 fileSystemAccess) throws CoreException {
    IProject project = context.getBuiltProject();
    for (OutputConfiguration config : fileSystemAccess.getOutputConfigurations().values()) {
        IFolder folder = project.getFolder(new Path(config.getOutputDirectory()));
        makeSourceFolder(folder, null);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 17 with OutputConfiguration

use of org.eclipse.xtext.generator.OutputConfiguration in project mechanoid by robotoworks.

the class StandaloneFileSystemAccess method generateFile.

@Override
public void generateFile(String fileName, String outputConfigName, CharSequence contents) throws RuntimeIOException {
    OutputConfiguration config = getOutputConfig(outputConfigName);
    File file = getFile(fileName, outputConfigName);
    if (file.exists()) {
        if (config.isOverrideExistingResources()) {
            System.out.println("generating " + file.getAbsolutePath());
            super.generateFile(fileName, outputConfigName, contents);
        } else {
            System.out.println("skipping " + file.getAbsolutePath() + ", already exists.");
        }
    } else {
        System.out.println("generating " + file.getAbsolutePath());
        super.generateFile(fileName, outputConfigName, contents);
    }
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) File(java.io.File)

Example 18 with OutputConfiguration

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

the class ApplauseBuilderParticipant method build.

public void build(final IBuildContext context, IProgressMonitor monitor) throws CoreException {
    if (!isEnabled(context)) {
        return;
    }
    final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context);
    if (deltas.isEmpty()) {
        return;
    }
    final int numberOfDeltas = deltas.size();
    // monitor handling
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    SubMonitor subMonitor = SubMonitor.convert(monitor, numberOfDeltas + 3);
    ApplauseEclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get();
    final IProject builtProject = context.getBuiltProject();
    access.setProject(builtProject);
    final Map<String, OutputConfiguration> outputConfigurations = getOutputConfigurations(context);
    refreshOutputFolders(context, outputConfigurations, subMonitor.newChild(1));
    access.setOutputConfigurations(outputConfigurations);
    if (context.getBuildType() == BuildType.CLEAN || context.getBuildType() == BuildType.RECOVERY) {
        SubMonitor cleanMonitor = SubMonitor.convert(subMonitor.newChild(1), outputConfigurations.size());
        for (OutputConfiguration config : outputConfigurations.values()) {
            cleanOutput(context, config, cleanMonitor.newChild(1));
        }
        if (context.getBuildType() == BuildType.CLEAN)
            return;
    }
    Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = getGeneratorMarkers(builtProject, outputConfigurations.values());
    for (int i = 0; i < numberOfDeltas; i++) {
        final IResourceDescription.Delta delta = deltas.get(i);
        // monitor handling
        if (subMonitor.isCanceled())
            throw new OperationCanceledException();
        subMonitor.subTask("Compiling " + delta.getUri().lastSegment() + " (" + i + " of " + numberOfDeltas + ")");
        access.setMonitor(subMonitor.newChild(1));
        final String uri = delta.getUri().toString();
        final Set<IFile> derivedResources = newLinkedHashSet();
        for (OutputConfiguration config : outputConfigurations.values()) {
            if (config.isCleanUpDerivedResources()) {
                Iterable<IMarker> markers = generatorMarkers.get(config);
                for (IMarker marker : markers) {
                    String source = derivedResourceMarkers.getSource(marker);
                    if (source != null && source.equals(uri))
                        derivedResources.add((IFile) marker.getResource());
                }
            }
        }
        access.setPostProcessor(new ApplauseEclipseResourceFileSystemAccess2.IFileCallback() {

            public boolean beforeFileDeletion(IFile file) {
                derivedResources.remove(file);
                context.needRebuild();
                return true;
            }

            public void afterFileUpdate(IFile file) {
                handleFileAccess(file);
            }

            public void afterFileCreation(IFile file) {
                handleFileAccess(file);
            }

            protected void handleFileAccess(IFile file) {
                try {
                    derivedResources.remove(file);
                    derivedResourceMarkers.installMarker(file, uri);
                    context.needRebuild();
                } catch (CoreException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        if (delta.getNew() != null) {
            try {
                handleChangedContents(delta, context, access);
            } catch (OperationCanceledException e) {
                throw e;
            } catch (Exception e) {
                logger.error("Error during compilation of '" + delta.getUri() + "'.", e);
            }
        }
        access.flushSourceTraces();
        SubMonitor deleteMonitor = SubMonitor.convert(subMonitor.newChild(1), derivedResources.size());
        for (IFile iFile : newLinkedHashSet(derivedResources)) {
            IMarker marker = derivedResourceMarkers.findDerivedResourceMarker(iFile, uri);
            if (marker != null)
                marker.delete();
            if (derivedResourceMarkers.findDerivedResourceMarkers(iFile).length == 0) {
                access.deleteFile(iFile, deleteMonitor);
                context.needRebuild();
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) IMarker(org.eclipse.core.resources.IMarker)

Example 19 with OutputConfiguration

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

the class ApplauseBuilderParticipant method refreshOutputFolders.

protected void refreshOutputFolders(IBuildContext ctx, Map<String, OutputConfiguration> outputConfigurations, IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, outputConfigurations.size());
    for (OutputConfiguration config : outputConfigurations.values()) {
        SubMonitor child = subMonitor.newChild(1);
        final IProject project = ctx.getBuiltProject();
        IContainer container = getContainer(project, config.getOutputDirectory());
        container.refreshLocal(IResource.DEPTH_INFINITE, child);
    }
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) SubMonitor(org.eclipse.core.runtime.SubMonitor) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject)

Example 20 with OutputConfiguration

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

the class ApplauseEclipseResourceFileSystemAccess2 method generateFile.

/**
	 * @since 2.4
	 */
public void generateFile(String fileName, String outputName, InputStream content) {
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    OutputConfiguration outputConfig = getOutputConfig(outputName);
    if (!ensureOutputConfigurationDirectoryExists(outputConfig))
        return;
    try {
        IFile file = getFile(fileName, outputName);
        if (file.exists()) {
            if (outputConfig.isOverrideExistingResources()) {
                if (hasContentsChanged(file, content)) {
                    // reset to offset zero allows to reuse internal byte[]
                    // no need to convert the string twice
                    content.reset();
                    file.setContents(content, true, true, monitor);
                } else {
                    file.touch(getMonitor());
                }
                if (file.isDerived() != outputConfig.isSetDerivedProperty())
                    setDerived(file, outputConfig.isSetDerivedProperty());
                if (callBack != null)
                    callBack.afterFileUpdate(file);
            }
        } else {
            ensureParentExists(file);
            file.create(content, true, monitor);
            if (outputConfig.isSetDerivedProperty()) {
                setDerived(file, true);
            }
            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) 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)

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