private String getDisplayName(String name) { String truncatedName = name.length() >= MAX_NAME_LENGTH ? StringUtils.substring(name, 0, MAX_NAME_LENGTH) : name + " "; return StringUtils.rightPad(truncatedName, MAX_NAME_LENGTH, "."); } }
private String getCommonPackage(String packageName, String templatePackage) { String common; String difference=StringUtils.difference(packageName, templatePackage); if (StringUtils.isNotEmpty(difference)) { String temporaryCommon=StringUtils.substring(templatePackage, 0, templatePackage.lastIndexOf(difference)); if (!difference.startsWith(".")) { common=StringUtils.substring(temporaryCommon, 0, temporaryCommon.lastIndexOf(".")); } else { common=temporaryCommon; } } else { common=packageName; } return common; }
protected static String removeNonDigitPrefix(String version) { if (version != null && !version.isEmpty()) { if (!Character.isDigit(version.charAt(0))) { Matcher matcher = Pattern.compile("\\d+").matcher(version); int i = 0; if (matcher.find()) { i = matcher.start(); } if (i > 0) { version = StringUtils.substring(version, i, version.length()); } } } return version; }
/** * The 4th (build) token MUST be separed with "-" and not with "." in maven. A version with 4 dots is not parsed, * and the whole string is considered a qualifier. See tests in DefaultArtifactVersion for reference. * * @param version initial version * @param forcedQualifier build number * @param stripQualifier always remove 4th token in version * @return converted version */ protected String osgiVersionToMavenVersion( String version, String forcedQualifier, boolean stripQualifier ) { if ( stripQualifier && StringUtils.countMatches( version, "." ) > 2 ) //$NON-NLS-1$ { version = StringUtils.substring( version, 0, version.lastIndexOf( '.' ) ); //$NON-NLS-1$ } else if ( StringUtils.countMatches( version, "." ) > 2 ) //$NON-NLS-1$ { int lastDot = version.lastIndexOf( '.' ); //$NON-NLS-1$ if ( StringUtils.isNotEmpty( forcedQualifier ) ) { version = StringUtils.substring( version, 0, lastDot ) + "-" + forcedQualifier; //$NON-NLS-1$ } else { version = StringUtils.substring( version, 0, lastDot ) + "-" //$NON-NLS-1$ + StringUtils.substring( version, lastDot + 1, version.length() ); } } return version; }
private String getCommonPackage( String packageName, String templatePackage ) { String common = ""; String difference = StringUtils.difference( packageName, templatePackage ); if ( StringUtils.isNotEmpty( difference ) ) { String temporaryCommon = StringUtils.substring( templatePackage, 0, templatePackage.lastIndexOf( difference ) ); if ( !difference.startsWith( "." ) ) { common = StringUtils.substring( temporaryCommon, 0, temporaryCommon.lastIndexOf( "." ) ); } else { common = temporaryCommon; } } else { common = packageName; } return common; }
/** * Fix the separator for the 4th token in a versions. In maven this must be "-", in OSGI it's "." * * @param versionRange input range * @return modified version range */ protected String fixBuildNumberSeparator( String versionRange ) { // should not be called with a null versionRange, but a check doesn't hurt... if ( versionRange == null ) { return null; } StringBuffer newVersionRange = new StringBuffer(); Matcher matcher = VERSION_PATTERN.matcher( versionRange ); while ( matcher.find() ) { String group = matcher.group(); if ( StringUtils.countMatches( group, "." ) > 2 ) //$NON-NLS-1$ { // build number found, fix it int lastDot = group.lastIndexOf( '.' ); //$NON-NLS-1$ group = StringUtils.substring( group, 0, lastDot ) + "-" //$NON-NLS-1$ + StringUtils.substring( group, lastDot + 1, group.length() ); } matcher.appendReplacement( newVersionRange, group ); } matcher.appendTail( newVersionRange ); return newVersionRange.toString(); }
private String shortenFilename( String filename, PmdFileInfo fileInfo ) { String result = filename; if ( fileInfo != null && fileInfo.getSourceDirectory() != null ) { result = StringUtils.substring( result, fileInfo.getSourceDirectory().getAbsolutePath().length() + 1 ); } return StringUtils.replace( result, "\\", "/" ); }
private Collection<String> getUpgradeListFromScriptDir() throws DBUpgradeException { SortedSet<String> upgradeFileNameSet = new TreeSet<String>( new Comparator<String>() { public int compare( String a, String b ) { return a.compareTo( b ); } } ); Collection<File> fileList = FileUtils.listFiles( config.getScriptDirectory(), new String[] { "sql" }, true ); for ( File file : fileList ) { String diff = StringUtils.difference( config.getScriptDirectory().getAbsolutePath(), file.getAbsolutePath() ); diff = StringUtils.substring( diff, 1 ); // remove the starting / after the diff diff = StringUtils.replace( diff, File.separator, "/" ); upgradeFileNameSet.add( diff ); } return upgradeFileNameSet; }
protected static ArtifactVersion parseArtifactVersion(String version) { version = version.replaceAll("\\s", ""); version = removeNonDigitPrefix(version); version = addSuffixDelimeterIfNeeded(version); ArtifactVersion artifactVersion = new DefaultArtifactVersion(version); if (ArtifactUtils.isSnapshot(version)) { artifactVersion = new DefaultArtifactVersion(StringUtils.substring(version, 0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1)); } return artifactVersion; }
/** {@inheritDoc} */ public void fileStarted( AuditEvent event ) { final String fileName = StringUtils.replace( event.getFileName(), "\\", "/" ); for ( File sourceDirectory : sourceDirectories ) { String sourceDirectoryPath = StringUtils.replace( sourceDirectory.getPath(), "\\", "/" ); if ( fileName.startsWith( sourceDirectoryPath + "/" ) ) { currentFile = StringUtils.substring( fileName, sourceDirectoryPath.length() + 1 ); events = getResults().getFileViolations( currentFile ); break; } } if ( events == null ) { events = new ArrayList<>(); } }
/** * Output looks like this: * * <pre> * UID PID PPID C STIME TTY TIME CMD * tomcat 15461 15460 0 22:51 pts/0 00:00:00 -bash * tomcat 15480 15461 0 22:52 pts/0 00:00:02 java -jar /usr/local/machine-agent/machineagent.jar * </pre> */ public static UnixProcess getUnixProcess(String header, String line) { // Split the strings up into tokens String[] tokens = StringUtils.split(line, " "); // First token is the user id String userId = StringUtils.trim(tokens[0]); // Second token is the process id String processId = StringUtils.trim(tokens[1]); // The command starts where "CMD" starts in the header line int pos = header.indexOf(CMD); // Make sure we found the string "CMD" Assert.isFalse(pos == -1, "[" + line + "] does not contain [" + CMD + "]"); // This is the command used to launch the process String command = StringUtils.trim(StringUtils.substring(line, pos)); // Store the information we've parsed out into pojo UnixProcess process = new UnixProcess(); process.setUserId(userId); process.setProcessId(Integer.parseInt(processId)); process.setCommand(command); return process; }
PmdFileInfo fileInfo = fileMap.get( file ); File sourceDirectory = fileInfo.getSourceDirectory(); filename = StringUtils.substring( filename, sourceDirectory.getAbsolutePath().length() + 1 ); String xrefLocation = fileInfo.getXrefLocation(); MavenProject projectFile = fileInfo.getProject();