Introduce customized JOptCommandLinePropertySource

This temporary subclass introduces the same change proposed in
spring-projects/spring-framework#693, and should be removed when that
pull request is merged and made available.
This commit is contained in:
Chris Beams 2014-11-13 10:11:07 +01:00
parent c7f7b37572
commit 0e167bed6c
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
2 changed files with 52 additions and 2 deletions

View File

@ -22,13 +22,13 @@ import io.bitsquare.btc.UserAgent;
import io.bitsquare.btc.WalletService;
import io.bitsquare.gui.ViewCB;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.util.spring.JOptCommandLinePropertySource;
import java.nio.file.Paths;
import java.util.Properties;
import joptsimple.OptionSet;
import org.springframework.core.env.JOptCommandLinePropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
@ -64,7 +64,7 @@ public class BitsquareEnvironment extends StandardEnvironment {
private final String appDataDir;
public BitsquareEnvironment(OptionSet options) {
this(new JOptCommandLinePropertySource(BITSQUARE_COMMANDLINE_PROPERTY_SOURCE_NAME, checkNotNull(options)));
this(new JOptCommandLinePropertySource(BITSQUARE_CLASSPATH_PROPERTY_SOURCE_NAME, checkNotNull(options)));
}
BitsquareEnvironment(PropertySource commandLineProperties) {

View File

@ -0,0 +1,50 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.util.spring;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import joptsimple.OptionSet;
/**
* Customizes {@link io.bitsquare.util.spring.JOptCommandLinePropertySource#getOptionValues(String)}
* to allow for proper use of {@link joptsimple.ArgumentAcceptingOptionSpec#ofType(Class)}.
* To be removed once https://github.com/spring-projects/spring-framework/pull/693 has
* been merged and made available in a release.
*/
public class JOptCommandLinePropertySource extends org.springframework.core.env.JOptCommandLinePropertySource {
public JOptCommandLinePropertySource(String name, OptionSet options) {
super(name, options);
}
@Override
public List<String> getOptionValues(String name) {
List<?> argValues = this.source.valuesOf(name);
List<String> stringArgValues = new ArrayList<>();
for (Object argValue : argValues) {
stringArgValues.add(argValue instanceof String ? (String) argValue : argValue.toString());
}
if (stringArgValues.isEmpty()) {
return (this.source.has(name) ? Collections.<String>emptyList() : null);
}
return Collections.unmodifiableList(stringArgValues);
}
}