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);
}
}
}
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);
}
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));
}
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));
}
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);
}
Aggregations