/** * Setting the compile output-configurations to contain path-locations relative to the user.dir: Wrapper function * written against Xtext 2.7.1. * * In Eclipse-compile mode there are "projects" and the FSA is configured relative to these projects. In this * filebasedWorkspace here there is no "project"-concept for the generator. So the paths of the FSA need to be * reconfigured to contain the navigation to the IN4JSProject-root. * * @param project * project to be compiled */ private void configureFSA(IN4JSProject project) { Map<String, OutputConfiguration> outputConfigToBeWrapped = getInitialOutputConfigurations(); File currentDirectory = new File("."); File projectLocation = new File(project.getLocation().toFileString()); // If project is not in a sub directory of the current directory an absolute path is computed. final java.net.URI projectURI = currentDirectory.toURI().relativize(projectLocation.toURI()); final String projectPath = projectURI.getPath(); if (projectPath.length() == 0) { // same directory, skip return; } // set different output configuration. fsa.setOutputConfigurations(transformedOutputConfiguration(projectPath, outputConfigToBeWrapped)); }
private void cleanOutput(IProject aProject, OutputConfiguration config, IProgressMonitor monitor) throws CoreException { IContainer container = getContainer(aProject, config.getOutputDirectory()); if (!container.exists()) { return; } if (config.isCanClearOutputDirectory()) { for (IResource resource : container.members()) { resource.delete(IResource.KEEP_HISTORY, monitor); } } else if (config.isCleanUpDerivedResources()) { List<IFile> resources = derivedResourceMarkers.findDerivedResources(container, null); for (IFile iFile : resources) { iFile.delete(IResource.KEEP_HISTORY, monitor); } } }
@Override protected Map<OutputConfiguration, Iterable<IMarker>> getGeneratorMarkers(IProject builtProject, Collection<OutputConfiguration> outputConfigurations) throws CoreException { if (builtProject instanceof ExternalProject) { return emptyMap(); } Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = newHashMap(); for (OutputConfiguration config : outputConfigurations) { if (config.isCleanUpDerivedResources()) { List<IMarker> markers = Lists.newArrayList(); for (IContainer container : getOutputs(builtProject, config)) { Iterables.addAll( markers, getDerivedResourceMarkers().findDerivedResourceMarkers(container, getGeneratorIdProvider().getGeneratorIdentifier())); } generatorMarkers.put(config, markers); } } return generatorMarkers; }
private static CompilerDescriptor createDescriptor() { final CompilerDescriptor result = new CompilerDescriptor(); result.setIdentifier(COMPILER_ID); result.setName("N4JS to ECMAScript transpiler"); result.setDescription( "Transpiles N4JS to ECMAScript, currently ES5 plus some selected ES6 features supported by V8."); result.setActive(true); result.setCompiledFileExtension("js"); result.setCompiledFileSourceMapExtension("map"); final OutputConfiguration outCfg = new OutputConfiguration(COMPILER_ID); outCfg.setDescription("N4JS to ECMAScript transpiler"); outCfg.setOutputDirectory(calculateOutputDirectory("src-gen", COMPILER_ID)); outCfg.setOverrideExistingResources(true); outCfg.setCreateOutputDirectory(true); outCfg.setCleanUpDerivedResources(true); outCfg.setSetDerivedProperty(true); outCfg.setKeepLocalHistory(true); outCfg.setCanClearOutputDirectory(true); result.setOutputConfiguration(outCfg); return result; }
protected IFileSystemAccess2 getFileSystemAccess(final IProject project, final IProgressMonitor monitor) { EclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get(); access.setContext(project); access.setMonitor(monitor); OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); defaultOutput.setDescription("Output Folder"); defaultOutput.setOutputDirectory("./"); defaultOutput.setOverrideExistingResources(true); defaultOutput.setCreateOutputDirectory(true); defaultOutput.setCleanUpDerivedResources(false); defaultOutput.setSetDerivedProperty(false); defaultOutput.setKeepLocalHistory(false); HashMap<String, OutputConfiguration> outputConfigurations = new HashMap<String, OutputConfiguration>(); outputConfigurations.put(IFileSystemAccess.DEFAULT_OUTPUT, defaultOutput); access.setOutputConfigurations(outputConfigurations); return access; }
private ISCTFileSystemAccess getFileSystemAccess(GeneratorEntry entry) { final ISCTFileSystemAccess fileSystemAccess = this.factory.create(entry); final FeatureConfiguration featureConfiguration = entry .getFeatureConfiguration(IArduinoFeatureConstants.FEATURE_NAME); if (featureConfiguration != null) { final String userSrcFolder = featureConfiguration .getParameterValue(IArduinoFeatureConstants.PARAM_USER_SRC_FOLDER).getStringValue(); fileSystemAccess.setOutputPath(IArduinoFeatureConstants.PARAM_USER_SRC_FOLDER, userSrcFolder); final OutputConfiguration outputConfiguration = fileSystemAccess.getOutputConfigurations() .get(IArduinoFeatureConstants.PARAM_USER_SRC_FOLDER); outputConfiguration.setCreateOutputDirectory(true); outputConfiguration.setOverrideExistingResources(false); outputConfiguration.setSetDerivedProperty(false); } return fileSystemAccess; }
@Before public void before() { try { final Path tmpPath = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value()); StringConcatenation _builder = new StringConcatenation(); _builder.append("tempFolder_"); UUID _randomUUID = UUID.randomUUID(); _builder.append(_randomUUID); final Path output = Files.createTempDirectory(tmpPath, _builder.toString()); final Path resource = Files.createFile(output.resolve(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME)); resource.toFile().deleteOnExit(); output.toFile().deleteOnExit(); final OutputConfiguration config = IterableExtensions.<OutputConfiguration>head(this.configProvider.getOutputConfigurations()); config.setOutputDirectory(output.toString()); Pair<String, OutputConfiguration> _mappedTo = Pair.<String, OutputConfiguration>of(IFileSystemAccess.DEFAULT_OUTPUT, config); this.fsa.setOutputConfigurations(Collections.<String, OutputConfiguration>unmodifiableMap(CollectionLiterals.<String, OutputConfiguration>newHashMap(_mappedTo))); this.fsa.setConverter(this.uriConverter); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void outputConfigurations() { Set<OutputConfiguration> configs = new Antlr4OutputConfigurationProvider() .getOutputConfigurations(); assertNotNull(configs); assertEquals(1, configs.size()); OutputConfiguration config = configs.iterator().next(); assertNotNull(config); assertEquals("Options", config.getDescription()); assertEquals("DEFAULT_OUTPUT", config.getName()); assertEquals("./target/generated-sources/antlr4", config.getOutputDirectory()); assertEquals(false, config.isCanClearOutputDirectory()); assertEquals(true, config.isCreateOutputDirectory()); assertEquals(true, config.isHideSyntheticLocalVariables()); assertEquals(false, config.isInstallDslAsPrimarySource()); assertEquals(true, config.isKeepLocalHistory()); assertEquals(true, config.isOverrideExistingResources()); assertEquals(true, config.isSetDerivedProperty()); }
public WrappedOutputConfiguration(OutputConfiguration delegate, String pathprefix) { super(delegate.getName()); this.delegate = delegate; this.pathprefix = normalize(pathprefix); // Wrapp all sourcemappings: sourceMappings = Sets.<WrappedSourceMapping> newHashSet(); for (SourceMapping sm : delegate.getSourceMappings()) { sourceMappings.add(new WrappedSourceMapping(sm, this)); } }
/** Build an output configuration from a composite generator. */ private Map<String, OutputConfiguration> getInitialOutputConfigurations() { if (initialOutputConfiguration == null) { initialOutputConfiguration = new HashMap<>(); for (CompilerDescriptor desc : compositeGenerator.getCompilerDescriptors()) { initialOutputConfiguration.put(desc.getIdentifier(), desc.getOutputConfiguration()); } } return initialOutputConfiguration; // return result; }
/** * Wraps the output-configurations with a delegate that transparently injects the relative path to the project-root. * * @param projectPath * relative path to the project-root * @return wrapped configurations. */ private Map<String, OutputConfiguration> transformedOutputConfiguration(String projectPath, Map<String, OutputConfiguration> outputConfigToBeWrapped) { Map<String, OutputConfiguration> result = new HashMap<>(); for (Entry<String, OutputConfiguration> pair : outputConfigToBeWrapped.entrySet()) { final OutputConfiguration input = pair.getValue(); OutputConfiguration transOC = new WrappedOutputConfiguration(input, projectPath); result.put(pair.getKey(), transOC); } return result; }
/** * Create a build instruction for the given project. */ public BuildInstruction(IProject project, Map<String, OutputConfiguration> outputConfigurations, IDerivedResourceMarkers derivedResourceMarkers, EclipseResourceFileSystemAccess2 access, Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers, IStorage2UriMapper storage2UriMapper, ICompositeGenerator compositeGenerator, Injector injector) { super(project, outputConfigurations, derivedResourceMarkers); this.access = access; this.generatorMarkers = generatorMarkers; this.storage2UriMapper = storage2UriMapper; this.compositeGenerator = compositeGenerator; this.injector = injector; }
private void deleteEmptyDirectories(IProgressMonitor progressMonitor) throws CoreException { for (OutputConfiguration config : outputConfigurations.values()) { IFolder folder = project.getFolder(config.getOutputDirectory()); if (null != folder && folder.exists()) { deleteEmptyDirectories(folder, progressMonitor); folder.getParent().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor); } } }
private void recordDerivedResources(final String uri) { for (OutputConfiguration config : outputConfigurations.values()) { if (config.isCleanUpDerivedResources()) { Iterable<IMarker> markers = generatorMarkers.get(config); if (null != markers) { for (IMarker marker : markers) { String source = derivedResourceMarkers.getSource(marker); if (source != null && source.equals(uri)) { derivedResources.add((IFile) marker.getResource()); } } } } } }
/** * Creates a new clean operation for the given project. */ public CleanInstruction(IProject project, Map<String, OutputConfiguration> outputConfigurations, IDerivedResourceMarkers derivedResourceMarkers) { super(project, outputConfigurations, derivedResourceMarkers); this.project = project; this.outputConfigurations = outputConfigurations; this.derivedResourceMarkers = derivedResourceMarkers; }
@Override public void finish(List<Delta> deltas, IProgressMonitor progressMonitor) throws CoreException { SubMonitor cleanMonitor = SubMonitor.convert(progressMonitor, outputConfigurations.size()); for (OutputConfiguration config : outputConfigurations.values()) { cleanOutput(project, config, cleanMonitor.newChild(1)); } }
/** * Intentionally package visible producer for the {@link IBuildParticipantInstruction}. * * @param project * the currently build project * @param buildType * the current build type * @return a StatefulBuilderParticipant. Never <code>null</code>. */ IBuildParticipantInstruction prepareBuild(IProject project, IXtextBuilderParticipant.BuildType buildType) throws CoreException { if (!isEnabled(project)) { return IBuildParticipantInstruction.NOOP; } EclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get(); access.setProject(project); final Map<String, OutputConfiguration> outputConfigurations = getOutputConfigurations(project); refreshOutputFolders(project, outputConfigurations, null); access.setOutputConfigurations(outputConfigurations); if (buildType == BuildType.CLEAN || buildType == BuildType.RECOVERY) { IBuildParticipantInstruction clean = new CleanInstruction(project, outputConfigurations, getDerivedResourceMarkers()); if (buildType == BuildType.RECOVERY) { clean.finish(Collections.<Delta> emptyList(), null); } else { return clean; } } Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = getGeneratorMarkers(project, outputConfigurations.values()); BuildInstruction buildInstruction = new BuildInstruction(project, outputConfigurations, getDerivedResourceMarkers(), access, generatorMarkers, storage2UriMapper, compositeGenerator, injector); return buildInstruction; }
/** * @see #refreshOutputFolders(org.eclipse.xtext.builder.IXtextBuilderParticipant.IBuildContext, Map, * IProgressMonitor) */ protected void refreshOutputFolders(IProject project, 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); IContainer container = getContainer(project, config.getOutputDirectory()); if (null != container) { container.refreshLocal(IResource.DEPTH_INFINITE, child); } } }
/** * @see #getOutputConfigurations(org.eclipse.xtext.builder.IXtextBuilderParticipant.IBuildContext) */ protected Map<String, OutputConfiguration> getOutputConfigurations(IProject project) { Set<OutputConfiguration> configurations = getOutputConfigurationProvider().getOutputConfigurations(project); return uniqueIndex(getNonNullOutputConfigurations(configurations), new Function<OutputConfiguration, String>() { @Override public String apply(OutputConfiguration from) { return from.getName(); } }); }
private/* @Nonnull */ Iterable<OutputConfiguration> getNonNullOutputConfigurations(Set<OutputConfiguration> configurations) { if (configurations == null) { return new HashSet<>(); } else { return configurations; } }
@Override protected List<String> getAllFolders() { Set<OutputConfiguration> outputConfigurations = outputConfigurationProvider.getOutputConfigurations(); String outputFolder = "src-gen"; for (OutputConfiguration outputConfiguration : outputConfigurations) { if (IFileSystemAccess.DEFAULT_OUTPUT.equals(outputConfiguration.getName())) { outputFolder = outputConfiguration.getOutputDirectory(); break; } } return ImmutableList.of(getModelFolderName(), outputFolder); }
private void configureFileSystemAccess(final File baseDir, AbstractFileSystemAccess2 fsa) { Set<OutputConfiguration> confsForFsa = Sets.newHashSet(); Set<OutputConfiguration> pomOutputConfigs = getConfiguredOutputConfigs(); if (pomOutputConfigs != null && !pomOutputConfigs.isEmpty()) { for (OutputConfiguration pomConfig : pomOutputConfigs) { if (getOutputConfigurationProvider().getOutputConfigurations().contains(pomConfig)) { confsForFsa.add(pomConfig); } else { LOG.warn("Output '" + pomConfig.getName() + "' is not configured in OutputConfigurationProvider. Used provider " + getOutputConfigurationProvider().getClass().getName()); } } } confsForFsa.addAll(getOutputConfigurationProvider().getOutputConfigurations()); Map<String, OutputConfiguration> asMap = IterableExtensions.toMap( Iterables.transform(confsForFsa, new Function<OutputConfiguration, OutputConfiguration>() { @Override public OutputConfiguration apply(OutputConfiguration output) { output.setOutputDirectory(resolveToBaseDir(output.getOutputDirectory(), baseDir)); for (SourceMapping sourceMapping : output.getSourceMappings()) { sourceMapping.setOutputDirectory(resolveToBaseDir(sourceMapping.getOutputDirectory(), baseDir)); } return output; } }), new Function1<OutputConfiguration, String>() { @Override public String apply(final OutputConfiguration it) { return it.getName(); } }); fsa.setOutputConfigurations(asMap); }
@Override public Set<OutputConfiguration> getOutputConfigurations() { OutputConfiguration config = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); config.setOutputDirectory("src-gen"); if (useOutputPerSource) { SourceMapping sourceMapping = new OutputConfiguration.SourceMapping("src2"); sourceMapping.setOutputDirectory("src2-gen"); config.getSourceMappings().add(sourceMapping); config.setUseOutputPerSourceFolder(true); } return ImmutableSet.of(config); }
protected AbstractFileSystemAccess2 getFileSystemAccess(final StorageAwareResource resource) { final AbstractFileSystemAccess2 fsa = this.fileSystemAccessProvider.get(); fsa.setContext(resource); final Function1<OutputConfiguration, String> _function = (OutputConfiguration it) -> { return it.getName(); }; fsa.setOutputConfigurations(IterableExtensions.<String, OutputConfiguration>toMap(this.outputConfigurationProvider.getOutputConfigurations(resource), _function)); return fsa; }
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); }
@Override public Set<OutputConfiguration> getOutputConfigurations() { Set<OutputConfiguration> configurations = super.getOutputConfigurations(); configurations.add(getFormatterConfig()); configurations.add(getAbstractFormatterConfig()); return configurations; }
/** * Creates output configuration for a Formatter. * * @return output configuration */ private OutputConfiguration getFormatterConfig() { OutputConfiguration config = new OutputConfiguration(FormatConstants.FORMATTER); config.setDescription("Output configuration for a formatter"); config.setOverrideExistingResources(false); config.setCanClearOutputDirectory(false); config.setCleanUpDerivedResources(false); config.setOutputDirectory("src"); return config; }
/** * Creates output configuration for a AbstractFormatter. * * @return output configuration */ private OutputConfiguration getAbstractFormatterConfig() { OutputConfiguration config = new OutputConfiguration(FormatConstants.ABSTRACT_FORMATTER); config.setDescription("Output configuration for a abstract formatter"); config.setOverrideExistingResources(true); config.setOutputDirectory("src-gen"); return config; }
@Override public Set<OutputConfiguration> getOutputConfigurations() { Set<OutputConfiguration> configurations = super.getOutputConfigurations(); configurations.add(getStubConfig()); configurations.add(getDefaultConfig()); return configurations; }
/** * Creates output configuration for generated stubs. * * @return output configuration */ private OutputConfiguration getStubConfig() { OutputConfiguration config = new OutputConfiguration(STUB_OUTPUT); config.setDescription("Output configuration for stubs"); config.setOverrideExistingResources(false); config.setCanClearOutputDirectory(false); config.setCleanUpDerivedResources(false); config.setOutputDirectory("src"); return config; }
/** * Creates output configuration for regular generated files. * * @return output configuration */ private OutputConfiguration getDefaultConfig() { OutputConfiguration config = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); config.setDescription("Output configuration for generated classes"); config.setOverrideExistingResources(true); config.setOutputDirectory("src-gen"); return config; }
@Override public Set<OutputConfiguration> getOutputConfigurations() { Set<OutputConfiguration> configurations = super.getOutputConfigurations(); configurations.add(getCheckDocumentationConfig()); configurations.add(getServiceRegistryConfig()); return configurations; }
/** * Gets the check documentation output configuration. * * @return the check documentation configuration */ private OutputConfiguration getCheckDocumentationConfig() { OutputConfiguration config = new OutputConfiguration(CheckGeneratorConstants.CHECK_DOC_OUTPUT); config.setDescription("Output configuration for check documentation use"); config.setOutputDirectory(DOCS_PATH); config.setCreateOutputDirectory(true); config.setCanClearOutputDirectory(true); return config; }
/** * Gets the service registry output configuration. * * @return the service registry configuration */ private OutputConfiguration getServiceRegistryConfig() { OutputConfiguration config = new OutputConfiguration(CheckGeneratorConstants.CHECK_REGISTRY_OUTPUT); config.setDescription("Output configuration for service registry use"); config.setOutputDirectory("META-INF/services"); config.setOverrideExistingResources(true); config.setCreateOutputDirectory(true); config.setCleanUpDerivedResources(false); config.setSetDerivedProperty(true); return config; }
/** * @return a set of {@link OutputConfiguration} available for the generator */ public Set<OutputConfiguration> getOutputConfigurations() { OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); defaultOutput.setDescription("Output Folder"); defaultOutput.setOutputDirectory("./src-gen"); defaultOutput.setOverrideExistingResources(true); defaultOutput.setCreateOutputDirectory(true); defaultOutput.setCleanUpDerivedResources(true); defaultOutput.setSetDerivedProperty(true); return newHashSet(defaultOutput); }
protected void initLibraryTargetFolder(ISCTFileSystemAccess access, GeneratorEntry entry) { FeatureParameterValue libraryTargetFolderValue = helper.getLibraryTargetFolderValue(entry); if (libraryTargetFolderValue != null) { access.setOutputPath(LIBRARY_TARGET_FOLDER_OUTPUT, libraryTargetFolderValue.getStringValue()); OutputConfiguration output = access.getOutputConfigurations().get(LIBRARY_TARGET_FOLDER_OUTPUT); output.setCreateOutputDirectory(true); output.setCanClearOutputDirectory(false); output.setOverrideExistingResources(false); } }
protected void initApiTargetFolder(ISCTFileSystemAccess access, GeneratorEntry entry) { FeatureParameterValue apiTargetFolderValue = helper.getApiTargetFolderValue(entry); if (apiTargetFolderValue != null) { access.setOutputPath(API_TARGET_FOLDER_OUTPUT, apiTargetFolderValue.getStringValue()); OutputConfiguration output = access.getOutputConfigurations().get(API_TARGET_FOLDER_OUTPUT); output.setCreateOutputDirectory(true); } }
@Override public URI getURI(String path, String outputConfiguration) { OutputConfiguration outputConfig = getOutputConfig(outputConfiguration); String outputDir = outputConfig.getOutputDirectory(); if (isRootPath(outputDir) && isRootPath(path)) { return URI.createFileURI(getProject().getLocationURI().getPath()); } IFile file = getProject().getFile(outputDir + File.separator + path); if (file != null) { return URI.createFileURI(file.getLocationURI().getPath()); } return super.getURI(path); }
public Set<OutputConfiguration> getOutputConfigurations() { OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT); defaultOutput.setDescription("Output Folder"); defaultOutput.setOutputDirectory("./application-gen"); defaultOutput.setOverrideExistingResources(true); defaultOutput.setCreateOutputDirectory(true); defaultOutput.setCleanUpDerivedResources(true); defaultOutput.setSetDerivedProperty(true); defaultOutput.setKeepLocalHistory(true); return newHashSet(defaultOutput); }
@Override public Set<OutputConfiguration> getOutputConfigurations() { Set<OutputConfiguration> outputconfigurations = super .getOutputConfigurations(); OutputConfiguration outputConfiguration = outputconfigurations .iterator().next(); outputConfiguration.setOutputDirectory(XSEMANTICS_GEN); return outputconfigurations; }