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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

Usage

From source file:org.jboss.windup.reporting.ReportUtil.java

public static String calculateRelativePathToRoot(File reportDirectory, File htmlOutputPath) {
    Validate.notNull(reportDirectory, "Report directory is null, but a required field.");
    Validate.notNull(htmlOutputPath, "HTML output directory is null, but a required field.");

    String archiveOutput = FilenameUtils.normalize(reportDirectory.getAbsolutePath());
    String htmlOutput = FilenameUtils.normalize(htmlOutputPath.getAbsolutePath());

    if (LOG.isDebugEnabled()) {
        LOG.debug("archiveOutput: " + archiveOutput);
        LOG.debug("htmlOutput: " + htmlOutput);
    }//from  w w w  .  j  a  v a  2s .co m

    String relative = StringUtils.removeStart(htmlOutput, archiveOutput);
    relative = StringUtils.replace(relative, "\\", "/");

    int dirCount = (StringUtils.countMatches(relative, "/") - 1);
    String relPath = "";
    for (int i = 0; i < dirCount; i++) {
        relPath += "../";
    }
    return relPath;
}

From source file:org.jboss.windup.reporting.ReportUtil.java

public static String calculateRelativePathFromRoot(File reportDirectory, File relativeFile) {
    String relPath = StringUtils.removeStart(FilenameUtils.normalize(relativeFile.getAbsolutePath()),
            FilenameUtils.normalize(reportDirectory.getAbsolutePath()));
    relPath = StringUtils.replace(relPath, "\\", "/");
    relPath = StringUtils.removeStart(relPath, "/");
    return relPath;
}

From source file:org.jboss.windup.reporting.spreadsheet.ScorecardReporter.java

