Search in sources :

Example 16 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class ProjectCompareHelper method compareModules.

/**
 * Specific Comparison between two modules.
 *
 * @param apiProject
 *            API project
 * @param api
 *            module containing the definition
 * @param implProject
 *            API-impl project
 * @param impl
 *            implementation to
 * @param includePolyfills
 *            {@code true} if polyfills should be considered as the part of the API and the implementation.
 *            Otherwise {@code false}.
 * @return data containing the comparison (implementation is in slot 0)
 */
public ProjectComparisonEntry compareModules(N4JSProjectConfigSnapshot apiProject, TModule api, N4JSProjectConfigSnapshot implProject, TModule impl, final boolean includePolyfills) {
    String implId = implProject.getImplementationId();
    N4JSPackageName implIdAsName = implId != null ? new N4JSPackageName(implId) : null;
    ProjectComparison projectComparison = new ProjectComparison(new N4JSPackageName[] { implIdAsName });
    ProjectComparisonEntry dummyParent = new ProjectComparisonEntry(projectComparison, apiProject, implProject);
    ProjectComparisonEntry ret = createEntries(dummyParent, -1, api, new EObject[] { impl }, includePolyfills);
    return ret;
}
Also used : N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName)

Example 17 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class ApiImplMapping method put.

/**
 * Add a single API -> implementation association to the receiving mapping (if it is not present already).
 */
public void put(N4JSProjectConfigSnapshot api, N4JSProjectConfigSnapshot impl) {
    final N4JSPackageName apiId = api.getN4JSPackageName();
    if (apiId == null)
        // just ignore (complaining about this problem is not our business)
        return;
    final String implIdStr = impl.getImplementationId();
    final N4JSPackageName implId = implIdStr != null ? new N4JSPackageName(implIdStr) : null;
    if (implId == null) {
        projectsWithUndefImplIds.add(impl);
        return;
    }
    ApiImplMapping.ApiImplAssociation assoc = assocs.get(apiId);
    if (assoc == null) {
        assoc = new ApiImplAssociation(api);
        assocs.put(apiId, assoc);
    }
    final N4JSProjectConfigSnapshot replaced = assoc.putImpl(impl);
    if (replaced != null && !Objects.equals(replaced, impl)) {
        // ooops! we have several projects defining an implementation for project 'api' with the same
        // implementation id -> remember them!
        putConflict(apiId, implId, replaced, impl);
    }
}
Also used : N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)

Example 18 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class ApiImplMapping method getErrorMessages.

/**
 * In {@link #hasErrors() case of error}, returns human-readable error messages. Otherwise, an empty list will be
 * returned.
 */
