Search in sources :

Example 1 with DataFormatModel

use of org.apache.camel.tooling.model.DataFormatModel in project camel-quarkus by apache.

the class CqCatalog method toCamelDocsModel.

public static ArtifactModel<?> toCamelDocsModel(ArtifactModel<?> m) {
    if ("imap".equals(m.getName())) {
        final ComponentModel clone = (ComponentModel) CqUtils.cloneArtifactModel(m);
        clone.setName("mail");
        clone.setTitle("Mail");
        return clone;
    }
    if (m.getName().startsWith("bindy")) {
        final DataFormatModel clone = (DataFormatModel) CqUtils.cloneArtifactModel(m);
        clone.setName("bindy");
        return clone;
    }
    return m;
}
Also used : DataFormatModel(org.apache.camel.tooling.model.DataFormatModel) ComponentModel(org.apache.camel.tooling.model.ComponentModel)

Example 2 with DataFormatModel

use of org.apache.camel.tooling.model.DataFormatModel in project camel-quarkus by apache.

the class CqCatalog method serialize.

static void serialize(final Path catalogPath, ArtifactModel<?> model) {
    final Path out = catalogPath.resolve(model.getKind() + "s").resolve(model.getName() + ".json");
    try {
        Files.createDirectories(out.getParent());
    } catch (IOException e) {
        throw new RuntimeException("Could not create " + out.getParent(), e);
    }
    String rawJson;
    switch(Kind.valueOf(model.getKind())) {
        case component:
            rawJson = JsonMapper.createParameterJsonSchema((ComponentModel) model);
            break;
        case language:
            rawJson = JsonMapper.createParameterJsonSchema((LanguageModel) model);
            break;
        case dataformat:
            rawJson = JsonMapper.createParameterJsonSchema((DataFormatModel) model);
            break;
        case other:
            rawJson = JsonMapper.createJsonSchema((OtherModel) model);
            break;
        default:
            throw new IllegalStateException("Cannot serialize kind " + model.getKind());
    }
    try {
        Files.write(out, rawJson.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
        throw new RuntimeException("Could not write to " + out, e);
    }
}
Also used : Path(java.nio.file.Path) DataFormatModel(org.apache.camel.tooling.model.DataFormatModel) ComponentModel(org.apache.camel.tooling.model.ComponentModel) LanguageModel(org.apache.camel.tooling.model.LanguageModel) IOException(java.io.IOException) OtherModel(org.apache.camel.tooling.model.OtherModel)

Example 3 with DataFormatModel

use of org.apache.camel.tooling.model.DataFormatModel in project camel-quarkus by apache.

the class PrepareCatalogQuarkusMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Path catalogPath = catalogBaseDir.toPath().resolve(CqCatalog.CQ_CATALOG_DIR);
    final Map<String, Set<String>> schemesByKind = new LinkedHashMap<>();
    CqCatalog.kinds().forEach(kind -> schemesByKind.put(kind.name(), new TreeSet<>()));
    final CqCatalog catalog = CqCatalog.findFirstFromClassPath();
    if (extendClassPathCatalog) {
        catalog.store(catalogBaseDir.toPath());
        catalog.models().forEach(model -> schemesByKind.get(model.getKind()).add(model.getName()));
    }
    findExtensions().forEach(ext -> {
        final String artifactIdBase = ext.getArtifactIdBase();
        final Path schemaFile = ext.getExtensionDir().resolve("component/src/generated/resources/org/apache/camel/component/" + artifactIdBase + "/" + artifactIdBase + ".json").toAbsolutePath().normalize();
        if (Files.isRegularFile(schemaFile)) {
            try {
                final String schema = new String(Files.readAllBytes(schemaFile), StandardCharsets.UTF_8);
                final String capBase = artifactIdBase.substring(0, 1).toUpperCase() + artifactIdBase.substring(1);
                getLog().debug("Adding an extra component " + artifactIdBase + " " + "org.apache.camel.component." + artifactIdBase + "." + capBase + "Component " + schema);
                catalog.addComponent(artifactIdBase, "org.apache.camel.component." + artifactIdBase + "." + capBase + "Component", schema);
            } catch (IOException e) {
                throw new RuntimeException("Could not read " + schemaFile, e);
            }
        }
    });
    findExtensions().forEach(extPath -> {
        final String artifactIdBase = extPath.getArtifactIdBase();
        final List<ArtifactModel<?>> models = catalog.filterModels(artifactIdBase).collect(Collectors.toList());
        final Path runtimePomXmlPath = extPath.getExtensionDir().resolve("runtime/pom.xml").toAbsolutePath().normalize();
        final CamelQuarkusExtension ext = CamelQuarkusExtension.read(runtimePomXmlPath);
        final boolean nativeSupported = ext.isNativeSupported();
        if (models.isEmpty()) {
            final ArtifactModel<?> model;
            final Kind extKind = ext.getKind();
            if (extKind == Kind.component) {
                model = new ComponentModel();
            } else if (extKind == Kind.language) {
                model = new LanguageModel();
            } else if (extKind == Kind.dataformat) {
                model = new DataFormatModel();
            } else {
                model = new OtherModel();
            }
            final String name = ext.getRuntimeArtifactId().replace("camel-quarkus-", "");
            model.setName(name);
            final String title = ext.getName().orElseThrow(() -> new RuntimeException("name is missing in " + ext.getRuntimePomXmlPath()));
            model.setTitle(title);
            model.setDescription(ext.getDescription().orElseThrow(() -> new RuntimeException("description is missing in " + ext.getRuntimePomXmlPath())));
            model.setDeprecated(CqUtils.isDeprecated(title, models, ext.isDeprecated()));
            model.setLabel(ext.getLabel().orElse("quarkus"));
            update(model, ext, nativeSupported);
            CqCatalog.serialize(catalogPath, model);
            schemesByKind.get(model.getKind()).add(model.getName());
        } else {
            for (ArtifactModel<?> model : models) {
                update(model, ext, nativeSupported);
                CqCatalog.serialize(catalogPath, model);
                schemesByKind.get(model.getKind()).add(model.getName());
            }
        }
    });
    CqCatalog.kinds().forEach(kind -> {
        final Path newCatalog = catalogPath.resolve(kind.name() + "s.properties");
        try {
            Files.createDirectories(newCatalog.getParent());
            Files.write(newCatalog, schemesByKind.get(kind.name()).stream().collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            throw new RuntimeException("Could not write to " + newCatalog);
        }
    });
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) TreeSet(java.util.TreeSet) IOException(java.io.IOException) OtherModel(org.apache.camel.tooling.model.OtherModel) LinkedHashMap(java.util.LinkedHashMap) DataFormatModel(org.apache.camel.tooling.model.DataFormatModel) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) TreeSet(java.util.TreeSet) Kind(org.apache.camel.catalog.Kind) ComponentModel(org.apache.camel.tooling.model.ComponentModel) LanguageModel(org.apache.camel.tooling.model.LanguageModel)

