Skip to content

Commit

Permalink
4.x: Remove unused code from ClasspathSourceHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Captain1653 committed Dec 18, 2024
1 parent e36b9d4 commit 3a3d7a7
Showing 1 changed file with 1 addition and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
* Copyright (c) 2017, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,16 +16,12 @@

package io.helidon.config;

import java.io.InputStream;
import java.lang.System.Logger.Level;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.function.BiFunction;

/**
* Utilities for file-related source classes.
Expand Down Expand Up @@ -74,40 +70,4 @@ static Path resourcePath(String resourceName) throws URISyntaxException {
}
}

static Instant resourceTimestamp(String resourceName) {
try {
Path resourcePath = resourcePath(resourceName);
if (resourcePath != null) {
return Files.getLastModifiedTime(resourcePath).toInstant();
}
} catch (Exception ex) {
LOGGER.log(Level.DEBUG, "Error to get resource '" + resourceName + "' last modified time.", ex);
}
return Instant.EPOCH;
}

static <T> T content(String resource,
String description,
BiFunction<InputStream, Instant, T> processor) throws ConfigException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

InputStream inputStream = classLoader.getResourceAsStream(resource);

if (inputStream == null) {
LOGGER.log(Level.DEBUG,
String.format("Error to get %s using %s CONTEXT ClassLoader.", description, classLoader));
throw new ConfigException(description + " does not exist. Used ClassLoader: " + classLoader);
}
Instant resourceTimestamp = resourceTimestamp(resource);
try {
LOGGER.log(Level.DEBUG,
String.format("Getting content from '%s'. Last modified at %s. Used ClassLoader: %s",
resourcePath(resource), resourceTimestamp, classLoader));
} catch (Exception ex) {
LOGGER.log(Level.DEBUG, "Error to get resource '" + resource + "' path. Used ClassLoader: " + classLoader, ex);
}

return processor.apply(inputStream, resourceTimestamp);
}

}

0 comments on commit 3a3d7a7

Please sign in to comment.