Skip to content
Permalink
Browse files
BATCHEE-121 ensure cli can use default values for options
  • Loading branch information
rmannibucau committed Jun 23, 2017
1 parent a07bf2c commit fa48787aac9c8656f35ad9033f053707004dfb3b
Showing 6 changed files with 115 additions and 4 deletions.
@@ -45,6 +45,15 @@
<outputDirectory>conf/</outputDirectory>
<includes>
<include>logging.properties</include>
<include>batchee-cli_openejb.properties</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>${project.build.outputDirectory}/openejb</directory>
<outputDirectory>conf/</outputDirectory>
<includes>
<include>batchee-cli.properties</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
@@ -48,6 +48,14 @@
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>${project.build.outputDirectory}/default</directory>
<outputDirectory>conf/</outputDirectory>
<includes>
<include>batchee-cli.properties</include>
</includes>
<lineEnding>unix</lineEnding>
</fileSet>
<fileSet>
<directory>${project.build.directory}/</directory>
<outputDirectory>bin/</outputDirectory>
@@ -40,6 +40,10 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -50,6 +54,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.TreeMap;

@@ -112,6 +117,49 @@ public static void main(final String[] args) {
final Collection<String> newArgs = new ArrayList<String>(asList(args));
newArgs.remove(newArgs.iterator().next());

final File cliConf;
String home = System.getProperty("batchee.home");
if (home == null) {
final String conf = System.getProperty("batchee.cli.configuration");
if (conf == null) {
cliConf = null;
} else {
cliConf = new File(conf);
}
} else {
cliConf = new File(home, "conf/batchee-cli.properties");
}
if (cliConf != null && cliConf.exists()) {
final Properties properties = new Properties() {{
Reader reader = null;
try {
reader = new FileReader(cliConf);
load(reader);
} catch (IOException e) {
throw new IllegalArgumentException(e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
// no-op
}
}
}
}};
for (final String key : properties.stringPropertyNames()) {
if (key.startsWith("_arguments.")) { // /!\ added whatever passed values are
newArgs.add(properties.getProperty(key));
} else {
final String opt = "-" + key;
if (!newArgs.contains(opt)) {
newArgs.add(opt);
newArgs.add(properties.getProperty(key));
}
}
}
}

final CommandLineParser parser = new DefaultParser();
try {
final CommandLine line = parser.parse(options, newArgs.toArray(new String[newArgs.size()]));
@@ -175,10 +175,6 @@ public final void run() {
final Lifecycle<Object> lifecycleInstance;
final Object state;

if (lifecycle == null) {
lifecycle = System.getProperty("org.apache.batchee.cli.lifecycle");
}

if (lifecycle != null) {
lifecycleInstance = createLifecycle(loader);
state = lifecycleInstance.start();
@@ -0,0 +1,24 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.


#
# You can put here default options you want inherited by all commands (without trailing iphen).
#

# ex:
# lifecycle = openejb
# sharedLibs = /opt/batch/libs
@@ -0,0 +1,26 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.


#
# You can put here default options you want inherited by all commands (without trailing iphen).
#

# ex:
# sharedLibs = /opt/batch/libs

lifecycle = openejb

0 comments on commit fa48787

Please sign in to comment.