Skip to content

Commit

Permalink
Helbers comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Jul 28, 2023
1 parent e724620 commit 667da35
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkiverse.asyncapi.generator.input;

import java.io.IOException;

import io.quarkiverse.asyncapi.config.AsyncAPISupplier;
import io.quarkiverse.asyncapi.config.AsyncAPISupplierFactory;
import io.quarkiverse.asyncapi.generator.AsyncAPIBuildItem;
Expand All @@ -10,8 +8,8 @@

public class AsyncAPIOutputProcessor {
@BuildStep
void processResource(BuildProducer<AsyncAPIBuildItem> outputBI) throws IOException {
for (AsyncAPISupplier supplier : AsyncAPISupplierFactory.get().getAsyncApiSuppliers()) {
void processResource(BuildProducer<AsyncAPIBuildItem> outputBI) {
for (AsyncAPISupplier supplier : AsyncAPISupplierFactory.getAsyncApiSuppliers()) {
outputBI.produce(new AsyncAPIBuildItem(supplier));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AsyncAPIConfigSourceFactory implements ConfigSourceFactory {

@Override
public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context) {
return AsyncAPISupplierFactory.init(context).getAsyncApiSuppliers().stream().map(AsyncAPIConfigSource::new)
return AsyncAPISupplierFactory.init(context).stream().map(AsyncAPIConfigSource::new)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class AsyncAPIRegistryProducer {

@Produces
AsyncAPIRegistry getAPIRegistry() {
return new MapAsyncAPIRegistry(AsyncAPISupplierFactory.get().getAsyncApiSuppliers());
return new MapAsyncAPIRegistry(AsyncAPISupplierFactory.getAsyncApiSuppliers());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -15,29 +16,14 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.smallrye.config.ConfigSourceContext;

public class AsyncAPISupplierFactory {

private static final Logger logger = LoggerFactory.getLogger(AsyncAPISupplierFactory.class);
private static AsyncAPISupplierFactory instance;

private final Set<String> EXTENSIONS = Set.of(".yml", ".yaml", ".json");
private Collection<AsyncAPISupplier> asyncAPISuppliers = new ArrayList<>();

public static AsyncAPISupplierFactory init(ConfigSourceContext context) {
instance = new AsyncAPISupplierFactory(context);
return instance;
}
private final static Set<String> EXTENSIONS = Set.of(".yml", ".yaml", ".json");
private static Collection<AsyncAPISupplier> asyncAPISuppliers = new ArrayList<>();

public static AsyncAPISupplierFactory get() {
return instance;
}

private AsyncAPISupplierFactory(ConfigSourceContext context) {
public static Collection<AsyncAPISupplier> init(ConfigSourceContext context) {
List<String> specDirs = getValues(context, AsyncAPIConfigGroup.SOURCES_PROP,
Arrays.asList("src/main/asyncapi", "src/test/asyncapi"));
final Collection<String> ignoredFiles = excludedFiles(context);
Expand All @@ -53,7 +39,7 @@ private AsyncAPISupplierFactory(ConfigSourceContext context) {
AsyncAPIUtils.getJavaClassName(file.getFileName().toString()), Files.readString(file)));
}
} catch (IOException e) {
logger.error("Error processing dir {}", specDir, e);
throw new UncheckedIOException(e);
}
}
}
Expand All @@ -64,31 +50,38 @@ private AsyncAPISupplierFactory(ConfigSourceContext context) {
try (InputStream stream = entry.getValue().get()) {
asyncAPISuppliers.add(new JacksonAsyncAPISupplier(entry.getKey(), new String(stream.readAllBytes())));
} catch (IOException e) {
logger.error("Error processing stream id {}", entry.getKey(), e);
throw new UncheckedIOException(e);
}
}
}
return asyncAPISuppliers;
}

private AsyncAPISupplierFactory(ConfigSourceContext context) {
}

public Collection<AsyncAPISupplier> getAsyncApiSuppliers() {
public static Collection<AsyncAPISupplier> getAsyncApiSuppliers() {
return asyncAPISuppliers;
}

private Collection<String> excludedFiles(ConfigSourceContext context) {
private static Collection<String> excludedFiles(ConfigSourceContext context) {
return getValues(context, AsyncAPIConfigGroup.EXCLUDED_FILES_PROP, Collections.emptyList());
}

private boolean isCandidateFile(Path path, Collection<String> ignoredFiles) {
private static boolean isCandidateFile(Path path, Collection<String> ignoredFiles) {
String fileName = path.getFileName().toString();
return Files.isRegularFile(path) && !ignoredFiles.contains(fileName) && isExtension(fileName);
}

List<String> getValues(ConfigSourceContext context, String propertyName, List<String> defaultValue) {
private static List<String> getValues(ConfigSourceContext context, String propertyName, List<String> defaultValue) {
String propValue = context.getValue(propertyName).getValue();
return propValue == null ? defaultValue : Arrays.asList(propValue.split(",; "));
}

private boolean isExtension(String fileName) {
return EXTENSIONS.stream().anyMatch(ext -> fileName.endsWith(ext));
private static boolean isExtension(String fileName) {
return EXTENSIONS.stream().anyMatch(fileName::endsWith);
}

private AsyncAPISupplierFactory() {
}
}

0 comments on commit 667da35

Please sign in to comment.