public List<String> getErrorMessages() {
    final List<String> msgs = new ArrayList<>();
    for (N4JSProjectConfigSnapshot p : projectsWithUndefImplIds) {
        msgs.add("project '" + p.getName() + "' does not define an ImplementationId in its manifest");
    }
    for (Map.Entry<Pair<N4JSPackageName, N4JSPackageName>, Set<N4JSProjectConfigSnapshot>> currConflict : conflicts.entrySet()) {
        final N4JSPackageName apiId = currConflict.getKey().getKey();
        final N4JSPackageName implId = currConflict.getKey().getValue();
        final Set<N4JSProjectConfigSnapshot> culprits = currConflict.getValue();
        final String culpritsStr = " - " + culprits.stream().map(c -> c.getName()).collect(Collectors.joining("\n - "));
        msgs.add("several projects define an implementation for API project '" + apiId + "' with implementation ID '" + implId + "':\n" + culpritsStr);
    }
    return msgs;
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 19 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class N4jsLibsAccess method installN4jsLibs.

/**
 * Installs one or more N4JS libraries (i.e. the npm packages located under "n4js-libs/packages" in the N4JS Git
 * repository on the local file system) by copying or symbolically linking them from their location in the local
 * N4JS Git repository clone.
 * <p>
 * This method should be preferred over an installation from the remote npm registry to use the current version of
 * the N4JS libraries of the currently running build. For tests that do not require execution of N4JS code (just
 * compilation), method {@code ProjectTestsUtils#createDummyN4JSRuntime(Path)} might be a simpler alternative.
 *
 * @param targetPath
 *            where to install.
 * @param includeDependencies
 *            whether the transitive dependencies of the installed N4JS libraries should be installed, too. This may
 *            include both other N4JS libraries or third-party dependencies that reside under folder
 *            "n4js-libs/node_modules" and will be installed by MWE2 workflow BuildN4jsLibs in the early stages of
 *            the N4JS build.
 * @param useSymbolicLinks
 *            whether symbolic links should be used instead of copying the files.<br>
 *            WARNING: if your tests changes the installed packages, this will affect a global location that will
 *            influence other tests!
 * @param deleteOnExit
 *            whether the copied files / created symbolic links should be removed when the JVM shuts down.
 * @param n4jsLibsNames
 *            One or more package names of N4JS libraries that are to be installed.
 * @return actually installed packages (including dependencies, if requested) as a map from package name to absolute
 *         path.
 * @throws IOException
 *             in case of trouble.
 */
public static Map<N4JSPackageName, Path> installN4jsLibs(Path targetPath, boolean includeDependencies, boolean useSymbolicLinks, boolean deleteOnExit, N4JSPackageName... n4jsLibsNames) throws IOException {
    Path n4jsLibsLocation = findN4jsLibsLocation();
    Map<N4JSPackageName, Path> toBeInstalled = new HashMap<>();
    for (N4JSPackageName projectName : n4jsLibsNames) {
        Path projectPath = findN4jsLib(n4jsLibsLocation, projectName, false);
        toBeInstalled.put(projectName, projectPath);
    }
    return installN4jsLibs(targetPath, includeDependencies, useSymbolicLinks, deleteOnExit, toBeInstalled);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName)

Example 20 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class N4jsLibsAccess method installN4jsLibs.

private static Map<N4JSPackageName, Path> installN4jsLibs(Path targetPath, boolean includeDependencies, boolean useSymbolicLinks, boolean deleteOnExit, Map<N4JSPackageName, Path> n4jsLibsToBeInstalled) throws IOException {
    Map<N4JSPackageName, Path> toBeInstalled = new LinkedHashMap<>();
    // add projects in 'projectNames' to 'toBeInstalled'
    toBeInstalled.putAll(n4jsLibsToBeInstalled);
    // add dependencies of projects in 'toBeInstalled' to 'toBeInstalled' (if requested)
    if (includeDependencies) {
        Path n4jsLibsLocation = N4jsLibsAccess.findN4jsLibsLocation();
        for (Path projectPath : new ArrayList<>(toBeInstalled.values())) {
            // will be modified in next line!
            collectDependencies(n4jsLibsLocation, projectPath, toBeInstalled);
        }
    }
    // actually install projects in 'toBeInstalled'
    for (Entry<N4JSPackageName, Path> projectEntry : toBeInstalled.entrySet()) {
        N4JSPackageName projectName = projectEntry.getKey();
        Path projectPath = projectEntry.getValue();
        Path targetProjectPath = toProjectPath(targetPath, projectName);
        if (useSymbolicLinks) {
            // i.e. create parent of targetProjectPath
            Files.createDirectories(targetPath);
            Path symLinkPath = Files.createSymbolicLink(targetProjectPath, projectPath);
            if (deleteOnExit) {
                symLinkPath.toFile().deleteOnExit();
            }
        } else {
            Files.createDirectories(targetProjectPath);
            FileCopier.copy(projectPath, targetProjectPath);
            if (deleteOnExit) {
                FileDeleter.deleteOnExit(targetProjectPath);
            }
        }
    }
    return toBeInstalled;
}
Also used : Path(java.nio.file.Path) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)23 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)9 Path (java.nio.file.Path)8 File (java.io.File)5 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Set (java.util.Set)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)3 Optional (com.google.common.base.Optional)2 FluentIterable (com.google.common.collect.FluentIterable)2 Multimap (com.google.common.collect.Multimap)2 Sets (com.google.common.collect.Sets)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 FileTime (java.nio.file.attribute.FileTime)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2