public static void bombUnless(boolean check, String msg) { bombIf(!check, msg); }
public MaterialRevision(Material material, boolean changed, List<Modification> modifications) { bombIfNull(modifications, "modifications cannot be null"); bombIf(modifications.contains(null), "modifications cannot be null"); this.material = material; this.changed = changed; this.modifications = new Modifications(modifications); }
public static void bombIfNull(Object o, String msg) { bombIf(o == null, msg); }
private void ensureNoStagesDefined(CaseInsensitiveString newTemplateName) { bombIf(!isEmpty(), format("Cannot set template '%s' on pipeline '%s' because it already has stages defined", newTemplateName, name)); }
private ConfigTag configTag(Class<?> type) { bombIf(!ConfigCache.isAnnotationPresent(type, ConfigTag.class), "Invalid type '" + type + "' to autoload. Must have ConfigTag annotation."); return ConfigCache.annotationFor(type, ConfigTag.class); }
private void verifyUniqueName(JobConfig jobConfig) { bombIf(containsName(jobConfig.name()), String.format("You have defined multiple Jobs called '%s'. Job names are case-insensitive and must be unique.", jobConfig.name())); }
private boolean atElement() { AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class); if (attributeAwareConfigTag != null) { final String attribute = attributeAwareConfigTag.attribute(); bombIf(isBlank(attribute), format("Type '%s' has invalid configuration for @AttributeAwareConfigTag. It must have `attribute` with non blank value.", aClass.getName())); bombIf(!hasAttribute(attribute), format("Expected attribute `%s` to be present for %s.", attribute, configUtil.elementOutput(e))); return configUtil.atTag(e, attributeAwareConfigTag.value()); } ConfigTag configTag = annotationFor(aClass, ConfigTag.class); if (configTag == null) { return false; } String tag = configTag.value(); return configUtil.atTag(e, tag); }
public SubversionRevision checkoutTo(ConsoleOutputStreamConsumer outputStreamConsumer, File targetFolder, SubversionRevision revision) { CommandLine command = svn(true) .withArgs("checkout", "--non-interactive", "-r", revision.getRevision()) .withArg(repositoryUrl) .withArg(targetFolder.getAbsolutePath()); executeCommand(command, outputStreamConsumer); bombIf(!targetFolder.exists(), "Folder was not created or does not exist.. something broken"); return null; }
public boolean remove(Role role) { bombIf(!this.contains(role), "Role '" + CaseInsensitiveString.str(role.getName()) + "' does not exist."); return super.remove(role); }
@SuppressWarnings("unchecked") private Collection parseCollection(Element e, Class<?> collectionType) { ConfigCollection collection = collectionType.getAnnotation(ConfigCollection.class); Class<?> type = collection.value(); Object o = newInstance(collectionType); bombUnless(o instanceof Collection, "Must be some sort of list. Was: " + collectionType.getName()); Collection baseCollection = (Collection) o; for (Element childElement : (List<Element>) e.getChildren()) { if (isInCollection(childElement, type)) { baseCollection.add(parseType(childElement, type)); } } bombIf(baseCollection.size() < collection.minimum(), "Required at least " + collection.minimum() + " subelements to '" + e.getName() + "'. " + "Found " + baseCollection.size() + "."); return baseCollection; }
public String toXmlPartial(Object domainObject) { bombIf(!isAnnotationPresent(domainObject.getClass(), ConfigTag.class), "Object " + domainObject + " does not have a ConfigTag"); Element element = elementFor(domainObject.getClass(), configCache); write(domainObject, element, configCache, registry); if (isAnnotationPresent(domainObject.getClass(), ConfigCollection.class) && domainObject instanceof Collection) { for (Object item : (Collection) domainObject) { if (isAnnotationPresent(item.getClass(), ConfigCollection.class) && item instanceof Collection) { new ExplicitCollectionXmlFieldWithValue(domainObject.getClass(), null, (Collection) item, configCache, registry).populate(element); continue; } Element childElement = elementFor(item.getClass(), configCache); element.addContent(childElement); write(item, childElement, configCache, registry); } } try { ByteArrayOutputStream output = new ByteArrayOutputStream(); XmlUtils.writeXml(element, output); return output.toString(); } catch (IOException e) { throw bomb("Unable to write xml to String"); } }
@SuppressWarnings("unchecked") private void parseCollection(Collection collection) { ConfigCollection collectionAnnotation = annotationFor(aClass, ConfigCollection.class); Class<?> elementType = collectionAnnotation.value(); for (Element childElement : (List<Element>) e.getChildren()) { if (isInCollection(childElement, elementType)) { Class<?> collectionType = findConcreteType(childElement, elementType); collection.add(classParser(childElement, collectionType, configCache, new GoCipher(), registry, configReferenceElements).parse()); } } int minimumSize = collectionAnnotation.minimum(); bombIf(collection.size() < minimumSize, "Required at least " + minimumSize + " subelements to '" + e.getName() + "'. " + "Found " + collection.size() + "."); }
public void onMessage(MaterialUpdateMessage message) { final Material material = message.getMaterial(); if (maintenanceModeService.isMaintenanceMode()) { LOGGER.debug("[Maintenance Mode] GoCD server is in 'maintenance' mode, skip performing MDU for material {}.", material); channel.post(new MaterialUpdateSkippedMessage(material, message.trackingId())); return; } try { maintenanceModeService.mduStartedForMaterial(material); mduPerformanceLogger.pickedUpMaterialForMDU(message.trackingId(), material); bombIf(diskSpaceMonitor.isLowOnDisk(), "GoCD server is too low on disk to continue with material update"); updater.updateMaterial(material); mduPerformanceLogger.postingMessageAboutMDUCompletion(message.trackingId(), material); channel.post(new MaterialUpdateSuccessfulMessage(material, message.trackingId())); //This should happen only if the transaction is committed. } catch (Exception e) { channel.post(new MaterialUpdateFailedMessage(material, message.trackingId(), e)); mduPerformanceLogger.postingMessageAboutMDUFailure(message.trackingId(), material); } finally { maintenanceModeService.mduFinishedForMaterial(material); } } }