Search in sources :

Example 1 with CaseInsensitiveMap

use of org.apache.commons.collections.map.CaseInsensitiveMap in project hadoop by apache.

the class FileUtil method createJarWithClassPath.

/**
   * Create a jar file at the given path, containing a manifest with a classpath
   * that references all specified entries.
   *
   * Some platforms may have an upper limit on command line length.  For example,
   * the maximum command line length on Windows is 8191 characters, but the
   * length of the classpath may exceed this.  To work around this limitation,
   * use this method to create a small intermediate jar with a manifest that
   * contains the full classpath.  It returns the absolute path to the new jar,
   * which the caller may set as the classpath for a new process.
   *
   * Environment variable evaluation is not supported within a jar manifest, so
   * this method expands environment variables before inserting classpath entries
   * to the manifest.  The method parses environment variables according to
   * platform-specific syntax (%VAR% on Windows, or $VAR otherwise).  On Windows,
   * environment variables are case-insensitive.  For example, %VAR% and %var%
   * evaluate to the same value.
   *
   * Specifying the classpath in a jar manifest does not support wildcards, so
   * this method expands wildcards internally.  Any classpath entry that ends
   * with * is translated to all files at that path with extension .jar or .JAR.
   *
   * @param inputClassPath String input classpath to bundle into the jar manifest
   * @param pwd Path to working directory to save jar
   * @param targetDir path to where the jar execution will have its working dir
   * @param callerEnv Map<String, String> caller's environment variables to use
   *   for expansion
   * @return String[] with absolute path to new jar in position 0 and
   *   unexpanded wild card entry path in position 1
   * @throws IOException if there is an I/O error while writing the jar file
   */
