private void printAndAddWarning(DefinitionsChildId id, String error) { printError(error); errorCollector.warning(id, error); }
private void printAndAddError(DefinitionsChildId id, String error) { printError(error); errorCollector.error(id, error); }
/** * Checks whether a README.md and a LICENSE file exists for the given definitions child id. */ private void checkDocumentation(DefinitionsChildId id) { checkFileExistenceAndSize(id, "README.md"); checkFileExistenceAndSize(id, "LICENSE"); }
} catch (IOException e) { LOGGER.debug("Could not create temp CSAR file", e); errorCollector.error("Could not create temp CSAR file"); return; for (DefinitionsChildId id : allDefinitionsChildIds) { float progress = ++elementsChecked / size; if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) { progressListener.updateProgress(progress, id.toReadableString()); } else { progressListener.updateProgress(progress); checkId(id); checkXmlSchemaValidation(id); checkReferencedQNames(id); checkPropertiesValidation(id); if (id instanceof ServiceTemplateId) { checkServiceTemplate((ServiceTemplateId) id); if (configuration.isCheckDocumentation()) { checkDocumentation(id); checkPlainConformance(id, tempCsar); checkCsar(id, tempCsar);
@GET @Path("consistencycheck") @Produces(MediaType.APPLICATION_JSON) public ConsistencyErrorCollector checkConsistency(@QueryParam("serviceTemplatesOnly") boolean serviceTemplatesOnly, @QueryParam("checkDocumentation") boolean checkDocumentation) { IRepository repo = RepositoryFactory.getRepository(); EnumSet<ConsistencyCheckerVerbosity> verbosity = EnumSet.of(ConsistencyCheckerVerbosity.NONE); ConsistencyCheckerConfiguration config = new ConsistencyCheckerConfiguration(serviceTemplatesOnly, checkDocumentation, verbosity, repo); final ConsistencyChecker consistencyChecker = new ConsistencyChecker(config); consistencyChecker.checkCorruption(); return consistencyChecker.getErrorCollector(); }
@OnMessage public void onMessage(String message, Session session) throws IOException { ObjectMapper mapper = new ObjectMapper(); ConsistencyCheckerConfiguration config = mapper.readValue(message, ConsistencyCheckerConfiguration.class); final ConsistencyChecker consistencyChecker = new ConsistencyChecker(config, this); consistencyChecker.checkCorruption(); ConsistencyErrorCollector errorList = consistencyChecker.getErrorCollector(); // Transform object to JSON and send it. this.session.getBasicRemote().sendText(mapper.writeValueAsString(errorList)); // Close the connection after the check has passed. onClose(session); }
/** * This method may be called only once during the lifecycle of this object */ public void checkCorruption() { if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_NUMBER_OF_TOSCA_COMPONENTS)) { System.out.format("Number of TOSCA definitions to check: %d\n", numberOfDefinitionsToCheck()); } checkAllDefinitions(); // some console output cleanup if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_ERRORS) && !configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) { System.out.println(); } }
/** * Checks all references QNames whether they are valid */ private void checkReferencedQNames(DefinitionsChildId id) { final QNameValidator qNameValidator = new QNameValidator(error -> printAndAddError(id, error)); try { configuration.getRepository().getDefinitions(id).getElement().accept(qNameValidator); } catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during reading of id {}", id.toReadableString(), e); printAndAddError(id, "Reading error " + e.getMessage()); } }
@Override public void visit(TImplementationArtifact artifact) { QName type = artifact.getArtifactType(); if (type == null) { errorLogger.log("type is null"); } validateQName(type); super.visit(artifact); }
/** * Checks whether the given filename exists within the given defintions child id and if the size is above a threshold (currently 100 bytes) */ private void checkFileExistenceAndSize(DefinitionsChildId id, String filename) { RepositoryFileReference repositoryFileReference = new RepositoryFileReference(id, filename); if (!configuration.getRepository().exists(repositoryFileReference)) { printAndAddWarning(id, filename + " does not exist."); return; } long size; try { size = configuration.getRepository().getSize(repositoryFileReference); } catch (IOException e) { LOGGER.debug("Could not determine size for {}", id.toReadableString(), e); printAndAddError(id, "Could not determine size, because " + e.toString()); return; } if (size < 100) { printAndAddWarning(id, filename + " has size of less then 100 bytes."); } }
public void error(@NonNull DefinitionsChildId id, @NonNull String message) { this.getElementFromList(id).addError(message); }
public void warning(@NonNull DefinitionsChildId id, @NonNull String message) { this.getElementFromList(id).addWarning(message); }
/** * Use this only in exceptional cases. Please use the other methods to provide a {@link DefinitionsChildId} * * @param message The message to log. */ public void error(@NonNull String message) { ElementErrorList element = this.errorList.get(CONFIG_Q_NAME); if (Objects.isNull(element)) { element = new ElementErrorList(CONFIGURATION_ERROR); this.errorList.put(CONFIG_Q_NAME, element); } element.addError(message); }
private void checkId(DefinitionsChildId id) { checkNamespaceUri(id); checkNcname(id, id.getXmlId().getDecoded()); }
private void checkNcname(DefinitionsChildId id, String ncname) { if (!ncname.trim().equals(ncname)) { printAndAddError(id, "local name starts or ends with white spaces"); } if (ncname.toLowerCase().contains(ARTEFACT_BE)) { printAndAddError(id, "artifact is spelled with i in American English, not artefact as in British English"); } }
private void printError(String error) { if (configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_ERRORS)) { if (!configuration.getVerbosity().contains(ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID)) { System.out.println(); } System.out.println(error); } }
private void validateQName(QName qname) { if (qname != null && StringUtils.isEmpty(qname.getNamespaceURI())) { errorLogger.log(String.format("Referenced element \"%s\" is not a full QName", qname)); } }
@Override public void visit(TEntityType.PropertiesDefinition propertiesDefinition) { final QName element = propertiesDefinition.getElement(); validateQName(element); super.visit(propertiesDefinition); }
@Override public void visit(TEntityTemplate entityTemplate) { QName type = entityTemplate.getType(); if (type == null) { errorLogger.log("type is null"); } validateQName(type); super.visit(entityTemplate); }
@Override public void visit(TDeploymentArtifact artifact) { QName type = artifact.getArtifactType(); if (type == null) { errorLogger.log("type is null"); } validateQName(type); super.visit(artifact); }