use of org.apache.commons.lang3.StringUtils.join in project records-management by Alfresco.
the class PublicAPITestUtil method testPublicAPIConsistency.
/**
* Check the consistency of the public API exposed from the given package. For each class in the package that is
* annotated {@link AlfrescoPublicApi}, check that no exposed methods (or fields, constructors, etc.) use
* non-public-API classes from Alfresco.
*
* @param basePackageName The package to check classes within.
* @param knownBadReferences Any references that would cause this test to fail, but which we don't want to change.
* The keys should be public API classes within our code and the values should be the non-public-API
* class that is being referenced.
*/
public static void testPublicAPIConsistency(String basePackageName, SetMultimap<Class<?>, Class<?>> knownBadReferences) {
Reflections reflections = new Reflections(basePackageName);
Set<Class<?>> publicAPIClasses = reflections.getTypesAnnotatedWith(AlfrescoPublicApi.class, true);
SetMultimap<Class<?>, Class<?>> referencedFrom = HashMultimap.create();
Set<Class<?>> referencedClasses = new HashSet<>();
for (Class<?> publicAPIClass : publicAPIClasses) {
Set<Class<?>> referencedClassesFromClass = getReferencedClassesFromClass(publicAPIClass, new HashSet<>());
referencedClassesFromClass.forEach(clazz -> referencedFrom.put(clazz, publicAPIClass));
// Remove any references in knownBadReferences and error if an expected reference wasn't found.
if (knownBadReferences.containsKey(publicAPIClass)) {
for (Class<?> clazz : knownBadReferences.get(publicAPIClass)) {
assertTrue("Supplied knownBadReferences expects " + clazz + " to be referenced by " + publicAPIClass + ", but no such error was found", referencedClassesFromClass.remove(clazz));
}
}
referencedClasses.addAll(referencedClassesFromClass);
}
List<String> errorMessages = new ArrayList<>();
for (Class<?> referencedClass : referencedClasses) {
if (isInAlfresco(referencedClass) && !isPartOfPublicApi(referencedClass)) {
Set<String> referencerNames = referencedFrom.get(referencedClass).stream().map(c -> c.getName()).collect(Collectors.toSet());
errorMessages.add(referencedClass.getName() + " <- " + StringUtils.join(referencerNames, ", "));
}
}
if (!errorMessages.isEmpty()) {
System.out.println("Errors found:");
System.out.println(StringUtils.join(errorMessages, "\n"));
}
assertEquals("Found references to non-public API classes from public API classes.", Collections.emptyList(), errorMessages);
}
use of org.apache.commons.lang3.StringUtils.join in project beijingThirdPeriod by weidongcao.
the class TestHbase method main.
public static void main(String[] args) {
SparkConf conf = new SparkConf().setAppName("aaa").setMaster("local");
JavaSparkContext sc = new JavaSparkContext(conf);
Random random = new Random();
List<String> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int[] aaa = new int[4];
for (int j = 0; j < 4; j++) {
aaa[j] = random.nextInt(900) + 100;
}
list.add(StringUtils.join(aaa, ","));
}
JavaRDD<String> originalRDD = sc.parallelize(list);
originalRDD.foreach((VoidFunction<String>) s -> System.out.println(s));
/*JavaPairRDD<RowkeyColumnSecondarySort, String> hfileRDD = originalRDD.flatMapToPair(
new PairFlatMapFunction<String, RowkeyColumnSecondarySort, String>() {
@Override
public Iterable<Tuple2<RowkeyColumnSecondarySort, String>> call(String s) throws Exception {
String[] aa = s.split(",");
}
}
)*/
sc.close();
}
use of org.apache.commons.lang3.StringUtils.join in project custom-war-packager by jenkinsci.
the class JenkinsWarPatcher method replaceLib.
private void replaceLib(DependencyInfo lib, Map<String, String> versionOverrides) throws IOException, InterruptedException {
if (lib.source == null) {
throw new IOException("Source is not defined for " + lib);
}
File libsDir = getLibsDir();
String effectiveVersion = versionOverrides.get(lib.artifactId);
if (effectiveVersion == null) {
if (!lib.source.isReleasedVersion()) {
throw new IOException("Cannot resolve new version for library " + lib);
}
effectiveVersion = lib.source.version;
}
List<Path> paths = Files.find(libsDir.toPath(), 1, (path, basicFileAttributes) -> {
// TODO: this matcher is a bit lame, it may suffer from false positives
String fileName = String.valueOf(path.getFileName());
if (fileName.matches(lib.artifactId + "-\\d+.*")) {
return true;
}
return false;
}).collect(Collectors.toList());
if (paths.size() > 1) {
throw new IOException("Bug in Jenkins WAR Packager, cannot find unique lib JAR for artifact " + lib.artifactId + ". Candidates: " + StringUtils.join(paths, ","));
} else if (paths.size() == 1) {
Path oldFile = paths.get(0);
LOGGER.log(Level.INFO, "Replacing the existing library {0} by version {1}. Original File: {2}", new Object[] { lib.artifactId, effectiveVersion, oldFile.getFileName() });
Files.delete(oldFile);
} else {
LOGGER.log(Level.INFO, "Adding new library {0} with version {1}", new Object[] { lib.artifactId, effectiveVersion });
}
File newJarFile = new File(libsDir, lib.artifactId + "-" + effectiveVersion + ".jar");
MavenHelper.downloadArtifact(dstDir, lib, effectiveVersion, newJarFile);
}
use of org.apache.commons.lang3.StringUtils.join in project custom-war-packager by jenkinsci.
the class JenkinsWarPatcher method excludeLib.
private void excludeLib(DependencyInfo lib) throws IOException, InterruptedException {
File libsDir = getLibsDir();
List<Path> paths = Files.find(libsDir.toPath(), 1, (path, basicFileAttributes) -> {
// TODO: this matcher is a bit lame, it may suffer from false positives
String fileName = String.valueOf(path.getFileName());
if (fileName.matches(lib.artifactId + "-\\d+.*")) {
return true;
}
return false;
}).collect(Collectors.toList());
if (paths.size() > 1) {
throw new IOException("Bug in Jenkins WAR Packager, cannot find unique lib JAR for artifact " + lib.artifactId + ". Candidates: " + StringUtils.join(paths, ","));
} else if (paths.size() == 1) {
Path oldFile = paths.get(0);
LOGGER.log(Level.INFO, "Removing library {0}. Original File: {1}", new Object[] { lib.artifactId, oldFile.getFileName() });
Files.delete(oldFile);
} else {
throw new IOException("Cannot remove library " + lib + ". It is missing in the WAR file");
}
}
use of org.apache.commons.lang3.StringUtils.join in project Gemma by PavlidisLab.
the class SearchServiceImpl method characteristicSearchWithChildren.
/**
* Search for the query in ontologies, including items that are associated with children of matching query terms.
* That is, 'brain' should return entities tagged as 'hippocampus'. This method will return results only up to
* MAX_CHARACTERISTIC_SEARCH_RESULTS. It can handle AND in searches, so Parkinson's AND neuron finds items tagged
* with both of those terms. The use of OR is handled by the caller.
*
* @param classes Classes of characteristic-bound entities. For example, to get matching characteristics of
* ExpressionExperiments, pass ExpressionExperiments.class in this collection parameter.
* @return SearchResults of CharacteristicObjects. Typically to be useful one needs to retrieve the 'parents'
* (entities which have been 'tagged' with the term) of those Characteristics
*/
private Collection<SearchResult> characteristicSearchWithChildren(Collection<Class<?>> classes, String query) {
StopWatch timer = this.startTiming();
/*
* The tricky part here is if the user has entered a boolean query. If they put in Parkinson's disease AND neuron,
* then we want to eventually return entities that are associated with both. We don't expect to find single
* characteristics that match both.
*
* But if they put in Parkinson's disease we don't want to do two queries.
*/
List<String> subparts = Arrays.asList(query.split(" AND "));
// we would have to first deal with the separate queries, and then apply the logic.
Collection<SearchResult> allResults = new HashSet<>();
SearchServiceImpl.log.info("Starting characteristic search: " + query + " for type=" + StringUtils.join(classes, ","));
for (String rawTerm : subparts) {
String trimmed = StringUtils.strip(rawTerm);
if (StringUtils.isBlank(trimmed)) {
continue;
}
Collection<SearchResult> subqueryResults = this.characteristicSearchTerm(classes, trimmed);
if (allResults.isEmpty()) {
allResults.addAll(subqueryResults);
} else {
// this is our Intersection operation.
allResults.retainAll(subqueryResults);
// aggregate the highlighted text.
Map<SearchResult, String> highlights = new HashMap<>();
for (SearchResult sqr : subqueryResults) {
highlights.put(sqr, sqr.getHighlightedText());
}
for (SearchResult ar : allResults) {
String k = highlights.get(ar);
if (StringUtils.isNotBlank(k)) {
String highlightedText = ar.getHighlightedText();
if (StringUtils.isBlank(highlightedText)) {
ar.setHighlightedText(k);
} else {
ar.setHighlightedText(highlightedText + "," + k);
}
}
}
}
if (timer.getTime() > 1000) {
SearchServiceImpl.log.info("Characteristic search for '" + rawTerm + "': " + allResults.size() + " hits retained so far; " + timer.getTime() + "ms");
timer.reset();
timer.start();
}
}
return allResults;
}
Aggregations