public static String[] createJarWithClassPath(String inputClassPath, Path pwd, Path targetDir, Map<String, String> callerEnv) throws IOException {
    // Replace environment variables, case-insensitive on Windows
    @SuppressWarnings("unchecked") Map<String, String> env = Shell.WINDOWS ? new CaseInsensitiveMap(callerEnv) : callerEnv;
    String[] classPathEntries = inputClassPath.split(File.pathSeparator);
    for (int i = 0; i < classPathEntries.length; ++i) {
        classPathEntries[i] = StringUtils.replaceTokens(classPathEntries[i], StringUtils.ENV_VAR_PATTERN, env);
    }
    File workingDir = new File(pwd.toString());
    if (!workingDir.mkdirs()) {
        // If mkdirs returns false because the working directory already exists,
        // then this is acceptable.  If it returns false due to some other I/O
        // error, then this method will fail later with an IOException while saving
        // the jar.
        LOG.debug("mkdirs false for " + workingDir + ", execution will continue");
    }
    StringBuilder unexpandedWildcardClasspath = new StringBuilder();
    // Append all entries
    List<String> classPathEntryList = new ArrayList<String>(classPathEntries.length);
    for (String classPathEntry : classPathEntries) {
        if (classPathEntry.length() == 0) {
            continue;
        }
        if (classPathEntry.endsWith("*")) {
            // Append all jars that match the wildcard
            List<Path> jars = getJarsInDirectory(classPathEntry);
            if (!jars.isEmpty()) {
                for (Path jar : jars) {
                    classPathEntryList.add(jar.toUri().toURL().toExternalForm());
                }
            } else {
                unexpandedWildcardClasspath.append(File.pathSeparator);
                unexpandedWildcardClasspath.append(classPathEntry);
            }
        } else {
            // Append just this entry
            File fileCpEntry = null;
            if (!new Path(classPathEntry).isAbsolute()) {
                fileCpEntry = new File(targetDir.toString(), classPathEntry);
            } else {
                fileCpEntry = new File(classPathEntry);
            }
            String classPathEntryUrl = fileCpEntry.toURI().toURL().toExternalForm();
            // created yet, but will definitely be created before running.
            if (classPathEntry.endsWith(Path.SEPARATOR) && !classPathEntryUrl.endsWith(Path.SEPARATOR)) {
                classPathEntryUrl = classPathEntryUrl + Path.SEPARATOR;
            }
            classPathEntryList.add(classPathEntryUrl);
        }
    }
    String jarClassPath = StringUtils.join(" ", classPathEntryList);
    // Create the manifest
    Manifest jarManifest = new Manifest();
    jarManifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
    jarManifest.getMainAttributes().putValue(Attributes.Name.CLASS_PATH.toString(), jarClassPath);
    // Write the manifest to output JAR file
    File classPathJar = File.createTempFile("classpath-", ".jar", workingDir);
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;
    JarOutputStream jos = null;
    try {
        fos = new FileOutputStream(classPathJar);
        bos = new BufferedOutputStream(fos);
        jos = new JarOutputStream(bos, jarManifest);
    } finally {
        IOUtils.cleanup(LOG, jos, bos, fos);
    }
    String[] jarCp = { classPathJar.getCanonicalPath(), unexpandedWildcardClasspath.toString() };
    return jarCp;
}
Also used : ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) FileOutputStream(java.io.FileOutputStream) ZipFile(java.util.zip.ZipFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with CaseInsensitiveMap

use of org.apache.commons.collections.map.CaseInsensitiveMap in project kylo by Teradata.

the class ConfigurationPropertyReplacer method replaceControllerServiceProperties.

/**
 * This will replace the Map of Properties in the DTO but not persist back to Nifi.  You need to call the rest client to persist the change
 *
 * @param controllerServiceDTO        the controller service
 * @param properties                  the properties to set
 * @param propertyDescriptorTransform transformer
 * @return {@code true} if the properties were updated, {@code false} if not
 */
public static boolean replaceControllerServiceProperties(ControllerServiceDTO controllerServiceDTO, Map<String, String> properties, NiFiPropertyDescriptorTransform propertyDescriptorTransform) {
    Set<String> changedProperties = new HashSet<>();
    if (controllerServiceDTO != null) {
        // check both Nifis Internal Key name as well as the Displayname to match the properties
        CaseInsensitiveMap propertyMap = new CaseInsensitiveMap(properties);
        Map<String, String> controllerServiceProperties = controllerServiceDTO.getProperties();
        controllerServiceProperties.entrySet().stream().filter(entry -> (propertyMap.containsKey(entry.getKey()) || (controllerServiceDTO.getDescriptors().get(entry.getKey()) != null && propertyMap.containsKey(controllerServiceDTO.getDescriptors().get(entry.getKey()).getDisplayName().toLowerCase())))).forEach(entry -> {
            boolean isSensitive = propertyDescriptorTransform.isSensitive(controllerServiceDTO.getDescriptors().get(entry.getKey()));
            String value = (String) propertyMap.get(entry.getKey());
            if (StringUtils.isBlank(value)) {
                value = (String) propertyMap.get(controllerServiceDTO.getDescriptors().get(entry.getKey()).getDisplayName().toLowerCase());
            }
            if (!isSensitive || (isSensitive && StringUtils.isNotBlank(value))) {
                entry.setValue(value);
                changedProperties.add(entry.getKey());
            }
        });
    }
    return !changedProperties.isEmpty();
}
Also used : CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) NifiProperty(com.thinkbiganalytics.nifi.rest.model.NifiProperty) Set(java.util.Set) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) NiFiPropertyDescriptorTransform(com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform) HashSet(java.util.HashSet) List(java.util.List) Matcher(java.util.regex.Matcher) Map(java.util.Map) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) HashSet(java.util.HashSet)

Example 3 with CaseInsensitiveMap

use of org.apache.commons.collections.map.CaseInsensitiveMap in project kylo by Teradata.

the class NifiControllerServiceProperties method mergeNifiAndEnvProperties.