@Override
public void process(ArchiveMetadata archive, File reportDirectory) {
    Validate.notNull(archive, "Archive is required, but null.");
    Validate.notNull(reportDirectory, "Report directory is required, but null.");

    File output = generateScorecardName(archive, reportDirectory);

    List<ArchiveMetadata> results = unwind(archive);

    FileOutputStream out = null;// w ww  .j  ava 2 s . c o  m
    try {
        out = new FileOutputStream(output);
        XSSFWorkbook workbook = new XSSFWorkbook();
        // create a new sheet
        XSSFSheet s = workbook.createSheet("MigrationScoreCard");

        s.setColumnWidth(0, 70 * 256);
        s.setColumnWidth(1, 20 * 256);
        s.setColumnWidth(2, 10 * 256);
        s.setColumnWidth(3, 255 * 256);

        appendTitleRow(workbook, s, 0);
        int rownum = 1;
        for (ArchiveMetadata result : results) {
            StringBuilder notes = new StringBuilder();

            for (AbstractDecoration dr : result.getDecorations()) {
                if (dr instanceof Version) {
                    notes.append(dr.toString());
                }
            }

            Set<String> classifications = new HashSet<String>();
            double estimate = 0;
            // calculate the nodes..
            for (FileMetadata ir : result.getEntries()) {
                for (AbstractDecoration dr : ir.getDecorations()) {
                    if (dr instanceof Classification) {
                        String tempDesc = dr.getDescription();
                        tempDesc = StringUtils.removeStart(tempDesc, "Classification: ");
                        classifications.add(tempDesc);
                    }
                    if (dr.getEffort() != null && dr.getEffort() instanceof StoryPointEffort) {
                        estimate += ((StoryPointEffort) dr.getEffort()).getHours();
                    }
                }

            }

            if (classifications.size() > 0) {
                for (String classification : classifications) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Found: " + classification);
                    }
                    notes.append(", ").append(classification);
                }
            }
            String notesExtracted = StringUtils.removeStart(notes.toString(), ", ");
            appendNotesRow(workbook, s, rownum, result.getRelativePath(), estimate, notesExtracted);
            rownum++;
        }
        appendTotalRow(workbook, s, rownum++);

        // empty row.
        rownum++;

        appendMentoringTitleRow(workbook, s, rownum++);
        int start = rownum + 1;
        appendNotesRow(workbook, s, rownum++, "JBoss Configuration / Documentation / Mentoring", 80, "");
        appendNotesRow(workbook, s, rownum++, "JBoss Server Setup for Apps", 80, "");
        appendNotesRow(workbook, s, rownum++, "JBoss Operations Network Setup / Documentation / Mentoring", 120,
                "");
        appendNotesRow(workbook, s, rownum++, "Deployment / Fail Over Plans", 80, "");
        int end = rownum;
        appendMentoringTotalRow(workbook, s, rownum++, start, end);

        // write the workbook to the output stream
        // close our file (don't blow out our file handles
        workbook.write(out);
    } catch (IOException e) {
        LOG.error("Exception writing scorecard to: " + output.getAbsolutePath());
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.jboss.windup.reporting.transformers.MetaResultTransformer.java

protected String buildTitle(T meta, File rootDirectory) {
    String title = StringUtils.removeStart(meta.getFilePointer().getAbsolutePath(),
            rootDirectory.getAbsolutePath());
    title = StringUtils.replace(title, "\\", "/");
    title = StringUtils.removeStart(title, "/");

    if (meta instanceof FileMetadata) {
        String starter = ((FileMetadata) meta).getArchiveMeta().getRelativePath();

        if (LOG.isDebugEnabled()) {
            LOG.debug("Removing: " + starter + " from " + title);
        }//from   w w  w  . ja v a2  s. c o m

        title = StringUtils.removeStart(title, starter);
    }
    title = StringUtils.removeStart(title, "/");

    return title;
}

From source file:org.jboss.windup.rules.apps.java.scan.ast.VariableResolvingASTVisitor.java

/***
 * Takes the MethodInvocation, and attempts to resolve the types of objects passed into the method invocation.
 */// ww w  . j av a2 s . com
public boolean visit(MethodInvocation node) {
    if (!StringUtils.contains(node.toString(), ".")) {
        // it must be a local method. ignore.
        return true;
    }

    String nodeName = StringUtils.removeStart(node.toString(), "this.");

    List<?> arguments = node.arguments();
    List<String> resolvedParams = methodParameterGuesser(arguments);

    String objRef = StringUtils.substringBefore(nodeName, "." + node.getName().toString());

    if (nameInstance.containsKey(objRef)) {
        objRef = nameInstance.get(objRef);
    }

    objRef = resolveClassname(objRef);

    MethodType methodCall = new MethodType(objRef, node.getName().toString(), resolvedParams);
    processMethod(methodCall, cu.getLineNumber(node.getName().getStartPosition()),
            cu.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength());

    return super.visit(node);
}

From source file:org.jboss.windup.util.RecursiveDirectoryMetaFactory.java

protected String generateRelativePath(File dir) {
    String absPath = start.getParentFile().getAbsolutePath();
    String relative = StringUtils.removeStart(dir.getAbsolutePath(), absPath);
    relative = StringUtils.replace(relative, "\\", "/");
    return relative;
}

From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java

private ZipMetadata generateArchive(ZipMetadata parent, File entryOutput) {
    String relativePath = StringUtils.removeStart(entryOutput.getAbsolutePath(),
            this.startLocation.getAbsolutePath().toString());

    if (LOG.isTraceEnabled()) {
        LOG.trace("RE Relative Path: " + relativePath);
        LOG.trace("SafeKey: " + safeExtractKey);
    }//from  w  w w  .  j  av  a  2s . c om

    relativePath = StringUtils.replace(relativePath, "\\", "/");
    relativePath = StringUtils.removeStart(relativePath, "/");

    if (StringUtils.contains(relativePath, this.safeExtractKey)) {
        // all subarchives of the target archive will get copied to a location with the safeExtractKey.
        relativePath = StringUtils.remove(relativePath, this.safeExtractKey);
    } else {
        // otherwise, we know it is the original file...
        relativePath = StringUtils.substringAfterLast(relativePath, "/");
    }

    String archiveName = relativePath;
    if (StringUtils.contains(archiveName, "/")) {
        archiveName = StringUtils.substringAfterLast(relativePath, "/");
    }

    ZipMetadata archive = new ZipMetadata();
    archive.setName(archiveName);
    archive.setFilePointer(entryOutput);
    archive.setRelativePath(relativePath);

    if (parent != null) {
        parent.getNestedArchives().add(archive);
    }

    archive.setArchiveMeta(parent);

    if (LOG.isTraceEnabled()) {
        LOG.trace("Created archive: " + archive.toString());
    }
    return archive;
}

From source file:org.jboss.windup.util.RPMToZipTransformer.java

public static File convertRpmToZip(File file) throws Exception {
    LOG.info("File: " + file.getAbsolutePath());

    FileInputStream fis = new FileInputStream(file);
    ReadableChannelWrapper in = new ReadableChannelWrapper(Channels.newChannel(fis));

    InputStream uncompressed = new GZIPInputStream(fis);
    in = new ReadableChannelWrapper(Channels.newChannel(uncompressed));

    String rpmZipName = file.getName();
    rpmZipName = StringUtils.replace(rpmZipName, ".", "-");
    rpmZipName = rpmZipName + ".zip";
    String rpmZipPath = FilenameUtils.getFullPath(file.getAbsolutePath());

    File rpmZipOutput = new File(rpmZipPath + File.separator + rpmZipName);
    LOG.info("Converting RPM: " + file.getName() + " to ZIP: " + rpmZipOutput.getName());
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(rpmZipOutput));

    String rpmName = file.getName();
    rpmName = StringUtils.replace(rpmName, ".", "-");

    CpioHeader header;/*w w  w. j  av  a  2  s . c  o  m*/
    int total = 0;
    do {
        header = new CpioHeader();
        total = header.read(in, total);

        if (header.getFileSize() > 0) {
            BoundedInputStream bis = new BoundedInputStream(uncompressed, header.getFileSize());

            String relPath = FilenameUtils.separatorsToSystem(header.getName());
            relPath = StringUtils.removeStart(relPath, ".");
            relPath = StringUtils.removeStart(relPath, "/");
            relPath = rpmName + File.separator + relPath;
            relPath = StringUtils.replace(relPath, "\\", "/");

            ZipEntry zipEntry = new ZipEntry(relPath);
            zos.putNextEntry(zipEntry);
            IOUtils.copy(bis, zos);
        } else {
            final int skip = header.getFileSize();
            if (uncompressed.skip(skip) != skip)
                throw new RuntimeException("Skip failed.");
        }

        total += header.getFileSize();
    } while (!header.isLast());

    zos.flush();
    zos.close();

    return rpmZipOutput;
}

