use of org.eclipse.n4js.n4mf.SourceFragment in project n4js by eclipse.
the class ProjectTestsUtils method createManifestN4MFFile.
/**
* @param manifestAdjustments
* before saving the manifest this procedure will be called to allow adjustments to the manifest's
* properties (the ProjectDescription object passed to the procedure will already contain all default
* values). May be <code>null</code> if no adjustments are required.
*/
public static void createManifestN4MFFile(IProject project, String sourceFolder, String outputFolder, Consumer<ProjectDescription> manifestAdjustments) throws CoreException {
IFile config = project.getFile("manifest.n4mf");
URI uri = URI.createPlatformResourceURI(config.getFullPath().toString(), true);
ProjectDescription projectDesc = N4mfFactory.eINSTANCE.createProjectDescription();
projectDesc.setProjectDependencies(N4mfFactory.eINSTANCE.createProjectDependencies());
projectDesc.setDeclaredVendorId("org.eclipse.n4js");
projectDesc.setVendorName("Eclipse N4JS Project");
projectDesc.setProjectId(project.getName());
projectDesc.setProjectType(ProjectType.LIBRARY);
DeclaredVersion projectVersion = N4mfFactory.eINSTANCE.createDeclaredVersion();
projectVersion.setMajor(0);
projectVersion.setMinor(0);
projectVersion.setMicro(1);
projectDesc.setProjectVersion(projectVersion);
projectDesc.setOutputPath(outputFolder);
SourceFragment sourceProjectPath = N4mfFactory.eINSTANCE.createSourceFragment();
sourceProjectPath.setSourceFragmentType(SourceFragmentType.SOURCE);
sourceProjectPath.getPaths().add(sourceFolder);
projectDesc.getSourceFragment().add(sourceProjectPath);
if (manifestAdjustments != null)
manifestAdjustments.accept(projectDesc);
ResourceSet rs = createResourceSet(project);
Resource res = rs.createResource(uri);
res.getContents().add(projectDesc);
// Workaround to avoid any unnecessary warnings due to empty project dependency block
if (projectDesc.getAllProjectDependencies().isEmpty()) {
projectDesc.setProjectDependencies(null);
}
try {
res.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
project.refreshLocal(IResource.DEPTH_INFINITE, monitor());
waitForAutoBuild();
Assert.assertTrue("manifest.n4mf should have been created", config.exists());
}
use of org.eclipse.n4js.n4mf.SourceFragment in project n4js by eclipse.
the class N4JSModel method getN4JSSourceContainers.
public ImmutableList<? extends IN4JSSourceContainer> getN4JSSourceContainers(N4JSProject project) {
ImmutableList.Builder<IN4JSSourceContainer> result = ImmutableList.builder();
URI location = project.getLocation();
ProjectDescription description = getProjectDescription(location);
if (description != null) {
List<SourceFragment> sourceFragments = newArrayList(from(description.getSourceFragment()));
sourceFragments.sort((f1, fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT) -> f1.compareByFragmentType(fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT));
for (SourceFragment sourceFragment : sourceFragments) {
List<String> paths = sourceFragment.getPaths();
for (String path : paths) {
// XXX poor man's canonical path conversion. Consider headless compiler with npm projects.
final String relativeLocation = ".".equals(path) ? "" : path;
IN4JSSourceContainer sourceContainer = this.createProjectN4JSSourceContainer(project, sourceFragment.getSourceFragmentType(), relativeLocation);
result.add(sourceContainer);
}
}
}
return result.build();
}
use of org.eclipse.n4js.n4mf.SourceFragment in project n4js by eclipse.
the class N4JSModel method getSourceContainers.
public ImmutableList<IN4JSSourceContainer> getSourceContainers(N4JSArchive archive) {
ImmutableList.Builder<IN4JSSourceContainer> result = ImmutableList.builder();
URI location = archive.getLocation();
ProjectDescription description = getProjectDescription(location);
if (description != null) {
List<SourceFragment> sourceFragments = newArrayList(from(description.getSourceFragment()));
sourceFragments.sort((f1, fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT) -> f1.compareByFragmentType(fDIRECT_RESOURCE_IN_PROJECT_SEGMENTCOUNT));
for (SourceFragment sourceFragment : sourceFragments) {
List<String> paths = sourceFragment.getPaths();
for (String path : paths) {
result.add(createArchiveN4JSSourceContainer(archive, sourceFragment.getSourceFragmentType(), path));
}
}
}
return result.build();
}
use of org.eclipse.n4js.n4mf.SourceFragment in project n4js by eclipse.
the class N4JSEclipseModel method getN4JSSourceContainers.
@Override
public ImmutableList<? extends IN4JSEclipseSourceContainer> getN4JSSourceContainers(N4JSProject project) {
ImmutableList.Builder<IN4JSEclipseSourceContainer> result = ImmutableList.builder();
URI location = project.getLocation();
ProjectDescription description = getProjectDescription(location);
if (description != null) {
List<SourceFragment> sourceFragments = newArrayList(from(description.getSourceFragment()));
sourceFragments.sort((f1, f2) -> f1.compareByFragmentType(f2));
for (SourceFragment sourceFragment : sourceFragments) {
List<String> paths = sourceFragment.getPaths();
for (String p : paths) {
IN4JSEclipseSourceContainer sourceContainer = createProjectN4JSSourceContainer(project, sourceFragment.getSourceFragmentType(), p);
result.add(sourceContainer);
}
}
}
return result.build();
}
use of org.eclipse.n4js.n4mf.SourceFragment in project n4js by eclipse.
the class N4MFSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == N4mfPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case N4mfPackage.BOOTSTRAP_MODULE:
sequence_BootstrapModule(context, (BootstrapModule) semanticObject);
return;
case N4mfPackage.DECLARED_VERSION:
sequence_DeclaredVersion(context, (DeclaredVersion) semanticObject);
return;
case N4mfPackage.EXEC_MODULE:
sequence_ExecModule(context, (ExecModule) semanticObject);
return;
case N4mfPackage.EXTENDED_RUNTIME_ENVIRONMENT:
sequence_ExtendedRuntimeEnvironment(context, (ExtendedRuntimeEnvironment) semanticObject);
return;
case N4mfPackage.IMPLEMENTED_PROJECTS:
sequence_ImplementedProjects(context, (ImplementedProjects) semanticObject);
return;
case N4mfPackage.INIT_MODULES:
sequence_InitModules(context, (InitModules) semanticObject);
return;
case N4mfPackage.MODULE_FILTER:
sequence_ModuleFilter(context, (ModuleFilter) semanticObject);
return;
case N4mfPackage.MODULE_FILTER_SPECIFIER:
sequence_ModuleFilterSpecifier(context, (ModuleFilterSpecifier) semanticObject);
return;
case N4mfPackage.PROJECT_DEPENDENCIES:
sequence_ProjectDependencies(context, (ProjectDependencies) semanticObject);
return;
case N4mfPackage.PROJECT_DEPENDENCY:
sequence_ProjectDependency(context, (ProjectDependency) semanticObject);
return;
case N4mfPackage.PROJECT_DESCRIPTION:
sequence_ProjectDescription(context, (ProjectDescription) semanticObject);
return;
case N4mfPackage.PROJECT_REFERENCE:
sequence_ProjectReference(context, (ProjectReference) semanticObject);
return;
case N4mfPackage.PROVIDED_RUNTIME_LIBRARIES:
sequence_ProvidedRuntimeLibraries(context, (ProvidedRuntimeLibraries) semanticObject);
return;
case N4mfPackage.PROVIDED_RUNTIME_LIBRARY_DEPENDENCY:
sequence_ProvidedRuntimeLibraryDependency(context, (ProvidedRuntimeLibraryDependency) semanticObject);
return;
case N4mfPackage.REQUIRED_RUNTIME_LIBRARIES:
sequence_RequiredRuntimeLibraries(context, (RequiredRuntimeLibraries) semanticObject);
return;
case N4mfPackage.REQUIRED_RUNTIME_LIBRARY_DEPENDENCY:
sequence_RequiredRuntimeLibraryDependency(context, (RequiredRuntimeLibraryDependency) semanticObject);
return;
case N4mfPackage.SIMPLE_PROJECT_DESCRIPTION:
sequence_SimpleProjectDescription(context, (SimpleProjectDescription) semanticObject);
return;
case N4mfPackage.SOURCE_FRAGMENT:
sequence_SourceFragment(context, (SourceFragment) semanticObject);
return;
case N4mfPackage.TESTED_PROJECT:
sequence_TestedProject(context, (TestedProject) semanticObject);
return;
case N4mfPackage.TESTED_PROJECTS:
sequence_TestedProjects(context, (TestedProjects) semanticObject);
return;
case N4mfPackage.VERSION_CONSTRAINT:
sequence_VersionConstraint(context, (VersionConstraint) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations