Skip to content

Commit

Permalink
#208 - Problem loading on remote nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdu committed Dec 14, 2014
1 parent 7fc7d20 commit 9baaa98
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 91 deletions.
35 changes: 28 additions & 7 deletions org.erlide.backend/src/org/erlide/backend/api/ICodeBundle.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*******************************************************************************
* Copyright (c) 2009-2013 Vlad Dumitrescu and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available
* at http://www.eclipse.org/legal/epl-v10.html
* Copyright (c) 2009-2013 Vlad Dumitrescu and others. All rights reserved. This program
* and the accompanying materials are made available under the terms of the Eclipse Public
* License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vlad Dumitrescu
* Contributors: Vlad Dumitrescu
*******************************************************************************/
package org.erlide.backend.api;

import java.net.URL;
import java.util.Collection;

import org.eclipse.xtext.xbase.lib.Pair;
Expand All @@ -25,8 +24,30 @@ public static enum CodeContext {

Bundle getBundle();

/**
* List of bundle-relative paths of ebin entries.
*
* @param context
* @return
*/
Collection<String> getEbinPaths(CodeContext context);

/**
* List of absolute paths of local directories corresponding to ebin entries.
*
* @param context
* @return
*/
Collection<String> getEbinDirs(CodeContext context);

/**
* List of URLs for all beam files within ebin entries.
*
* @param context
* @return
*/
Collection<URL> getEbinBeamURLs(CodeContext context);

Collection<Pair<String, String>> getInits();

RuntimeVersion getVersion();
Expand Down
69 changes: 43 additions & 26 deletions org.erlide.backend/src/org/erlide/backend/internal/CodeBundle.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/*******************************************************************************
* Copyright (c) 2009 Vlad Dumitrescu and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available
* at http://www.eclipse.org/legal/epl-v10.html
* Copyright (c) 2009 Vlad Dumitrescu and others. All rights reserved. This program and
* the accompanying materials are made available under the terms of the Eclipse Public
* License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vlad Dumitrescu
* Contributors: Vlad Dumitrescu
*******************************************************************************/
package org.erlide.backend.internal;

import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Enumeration;
import java.util.Set;

import org.eclipse.xtext.xbase.lib.Pair;
Expand Down Expand Up @@ -52,24 +50,11 @@ public Bundle getBundle() {

@Override
public Collection<String> getEbinDirs(final CodeContext context) {
final Set<String> result = Sets.newHashSet();
result.addAll(doGetEbinDirs(context));
if (context != CodeContext.COMMON) {
result.addAll(doGetEbinDirs(CodeContext.COMMON));
}
return result;
}

private List<String> doGetEbinDirs(final CodeContext context) {
final List<String> result = Lists.newArrayList();
for (final String path : paths.get(context)) {
final String entryName = path.replace(" ", "%20");
final URL entry = bundle.getEntry(entryName);
if (entry != null) {
final String aPath = BeamUtil.getPathFromUrl(entry);
if (aPath != null) {
result.add(aPath);
}
final Collection<String> result = Lists.newArrayList();
for (final String path : getEbinPaths(context)) {
final String aPath = bundlePathToDir(path);
if (aPath != null) {
result.add(aPath);
} else {
ErlLogger.warn("Can't access path %s, "
+ "plugin %s may be incorrectly built (%s)", path,
Expand All @@ -79,6 +64,15 @@ private List<String> doGetEbinDirs(final CodeContext context) {
return result;
}

private String bundlePathToDir(final String path) {
final String entryName = path.replace(" ", "%20");
final URL entry = bundle.getEntry(entryName);
if (entry != null) {
return BeamUtil.getPathFromUrl(entry);
}
return null;
}

@Override
public Collection<Pair<String, String>> getInits() {
return Collections.unmodifiableCollection(inits);
Expand All @@ -88,4 +82,27 @@ public Collection<Pair<String, String>> getInits() {
public RuntimeVersion getVersion() {
return version;
}

@Override
public Collection<String> getEbinPaths(final CodeContext context) {
final Set<String> result = Sets.newHashSet();
result.addAll(paths.get(context));
result.addAll(paths.get(CodeContext.COMMON));
return result;
}

@Override
public Collection<URL> getEbinBeamURLs(final CodeContext context) {
// TODO test with spaces in path too
final Collection<URL> result = Lists.newArrayList();
for (final String path : getEbinPaths(context)) {
final Enumeration<String> beams = bundle.getEntryPaths(path);
while (beams.hasMoreElements()) {
final String beam = beams.nextElement();
result.add(bundle.getEntry(beam));
}
}
return result;
}

}
44 changes: 20 additions & 24 deletions org.erlide.backend/src/org/erlide/backend/internal/CodeManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*******************************************************************************
* Copyright (c) 2009 Vlad Dumitrescu and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available
* at http://www.eclipse.org/legal/epl-v10.html
* Copyright (c) 2009 Vlad Dumitrescu and others. All rights reserved. This program and
* the accompanying materials are made available under the terms of the Eclipse Public
* License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vlad Dumitrescu
* Contributors: Vlad Dumitrescu
*******************************************************************************/
package org.erlide.backend.internal;

Expand Down Expand Up @@ -37,8 +35,7 @@ public class CodeManager {
private final RuntimeVersion version;

// only to be called by Backend
CodeManager(final IOtpRpc site, final String backendName,
final RuntimeVersion version) {
CodeManager(final IOtpRpc site, final String backendName, final RuntimeVersion version) {
this.site = site;
this.backendName = backendName;
this.version = version;
Expand Down Expand Up @@ -82,7 +79,7 @@ public void register(final CodeContext context, final ICodeBundle bundle) {
ErlangCode.addPathA(site, localDir);
} else {
ErlLogger.debug("loading %s for %s", bundle.getBundle(), backendName);
loadCodeForBundle(context, bundle);
loadCodeForBundle(context, bundle, ebinDir);
}
}
}
Expand All @@ -103,33 +100,32 @@ private boolean loadBeam(final String moduleName, final URL beamPath) {
return BeamLoader.loadBeam(site, moduleName, bin);
}

private void loadCodeForBundle(final CodeContext context, final ICodeBundle bundle) {
final Collection<String> ebinDirs = bundle.getEbinDirs(context);
if (ebinDirs == null) {
private void loadCodeForBundle(final CodeContext context, final ICodeBundle bundle,
final String ebinDir2) {
final Collection<URL> beams = bundle.getEbinBeamURLs(context);
if (beams == null) {
return;
}
for (final String ebinDir : ebinDirs) {
final String beamModuleName = BackendUtils.getBeamModuleName(ebinDir);
for (final URL beam : beams) {
final String beamModuleName = BackendUtils.getBeamModuleName(beam.getPath());
if (beamModuleName != null) {
// ErlLogger.debug(" load " + beamModuleName);
final URL entry = bundle.getBundle().getEntry(ebinDir);
final boolean ok = entry != null && loadBeam(beamModuleName, entry);
if (!ok) {
ErlLogger.debug(" load " + beamModuleName);
if (!loadBeam(beamModuleName, beam)) {
ErlLogger.error("Could not load %s", beamModuleName);
}
}
}
}

private void unloadCodeForBundle(final CodeContext context, final ICodeBundle bundle) {
final Collection<String> ebinDirs = bundle.getEbinDirs(context);
if (ebinDirs == null) {
final Collection<URL> beams = bundle.getEbinBeamURLs(context);
if (beams == null) {
return;
}
for (final String ebinDir : ebinDirs) {
final String beamModuleName = BackendUtils.getBeamModuleName(ebinDir);
for (final URL beam : beams) {
final String beamModuleName = BackendUtils.getBeamModuleName(beam.getPath());
if (beamModuleName != null) {
// ErlLogger.debug(" unload " + beamModuleName);
ErlLogger.debug(" unload " + beamModuleName);
unloadBeam(beamModuleName);
}
}
Expand Down
56 changes: 28 additions & 28 deletions org.erlide.kernel.common/src/erlide_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

load(Mod, All) ->
case code:is_sticky(Mod) of
true ->
ok;
false ->
if All ->
c:nl(Mod);
true ->
c:l(Mod)
end
true ->
ok;
false ->
if All ->
c:nl(Mod);
true ->
c:l(Mod)
end
end.

-define(SEP, ";").
Expand All @@ -48,10 +48,10 @@ reverse2(L) when is_list(L) ->

get_from_str(Text, Start) ->
case string:str(Text, Start) of
0 ->
Text;
N ->
string:substr(Text, N + length(Start))
0 ->
Text;
N ->
string:substr(Text, N + length(Start))
end.

get_between_strs(Text, Start, End) ->
Expand All @@ -60,26 +60,26 @@ get_between_strs(Text, Start, End) ->
get_all_between_strs(Text, Start, End) ->
{One, Next} = split_at(get_from_str(Text, Start), End),
case Next of
"" ->
[One];
_ ->
[One | get_all_between_strs(Next, Start, End)]
"" ->
[One];
_ ->
[One | get_all_between_strs(Next, Start, End)]
end.

get_upto_str(Text, End) ->
case string:rstr(Text, End) of
0 ->
Text;
N ->
string:substr(Text, 1, N-1)
0 ->
Text;
N ->
string:substr(Text, 1, N-1)
end.

split_at(Text, End) ->
case string:str(Text, End) of
0 ->
{Text, ""};
N ->
{string:substr(Text, 1, N-1), string:substr(Text, N+length(End))}
0 ->
{Text, ""};
N ->
{string:substr(Text, 1, N-1), string:substr(Text, N+length(End))}
end.

split_lines(<<B/binary>>) ->
Expand All @@ -92,13 +92,13 @@ split_lines([], [], Acc) ->
split_lines([], LineAcc, Acc) ->
split_lines([], [], [lists:reverse(LineAcc) | Acc]);
split_lines([$\n, $\r | Rest], LineAcc, Acc) ->
split_lines(Rest, [], [lists:reverse(LineAcc) | Acc]);
split_lines(Rest, [], [lists:reverse(LineAcc) | Acc]);
split_lines([$\n | Rest], LineAcc, Acc) ->
split_lines(Rest, [], [lists:reverse(LineAcc) | Acc]);
split_lines(Rest, [], [lists:reverse(LineAcc) | Acc]);
split_lines([$\r | Rest], LineAcc, Acc) ->
split_lines(Rest, [], [lists:reverse(LineAcc) | Acc]);
split_lines(Rest, [], [lists:reverse(LineAcc) | Acc]);
split_lines([C | Rest], LineAcc, Acc) ->
split_lines(Rest, [C | LineAcc], Acc).
split_lines(Rest, [C | LineAcc], Acc).

join([], Sep) when is_list(Sep) ->
[];
Expand Down
Loading

0 comments on commit 9baaa98

Please sign in to comment.