Example usage for org.apache.commons.lang StringUtils endsWith

List of usage examples for org.apache.commons.lang StringUtils endsWith

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils endsWith.

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:org.sonar.server.batch.BatchIndex.java

@Override
public void start() {
    StringBuilder sb = new StringBuilder();
    batchDir = new File(fs.getHomeDir(), "lib/scanner");
    if (batchDir.exists()) {
        Collection<File> files = FileUtils.listFiles(batchDir, HiddenFileFilter.VISIBLE,
                FileFilterUtils.directoryFileFilter());
        for (File file : files) {
            String filename = file.getName();
            if (StringUtils.endsWith(filename, ".jar")) {
                try (FileInputStream fis = new FileInputStream(file)) {
                    sb.append(filename).append('|').append(DigestUtils.md5Hex(fis)).append(CharUtils.LF);
                } catch (IOException e) {
                    throw new IllegalStateException("Fail to compute hash", e);
                }//from  ww  w.j a  v a 2  s . c  o m
            }
        }
    }
    this.index = sb.toString();
}

From source file:org.sonar.server.platform.ClassLoaderUtils.java

/**
 * Finds files within a given directory and its subdirectories
 *
 * @param classLoader/*from   ww w  .  ja v  a  2s  .c o  m*/
 * @param rootPath    the root directory, for example org/sonar/sqale
 * @return a list of relative paths, for example {"org/sonar/sqale/foo/bar.txt}. Never null.
 */
static Collection<String> listFiles(ClassLoader classLoader, String rootPath) {
    return listResources(classLoader, rootPath, new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String path) {
            return !StringUtils.endsWith(path, "/");
        }
    });
}

From source file:org.sonar.server.plugins.BatchWs.java

@Override
public void start() {
    StringBuilder sb = new StringBuilder();
    batchDir = new File(server.getRootDir(), "lib/batch");
    if (batchDir.exists()) {
        Collection<File> files = FileUtils.listFiles(batchDir, HiddenFileFilter.VISIBLE,
                FileFilterUtils.directoryFileFilter());
        for (File file : files) {
            String filename = file.getName();
            if (StringUtils.endsWith(filename, ".jar")) {
                sb.append(filename).append('|').append(new FileHashes().of(file)).append(CharUtils.LF);
            }/*from w  w  w .  j  a  v  a 2  s.  com*/
        }
    }
    this.index = sb.toString();
}

From source file:org.sonar.server.plugins.ClassLoaderUtils.java

/**
 * Finds files within a given directory and its subdirectories
 *
 * @param classLoader/*w  w  w.j a  v a  2 s  .c  o  m*/
 * @param rootPath    the root directory, for example org/sonar/sqale
 * @return a list of relative paths, for example {"org/sonar/sqale/foo/bar.txt}. Never null.
 */
public static Collection<String> listFiles(ClassLoader classLoader, String rootPath) {
    return listResources(classLoader, rootPath, new Predicate<String>() {
        public boolean apply(@Nullable String path) {
            return !StringUtils.endsWith(path, "/");
        }
    });
}

From source file:org.sonar.server.plugins.ClassLoaderUtilsTest.java

@Test
public void listResources_use_predicate() {
    Collection<String> strings = ClassLoaderUtils.listResources(classLoader, "org/sonar/sqale",
            new Predicate<String>() {
                public boolean apply(@Nullable String s) {
                    return StringUtils.endsWith(s, "md");
                }//  ww  w  . ja v  a2  s . co  m
            });
    assertThat(strings.size(), Is.is(1));
    assertThat(strings, hasItems("org/sonar/sqale/app/README.md"));
}

From source file:org.sonar.server.startup.GenerateBootstrapIndex.java

public static List<String> getLibs(ServletContext servletContext) {
    List<String> libs = Lists.newArrayList();
    Set<String> paths = servletContext.getResourcePaths("/WEB-INF/lib");
    for (String path : paths) {
        if (StringUtils.endsWith(path, ".jar")) {
            String filename = StringUtils.removeStart(path, "/WEB-INF/lib/");
            if (!isIgnored(filename)) {
                libs.add(filename);/*from   w  ww  .j av  a2  s  .  c  om*/
            }
        }
    }
    return libs;
}

From source file:org.sonar.server.util.ClassLoaderUtils.java

/**
 * Finds files within a given directory and its subdirectories
 *
 * @param classLoader/* ww  w  . j a  va  2 s . co m*/
 * @param rootPath    the root directory, for example org/sonar/sqale
 * @return a list of relative paths, for example {"org/sonar/sqale/foo/bar.txt}. Never null.
 */
public static Collection<String> listFiles(ClassLoader classLoader, String rootPath) {
    return listResources(classLoader, rootPath, path -> !StringUtils.endsWith(path, "/"));
}

From source file:org.sonar.updatecenter.common.PluginKeyUtils.java

public static String sanitize(String mavenArtifactId) {
    if (mavenArtifactId == null) {
        return null;
    }//from  www. j  a v  a2s  . c  o  m

    String key = mavenArtifactId;
    if (StringUtils.startsWith(mavenArtifactId, "sonar-") && StringUtils.endsWith(mavenArtifactId, "-plugin")) {
        key = StringUtils.removeEnd(StringUtils.removeStart(mavenArtifactId, "sonar-"), "-plugin");
    } else if (StringUtils.endsWith(mavenArtifactId, "-sonar-plugin")) {
        key = StringUtils.removeEnd(mavenArtifactId, "-sonar-plugin");
    }
    return keepLettersAndDigits(key);
}

From source file:org.sonarsource.pluginpackaging.PluginKeyUtils.java

public static String sanitize(String mavenArtifactId) {
    String key = mavenArtifactId;
    if (StringUtils.startsWith(mavenArtifactId, SONAR_PREFIX)
            && StringUtils.endsWith(mavenArtifactId, PLUGIN_SUFFIX)) {
        key = StringUtils.removeEnd(StringUtils.removeStart(mavenArtifactId, SONAR_PREFIX), PLUGIN_SUFFIX);
    } else if (StringUtils.endsWith(mavenArtifactId, SONAR_PLUGIN_SUFFIX)) {
        key = StringUtils.removeEnd(mavenArtifactId, SONAR_PLUGIN_SUFFIX);
    }/*from ww w.  j  av a2s  . c om*/
    return keepLettersAndDigits(key);
}

From source file:org.sonarsource.sonarlint.core.plugin.PluginKeyUtils.java

public static String sanitize(@Nullable String mavenArtifactId) {
    if (mavenArtifactId == null) {
        return null;
    }//from   w w  w.j  a v  a 2s  .co m

    String key = mavenArtifactId;
    if (StringUtils.startsWith(mavenArtifactId, SONAR_PREFIX)
            && StringUtils.endsWith(mavenArtifactId, PLUGIN_SUFFIX)) {
        key = StringUtils.removeEnd(StringUtils.removeStart(mavenArtifactId, SONAR_PREFIX), PLUGIN_SUFFIX);
    } else if (StringUtils.endsWith(mavenArtifactId, SONAR_PLUGIN_SUFFIX)) {
        key = StringUtils.removeEnd(mavenArtifactId, SONAR_PLUGIN_SUFFIX);
    }
    return keepLettersAndDigits(key);
}