Search in sources :

Example 31 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class ModelUtilsTest method getModuleFromExternalModulePath.

@Test
public void getModuleFromExternalModulePath() throws Exception {
    File externalFile = null;
    IErlProject project = null;
    try {
        // given
        // an erlang project and an external file not in any project
        project = ErlideTestUtils.createErlProject("testproject");
        final String externalFileName = "external4.erl";
        externalFile = ErlideTestUtils.createTmpFile(externalFileName, "-module(external4).\nf([_ | _]=L ->\n    atom_to_list(L).\n");
        final String absolutePath = externalFile.getAbsolutePath();
        final String externalsFileName = "x.erlidex";
        final File externalsFile = ErlideTestUtils.createTmpFile(externalsFileName, absolutePath);
        ((ErlProject) project).setExternalModulesFile(externalsFile.getAbsolutePath());
        project.open(null);
        // when
        // looking for it with its external module path
        final IErlModel model = ErlangEngine.getInstance().getModel();
        final IErlModule module = modelFindService.findModule(model, null, null, absolutePath, IErlElementLocator.Scope.ALL_PROJECTS);
        assertNotNull(module);
        final String externalModulePath = ErlangEngine.getInstance().getModelUtilService().getExternalModulePath(model, module);
        System.out.println(" >> %s" + externalModulePath);
        final IErlModule module2 = modelUtilService.getModuleFromExternalModulePath(model, externalModulePath);
        // then
        // we should find it
        assertNotNull(module2);
        assertEquals(externalFileName, module.getName());
        assertEquals(module, module2);
    } finally {
        if (externalFile != null && externalFile.exists()) {
            externalFile.delete();
        }
        if (project != null) {
            ErlideTestUtils.deleteProject(project);
        }
    }
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModel(org.erlide.engine.model.root.IErlModel) ErlProject(org.erlide.engine.internal.model.root.ErlProject) IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) File(java.io.File) Test(org.junit.Test)

Example 32 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class IParentTest method getChildWithResource.

