use of mpern.sap.commerce.ccv2.model.Aspect in project commerce-gradle-plugin by SAP.
the class UseConfigValidator method validateProperties.
private List<Error> validateProperties(Manifest manifest) {
List<Error> errors = new ArrayList<>();
for (int i = 0; i < manifest.useConfig.properties.size(); i++) {
Properties properties = manifest.useConfig.properties.get(i);
Tuple2<Path, List<Error>> result = validateAndNormalizePath(this.projectRoot, String.format("useConfig.properties[%d]", i), properties.location);
errors.addAll(result.getSecond());
if (!properties.aspect.isEmpty() && !ALLOWED_ASPECTS.contains(properties.aspect)) {
errors.add(new Error.Builder().setLocation("useConfig.properties[%d]", i).setMessage("Aspect `%s` not supported", properties.aspect).setCode("E-002").createError());
}
if (!properties.persona.isEmpty() && !ALLOWED_PERSONAS.contains(properties.persona)) {
errors.add(new Error.Builder().setLocation("useConfig.properties[%d]", i).setMessage("Persona `%s` not supported", properties.persona).setCode("E-008").createError());
}
if (result.getFirst() != null) {
try (InputStream stream = Files.newInputStream(result.getFirst())) {
new java.util.Properties().load(stream);
} catch (Exception e) {
errors.add(new Error.Builder().setLocation("useConfig.properties[%d]", i).setMessage("`%s` is not a valid Java properties file", properties.location).setCode("E-010").createError());
}
try {
// ref. java doc of java.util.Properties.load(InputStream)
String defaultCharset = String.join("\n", Files.readAllLines(result.getFirst(), StandardCharsets.ISO_8859_1));
String utf8 = String.join("\n", Files.readAllLines(result.getFirst(), StandardCharsets.UTF_8));
if (!defaultCharset.equals(utf8)) {
errors.add(new Error.Builder().setLocation("useConfig.properties[%d]", i).setLevel(Level.WARNING).setMessage("`%s` seems to use a different charset than ISO 8859-1. This might lead to corrupted properties after build and deployment.", properties.location).setCode("W-002").createError());
}
} catch (IOException e) {
// shouldn't happen
}
}
}
return errors;
}
use of mpern.sap.commerce.ccv2.model.Aspect in project commerce-gradle-plugin by SAP.
the class AspectValidator method validate.
@Override
public List<Error> validate(Manifest manifest) throws Exception {
List<Error> errors = new ArrayList<>();
Map<String, Integer> seenAspects = new HashMap<>();
for (int aspectIndex = 0; aspectIndex < manifest.aspects.size(); aspectIndex++) {
Aspect aspect = manifest.aspects.get(aspectIndex);
if (!Aspect.ALLOWED_ASPECTS.contains(aspect.name)) {
errors.add(new Error.Builder().setLocation("aspects[?name == '%s']", aspect.name).setMessage("Aspect `%s` not supported", aspect.name).setCode("E-002").createError());
} else {
Integer previous = seenAspects.put(aspect.name, aspectIndex);
if (previous != null) {
errors.add(new Error.Builder().setLocation("aspects[%d]", aspectIndex).setMessage("Aspect `%s` configured more than once. Previous location: `aspects[%d]", aspect.name, previous).setCode("E-003").createError());
}
errors.addAll(new SharedPropertyValidator(String.format("aspects[?name == '%s'].", aspect.name)).validateProperties(aspect.properties));
if (ADMIN_ASPECT.equals(aspect.name)) {
if (!aspect.webapps.isEmpty()) {
errors.add(new Error.Builder().setLocation("aspects[?name == '%s']", aspect.name).setMessage("Webapps not allowed for aspect `admin`").setCode("E-007").createError());
}
} else {
Map<String, Integer> loadedExtensions = new HashMap<>();
Map<String, Integer> webroots = new HashMap<>();
for (int j = 0; j < aspect.webapps.size(); j++) {
Webapp w = aspect.webapps.get(j);
previous = loadedExtensions.put(w.name, j);
if (previous != null) {
errors.add(new Error.Builder().setLocation("aspects[?name == '%s'].webapps[%d]", aspect.name, j).setMessage("Extension `%s` configured more than once. Previous location: `aspects[?name == '%s'].webapps[%d]`", w.name, aspect.name, previous).setCode("E-004").createError());
}
previous = webroots.put(w.contextPath, j);
if (previous != null) {
errors.add(new Error.Builder().setLocation("aspects[?name == '%s'].webapps[%d]", aspect.name, j).setMessage("Context path `%s` configured more than once! Previous location: `aspects[?name == '%s'].webapps[%d]`", w.contextPath, aspect.name, previous).setCode("E-005").createError());
}
if (!w.contextPath.isEmpty() && !w.contextPath.startsWith("/")) {
errors.add(new Error.Builder().setLocation("aspects[?name == '%s'].webapps[%d]", aspect.name, j).setMessage("contextPath `%s` must start with `/`", w.contextPath).setCode("E-006").createError());
}
}
}
}
}
return errors;
}
use of mpern.sap.commerce.ccv2.model.Aspect in project commerce-gradle-plugin by SAP.
the class WebrootValidator method validate.
@Override
public List<Error> validate(Manifest manifest) throws Exception {
Map<String, Set<String>> occurences = new HashMap<>();
for (int i = 0; i < manifest.properties.size(); i++) {
Property p = manifest.properties.get(i);
String location = String.format("properties[%d]", i);
checkProperty(p.key, location, occurences);
}
for (int i = 0; i < manifest.useConfig.properties.size(); i++) {
Properties properties = manifest.useConfig.properties.get(i);
Tuple2<Path, List<Error>> result = ValidationUtils.validateAndNormalizePath(this.projectRoot, "", properties.location);
if (result.getFirst() != null) {
try (InputStream stream = Files.newInputStream(result.getFirst())) {
java.util.Properties props = new java.util.Properties();
props.load(stream);
String location = String.format("useConfig.properties[%d].location (%s)", i, properties.location);
for (Map.Entry<Object, Object> entry : props.entrySet()) {
checkProperty((String) entry.getKey(), location, occurences);
}
} catch (IOException e) {
// ignore
}
}
}
for (Aspect aspect : manifest.aspects) {
for (int i = 0; i < aspect.properties.size(); i++) {
Property p = aspect.properties.get(i);
String location = String.format("aspects[?name == '%s'].properties[%d]", aspect.name, i);
checkProperty(p.key, location, occurences);
}
}
if (occurences.isEmpty()) {
return Collections.emptyList();
} else {
List<Error> errors = new ArrayList<>();
for (Map.Entry<String, Set<String>> errorEntry : occurences.entrySet()) {
errors.add(new Error.Builder().setLocation(errorEntry.getKey()).setCode("E-017").setMessage("Do not configure webroots in properties.\nFaulty properties:\n- " + String.join("\n -", errorEntry.getValue())).createError());
}
return errors;
}
}
use of mpern.sap.commerce.ccv2.model.Aspect in project commerce-gradle-plugin by SAP.
the class AspectWebappValidator method validateWithExtensions.
@Override
protected List<Error> validateWithExtensions(Manifest manifest, ExtensionsResolver.Result effectiveExtensions) {
List<Error> errors = new ArrayList<>();
Set<String> extensionNames = effectiveExtensions.extensions.stream().map(e -> e.name).collect(Collectors.toSet());
for (int i = 0; i < manifest.aspects.size(); i++) {
Aspect aspect = manifest.aspects.get(i);
if (ADMIN_ASPECT.equals(aspect.name)) {
continue;
}
for (int j = 0; j < aspect.webapps.size(); j++) {
Webapp w = aspect.webapps.get(j);
// extension does not exist / not loaded
if (!extensionNames.contains(w.name)) {
errors.add(new Error.Builder().setLocation("aspects[?name == '%s'].webapps[%d]", aspect.name, i).setMessage("Extension `%s` not available.\n%s", w.name, formatLocations(effectiveExtensions.locations)).setCode("E-001").createError());
}
}
}
return errors;
}
Aggregations