diff --git a/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/repository/DefaultNRepositoryDB.java b/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/repository/DefaultNRepositoryDB.java index cdc281f2e..926ba7e14 100644 --- a/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/repository/DefaultNRepositoryDB.java +++ b/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/repository/DefaultNRepositoryDB.java @@ -31,8 +31,8 @@ private DefaultNRepositoryDB(NSession session) { reg("google", "maven@https://maven.google.com"); reg("spring", "maven@https://repo.spring.io/release", "spring-framework"); reg("maven-thevpc-git", "maven@https://raw.githubusercontent.com/thevpc/vpc-public-maven/master", "vpc-public-maven"); - reg("nuts-public", "maven@dotfilefs:https://raw.githubusercontent.com/thevpc/nuts-public/master", "vpc-public-nuts","nuts-thevpc-git"); - reg("nuts-preview", "maven@dotfilefs://raw.githubusercontent.com/thevpc/nuts-preview/master", "preview"); + reg("nuts-public", "maven@dotfilefs:https://raw.githubusercontent.com/thevpc/nuts-public/master", "vpc-public-nuts","nuts-thevpc-git"); + reg("nuts-preview", "maven@dotfilefs:https://raw.githubusercontent.com/thevpc/nuts-preview/master", "preview"); reg("thevpc", "maven@htmlfs:https://thevpc.net/maven", "dev"); reg("thevpc-goodies", "nuts@htmlfs:https://thevpc.net/maven-goodies", "goodies"); reg("local", "nuts@local"); diff --git a/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/workspace/cmd/settings/DefaultNSettingsInternalExecutable.java b/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/workspace/cmd/settings/DefaultNSettingsInternalExecutable.java index f9b8338ef..a0d647b01 100644 --- a/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/workspace/cmd/settings/DefaultNSettingsInternalExecutable.java +++ b/core/nuts-runtime/src/main/java/net/thevpc/nuts/runtime/standalone/workspace/cmd/settings/DefaultNSettingsInternalExecutable.java @@ -23,7 +23,7 @@ public class DefaultNSettingsInternalExecutable extends DefaultInternalNExecutableCommand { public DefaultNSettingsInternalExecutable(String[] args, NExecCmd execCommand) { - super("fetch", args, execCommand); + super("settings", args, execCommand); } private List subCommands; diff --git a/core/nuts/src/main/java/net/thevpc/nuts/reserved/optional/NReservedOptionalValidCallable.java b/core/nuts/src/main/java/net/thevpc/nuts/reserved/optional/NReservedOptionalValidCallable.java index 5c2a828d0..a8be30a58 100644 --- a/core/nuts/src/main/java/net/thevpc/nuts/reserved/optional/NReservedOptionalValidCallable.java +++ b/core/nuts/src/main/java/net/thevpc/nuts/reserved/optional/NReservedOptionalValidCallable.java @@ -13,6 +13,8 @@ public class NReservedOptionalValidCallable extends NReservedOptionalValid implements Cloneable { private final NCallable value; + private T result; + private boolean evaluated; public NReservedOptionalValidCallable(NCallable value) { NAssert.requireNonNull(value, "callable"); @@ -40,6 +42,10 @@ public NOptional then(Function mapper) { @Override public T get(NSession session) { - return value.call(session); + if(!evaluated){ + result=value.call(session); + evaluated=true; + } + return result; } } diff --git a/core/nuts/src/main/java/net/thevpc/nuts/util/CallableSupport.java b/core/nuts/src/main/java/net/thevpc/nuts/util/CallableSupport.java new file mode 100644 index 000000000..412a7b07c --- /dev/null +++ b/core/nuts/src/main/java/net/thevpc/nuts/util/CallableSupport.java @@ -0,0 +1,123 @@ +/** + * ==================================================================== + * Nuts : Network Updatable Things Service + * (universal package manager) + *
+ * is a new Open Source Package Manager to help install packages + * and libraries for runtime execution. Nuts is the ultimate companion for + * maven (and other build managers) as it helps installing all package + * dependencies at runtime. Nuts is not tied to java and is a good choice + * to share shell scripts and other 'things' . Its based on an extensible + * architecture to help supporting a large range of sub managers / repositories. + * + *
+ *

+ * Copyright [2020] [thevpc] + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain a + * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + *
+ * ==================================================================== + */ +package net.thevpc.nuts.util; + +import net.thevpc.nuts.NConstants; + +import java.util.Collection; +import java.util.function.Supplier; +import java.util.stream.Stream; + +public interface CallableSupport { + + static CallableSupport resolve(Collection> source, Supplier emptyMessage) { + if (source == null) { + return invalid(emptyMessage); + } + return resolve(source.stream(), emptyMessage); + } + + static CallableSupport resolve(Stream> source, Supplier emptyMessage) { + if (source == null) { + return invalid(emptyMessage); + } + return resolveSupplier(source.map(x -> () -> x), emptyMessage); + } + + static CallableSupport resolveSupplier(Collection>> source, Supplier emptyMessage) { + if (source == null) { + return invalid(emptyMessage); + } + return resolveSupplier(source.stream(), emptyMessage); + } + + static CallableSupport resolveSupplier(Stream>> source, Supplier emptyMessage) { + Object[] track = new Object[2]; + if (source != null) { + source.forEach(i -> { + CallableSupport s = i.get(); + NAssert.requireNonNull(s, "NSupported"); + int supportLevel = s.getSupportLevel(); + boolean valid = supportLevel > 0; + if (valid) { + if (track[0] == null) { + track[0] = s; + track[1] = supportLevel; + } else { + int oldSupportLevel = (Integer) track[1]; + if (supportLevel > oldSupportLevel) { + track[0] = s; + track[1] = supportLevel; + } + } + } + }); + } + CallableSupport r = (CallableSupport) track[0]; + if (r == null) { + return invalid(emptyMessage); + } + return (CallableSupport) r; + } + + static CallableSupport of(int supportLevel, T value) { + return of(supportLevel, value, null); + } + + static CallableSupport of(int supportLevel, T value, Supplier emptyMessage) { + return supportLevel <= 0 ? invalid(emptyMessage) : new DefaultCallableSupport<>(() -> value, supportLevel, emptyMessage); + } + + static CallableSupport of(int supportLevel, Supplier supplier) { + return of(supportLevel, supplier, null); + } + + static CallableSupport of(int supportLevel, Supplier supplier, Supplier emptyMessage) { + return (supportLevel <= 0 || supplier == null) ? invalid(emptyMessage) + : new DefaultCallableSupport<>(supplier, supportLevel, emptyMessage) + ; + } + + @SuppressWarnings("unchecked") + static CallableSupport invalid(Supplier emptyMessage) { + return new DefaultCallableSupport<>(null, NConstants.Support.NO_SUPPORT, emptyMessage); + } + + static boolean isValid(CallableSupport s) { + return s != null && s.isValid(); + } + + T call(); + + default boolean isValid() { + return getSupportLevel() > 0; + } + + int getSupportLevel(); + + NOptional toOptional(); +} diff --git a/core/nuts/src/main/java/net/thevpc/nuts/util/DefaultCallableSupport.java b/core/nuts/src/main/java/net/thevpc/nuts/util/DefaultCallableSupport.java new file mode 100644 index 000000000..9d0596cc3 --- /dev/null +++ b/core/nuts/src/main/java/net/thevpc/nuts/util/DefaultCallableSupport.java @@ -0,0 +1,62 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package net.thevpc.nuts.util; + +import net.thevpc.nuts.NCallableSupport; +import net.thevpc.nuts.NNoSuchElementException; +import net.thevpc.nuts.NSession; +import net.thevpc.nuts.reserved.NApiUtilsRPI; + +import java.util.NoSuchElementException; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Default implementation of NutsSupported + * + * @param value type + * @author thevpc + */ +public class DefaultCallableSupport implements CallableSupport { + private final Supplier value; + private final int supportLevel; + private final Supplier emptyMessage; + + public DefaultCallableSupport(Supplier value, int supportLevel, Supplier emptyMessage) { + this.value = value; + if (this.value == null && supportLevel > 0) { + throw new IllegalArgumentException("null callable requires invalid support"); + } else if (this.value != null && supportLevel <= 0) { + throw new IllegalArgumentException("non null callable requires valid support"); + } + this.supportLevel = supportLevel; + this.emptyMessage = emptyMessage == null ? () -> "not found" : emptyMessage; + } + + public T call() { + if (isValid()) { + return value.get(); + } else { + String m = emptyMessage.get(); + if(m==null){ + m="not found"; + } + throw new NoSuchElementException(m); + } + } + + public int getSupportLevel() { + return supportLevel; + } + + @Override + public NOptional toOptional() { + if (isValid()) { + return NOptional.ofCallable(s -> value.get()); + } + return NOptional.ofEmpty(s->NMsg.ofPlain(emptyMessage.get())); + } +} diff --git a/toolbox/noapi/pom.xml b/toolbox/noapi/pom.xml index ade6e1ca7..d2e5bddc7 100644 --- a/toolbox/noapi/pom.xml +++ b/toolbox/noapi/pom.xml @@ -70,6 +70,11 @@ nlib-md 0.8.4.0 + + org.jruby + jruby-complete + 1.7.26 + org.asciidoctor asciidoctorj diff --git a/toolbox/noapi/src/main/java/net/thevpc/nuts/toolbox/noapi/util/NoApiUtils.java b/toolbox/noapi/src/main/java/net/thevpc/nuts/toolbox/noapi/util/NoApiUtils.java index eba985460..0c1029dc8 100644 --- a/toolbox/noapi/src/main/java/net/thevpc/nuts/toolbox/noapi/util/NoApiUtils.java +++ b/toolbox/noapi/src/main/java/net/thevpc/nuts/toolbox/noapi/util/NoApiUtils.java @@ -171,7 +171,7 @@ public static String toCode(TypeInfo o, boolean includeDesc, String indent, AppM type += ("(" + o.getMinLength().trim() + "..." + o.getMaxLength().trim() + ")"); } else if (!NBlankable.isBlank(o.getMinLength())) { type += (">=" + o.getMinLength().trim()); - } else if (!NBlankable.isBlank(o.getMaxLength())) { + } else if (!NBlankable.isBlank(o.getMinLength())) { type += ("<=" + o.getMinLength().trim()); } if (o.getEnumValues() != null && o.getEnumValues().size() > 0) { @@ -187,7 +187,7 @@ public static String toCode(TypeInfo o, boolean includeDesc, String indent, AppM type += ("(" + o.getMinLength().trim() + "..." + o.getMaxLength().trim() + ")"); } else if (!NBlankable.isBlank(o.getMinLength())) { type += (">=" + o.getMinLength().trim()); - } else if (!NBlankable.isBlank(o.getMaxLength())) { + } else if (!NBlankable.isBlank(o.getMinLength())) { type += ("<=" + o.getMinLength().trim()); } if (o.getEnumValues() != null && o.getEnumValues().size() > 0) {