use of org.eclipse.n4js.n4mf.ProjectDescription 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.ProjectDescription in project n4js by eclipse.
the class AbstractInternalWorkspaceTest method testGetProjectDescription_04.
@SuppressWarnings("javadoc")
@Test
public void testGetProjectDescription_04() {
final URI doesNotExist = URI.createURI(myProjectId + "doesNotExist");
final ProjectDescription description = getWorkspace().getProjectDescription(doesNotExist);
assertNull("Expecting null project description for non-existing project. Was: " + description, description);
}
use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.
the class AbstractInternalWorkspaceTest method testGetProjectDescription_02.
@SuppressWarnings("javadoc")
@Test
public void testGetProjectDescription_02() {
ProjectDescription description = getWorkspace().getProjectDescription(libProjectURI);
assertNotNull(description);
assertEquals(libProjectId, description.getProjectId());
}
use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.
the class ProjectDescriptionProviderUtil method getFromFile.
/**
* Creates new instance of {@link ProjectDescription} (or null) based on the provided manifest file.
*/
public static ProjectDescription getFromFile(File manifest) {
ProjectDescription projectDescription = null;
if (manifest == null) {
LOGGER.warn("Provided file was null.");
return projectDescription;
}
if (!manifest.isFile()) {
LOGGER.warn("Cannot find manifest file at " + manifest.getAbsolutePath());
return projectDescription;
}
String text = null;
try {
text = new String(Files.readAllBytes(manifest.toPath()));
} catch (IOException e) {
LOGGER.warn("Cannot read manifest content at " + manifest.getAbsolutePath());
return projectDescription;
}
if (Strings.isNullOrEmpty(text)) {
LOGGER.warn("No content read for manifest content at " + manifest.getAbsolutePath());
return projectDescription;
}
try {
projectDescription = ManifestValuesParsingUtil.parseProjectDescription(text).getAST();
} catch (Exception e) {
LOGGER.warn("Cannot parse manifest content at " + manifest.getAbsolutePath());
return projectDescription;
}
return projectDescription;
}
use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.
the class N4JSModel method getTestedProjects.
public Collection<IN4JSProject> getTestedProjects(final N4JSProject project) {
if (null == project || !project.exists()) {
return emptyList();
}
// Shortcut to avoid reading the project description at all.
if (!TEST.equals(project.getProjectType())) {
return emptyList();
}
final Builder<IN4JSProject> builder = ImmutableList.builder();
final URI location = project.getLocation();
final ProjectDescription description = getProjectDescription(location);
if (null != description) {
for (TestedProject testedProject : description.getAllTestedProjects()) {
if (null != testedProject.getProject()) {
URI hostLocation = workspace.getLocation(location, testedProject, PROJECT);
if (null == hostLocation) {
hostLocation = externalLibraryWorkspace.getLocation(location, testedProject, PROJECT);
}
if (hostLocation != null) {
final N4JSProject tested = getN4JSProject(hostLocation);
if (null != tested && tested.exists()) {
builder.add(tested);
}
}
}
}
}
return builder.build();
}
Aggregations