org.eclipse.xtext.generator.OutputConfiguration.SourceMapping Java Examples

The following examples show how to use org.eclipse.xtext.generator.OutputConfiguration.SourceMapping. 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: XtextProjectConfigurator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void configureOutlet(IEclipsePreferences languagePreferences, OutputConfiguration mavenConfiguration, ProjectConfigurationRequest request) {
	org.eclipse.xtext.generator.OutputConfiguration configuration = mavenConfiguration.toGeneratorConfiguration();
	languagePreferences.put(getKey(configuration, OUTPUT_NAME), configuration.getName());
	languagePreferences.put(getKey(configuration, OUTPUT_DESCRIPTION), configuration.getDescription());
	languagePreferences.put(getKey(configuration, OUTPUT_DIRECTORY), makeProjectRelative(configuration.getOutputDirectory(), request));
	languagePreferences.putBoolean(getKey(configuration, OUTPUT_DERIVED), configuration.isSetDerivedProperty());
	languagePreferences.putBoolean(getKey(configuration, OUTPUT_CREATE_DIRECTORY), configuration.isCreateOutputDirectory());
	languagePreferences.putBoolean(getKey(configuration, OUTPUT_CLEAN_DIRECTORY), configuration.isCanClearOutputDirectory());
	languagePreferences.putBoolean(getKey(configuration, OUTPUT_OVERRIDE), configuration.isOverrideExistingResources());
	languagePreferences.putBoolean(getKey(configuration, OUTPUT_CLEANUP_DERIVED), configuration.isCleanUpDerivedResources());
	languagePreferences.putBoolean(getKey(configuration, INSTALL_DSL_AS_PRIMARY_SOURCE), configuration.isInstallDslAsPrimarySource());
	languagePreferences.putBoolean(getKey(configuration, HIDE_LOCAL_SYNTHETIC_VARIABLES), configuration.isHideSyntheticLocalVariables());
	languagePreferences.putBoolean(getKey(configuration, OUTPUT_KEEP_LOCAL_HISTORY), configuration.isKeepLocalHistory());
	languagePreferences.putBoolean(getKey(configuration, USE_OUTPUT_PER_SOURCE_FOLDER), configuration.isUseOutputPerSourceFolder());
	for (SourceMapping sourceMapping : configuration.getSourceMappings()) {
		languagePreferences.put(getOutputForSourceFolderKey(configuration, makeProjectRelative(sourceMapping.getSourceFolder(), request)),
				makeProjectRelative(Strings.nullToEmpty(sourceMapping.getOutputDirectory()), request));
		languagePreferences.putBoolean(getIgnoreSourceFolderKey(configuration, makeProjectRelative(sourceMapping.getSourceFolder(), request)),
				sourceMapping.isIgnore());
	}
}
 
Example #2
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.7
 */
protected String getCurrentSourceFolder(IBuildContext context, Delta delta) {
	Iterable<org.eclipse.xtext.util.Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(delta.getUri());
	for (org.eclipse.xtext.util.Pair<IStorage, IProject> pair : storages) {
		if (pair.getFirst() instanceof IResource) {
			final IResource resource = (IResource) pair.getFirst();
			IProject project = pair.getSecond();
			for (OutputConfiguration output : getOutputConfigurations(context).values()) {
				for (SourceMapping sourceMapping : output.getSourceMappings()) {
					IContainer folder = ResourceUtil.getContainer(project, sourceMapping.getSourceFolder());
					if (folder.contains(resource)) {
						return sourceMapping.getSourceFolder();
					}
				}
			}
		}
	}
	return null;
}
 
Example #3
Source File: BuilderPreferenceAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void initializeOutputPreferences(IPreferenceStore store, OutputConfiguration configuration) {
	store.setDefault(getKey(configuration, OUTPUT_NAME), configuration.getName());
	store.setDefault(getKey(configuration, OUTPUT_DESCRIPTION), configuration.getDescription());
	store.setDefault(getKey(configuration, OUTPUT_DERIVED), configuration.isSetDerivedProperty());
	store.setDefault(getKey(configuration, OUTPUT_DIRECTORY), configuration.getOutputDirectory());
	store.setDefault(getKey(configuration, OUTPUT_CREATE_DIRECTORY), configuration.isCreateOutputDirectory());
	store.setDefault(getKey(configuration, OUTPUT_CLEAN_DIRECTORY), configuration.isCanClearOutputDirectory());
	store.setDefault(getKey(configuration, OUTPUT_OVERRIDE), configuration.isOverrideExistingResources());
	store.setDefault(getKey(configuration, OUTPUT_CLEANUP_DERIVED), configuration.isCleanUpDerivedResources());
	store.setDefault(getKey(configuration, INSTALL_DSL_AS_PRIMARY_SOURCE), configuration.isInstallDslAsPrimarySource());
	store.setDefault(getKey(configuration, HIDE_LOCAL_SYNTHETIC_VARIABLES), configuration.isHideSyntheticLocalVariables());
	store.setDefault(getKey(configuration, OUTPUT_KEEP_LOCAL_HISTORY), configuration.isKeepLocalHistory());
	
	for (SourceMapping sourceMapping : configuration.getSourceMappings()) {
		store.setDefault(getOutputForSourceFolderKey(configuration, sourceMapping.getSourceFolder()), Strings.nullToEmpty(sourceMapping.getOutputDirectory()));
		store.setDefault(getIgnoreSourceFolderKey(configuration, sourceMapping.getSourceFolder()), sourceMapping.isIgnore());
	}
}
 
