Skip to content

Commit

Permalink
[FIXED] minimal archetype fails to create workspace (closing #84)
Browse files Browse the repository at this point in the history
  • Loading branch information
thevpc committed Oct 26, 2021
1 parent be9ab1c commit 9018b8d
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 200 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml -Dmaven.test.skip=true
# run: mvn -B install --file pom.xml -Dmaven.test.skip=true
run: mvn -B install --file pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ private void initWorkspace(NutsWorkspaceInitInformation info) {
// }
configModel.onExtensionsPrepared(defaultSession());
boolean justInstalled = false;
NutsWorkspaceArchetypeComponent justInstalledArchetype=null;
if (!loadWorkspace(defaultSession(), uoptions.getExcludedExtensions(), null)) {
bootModel.setFirstBoot(true);
if (uuid == null) {
Expand Down Expand Up @@ -511,7 +512,7 @@ private void initWorkspace(NutsWorkspaceInitInformation info) {
configModel.setConfigBoot(bconfig, defaultSession());
configModel.setConfigApi(aconfig, defaultSession());
configModel.setConfigRuntime(rconfig, defaultSession());
initializeWorkspace(uoptions.getArchetype(), defaultSession());
justInstalledArchetype=initializeWorkspace(uoptions.getArchetype(), defaultSession());
if (!_config.isReadOnly()) {
_config.save();
}
Expand Down Expand Up @@ -596,7 +597,7 @@ private void initWorkspace(NutsWorkspaceInitInformation info) {
if (defaultSession().repos().getRepositories().length == 0) {
LOG.with().session(defaultSession()).level(Level.CONFIG).verb(NutsLogVerb.FAIL)
.log(NutsMessage.jstyle("workspace has no repositories. Will re-create defaults"));
initializeWorkspace(uoptions.getArchetype(), defaultSession());
justInstalledArchetype=initializeWorkspace(uoptions.getArchetype(), defaultSession());
}
List<String> transientRepositoriesSet = uoptions.getRepositories() == null ? new ArrayList<>() : new ArrayList<>(Arrays.asList(uoptions.getRepositories()));
NutsRepositorySelector.SelectorList expected = NutsRepositorySelector.parse(transientRepositoriesSet.toArray(new String[0]));
Expand All @@ -621,10 +622,7 @@ private void initWorkspace(NutsWorkspaceInitInformation info) {
}
configModel.setEndCreateTimeMillis(System.currentTimeMillis());
if (justInstalled) {
installSettings(defaultSession());
if (!_boot.getBootOptions().isSkipCompanions()) {
installCompanions(defaultSession());
}
justInstalledArchetype.startWorkspace(defaultSession());
DefaultNutsWorkspaceEvent workspaceCreatedEvent = new DefaultNutsWorkspaceEvent(defaultSession(), null, null, null, null);
for (NutsWorkspaceListener workspaceListener : defaultSession().events().getWorkspaceListeners()) {
workspaceListener.onCreateWorkspace(workspaceCreatedEvent);
Expand Down Expand Up @@ -673,149 +671,6 @@ private String getApiDigest() {
return new CoreDigestHelper().append(getApiURL()).getDigest();
}

private void installSettings(NutsSession session) {
NutsWorkspace ws = session.getWorkspace();
NutsBootManager boot = session.boot();
NutsWorkspaceEnvManager env = session.env();
NutsWorkspaceConfigManager config = session.config();
boolean initializeAllPlatforms = boot.getCustomBootOption("init-platforms").getBoolean(true, false);
if (initializeAllPlatforms && boot.getCustomBootOption("init-java").getBoolean(true, false)) {
try {
if (session.isPlainTrace()) {
session.out().resetLine().println("looking for java installations in default locations...");
}
NutsPlatformLocation[] found = env.platforms()
.searchSystemPlatforms(NutsPlatformType.JAVA);
int someAdded = 0;
for (NutsPlatformLocation java : found) {
if (env.platforms().addPlatform(java)) {
someAdded++;
}
}
NutsTextManager factory = session.text();
if (session.isPlainTrace()) {
if (someAdded == 0) {
session.out().print("```error no new``` java installation locations found...\n");
} else if (someAdded == 1) {
session.out().printf("%s new java installation location added...\n", factory.ofStyled("1", NutsTextStyle.primary2()));
} else {
session.out().printf("%s new java installation locations added...\n", factory.ofStyled("" + someAdded, NutsTextStyle.primary2()));
}
session.out().println("you can always add another installation manually using 'nuts settings add java' command.");
}
if (!config.isReadOnly()) {
config.save();
}
} catch (Exception ex) {
LOG.with().session(session).level(Level.FINEST).verb(NutsLogVerb.WARNING).error(ex)
.log(NutsMessage.jstyle("unable to resolve default JRE/JDK locations : {0}", ex));
if (session.isPlainTrace()) {
NutsPrintStream out = session.out();
out.resetLine();
out.printf("```unable to resolve default JRE/JDK locations``` : %s%n", ex);
}
}
} else {
//at least add current vm
try {
if (session.isPlainTrace()) {
session.out().resetLine().println("adding current JVM...");
}
NutsPlatformLocation found0 = env.platforms()
.resolvePlatform(NutsPlatformType.JAVA, System.getProperty("java.home"), null);
NutsPlatformLocation[] found = found0 == null ? new NutsPlatformLocation[0] : new NutsPlatformLocation[]{found0};
int someAdded = 0;
for (NutsPlatformLocation java : found) {
if (env.platforms().addPlatform(java)) {
someAdded++;
}
}
NutsTextManager factory = session.text();
if (session.isPlainTrace()) {
if (someAdded == 0) {
session.out().print("```error no new``` java installation locations found...\n");
} else if (someAdded == 1) {
session.out().printf("%s new java installation location added...\n", factory.ofStyled("1", NutsTextStyle.primary2()));
} else {
session.out().printf("%s new java installation locations added...\n", factory.ofStyled("" + someAdded, NutsTextStyle.primary2()));
}
session.out().println("you can always add another installation manually using 'nuts settings add java' command.");
}
if (!config.isReadOnly()) {
config.save();
}
} catch (Exception ex) {
LOG.with().session(session).level(Level.FINEST).verb(NutsLogVerb.WARNING).error(ex)
.log(NutsMessage.jstyle("unable to resolve default JRE/JDK locations : {0}", ex));
if (session.isPlainTrace()) {
NutsPrintStream out = session.out();
out.resetLine();
out.printf("```unable to resolve default JRE/JDK locations``` : %s%n", ex);
}
}
}
if (boot.getCustomBootOption("init-launchers").getBoolean(true, false)) {
try {
env.addLauncher(
new NutsLauncherOptions()
.setId(getApiId())
.setCreateScript(true)
.setSystemWideConfig(
session.boot().getBootOptions().isSwitchWorkspace()
)
.setCreateDesktopShortcut(NutsSupportCondition.PREFERRED)
.setCreateMenuShortcut(NutsSupportCondition.SUPPORTED)
);
} catch (Exception ex) {
LOG.with().session(session).level(Level.FINEST).verb(NutsLogVerb.WARNING).error(ex)
.log(NutsMessage.jstyle("unable to install desktop launchers : {0}", ex));
if (session.isPlainTrace()) {
NutsPrintStream out = session.out();
out.resetLine();
out.printf("```error unable to install desktop launchers``` : %s%n", ex);
}
}
}
}

public void installCompanions(NutsSession session) {
NutsWorkspaceUtils.checkSession(this, session);
NutsTextManager text = session.text();
Set<NutsId> companionIds = session.extensions().getCompanionIds();
if (companionIds.isEmpty()) {
return;
}
if (session.isPlainTrace()) {
NutsPrintStream out = session.out();
out.resetLine();
out.printf("looking for recommended companion tools to install... detected : %s%n",
text.builder().appendJoined(text.ofPlain(","),
companionIds
)
);
}
try {
session.install().companions().setSession(session.copy().setTrace(session.isTrace() && session.isPlainOut()))
.run();
} catch (Exception ex) {
LOG.with().session(session).level(Level.FINEST).verb(NutsLogVerb.WARNING).error(ex)
.log(NutsMessage.jstyle("unable to install companions : {0}", ex));
if (session.isPlainTrace()) {
NutsPrintStream out = session.out();
out.resetLine();
out.printf("```error unable to install companion tools``` : %s \n"
+ "this happens when none of the following repositories are able to locate them : %s\n",
ex,
text.builder().appendJoined(text.ofPlain(", "),
Arrays.stream(session.repos().getRepositories()).map(x
-> text.builder().append(x.getName(), NutsTextStyle.primary3())
).collect(Collectors.toList())
)
);
}
}
}

protected NutsDescriptor _resolveEffectiveDescriptor(NutsDescriptor descriptor, NutsSession session) {
LOG.with().session(session).level(Level.FINEST).verb(NutsLogVerb.START)
.log(NutsMessage.jstyle("resolve effective {0}", descriptor.getId()));
Expand Down Expand Up @@ -931,7 +786,7 @@ public String toString() {
+ '}';
}

protected void initializeWorkspace(String archetype, NutsSession session) {
protected NutsWorkspaceArchetypeComponent initializeWorkspace(String archetype, NutsSession session) {
checkSession(session);
if (NutsBlankable.isBlank(archetype)) {
archetype = "default";
Expand Down Expand Up @@ -964,6 +819,7 @@ protected void initializeWorkspace(String archetype, NutsSession session) {
// } catch (Exception ex) {
// log.log(Level.SEVERE, "Unable to loadWorkspace nuts-runtime. The tool is running in minimal mode.");
// }
return instance;
}

private void checkSession(NutsSession session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* other 'things' . Its based on an extensible architecture to help supporting a
* large range of sub managers / repositories.
* <br>
*
* <p>
* Copyright [2020] [thevpc] Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -23,35 +23,32 @@
*/
package net.thevpc.nuts.runtime.standalone.archetypes;

import java.util.HashMap;
import java.util.*;

import net.thevpc.nuts.*;
import net.thevpc.nuts.runtime.standalone.config.DefaultNutsWorkspaceConfigManager;
import net.thevpc.nuts.runtime.standalone.util.NutsWorkspaceUtils;
import net.thevpc.nuts.spi.NutsSingleton;
import net.thevpc.nuts.spi.NutsSupportLevelContext;
import net.thevpc.nuts.spi.NutsWorkspaceArchetypeComponent;

import java.util.LinkedHashMap;
import java.util.Map;
import net.thevpc.nuts.runtime.core.repos.NutsRepositorySelector;

/**
* Created by vpc on 1/23/17.
*/
@NutsSingleton
public class DefaultNutsWorkspaceArchetypeComponent implements NutsWorkspaceArchetypeComponent {
private NutsLogger LOG;

@Override
public String getName() {
return "default";
}

@Override
public int getSupportLevel(NutsSupportLevelContext<String> criteria) {
return DEFAULT_SUPPORT + 2;
}

@Override
public void initializeWorkspace(NutsSession session) {
this.LOG = session.log().of(DefaultNutsWorkspaceArchetypeComponent.class);
DefaultNutsWorkspaceConfigManager rm = (DefaultNutsWorkspaceConfigManager) session.config();
LinkedHashMap<String, NutsAddRepositoryOptions> def = new LinkedHashMap<>();
Map<String, String> defaults = new HashMap<>();
Expand Down Expand Up @@ -82,8 +79,8 @@ public void initializeWorkspace(NutsSession session) {
// ws.repos().addRepository(d);
// }
session.imports().add(new String[]{
"net.thevpc.nuts.toolbox",
"net.thevpc"
"net.thevpc.nuts.toolbox",
"net.thevpc"
});

session.security().updateUser(NutsConstants.Users.ANONYMOUS)
Expand All @@ -94,13 +91,43 @@ public void initializeWorkspace(NutsSession session) {
//has read rights
session.security().setSession(session).addUser("user")
.setCredentials("user".toCharArray()).addPermissions(
NutsConstants.Permissions.FETCH_DESC,
NutsConstants.Permissions.FETCH_CONTENT,
NutsConstants.Permissions.DEPLOY,
NutsConstants.Permissions.UNDEPLOY,
NutsConstants.Permissions.PUSH,
NutsConstants.Permissions.SAVE
).setRemoteIdentity("contributor")
NutsConstants.Permissions.FETCH_DESC,
NutsConstants.Permissions.FETCH_CONTENT,
NutsConstants.Permissions.DEPLOY,
NutsConstants.Permissions.UNDEPLOY,
NutsConstants.Permissions.PUSH,
NutsConstants.Permissions.SAVE
).setRemoteIdentity("contributor")
.run();
}

@Override
public void startWorkspace(NutsSession session) {
NutsBootManager boot = session.boot();
boolean initializeAllPlatforms = boot.getCustomBootOption("init-platforms").getBoolean(true, false);
if (initializeAllPlatforms && boot.getCustomBootOption("init-java").getBoolean(true, false)) {
NutsWorkspaceUtils.of(session).installAllJVM();
} else {
//at least add current vm
NutsWorkspaceUtils.of(session).installCurrentJVM();
}
Boolean initScripts = boot.getCustomBootOption("init-launchers").getBoolean(true, false);
Boolean initLaunchers = boot.getCustomBootOption("init-launchers").getBoolean(true, false);
if (initScripts || initLaunchers) {
NutsWorkspaceUtils.of(session).installLaunchers(initLaunchers);
}
Boolean skipCompanions = session.boot().getBootOptions().getSkipCompanions();
if (skipCompanions == null) {
skipCompanions = false;
}
if (!skipCompanions) {
NutsWorkspaceUtils.of(session).installCompanions();
}
}

@Override
public int getSupportLevel(NutsSupportLevelContext<String> criteria) {
return DEFAULT_SUPPORT + 2;
}

}
Loading

0 comments on commit 9018b8d

Please sign in to comment.