Search in sources :

Example 6 with IN4JSEclipseProject

use of org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject in project n4js by eclipse.

the class N4JSToBeBuiltComputer method updateStorage.

@Override
public boolean updateStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
    if (storage instanceof IFile) {
        IFile file = (IFile) storage;
        String extension = file.getFileExtension();
        // changed archive - schedule contents
        if (IN4JSArchive.NFAR_FILE_EXTENSION.equals(extension)) {
            IProject project = file.getProject();
            String key = project.getName() + "|" + storage.getFullPath().toPortableString();
            Set<URI> cachedURIs = knownEntries.remove(key);
            if (cachedURIs != null) {
                toBeBuilt.getToBeDeleted().addAll(cachedURIs);
            }
            cachedURIs = Sets.newHashSet();
            storageMapper.collectNfarURIs((IFile) storage, cachedURIs);
            knownEntries.put(key, cachedURIs);
            toBeBuilt.getToBeUpdated().addAll(cachedURIs);
            return true;
        } else if (IN4JSProject.N4MF_MANIFEST.equals(file.getName())) {
            // changed manifest - schedule all resources from source folders
            final IN4JSEclipseProject project = eclipseCore.create(file.getProject()).orNull();
            if (null != project && project.exists()) {
                List<? extends IN4JSEclipseSourceContainer> sourceContainers = project.getSourceContainers();
                Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
                for (IN4JSEclipseSourceContainer sourceContainer : sourceContainers) {
                    for (URI uri : sourceContainer) {
                        if (uriValidator.canBuild(uri, new URIBasedStorage(uri))) {
                            toBeUpdated.add(uri);
                        }
                    }
                }
            }
            IProject resourceProject = file.getProject();
            String projectName = resourceProject.getName();
            Set<URI> toBeDeleted = toBeBuilt.getToBeDeleted();
            for (final IResourceDescription description : builderState.getAllResourceDescriptions()) {
                URI uri = description.getURI();
                if (uri.isPlatformResource()) {
                    if (projectName.equals(uri.segment(1))) {
                        toBeDeleted.add(uri);
                    }
                }
            }
            // still return false because we want to do the normal processing for the manifest file, too
            return false;
        }
    }
    return false;
}
Also used : IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) IFile(org.eclipse.core.resources.IFile) Set(java.util.Set) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URIBasedStorage(org.eclipse.n4js.ts.ui.navigation.URIBasedStorage) IN4JSEclipseSourceContainer(org.eclipse.n4js.ui.projectModel.IN4JSEclipseSourceContainer) List(java.util.List) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Example 7 with IN4JSEclipseProject

use of org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject in project n4js by eclipse.

the class ProjectDescriptionLoadListener method onDescriptionLoaded.

void onDescriptionLoaded(URI location) {
    if (location.isPlatformResource() && location.segmentCount() == 2) {
        IN4JSEclipseProject n4project = eclipseCore.create(location);
        IProject eclipseProject = n4project.getProject();
        updateProjectReferencesIfNecessary(eclipseProject);
    }
}
Also used : IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) IProject(org.eclipse.core.resources.IProject)

Example 8 with IN4JSEclipseProject

use of org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject in project n4js by eclipse.

the class N4JSEclipseModel method findN4JSSourceContainer.

