Skip to content

Commit

Permalink
SWARM-1211 - Clean up warnings and deprecations. (thorntail#422)
Browse files Browse the repository at this point in the history
Motivation
----------

Warnings and deprecations can hide important things if
we're used to seeing them so much that we begin to ignore
them.

Modifications
-------------

Some places the warnings were un-fixable beyond a @SuppressWarnings,
but other places we were definitely being too loosey-goosey with things
that could be fixed up.

Result
------

Cleaner build.
  • Loading branch information
bobmcwhirter authored and kenfinnigan committed Mar 16, 2017
1 parent 6c42e46 commit dfa87f2
Show file tree
Hide file tree
Showing 54 changed files with 207 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public ArtifactSpec resolve(ArtifactSpec spec) {
@Override
public Set<ArtifactSpec> resolveAll(final Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) {
if (specs.isEmpty()) {
return Collections.EMPTY_SET;
return Collections.emptySet();
}

MavenResolutionStrategy transitivityStrategy = (transitive ? TransitiveStrategy.INSTANCE : NonTransitiveStrategy.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void read(URL url) throws IOException {
}
}

@SuppressWarnings("unchecked")
protected void read(InputStream in) throws IOException {
Yaml yaml = new Yaml();
Map data = (Map) yaml.load(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* @author Heiko Braun
* @since 18/07/16
*/
public class SystemDependencyResolution implements DependencyResolution {
class SystemDependencyResolution implements DependencyResolution {


public SystemDependencyResolution() {
SystemDependencyResolution() {
final String classpathProp = System.getProperty("java.class.path");
final String javaHomProp = System.getProperty("java.home");
final String userDirProp = System.getProperty("user.dir");
Expand All @@ -27,7 +27,7 @@ public SystemDependencyResolution() {
this.useGradleRepo = classpathProp.contains(File.separator + ".gradle");

this.classpath = Arrays.asList(classpathProp.split(File.pathSeparator));
this.testClasspath = testClasspatProp != null ? Arrays.asList(testClasspatProp.split(File.pathSeparator)) : Collections.EMPTY_LIST;
this.testClasspath = testClasspatProp != null ? Arrays.asList(testClasspatProp.split(File.pathSeparator)) : Collections.emptyList();

this.pwd = userDirProp;
this.javaHome = javaHomProp.endsWith(JRE) ? javaHomProp.substring(0, javaHomProp.lastIndexOf(JRE)) : javaHomProp;
Expand All @@ -44,7 +44,7 @@ public Set<String> resolve(List<String> exclusions) throws IOException {
ApplicationEnvironment env = ApplicationEnvironment.get();
Set<String> classpathElements = new HashSet<>();
Set<String> providedGAVs = new HashSet<>();
List<String> testClasspathElements = testClasspath != null ? testClasspath : Collections.EMPTY_LIST;
List<String> testClasspathElements = testClasspath != null ? testClasspath : Collections.emptyList();

for (final String element : classpath) {
if (!element.startsWith(javaHome) && !element.startsWith(pwd + File.separatorChar) && !element.endsWith(".pom")) {
Expand Down Expand Up @@ -80,17 +80,15 @@ public Set<String> resolve(List<String> exclusions) throws IOException {
return archivesPaths;
}

private static final String JAR = ".jar";

private static final String JRE = "jre";

final List<String> classpath;
private final List<String> classpath;

final String javaHome;
private final String javaHome;

final String pwd;
private final String pwd;

final List<String> testClasspath;
private final List<String> testClasspath;

private final boolean useGradleRepo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void read(URL url) throws IOException {
}
}

@SuppressWarnings("unchecked")
public void read(InputStream in) throws IOException {
Yaml yaml = new Yaml();
Map data = (Map) yaml.load(in);
Expand Down Expand Up @@ -98,7 +99,7 @@ public void write(Path path) throws IOException {

@Override
public String toString() {
Map data = new LinkedHashMap() {{
Map<String,Object> data = new LinkedHashMap<String,Object>() {{
if (asset != null) {
put(ASSET, asset);
}
Expand All @@ -119,7 +120,7 @@ public String toString() {
return yaml.dump(data);
}

protected void setupProperties() {
private void setupProperties() {
// enumerate all properties, not just those with string
// values, because Gradle (and others) can set non-string
// values for things like swarm.http.port (integer)
Expand Down Expand Up @@ -185,6 +186,7 @@ public void bundleDependencies(boolean bundleDependencies) {
this.bundleDependencies = bundleDependencies;
}

@SuppressWarnings("unused")
public boolean isBundleDependencies() {
if (this.bundleDependencies == null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public class GradleResolver implements MavenResolver {
private final String gradleCachePath;
private final List<String> remoteRepositories = new LinkedList();
private final List<String> remoteRepositories = new LinkedList<>();

public GradleResolver(String gradleCachePath) {
this.gradleCachePath = gradleCachePath;
Expand Down
1 change: 1 addition & 0 deletions core/container/src/main/java/org/wildfly/swarm/Swarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ public ConfigView configView() {
* @return The {@code ConfigView} through a deprecated interface.
* @see #configView()
*/
@SuppressWarnings("deprecation")
@Deprecated
public StageConfig stageConfig() {
return this.configView.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public List asList() {
}

public Map asMap() {
Map map = new HashMap();
Map<String,Object> map = new HashMap<>();

this.children.entrySet()
.forEach(entry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private void loadProjectStages(URL url) throws IOException {
loadProjectStages(url.openStream());
}

@SuppressWarnings("unchecked")
private void loadProjectStages(InputStream inputStream) {
Yaml yaml = new Yaml();
Iterable<Object> docs = yaml.loadAll(inputStream);
Expand All @@ -163,6 +164,7 @@ private void loadYamlProjectConfig(String name, URL url) throws IOException {
loadYamlProjectConfig(name, url.openStream());
}

@SuppressWarnings("unchecked")
private void loadYamlProjectConfig(String name, InputStream inputStream) {
Yaml yaml = new Yaml();
Map<String, ?> doc = (Map<String, ?>) yaml.load(inputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public List<ConfigurableHandle> configurables() {
return this.configurables;
}

@SuppressWarnings("unchecked")
protected <T> void configure(ConfigurableHandle configurable) throws Exception {
try (AutoCloseable handle = Performance.accumulate("ConfigurableManager#configure")) {
Resolver<?> resolver = this.configView.resolve(configurable.key());
Expand Down Expand Up @@ -164,7 +165,7 @@ private Resolver<Map> mapResolver(Resolver<String> resolver, ConfigKey key) {

private Converter<Map> mapConverter(ConfigKey key) {
return (ignored) -> {
Map map = new HashMap();
Map<String,Object> map = new HashMap<>();
Set<SimpleKey> subKeys = this.configView.simpleSubkeys(key);

for (SimpleKey subKey : subKeys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ public Class<?> type() throws IllegalAccessException {
return this.field.getType();
}

@SuppressWarnings("unchecked")
@Override
public <T> void set(T value) throws IllegalAccessException {
if (isDefaultable()) {
((Defaultable) this.field.get(this.instance)).set(value);
((Defaultable<T>) this.field.get(this.instance)).set(value);
} else {
this.field.set(this.instance, value);
}
}

@SuppressWarnings("unchecked")
@Override
public <T> T currentValue() throws IllegalAccessException {
Object value = this.field.get(this.instance);
if (value instanceof Defaultable) {
return (T) ((Defaultable) value).get();
return ((Defaultable<T>) value).get();
}
return (T) value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void deploy(Archive<?> deployment) throws DeploymentException {
// check for "org.wildfly.swarm.allDependencies" flag
// see DependenciesContainer#addAllDependencies()
if (deployment instanceof DependenciesContainer) {
DependenciesContainer depContainer = (DependenciesContainer) deployment;
DependenciesContainer<?> depContainer = (DependenciesContainer) deployment;
if (depContainer.hasMarker(DependenciesContainer.ALL_DEPENDENCIES_MARKER)) {
if (!depContainer.hasMarker(ALL_DEPENDENCIES_ADDED_MARKER)) {
ApplicationEnvironment appEnv = ApplicationEnvironment.get();
Expand All @@ -181,7 +181,7 @@ public void deploy(Archive<?> deployment) throws DeploymentException {
depContainer.addAsLibrary(artifactLookup.artifact(gav));
}
} else {
Set<String> paths = appEnv.resolveDependencies(Collections.EMPTY_LIST);
Set<String> paths = appEnv.resolveDependencies(Collections.emptyList());
for (String path : paths) {
final File pathFile = new File(path);
if (path.endsWith(".jar")) {
Expand Down Expand Up @@ -294,12 +294,13 @@ public void deploy(Archive<?> deployment) throws DeploymentException {
}
}

@SuppressWarnings("unused")
@PreDestroy
void stop() {
for (Closeable each : this.mountPoints) {
try {
each.close();
} catch (IOException e) {
} catch (IOException ignored) {
}
}

Expand All @@ -309,25 +310,32 @@ void stop() {

private String defaultDeploymentType;

@SuppressWarnings("unused")
@Inject
private ModelControllerClient client;

@SuppressWarnings("unused")
@Inject
private SimpleContentProvider contentProvider;

@SuppressWarnings("unused")
@Inject
private TempFileProvider tempFileProvider;

@SuppressWarnings("unused")
@Inject
private DefaultDeploymentCreator defaultDeploymentCreator;

private final List<Closeable> mountPoints = new ArrayList<>();

@SuppressWarnings("unused")
private boolean debug = false;

@SuppressWarnings("unused")
@Inject
private Instance<ArchivePreparer> archivePreparers;

@SuppressWarnings("unused")
@Inject
private Instance<ArchiveMetadataProcessor> archiveMetadataProcessors;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public ConfigViewProducingExtension(ConfigView configView) {
this.configView = configView;
}

@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
try (AutoCloseable handle = Performance.time("ConfigViewProducingExtension.afterBeanDiscovery")) {
CommonBean<ConfigView> configViewBean = CommonBeanBuilder.newBuilder()
CommonBean<ConfigView> configViewBean = CommonBeanBuilder.newBuilder(ConfigView.class)
.beanClass(ConfigViewProducingExtension.class)
.scope(Singleton.class)
.addQualifier(DefaultLiteral.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Double produceDoubleConfigValue(InjectionPoint injectionPoint) {
return resolve(injectionPoint, Double.class);
}

@SuppressWarnings("unchecked")
@ConfigurationValue("")
@Dependent
@Produces
Expand All @@ -106,6 +107,7 @@ <T> Optional<T> produceOptionalConfigValue(InjectionPoint injectionPoint) {
return Optional.ofNullable(resolve(injectionPoint, valueType));
}

@SuppressWarnings("unchecked")
private <T> Class<T> unwrapType(Type type) {
if (type instanceof ParameterizedType) {
type = ((ParameterizedType) type).getRawType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ public FractionProducingExtension(Collection<Fraction> explicitlyInstalled, Conf
*
* @param abd AfterBeanDiscovery
*/
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
try (AutoCloseable handle = Performance.time("FractionProducingExtension.afterBeanDiscovery")) {
Set<Type> preExistingFractionClasses = new HashSet<>();

try (AutoCloseable pre = Performance.time("FractionProducingExtension.afterBeanDiscovery - pre-existing")) {
for (Fraction fraction : explicitlyInstalledFractions) {
for (Fraction<?> fraction : explicitlyInstalledFractions) {
try {
abd.addBean(new ConfigurableFractionBean<>(fraction, this.configurableManager));
} catch (Exception e) {
Expand All @@ -93,21 +94,21 @@ void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManage
Set<Class<? extends Fraction>> fractionClasses = uninstalledFractionClasses(preExistingFractionClasses);

try (AutoCloseable defaultHandle = Performance.time("FractionProducingExtension.afterBeanDiscovery - default")) {
fractionClasses.stream()
.forEach((cls) -> {
try {
abd.addBean(new ConfigurableFractionBean<>(cls, this.configurableManager));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
fractionClasses.forEach((cls) -> {
try {
abd.addBean(new ConfigurableFractionBean<>(cls, this.configurableManager));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
}
}

@SuppressWarnings("unchecked")
private Set<Class<? extends Fraction>> uninstalledFractionClasses(Set<Type> installedClasses) throws ModuleLoadException, IOException, ClassNotFoundException {

Set<String> installedClassNames = installedClasses.stream().map(e -> e.getTypeName()).collect(Collectors.toSet());
Set<String> installedClassNames = installedClasses.stream().map(Type::getTypeName).collect(Collectors.toSet());

List<String> moduleNames = ApplicationEnvironment.get().bootstrapModules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,24 @@ public OutboundSocketBindingExtension(List<OutboundSocketBindingRequest> binding
this.bindings = bindings;
}

@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
try (AutoCloseable handle = Performance.time("OutboundSocketBindingExtension.afterBeanDiscovery")) {
for (OutboundSocketBindingRequest each : this.bindings) {

Supplier<Customizer> customizerSupplier = () -> {
return new Customizer() {
@Override
public void customize() {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
Supplier<Customizer> customizerSupplier = () -> (Customizer) () -> {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);

groups.stream()
.map((Bean e) -> {
CreationalContext<SocketBindingGroup> ctx = beanManager.createCreationalContext(e);
return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
})
.filter(group -> group.name().equals(each.socketBindingGroup()))
.findFirst()
.ifPresent((group) -> {
group.outboundSocketBinding(each.outboundSocketBinding());
});
}
};
groups.stream()
.map((Bean<?> e) -> {
CreationalContext<?> ctx = beanManager.createCreationalContext(e);
return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
})
.filter(group -> group.name().equals(each.socketBindingGroup()))
.findFirst()
.ifPresent((group) -> group.outboundSocketBinding(each.outboundSocketBinding()));
};
CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder()
CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class)
.beanClass(OutboundSocketBindingExtension.class)
.scope(Singleton.class)
.addQualifier(new AnnotationLiteral<Pre>() {
Expand Down
Loading

0 comments on commit dfa87f2

Please sign in to comment.