org.eclipse.xtext.generator.IFileSystemAccessExtension3 Java Examples

The following examples show how to use org.eclipse.xtext.generator.IFileSystemAccessExtension3. 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: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Stores the process resource as a binary if it doesn't contain syntax or linking errors.
 *
 * @param resource
 *          resource to store, must not be {@code null}
 * @param buildData
 *          build data, must not be {@code null}
 */
protected void storeBinaryResource(final Resource resource, final BuildData buildData) {
  if (isBinaryModelStorageAvailable && resource instanceof StorageAwareResource && ((StorageAwareResource) resource).getResourceStorageFacade() != null
      && fileSystemAccess instanceof IFileSystemAccessExtension3) {
    CompletableFuture.runAsync(() -> {
      final long maxTaskExecutionNanos = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);

      try {
        long elapsed = System.nanoTime();

        IResourceStorageFacade storageFacade = ((StorageAwareResource) resource).getResourceStorageFacade();
        storageFacade.saveResource((StorageAwareResource) resource, (IFileSystemAccessExtension3) fileSystemAccess);
        buildData.getSourceLevelURICache().getSources().remove(resource.getURI());

        elapsed = System.nanoTime() - elapsed;
        if (elapsed > maxTaskExecutionNanos) {
          LOGGER.info("saving binary taking longer than expected (" + elapsed + " ns) : " + resource.getURI()); //$NON-NLS-1$ //$NON-NLS-2$
        }
        // CHECKSTYLE:OFF
      } catch (Throwable ex) {
        // CHECKSTYLE:ON
        LOGGER.error("Failed to save binary for " + resource.getURI(), ex); //$NON-NLS-1$
      }
    }, binaryStorageExecutor);
  }
}
 
Example #2
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.8
 */
protected void saveResourceStorage(Resource resource, IFileSystemAccess access) {
	if (resource instanceof StorageAwareResource && access instanceof IFileSystemAccessExtension3) {
		IResourceStorageFacade storageFacade = ((StorageAwareResource) resource).getResourceStorageFacade();
		if (storageFacade != null) {
			storageFacade.saveResource((StorageAwareResource)resource, (IFileSystemAccessExtension3)access);
		}
	}
}
 
Example #3
Source File: ResourceStorageFacade.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void saveResource(StorageAwareResource resource, IFileSystemAccessExtension3 fsa) {
	MyByteArrayOutputStream bout = new MyByteArrayOutputStream();
	try {
		createResourceStorageWritable(bout).writeResource(resource);
	} catch (IOException e) {
		// something went wrong when writing the resource - stream's content is bogus and not written to disk
		LOG.warn("Cannot write storage for " + resource.getURI(), e);
		return;
	}
	fsa.generateFile(computeOutputPath(resource), new ByteArrayInputStream(bout.toByteArray(), 0, bout.length()));
}
 
Example #4
Source File: DirectLinkingResourceStorageFacade.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * If the resource contains errors, any existing storage will be deleted.
 */
@Override
public void saveResource(final StorageAwareResource resource, final IFileSystemAccessExtension3 fsa) {
  // delete storage first in case saving fails
  deleteStorage(resource.getURI(), (IFileSystemAccess) fsa);
  if (resource.getErrors().isEmpty()) {
    super.saveResource(resource, fsa);
  }
}
 
Example #5
Source File: IResourceStorageFacade.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Saves the resource using the given file system access.
 */
void saveResource(StorageAwareResource resource, IFileSystemAccessExtension3 fsa);