public Map<String, String> mergeNifiAndEnvProperties(Map<String, String> nifiProperties, String serviceName) {
    if (nifiProperties != null) {
        CaseInsensitiveMap propertyMap = new CaseInsensitiveMap(nifiProperties);
        String servicePrefix = NifiEnvironmentProperties.getEnvironmentControllerServicePropertyPrefix(serviceName);
        Map<String, Object> map = environmentProperties.getPropertiesStartingWith(servicePrefix);
        if (map != null && !map.isEmpty()) {
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                String key = NifiEnvironmentProperties.environmentPropertyToControllerServiceProperty(entry.getKey());
                if (propertyMap.containsKey(key) && entry.getValue() != null) {
                    propertyMap.put(key, entry.getValue());
                }
            }
        }
        return propertyMap;
    }
    return null;
}
Also used : CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) Map(java.util.Map) CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap)

Example 4 with CaseInsensitiveMap

use of org.apache.commons.collections.map.CaseInsensitiveMap in project maven-plugins by apache.

the class ChangesMojo method executeReport.

public void executeReport(Locale locale) throws MavenReportException {
    failIfUsingDeprecatedParameter(escapeHTML, "escapeHTML", "Using markup inside CDATA sections does not work for all output formats!");
    failIfUsingDeprecatedParameter(issueLinkTemplate, "issueLinkTemplate", "You must use 'issueLinkTemplatePerSystem' for the system '" + ChangesReportGenerator.DEFAULT_ISSUE_SYSTEM_KEY + "' instead.");
    Date now = new Date();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(publishDateFormat, new Locale(publishDateLocale));
    Properties additionalProperties = new Properties();
    additionalProperties.put("publishDate", simpleDateFormat.format(now));
    ChangesXML changesXml = getChangesFromFile(xmlPath, project, additionalProperties);
    if (changesXml == null) {
        return;
    }
    if (aggregated) {
        final String basePath = project.getBasedir().getAbsolutePath();
        final String absolutePath = xmlPath.getAbsolutePath();
        if (!absolutePath.startsWith(basePath)) {
            getLog().warn("xmlPath should be within the project dir for aggregated changes report.");
            return;
        }
        final String relativePath = absolutePath.substring(basePath.length());
        List<Release> releaseList = changesXml.getReleaseList();
        for (Object o : project.getCollectedProjects()) {
            final MavenProject childProject = (MavenProject) o;
            final File changesFile = new File(childProject.getBasedir(), relativePath);
            final ChangesXML childXml = getChangesFromFile(changesFile, childProject, additionalProperties);
            if (childXml != null) {
                releaseList = releaseUtils.mergeReleases(releaseList, childProject.getName(), childXml.getReleaseList());
            }
        }
        changesXml.setReleaseList(releaseList);
    }
    ChangesReportGenerator report = new ChangesReportGenerator(changesXml.getReleaseList());
    report.setAuthor(changesXml.getAuthor());
    report.setTitle(changesXml.getTitle());
    report.setEscapeHTML(true);
    // We need something case insensitive to maintain backward compatibility
    if (issueLinkTemplatePerSystem == null) {
        caseInsensitiveIssueLinkTemplatePerSystem = new CaseInsensitiveMap();
    } else {
        caseInsensitiveIssueLinkTemplatePerSystem = new CaseInsensitiveMap(issueLinkTemplatePerSystem);
    }
    // Set good default values for issue management systems here
    addIssueLinkTemplate(ChangesReportGenerator.DEFAULT_ISSUE_SYSTEM_KEY, "%URL%/ViewIssue.jspa?key=%ISSUE%");
    addIssueLinkTemplate("Bitbucket", "%URL%/issue/%ISSUE%");
    addIssueLinkTemplate("Bugzilla", "%URL%/show_bug.cgi?id=%ISSUE%");
    addIssueLinkTemplate("GitHub", "%URL%/%ISSUE%");
    addIssueLinkTemplate("GoogleCode", "%URL%/detail?id=%ISSUE%");
    addIssueLinkTemplate("JIRA", "%URL%/%ISSUE%");
    addIssueLinkTemplate("Mantis", "%URL%/view.php?id=%ISSUE%");
    addIssueLinkTemplate("MKS", "%URL%/viewissue?selection=%ISSUE%");
    addIssueLinkTemplate("Redmine", "%URL%/issues/show/%ISSUE%");
    addIssueLinkTemplate("Scarab", "%URL%/issues/id/%ISSUE%");
    addIssueLinkTemplate("SourceForge", "http://sourceforge.net/support/tracker.php?aid=%ISSUE%");
    addIssueLinkTemplate("SourceForge2", "%URL%/%ISSUE%");
    addIssueLinkTemplate("Trac", "%URL%/ticket/%ISSUE%");
    addIssueLinkTemplate("Trackplus", "%URL%/printItem.action?key=%ISSUE%");
    addIssueLinkTemplate("YouTrack", "%URL%/issue/%ISSUE%");
    // @todo Add more issue management systems here
    // Remember to also add documentation in usage.apt.vm
    // Show the current issueLinkTemplatePerSystem configuration
    logIssueLinkTemplatePerSystem(caseInsensitiveIssueLinkTemplatePerSystem);
    report.setIssueLinksPerSystem(caseInsensitiveIssueLinkTemplatePerSystem);
    report.setSystem(system);
    report.setTeamlist(teamlist);
    report.setUrl(url);
    report.setAddActionDate(addActionDate);
    if (StringUtils.isEmpty(url)) {
        getLog().warn("No issue management URL defined in POM. Links to your issues will not work correctly.");
    }
    boolean feedGenerated = false;
    if (StringUtils.isNotEmpty(feedType)) {
        feedGenerated = generateFeed(changesXml, locale);
    }
    report.setLinkToFeed(feedGenerated);
    report.doGenerateReport(getBundle(locale), getSink());
    // Copy the images
    copyStaticResources();
}
Also used : Locale(java.util.Locale) Properties(java.util.Properties) Date(java.util.Date) CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) MavenProject(org.apache.maven.project.MavenProject) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Release(org.apache.maven.plugins.changes.model.Release)

