diff --git a/README.md b/README.md
index c2e7b2a7a..bbfa0761e 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Network Updatable Things Services
/ | / /_ __/ /______
/ |/ / / / / __/ ___/
/ /| / /_/ / /_(__ )
-/_/ |_/\__,_/\__/____/ version 0.5.3.0
+/_/ |_/\__,_/\__/____/ version 0.5.4.0
nuts stands for **Network Updatable Things Services** tool. It is a simple tool for managing remote
@@ -30,7 +30,7 @@ to install and uninstall components allowing multiple versions of the very same
+ find : searches for existing/installable components
## Download Latest stable version
-+ Java or any Java enabled OS : Linux,Windows,iOS, ... :: [nuts-0.5.3.jar](https://github.com/thevpc/vpc-public-maven/raw/master/net/vpc/app/nuts/nuts/0.5.3/nuts-0.5.3.jar)
++ Java or any Java enabled OS : Linux,Windows,iOS, ... :: [nuts-0.5.4.jar](https://github.com/thevpc/vpc-public-maven/raw/master/net/vpc/app/nuts/nuts/0.5.4/nuts-0.5.4.jar)
## Requirements
Java Runtime Environment (JRE) or Java Development Kit (JDK) version 8 or later
@@ -61,6 +61,7 @@ java -jar nuts-0.5.4.jar
## Latest News
++ 2019/04/21 nuts 0.5.4.0 released [nuts-0.5.3.jar](https://github.com/thevpc/vpc-public-maven/raw/master/net/vpc/app/nuts/nuts/0.5.4/nuts-0.5.4.jar)
+ 2019/01/05 nuts 0.5.3.0 released [nuts-0.5.3.jar](https://github.com/thevpc/vpc-public-maven/raw/master/net/vpc/app/nuts/nuts/0.5.3/nuts-0.5.3.jar)
+ 2018/12/28 nuts 0.5.2.0 released [nuts-0.5.2.jar](https://github.com/thevpc/vpc-public-maven/raw/master/net/vpc/app/nuts/nuts/0.5.2/nuts-0.5.2.jar)
+ 2018/12/18 nuts 0.5.1.0 released [nuts-0.5.1.jar](https://github.com/thevpc/vpc-public-maven/raw/master/net/vpc/app/nuts/nuts/0.5.1/nuts-0.5.1.jar)
diff --git a/nuts-core/nbactions.xml b/nuts-core/nbactions.xml
index d0e8e73cb..e368b0dc9 100644
--- a/nuts-core/nbactions.xml
+++ b/nuts-core/nbactions.xml
@@ -10,7 +10,7 @@
org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
- -Dnuts.export.trace-exit-errors=y -classpath %classpath net.vpc.app.nuts.Nuts --init=reset -y find -f local --lenient --json
+ -Dnuts.export.trace-exit-errors=y -classpath %classpath net.vpc.app.nuts.Nuts --exec --show-command vr-box
java
@@ -38,7 +38,7 @@
org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
- -Dnuts.export.trace-exit-errors=y -classpath %classpath net.vpc.app.nuts.Nuts --init=reset -y find -f local --lenient --json
+ -Dnuts.export.trace-exit-errors=y -classpath %classpath net.vpc.app.nuts.Nuts --exec --show-command vr-box
java
@@ -52,7 +52,7 @@
org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
- -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -Dnuts.export.trace-exit-errors=y -classpath %classpath net.vpc.app.nuts.Nuts --init=reset -y find -f local --lenient --json
+ -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -Dnuts.export.trace-exit-errors=y -classpath %classpath net.vpc.app.nuts.Nuts --exec --show-command vr-box
java
true
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsAddUserCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsAddUserCommand.java
index 88393235b..0a486d0ea 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsAddUserCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsAddUserCommand.java
@@ -35,9 +35,11 @@
import java.util.HashSet;
import java.util.Set;
import net.vpc.app.nuts.NutsAddUserCommand;
+import net.vpc.app.nuts.NutsCommandArg;
+import net.vpc.app.nuts.NutsCommandLine;
import net.vpc.app.nuts.NutsIllegalArgumentException;
import net.vpc.app.nuts.NutsRepository;
-import net.vpc.app.nuts.NutsSession;
+import net.vpc.app.nuts.NutsUpdateUserCommand;
import net.vpc.app.nuts.NutsUserConfig;
import net.vpc.app.nuts.NutsWorkspace;
import net.vpc.app.nuts.core.spi.NutsRepositoryConfigManagerExt;
@@ -48,84 +50,23 @@
* @author vpc
* @since 0.5.4
*/
-public class DefaultNutsAddUserCommand implements NutsAddUserCommand {
+public class DefaultNutsAddUserCommand extends NutsWorkspaceCommandBase implements NutsAddUserCommand {
- private boolean trace = true;
- private boolean force = false;
private String login;
private String remoteIdentity;
private String password;
- private Set rights = new HashSet();
- private Set groups = new HashSet();
- private NutsSession session;
+ private final Set rights = new HashSet<>();
+ private final Set groups = new HashSet<>();
private NutsRepository repo;
- private NutsWorkspace ws;
public DefaultNutsAddUserCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
public DefaultNutsAddUserCommand(NutsRepository repo) {
+ super(repo.getWorkspace());
this.repo = repo;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public DefaultNutsAddUserCommand trace() {
- return trace(true);
- }
-
- @Override
- public DefaultNutsAddUserCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
- @Override
- public DefaultNutsAddUserCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public DefaultNutsAddUserCommand force() {
- return force(true);
- }
-
- @Override
- public DefaultNutsAddUserCommand force(boolean force) {
- return setForce(force);
- }
-
- @Override
- public DefaultNutsAddUserCommand setForce(boolean force) {
- this.force = force;
- return this;
- }
-
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public DefaultNutsAddUserCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public DefaultNutsAddUserCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
@Override
public String getLogin() {
return login;
@@ -328,4 +269,24 @@ public NutsAddUserCommand run() {
}
return this;
}
+
+ public NutsAddUserCommand parseOptions(String... args) {
+ NutsCommandLine cmd = new NutsCommandLine(args);
+ NutsCommandArg a;
+ while ((a = cmd.next()) != null) {
+ switch (a.strKey()) {
+ default: {
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ //id(a.getString());
+ }
+ }
+ }
+ }
+ }
+ return this;
+ }
+
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsDeployCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsDeployCommand.java
index b078e31e7..cb3fb0c00 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsDeployCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsDeployCommand.java
@@ -5,15 +5,15 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStreamWriter;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Properties;
+import java.util.Map;
import net.vpc.app.nuts.core.util.CharacterizedFile;
import net.vpc.app.nuts.core.util.io.CoreIOUtils;
import net.vpc.app.nuts.core.util.common.CorePlatformUtils;
@@ -24,7 +24,7 @@
import net.vpc.app.nuts.core.util.io.ZipOptions;
import net.vpc.app.nuts.core.util.io.ZipUtils;
-public class DefaultNutsDeployCommand implements NutsDeployCommand {
+public class DefaultNutsDeployCommand extends NutsWorkspaceCommandBase implements NutsDeployCommand {
private List result;
private Object content;
@@ -33,17 +33,12 @@ public class DefaultNutsDeployCommand implements NutsDeployCommand {
private String descSha1;
private String fromRepository;
private String toRepository;
- private boolean trace = true;
- private boolean force = false;
private boolean offline = false;
private boolean transitive = true;
- private NutsWorkspace ws;
- private NutsSession session;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
private final List ids = new ArrayList<>();
public DefaultNutsDeployCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -164,7 +159,7 @@ public NutsDeployCommand targetRepository(String repository) {
public NutsDeployCommand setRepository(String repository) {
return setTargetRepository(repository);
}
-
+
@Override
public NutsDeployCommand setTargetRepository(String repository) {
this.toRepository = repository;
@@ -189,30 +184,6 @@ public NutsDeployCommand setSourceRepository(String repository) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsDeployCommand setTrace(boolean trace) {
- this.trace = trace;
- invalidateResult();
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public NutsDeployCommand setForce(boolean force) {
- this.force = force;
- invalidateResult();
- return this;
- }
-
@Override
public boolean isOffline() {
return offline;
@@ -237,27 +208,6 @@ public NutsDeployCommand setTransitive(boolean transitive) {
return this;
}
- public NutsWorkspace getWs() {
- return ws;
- }
-
- public void setWs(NutsWorkspace ws) {
- this.ws = ws;
- invalidateResult();
- }
-
- @Override
- public NutsDeployCommand setSession(NutsSession session) {
- this.session = session;
- invalidateResult();
- return this;
- }
-
- @Override
- public NutsSession getSession() {
- return session;
- }
-
@Override
public NutsDeployCommand content(InputStream value) {
return setContent(value);
@@ -335,21 +285,6 @@ public NutsDeployCommand repository(String repository) {
return setTargetRepository(repository);
}
- @Override
- public NutsDeployCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public NutsDeployCommand force() {
- return setForce(true);
- }
-
- @Override
- public NutsDeployCommand force(boolean force) {
- return setForce(force);
- }
-
@Override
public NutsDeployCommand offline() {
return setOffline(true);
@@ -360,16 +295,6 @@ public NutsDeployCommand offline(boolean offline) {
return setOffline(offline);
}
- @Override
- public NutsDeployCommand trace() {
- return setTrace(true);
- }
-
- @Override
- public NutsDeployCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
@Override
public NutsDeployCommand transitive() {
return setTransitive(true);
@@ -380,6 +305,7 @@ public NutsDeployCommand transitive(boolean transitive) {
return setTransitive(transitive);
}
+ @Override
public NutsId[] getResult() {
if (result == null) {
run();
@@ -387,7 +313,7 @@ public NutsId[] getResult() {
return result.toArray(new NutsId[0]);
}
- private void invalidateResult() {
+ protected void invalidateResult() {
result = null;
}
@@ -402,21 +328,21 @@ public NutsDeployCommand run() {
runDeployFile(fetched.getPath(), fetched.getDescriptor(), null);
}
}
- if (trace) {
+ if (isTrace()) {
if (getOutputFormat() == null || getOutputFormat() == NutsOutputFormat.PLAIN) {
- session = NutsWorkspaceUtils.validateSession(ws, getSession());
+
if (getOutputFormat() != null && getOutputFormat() != NutsOutputFormat.PLAIN) {
switch (getOutputFormat()) {
case JSON: {
- session.getTerminal().out().printf(ws.io().toJsonString(result, true));
+ getValidSession().getTerminal().out().printf(ws.io().toJsonString(result, true));
break;
}
case PROPS: {
- Properties props = new Properties();
+ Map props = new LinkedHashMap<>();
for (int i = 0; i < result.size(); i++) {
props.put(String.valueOf(i + 1), result.get(i).toString());
}
- CoreIOUtils.storeProperties(props, session.getTerminal().out());
+ CoreIOUtils.storeProperties(props, getValidSession().getTerminal().out());
break;
}
@@ -444,8 +370,8 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
Path contentFile2 = null;
try {
if (descriptor == null) {
- NutsFetchCommand p = ws.fetch().setTransitive(this.isTransitive()).setSession(session);
- characterizedFile = CoreIOUtils.characterize(ws, contentSource, p, session);
+ NutsFetchCommand p = ws.fetch().setTransitive(this.isTransitive()).setSession(getValidSession());
+ characterizedFile = CoreIOUtils.characterize(ws, contentSource, p, getValidSession());
if (characterizedFile.descriptor == null) {
throw new NutsIllegalArgumentException("Missing descriptor");
}
@@ -461,7 +387,6 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
NutsWorkspaceUtils.checkReadOnly(ws);
Path contentFile = contentFile0;
- session = NutsWorkspaceUtils.validateSession(ws, session);
Path tempFile2 = null;
NutsFetchCommand fetchOptions = ws.fetch().setTransitive(this.isTransitive());
try {
@@ -473,7 +398,7 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
} else {
descriptor2 = CoreIOUtils.resolveNutsDescriptorFromFileContent(ws,
CoreIOUtils.createInputSource(contentFile).multi(),
- fetchOptions, session);
+ fetchOptions, getValidSession());
}
if (descriptor == null) {
descriptor = descriptor2;
@@ -498,7 +423,7 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
}
} else {
if (descriptor == null) {
- descriptor = CoreIOUtils.resolveNutsDescriptorFromFileContent(ws, CoreIOUtils.createInputSource(contentFile).multi(), fetchOptions, session);
+ descriptor = CoreIOUtils.resolveNutsDescriptorFromFileContent(ws, CoreIOUtils.createInputSource(contentFile).multi(), fetchOptions, getValidSession());
}
}
if (descriptor == null) {
@@ -510,7 +435,7 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
throw new NutsIllegalArgumentException("Invalid Version " + descriptor.getId().getVersion());
}
- NutsId effId = dws.resolveEffectiveId(descriptor, ws.fetch().setTransitive(true).session(session));
+ NutsId effId = dws.resolveEffectiveId(descriptor, ws.fetch().setTransitive(true).session(getValidSession()));
for (String os : descriptor.getOs()) {
CorePlatformUtils.checkSupportedOs(ws.parser().parseRequiredId(os).getSimpleName());
}
@@ -521,7 +446,7 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
NutsRepositoryFilter repositoryFilter = null;
//TODO CHECK ME, why offline
for (NutsRepository repo : NutsWorkspaceUtils.filterRepositories(ws, NutsRepositorySupportedAction.FIND, effId, repositoryFilter, NutsFetchMode.LOCAL, fetchOptions)) {
- NutsRepositorySession rsession = NutsWorkspaceHelper.createRepositorySession(session, repo, this.isOffline() ? NutsFetchMode.LOCAL : NutsFetchMode.REMOTE, fetchOptions);
+ NutsRepositorySession rsession = NutsWorkspaceHelper.createRepositorySession(getValidSession(), repo, this.isOffline() ? NutsFetchMode.LOCAL : NutsFetchMode.REMOTE, fetchOptions);
effId = ws.config().createComponentFaceId(effId.unsetQuery(), descriptor).setAlternative(CoreStringUtils.trim(descriptor.getAlternative()));
repo.deploy(
@@ -543,7 +468,7 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
if (!repo.config().isEnabled()) {
throw new NutsRepositoryNotFoundException("Repository " + repository + " is disabled.");
}
- NutsRepositorySession rsession = NutsWorkspaceHelper.createRepositorySession(session, repo, this.isOffline() ? NutsFetchMode.LOCAL : NutsFetchMode.REMOTE, fetchOptions);
+ NutsRepositorySession rsession = NutsWorkspaceHelper.createRepositorySession(getValidSession(), repo, this.isOffline() ? NutsFetchMode.LOCAL : NutsFetchMode.REMOTE, fetchOptions);
effId = ws.config().createComponentFaceId(effId.unsetQuery(), descriptor).setAlternative(CoreStringUtils.trim(descriptor.getAlternative()));
repo.deploy(new DefaultNutsRepositoryDeploymentOptions()
.setForce(this.isForce())
@@ -580,14 +505,13 @@ private NutsDeployCommand runDeployFile(Object content, Object descriptor0, Stri
}
private void addResult(NutsId nid) {
- if (trace) {
+ if (isTrace()) {
if (result == null) {
result = new ArrayList<>();
}
result.add(nid);
- session = NutsWorkspaceUtils.validateSession(ws, getSession());
if (getOutputFormat() == null || getOutputFormat() == NutsOutputFormat.PLAIN) {
- session.getTerminal().out().printf("Nuts %N deployed successfully to ==%s==\n", ws.formatter().createIdFormat().toString(nid), toRepository == null ? "" : toRepository);
+ getValidSession().getTerminal().out().printf("Nuts %N deployed successfully to ==%s==\n", ws.formatter().createIdFormat().toString(nid), toRepository == null ? "" : toRepository);
}
}
}
@@ -622,40 +546,6 @@ protected NutsDescriptor buildDescriptor(Object descriptor, String descSHA1) {
}
}
- @Override
- public NutsDeployCommand outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- @Override
- public NutsDeployCommand setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return this;
- }
-
- @Override
- public NutsDeployCommand json() {
- return setOutputFormat(NutsOutputFormat.JSON);
- }
-
- @Override
- public NutsDeployCommand plain() {
- return setOutputFormat(NutsOutputFormat.PLAIN);
- }
-
- @Override
- public NutsDeployCommand props() {
- return setOutputFormat(NutsOutputFormat.PROPS);
- }
-
- @Override
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
-
@Override
public NutsDeployCommand ids(String... values) {
return addIds(values);
@@ -746,27 +636,12 @@ public NutsDeployCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "-f":
- case "--force": {
- setForce(a.getBooleanValue());
- break;
- }
- case "-T":
- case "--transitive": {
- setTransitive(a.getBooleanValue());
- break;
- }
+ switch (a.strKey()) {
case "-o":
case "--offline": {
setOffline(a.getBooleanValue());
break;
}
- case "-t":
- case "--trace": {
- setTrace(a.getBooleanValue());
- break;
- }
case "-d":
case "--desc": {
setDescriptor(cmd.getValueFor(a).getString());
@@ -808,31 +683,17 @@ public NutsDeployCommand parseOptions(String... args) {
}
break;
}
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- String idOrPath = a.getString();
- if (idOrPath.indexOf('/') >= 0 || idOrPath.indexOf('\\') >= 0) {
- setContent(idOrPath);
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
} else {
- id(idOrPath);
+ String idOrPath = a.getString();
+ if (idOrPath.indexOf('/') >= 0 || idOrPath.indexOf('\\') >= 0) {
+ setContent(idOrPath);
+ } else {
+ id(idOrPath);
+ }
}
}
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsExecCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsExecCommand.java
index c2aa63b11..6c21c4035 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsExecCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsExecCommand.java
@@ -19,11 +19,12 @@
import net.vpc.app.nuts.core.util.NutsWorkspaceUtils;
/**
- *
+ *
* type: Command Class
+ *
* @author vpc
*/
-public class DefaultNutsExecCommand implements NutsExecCommand {
+public class DefaultNutsExecCommand extends NutsWorkspaceCommandBase implements NutsExecCommand {
public static final Logger LOG = Logger.getLogger(DefaultNutsExecCommand.class.getName());
private static final NutsDescriptor TEMP_DESC = new DefaultNutsDescriptorBuilder()
@@ -36,11 +37,8 @@ public class DefaultNutsExecCommand implements NutsExecCommand {
private List command;
private List executorOptions;
private Properties env;
- private DefaultNutsWorkspace ws;
- private NutsSession session;
private NutsExecutionException result;
private boolean executed;
- private boolean ask = true;
private String directory;
private PrintStream out;
private PrintStream err;
@@ -51,7 +49,7 @@ public class DefaultNutsExecCommand implements NutsExecCommand {
private NutsCommandStringFormatter commandStringFormatter;
public DefaultNutsExecCommand(DefaultNutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -86,23 +84,6 @@ public NutsExecCommand failFast(boolean failFast) {
return setFailFast(failFast);
}
- public boolean isAsk() {
- return ask;
- }
-
- public NutsExecCommand setAsk(boolean ask) {
- this.ask = ask;
- return this;
- }
-
- public NutsExecCommand ask(boolean ask) {
- return setAsk(true);
- }
-
- public NutsExecCommand ask() {
- return ask(true);
- }
-
@Override
public NutsExecCommand clearCommand() {
this.command = null;
@@ -137,30 +118,14 @@ public NutsExecCommand clearEnv() {
return this;
}
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsExecCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
- @Override
- public NutsExecCommand session(NutsSession session) {
- return setSession(session);
- }
-
@Override
public String[] getCommand() {
- return command.toArray(new String[0]);
+ return command == null ? new String[0] : command.toArray(new String[0]);
}
@Override
public String[] getExecutorOptions() {
- return executorOptions.toArray(new String[0]);
+ return executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]);
}
@Override
@@ -406,12 +371,9 @@ public NutsExecCommand run() {
@Override
public NutsExecutableInfo which() {
- if (this.session == null) {
- this.session = ws.createSession();
- }
DefaultNutsSessionTerminal terminal = new DefaultNutsSessionTerminal();
terminal.install(ws);
- terminal.setParent(session.getTerminal());
+ terminal.setParent(getValidSession().getTerminal());
if (this.in != null) {
terminal.setIn(this.in);
}
@@ -422,7 +384,7 @@ public NutsExecutableInfo which() {
if (this.out != null) {
terminal.setErr(this.out);
} else {
- terminal.setErr(session.getTerminal().out());
+ terminal.setErr(getValidSession().getTerminal().out());
}
}
terminal.out().flush();
@@ -431,15 +393,15 @@ public NutsExecutableInfo which() {
NutsExecutableImpl exec = null;
switch (executionType) {
case SYSCALL: {
- exec = new SystemExecutable(ts, executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]), session.copy().setTerminal(terminal));
+ exec = new SystemExecutable(ts, executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]), getValidSession().copy().setTerminal(terminal));
break;
}
case SPAWN: {
- exec = execEmbeddedOrExternal(ts, executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]), session.copy().setTerminal(terminal), false);
+ exec = execEmbeddedOrExternal(ts, executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]), getValidSession().copy().setTerminal(terminal), false);
break;
}
case EMBEDDED: {
- exec = execEmbeddedOrExternal(ts, executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]), session.copy().setTerminal(terminal), true);
+ exec = execEmbeddedOrExternal(ts, executorOptions == null ? new String[0] : executorOptions.toArray(new String[0]), getValidSession().copy().setTerminal(terminal), true);
break;
}
default: {
@@ -449,6 +411,7 @@ public NutsExecutableInfo which() {
return exec;
}
+ @Override
public boolean isRedirectErrorStream() {
return redirectErrorStream;
}
@@ -458,6 +421,7 @@ public NutsExecCommand redirectErrorStream() {
return setRedirectErrorStream(true);
}
+ @Override
public NutsExecCommand setRedirectErrorStream(boolean redirectErrorStream) {
this.redirectErrorStream = redirectErrorStream;
return this;
@@ -465,10 +429,10 @@ public NutsExecCommand setRedirectErrorStream(boolean redirectErrorStream) {
@Override
public NutsExecCommand copyFrom(NutsExecCommand other) {
+ super.copyFromWorkspaceCommandBase((NutsWorkspaceCommandBase) other);
addCommand(other.getCommand());
addEnv(other.getEnv());
addExecutorOptions(other.getExecutorOptions());
- setAsk(other.isAsk());
setDirectory(other.getDirectory());
setIn(other.getIn());
setOut(other.getOut());
@@ -489,10 +453,15 @@ public NutsExecCommand copy() {
public NutsExecCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
+ if (command == null) {
+ command = new ArrayList<>();
+ }
while ((a = cmd.next()) != null) {
if (a.isOption()) {
if (command.isEmpty()) {
- executorOptions.add(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ executorOptions.add(a.getString());
+ }
} else {
throw new NutsIllegalArgumentException("Unexpected option here");
}
@@ -832,7 +801,7 @@ public void execute() {
return new InternalExecutable(cmdName, args) {
@Override
public void execute() {
- session.getTerminal().fout().println(ws.getLicenseText());
+ session.getTerminal().fout().println(NutsWorkspaceExt.of(ws).getLicenseText());
}
};
}
@@ -841,7 +810,7 @@ public void execute() {
@Override
public void execute() {
if (args.length == 0) {
- session.getTerminal().fout().println(ws.getHelpText());
+ session.getTerminal().fout().println(NutsWorkspaceExt.of(ws).getHelpText());
}
for (String arg : args) {
NutsExecutableInfo w = null;
@@ -865,7 +834,7 @@ public void execute() {
return new InternalExecutable(cmdName, args) {
@Override
public void execute() {
- session.getTerminal().fout().println(ws.getWelcomeText());
+ session.getTerminal().fout().println(NutsWorkspaceExt.of(ws).getWelcomeText());
}
};
}
@@ -880,6 +849,54 @@ public void execute() {
}
};
}
+ case "which": {
+ return new InternalExecutable(cmdName, args) {
+ @Override
+ public void execute() {
+ for (String arg : this.args) {
+ PrintStream out = session.getTerminal().fout();
+ try {
+ NutsExecutableInfo p = DefaultNutsExecCommand.this.copy()
+ .session(session)
+ .clearCommand()
+ .parseOptions(arg)
+ .which();
+ boolean showDesc = false;
+ switch (p.getType()) {
+ case SYSTEM: {
+ out.printf("[[%s]] : ==system command== %s%n", arg, p.getDescription());
+ break;
+ }
+ case ALIAS: {
+ out.printf("[[%s]] : ==nuts alias== (owner %N ) : %N%n", arg,
+ p.getId() == null ? null : ws.formatter().createIdFormat().toString(p.getId()),
+ NutsCommandLine.escapeArguments(ws.config().findCommandAlias(p.getName()).getCommand()));
+ break;
+ }
+ case COMPONENT: {
+ if (p.getId() == null) {
+ throw new NutsNotFoundException(arg);
+ }
+ out.printf("[[%s]] : ==nuts component== %N%n", arg, ws.formatter().createIdFormat().toString(p.getId()), p.getDescription());
+ break;
+ }
+ case INTERNAL: {
+ out.printf("[[%s]] : ==internal command== %n", arg);
+ break;
+ }
+ }
+ if (showDesc) {
+ out.printf("\t %N%n", arg, p.getDescription());
+ }
+
+ } catch (NutsNotFoundException ex) {
+ out.printf("[[%s]] : @@not found@@%n", arg);
+ }
+ }
+
+ }
+ };
+ }
case "exec": {
return new InternalExecutable(cmdName, args) {
@Override
@@ -899,8 +916,8 @@ public void execute() {
} else if (cmdName.contains(":")) {
return ws_exec(cmdName, args, executorOptions, env, directory, failFast, session, embedded);
} else {
- NutsWorkspaceCommand command = null;
- command = ws.config().findCommandAliases(cmdName);
+ NutsWorkspaceCommandAlias command = null;
+ command = ws.config().findCommandAlias(cmdName);
if (command != null) {
NutsCommandExecOptions o = new NutsCommandExecOptions().setExecutorOptions(executorOptions).setDirectory(directory).setFailFast(failFast)
.setExecutionType(embedded ? NutsExecutionType.EMBEDDED : NutsExecutionType.SPAWN).setEnv(env);
@@ -933,9 +950,9 @@ public void execute() {
protected NutsExecutableImpl ws_exec(String commandName, String[] appArgs, String[] executorOptions, Properties env, String dir, boolean failFast, NutsSession session, boolean embedded) {
NutsDefinition def = null;
NutsId nid = ws.parser().parseId(commandName);
- def = ws.find().id(nid).session(session).setAcceptOptional(false).includeDependencies().setLenient(true).installed().getResultDefinitions().first();
+ def = ws.find().id(nid).session(session).setAcceptOptional(false).includeDependencies().latestVersions().setLenient(true).installed().getResultDefinitions().first();
if (def == null) {
- def = ws.find().id(nid).session(session).setAcceptOptional(false).includeDependencies().setLenient(false).wired().getResultDefinitions().required();
+ def = ws.find().id(nid).session(session).setAcceptOptional(false).includeDependencies().setLenient(false).wired().latestVersions().getResultDefinitions().required();
}
return new ComponentExecutable(def, commandName, appArgs, executorOptions, env, dir, failFast, session, embedded);
}
@@ -1071,12 +1088,12 @@ public String getHelpText() {
public class AliasExecutable extends AbstractExecutable {
- private NutsWorkspaceCommand command;
+ private NutsWorkspaceCommandAlias command;
private NutsCommandExecOptions o;
private NutsSession session;
private String[] args;
- public AliasExecutable(NutsWorkspaceCommand command, NutsCommandExecOptions o, NutsSession session, String[] args) {
+ public AliasExecutable(NutsWorkspaceCommandAlias command, NutsCommandExecOptions o, NutsSession session, String[] args) {
super(command.getName(), NutsExecutableType.ALIAS);
this.command = command;
this.o = o;
@@ -1128,8 +1145,8 @@ public PathComponentExecutable(String cmdName, String[] args, String[] executorO
public NutsId getId() {
NutsFetchCommand p = ws.fetch();
p.setTransitive(true);
- try (CharacterizedFile c = CoreIOUtils.characterize(ws, CoreIOUtils.createInputSource(cmdName), p, session)) {
- return c.descriptor.getId();
+ try (CharacterizedFile c = CoreIOUtils.characterize(ws, CoreIOUtils.createInputSource(cmdName), p, getValidSession())) {
+ return c.descriptor == null ? null : c.descriptor.getId();
}
}
@@ -1138,7 +1155,7 @@ public void execute() {
NutsFetchCommand p = ws.fetch();
p.setTransitive(true);
- try (CharacterizedFile c = CoreIOUtils.characterize(ws, CoreIOUtils.createInputSource(cmdName), p, session)) {
+ try (CharacterizedFile c = CoreIOUtils.characterize(ws, CoreIOUtils.createInputSource(cmdName), p, getValidSession())) {
if (c.descriptor == null) {
//this is a native file?
c.descriptor = TEMP_DESC;
@@ -1150,7 +1167,7 @@ public void execute() {
new NutsContent(c.getContentPath(), false, c.temps.size() > 0),
null
);
- ws_exec(nutToRun, cmdName, args, executorOptions, env, directory, failFast, session, embedded);
+ ws_exec(nutToRun, cmdName, args, executorOptions, env, directory, failFast, getValidSession(), embedded);
}
}
@@ -1235,12 +1252,28 @@ public class SystemExecutable extends AbstractExecutable {
private String[] cmd;
private String[] executorOptions;
private NutsSession session;
+ private boolean showCommand = false;
+ private boolean failFast = true;
public SystemExecutable(String[] cmd, String[] executorOptions, NutsSession session) {
super(cmd[0], NutsExecutableType.SYSTEM);
this.cmd = cmd;
- this.executorOptions = executorOptions;
+ this.executorOptions = executorOptions == null ? new String[0] : executorOptions;
this.session = session;
+ NutsCommandLine cmdLine = new NutsCommandLine(this.executorOptions);
+ while (cmdLine.hasNext()) {
+ NutsCommandArg a = cmdLine.next();
+ switch (a.strKey()) {
+ case "--show-command": {
+ showCommand = a.getBooleanValue();
+ break;
+ }
+ case "--fail-fast": {
+ failFast = a.getBooleanValue();
+ break;
+ }
+ }
+ }
}
@Override
@@ -1257,7 +1290,7 @@ public void execute() {
CoreIOUtils.execAndWait(ws, cmd,
e2,
ws.io().path(directory),
- session.getTerminal(), true, true);
+ session.getTerminal(), showCommand, failFast);
}
@Override
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFetchCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFetchCommand.java
index 9d140bc13..3ca72bd6a 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFetchCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFetchCommand.java
@@ -29,11 +29,10 @@
public class DefaultNutsFetchCommand extends DefaultNutsQueryBaseOptions implements NutsFetchCommand {
public static final Logger LOG = Logger.getLogger(DefaultNutsFetchCommand.class.getName());
- private final DefaultNutsWorkspace ws;
private NutsId id;
- public DefaultNutsFetchCommand(DefaultNutsWorkspace ws) {
- this.ws = ws;
+ public DefaultNutsFetchCommand(NutsWorkspace ws) {
+ super(ws);
}
@Override
@@ -198,7 +197,7 @@ public NutsId getId() {
@Override
public NutsFetchCommand copyFrom(NutsFetchCommand other) {
- super.copyFrom0((DefaultNutsQueryBaseOptions) other);
+ super.copyFromDefaultNutsQueryBaseOptions((DefaultNutsQueryBaseOptions) other);
if (other != null) {
NutsFetchCommand o = other;
this.id = o.getId();
@@ -492,126 +491,14 @@ public NutsFetchCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "--lenient": {
- this.setLenient(a.getBooleanValue());
- break;
- }
- case "--trace": {
- this.setTrace(a.getBooleanValue());
- break;
- }
- case "--main-only": {
- this.includeDependencies(!a.getBooleanValue());
- break;
- }
- case "--main-and-dependencies": {
- this.includeDependencies(a.getBooleanValue());
- break;
- }
- case "--dependencies": {
- this.includeDependencies(a.getBooleanValue());
- break;
- }
- case "--repo": {
- this.addRepository(cmd.getValueFor(a).getString());
- break;
- }
- case "-s":
- case "--scope": {
- this.addScope(NutsDependencyScope.valueOf(cmd.getValueFor(a).getString().toUpperCase().replace("-", "_")));
- break;
- }
- case "-f":
- case "--fetch": {
- this.setFetchStratery(NutsFetchStrategy.valueOf(cmd.getValueFor(a).getString().toUpperCase().replace("-", "_")));
- break;
- }
- case "--anywhere": {
- this.setFetchStratery(NutsFetchStrategy.ANYWHERE);
- break;
- }
- case "--installed": {
- this.setFetchStratery(NutsFetchStrategy.INSTALLED);
- break;
- }
- case "--local": {
- this.setFetchStratery(NutsFetchStrategy.LOCAL);
- break;
- }
- case "--offline": {
- this.setFetchStratery(NutsFetchStrategy.OFFLINE);
- break;
- }
- case "--online": {
- this.setFetchStratery(NutsFetchStrategy.ONLINE);
- break;
- }
- case "--remote": {
- this.setFetchStratery(NutsFetchStrategy.REMOTE);
- break;
- }
- case "--wired": {
- this.setFetchStratery(NutsFetchStrategy.WIRED);
- break;
- }
- case "--optional": {
- NutsCommandArg v = cmd.getValueFor(a);
- if (CoreCommonUtils.isYes(v.getString())) {
- this.setAcceptOptional(true);
- } else if (CoreCommonUtils.isNo(v.getString())) {
- this.setAcceptOptional(false);
- } else if (CoreCommonUtils.isNo(v.getString())) {
- this.setAcceptOptional(null);
- }
- break;
- }
- case "--cached": {
- this.setCached(a.getBooleanValue());
- break;
- }
- case "--effective": {
- this.setEffective(a.getBooleanValue());
- break;
- }
- case "--indexed": {
- this.setIndexed(a.getBooleanValue());
- break;
- }
- case "--content": {
- this.setIncludeContent(a.getBooleanValue());
- break;
- }
- case "--install-info": {
- this.setIncludeInstallInformation(a.getBooleanValue());
- break;
- }
- case "--location": {
- String location = cmd.getValueFor(a).getString();
- this.setLocation(CoreStringUtils.isBlank(location) ? null : Paths.get(location));
- break;
- }
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
+ switch (a.strKey()) {
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("find: Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFindCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFindCommand.java
index 8df18ab66..3dc27e758 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFindCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsFindCommand.java
@@ -50,26 +50,19 @@
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.nio.file.Paths;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import net.vpc.app.nuts.core.filters.DefaultNutsIdMultiFilter;
-import net.vpc.app.nuts.core.util.CanonicalBuilder;
import static net.vpc.app.nuts.core.util.CoreNutsUtils.And;
import static net.vpc.app.nuts.core.util.CoreNutsUtils.simplify;
-import net.vpc.app.nuts.core.util.DefaultNutsFindTraceFormatJson;
-import net.vpc.app.nuts.core.util.DefaultNutsFindTraceFormatPlain;
-import net.vpc.app.nuts.core.util.DefaultNutsFindTraceFormatProps;
import net.vpc.app.nuts.core.util.NutsWorkspaceHelper;
import net.vpc.app.nuts.core.util.NutsWorkspaceUtils;
-import static net.vpc.app.nuts.core.util.NutsWorkspaceUtils.getIdFormat;
import net.vpc.app.nuts.core.util.common.CoreCommonUtils;
import net.vpc.app.nuts.core.util.common.IteratorBuilder;
import net.vpc.app.nuts.core.util.common.IteratorUtils;
-import net.vpc.app.nuts.core.util.io.CoreIOUtils;
/**
* @author vpc
@@ -85,14 +78,13 @@ public class DefaultNutsFindCommand extends DefaultNutsQueryBaseOptions arch = new ArrayList<>();
private final List ids = new ArrayList<>();
private final List scripts = new ArrayList<>();
private final List packaging = new ArrayList<>();
- public DefaultNutsFindCommand(DefaultNutsWorkspace ws) {
- this.ws = ws;
+ public DefaultNutsFindCommand(NutsWorkspace ws) {
+ super(ws);
}
@Override
@@ -298,13 +290,13 @@ public NutsFindCommand copy() {
@Override
public NutsFindCommand copyFrom(NutsFetchCommand other) {
- super.copyFrom0((DefaultNutsQueryBaseOptions) other);
+ super.copyFromDefaultNutsQueryBaseOptions((DefaultNutsQueryBaseOptions) other);
return this;
}
@Override
public NutsFindCommand copyFrom(NutsFindCommand other) {
- super.copyFrom0((DefaultNutsQueryBaseOptions) other);
+ super.copyFromDefaultNutsQueryBaseOptions((DefaultNutsQueryBaseOptions) other);
if (other != null) {
NutsFindCommand o = other;
this.idComparator = o.getSortIdComparator();
@@ -371,6 +363,11 @@ public NutsFindCommand allVersions() {
return setAllVersions(true);
}
+ @Override
+ public NutsFindCommand setLatestVersions(boolean enable) {
+ return setAllVersions(!enable);
+ }
+
@Override
public NutsFindCommand allVersions(boolean includeAllVersions) {
return setAllVersions(includeAllVersions);
@@ -633,14 +630,13 @@ private DefaultNutsSearch build() {
goodIds.toArray(new String[0]),
_repositoryFilter,
_idFilter, _descriptorFilter,
- ws,
toFetch()
);
}
@Override
public NutsFetchCommand toFetch() {
- return new DefaultNutsFetchCommand(ws).copyFrom0((DefaultNutsQueryBaseOptions) this).setSession(evalSession(true));
+ return new DefaultNutsFetchCommand(ws).copyFromDefaultNutsQueryBaseOptions((DefaultNutsQueryBaseOptions) this).setSession(evalSession(true));
}
@Override
@@ -695,12 +691,7 @@ private Collection applyTraceDecoratorCollectionOfNutsId(Collection applyTraceDecoratorIterOfNutsId(Iterator curr, boolean trace) {
- if (trace) {
- final PrintStream out = NutsWorkspaceUtils.validateSession(ws, getSession()).getTerminal().getOut();
- return new TraceIterator(curr, ws, out, getOutputFormat(), getTraceFormat());
- } else {
- return curr;
- }
+ return trace ? NutsWorkspaceUtils.decorateTrace(ws, curr, getSession(), getOutputFormat(), getTraceFormat()) : curr;
}
private NutsCollectionFindResult applyVersionFlagFilters(Iterator curr, boolean trace) {
@@ -963,8 +954,7 @@ public NutsDefinition next() {
if (!trace) {
return ii;
}
- final PrintStream out = NutsWorkspaceUtils.validateSession(ws, getSession()).getTerminal().getOut();
- return new TraceIterator(ii, ws, out, getOutputFormat(),getTraceFormat());
+ return NutsWorkspaceUtils.decorateTrace(ws, ii, getSession(), getOutputFormat(), getTraceFormat());
}
}
@@ -1005,7 +995,8 @@ public Iterator iterator() {
NutsWorkspaceHelper.createNoRepositorySession(session, mode,
search.getOptions())
).simplify();
- return ws.getInstalledRepository().findVersions(nutsId1, filter);
+ return NutsWorkspaceExt.of(ws)
+ .getInstalledRepository().findVersions(nutsId1, filter);
}
}).safeIgnore().iterator());
} else {
@@ -1105,23 +1096,12 @@ public NutsFindCommand run() {
return this;
}
-
-
@Override
public NutsFindCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "--lenient": {
- this.setLenient(a.getBooleanValue());
- break;
- }
- case "-t":
- case "--trace": {
- this.setTrace(a.getBooleanValue());
- break;
- }
+ switch (a.strKey()) {
case "--all-versions": {
this.setAllVersions(a.getBooleanValue());
break;
@@ -1167,11 +1147,6 @@ public NutsFindCommand parseOptions(String... args) {
this.dependenciesOnly();
break;
}
- case "-r":
- case "--repository": {
- this.addRepository(cmd.getValueFor(a).getString());
- break;
- }
case "--arch": {
this.addArch(cmd.getValueFor(a).getString());
break;
@@ -1188,101 +1163,13 @@ public NutsFindCommand parseOptions(String... args) {
this.addId(cmd.getValueFor(a).getString());
break;
}
- case "--scope": {
- this.addScope(NutsDependencyScope.valueOf(cmd.getValueFor(a).getString().toUpperCase().replace("-", "_")));
- break;
- }
- case "-f":
- case "--fetch": {
- this.setFetchStratery(NutsFetchStrategy.valueOf(cmd.getValueFor(a).getString().toUpperCase().replace("-", "_")));
- break;
- }
- case "--anywhere": {
- this.setFetchStratery(NutsFetchStrategy.ANYWHERE);
- break;
- }
- case "--installed": {
- this.setFetchStratery(NutsFetchStrategy.INSTALLED);
- break;
- }
- case "--local": {
- this.setFetchStratery(NutsFetchStrategy.LOCAL);
- break;
- }
- case "--offline": {
- this.setFetchStratery(NutsFetchStrategy.OFFLINE);
- break;
- }
- case "--online": {
- this.setFetchStratery(NutsFetchStrategy.ONLINE);
- break;
- }
- case "--remote": {
- this.setFetchStratery(NutsFetchStrategy.REMOTE);
- break;
- }
- case "--wired": {
- this.setFetchStratery(NutsFetchStrategy.WIRED);
- break;
- }
- case "--optional": {
- NutsCommandArg v = cmd.getValueFor(a);
- if (CoreCommonUtils.isYes(v.getString())) {
- this.setAcceptOptional(true);
- } else if (CoreCommonUtils.isNo(v.getString())) {
- this.setAcceptOptional(false);
- } else if (CoreCommonUtils.isNo(v.getString())) {
- this.setAcceptOptional(null);
- }
- break;
- }
- case "--cached": {
- this.setCached(a.getBooleanValue());
- break;
- }
- case "--effective": {
- this.setEffective(a.getBooleanValue());
- break;
- }
- case "--indexed": {
- this.setIndexed(a.getBooleanValue());
- break;
- }
- case "--content": {
- this.setIncludeContent(a.getBooleanValue());
- break;
- }
- case "--install-info": {
- this.setIncludeInstallInformation(a.getBooleanValue());
- break;
- }
- case "--location": {
- String location = cmd.getValueFor(a).getString();
- this.setLocation(CoreStringUtils.isBlank(location) ? null : Paths.get(location));
- break;
- }
-
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("find: Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
@@ -1290,61 +1177,4 @@ public NutsFindCommand parseOptions(String... args) {
return this;
}
- public static class TraceIterator implements Iterator {
-
- Iterator curr;
- NutsWorkspace ws;
- NutsTraceFormat conv;
- PrintStream out;
- NutsOutputFormat format;
- long count = 0;
-
- public TraceIterator(Iterator curr, NutsWorkspace ws, PrintStream out, NutsOutputFormat format, NutsTraceFormat conv) {
- this.curr = curr;
- this.ws = ws;
- this.out = out;
- this.conv = conv;
- this.format = format;
- if (this.conv == null) {
- switch (this.format) {
- case JSON: {
- this.conv = new DefaultNutsFindTraceFormatJson();
- break;
- }
- case PROPS: {
- this.conv = new DefaultNutsFindTraceFormatProps();
- break;
- }
- case PLAIN: {
- this.conv = new DefaultNutsFindTraceFormatPlain();
- break;
- }
- default: {
- throw new NutsUnsupportedOperationException("Unsupported " + format);
- }
- }
- }
- }
-
- @Override
- public boolean hasNext() {
- boolean p = curr.hasNext();
- if (!p) {
- conv.formatEnd(count, out, ws);
- }
- return p;
- }
-
- @Override
- public T next() {
- T n = curr.next();
- if (count == 0) {
- conv.formatStart(out, ws);
- } else {
- conv.formatElement(n, count, out, ws);
- }
- count++;
- return n;
- }
- };
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsInstallCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsInstallCommand.java
index bad4941d2..2f951f11f 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsInstallCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsInstallCommand.java
@@ -33,26 +33,21 @@
/**
*
* type: Command Class
+ *
* @author vpc
*/
-public class DefaultNutsInstallCommand implements NutsInstallCommand {
+public class DefaultNutsInstallCommand extends NutsWorkspaceCommandBase implements NutsInstallCommand {
public static final Logger LOG = Logger.getLogger(DefaultNutsInstallCommand.class.getName());
- private boolean ask = true;
- private boolean trace = true;
- private boolean force = false;
private boolean defaultVersion = true;
private boolean includecompanions = false;
private List args;
private final List ids = new ArrayList<>();
- private NutsSession session;
- private final NutsWorkspace ws;
private NutsDefinition[] result;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
public DefaultNutsInstallCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -96,39 +91,6 @@ public NutsInstallCommand addIds(NutsId... ids) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsInstallCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public NutsInstallCommand setForce(boolean forceInstall) {
- this.force = forceInstall;
- return this;
- }
-
- @Override
- public boolean isAsk() {
- return ask;
- }
-
- @Override
- public NutsInstallCommand setAsk(boolean ask) {
- this.ask = ask;
- return this;
- }
-
@Override
public NutsInstallCommand removeId(NutsId id) {
if (id != null) {
@@ -163,26 +125,6 @@ public NutsInstallCommand clearArgs() {
return this;
}
- @Override
- public NutsInstallCommand ask() {
- return setAsk(true);
- }
-
- @Override
- public NutsInstallCommand ask(boolean ask) {
- return setAsk(ask);
- }
-
- @Override
- public NutsInstallCommand force() {
- return setForce(force);
- }
-
- @Override
- public NutsInstallCommand force(boolean force) {
- return setForce(force);
- }
-
@Override
public String[] getArgs() {
return args == null ? new String[0] : args.toArray(new String[0]);
@@ -221,17 +163,6 @@ public NutsInstallCommand addArgs(Collection args) {
return this;
}
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsInstallCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
@Override
public NutsId[] getIds() {
return ids == null ? new NutsId[0] : ids.toArray(new NutsId[0]);
@@ -273,21 +204,6 @@ public boolean isDefaultVersion() {
return defaultVersion;
}
- @Override
- public NutsInstallCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public NutsInstallCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
- @Override
- public NutsInstallCommand trace() {
- return setTrace(true);
- }
-
@Override
public NutsInstallCommand setDefaultVersion(boolean defaultVersion) {
this.defaultVersion = defaultVersion;
@@ -319,52 +235,26 @@ public NutsInstallCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "-f":
- case "--force": {
- this.setForce(a.getBooleanValue());
- break;
- }
- case "-t":
- case "--trace": {
- this.setTrace(a.getBooleanValue());
- break;
- }
- case "-c":
- case "--companions":
- {
+ switch (a.strKey()) {
+ case "-c":
+ case "--companions": {
this.setIncludeCompanions(a.getBooleanValue());
break;
}
- case "-g":
- case "--args":
- {
+ case "-g":
+ case "--args": {
while ((a = cmd.next()) != null) {
this.addArg(a.getString());
}
break;
}
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
@@ -481,38 +371,4 @@ public NutsDefinition[] getResult() {
}
return result;
}
-
- @Override
- public DefaultNutsInstallCommand outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- @Override
- public DefaultNutsInstallCommand setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return this;
- }
-
- @Override
- public DefaultNutsInstallCommand json() {
- return setOutputFormat(NutsOutputFormat.JSON);
- }
-
- @Override
- public DefaultNutsInstallCommand plain() {
- return setOutputFormat(NutsOutputFormat.PLAIN);
- }
-
- @Override
- public DefaultNutsInstallCommand props() {
- return setOutputFormat(NutsOutputFormat.PROPS);
- }
-
- @Override
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsPushCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsPushCommand.java
index 506cd1ac7..df1aa9593 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsPushCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsPushCommand.java
@@ -41,22 +41,16 @@
*
* @author vpc
*/
-public class DefaultNutsPushCommand implements NutsPushCommand {
+public class DefaultNutsPushCommand extends NutsWorkspaceCommandBase implements NutsPushCommand {
- private boolean ask = true;
- private boolean trace = true;
- private boolean force = false;
private boolean offline = false;
private List args;
private final List ids = new ArrayList<>();
private List frozenIds;
- private NutsSession session;
- private final NutsWorkspace ws;
private String repository;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
public DefaultNutsPushCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -180,39 +174,6 @@ public NutsPushCommand addFrozenIds(NutsId... ids) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsPushCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public NutsPushCommand setForce(boolean forceInstall) {
- this.force = forceInstall;
- return this;
- }
-
- @Override
- public boolean isAsk() {
- return ask;
- }
-
- @Override
- public NutsPushCommand setAsk(boolean ask) {
- this.ask = ask;
- return this;
- }
-
@Override
public String[] getArgs() {
return args == null ? new String[0] : args.toArray(new String[0]);
@@ -251,17 +212,6 @@ public NutsPushCommand addArgs(Collection args) {
return this;
}
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsPushCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
@Override
public NutsId[] getIds() {
return ids == null ? new NutsId[0] : ids.toArray(new NutsId[0]);
@@ -426,41 +376,6 @@ public NutsPushCommand clearFrozenIds() {
return this;
}
- @Override
- public NutsPushCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public NutsPushCommand ask() {
- return ask(true);
- }
-
- @Override
- public NutsPushCommand ask(boolean enable) {
- return setAsk(enable);
- }
-
- @Override
- public NutsPushCommand force() {
- return force(true);
- }
-
- @Override
- public NutsPushCommand force(boolean enable) {
- return setForce(enable);
- }
-
- @Override
- public NutsPushCommand trace() {
- return trace(true);
- }
-
- @Override
- public NutsPushCommand trace(boolean enable) {
- return setTrace(enable);
- }
-
@Override
public NutsPushCommand offline() {
return offline(true);
@@ -471,56 +386,12 @@ public NutsPushCommand offline(boolean enable) {
return setOffline(enable);
}
- @Override
- public NutsPushCommand outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- @Override
- public NutsPushCommand setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return this;
- }
-
- @Override
- public NutsPushCommand json() {
- return setOutputFormat(NutsOutputFormat.JSON);
- }
-
- @Override
- public NutsPushCommand plain() {
- return setOutputFormat(NutsOutputFormat.PLAIN);
- }
-
- @Override
- public NutsPushCommand props() {
- return setOutputFormat(NutsOutputFormat.PROPS);
- }
-
- @Override
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
-
@Override
public NutsPushCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "-f":
- case "--force": {
- setForce(a.getBooleanValue());
- break;
- }
- case "-k":
- case "--ask": {
- setAsk(a.getBooleanValue());
- break;
- }
+ switch (a.strKey()) {
case "-o":
case "--offline": {
setOffline(a.getBooleanValue());
@@ -546,32 +417,13 @@ public NutsPushCommand parseOptions(String... args) {
}
break;
}
- case "-t":
- case "--trace": {
- setTrace(a.getBooleanValue());
- break;
- }
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQueryBaseOptions.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQueryBaseOptions.java
index 32c1f4658..039322228 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQueryBaseOptions.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQueryBaseOptions.java
@@ -6,30 +6,33 @@
package net.vpc.app.nuts.core;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
+import net.vpc.app.nuts.NutsCommandArg;
+import net.vpc.app.nuts.NutsCommandLine;
import net.vpc.app.nuts.NutsDependencyScope;
-import net.vpc.app.nuts.NutsSession;
import net.vpc.app.nuts.NutsFetchStrategy;
-import net.vpc.app.nuts.NutsOutputFormat;
-import net.vpc.app.nuts.NutsTraceFormat;
+import net.vpc.app.nuts.NutsWorkspace;
+import net.vpc.app.nuts.core.util.common.CoreCommonUtils;
+import net.vpc.app.nuts.core.util.common.CoreStringUtils;
/**
*
* @author vpc
* @param
*/
-public class DefaultNutsQueryBaseOptions {
+public abstract class DefaultNutsQueryBaseOptions extends NutsWorkspaceCommandBase {
+ private boolean lenient = false;
private boolean transitive = true;
private boolean cached = true;
private Boolean indexed = null;
private NutsFetchStrategy mode = null;
- protected NutsSession session;
private Boolean acceptOptional = null;
private Set scope = EnumSet.noneOf(NutsDependencyScope.class);
private boolean includeContent = true;
@@ -37,18 +40,18 @@ public class DefaultNutsQueryBaseOptions {
private boolean effective = false;
private boolean includeInstallInfo = true;
private Path location = null;
- private boolean trace = false;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
- private boolean lenient = false;
private final List repos = new ArrayList<>();
- protected NutsTraceFormat[] traceFormats = new NutsTraceFormat[NutsOutputFormat.values().length];
+
+ public DefaultNutsQueryBaseOptions(NutsWorkspace ws) {
+ super(ws);
+ }
//@Override
- protected T copyFrom0(DefaultNutsQueryBaseOptions other) {
+ protected T copyFromDefaultNutsQueryBaseOptions(DefaultNutsQueryBaseOptions other) {
if (other != null) {
+ super.copyFromWorkspaceCommandBase(other);
this.acceptOptional = other.getAcceptOptional();
this.lenient = other.isLenient();
- this.session = other.getSession();
this.mode = other.getFetchStrategy();
this.indexed = other.getIndexed();
this.includeContent = other.isIncludeContent();
@@ -62,38 +65,12 @@ protected T copyFrom0(DefaultNutsQueryBaseOptions other) {
this.transitive = other.isTransitive();
this.cached = other.isCached();
this.location = other.getLocation();
- System.arraycopy(other.traceFormats, 0, this.traceFormats, 0, NutsOutputFormat.values().length);
this.repos.clear();
this.repos.addAll(Arrays.asList(other.getRepositories()));
}
return (T) this;
}
- public NutsTraceFormat getTraceFormat() {
- return traceFormats[getOutputFormat().ordinal()];
- }
-
- public T unsetTraceFormat(NutsOutputFormat f) {
- traceFormats[f.ordinal()] = null;
- return (T) this;
- }
-
- public T traceFormat(NutsTraceFormat traceFormat) {
- return setTraceFormat(traceFormat);
- }
-
- public T setTraceFormat(NutsTraceFormat f) {
- if (f == null) {
- throw new NullPointerException();
- }
- traceFormats[f.getSupportedFormat().ordinal()] = f;
- return (T) this;
- }
-
- public NutsTraceFormat[] getTraceFormats() {
- return Arrays.copyOf(traceFormats, traceFormats.length);
- }
-
//@Override
public boolean isCached() {
return cached;
@@ -251,22 +228,6 @@ public T setIncludeOptional(boolean includeOptional) {
return setAcceptOptional(includeOptional ? null : false);
}
- //@Override
- public NutsSession getSession() {
- return session;
- }
-
- //@Override
- public T session(NutsSession session) {
- return setSession(session);
- }
-
- //@Override
- public T setSession(NutsSession session) {
- this.session = session;
- return (T) this;
- }
-
//@Override
public T scopes(Collection scope) {
return DefaultNutsQueryBaseOptions.this.addScopes(scope);
@@ -441,39 +402,6 @@ public T setDefaultLocation() {
return (T) this;
}
- public T outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- public T setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return (T) this;
- }
-
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
-
- public boolean isTrace() {
- return trace;
- }
-
- public T setTrace(boolean trace) {
- this.trace = trace;
- return (T) this;
- }
-
- public T trace(boolean trace) {
- return setTrace(trace);
- }
-
- public T trace() {
- return trace(true);
- }
-
public boolean isLenient() {
return lenient;
}
@@ -536,4 +464,109 @@ public String[] getRepositories() {
return repos.toArray(new String[0]);
}
+ @Override
+ protected boolean parseOption(NutsCommandArg a, NutsCommandLine cmd) {
+ if (super.parseOption(a, cmd)) {
+ return true;
+ }
+ switch (a.strKey()) {
+ case "--lenient": {
+ this.setLenient(a.getBooleanValue());
+ return true;
+ }
+ case "-r":
+ case "--repository": {
+ this.addRepository(cmd.getValueFor(a).getString());
+ return true;
+ }
+
+ case "--scope": {
+ this.addScope(NutsDependencyScope.valueOf(cmd.getValueFor(a).getString().toUpperCase().replace("-", "_")));
+ return true;
+ }
+ case "-f":
+ case "--fetch": {
+ this.setFetchStratery(NutsFetchStrategy.valueOf(cmd.getValueFor(a).getString().toUpperCase().replace("-", "_")));
+ return true;
+ }
+ case "--main-only": {
+ this.includeDependencies(!a.getBooleanValue());
+ break;
+ }
+ case "--main-and-dependencies": {
+ this.includeDependencies(a.getBooleanValue());
+ break;
+ }
+ case "--dependencies": {
+ this.includeDependencies(a.getBooleanValue());
+ break;
+ }
+ case "--anywhere": {
+ this.setFetchStratery(NutsFetchStrategy.ANYWHERE);
+ return true;
+ }
+ case "--installed": {
+ this.setFetchStratery(NutsFetchStrategy.INSTALLED);
+ return true;
+ }
+ case "--local": {
+ this.setFetchStratery(NutsFetchStrategy.LOCAL);
+ return true;
+ }
+ case "--offline": {
+ this.setFetchStratery(NutsFetchStrategy.OFFLINE);
+ return true;
+ }
+ case "--online": {
+ this.setFetchStratery(NutsFetchStrategy.ONLINE);
+ return true;
+ }
+ case "--remote": {
+ this.setFetchStratery(NutsFetchStrategy.REMOTE);
+ return true;
+ }
+ case "--wired": {
+ this.setFetchStratery(NutsFetchStrategy.WIRED);
+ return true;
+ }
+ case "--optional": {
+ NutsCommandArg v = cmd.getValueFor(a);
+ if (CoreCommonUtils.isYes(v.getString())) {
+ this.setAcceptOptional(true);
+ } else if (CoreCommonUtils.isNo(v.getString())) {
+ this.setAcceptOptional(false);
+ } else if (CoreCommonUtils.isNo(v.getString())) {
+ this.setAcceptOptional(null);
+ }
+ return true;
+ }
+ case "--cached": {
+ this.setCached(a.getBooleanValue());
+ return true;
+ }
+ case "--effective": {
+ this.setEffective(a.getBooleanValue());
+ return true;
+ }
+ case "--indexed": {
+ this.setIndexed(a.getBooleanValue());
+ return true;
+ }
+ case "--content": {
+ this.setIncludeContent(a.getBooleanValue());
+ return true;
+ }
+ case "--install-info": {
+ this.setIncludeInstallInformation(a.getBooleanValue());
+ return true;
+ }
+ case "--location": {
+ String location = cmd.getValueFor(a).getString();
+ this.setLocation(CoreStringUtils.isBlank(location) ? null : Paths.get(location));
+ return true;
+ }
+ }
+ return false;
+ }
+
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQuestionExecutor.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQuestionExecutor.java
index 5398225c7..1e4c491db 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQuestionExecutor.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsQuestionExecutor.java
@@ -7,10 +7,10 @@
public class DefaultNutsQuestionExecutor {
- private NutsQuestion question;
- private NutsTerminal terminal;
- private PrintStream out;
- private NutsWorkspace ws;
+ private final NutsQuestion question;
+ private final NutsTerminal terminal;
+ private final PrintStream out;
+ private final NutsWorkspace ws;
public DefaultNutsQuestionExecutor(NutsWorkspace ws, NutsQuestion question, NutsTerminal terminal, PrintStream out) {
this.ws = ws;
@@ -32,7 +32,7 @@ public T execute() {
p = DefaultNutsResponseParser.INSTANCE;
}
Object[] acceptedValues = question.getAcceptedValues();
- if (acceptedValues != null && acceptedValues.length > 0) {
+ if (acceptedValues == null) {
acceptedValues = p.getDefaultAcceptedValues(question.getValueType());
}
boolean first = true;
@@ -44,7 +44,7 @@ public T execute() {
} else {
out.print(", ");
}
- out.printf("default is [[%s]]", question.getDefautValue());
+ out.printf("default is [[%s]]", p.format(question.getDefautValue()));
}
if (acceptedValues != null && acceptedValues.length > 0) {
@@ -54,7 +54,15 @@ public T execute() {
} else {
out.print(", ");
}
- out.printf("accepts [[%s]]", Arrays.toString(acceptedValues));
+ StringBuilder sb=new StringBuilder();
+ for (int i = 0; i < acceptedValues.length; i++) {
+ Object acceptedValue = acceptedValues[i];
+ if(i>0){
+ sb.append(", ");
+ }
+ sb.append(p.format(acceptedValue));
+ }
+ out.printf("accepts [[%s]]", sb.toString());
}
if (!first) {
out.print("\\)");
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsRemoveUserCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsRemoveUserCommand.java
index 7cba08263..516270a87 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsRemoveUserCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsRemoveUserCommand.java
@@ -5,10 +5,12 @@
*/
package net.vpc.app.nuts.core;
+import net.vpc.app.nuts.NutsCommandArg;
+import net.vpc.app.nuts.NutsCommandLine;
+import net.vpc.app.nuts.NutsIllegalArgumentException;
import net.vpc.app.nuts.core.spi.NutsWorkspaceConfigManagerExt;
import net.vpc.app.nuts.NutsRemoveUserCommand;
import net.vpc.app.nuts.NutsRepository;
-import net.vpc.app.nuts.NutsSession;
import net.vpc.app.nuts.NutsWorkspace;
import net.vpc.app.nuts.core.spi.NutsRepositoryConfigManagerExt;
@@ -16,19 +18,17 @@
*
* @author vpc
*/
-public class DefaultNutsRemoveUserCommand implements NutsRemoveUserCommand {
+public class DefaultNutsRemoveUserCommand extends NutsWorkspaceCommandBase implements NutsRemoveUserCommand {
- private boolean trace = true;
- private NutsSession session;
- private NutsWorkspace ws;
private NutsRepository repo;
private String login;
public DefaultNutsRemoveUserCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
public DefaultNutsRemoveUserCommand(NutsRepository repo) {
+ super(repo.getWorkspace());
this.repo = repo;
}
@@ -48,43 +48,6 @@ public NutsRemoveUserCommand setLogin(String login) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsRemoveUserCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
- @Override
- public NutsRemoveUserCommand trace() {
- return trace(true);
- }
-
- @Override
- public NutsRemoveUserCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsRemoveUserCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public NutsRemoveUserCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
public NutsRemoveUserCommand run() {
if (repo != null) {
NutsRepositoryConfigManagerExt.of(repo.config()).removeUser(login);
@@ -93,4 +56,23 @@ public NutsRemoveUserCommand run() {
}
return this;
}
+
+ public NutsRemoveUserCommand parseOptions(String... args) {
+ NutsCommandLine cmd = new NutsCommandLine(args);
+ NutsCommandArg a;
+ while ((a = cmd.next()) != null) {
+ switch (a.strKey()) {
+ default: {
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ //id(a.getString());
+ }
+ }
+ }
+ }
+ }
+ return this;
+ }
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsResponseParser.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsResponseParser.java
index 948b4d349..77d3bbebb 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsResponseParser.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsResponseParser.java
@@ -1,12 +1,14 @@
package net.vpc.app.nuts.core;
+import net.vpc.app.nuts.NutsCommandArg;
import net.vpc.app.nuts.NutsIllegalArgumentException;
import net.vpc.app.nuts.NutsResponseParser;
import net.vpc.app.nuts.NutsUnsupportedArgumentException;
public class DefaultNutsResponseParser implements NutsResponseParser {
- public static final NutsResponseParser INSTANCE=new DefaultNutsResponseParser();
-
+
+ public static final NutsResponseParser INSTANCE = new DefaultNutsResponseParser();
+
@Override
public Object parse(Object response, Class type) {
if (response == null) {
@@ -15,16 +17,16 @@ public Object parse(Object response, Class type) {
if (type.isInstance(response)) {
return response;
}
- if(type.isEnum()){
+ if (type.isEnum()) {
String s = String.valueOf(response).trim();
- if(s.isEmpty()){
+ if (s.isEmpty()) {
return null;
}
try {
return Enum.valueOf(type, s);
- }catch (Exception ex){
+ } catch (Exception ex) {
for (Object enumConstant : type.getEnumConstants()) {
- if(enumConstant.toString().equalsIgnoreCase(s)){
+ if (enumConstant.toString().equalsIgnoreCase(s.replace("-", "_"))) {
return enumConstant;
}
}
@@ -53,37 +55,26 @@ public Object parse(Object response, Class type) {
}
case "boolean":
case "java.lang.Boolean": {
- if(!(response instanceof String)){
- response=String.valueOf(response);
+ if (!(response instanceof String)) {
+ response = String.valueOf(response);
}
String sReponse = response.toString();
- if(
- "y".equalsIgnoreCase(sReponse)
- ||"yes".equalsIgnoreCase(sReponse)
- ||"t".equalsIgnoreCase(sReponse)
- ||"true".equalsIgnoreCase(sReponse)
- ){
- return true;
- }
- if(
- "n".equalsIgnoreCase(sReponse)
- ||"no".equalsIgnoreCase(sReponse)
- ||"f".equalsIgnoreCase(sReponse)
- ||"false".equalsIgnoreCase(sReponse)
- ){
- return false;
+ NutsCommandArg a = new NutsCommandArg(sReponse);
+ if (!a.isBoolean()) {
+ throw new NutsIllegalArgumentException("Invalid response " + sReponse);
}
- throw new NutsIllegalArgumentException("Invalid response "+sReponse);
+ return a.getBoolean();
}
- default:{
- throw new NutsUnsupportedArgumentException("Unsupported type "+type.getName());
+
+ default: {
+ throw new NutsUnsupportedArgumentException("Unsupported type " + type.getName());
}
}
}
@Override
public Object[] getDefaultAcceptedValues(Class type) {
- if(type.isEnum()){
+ if (type.isEnum()) {
return type.getEnumConstants();
}
switch (type.getName()) {
@@ -108,11 +99,20 @@ public Object[] getDefaultAcceptedValues(Class type) {
}
case "boolean":
case "java.lang.Boolean": {
- return new Object[]{"y","n"};
+ return new Object[]{true, false};
}
- default:{
- throw new NutsUnsupportedArgumentException("Unsupported type "+type.getName());
+ default: {
+ throw new NutsUnsupportedArgumentException("Unsupported type " + type.getName());
}
}
}
+
+ @Override
+ public String format(Object value) {
+ if (value instanceof Boolean) {
+ return ((Boolean) value) ? "y" : "n";
+ }
+ return String.valueOf(value);
+ }
+
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsSearch.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsSearch.java
index 6e1964bbf..2f47ac0b5 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsSearch.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsSearch.java
@@ -8,15 +8,12 @@ public class DefaultNutsSearch {
private final NutsIdFilter idFilter;
private final NutsDescriptorFilter descriptorFilter;
private final String[] ids;
- private final DefaultNutsWorkspace ws;
private final NutsFetchCommand options;
public DefaultNutsSearch(String[] ids, NutsRepositoryFilter repositoryFilter, NutsIdFilter idFilter,
NutsDescriptorFilter descriptorFilter,
- DefaultNutsWorkspace ws,
NutsFetchCommand options) {
this.ids = ids;
- this.ws = ws;
this.options = options;
this.repositoryFilter = repositoryFilter;
this.idFilter = idFilter;
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUndeployCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUndeployCommand.java
index cfcbf0d51..37b59e046 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUndeployCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUndeployCommand.java
@@ -12,21 +12,16 @@
import net.vpc.app.nuts.core.util.NutsWorkspaceHelper;
import net.vpc.app.nuts.core.util.NutsWorkspaceUtils;
-public class DefaultNutsUndeployCommand implements NutsUndeployCommand {
+public class DefaultNutsUndeployCommand extends NutsWorkspaceCommandBase implements NutsUndeployCommand {
private List result;
private final List ids = new ArrayList<>();
private String repository;
- private boolean trace = true;
private boolean offline = true;
- private boolean force = false;
private boolean transitive = true;
- private NutsWorkspace ws;
- private NutsSession session;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
public DefaultNutsUndeployCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -110,30 +105,6 @@ public NutsUndeployCommand setRepository(String repository) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsUndeployCommand setTrace(boolean trace) {
- this.trace = trace;
- invalidateResult();
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public NutsUndeployCommand setForce(boolean force) {
- this.force = force;
- invalidateResult();
- return this;
- }
-
@Override
public boolean isTransitive() {
return transitive;
@@ -146,56 +117,11 @@ public NutsUndeployCommand setTransitive(boolean transitive) {
return this;
}
- public NutsWorkspace getWs() {
- return ws;
- }
-
- public void setWs(NutsWorkspace ws) {
- this.ws = ws;
- invalidateResult();
- }
-
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsUndeployCommand setSession(NutsSession session) {
- this.session = session;
- invalidateResult();
- return this;
- }
-
@Override
public NutsUndeployCommand repository(String repository) {
return setRepository(repository);
}
- @Override
- public NutsUndeployCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public NutsUndeployCommand force() {
- return setForce(true);
- }
-
- @Override
- public NutsUndeployCommand force(boolean force) {
- return setForce(force);
- }
-
- @Override
- public NutsUndeployCommand trace() {
- return setTrace(true);
- }
-
- @Override
- public NutsUndeployCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
@Override
public NutsUndeployCommand transitive() {
return setTransitive(true);
@@ -209,7 +135,7 @@ public NutsUndeployCommand transitive(boolean transitive) {
@Override
public NutsUndeployCommand run() {
NutsWorkspaceUtils.checkReadOnly(ws);
- session = NutsWorkspaceUtils.validateSession(ws, session);
+
NutsFetchCommand fetchOptions = ws.fetch().setTransitive(this.isTransitive());
if (ids.isEmpty()) {
throw new NutsExecutionException("No component to undeploy", 1);
@@ -223,7 +149,7 @@ public NutsUndeployCommand run() {
.duplicateVersions(false)
.lenient(false)
.getResultDefinitions().required();
- NutsRepositorySession rsession = NutsWorkspaceHelper.createRepositorySession(session, p.getRepository(), NutsFetchMode.LOCAL, fetchOptions);
+ NutsRepositorySession rsession = NutsWorkspaceHelper.createRepositorySession(getValidSession(), p.getRepository(), NutsFetchMode.LOCAL, fetchOptions);
p.getRepository().undeploy(new DefaultNutsRepositoryUndeploymentOptions()
.id(p.getId())
.force(isForce())
@@ -231,13 +157,12 @@ public NutsUndeployCommand run() {
rsession);
addResult(id);
}
- if (trace) {
+ if (isTrace()) {
if (getOutputFormat() == null || getOutputFormat() == NutsOutputFormat.PLAIN) {
- session = NutsWorkspaceUtils.validateSession(ws, getSession());
if (getOutputFormat() != null && getOutputFormat() != NutsOutputFormat.PLAIN) {
switch (getOutputFormat()) {
case JSON: {
- session.getTerminal().out().printf(ws.io().toJsonString(result, true));
+ getValidSession().getTerminal().out().printf(ws.io().toJsonString(result, true));
break;
}
case PROPS: {
@@ -245,7 +170,7 @@ public NutsUndeployCommand run() {
for (int i = 0; i < result.size(); i++) {
props.put(String.valueOf(i + 1), result.get(i).toString());
}
- OutputStreamWriter w = new OutputStreamWriter(session.getTerminal().out());
+ OutputStreamWriter w = new OutputStreamWriter(getValidSession().getTerminal().out());
try {
props.store(w, null);
w.flush();
@@ -267,50 +192,15 @@ private void addResult(NutsId id) {
result = new ArrayList<>();
}
result.add(id);
- if (trace) {
+ if (isTrace()) {
if (getOutputFormat() == null || getOutputFormat() == NutsOutputFormat.PLAIN) {
- session = NutsWorkspaceUtils.validateSession(ws, getSession());
if (getOutputFormat() == null || getOutputFormat() == NutsOutputFormat.PLAIN) {
- session.getTerminal().out().printf("Nuts %N undeployed successfully\n", ws.formatter().createIdFormat().toString(id));
+ getValidSession().getTerminal().out().printf("Nuts %N undeployed successfully\n", ws.formatter().createIdFormat().toString(id));
}
}
}
}
- @Override
- public NutsUndeployCommand outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- @Override
- public NutsUndeployCommand setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return this;
- }
-
- @Override
- public NutsUndeployCommand json() {
- return setOutputFormat(NutsOutputFormat.JSON);
- }
-
- @Override
- public NutsUndeployCommand plain() {
- return setOutputFormat(NutsOutputFormat.PLAIN);
- }
-
- @Override
- public NutsUndeployCommand props() {
- return setOutputFormat(NutsOutputFormat.PROPS);
- }
-
- @Override
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
-
@Override
public boolean isOffline() {
return offline;
@@ -333,7 +223,7 @@ public NutsUndeployCommand offline(boolean offline) {
return setOffline(offline);
}
- private void invalidateResult() {
+ protected void invalidateResult() {
result = null;
}
@@ -342,17 +232,7 @@ public NutsUndeployCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "-f":
- case "--force": {
- setForce(a.getBooleanValue());
- break;
- }
- case "-T":
- case "--transitive": {
- setTransitive(a.getBooleanValue());
- break;
- }
+ switch (a.strKey()) {
case "-o":
case "--offline": {
setOffline(a.getBooleanValue());
@@ -364,32 +244,13 @@ public NutsUndeployCommand parseOptions(String... args) {
setRepository(cmd.getValueFor(a).getString());
break;
}
- case "-t":
- case "--trace": {
- setTrace(a.getBooleanValue());
- break;
- }
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUninstallCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUninstallCommand.java
index 1ec080c82..d5be748aa 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUninstallCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUninstallCommand.java
@@ -32,22 +32,17 @@
/**
*
* type: Command Class
+ *
* @author vpc
*/
-public class DefaultNutsUninstallCommand implements NutsUninstallCommand {
+public class DefaultNutsUninstallCommand extends NutsWorkspaceCommandBase implements NutsUninstallCommand {
- private boolean ask = true;
- private boolean trace = true;
- private boolean force = false;
private boolean erase = false;
private List args;
- private List ids = new ArrayList<>();
- private NutsSession session;
- private NutsWorkspace ws;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
+ private final List ids = new ArrayList<>();
public DefaultNutsUninstallCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -91,39 +86,6 @@ public NutsUninstallCommand addIds(NutsId... ids) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsUninstallCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public NutsUninstallCommand setForce(boolean forceInstall) {
- this.force = forceInstall;
- return this;
- }
-
- @Override
- public boolean isAsk() {
- return ask;
- }
-
- @Override
- public NutsUninstallCommand setAsk(boolean ask) {
- this.ask = ask;
- return this;
- }
-
@Override
public NutsUninstallCommand removeId(NutsId id) {
if (id != null) {
@@ -164,36 +126,6 @@ public NutsUninstallCommand clearArgs() {
return this;
}
- @Override
- public NutsUninstallCommand ask() {
- return setAsk(true);
- }
-
- @Override
- public NutsUninstallCommand ask(boolean ask) {
- return setAsk(ask);
- }
-
- @Override
- public NutsUninstallCommand force() {
- return setForce(true);
- }
-
- @Override
- public NutsUninstallCommand force(boolean force) {
- return setForce(force);
- }
-
- @Override
- public NutsUninstallCommand trace() {
- return setTrace(true);
- }
-
- @Override
- public NutsUninstallCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
@Override
public NutsUninstallCommand erase() {
return setErase(true);
@@ -204,11 +136,6 @@ public NutsUninstallCommand erase(boolean erase) {
return setErase(erase);
}
- @Override
- public NutsUninstallCommand session(NutsSession session) {
- return setSession(session);
- }
-
@Override
public String[] getArgs() {
return args == null ? new String[0] : args.toArray(new String[0]);
@@ -245,17 +172,6 @@ public NutsUninstallCommand addArgs(Collection args) {
return this;
}
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsUninstallCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
@Override
public NutsId[] getIds() {
return ids == null ? new NutsId[0] : ids.toArray(new NutsId[0]);
@@ -323,50 +239,26 @@ public NutsUninstallCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
- case "-f":
- case "--force": {
- this.setForce(a.getBooleanValue());
- break;
- }
+ switch (a.strKey()) {
case "-e":
case "--earse": {
this.setErase(a.getBooleanValue());
break;
}
- case "--trace": {
- this.setTrace(a.getBooleanValue());
- break;
- }
- case "-g":
- case "--args":
- {
+ case "-g":
+ case "--args": {
while (cmd.hasNext()) {
this.addArg(cmd.next().getString());
}
break;
}
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
@@ -374,38 +266,4 @@ public NutsUninstallCommand parseOptions(String... args) {
return this;
}
- @Override
- public NutsUninstallCommand outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- @Override
- public NutsUninstallCommand setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return this;
- }
-
- @Override
- public NutsUninstallCommand json() {
- return setOutputFormat(NutsOutputFormat.JSON);
- }
-
- @Override
- public NutsUninstallCommand plain() {
- return setOutputFormat(NutsOutputFormat.PLAIN);
- }
-
- @Override
- public NutsUninstallCommand props() {
- return setOutputFormat(NutsOutputFormat.PROPS);
- }
-
- @Override
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
-
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateCommand.java
index 37afe78e9..ae97e52c0 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateCommand.java
@@ -56,34 +56,28 @@
/**
*
* type: Command Class
+ *
* @author vpc
*/
-public class DefaultNutsUpdateCommand implements NutsUpdateCommand {
+public class DefaultNutsUpdateCommand extends NutsWorkspaceCommandBase implements NutsUpdateCommand {
public static final Logger LOG = Logger.getLogger(DefaultNutsUpdateCommand.class.getName());
-
- private boolean ask = true;
- private boolean trace = true;
- private boolean force = false;
private boolean enableInstall = true;
private boolean updateApi = false;
private boolean updateRuntime = false;
private boolean updateExtensions = false;
private boolean updateInstalled = false;
private boolean includeOptional = false;
- private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
private String forceBootAPIVersion;
private List args;
private final List scopes = new ArrayList<>();
private final List frozenIds = new ArrayList<>();
- private NutsSession session;
- private final NutsWorkspace ws;
private final List ids = new ArrayList<>();
private NutsWorkspaceUpdateResult result;
public DefaultNutsUpdateCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
@Override
@@ -198,17 +192,6 @@ public NutsUpdateCommand addScopes(Collection scopes) {
return this;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public NutsUpdateCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
@Override
public boolean isIncludeOptional() {
return includeOptional;
@@ -220,28 +203,6 @@ public NutsUpdateCommand setIncludeOptional(boolean includeOptional) {
return this;
}
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public NutsUpdateCommand setForce(boolean forceInstall) {
- this.force = forceInstall;
- return this;
- }
-
- @Override
- public boolean isAsk() {
- return ask;
- }
-
- @Override
- public NutsUpdateCommand setAsk(boolean ask) {
- this.ask = ask;
- return this;
- }
-
@Override
public String[] getArgs() {
return args == null ? new String[0] : args.toArray(new String[0]);
@@ -286,17 +247,6 @@ public NutsUpdateCommand addArgs(Collection args) {
return this;
}
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public NutsUpdateCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
@Override
public NutsId[] getFrozenIds() {
return frozenIds == null ? new NutsId[0] : frozenIds.toArray(new NutsId[0]);
@@ -406,6 +356,11 @@ public NutsWorkspaceUpdateResult getResult() {
return result;
}
+ @Override
+ public NutsUpdateCommand run() {
+ return update();
+ }
+
@Override
public NutsUpdateCommand update() {
applyResult(getResult());
@@ -845,14 +800,14 @@ private void applyRegularUpdate(DefaultNutsUpdateResult r) {
return;
}
NutsWorkspaceExt dws = NutsWorkspaceExt.of(ws);
- final PrintStream out = CoreIOUtils.resolveOut(ws, session);
+ final PrintStream out = CoreIOUtils.resolveOut(ws, getValidSession());
NutsId id = r.getId();
NutsDefinition d0 = r.getLocal();
NutsDefinition d1 = r.getAvailable();
final String simpleName = d0 != null ? d0.getId().getSimpleName() : d1 != null ? d1.getId().getSimpleName() : id.getSimpleName();
if (d0 == null) {
ws.security().checkAllowed(NutsConstants.Rights.UPDATE, "update");
- dws.installImpl(d1, new String[0], null, session, true, this.isTrace(), true);
+ dws.installImpl(d1, new String[0], null, getValidSession(), true, this.isTrace(), true);
r.setUpdateApplied(true);
if (this.isTrace()) {
out.printf("==%s== is [[forced]] to latest version ==%s==\n", simpleName, d1.getId().getVersion());
@@ -866,7 +821,7 @@ private void applyRegularUpdate(DefaultNutsUpdateResult r) {
//no update needed!
if (this.isForce()) {
ws.security().checkAllowed(NutsConstants.Rights.UPDATE, "update");
- dws.installImpl(d1, new String[0], null, session, true, this.isTrace(), true);
+ dws.installImpl(d1, new String[0], null, getValidSession(), true, this.isTrace(), true);
r.setUpdateApplied(true);
r.setUpdateForced(true);
if (this.isTrace()) {
@@ -875,7 +830,7 @@ private void applyRegularUpdate(DefaultNutsUpdateResult r) {
}
} else {
ws.security().checkAllowed(NutsConstants.Rights.UPDATE, "update");
- dws.installImpl(d1, new String[0], null, session, true, this.isTrace(), true);
+ dws.installImpl(d1, new String[0], null, getValidSession(), true, this.isTrace(), true);
r.setUpdateApplied(true);
if (this.isTrace()) {
out.printf("==%s== is [[updated]] from ==%s== to latest version ==%s==\n", simpleName, d0.getId().getVersion(), d1.getId().getVersion());
@@ -983,31 +938,6 @@ public NutsUpdateCommand args(Collection arg) {
return addArgs(arg);
}
- @Override
- public NutsUpdateCommand ask() {
- return ask(true);
- }
-
- @Override
- public NutsUpdateCommand ask(boolean ask) {
- return setAsk(ask);
- }
-
- @Override
- public NutsUpdateCommand force() {
- return force(true);
- }
-
- @Override
- public NutsUpdateCommand force(boolean forceInstall) {
- return setForce(forceInstall);
- }
-
- @Override
- public NutsUpdateCommand session(NutsSession session) {
- return setSession(session);
- }
-
@Override
public NutsUpdateCommand all() {
setUpdateApi(true);
@@ -1085,16 +1015,6 @@ public NutsUpdateCommand clearFrozenIds() {
return this;
}
- @Override
- public NutsUpdateCommand trace() {
- return trace(true);
- }
-
- @Override
- public NutsUpdateCommand trace(boolean enable) {
- return setTrace(enable);
- }
-
@Override
public NutsUpdateCommand includeOptional() {
return includeOptional(true);
@@ -1161,7 +1081,7 @@ public NutsUpdateCommand parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
+ switch (a.strKey()) {
case "-a":
case "--all": {
this.all();
@@ -1199,35 +1119,20 @@ public NutsUpdateCommand parseOptions(String... args) {
this.setApiVersion(cmd.getValueFor(a).getString());
break;
}
- case "-g":
- case "--args":
- {
+ case "-g":
+ case "--args": {
while (cmd.hasNext()) {
this.addArg(cmd.next().getString());
}
break;
}
- case "--trace-format": {
- this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
- break;
- }
- case "--json": {
- this.setOutputFormat(NutsOutputFormat.JSON);
- break;
- }
- case "--props": {
- this.setOutputFormat(NutsOutputFormat.PROPS);
- break;
- }
- case "--plain": {
- this.setOutputFormat(NutsOutputFormat.PLAIN);
- break;
- }
default: {
- if (a.isOption()) {
- throw new NutsIllegalArgumentException("Unsupported option " + a);
- } else {
- id(a.getString());
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ id(a.getString());
+ }
}
}
}
@@ -1235,38 +1140,4 @@ public NutsUpdateCommand parseOptions(String... args) {
return this;
}
- @Override
- public NutsUpdateCommand outputFormat(NutsOutputFormat outputFormat) {
- return setOutputFormat(outputFormat);
- }
-
- @Override
- public NutsUpdateCommand setOutputFormat(NutsOutputFormat outputFormat) {
- if (outputFormat == null) {
- outputFormat = NutsOutputFormat.PLAIN;
- }
- this.outputFormat = outputFormat;
- return this;
- }
-
- @Override
- public NutsUpdateCommand json() {
- return setOutputFormat(NutsOutputFormat.JSON);
- }
-
- @Override
- public NutsUpdateCommand plain() {
- return setOutputFormat(NutsOutputFormat.PLAIN);
- }
-
- @Override
- public NutsUpdateCommand props() {
- return setOutputFormat(NutsOutputFormat.PROPS);
- }
-
- @Override
- public NutsOutputFormat getOutputFormat() {
- return this.outputFormat;
- }
-
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateUserCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateUserCommand.java
index eb6d4fd0c..519fa8612 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateUserCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsUpdateUserCommand.java
@@ -34,10 +34,11 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import net.vpc.app.nuts.NutsCommandArg;
+import net.vpc.app.nuts.NutsCommandLine;
import net.vpc.app.nuts.NutsConstants;
import net.vpc.app.nuts.NutsIllegalArgumentException;
import net.vpc.app.nuts.NutsRepository;
-import net.vpc.app.nuts.NutsSession;
import net.vpc.app.nuts.NutsUpdateUserCommand;
import net.vpc.app.nuts.NutsUserConfig;
import net.vpc.app.nuts.NutsWorkspace;
@@ -49,10 +50,7 @@
* @author vpc
* @since 0.5.4
*/
-public class DefaultNutsUpdateUserCommand implements NutsUpdateUserCommand {
-
- private boolean trace = true;
- private boolean force = false;
+public class DefaultNutsUpdateUserCommand extends NutsWorkspaceCommandBase implements NutsUpdateUserCommand {
private String login;
private String remoteIdentity;
private boolean remoteIdentityUpdated;
@@ -60,80 +58,21 @@ public class DefaultNutsUpdateUserCommand implements NutsUpdateUserCommand {
private boolean resetGroups;
private String credentials;
private String oldCredentials;
- private Set rights = new HashSet();
- private Set groups = new HashSet();
- private Set rm_rights = new HashSet();
- private Set rm_groups = new HashSet();
- private NutsSession session;
- private NutsWorkspace ws;
+ private final Set rights = new HashSet<>();
+ private final Set groups = new HashSet<>();
+ private final Set rm_rights = new HashSet<>();
+ private final Set rm_groups = new HashSet<>();
private NutsRepository repo;
public DefaultNutsUpdateUserCommand(NutsWorkspace ws) {
- this.ws = ws;
+ super(ws);
}
public DefaultNutsUpdateUserCommand(NutsRepository repo) {
+ super(repo.getWorkspace());
this.repo = repo;
}
- @Override
- public boolean isTrace() {
- return trace;
- }
-
- @Override
- public DefaultNutsUpdateUserCommand trace() {
- return trace(true);
- }
-
- @Override
- public DefaultNutsUpdateUserCommand trace(boolean trace) {
- return setTrace(trace);
- }
-
- @Override
- public DefaultNutsUpdateUserCommand setTrace(boolean trace) {
- this.trace = trace;
- return this;
- }
-
- @Override
- public boolean isForce() {
- return force;
- }
-
- @Override
- public DefaultNutsUpdateUserCommand force() {
- return force(true);
- }
-
- @Override
- public DefaultNutsUpdateUserCommand force(boolean force) {
- return setForce(force);
- }
-
- @Override
- public DefaultNutsUpdateUserCommand setForce(boolean force) {
- this.force = force;
- return this;
- }
-
- @Override
- public NutsSession getSession() {
- return session;
- }
-
- @Override
- public DefaultNutsUpdateUserCommand session(NutsSession session) {
- return setSession(session);
- }
-
- @Override
- public DefaultNutsUpdateUserCommand setSession(NutsSession session) {
- this.session = session;
- return this;
- }
-
@Override
public String getCredentials() {
return credentials;
@@ -591,4 +530,24 @@ public NutsUpdateUserCommand run() {
}
return this;
}
+
+ public NutsUpdateUserCommand parseOptions(String... args) {
+ NutsCommandLine cmd = new NutsCommandLine(args);
+ NutsCommandArg a;
+ while ((a = cmd.next()) != null) {
+ switch (a.strKey()) {
+ default: {
+ if (!super.parseOption(a, cmd)) {
+ if (a.isOption()) {
+ throw new NutsIllegalArgumentException("Unsupported option " + a);
+ } else {
+ //id(a.getString());
+ }
+ }
+ }
+ }
+ }
+ return this;
+ }
+
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspace.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspace.java
index 6d74df31b..562b6b477 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspace.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspace.java
@@ -802,7 +802,7 @@ public NutsExecutionContext createNutsExecutionContext(NutsDefinition nutToInsta
public String resolveCommandName(NutsId id) {
String nn = id.getName();
- NutsWorkspaceCommand c = config().findCommandAliases(nn);
+ NutsWorkspaceCommandAlias c = config().findCommandAlias(nn);
if (c != null) {
if (c.getOwner().getLongName().equals(id.getLongName())) {
return nn;
@@ -811,7 +811,7 @@ public String resolveCommandName(NutsId id) {
return nn;
}
nn = id.getName() + "-" + id.getVersion();
- c = config().findCommandAliases(nn);
+ c = config().findCommandAlias(nn);
if (c != null) {
if (c.getOwner().getLongName().equals(id.getLongName())) {
return nn;
@@ -820,7 +820,7 @@ public String resolveCommandName(NutsId id) {
return nn;
}
nn = id.getGroup() + "." + id.getName() + "-" + id.getVersion();
- c = config().findCommandAliases(nn);
+ c = config().findCommandAlias(nn);
if (c != null) {
if (c.getOwner().getLongName().equals(id.getLongName())) {
return nn;
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceCommand.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceCommandAlias.java
similarity index 79%
rename from nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceCommand.java
rename to nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceCommandAlias.java
index 7bb5ba277..f27da3a7f 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceCommand.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceCommandAlias.java
@@ -8,11 +8,11 @@
import net.vpc.app.nuts.NutsId;
import net.vpc.app.nuts.NutsSession;
import net.vpc.app.nuts.NutsWorkspace;
-import net.vpc.app.nuts.NutsWorkspaceCommand;
import net.vpc.app.nuts.core.util.common.CoreCommonUtils;
import net.vpc.app.nuts.core.util.common.CoreStringUtils;
+import net.vpc.app.nuts.NutsWorkspaceCommandAlias;
-public class DefaultNutsWorkspaceCommand implements NutsWorkspaceCommand {
+public class DefaultNutsWorkspaceCommandAlias implements NutsWorkspaceCommandAlias {
private String name;
private NutsId owner;
@@ -23,7 +23,7 @@ public class DefaultNutsWorkspaceCommand implements NutsWorkspaceCommand {
private String[] executorOptions;
private NutsWorkspace ws;
- public DefaultNutsWorkspaceCommand(NutsWorkspace ws) {
+ public DefaultNutsWorkspaceCommandAlias(NutsWorkspace ws) {
this.ws = ws;
}
@@ -32,7 +32,7 @@ public String getName() {
return name;
}
- public DefaultNutsWorkspaceCommand setName(String name) {
+ public DefaultNutsWorkspaceCommandAlias setName(String name) {
this.name = name;
return this;
}
@@ -42,7 +42,7 @@ public NutsId getOwner() {
return owner;
}
- public DefaultNutsWorkspaceCommand setOwner(NutsId owner) {
+ public DefaultNutsWorkspaceCommandAlias setOwner(NutsId owner) {
this.owner = owner;
return this;
}
@@ -52,17 +52,17 @@ public String getFactoryId() {
return factoryId;
}
- public DefaultNutsWorkspaceCommand setFactoryId(String factoryId) {
+ public DefaultNutsWorkspaceCommandAlias setFactoryId(String factoryId) {
this.factoryId = factoryId;
return this;
}
- public DefaultNutsWorkspaceCommand setHelpCommand(String[] helpCommand) {
+ public DefaultNutsWorkspaceCommandAlias setHelpCommand(String[] helpCommand) {
this.helpCommand = helpCommand;
return this;
}
- public DefaultNutsWorkspaceCommand setHelpText(String helpText) {
+ public DefaultNutsWorkspaceCommandAlias setHelpText(String helpText) {
this.helpText = helpText;
return this;
}
@@ -76,19 +76,19 @@ public void setWs(NutsWorkspace ws) {
}
public String[] getCommand() {
- return command;
+ return command==null?new String[0] : Arrays.copyOf(command, command.length);
}
- public DefaultNutsWorkspaceCommand setCommand(String[] command) {
+ public DefaultNutsWorkspaceCommandAlias setCommand(String[] command) {
this.command = command;
return this;
}
public String[] getExecutorOptions() {
- return executorOptions;
+ return executorOptions==null?new String[0] : Arrays.copyOf(executorOptions, command.length);
}
- public DefaultNutsWorkspaceCommand setExecutorOptions(String[] executorOptions) {
+ public DefaultNutsWorkspaceCommandAlias setExecutorOptions(String[] executorOptions) {
this.executorOptions = executorOptions;
return this;
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceConfigManager.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceConfigManager.java
index 90e9afb81..efb387b4c 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceConfigManager.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceConfigManager.java
@@ -795,7 +795,7 @@ public byte[] encryptString(byte[] input) {
}
@Override
- public NutsWorkspaceCommand findCommandAliases(String name) {
+ public NutsWorkspaceCommandAlias findCommandAlias(String name) {
NutsCommandAliasConfig c = defaultCommandFactory.findCommand(name, ws);
if (c == null) {
for (NutsWorkspaceCommandFactory commandFactory : commandFactories) {
@@ -811,7 +811,7 @@ public NutsWorkspaceCommand findCommandAliases(String name) {
return toDefaultNutsWorkspaceCommand(c);
}
- private NutsWorkspaceCommand toDefaultNutsWorkspaceCommand(NutsCommandAliasConfig c) {
+ private NutsWorkspaceCommandAlias toDefaultNutsWorkspaceCommand(NutsCommandAliasConfig c) {
if (c.getCommand() == null || c.getCommand().length == 0) {
LOG.log(Level.WARNING, "Invalid Command Definition ''{0}''. Missing Command. Ignored", c.getName());
return null;
@@ -820,7 +820,7 @@ private NutsWorkspaceCommand toDefaultNutsWorkspaceCommand(NutsCommandAliasConfi
LOG.log(Level.WARNING, "Invalid Command Definition ''{0}''. Missing Owner. Ignored", c.getName());
return null;
}
- return new DefaultNutsWorkspaceCommand(ws)
+ return new DefaultNutsWorkspaceCommandAlias(ws)
.setCommand(c.getCommand())
.setFactoryId(c.getFactoryId())
.setOwner(c.getOwner())
@@ -884,8 +884,8 @@ public boolean removeCommandAlias(String name, NutsRemoveOptions options) {
}
@Override
- public List findCommandAliases() {
- HashMap all = new HashMap<>();
+ public List findCommandAliases() {
+ HashMap all = new HashMap<>();
for (NutsCommandAliasConfig command : defaultCommandFactory.findCommands(ws)) {
all.put(command.getName(), toDefaultNutsWorkspaceCommand(command));
}
@@ -980,8 +980,8 @@ public boolean removeCommandAliasFactory(String factoryId, NutsRemoveOptions opt
}
@Override
- public List findCommandAliases(NutsId id) {
- HashMap all = new HashMap<>();
+ public List findCommandAliases(NutsId id) {
+ HashMap all = new HashMap<>();
for (NutsCommandAliasConfig command : defaultCommandFactory.findCommands(id, ws)) {
all.put(command.getName(), toDefaultNutsWorkspaceCommand(command));
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceInfoFormat.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceInfoFormat.java
index 984847f89..60e0101a9 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceInfoFormat.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceInfoFormat.java
@@ -56,7 +56,7 @@ public NutsWorkspaceInfoFormat parseOptions(String... args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().toString()) {
+ switch (a.strKey()) {
case "--min": {
this.setMinimal(true);
break;
@@ -83,7 +83,7 @@ public NutsWorkspaceInfoFormat parseOptions(String... args) {
}
case "--add": {
NutsCommandArg r = cmd.getValueFor(a);
- extraProperties.put(r.getKey(), r.getValue());
+ extraProperties.put(r.getKey().getString(), r.getValue().getString());
break;
}
default: {
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceVersionFormat.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceVersionFormat.java
index d0e182217..69434818d 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceVersionFormat.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/DefaultNutsWorkspaceVersionFormat.java
@@ -46,7 +46,7 @@ public NutsWorkspaceVersionFormat parseOptions(String[] args) {
NutsCommandLine cmd = new NutsCommandLine(args);
NutsCommandArg a;
while ((a = cmd.next()) != null) {
- switch (a.getKey().getString()) {
+ switch (a.strKey()) {
case "--min": {
this.setMinimal(a.getBooleanValue());
break;
@@ -57,7 +57,7 @@ public NutsWorkspaceVersionFormat parseOptions(String[] args) {
}
case "--add": {
NutsCommandArg r = cmd.getValueFor(a);
- extraProperties.put(r.getKey(), r.getValue());
+ extraProperties.put(r.getKey().getString(), r.getValue().getString());
break;
}
case "--trace-format": {
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/NutsWorkspaceCommandBase.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/NutsWorkspaceCommandBase.java
new file mode 100644
index 000000000..e48232d49
--- /dev/null
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/NutsWorkspaceCommandBase.java
@@ -0,0 +1,247 @@
+/*
+ * 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.vpc.app.nuts.core;
+
+import java.util.Arrays;
+import net.vpc.app.nuts.NutsCommandArg;
+import net.vpc.app.nuts.NutsCommandLine;
+import net.vpc.app.nuts.NutsSession;
+import net.vpc.app.nuts.NutsOutputFormat;
+import net.vpc.app.nuts.NutsTraceFormat;
+import net.vpc.app.nuts.NutsWorkspace;
+import net.vpc.app.nuts.core.util.NutsWorkspaceUtils;
+
+/**
+ *
+ * @author vpc
+ * @param
+ */
+public abstract class NutsWorkspaceCommandBase {
+
+ protected NutsWorkspace ws;
+ private NutsSession session;
+ private NutsSession validSession;
+ private boolean ask = true;
+ private boolean trace = false;
+ private boolean force = false;
+ private NutsOutputFormat outputFormat = NutsOutputFormat.PLAIN;
+ private final NutsTraceFormat[] traceFormats = new NutsTraceFormat[NutsOutputFormat.values().length];
+
+ public NutsWorkspaceCommandBase(NutsWorkspace ws) {
+ this.ws = ws;
+ }
+
+ //@Override
+ protected T copyFromWorkspaceCommandBase(NutsWorkspaceCommandBase other) {
+ if (other != null) {
+ this.session = other.getSession();
+ this.trace = other.isTrace();
+ this.force = other.isForce();
+ this.ask = other.isAsk();
+ System.arraycopy(other.traceFormats, 0, this.traceFormats, 0, NutsOutputFormat.values().length);
+ }
+ return (T) this;
+ }
+
+ public NutsTraceFormat getTraceFormat() {
+ return traceFormats[getOutputFormat().ordinal()];
+ }
+
+ public T unsetTraceFormat(NutsOutputFormat f) {
+ traceFormats[f.ordinal()] = null;
+ return (T) this;
+ }
+
+ public T traceFormat(NutsTraceFormat traceFormat) {
+ return setTraceFormat(traceFormat);
+ }
+
+ public T setTraceFormat(NutsTraceFormat f) {
+ if (f == null) {
+ throw new NullPointerException();
+ }
+ traceFormats[f.getSupportedFormat().ordinal()] = f;
+ return (T) this;
+ }
+
+ public NutsTraceFormat[] getTraceFormats() {
+ return Arrays.copyOf(traceFormats, traceFormats.length);
+ }
+
+ //@Override
+ public NutsSession getSession() {
+ return session;
+ }
+
+ //@Override
+ public T session(NutsSession session) {
+ return setSession(session);
+ }
+
+ //@Override
+ public T setSession(NutsSession session) {
+ this.session = session;
+ return (T) this;
+ }
+
+ public T outputFormat(NutsOutputFormat outputFormat) {
+ return setOutputFormat(outputFormat);
+ }
+
+ public T setOutputFormat(NutsOutputFormat outputFormat) {
+ if (outputFormat == null) {
+ outputFormat = NutsOutputFormat.PLAIN;
+ }
+ this.outputFormat = outputFormat;
+ return (T) this;
+ }
+
+ public NutsOutputFormat getOutputFormat() {
+ return this.outputFormat;
+ }
+
+ public boolean isTrace() {
+ return trace;
+ }
+
+ public T setTrace(boolean trace) {
+ this.trace = trace;
+ return (T) this;
+ }
+
+ public T trace(boolean trace) {
+ return setTrace(trace);
+ }
+
+ public T trace() {
+ return trace(true);
+ }
+
+ public boolean isForce() {
+ return force;
+ }
+
+ public T force() {
+ return force(true);
+ }
+
+ public T force(boolean force) {
+ return setForce(force);
+ }
+
+ public T setForce(boolean force) {
+ this.force = force;
+ return (T) this;
+ }
+
+// public boolean isLenient() {
+// return lenient;
+// }
+//
+// public T setLenient(boolean ignoreNotFound) {
+// this.lenient = ignoreNotFound;
+// return (T) this;
+// }
+//
+// public T lenient() {
+// return setLenient(true);
+// }
+//
+// public T lenient(boolean lenient) {
+// return setLenient(lenient);
+// }
+ protected void invalidateResult() {
+
+ }
+
+ public NutsSession getValidSession() {
+ if (validSession == null) {
+ validSession = NutsWorkspaceUtils.validateSession(ws, getSession());
+ }
+ return validSession;
+ }
+
+ public T json() {
+ return setOutputFormat(NutsOutputFormat.JSON);
+ }
+
+ public T plain() {
+ return setOutputFormat(NutsOutputFormat.PLAIN);
+ }
+
+ public T props() {
+ return setOutputFormat(NutsOutputFormat.PROPS);
+ }
+
+ public boolean isAsk() {
+ return ask;
+ }
+
+ public T setAsk(boolean ask) {
+ this.ask = ask;
+ return (T) this;
+ }
+
+ public T ask(boolean ask) {
+ return setAsk(true);
+ }
+
+ public T ask() {
+ return ask(true);
+ }
+
+ protected NutsWorkspace getWs() {
+ return ws;
+ }
+
+ protected void setWs(NutsWorkspace ws) {
+ this.ws = ws;
+ invalidateResult();
+ }
+
+ protected boolean parseOption(NutsCommandArg a, NutsCommandLine cmd) {
+
+ switch (a.strKey()) {
+// case "--lenient": {
+// this.setLenient(a.getBooleanValue());
+// break;
+// }
+ case "--trace": {
+ this.setTrace(a.getBooleanValue());
+ return true;
+ }
+ case "--ask": {
+ this.setAsk(a.getBooleanValue());
+ return true;
+ }
+ case "--force": {
+ this.setForce(a.getBooleanValue());
+ return true;
+ }
+ case "--trace-format": {
+ this.setOutputFormat(NutsOutputFormat.valueOf(cmd.getValueFor(a).getString().toUpperCase()));
+ return true;
+ }
+ case "--json": {
+ this.setOutputFormat(NutsOutputFormat.JSON);
+ return true;
+ }
+ case "--props": {
+ this.setOutputFormat(NutsOutputFormat.PROPS);
+ return true;
+ }
+ case "--plain": {
+ this.setOutputFormat(NutsOutputFormat.PLAIN);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public abstract T parseOptions(String... args);
+
+ public abstract T run();
+}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/TraceIterator.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/TraceIterator.java
new file mode 100644
index 000000000..251a7b6f0
--- /dev/null
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/TraceIterator.java
@@ -0,0 +1,82 @@
+/*
+ * 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.vpc.app.nuts.core;
+
+import java.io.PrintStream;
+import java.util.Iterator;
+import net.vpc.app.nuts.NutsOutputFormat;
+import net.vpc.app.nuts.NutsTraceFormat;
+import net.vpc.app.nuts.NutsUnsupportedOperationException;
+import net.vpc.app.nuts.NutsWorkspace;
+import net.vpc.app.nuts.core.util.DefaultNutsFindTraceFormatJson;
+import net.vpc.app.nuts.core.util.DefaultNutsFindTraceFormatPlain;
+import net.vpc.app.nuts.core.util.DefaultNutsFindTraceFormatProps;
+
+/**
+ *
+ * @author vpc
+ */
+public class TraceIterator implements Iterator {
+
+ Iterator curr;
+ NutsWorkspace ws;
+ NutsTraceFormat conv;
+ PrintStream out;
+ NutsOutputFormat format;
+ long count = 0;
+
+ public TraceIterator(Iterator curr, NutsWorkspace ws, PrintStream out, NutsOutputFormat format, NutsTraceFormat conv) {
+ this.curr = curr;
+ this.ws = ws;
+ this.out = out;
+ this.conv = conv;
+ this.format = format;
+ if (this.conv == null) {
+ switch (this.format) {
+ case JSON:
+ {
+ this.conv = new DefaultNutsFindTraceFormatJson();
+ break;
+ }
+ case PROPS:
+ {
+ this.conv = new DefaultNutsFindTraceFormatProps();
+ break;
+ }
+ case PLAIN:
+ {
+ this.conv = new DefaultNutsFindTraceFormatPlain();
+ break;
+ }
+ default:
+ {
+ throw new NutsUnsupportedOperationException("Unsupported " + format);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ boolean p = curr.hasNext();
+ if (!p) {
+ conv.formatEnd(count, out, ws);
+ }
+ return p;
+ }
+
+ @Override
+ public T next() {
+ T n = curr.next();
+ if (count == 0) {
+ conv.formatStart(out, ws);
+ }
+ conv.formatElement(n, count, out, ws);
+ count++;
+ return n;
+ }
+
+}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/executors/JavaNutsExecutorComponent.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/executors/JavaNutsExecutorComponent.java
index 82c94115a..cc85b4d6f 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/executors/JavaNutsExecutorComponent.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/executors/JavaNutsExecutorComponent.java
@@ -73,7 +73,7 @@ public void exec(NutsExecutionContext executionContext) {
JavaExecutorOptions joptions = new JavaExecutorOptions(
nutsMainDef, executionContext.getArgs(),
executionContext.getExecutorOptions(),
- executionContext.getCwd(),
+ CoreStringUtils.isBlank(executionContext.getCwd()) ? System.getProperty("user.dir") : executionContext.getCwd(),
executionContext.getWorkspace(),
executionContext.getSession());
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/DefaultNutsFindTraceFormatProps.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/DefaultNutsFindTraceFormatProps.java
index 209bfe367..52db4b565 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/DefaultNutsFindTraceFormatProps.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/DefaultNutsFindTraceFormatProps.java
@@ -6,6 +6,9 @@
package net.vpc.app.nuts.core.util;
import java.io.PrintStream;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
import java.util.Properties;
import net.vpc.app.nuts.NutsOutputFormat;
import net.vpc.app.nuts.NutsTraceFormat;
@@ -36,8 +39,8 @@ public void formatElement(Object object, long index, PrintStream out, NutsWorksp
if (canonicalBuilder == null) {
canonicalBuilder = new CanonicalBuilder(ws).setConvertDesc(true).setConvertId(false);
}
- Properties p = new Properties();
- CoreCommonUtils.putAllInProps(null, p, canonicalBuilder.toCanonical(object));
+ Map p = new LinkedHashMap<>();
+ CoreCommonUtils.putAllInProps(String.valueOf(index+1), p, canonicalBuilder.toCanonical(object));
CoreIOUtils.storeProperties(p, out);
out.flush();
out.flush();
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsIdGraph.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsIdGraph.java
index 03606efe5..a05226768 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsIdGraph.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsIdGraph.java
@@ -33,7 +33,6 @@
import java.io.PrintStream;
import java.util.*;
-import net.vpc.app.nuts.core.DefaultNutsWorkspace;
import net.vpc.app.nuts.core.NutsIdAndNutsDependencyFilterItem;
import net.vpc.app.nuts.core.filters.dependency.NutsExclusionDependencyFilter;
import net.vpc.app.nuts.core.util.common.CoreStringUtils;
@@ -45,12 +44,12 @@ public class NutsIdGraph {
private final Set visited = new LinkedHashSet<>();
private final Set wildeIds = new LinkedHashSet<>();
- private final DefaultNutsWorkspace ws;
+ private final NutsWorkspace ws;
private final NutsSession session;
private final boolean ignoreNotFound;
private int maxComplexity = 300;
- public NutsIdGraph(DefaultNutsWorkspace ws, NutsSession session, boolean ignoreNotFound) {
+ public NutsIdGraph(NutsWorkspace ws, NutsSession session, boolean ignoreNotFound) {
this.ws = ws;
this.session = session;
this.ignoreNotFound = ignoreNotFound;
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsWorkspaceUtils.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsWorkspaceUtils.java
index 067d9a3aa..f77f5df42 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsWorkspaceUtils.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/NutsWorkspaceUtils.java
@@ -9,27 +9,20 @@
import net.vpc.app.nuts.core.util.common.CorePlatformUtils;
import java.io.IOException;
import java.io.PrintStream;
-import java.io.StringReader;
import java.io.UncheckedIOException;
-import java.lang.reflect.Array;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Date;
-import java.util.LinkedHashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.vpc.app.nuts.NutsConstants;
-import net.vpc.app.nuts.NutsDefinition;
-import net.vpc.app.nuts.NutsDescriptor;
import net.vpc.app.nuts.NutsDescriptorFormat;
import net.vpc.app.nuts.NutsExecCommand;
import net.vpc.app.nuts.NutsFetchCommand;
@@ -43,11 +36,9 @@
import net.vpc.app.nuts.NutsRepositorySupportedAction;
import net.vpc.app.nuts.NutsSdkLocation;
import net.vpc.app.nuts.NutsSession;
-import net.vpc.app.nuts.NutsUnsupportedOperationException;
+import net.vpc.app.nuts.NutsTraceFormat;
import net.vpc.app.nuts.NutsWorkspace;
-import static net.vpc.app.nuts.core.util.CoreNutsUtils.tracePlainNutsDefinition;
-import net.vpc.app.nuts.core.util.common.CoreCommonUtils;
-import net.vpc.app.nuts.core.util.io.CoreIOUtils;
+import net.vpc.app.nuts.core.TraceIterator;
/**
*
@@ -301,6 +292,12 @@ public static NutsDescriptorFormat getDescriptorFormat(NutsWorkspace ws) {
// ws.io().writeJson(o, out, true);
// out.println();
// }
+ public static Iterator decorateTrace(NutsWorkspace ws, Iterator it, PrintStream out, NutsOutputFormat oformat,NutsTraceFormat format) {
+ return new TraceIterator<>(it, ws, out, oformat,format);
+ }
-
+ public static Iterator decorateTrace(NutsWorkspace ws, Iterator it, NutsSession session, NutsOutputFormat oformat,NutsTraceFormat format) {
+ final PrintStream out = NutsWorkspaceUtils.validateSession(ws, session).getTerminal().getOut();
+ return new TraceIterator<>(it, ws, out, oformat,format);
+ }
}
diff --git a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/common/CoreCommonUtils.java b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/common/CoreCommonUtils.java
index 2c29423a3..99ed593cb 100644
--- a/nuts-core/src/main/java/net/vpc/app/nuts/core/util/common/CoreCommonUtils.java
+++ b/nuts-core/src/main/java/net/vpc/app/nuts/core/util/common/CoreCommonUtils.java
@@ -261,7 +261,7 @@ public static boolean isNo(String s) {
return false;
}
- public static void putAllInProps(String prefix, Properties dest, Object value) {
+ public static void putAllInProps(String prefix, Map dest, Object value) {
if (!CoreStringUtils.isBlank(prefix)) {
if (value instanceof Map) {
for (Map.Entry