/** * If the string is not blank then return a trimmed version of it ending in * */ protected String endWithStarIfNotBlank(String text) { if (StringUtils.isNotBlank(text)) if (!text.endsWith("*")) { return StringUtils.trim(text) + "*"; } else { return StringUtils.trim(text); } else { return text; } }
/** * Retrieves the current Maven version. * * @return The current Maven version. */ static String getMavenVersion() { try { // This relies on the fact that MavenProject is the in core classloader // and that the core classloader is for the maven-core artifact // and that should have a pom.properties file // if this ever changes, we will have to revisit this code. Properties properties = new Properties(); // CHECKSTYLE_OFF: LineLength properties.load( MavenProject.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) ); // CHECKSTYLE_ON: LineLength return StringUtils.trim( properties.getProperty( "version" ) ); } catch ( Exception e ) { return null; } }
private void readVersion() { if (isBlank(extensionVersion)) { System.out.println("* Enter the extension's version (empty for default): "); this.extensionVersion = trim(readLine()); displayDefaultValueMessage(EXTENSION_VERSION, extensionVersion); } }
private void readArtifactId() { if (isBlank(extensionArtifactId)) { System.out.println("* Enter the extension's artifactId (empty for default): "); this.extensionArtifactId = trim(readLine()); displayDefaultValueMessage(ARTIFACT_ID, extensionArtifactId); } }
private void readGroupId() { if (isBlank(extensionGroupId)) { System.out.println("* Enter the extension's groupId (empty for default): "); this.extensionGroupId = trim(readLine()); displayDefaultValueMessage(GROUP_ID, extensionGroupId); } }
private String getVersion(String binary) { try { Process process = new PhantomJsProcessBuilder(binary).commandLineOptions("-v").start(); BufferedReader standardOut = new BufferedReader(new InputStreamReader(process.getInputStream())); String versionString = StringUtils.trim(standardOut.readLine()); return process.waitFor() == 0 ? versionString : null; // TODO Should these exceptions just be wrapped and rethrown for the mojo to handle? } catch (ExecutionException | InterruptedException | IOException e) { LOGGER.warn(SYSTEM_CHECK_FAILURE,e); } return null; } }
private String getGravatarUrl( String email ) { if ( email == null ) { return null; } email = StringUtils.trim( email ); email = email.toLowerCase(); MessageDigest md; try { md = MessageDigest.getInstance( "MD5" ); md.update( email.getBytes() ); byte[] byteData = md.digest(); StringBuilder sb = new StringBuilder(); final int lowerEightBitsOnly = 0xff; for ( byte aByteData : byteData ) { sb.append( Integer.toString( ( aByteData & lowerEightBitsOnly ) + 0x100, 16 ).substring( 1 ) ); } return protocol + "://www.gravatar.com/avatar/" + sb.toString() + "?d=mm&" + AVATAR_SIZE; } catch ( NoSuchAlgorithmException e ) { return null; } }
private void readPackage() { if (isBlank(mainPackage)) { System.out.println("* Enter the extension's main package (empty for default): "); this.mainPackage = trim(readLine()); displayDefaultValueMessage(PACKAGE, mainPackage); if (isBlank(mainPackage) && !isBlank(extensionName)) { useDefaultPackage(); } } }
private String getGravatarUrl( String email ) { if ( email == null ) { return null; } email = StringUtils.trim( email ); email = email.toLowerCase(); MessageDigest md; try { md = MessageDigest.getInstance( "MD5" ); md.update( email.getBytes() ); byte byteData[] = md.digest(); StringBuilder sb = new StringBuilder(); final int lowerEightBitsOnly = 0xff; for ( byte aByteData : byteData ) { sb.append( Integer.toString( ( aByteData & lowerEightBitsOnly ) + 0x100, 16 ).substring( 1 ) ); } return "http://www.gravatar.com/avatar/" + sb.toString() + "?d=mm&" + AVATAR_SIZE; } catch ( NoSuchAlgorithmException e ) { return null; } }
private void readExtensionName() { if (isBlank(extensionName)) { System.out.println("* Enter the name of the extension (empty for default): "); this.extensionName = capitalise(trim(readLine())); displayDefaultValueMessage(EXTENSION_NAME, extensionName); } }
@Override public String getVersion() { String line = getRequiredLines(1, "--version").get(0); return trim(remove(remove(line, "svn,"), "version")); }
/** * 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; }
/** * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String) */ public void consumeLine( String line ) { if ( getLogger().isDebugEnabled() ) { getLogger().debug( "consume line " + line ); } if ( infoItems.isEmpty() ) { if ( !StringUtils.isEmpty( line ) ) { InfoItem infoItem = new InfoItem(); infoItem.setRevision( StringUtils.trim( line ) ); infoItem.setURL( scmFileSet.getBasedir().toPath().toUri().toASCIIString() ); infoItems.add( infoItem ); } } }
/** * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String) */ public void consumeLine( String line ) { if ( getLogger().isDebugEnabled() ) { getLogger().debug( "consume line " + line ); } if ( infoItems.isEmpty() ) { if ( !StringUtils.isEmpty( line ) ) { InfoItem infoItem = new InfoItem(); infoItem.setRevision( StringUtils.trim( line ) ); infoItem.setURL( scmFileSet.getBasedir().toPath().toUri().toASCIIString() ); infoItems.add( infoItem ); } } }
public String prompt(String message) throws PrompterException { try { writePrompt(message); } catch (IOException e) { throw new PrompterException("Failed to present prompt", e); } try { return StringUtils.trim(inputHandler.readLine()); } catch (IOException e) { throw new PrompterException("Failed to read user response", e); } }
public String prompt(String message, String defaultReply) throws PrompterException { try { writePrompt(formatMessage(message, null, defaultReply)); } catch (IOException e) { throw new PrompterException("Failed to present prompt", e); } try { String line = inputHandler.readLine(); if (StringUtils.isEmpty(line)) { line = defaultReply; } return StringUtils.trim(line); } catch (IOException e) { throw new PrompterException("Failed to read user response", e); } }
infoItem.setRevision( StringUtils.trim( objectId.name() ) ); infoItem.setURL( basedir.toPath().toUri().toASCIIString() );
infoItem.setRevision( StringUtils.trim( objectId.name() ) ); infoItem.setURL( basedir.toPath().toUri().toASCIIString() );
packaging = StringUtils.trim( parser.nextText() ); break;