Skip to content

Commit

Permalink
Fix loading of Red Hat artifacts for catalog
Browse files Browse the repository at this point in the history
io.kaoto.camelcatalog.maven.CamelCatalogVersionLoader.configureRepositories(String)
is called too late for Camel Yaml DSL loading. it is called when loading
Camel Catalogs.
Quickfix provided: calling the CamelCatalog which is configuring the
repositories at first
not perfect as note all versions are aligned and some others might need
it but should be enough to unblock current situation

note that the provided is not efficient because the camel-yaml-dsl test
dependency is leaking in the other tests, thus even without the fix the
test is passing... I guess it would require to create a separate module
for the test or to ensure a specific version is picked (see also next
paragraph)

Another note: when several catalog are generated at same time, I'm not
sure that we can ensure that it picks the exact correct version of the
camel-yaml-dsl, it might be the first one found, whatever version it is;
To be checked. In practice I think that most of the time there are no
differences.

fixes #1597

Signed-off-by: Aurélien Pupier <[email protected]>
  • Loading branch information
apupier committed Nov 20, 2024
1 parent 94ebfb8 commit 5c2d1c6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public class CatalogGenerator {

public CatalogDefinition generate() {
camelCatalogVersionLoader.loadKameletBoundaries();
camelCatalogVersionLoader.loadCamelCatalog(camelCatalogVersion);
camelCatalogVersionLoader.loadKamelets(kameletsVersion);
camelCatalogVersionLoader.loadKubernetesSchema();
camelCatalogVersionLoader.loadCamelKCRDs(camelKCRDsVersion);
camelCatalogVersionLoader.loadLocalSchemas();
camelCatalogVersionLoader.loadCamelYamlDsl(camelCatalogVersion);
camelCatalogVersionLoader.loadCamelCatalog(camelCatalogVersion);

var catalogDefinition = new CatalogDefinition();
var yamlDslSchemaProcessor = processCamelSchema(catalogDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public boolean loadCamelYamlDsl(String version) {
ClassLoader classLoader = kaotoVersionManager.getClassLoader();
URL resourceURL = classLoader.getResource(Constants.CAMEL_YAML_DSL_ARTIFACT);
if (resourceURL == null) {
LOGGER.log(Level.SEVERE, "No " + Constants.CAMEL_YAML_DSL_ARTIFACT + " file found in the classpath");

Check warning on line 134 in packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/maven/CamelCatalogVersionLoader.java

View check run for this annotation

Codecov / codecov/patch

packages/catalog-generator/src/main/java/io/kaoto/camelcatalog/maven/CamelCatalogVersionLoader.java#L134

Added line #L134 was not covered by tests
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.kaoto.camelcatalog.commands;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.io.File;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import io.kaoto.camelcatalog.beans.ConfigBean;
import io.kaoto.camelcatalog.model.CatalogCliArgument;
import io.kaoto.camelcatalog.model.CatalogDefinition;
import io.kaoto.camelcatalog.model.CatalogRuntime;

class GenerateCatalogWithRedHatVersionTest {

@TempDir
File tempDir;

@Test
void testOK() throws Exception {
CatalogDefinition catalogDefinition = new CatalogDefinition();
catalogDefinition.setFileName("index.json");
catalogDefinition.setName("test-camel-catalog");
catalogDefinition.setVersion("4.4.0.redhat-00045");
catalogDefinition.setRuntime(CatalogRuntime.Main);

CatalogCliArgument catalogCliArg = new CatalogCliArgument();
catalogCliArg.setRuntime(CatalogRuntime.Main);
catalogCliArg.setCatalogVersion("4.4.0.redhat-00045");

ConfigBean configBean = new ConfigBean();
configBean.setOutputFolder(tempDir.toString());
configBean.setCatalogsName("test-camel-catalog");
configBean.addCatalogVersion(catalogCliArg);
configBean.setKameletsVersion("1.0.0");

GenerateCommand generateCommand = new GenerateCommand(configBean);

generateCommand.run();

assertTrue(new File(tempDir, "camel-main/4.4.0.redhat-00045").exists(), "The folder for the catalog wasn't created");
assertEquals(34, new File(tempDir, "camel-main/4.4.0.redhat-00045").listFiles().length, "The folder for the catalog doesn't contain the correct number of files");
}

}

0 comments on commit 5c2d1c6

Please sign in to comment.