@Override
public Optional<? extends IN4JSSourceContainer> findN4JSSourceContainer(URI location) {
    Optional<? extends IN4JSSourceContainer> n4jsContainer = Optional.absent();
    if (!location.isArchive()) {
        if (N4Scheme.isN4Scheme(location)) {
            return n4jsContainer;
        }
        if (!location.isPlatformResource()) {
            // just do not throw exception then, but continue with null:
            if ("revision".equals(location.scheme())) {
                if (LOGGER.isDebugEnabled()) {
                    final String message = "Got revision-scheme request, but refuse to find source-container for that:" + location;
                    LOGGER.debug(message);
                }
                return n4jsContainer;
            }
            if (location.isFile()) {
                final IN4JSEclipseProject eclipseProject = findProjectWith(location);
                if (null != eclipseProject && eclipseProject.exists()) {
                    if (eclipseProject.getProject() instanceof ExternalProject) {
                        final IResource resource = externalLibraryWorkspace.getResource(location);
                        if (null != resource) {
                            n4jsContainer = getN4JSSourceContainer(resource);
                        }
                    }
                }
            }
            return n4jsContainer;
        }
        final IN4JSEclipseProject project = findProjectWith(location);
        if (null != project && project.exists()) {
            final Path path = new Path(location.toPlatformString(true));
            final IResource resource;
            if (1 == path.segmentCount()) {
                resource = workspace.getProject(path.segment(0));
            } else {
                resource = workspace.getFile(path);
            }
            n4jsContainer = getN4JSSourceContainer(resource);
        }
    } else {
        String archiveFilePath = location.authority();
        URI archiveURI = URI.createURI(archiveFilePath.substring(0, archiveFilePath.length() - 1));
        N4JSEclipseProject containingProject = findProjectWith(archiveURI);
        N4JSEclipseArchive archive = getN4JSArchive(containingProject, workspace.getFile(new Path(archiveURI.toPlatformString(true))));
        n4jsContainer = findN4JSSourceContainerInArchive(location, archive);
    }
    return n4jsContainer;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IN4JSEclipseArchive(org.eclipse.n4js.ui.projectModel.IN4JSEclipseArchive) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Example 9 with IN4JSEclipseProject

use of org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject in project n4js by eclipse.

the class NpmExportWizard method init.

@Override
public void init(IWorkbench targetWorkbench, IStructuredSelection currentSelection) {
    // this.selection = currentSelection;
    List<?> selectedResources = IDE.computeSelectedResources(currentSelection);
    List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
    // Find all selected projects
    Set<IProject> projects = selectedResources.stream().filter(m -> m instanceof IResource).map(m -> ((IResource) m).getProject()).filter(// only open projects
    p -> p.isOpen()).collect(Collectors.toSet());
    // make the behavior predictable by ordering:
    TreeSet<IProject> sortedProjects = Sets.<IProject>newTreeSet((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
    sortedProjects.addAll(projects);
    // 0) turn into IN4JSProject and give and process further.
    // a) find out which projects fulfill the npm-"exportable"-contract
    // b) give back a list to the user what to export,
    // c) disable things not fullfilling the contract.
    // d) take choosing from the list and pass to exporter in non-ui package.
    // 0)
    List<IN4JSEclipseProject> rawN4jsProjects = Lists.newArrayList();
    iP2in4jsP = HashBiMap.create();
    for (IProject iProject : workspaceProjects) {
        IN4JSEclipseProject mappedIn4jsProject = map2In4js(iProject);
        if (mappedIn4jsProject != null) {
            rawN4jsProjects.add(mappedIn4jsProject);
            iP2in4jsP.put(iProject, mappedIn4jsProject);
        }
    }
    // filter out Non-N4JS-projects from initial selection.
    sortedProjects.retainAll(iP2in4jsP.keySet());
    // filter out all non-N4JS-projects from the workspace projects.
    ArrayList<IProject> filteredWorkspaceProjects = new ArrayList<>(workspaceProjects);
    filteredWorkspaceProjects.retainAll(iP2in4jsP.keySet());
    setWindowTitle("N4JS to npm Export");
    setNeedsProgressMonitor(true);
    Map<IProject, Boolean> selectedProjects = new HashMap<>();
    // Add all workspace projects to list, default selection value is false
    filteredWorkspaceProjects.forEach(project -> selectedProjects.put(project, false));
    // Override selection value for all initially selected projects
    sortedProjects.forEach(project -> selectedProjects.put(project, true));
    // exportPage = new ExportSelectionPage("Export Page", rawN4jsProjects, labelProvider);
    exportPage = new ExportSelectionPage("Export Page", selectedProjects);
    if (runTools())
        toolRunnerPage = new NpmToolRunnerPage("npm Execution Page");
    comparePage = new PackageJsonComparePage("Compare package.json Page");
    pageListener = new IPageChangedListener() {

        @Override
        public void pageChanged(PageChangedEvent event) {
            if (event.getSelectedPage() == comparePage) {
                udpatePackagJasonComparison();
            }
        }
    };
}
Also used : Arrays(java.util.Arrays) WorkbenchPlugin(org.eclipse.ui.internal.WorkbenchPlugin) IN4JSEclipseCore(org.eclipse.n4js.ui.projectModel.IN4JSEclipseCore) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) N4JSActivator(org.eclipse.n4js.ui.internal.N4JSActivator) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) Map(java.util.Map) Diagnostician(org.eclipse.n4js.npmexporter.validation.Diagnostician) BiMap(com.google.common.collect.BiMap) ArchiveException(org.apache.commons.compress.archivers.ArchiveException) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) Wizard(org.eclipse.jface.wizard.Wizard) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Sets(com.google.common.collect.Sets) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) WizardDialog(org.eclipse.jface.wizard.WizardDialog) NpmExporter(org.eclipse.n4js.npmexporter.NpmExporter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) Joiner(com.google.common.base.Joiner) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) MergeResult(org.eclipse.n4js.npmexporter.NpmExporter.MergeResult) URI(org.eclipse.emf.common.util.URI) IWizardPage(org.eclipse.jface.wizard.IWizardPage) ERROR(org.eclipse.core.runtime.IStatus.ERROR) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) IProject(org.eclipse.core.resources.IProject) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) IExportWizard(org.eclipse.ui.IExportWizard) ExecutorService(java.util.concurrent.ExecutorService) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) IResourceSetProvider(org.eclipse.xtext.ui.resource.IResourceSetProvider) CompressorException(org.apache.commons.compress.compressors.CompressorException) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) File(java.io.File) HashBiMap(com.google.common.collect.HashBiMap) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IWorkbench(org.eclipse.ui.IWorkbench) BufferedReader(java.io.BufferedReader) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) HashMap(java.util.HashMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) IProject(org.eclipse.core.resources.IProject) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) IResource(org.eclipse.core.resources.IResource)

Example 10 with IN4JSEclipseProject

use of org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject in project n4js by eclipse.

the class NpmExportWizard method map2In4js.

/**
 * @param iProject
 *            project from selection
 * @return
 */
private IN4JSEclipseProject map2In4js(IProject iProject) {
    URI projectURI = URI.createPlatformResourceURI(iProject.getName(), true);
    IN4JSEclipseProject project = n4JSCore.findProject(projectURI).orNull();
    // Additionally check for existence to only obtain visible N4JS workspace projects.
    if (project.exists()) {
        return project;
    } else {
        return null;
    }
}
Also used : IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) URI(org.eclipse.emf.common.util.URI)

Aggregations

IN4JSEclipseProject (org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject)10 URI (org.eclipse.emf.common.util.URI)7 IProject (org.eclipse.core.resources.IProject)5 List (java.util.List)3 Set (java.util.Set)2 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 IN4JSEclipseArchive (org.eclipse.n4js.ui.projectModel.IN4JSEclipseArchive)2 Joiner (com.google.common.base.Joiner)1 Optional (com.google.common.base.Optional)1 BiMap (com.google.common.collect.BiMap)1 FluentIterable.from (com.google.common.collect.FluentIterable.from)1 HashBiMap (com.google.common.collect.HashBiMap)1 Lists (com.google.common.collect.Lists)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1