Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x: Remove unused code from ClasspathSourceHelper #9611

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 2025 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);
}

}