diff --git a/config/src/main/java/org/wildfly/extension/camel/config/ConfigSupport.java b/config/src/main/java/org/wildfly/extension/camel/config/ConfigSupport.java index b916fe4ae6..f71b1d8beb 100644 --- a/config/src/main/java/org/wildfly/extension/camel/config/ConfigSupport.java +++ b/config/src/main/java/org/wildfly/extension/camel/config/ConfigSupport.java @@ -51,6 +51,7 @@ import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import org.wildfly.extension.camel.config.LayerConfig.Type; +import org.wildfly.extension.camel.config.internal.IllegalStateAssertion; public class ConfigSupport { @@ -60,6 +61,8 @@ public static ConfigContext createContext(Path jbossHome, Path configuration, Do public static void applyConfigChange(Path jbossHome, List<String> configs, boolean enable) throws Exception { + IllegalStateAssertion.assertFalse(configs.isEmpty(), "No configurations specified"); + Iterator<ConfigPlugin> itsrv; ClassLoader classLoader = ConfigSupport.class.getClassLoader(); diff --git a/config/src/main/java/org/wildfly/extension/camel/config/internal/IllegalArgumentAssertion.java b/config/src/main/java/org/wildfly/extension/camel/config/internal/IllegalArgumentAssertion.java new file mode 100644 index 0000000000..9033ace2d0 --- /dev/null +++ b/config/src/main/java/org/wildfly/extension/camel/config/internal/IllegalArgumentAssertion.java @@ -0,0 +1,61 @@ +/* + * #%L + * Gravia :: Resource + * %% + * Copyright (C) 2010 - 2014 JBoss by Red Hat + * %% + * 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. + * #L% + */ +package org.wildfly.extension.camel.config.internal; + +/** + * Legal argument assertions + * + * @author thomas.diesler@jboss.com + * @since 27-Sep-2013 + */ +public final class IllegalArgumentAssertion { + + // hide ctor + private IllegalArgumentAssertion() { + } + + /** + * Throws an IllegalArgumentException when the given value is null. + */ + public static <T> T assertNotNull(T value, String name) { + if (value == null) + throw new IllegalArgumentException("Null " + name); + + return value; + } + + /** + * Throws an IllegalArgumentException when the given value is not true. + */ + public static Boolean assertTrue(Boolean value, String message) { + if (!Boolean.valueOf(value)) + throw new IllegalArgumentException(message); + return value; + } + + /** + * Throws an IllegalArgumentException when the given value is not false. + */ + public static Boolean assertFalse(Boolean value, String message) { + if (Boolean.valueOf(value)) + throw new IllegalArgumentException(message); + return value; + } +} diff --git a/config/src/main/java/org/wildfly/extension/camel/config/internal/IllegalStateAssertion.java b/config/src/main/java/org/wildfly/extension/camel/config/internal/IllegalStateAssertion.java new file mode 100644 index 0000000000..b19cf1cacb --- /dev/null +++ b/config/src/main/java/org/wildfly/extension/camel/config/internal/IllegalStateAssertion.java @@ -0,0 +1,92 @@ +/* + * #%L + * Fabric8 :: SPI + * %% + * Copyright (C) 2014 Red Hat + * %% + * 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. + * #L% + */ +package org.wildfly.extension.camel.config.internal; + +/** + * Legal state assertions + * + * @author thomas.diesler@jboss.com + * @since 18-Apr-2014 + */ +public final class IllegalStateAssertion { + + // hide ctor + private IllegalStateAssertion() { + } + + /** + * Throws an IllegalStateException when the given value is not null. + * @return the value + */ + public static <T> T assertNull(T value, String message) { + if (value != null) + throw new IllegalStateException(message); + return value; + } + + /** + * Throws an IllegalStateException when the given value is null. + * @return the value + */ + public static <T> T assertNotNull(T value, String message) { + if (value == null) + throw new IllegalStateException(message); + return value; + } + + /** + * Throws an IllegalStateException when the given value is not true. + */ + public static Boolean assertTrue(Boolean value, String message) { + if (!Boolean.valueOf(value)) + throw new IllegalStateException(message); + + return value; + } + + /** + * Throws an IllegalStateException when the given value is not false. + */ + public static Boolean assertFalse(Boolean value, String message) { + if (Boolean.valueOf(value)) + throw new IllegalStateException(message); + return value; + } + + /** + * Throws an IllegalStateException when the given values are not equal. + */ + public static <T> T assertEquals(T exp, T was, String message) { + assertNotNull(exp, message); + assertNotNull(was, message); + assertTrue(exp.equals(was), message); + return was; + } + + /** + * Throws an IllegalStateException when the given values are not equal. + */ + public static <T> T assertSame(T exp, T was, String message) { + assertNotNull(exp, message); + assertNotNull(was, message); + assertTrue(exp == was, message); + return was; + } +} diff --git a/config/src/main/java/org/wildfly/extension/camel/config/internal/Options.java b/config/src/main/java/org/wildfly/extension/camel/config/internal/Options.java index 73f437e819..aeb8ee4a05 100644 --- a/config/src/main/java/org/wildfly/extension/camel/config/internal/Options.java +++ b/config/src/main/java/org/wildfly/extension/camel/config/internal/Options.java @@ -7,9 +7,9 @@ * 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. @@ -26,7 +26,7 @@ final class Options { @Option(name = "--help", help = true) boolean help; - @Option(name = "--configs", required = true, usage = "The configurations to enable/disable") + @Option(name = "--configs", usage = "The configurations to enable/disable") String configs; @Option(name = "--enable", forbids = { "--disable" }, usage = "Enable the given configurations")