Example 5 with CaseInsensitiveMap

use of org.apache.commons.collections.map.CaseInsensitiveMap in project ddf by codice.

the class CswRecordConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> cswAttrMap = new CaseInsensitiveMap(DefaultCswRecordMap.getDefaultCswRecordMap().getCswToMetacardAttributeNames());
    Object mappingObj = context.get(CswConstants.CSW_MAPPING);
    if (mappingObj instanceof Map<?, ?>) {
        CswUnmarshallHelper.removeExistingAttributes(cswAttrMap, (Map<String, String>) mappingObj);
    }
    CswAxisOrder cswAxisOrder = CswAxisOrder.LON_LAT;
    Object cswAxisOrderObject = context.get(CswConstants.AXIS_ORDER_PROPERTY);
    if (cswAxisOrderObject != null && cswAxisOrderObject.getClass().isEnum()) {
        Enum value = (Enum) cswAxisOrderObject;
        cswAxisOrder = CswAxisOrder.valueOf(value.name());
    }
    Map<String, String> namespaceMap = null;
    Object namespaceObj = context.get(CswConstants.NAMESPACE_DECLARATIONS);
    if (namespaceObj instanceof Map<?, ?>) {
        namespaceMap = (Map<String, String>) namespaceObj;
    }
    Metacard metacard = CswUnmarshallHelper.createMetacardFromCswRecord(metacardType, reader, cswAxisOrder, namespaceMap);
    Object sourceIdObj = context.get(Core.SOURCE_ID);
    if (sourceIdObj instanceof String) {
        metacard.setSourceId((String) sourceIdObj);
    }
    return metacard;
}
Also used : CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap) Metacard(ddf.catalog.data.Metacard) CswAxisOrder(org.codice.ddf.spatial.ogc.csw.catalog.common.CswAxisOrder) Map(java.util.Map) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) CaseInsensitiveMap(org.apache.commons.collections.map.CaseInsensitiveMap)

Aggregations

CaseInsensitiveMap (org.apache.commons.collections.map.CaseInsensitiveMap)5 Map (java.util.Map)3 File (java.io.File)2 NiFiPropertyDescriptorTransform (com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform)1 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)1 Metacard (ddf.catalog.data.Metacard)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 JarOutputStream (java.util.jar.JarOutputStream)1 Manifest (java.util.jar.Manifest)1 Matcher (java.util.regex.Matcher)1