From source file:org.jdto.impl.BeanPropertyUtils.java

/**
 * Remove the accessor prefix from name and the bean capitalization.
 * This can be used by getters and setters.
 * @param method/* ww  w . ja  v a2s.  c  o m*/
 * @return 
 */
private static String convertToPropertyName(Method method) {
    String methodName = method.getName();

    if (StringUtils.startsWith(methodName, "set")) {
        methodName = StringUtils.removeStart(methodName, "set");
    } else if (StringUtils.startsWith(methodName, "is")) {
        methodName = StringUtils.removeStart(methodName, "is");
    } else if (StringUtils.startsWith(methodName, "get")) {
        methodName = StringUtils.removeStart(methodName, "get");
    }

    //remove the first capital
    return StringUtils.uncapitalize(methodName);
}

From source file:org.jenkins.plugins.cloudbees.CloudbeesPublisher.java

/**
 * Called when object has been deserialized from a stream.
 *
 * @return {@code this}, or a replacement for {@code this}.
 * @throws java.io.ObjectStreamException if the object cannot be restored.
 * @see <a href="http://download.oracle.com/javase/1.3/docs/guide/serialization/spec/input.doc6.html">The Java
 *      Object Serialization Specification</a>
 *//*from   w ww  .j a  va  2s . co  m*/
private Object readResolve() throws ObjectStreamException {
    String accountName = Util.fixEmptyAndTrim(this.accountName);
    String applicationId = StringUtils.removeStart(this.applicationId, accountName + "/");
    int index = applicationId.lastIndexOf('/');
    if (index != -1 && index + 1 < applicationId.length()) {
        applicationId = applicationId.substring(index + 1);
    }
    List<RunTargetImpl> deployTargets = new ArrayList<RunTargetImpl>();
    if (StringUtils.isNotEmpty(applicationId)) {
        deployTargets.add(new RunTargetImpl(EndPoints.runAPI(), applicationId, null, null, null,
                new WildcardPathDeploySource(StringUtils.isEmpty(filePattern) ? "**/*.war" : filePattern),
                false, null, null, null));
    }
    CloudbeesAccount account = null;
    for (CloudbeesAccount a : DESCRIPTOR.accounts) {
        if (accountName.equals(a.name)) {
            account = a;
            break;
        }
    }
    CloudBeesUser user = null;
    if (account != null) {
        for (CloudBeesUser u : CredentialsProvider.lookupCredentials(CloudBeesUser.class)) {
            if (u.getAPIKey().equals(account.apiKey)) {
                user = u;
                break;
            }
        }
    }
    return new DeployPublisher(
            Arrays.asList(new RunHostImpl(user != null ? user.getName() : null, accountName, deployTargets)),
            false);
}