Skip to content

Commit

Permalink
#260 - disable invalid runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdu committed Mar 16, 2016
1 parent 6aa29d8 commit 3a1b354
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 101 deletions.

This file was deleted.

@@ -0,0 +1,27 @@
package org.erlide.runtime

import java.util.Collection
import org.erlide.runtime.runtimeinfo.RuntimeInfo
import org.junit.Test

import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.is

class RuntimeInfoTest {

@Test
def void codePath_Runtime_1() {
val RuntimeInfo info = new RuntimeInfo("dummy")
val Collection<String> pa = info.getCodePath()
assertThat(pa.size(), is(0))
assertThat(info.isValid(), is(false))
}

// @Test
// def void versionLocator() {
// val RuntimeInfo info1 = new RuntimeInfo("dummy", "", "", #[])
// TODO create dir that looks like an otp home
// val RuntimeInfo info2 = new RuntimeInfo("dummy", "", "", #[])
// assertThat(VersionLocator.locateVersion(new RuntimeVersion(18), #[info1, info2], false), is(#[info1]))
// }
}
@@ -0,0 +1,23 @@
package org.erlide.runtime;

import java.util.Collection;
import org.erlide.runtime.runtimeinfo.RuntimeInfo;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

@SuppressWarnings("all")
public class RuntimeInfoTest {
@Test
public void codePath_Runtime_1() {
final RuntimeInfo info = new RuntimeInfo("dummy");
final Collection<String> pa = info.getCodePath();
int _size = pa.size();
Matcher<Integer> _is = Matchers.<Integer>is(Integer.valueOf(0));
MatcherAssert.<Integer>assertThat(Integer.valueOf(_size), _is);
boolean _isValid = info.isValid();
Matcher<Boolean> _is_1 = Matchers.<Boolean>is(Boolean.valueOf(false));
MatcherAssert.<Boolean>assertThat(Boolean.valueOf(_isValid), _is_1);
}
}
Expand Up @@ -22,6 +22,7 @@
import com.google.common.base.Charsets;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
Expand Down Expand Up @@ -153,10 +154,7 @@ public static boolean validateLocation(final String path) {

public static boolean isValidOtpHome(final String otpHome) {
// Check if it looks like a ERL_TOP location:
if (otpHome == null) {
return false;
}
if (otpHome.length() == 0) {
if (Strings.isNullOrEmpty(otpHome)) {
return false;
}
final File d = new File(otpHome);
Expand Down
Expand Up @@ -85,7 +85,7 @@ public boolean hasRuntimeWithName(final String name) {
@Override
public @NonNull RuntimeInfo getRuntime(final String name) {
final RuntimeInfo rt = runtimes.get(name);
if (rt != null) {
if (rt != null && rt.isValid()) {
return rt;
}
return RuntimeInfo.NO_RUNTIME_INFO;
Expand Down Expand Up @@ -140,19 +140,19 @@ private synchronized void setErlideRuntime(final @NonNull RuntimeInfo runtime) {
@Override
public RuntimeInfo getRuntime(final RuntimeVersion runtimeVersion,
final String runtimeName) {
final List<RuntimeInfo> vsns = VersionLocator.locateVersion(runtimeVersion,
final Collection<RuntimeInfo> vsns = VersionLocator.locateVersion(runtimeVersion,
runtimes.values(), false);
if (vsns.isEmpty()) {
return null;
} else if (vsns.size() == 1) {
return vsns.get(0);
return vsns.iterator().next();
} else {
for (final RuntimeInfo ri : vsns) {
if (runtimeName == null || ri.getName().equals(runtimeName)) {
return ri;
}
}
return vsns.get(0);
return vsns.iterator().next();
}
}

Expand All @@ -171,16 +171,15 @@ public List<String> getAllRuntimesVersions() {
}

/**
* If runtime is not set, try to locate one. The first one found as below is
* set as default. All "obvious" runtimes found are stored.
* If runtime is not set, try to locate one. The first one found as below is set as
* default. All "obvious" runtimes found are stored.
* <ul>
* <li>A system property <code>erlide.runtime</code> can be set to point to
* a location.</li>
* <li>A preference in the default scope
* <code>org.erlide.core/default_runtime</code> can be set to point to a
* <li>A system property <code>erlide.runtime</code> can be set to point to a
* location.</li>
* <li>Look for existing Erlang runtimes in a few obvious places and install
* them, choosing a suitable one as default.</li>
* <li>A preference in the default scope <code>org.erlide.core/default_runtime</code>
* can be set to point to a location.</li>
* <li>Look for existing Erlang runtimes in a few obvious places and install them,
* choosing a suitable one as default.</li>
* </ul>
*
*/
Expand Down

This file was deleted.

@@ -0,0 +1,38 @@
package org.erlide.runtime.runtimeinfo

import java.util.Collection
import java.util.Collections
import java.util.List

class VersionLocator {
/**
* Locate runtimes with this version. If exact matches exist, they are first in the
* result list. If strict, only this version or newer are returned, otherwise all. A
* null or empty version returns all runtimes.
*/
def static Collection<RuntimeInfo> locateVersion(RuntimeVersion vsn, Collection<RuntimeInfo> runtimes,
boolean strict) {
val List<RuntimeInfo> result = newArrayList()
for (info : runtimes) {
val v = info.getVersion()
if (v.isReleaseCompatible(vsn)) {
result.add(info)
}
}
Collections.reverse(result)
// at the end, first newer versions
for (info : runtimes) {
val v = info.getVersion()
if (v.compareTo(vsn) > 0) {
result.add(info)
}
}
// and if necessary, older versions
if (!strict) {
for (info : runtimes) {
result.add(info)
}
}
result.filter[isValid()].toSet
}
}
@@ -0,0 +1,60 @@
package org.erlide.runtime.runtimeinfo;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.erlide.runtime.runtimeinfo.RuntimeInfo;
import org.erlide.runtime.runtimeinfo.RuntimeVersion;

@SuppressWarnings("all")
public class VersionLocator {
/**
* Locate runtimes with this version. If exact matches exist, they are first in the
* result list. If strict, only this version or newer are returned, otherwise all. A
* null or empty version returns all runtimes.
*/
public static Collection<RuntimeInfo> locateVersion(final RuntimeVersion vsn, final Collection<RuntimeInfo> runtimes, final boolean strict) {
Set<RuntimeInfo> _xblockexpression = null;
{
final List<RuntimeInfo> result = CollectionLiterals.<RuntimeInfo>newArrayList();
for (final RuntimeInfo info : runtimes) {
{
final RuntimeVersion v = info.getVersion();
boolean _isReleaseCompatible = v.isReleaseCompatible(vsn);
if (_isReleaseCompatible) {
result.add(info);
}
}
}
Collections.reverse(result);
for (final RuntimeInfo info_1 : runtimes) {
{
final RuntimeVersion v = info_1.getVersion();
int _compareTo = v.compareTo(vsn);
boolean _greaterThan = (_compareTo > 0);
if (_greaterThan) {
result.add(info_1);
}
}
}
if ((!strict)) {
for (final RuntimeInfo info_2 : runtimes) {
result.add(info_2);
}
}
final Function1<RuntimeInfo, Boolean> _function = new Function1<RuntimeInfo, Boolean>() {
@Override
public Boolean apply(final RuntimeInfo it) {
return Boolean.valueOf(it.isValid());
}
};
Iterable<RuntimeInfo> _filter = IterableExtensions.<RuntimeInfo>filter(result, _function);
_xblockexpression = IterableExtensions.<RuntimeInfo>toSet(_filter);
}
return _xblockexpression;
}
}

0 comments on commit 3a1b354

Please sign in to comment.