Skip to content

Commit

Permalink
Optimizing taglib loading
Browse files Browse the repository at this point in the history
  • Loading branch information
cuioss committed Jan 3, 2024
1 parent e853734 commit 8f1ba39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import de.cuioss.jsf.dev.metadata.model.TagStorage;
import de.cuioss.jsf.dev.metadata.model.UIComponentMetadata;
import de.cuioss.jsf.dev.metadata.model.ValidatorMetadata;
import de.cuioss.tools.base.Preconditions;
import de.cuioss.portal.common.util.PortalResourceLoader;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
Expand Down Expand Up @@ -93,16 +93,15 @@ public TagLib(final String tagLibPath, final String tagLibNamespaceUrl) {

tagPath = tagLibPath;

final var resource = TagLib.class.getResource(tagPath);

Preconditions.checkState(null != resource, "Unable to load path %d", tagPath);
final var resource = PortalResourceLoader.getRessource(tagLibPath, getClass());

componentMetadata = new TagStorage<>();
converterMetadata = new TagStorage<>();
validatorMetadata = new TagStorage<>();
behaviorMetadata = new TagStorage<>();

parseTagLib(resource);
parseTagLib(
resource.orElseThrow(() -> new IllegalStateException("Unable to load TagLib from path: " + tagPath)));

componentMetadata.sortCollected();
converterMetadata.sortCollected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import de.cuioss.jsf.api.application.navigation.NavigationUtils;
import de.cuioss.jsf.api.components.base.BaseCuiNamingContainer;
import de.cuioss.portal.common.util.PortalResourceLoader;
import de.cuioss.tools.collect.CollectionBuilder;
import de.cuioss.tools.io.FileLoaderUtility;
import de.cuioss.tools.io.FileTypePrefix;
Expand Down Expand Up @@ -228,10 +229,10 @@ private Optional<URL> resolvePath(final String path) {
if (!path.startsWith("/")) {
for (var candidate : determineViewRelativePath(path)) {
log.debug("Checking candidate '%s'", candidate);
var found = Thread.currentThread().getContextClassLoader().getResource(candidate);
if (found != null) {
var found = PortalResourceLoader.getRessource(candidate, getClass());
if (found.isPresent()) {
log.debug("Found candidate '%s'", candidate);
return Optional.of(found);
return found;
}
}
log.warn("%s", getClass().getResource(path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import de.cuioss.test.generator.Generators;
import de.cuioss.test.jsf.component.AbstractComponentTest;
Expand Down Expand Up @@ -52,34 +53,15 @@ void shouldResolveSourceId() {
assertTrue(resolved.contains("Extract Sample Source"));
}

@Test
@Disabled
void shouldReadRelativeSourceFile() {
getRequestConfigDecorator().setViewId(VIEW_ID);
var component = new SourceCodeComponent();
component.setSourcePath("test.properties");
var resolved = component.resolveSource();
assertEquals("hello=world", resolved);
}

@Test
@Disabled
void shouldReadRelativeToResourcesSourceFile() {
getRequestConfigDecorator().setViewId(VIEW_ID);
var component = new SourceCodeComponent();
component.setSourcePath("relativeResources.properties");
var resolved = component.resolveSource();
assertEquals("hello=relative", resolved);
}

@Test
@Disabled
void shouldReadRelativeAsAbsoluteSourceFile() {
@ParameterizedTest
@CsvSource({ "test.properties,hello=world", "relativeResources.properties,hello=relative",
"absoluteResources.properties,hello=absolute" })
void shouldReadRelativeSourceFile(String path, String result) {
getRequestConfigDecorator().setViewId(VIEW_ID);
var component = new SourceCodeComponent();
component.setSourcePath("absoluteResources.properties");
component.setSourcePath(path);
var resolved = component.resolveSource();
assertEquals("hello=absolute", resolved);
assertEquals(result, resolved);
}

@Test
Expand Down

0 comments on commit 8f1ba39

Please sign in to comment.