Search in sources :

Example 26 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class ExternalLibraryPreferencePage method getInstalledNpms.

private Map<String, String> getInstalledNpms() {
    final URI root = installLocationProvider.getTargetPlatformNodeModulesLocation();
    final Set<ProjectDescription> projects = from(externalLibraryWorkspace.getProjectsDescriptions((root))).toSet();
    final Map<String, String> versionedNpms = new HashMap<>();
    projects.forEach((ProjectDescription pd) -> {
        versionedNpms.put(pd.getProjectId(), VersionConstraintFormatUtil.npmFormat(pd.getProjectVersion()));
    });
    return versionedNpms;
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription)

Example 27 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class NpmPackageToProjectAdapter method adjustManifest.

/**
 * Adjust manifests based on provided manifest fragments.
 *
 * @param manifest
 *            file to be adjusted
 * @param manifestFragments
 *            that will be used to adjust the manifest
 */
private IStatus adjustManifest(final File manifest, final File... manifestFragments) {
    if (Arrays2.isEmpty(manifestFragments)) {
        // Nothing to merge.
        return statusHelper.OK();
    }
    final URI manifestURI = URI.createFileURI(manifest.getAbsolutePath());
    ProjectDescription pd = null;
    for (int i = 0; i < manifestFragments.length; i++) {
        File fragment = manifestFragments[i];
        if (fragment.exists() && fragment.isFile()) {
            URI manifestFragmentURI = URI.createFileURI(fragment.getAbsolutePath());
            pd = manifestMerger.mergeContent(manifestFragmentURI, manifestURI);
            fragment.delete();
        } else {
            LOGGER.warn("Broken manifest fragment: " + fragment + ".");
        }
    }
    if (pd != null) {
        ResourceSet resourceSet = resourceSetProvider.get();
        Resource resource = resourceSet.getResource(manifestURI, true);
        List<EObject> contents = resource.getContents();
        contents.clear();
        contents.add(pd);
        try {
            resource.save(null);
            return statusHelper.OK();
        } catch (IOException e) {
            final String message = "Error while trying to write N4JS manifest content for: " + manifestURI + ".";
            LOGGER.error(message, e);
            return statusHelper.createError(message, e);
        }
    } else {
        final String message = "Failed to merge N4JS manifest fragments into '" + manifestURI + "'.";
        LOGGER.error(message);
        return statusHelper.createError(message);
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) File(java.io.File)

Example 28 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class AbstractInternalWorkspaceTest method testGetLocation_04.

@SuppressWarnings("javadoc")
@Test
public void testGetLocation_04() {
    ProjectDescription description = getWorkspace().getProjectDescription(myProjectURI);
    ProjectDependency dependencyOnArchive = description.getAllProjectDependencies().get(0);
    URI expectedToBeNull = getWorkspace().getLocation(myProjectURI, dependencyOnArchive, N4JSSourceContainerType.ARCHIVE);
    assertNull(expectedToBeNull);
}
Also used : ProjectDependency(org.eclipse.n4js.n4mf.ProjectDependency) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 29 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class AbstractInternalWorkspaceTest method testDescriptionsAreSame.

@SuppressWarnings("javadoc")
@Test
public void testDescriptionsAreSame() {
    ProjectDescription first = getWorkspace().getProjectDescription(myProjectURI);
    ProjectDescription second = getWorkspace().getProjectDescription(myProjectURI);
    assertSame(first, second);
}
Also used : ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) Test(org.junit.Test)

Example 30 with ProjectDescription

use of org.eclipse.n4js.n4mf.ProjectDescription in project n4js by eclipse.

the class AbstractInternalWorkspaceTest method testGetProjectDescription_01.

@SuppressWarnings("javadoc")
@Test
public void testGetProjectDescription_01() {
    ProjectDescription description = getWorkspace().getProjectDescription(myProjectURI);
    assertNotNull(description);
    assertEquals(myProjectId, description.getProjectId());
}
Also used : ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) Test(org.junit.Test)

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