Search in sources :

Example 1 with ProjectDescription

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());
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) DeclaredVersion(org.eclipse.n4js.n4mf.DeclaredVersion) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) IProjectDescription(org.eclipse.core.resources.IProjectDescription) SourceFragment(org.eclipse.n4js.n4mf.SourceFragment)

Example 2 with ProjectDescription

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);
}
Also used : URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) Test(org.junit.Test)

Example 3 with ProjectDescription

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());
}
Also used : ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) Test(org.junit.Test)

Example 4 with ProjectDescription

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;
}
Also used : IOException(java.io.IOException) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) IOException(java.io.IOException)

Example 5 with 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();
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) SimpleProjectDescription(org.eclipse.n4js.n4mf.SimpleProjectDescription) TestedProject(org.eclipse.n4js.n4mf.TestedProject)

Aggregations

ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)37 URI (org.eclipse.emf.common.util.URI)19 SimpleProjectDescription (org.eclipse.n4js.n4mf.SimpleProjectDescription)11 Test (org.junit.Test)9 ImmutableList (com.google.common.collect.ImmutableList)7 File (java.io.File)6 EObject (org.eclipse.emf.ecore.EObject)6 ProjectDependency (org.eclipse.n4js.n4mf.ProjectDependency)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 SourceFragment (org.eclipse.n4js.n4mf.SourceFragment)5 N4JSExternalProject (org.eclipse.n4js.external.N4JSExternalProject)4 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)4 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 ExtendedRuntimeEnvironment (org.eclipse.n4js.n4mf.ExtendedRuntimeEnvironment)3 ProjectReference (org.eclipse.n4js.n4mf.ProjectReference)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 Optional (com.google.common.base.Optional)2 IResource (org.eclipse.core.resources.IResource)2