// IErlElement getChildWithResource(IResource rsrc);
@Test
public void getChildWithResource() throws Exception {
    final IProject workspaceProject = project.getWorkspaceProject();
    final IErlModel model = ErlangEngine.getInstance().getModel();
    final IErlElement childWithResource = model.getChildWithResource(workspaceProject);
    final IResource resource = module.getResource();
    final IErlElement childWithResource2 = model.getChildWithResource(resource);
    final IErlFolder folder = (IErlFolder) project.getChildNamed("src");
    final IErlElement childWithResource3 = folder.getChildWithResource(resource);
    assertEquals(project, childWithResource);
    assertNull(childWithResource2);
    assertEquals(module, childWithResource3);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlModel(org.erlide.engine.model.root.IErlModel) IErlFolder(org.erlide.engine.model.root.IErlFolder) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Example 33 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class InternalBuilder method handleErlangFiles.

private void handleErlangFiles(final IErlProject erlProject, @NonNull final IProject project, final BuildKind kind, final IResourceDelta resourceDelta, final BuildNotifier notifier) throws CoreException, BackendException {
    final OtpErlangList compilerOptions = CompilerOptions.get(project);
    final Set<BuildResource> resourcesToBuild = getResourcesToBuild(kind, project, resourceDelta, notifier);
    final int n = resourcesToBuild.size();
    if (n == 0) {
        return;
    }
    if (erlProject == null) {
        return;
    }
    // if (BuilderHelper.isDebugging()) {
    ErlLogger.debug("Will compile %d resource(s)", n);
    // }
    final IBackend backend = BackendCore.getBackendManager().getBuildBackend(erlProject);
    if (backend == null) {
        final String message = "No backend with the required " + "version could be found. Can't build.";
        MarkerUtils.createProblemMarker(project, null, message, 0, IMarker.SEVERITY_ERROR);
        throw new BackendException(message);
    }
    final IErlModel model = ErlangEngine.getInstance().getModel();
    backend.addProjectPath(model.findProject(project));
    notifier.setProgressPerCompilationUnit(1.0f / n);
    final Map<RpcFuture, IResource> results = new HashMap<>();
    for (final BuildResource bres : resourcesToBuild) {
        notifier.checkCancel();
        final IResource resource = bres.getResource();
        MarkerUtils.deleteMarkers(resource);
        notifier.aboutToCompile(resource);
        if ("erl".equals(resource.getFileExtension())) {
            final String outputDir = erlProject.getProperties().getOutputDir().toString();
            final RpcFuture f = helper.startCompileErl(project, bres, outputDir, backend.getOtpRpc(), compilerOptions, kind == BuildKind.FULL);
            if (f != null) {
                results.put(f, resource);
            }
        } else if ("yrl".equals(resource.getFileExtension())) {
            final RpcFuture f = helper.startCompileYrl(project, resource, backend.getOtpRpc(), compilerOptions);
            if (f != null) {
                results.put(f, resource);
            }
        } else {
            ErlLogger.warn("Don't know how to compile: %s", resource.getName());
        }
    }
    final List<Entry<RpcFuture, IResource>> done = Lists.newArrayList();
    final List<Entry<RpcFuture, IResource>> waiting = Lists.newArrayList(results.entrySet());
    // TODO should use some kind of notification!
    while (!waiting.isEmpty()) {
        for (final Entry<RpcFuture, IResource> result : waiting) {
            notifier.checkCancel();
            OtpErlangObject r;
            try {
                r = result.getKey().get(100, TimeUnit.MILLISECONDS);
            } catch (final Exception e) {
                r = null;
            }
            if (r != null) {
                final IResource resource = result.getValue();
                helper.completeCompile(project, resource, r, backend.getOtpRpc(), compilerOptions);
                notifier.compiled(resource);
                done.add(result);
            }
        }
        waiting.removeAll(done);
        done.clear();
    }
    helper.refreshOutputDir(project);
    try {
        helper.checkForClashes(backend.getOtpRpc(), project);
    } catch (final Exception e) {
    }
    backend.removeProjectPath(model.findProject(project));
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BackendException(org.erlide.backend.api.BackendException) BackendException(org.erlide.backend.api.BackendException) Entry(java.util.Map.Entry) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IBackend(org.erlide.backend.api.IBackend) RpcFuture(org.erlide.runtime.rpc.RpcFuture) IResource(org.eclipse.core.resources.IResource)

Example 34 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class BackendManager method addExecutionBackend.

@Override
public synchronized void addExecutionBackend(final IProject project, final IBackend b) {
    final Set<IBackend> list = executionBackends.computeIfAbsent(project, k -> Sets.newHashSet());
    list.add(b);
    final IErlModel model = ErlangEngine.getInstance().getModel();
    b.addProjectPath(model.findProject(project));
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) IBackend(org.erlide.backend.api.IBackend)

Example 35 with IErlModel

use of org.erlide.engine.model.root.IErlModel in project erlide_eclipse by erlang.

the class BackendManager method removeExecutionBackend.

@Override
public synchronized void removeExecutionBackend(final IProject project, final IProjectCodeLoader b) {
    final IErlModel model = ErlangEngine.getInstance().getModel();
    b.removeProjectPath(model.findProject(project));
    final Set<IBackend> list = executionBackends.computeIfAbsent(project, k -> Sets.newHashSet());
    list.remove(b);
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) IBackend(org.erlide.backend.api.IBackend)

Aggregations

IErlModel (org.erlide.engine.model.root.IErlModel)36 IErlModule (org.erlide.engine.model.root.IErlModule)18 IErlProject (org.erlide.engine.model.root.IErlProject)13 IFile (org.eclipse.core.resources.IFile)11 ErlModelException (org.erlide.engine.model.ErlModelException)11 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)8 IErlElement (org.erlide.engine.model.IErlElement)8 IResource (org.eclipse.core.resources.IResource)7 IPath (org.eclipse.core.runtime.IPath)5 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IBackend (org.erlide.backend.api.IBackend)3 OpenResult (org.erlide.engine.services.search.OpenResult)3 File (java.io.File)2 IOException (java.io.IOException)2 IContainer (org.eclipse.core.resources.IContainer)2