Skip to content

Commit

Permalink
20240320
Browse files Browse the repository at this point in the history
  • Loading branch information
thevpc committed Mar 20, 2024
1 parent 125614d commit a414d23
Show file tree
Hide file tree
Showing 57 changed files with 1,825 additions and 666 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.thevpc.nuts.runtime.standalone;

import net.thevpc.nuts.NId;
import net.thevpc.nuts.NStoreType;
import net.thevpc.nuts.util.NAssert;
import net.thevpc.nuts.util.NBlankable;
import net.thevpc.nuts.util.NStringUtils;

import java.util.Objects;

public class NLocationKey {
private String name;
private NId id;
private String repoUuid;
private NStoreType storeType;

public static NLocationKey of(NStoreType storeType,NId id,String name) {
return new NLocationKey(storeType, id, name, null);
}
public static NLocationKey of(NStoreType storeType,NId id,String name, String repoUuid) {
return new NLocationKey(storeType, id, name, repoUuid);
}
public static NLocationKey ofCache(NId id,String name, String repoUuid) {
return new NLocationKey(NStoreType.CACHE, id, name, repoUuid);
}

public NLocationKey(NStoreType storeType, NId id, String name, String repoUuid) {
if(NBlankable.isBlank(name)){
this.name = null;
}else {
NAssert.requireTrue(name.matches("[a-zA-Z0-9._-]"), "name matches [a-zA-Z0-9._-]");
this.name = name;
}
this.id = NAssert.requireNonBlank(id, "id");
this.storeType = NAssert.requireNonNull(storeType, "storeType");
this.repoUuid = NStringUtils.trimToNull(repoUuid);
}


public String getName() {
return name;
}

public NId getId() {
return id;
}

public String getRepoUuid() {
return repoUuid;
}

public NStoreType getStoreType() {
return storeType;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NLocationKey that = (NLocationKey) o;
return Objects.equals(name, that.name) && Objects.equals(id, that.id) && Objects.equals(repoUuid, that.repoUuid) && storeType == that.storeType;
}

@Override
public int hashCode() {
return Objects.hash(name, id, repoUuid, storeType);
}

@Override
public String toString() {
return "NLocationKey{" +
"name='" + name + '\'' +
", id=" + id +
", repoUuid='" + repoUuid + '\'' +
", storeType=" + storeType +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.thevpc.nuts.runtime.standalone;

import net.thevpc.nuts.NLocations;
import net.thevpc.nuts.NSession;
import net.thevpc.nuts.io.NPath;
import net.thevpc.nuts.util.NBlankable;

public class NWsConfDB {
public void storeStringNonBlank(NLocationKey k, String value, NSession session) {
storeString(k, value, true, session);
}

public void storeString(NLocationKey k, String value, boolean deleteIfBlank, NSession session) {
NPath path = NLocations.of(session).getStoreLocation(k.getId(), k.getStoreType(), k.getRepoUuid())
.resolve(k.getName());
if (NBlankable.isBlank(value) && deleteIfBlank) {
if (path.isRegularFile()) {
path.delete();
}
} else {
path.writeString(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public class DefaultNDefinition implements NDefinition {
public DefaultNDefinition() {
}

public DefaultNDefinition(String repoUuid, String repoName, NId id, NDescriptor descriptor, NPath content, NInstallInformation install, NId apiId, NSession session) {
public DefaultNDefinition(String repoUuid, String repoName, NId id, NDescriptor descriptor, NPath content, NInstallInformation install, NId apiId,
NDescriptor effectiveDescriptor,
NSession session) {
this.descriptor = descriptor;
this.content = content;
this.id = id;
Expand All @@ -60,6 +62,7 @@ public DefaultNDefinition(String repoUuid, String repoName, NId id, NDescriptor
this.installInformation = install;
this.repositoryUuid = repoUuid;
this.repositoryName = repoName;
this.effectiveDescriptor = effectiveDescriptor;
this.apiId = apiId;
this.session = session;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/**
* ====================================================================
* Nuts : Network Updatable Things Service
* (universal package manager)
* <br>
* is a new Open Source Package Manager to help install packages and libraries
* for runtime execution. Nuts is the ultimate companion for maven (and other
* build managers) as it helps installing all package dependencies at runtime.
* Nuts is not tied to java and is a good choice to share shell scripts and
* other 'things' . Its based on an extensible architecture to help supporting a
* large range of sub managers / repositories.
* <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
* http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
* or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
* <br> ====================================================================
*/
package net.thevpc.nuts.runtime.standalone.definition;

import net.thevpc.nuts.*;
import net.thevpc.nuts.io.NPath;
import net.thevpc.nuts.runtime.standalone.io.cache.CachedSupplier;
import net.thevpc.nuts.util.NAssert;
import net.thevpc.nuts.util.NMsg;
import net.thevpc.nuts.util.NOptional;

import java.util.Objects;
import java.util.function.Supplier;

/**
* Created by vpc on 1/6/17.
*/
public class DefaultNDefinitionRef implements NDefinition {

private NId id;
private CachedSupplier<NDescriptor> descriptor;
private CachedSupplier<String> repositoryUuid;
private CachedSupplier<String> repositoryName;

private CachedSupplier<NPath> content;
private CachedSupplier<NInstallInformation> installInformation;
private CachedSupplier<NDependencies> dependencies;
private CachedSupplier<NDescriptor> effectiveDescriptor;
private CachedSupplier<NId> apiId = null;
private transient NSession session;

public DefaultNDefinitionRef() {
}

public DefaultNDefinitionRef(CachedSupplier<String> repositoryUuid, CachedSupplier<String> repositoryName, NId id, CachedSupplier<NDescriptor> descriptor, CachedSupplier<NPath> content,
CachedSupplier<NInstallInformation> install,
CachedSupplier<NId> apiId,
CachedSupplier<NDependencies> dependencies,
CachedSupplier<NDescriptor> effectiveDescriptor,
NSession session) {
this.descriptor = NAssert.requireNonNull(descriptor, "descriptor", session);
this.content = NAssert.requireNonNull(content, "content", session);
this.id = NAssert.requireNonNull(id, "id", session);
if (!id.isLongId()) {
throw new NIllegalArgumentException(session, NMsg.ofC("id should not have query defined in descriptors : %s", id));
}
this.installInformation = NAssert.requireNonNull(install, "installInformation", session);
this.repositoryUuid = NAssert.requireNonNull(repositoryUuid, "repositoryUuid", session);
this.repositoryName = NAssert.requireNonNull(repositoryName, "repositoryName", session);
this.dependencies = NAssert.requireNonNull(dependencies, "dependencies", session);
this.effectiveDescriptor = NAssert.requireNonNull(effectiveDescriptor, "effectiveDescriptor", session);
this.apiId = NAssert.requireNonNull(apiId, "apiId", session);
this.session = session;
}

@Override
public String getRepositoryUuid() {
return repositoryUuid.getValue();
}

@Override
public String getRepositoryName() {
return repositoryName.getValue();
}

@Override
public NId getId() {
return id;
}

public boolean isTemporary() {
NPath c = content.getValue();
return c != null && c.isUserTemporary();
}

public NDescriptor getDescriptor() {
return descriptor.getValue();
}

@Override
public String toString() {
return "Definition{"
+ " id=" + id
+ ", content=" + content
+ '}';
}

public DefaultNDefinition copy() {
return new DefaultNDefinition(this, session);
}

@Override
public NOptional<NPath> getContent() {
NPath c = content.getValue();
return NOptional.of(c, s -> NMsg.ofC("content not found for id %s", getId()))
.setSession(session);
}

@Override
public NOptional<NDescriptor> getEffectiveDescriptor() {
NDescriptor c = effectiveDescriptor.getValue();
return NOptional.of(c, s -> NMsg.ofC("unable to get effectiveDescriptor for id %s. You need to call search.setEffective(...) first.", getId()))
.setSession(session);
}

@Override
public NOptional<NInstallInformation> getInstallInformation() {
return NOptional.of(installInformation.getValue(), s -> NMsg.ofC("unable to get install information for id %s.", getId()))
.setSession(session);
}

@Override
public NOptional<NDependencies> getDependencies() {
return NOptional.of(dependencies.getValue(), s -> NMsg.ofC("unable to get dependencies for id %s. You need to call search.setDependencies(...) first.", getId()))
.setSession(session);
}

@Override
public int compareTo(NDefinition n2) {
if (n2 == null) {
return 1;
}
if (!(n2 instanceof DefaultNDefinitionRef)) {
return -1;
}
NId o1 = getId();
NId o2 = n2.getId();
if (o1 == null || o2 == null) {
if (o1 == o2) {
return 0;
}
if (o1 == null) {
return -1;
}
return 1;
}
return o1.compareTo(o2);
}

@Override
public int hashCode() {
int hash = 5;
hash = 37 * hash + Objects.hashCode(this.id);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final DefaultNDefinitionRef other = (DefaultNDefinitionRef) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}

@Override
public NId getApiId() {
return apiId.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public NElement createElement(NDefinition o, Type typeOfSrc, NElementFactoryCont
@Override
public NDefinition createObject(NElement o, Type typeOfResult, NElementFactoryContext context) {
NDefinition d = context.defaultElementToObject(o, DefaultNDefinition.class);
//pass the session the the instance
//pass the session the instance
return new DefaultNDefinition(d, context.getSession());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public static ProcessExecHelper ofDefinition(NDefinition nutMainFile,
NPath storeFolder = nutMainFile.getInstallInformation().get(session).getInstallFolder();
HashMap<String, String> map = new HashMap<>();
HashMap<String, String> envmap = new HashMap<>();
Path nutsJarFile = NFetchCommand.ofNutsApi(session).getResultPath();
NPath nutsJarFile = NFetchCommand.ofNutsApi(session).getResultPath();
if (nutsJarFile != null) {
map.put("nuts.jar", nutsJarFile.toAbsolutePath().normalize().toString());
map.put("nuts.jar", nutsJarFile.normalize().toString());
}
map.put("nuts.artifact", id.toString());
map.put("nuts.file", nutMainFile.getContent().flatMap(NPath::toPath).map(Object::toString).orNull());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.thevpc.nuts.runtime.standalone.io.cache;


public interface CachedSupplier<T> {
enum NCacheLevel {
NONE,
MEM,
STORE
}

T getValue();
T getValue(NCacheLevel level);
}
Loading

0 comments on commit a414d23

Please sign in to comment.