All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.camel.maven.packaging.PackageHelper Maven / Gradle / Ivy

There is a newer version: 4.9.0
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.maven.packaging;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public final class PackageHelper {

    private PackageHelper() {
    }

    /**
     * Loads the entire stream into memory as a String and returns it.
     * 

* Notice: This implementation appends a \n as line * terminator at the of the text. *

* Warning, don't use for crazy big streams :) */ public static String loadText(InputStream in) throws IOException { StringBuilder builder = new StringBuilder(); InputStreamReader isr = new InputStreamReader(in); try { BufferedReader reader = new LineNumberReader(isr); while (true) { String line = reader.readLine(); if (line != null) { builder.append(line); builder.append("\n"); } else { break; } } return builder.toString(); } finally { isr.close(); in.close(); } } public static String after(String text, String after) { if (!text.contains(after)) { return null; } return text.substring(text.indexOf(after) + after.length()); } /** * Parses the text as a map (eg key=value) * @param data the data * @return the map */ public static Map parseAsMap(String data) { Map answer = new HashMap(); if (data != null) { String[] lines = data.split("\n"); for (String line : lines) { int idx = line.indexOf('='); if (idx != -1) { String key = line.substring(0, idx); String value = line.substring(idx + 1); // remove ending line break for the values value = value.trim().replaceAll("\n", ""); answer.put(key.trim(), value); } } } return answer; } public static void findJsonFiles(File dir, Set found, FileFilter filter) { File[] files = dir.listFiles(filter); if (files != null) { for (File file : files) { // skip files in root dirs as Camel does not store information there but others may do boolean jsonFile = file.isFile() && file.getName().endsWith(".json"); if (jsonFile) { found.add(file); } else if (file.isDirectory()) { findJsonFiles(file, found, filter); } } } } public static class CamelComponentsModelFilter implements FileFilter { @Override public boolean accept(File pathname) { // skip camel-jetty9 as its a duplicate of camel-jetty if ("camel-jetty9".equals(pathname)) { return false; } return pathname.isDirectory() || pathname.getName().endsWith(".json"); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy