Skip to content

Commit

Permalink
[resolves wildfly-extras#563] Add executable to enable/disable the ca…
Browse files Browse the repository at this point in the history
…mel subsytem
  • Loading branch information
Thomas Diesler committed Jul 6, 2015
1 parent fd0b685 commit c283df8
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand Down

0 comments on commit c283df8

Please sign in to comment.