Skip to content

Commit

Permalink
[FIXED] stabilization
Browse files Browse the repository at this point in the history
  • Loading branch information
thevpc committed Dec 1, 2024
1 parent e4b0142 commit d5a2cce
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 40 deletions.
7 changes: 7 additions & 0 deletions core/nuts-api/src/main/java/net/thevpc/nuts/NDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public interface NDescriptor extends Serializable, NBlankable {
*/
String getPackaging();

/**
*
* This is typically the case for pom projects
* @return true when the descriptor does not define a content.
*/
boolean isNoContent();

/**
* dependency resolution solver. defaults to 'maven'
*
Expand Down
6 changes: 3 additions & 3 deletions core/nuts-api/src/main/java/net/thevpc/nuts/NFetchCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ static NFetchCmd ofNutsRuntime() {
NFetchCmd setExpireTime(Instant value);

/**
* when true, NutsNotFoundException instances are ignored
* when true, NNotFoundException instances are ignored
*
* @return true if armed FailFast mode
*/
boolean isFailFast();

/**
* set armed (or disarmed) fail safe mode. if true, null replaces
* NutsNotFoundException.
* NNotFoundException.
*
* @param enable if true, null replaces NutsNotFoundException.
* @param enable if true, null replaces NNotFoundException.
* @return {@code this} instance
*/
NFetchCmd setFailFast(boolean enable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class NNoSuchElementException extends NException {

/**
* Constructs a new NutsIllegalArgumentException exception
* Constructs a new NNoSuchElementException exception
*
* @param message message
*/
Expand All @@ -47,7 +47,7 @@ public NNoSuchElementException(NMsg message) {
}

/**
* Constructs a new NutsIllegalArgumentException exception
* Constructs a new NNoSuchElementException exception
*
* @param message message
* @param cause cause
Expand All @@ -57,13 +57,13 @@ public NNoSuchElementException(NMsg message, Throwable cause) {
}

/**
* Constructs a new NutsIllegalArgumentException exception
* Constructs a new NNoSuchElementException exception
*
* @param message message
* @param cause cause
* @param enableSuppression whether or not suppression is enabled or
* @param enableSuppression whether suppression is enabled or
* disabled
* @param writableStackTrace whether or not the stack trace should be
* @param writableStackTrace whether the stack trace should be
* writable
*/
public NNoSuchElementException(NMsg message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.thevpc.nuts.util.NMsg;

/**
* Exception thrown when a non executable nuts id is requested to run.
* Exception thrown when a non-executable nuts id is requested to run.
*
* @app.category Exceptions
* @since 0.5.4
Expand All @@ -42,7 +42,7 @@ public class NNotExecutableException extends NExecutionException {
private final NId id;

/**
* Constructs a new NutsNotExecutableException exception
* Constructs a new NNotExecutableException exception
*
* @param id artifact id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class NNotFoundException extends NException {
private Set<NIdInvalidDependency> missingDependencies = Collections.emptySet();

/**
* Constructs a new NutsNotFoundException exception
* Constructs a new NNotFoundException exception
*
* @param id artifact id
*/
Expand All @@ -56,7 +56,7 @@ public NNotFoundException(NId id) {
}

/**
* Constructs a new NutsNotFoundException exception
* Constructs a new NNotFoundException exception
*
* @param id artifact id
* @param cause cause
Expand All @@ -67,7 +67,7 @@ public NNotFoundException(NId id, Throwable cause) {


/**
* Constructs a new NutsNotFoundException exception
* Constructs a new NNotFoundException exception
*
* @param id artifact id
* @param dependencies dependencies
Expand All @@ -88,7 +88,7 @@ public NNotFoundException(NId id, NIdInvalidDependency[] dependencies, NIdInvali
}

/**
* Constructs a new NutsNotFoundException exception
* Constructs a new NNotFoundException exception
*
* @param id artifact id
* @param message message
Expand All @@ -102,7 +102,7 @@ public NNotFoundException(NId id, NMsg message, Throwable cause) {
}

/**
* Constructs a new NutsNotFoundException exception
* Constructs a new NNotFoundException exception
*
* @param id artifact id
* @param message message
Expand Down
6 changes: 3 additions & 3 deletions core/nuts-api/src/main/java/net/thevpc/nuts/NSearchCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,17 +601,17 @@ static NSearchCmd of() {
List<String> getPackaging();

/**
* when true, NutsNotFoundException instances are ignored
* when true, NNotFoundException instances are ignored
*
* @return true if armed FailFast mode
*/
boolean isFailFast();

/**
* set armed (or disarmed) fail safe mode. if true, null replaces
* NutsNotFoundException.
* NNotFoundException.
*
* @param enable if true, null replaces NutsNotFoundException.
* @param enable if true, null replaces NNotFoundException.
* @return {@code this} instance
*/
NSearchCmd setFailFast(boolean enable);
Expand Down
8 changes: 8 additions & 0 deletions core/nuts-api/src/main/java/net/thevpc/nuts/log/NLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ default void warn(NMsg msg, Throwable thrown){
log(Level.WARNING, NLogVerb.WARNING, msg, thrown);
}

default void info(NMsg msg){
log(Level.INFO, NLogVerb.INFO, msg);
}

default void debug(NMsg msg){
log(Level.FINEST, NLogVerb.DEBUG, msg);
}

default void warn(NMsg msg){
log(Level.WARNING, NLogVerb.WARNING, msg,null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

import net.thevpc.nuts.*;

import net.thevpc.nuts.boot.NBootLogConfig;
import net.thevpc.nuts.boot.NBootOptionsInfo;
import net.thevpc.nuts.boot.reserved.cmdline.NBootWorkspaceCmdLineParser;
import net.thevpc.nuts.text.NText;
import net.thevpc.nuts.text.NTextBuilder;
import net.thevpc.nuts.util.NBlankable;
Expand Down Expand Up @@ -128,10 +131,39 @@ public static boolean resolveShowStackTrace(NWorkspaceOptions bo) {
}
}

public static boolean resolveShowStackTrace(NBootOptionsInfo bo) {
if (bo.getShowStacktrace()!=null) {
return bo.getShowStacktrace();
} else if (bo.getBot()!=null && bo.getBot()) {
return false;
} else {
if (NApiUtilsRPI.getSysBoolNutsProperty("stacktrace", false)) {
return true;
}
if (bo.getDebug()!=null && !NBlankable.isBlank(bo.getDebug())) {
return true;
}
NBootLogConfig nLogConfig = bo.getLogConfig();
if (nLogConfig!=null && nLogConfig.getLogTermLevel() != null
&& nLogConfig.getLogTermLevel().intValue() < Level.INFO.intValue()) {
return true;
}
return false;
}
}

public static int processThrowable(Throwable ex, String[] args) {
NWorkspaceOptionsBuilder bo = NWorkspaceOptionsBuilder.of();
bo.setCmdLine(args);
return processThrowable(ex, null, true, resolveShowStackTrace(bo), resolveGui(bo));
if (ex == null) {
return 0;
}
NSession session = NSessionAwareExceptionBase.resolveSession(ex).orNull();
if (session != null) {
return (NApplicationExceptionHandler.of()
.processThrowable(args, ex));
}
NBootOptionsInfo options = new NBootOptionsInfo();
NBootWorkspaceCmdLineParser.parseNutsArguments(args, options);
return processThrowable(ex, null, true, resolveShowStackTrace(options), resolveGui(options));
}

/**
Expand All @@ -145,26 +177,26 @@ public static int processThrowable(Throwable ex, NLog out) {
if (ex == null) {
return 0;
}

NSession session = NSessionAwareExceptionBase.resolveSession(ex).orNull();
NWorkspaceOptionsBuilder bo = null;
if (session != null) {
bo = NWorkspace.get().getBootOptions().builder().toWorkspaceOptions().builder();
return processThrowable(ex, out, true, resolveShowStackTrace(bo), resolveGui(bo));
} else {
NWorkspaceOptionsBuilder options = NWorkspaceOptionsBuilder.of();
//load inherited
String nutsArgs = NStringUtils.trim(
NStringUtils.trim(System.getProperty("nuts.boot.args"))
+ " " + NStringUtils.trim(System.getProperty("nuts.args"))
);
try {
options.setCmdLine(NCmdLine.parseDefault(nutsArgs).get().toStringArray());
NBootOptionsInfo options = new NBootOptionsInfo();
NBootWorkspaceCmdLineParser.parseNutsArguments(NCmdLine.parseDefault(nutsArgs).get().toStringArray(), options);
return processThrowable(ex, null, true, resolveShowStackTrace(options), resolveGui(options));
} catch (Exception e) {
//any, ignore...
}
bo = options;
return 254;
}
return processThrowable(ex, out, true, resolveShowStackTrace(bo), resolveGui(bo));
}

public static boolean resolveGui(NWorkspaceOptions bo) {
Expand All @@ -180,6 +212,19 @@ public static boolean resolveGui(NWorkspaceOptions bo) {
return false;
}
}
public static boolean resolveGui(NBootOptionsInfo bo) {
if (bo.getBot()!=null && bo.getBot()) {
return false;
}
if (bo.getGui()!=null && bo.getGui()) {
if (!NApiUtilsRPI.isGraphicalDesktopEnvironment()) {
return false;
}
return true;
} else {
return false;
}
}

public static int processThrowable(Throwable ex, NLog out, boolean showMessage, boolean showStackTrace, boolean showGui) {
if (ex == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public String getPackaging() {
return packaging;
}

public boolean isNoContent() {
return "pom".equals(getPackaging());
}

@Override
public String getSolver() {
return solver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,4 +843,8 @@ public List<NDescriptorContributor> getDevelopers() {
public int getSupportLevel(NSupportLevelContext context) {
return NConstants.Support.DEFAULT_SUPPORT;
}

public boolean isNoContent() {
return "pom".equals(getPackaging());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ private static NClassLoaderNode toClassLoaderNode(NDependencyTreeNode d, boolean
return toClassLoaderNodeWithOptional(d, false, withChildren, repositoryFilter);
}

private static NClassLoaderNode toClassLoaderNodeWithOptional(NDependency d, boolean isOptional, NRepositoryFilter repositoryFilter) {
private static NClassLoaderNode toClassLoaderNodeWithOptional(NDependency d, boolean optional, NRepositoryFilter repositoryFilter) {
NPath cc = null;
if (!isOptional) {
if (!NDependencyUtils.isRequiredDependency(d)) {
isOptional = true;
if (!optional) {
if (NDependencyUtils.isOptionalDependency(d)) {
optional = true;
}
}
NId id = d.toId();
Expand All @@ -94,7 +94,7 @@ private static NClassLoaderNode toClassLoaderNodeWithOptional(NDependency d, boo
);
}
}
if (isOptional) {
if (optional) {
return null;
}
throw new NNotFoundException(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public static String toExclusionListString(NId[] exclusions) {
return String.join(",", ex);
}

public static boolean isOptionalDependency(NDependency d) {
return !isRequiredDependency(d);
}

public static boolean isRequiredDependency(NDependency d) {
if (d.isOptional()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,9 @@ public List<NDescriptorMailingList> getMailingLists() {
public NDescriptorOrganization getOrganization() {
return getBase().getOrganization();
}

@Override
public boolean isNoContent() {
return getBase().isNoContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import java.util.stream.Collectors;

public class NDescriptorUtils {
public static boolean isNoContent(NDescriptor desc) {
return desc != null && "pom".equals(desc.getPackaging());
}

public static NDescriptor getEffectiveDescriptor(NDefinition def) {
final NDescriptor d = def.getEffectiveDescriptor().orNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public NDescriptor deploy(NDeployRepositoryCmd deployment, NConfirmationMode wri
CoreNIdUtils.checkLongId(id);
NInputSource inputSource = null;
if (deployment.getContent() == null) {
if (!NDescriptorUtils.isNoContent(descriptor)) {
if (!descriptor.isNoContent()) {
NAssert.requireNonNull(deployment.getContent(), () -> NMsg.ofC("invalid deployment; missing content for %s", deployment.getId()));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private String resolveAuthURLPart() {
// public void checkAllowedFetch(NutsId parse, NutsSession session) {
// super.checkAllowedFetch(parse, session);
// if (session.getFetchMode() != NutsFetchMode.REMOTE) {
// throw new NutsNotFoundException(session(), parse);
// throw new NNotFoundException(session(), parse);
// }
// }
private class NamedNIdFromStreamIterator extends NIteratorBase<NId> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public void installOrUpdateImpl(NDefinition def, String[] args, boolean resolveI
try {
NDependencyFilter ndf = NDependencyFilters.of().byRunnable();
if (def.getEffectiveDescriptor().isNotPresent()
|| (!NDescriptorUtils.isNoContent(def.getDescriptor()) && def.getContent().isNotPresent())) {
|| (!def.getDescriptor().isNoContent() && def.getContent().isNotPresent())) {
// reload def
NFetchCmd fetch2 = NFetchCmd.of(def.getId())
.content()
Expand Down Expand Up @@ -1074,7 +1074,7 @@ public void installOrUpdateImpl(NDefinition def, String[] args, boolean resolveI
}
out.flush();
NWorkspace envs = this;
if (def.getContent().isPresent() || NDescriptorUtils.isNoContent(def.getDescriptor())) {
if (def.getContent().isPresent() || def.getDescriptor().isNoContent()) {
if (requireParents) {
List<NDefinition> requiredDefinitions = new ArrayList<>();
for (NId parent : def.getDescriptor().getParents()) {
Expand Down
Loading

0 comments on commit d5a2cce

Please sign in to comment.