Example #4
Source File: LanguageAccess.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: StandaloneBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: StandaloneBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: ProjectAwareUniqueClassNameValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected boolean isDerived(IResource resource) {
	try {
		// Nullcheck for test org.eclipse.xtext.xbase.ui.tests.validation.ProjectAwareUniqueClassNameValidatorTest
		if (derivedResourceMarkers != null && derivedResourceMarkers.findDerivedResourceMarkers(resource).length >= 1) {
			return true;
		}
	} catch (CoreException e) {
		LOG.error(e.getMessage(), e);
		return false;
	}

	Collection<OutputConfiguration> outputConfigurations = (Collection<OutputConfiguration>) getContext()
			.get(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS);
	if (outputConfigurations != null) {
		IPath projectRelativePath = resource.getProjectRelativePath();
		for (OutputConfiguration outputConfiguration : outputConfigurations) {
			for (String dir : outputConfiguration.getOutputDirectories()) {
				for (SourceMapping sourceMapping : outputConfiguration.getSourceMappings()) {
					// Check if there is a sourceFolder that ends with the path of the current output dir
					if (sourceMapping.getSourceFolder().endsWith(dir)) {
						String sourceFolder = sourceMapping.getSourceFolder();
						// Check if there is a sourceMapping that matches the current output dir and is a prefix of the projectRelativePath
						if (new Path(sourceFolder).isPrefixOf(projectRelativePath)) {
							return true;
						}
					}
				}

				// In case no sourceMapping matches
				if (new Path(dir).isPrefixOf(projectRelativePath)) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #8
Source File: EclipseOutputConfigurationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.6
 */
protected OutputConfiguration createAndOverlayOutputConfiguration(IProject project, IPreferenceStore store, OutputConfiguration output) {
	OutputConfiguration result = createAndOverlayOutputConfiguration(store, output);
	if (project != null && sourceFolderProvider != null) {
		for (IContainer sourceContainer : sourceFolderProvider.getSourceFolders(project)) {
			String sourceFolder = toProjectRelativePath(sourceContainer).toString();
			SourceMapping mapping = new SourceMapping(sourceFolder);
			mapping.setOutputDirectory(getOutputForSourceFolder(store, output, sourceFolder));
			mapping.setIgnore(isIgnoreSourceFolder(store, output, sourceFolder));
			result.getSourceMappings().add(mapping);
		}
	}
	return result;
}
 
Example #9
Source File: XtendProjectConfigurator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void writePreferences(OutputConfiguration configuration,
		IProject project) {
	ProjectScope projectPreferences = new ProjectScope(project);
	IEclipsePreferences languagePreferences = projectPreferences
			.getNode("org.eclipse.xtend.core.Xtend");
	languagePreferences.putBoolean(
			OptionsConfigurationBlock.isProjectSpecificPropertyKey(BuilderConfigurationBlock.PROPERTY_PREFIX), true);
	languagePreferences.putBoolean(
			getKey(configuration, INSTALL_DSL_AS_PRIMARY_SOURCE),
			configuration.isInstallDslAsPrimarySource());
	languagePreferences.putBoolean(
			getKey(configuration, HIDE_LOCAL_SYNTHETIC_VARIABLES),
			configuration.isHideSyntheticLocalVariables());
	languagePreferences.putBoolean(
			getKey(configuration, USE_OUTPUT_PER_SOURCE_FOLDER),
			true);
	for (SourceMapping sourceMapping : configuration.getSourceMappings()) {
		languagePreferences.put(
				getOutputForSourceFolderKey(configuration,
						sourceMapping.getSourceFolder()),
				Strings.nullToEmpty(sourceMapping.getOutputDirectory()));
	}

	try {
		languagePreferences.flush();
	} catch (BackingStoreException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example #10
Source File: XtendProjectConfigurator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void readCompileConfig(OutputConfiguration config, ProjectConfigurationRequest request,
		MojoExecution execution, SubMonitor progress) throws CoreException {
	List<String> roots = request.getMavenProject().getCompileSourceRoots();
	progress = SubMonitor.convert(progress, roots.size());
	for (String source : roots) {
		SourceMapping mapping = new SourceMapping(makeProjectRelative(source, request));
		String outputDirectory = mojoParameterValue("outputDirectory", String.class, request, execution, progress);
		mapping.setOutputDirectory(makeProjectRelative(outputDirectory, request));
		config.getSourceMappings().add(mapping);
	}
}
 
Example #11
Source File: XtendProjectConfigurator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void readTestCompileConfig(OutputConfiguration config, ProjectConfigurationRequest request,
		MojoExecution execution, SubMonitor progress) throws CoreException {
	List<String> roots = request.getMavenProject().getTestCompileSourceRoots();
	progress = SubMonitor.convert(progress, roots.size());
	for (String source : roots) {
		SourceMapping mapping = new SourceMapping(makeProjectRelative(source, request));
		String testOutputDirectory = mojoParameterValue("testOutputDirectory", String.class, request, execution, progress);
		mapping.setOutputDirectory(makeProjectRelative(testOutputDirectory, request));
		config.getSourceMappings().add(mapping);
	}
}