Example 4 with DataFormatModel

use of org.apache.camel.tooling.model.DataFormatModel in project camel-spring-boot by apache.

the class SpringBootAutoConfigurationMojo method executeDataFormats.

private void executeDataFormats(JarFile componentJar, Map<String, Supplier<String>> jsonFiles) throws MojoFailureException {
    // find the data format names
    List<String> dataFormatNames = findDataFormatNames(componentJar);
    // create auto configuration for the data formats
    if (!dataFormatNames.isEmpty()) {
        getLog().debug("Found " + dataFormatNames.size() + " dataformats");
        List<DataFormatModel> allModels = new LinkedList<>();
        for (String dataFormatName : dataFormatNames) {
            String json = loadDataFormatJson(jsonFiles, dataFormatName);
            if (json != null) {
                DataFormatModel model = JsonMapper.generateDataFormatModel(json);
                allModels.add(model);
            }
        }
        // Group the models by implementing classes
        Map<String, List<DataFormatModel>> grModels = allModels.stream().collect(Collectors.groupingBy(DataFormatModel::getJavaType));
        for (String dataFormatClass : grModels.keySet()) {
            List<DataFormatModel> dfModels = grModels.get(dataFormatClass);
            // They should be
            DataFormatModel model = dfModels.get(0);
            // equivalent
            List<String> aliases = dfModels.stream().map(DataFormatModel::getName).sorted().collect(Collectors.toList());
            // use springboot as sub package name so the code is not in
            // normal
            // package so the Spring Boot JARs can be optional at runtime
            int pos = model.getJavaType().lastIndexOf(".");
            String pkg = model.getJavaType().substring(0, pos) + ".springboot";
            String overrideDataFormatName = null;
            if (aliases.size() > 1) {
                // determine component name when there are multiple ones
                overrideDataFormatName = model.getArtifactId().replace("camel-", "");
            }
            boolean complexOptions = model.getOptions().stream().anyMatch(this::isComplexType);
            createDataFormatConfigurationSource(pkg, model, overrideDataFormatName);
            createDataFormatAutoConfigurationSource(pkg, model, overrideDataFormatName, complexOptions);
            if (complexOptions) {
                createDataFormatConverterSource(pkg, model);
            }
            createDataFormatSpringFactorySource(pkg, model);
        }
    }
}
Also used : DataFormatModel(org.apache.camel.tooling.model.DataFormatModel)

Aggregations

DataFormatModel (org.apache.camel.tooling.model.DataFormatModel)4 ComponentModel (org.apache.camel.tooling.model.ComponentModel)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 LanguageModel (org.apache.camel.tooling.model.LanguageModel)2 OtherModel (org.apache.camel.tooling.model.OtherModel)2 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Kind (org.apache.camel.catalog.Kind)1 ArtifactModel (org.apache.camel.tooling.model.ArtifactModel)1