List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:org.jboss.windup.interrogator.impl.ClassInterrogator.java
protected String extractClassName(String entryName) { String className = StringUtils.replace(entryName, "\\", "/"); className = StringUtils.removeStart(className, "/"); className = StringUtils.replace(className, "/", "."); className = StringUtils.removeEnd(className, ".class"); className = StringUtils.removeEnd(className, ".java"); className = StringUtils.substringBefore(className, "$"); // account for WAR classes. if (StringUtils.contains(className, "WEB-INF.classes.")) { className = StringUtils.substringAfter(className, "WEB-INF.classes."); }/* w ww .ja va 2 s.c o m*/ return className; }
From source file:org.jboss.windup.reporting.html.freemarker.ArchiveReportSummarySerializer.java
@Override public void execute(Environment env, Map map, TemplateModel[] templateModel, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { StringModel stringModel = (StringModel) map.get("archive"); ArchiveReport archive = (ArchiveReport) stringModel.getWrappedObject(); Writer bw = env.getOut();/*from www. ja v a 2s . c o m*/ String jvmVersion = null; String vendor = null; Version version = null; String summary = null; // eliminate links to same place.. Set<Link> links = new TreeSet<Link>(new Comparator<Link>() { @Override public int compare(Link o1, Link o2) { String link1 = StringUtils.removeEnd(o1.getLink(), "/"); String link2 = StringUtils.removeEnd(o2.getLink(), "/"); if (StringUtils.equals(link1, link2)) { return 0; } if (o1 == null || o2 == null) { return 1; } return o1.getLink().compareTo(o2.getLink()); } }); if (archive.getDecorations() != null) { for (AbstractDecoration dr : archive.getDecorations()) { if (dr == null) { LOG.info("Skipping null decorator."); continue; } if (dr instanceof VendorResult) { vendor = ((VendorResult) dr).toString(); } if (dr instanceof Version) { if ((version != null && version instanceof PomVersion)) { // do nothing. } else if (version == null) { version = ((Version) dr); } else { version = ((Version) dr); } } if (dr instanceof Summary) { summary = ((Summary) dr).getDescription(); } if (dr instanceof Link) { links.add((Link) dr); } if (dr instanceof JVMBuildVersionResult) { jvmVersion = ((JVMBuildVersionResult) dr).getJdkBuildVersion(); } } } StringBuilder builder = new StringBuilder(); if (StringUtils.isNotBlank(vendor)) { builder.append("<div class='archiveSummaryPart'><h3>Vendor</h3><p>").append(vendor) .append("</p></div>"); } if (version != null) { builder.append("<div class='archiveSummaryPart'><h3>Version</h3><p>").append(version.toString()) .append("</p></div>"); } if (links.size() > 0) { for (Link link : links) { builder.append("<div class='archiveSummaryPart'><h3>Link</h3><p><a href='" + link.getLink() + "'>" + link.getDescription() + "</p></a></div>"); } } if (jvmVersion != null && builder.toString().length() > 0) { builder.append("<div class='archiveSummaryPart'><h3>JVM</h3><p>" + "<span class='jreVersion'>" + jvmVersion + "</span></div>"); } if (StringUtils.isNotBlank(summary)) { builder.append("<div class='archiveSummaryPart'><h3>Description</h3><p>" + summary + "</p></div>"); } String body = builder.toString(); if (body.length() > 0) { bw.append("<div class='archiveSummary'>"); bw.append(body); bw.append("</div>"); } }
From source file:org.jboss.windup.rules.apps.java.scan.ast.VariableResolvingASTVisitor.java
private String qualifyType(String objRef) { // temporarily remove to resolve arrays objRef = StringUtils.removeEnd(objRef, "[]"); if (nameInstance.containsKey(objRef)) { objRef = nameInstance.get(objRef); }/* w w w .j ava2s . c om*/ objRef = resolveClassname(objRef); return objRef; }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.java
/** * Tries to guess the HTTPS URL of the Git repository. * * @param source the source.//from ww w .ja va 2 s. com * @return the (possibly incorrect) best guess at the Git repository URL. */ private static String guessRemote(GitHubSCMSource source) { String apiUri = StringUtils.removeEnd(source.getApiUri(), "/"); if (StringUtils.isBlank(apiUri) || GitHubServerConfig.GITHUB_URL.equals(apiUri)) { apiUri = "https://github.com"; } else { apiUri = StringUtils.removeEnd(apiUri, "/" + API_V3); } return apiUri + "/" + source.getRepoOwner() + "/" + source.getRepository() + ".git"; }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.java
/** * Tries as best as possible to guess the repository HTML url to use with {@link GithubWeb}. * * @param owner the owner.// w w w . jav a 2 s. c om * @param repo the repository. * @return the HTML url of the repository or {@code null} if we could not determine the answer. */ @CheckForNull public final String repositoryUrl(String owner, String repo) { if (repositoryUrl != null) { if (repoOwner.equals(owner) && repository.equals(repo)) { return repositoryUrl.toExternalForm(); } // hack! return repositoryUrl.toExternalForm().replace(repoOwner + "/" + repository, owner + "/" + repo); } if (StringUtils.isBlank(apiUri) || GitHubServerConfig.GITHUB_URL.equals(apiUri)) { return "https://github.com/" + owner + "/" + repo; } if (StringUtils.endsWith(StringUtils.removeEnd(apiUri, "/"), "/" + API_V3)) { return StringUtils.removeEnd(StringUtils.removeEnd(apiUri, "/"), API_V3) + owner + "/" + repo; } return null; }
From source file:org.jfrog.bamboo.admin.ArtifactoryAdminConfigServlet.java
/** * Returns the global variable map in JSON format *//*ww w . j a v a 2 s .c o m*/ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Map<String, String> globalVariableMap = Maps.newHashMap(); String planKey = req.getParameter(ConstantValues.PLAN_KEY_PARAM); if (StringUtils.isNotBlank(planKey)) { Plan plan = planManager.getPlanByKey(planKey); if (plan instanceof DefaultJob) { //Default jobs don't have any global vars, so fetch the actual plan itself instead plan = planManager.getPlanByKey(StringUtils.removeEnd(plan.getKey(), "-" + plan.getBuildKey())); } appendVariableDefs(globalVariableMap, variableDefinitionManager.getPlanVariables(plan)); appendVariableDefs(globalVariableMap, variableDefinitionManager.getGlobalNotOverriddenVariables(plan)); } else { appendVariableDefs(globalVariableMap, variableDefinitionManager.getGlobalVariables()); } JsonFactory jsonFactory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(); jsonFactory.setCodec(mapper); PrintWriter writer = null; try { writer = resp.getWriter(); JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer); jsonGenerator.writeObject(globalVariableMap); writer.flush(); } finally { IOUtils.closeQuietly(writer); } }
From source file:org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper.java
public static String removeDoubleDotsFromPattern(String pattern) { if (pattern == null) { throw new IllegalArgumentException("Cannot remove double dots from a null pattern."); }/*from w w w . j ava 2 s. c om*/ if (!pattern.contains("..")) { return pattern; } String[] splitPattern = pattern.split("/"); StringBuilder patternBuilder = new StringBuilder(); if (pattern.startsWith("/")) { patternBuilder.append("/"); } for (int i = 0; i < splitPattern.length; i++) { if (!"..".equals(splitPattern[i])) { patternBuilder.append(splitPattern[i]); if (i != (splitPattern.length - 1)) { patternBuilder.append("/"); } } } return StringUtils.removeEnd(patternBuilder.toString(), "/"); }
From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java
private void addArtifactsToCurrentModule(MavenProject project, ModuleBuilder module) { Set<Artifact> moduleArtifacts = currentModuleArtifacts.get(); if (moduleArtifacts == null) { logger.warn(/*from w ww .j a va2 s .c o m*/ "Skipping Artifactory Build-Info module artifact addition: Null current module artifact list."); return; } ArtifactoryClientConfiguration.PublisherHandler publisher = conf.publisher; IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns()); boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild(); for (Artifact moduleArtifact : moduleArtifacts) { String artifactId = moduleArtifact.getArtifactId(); String artifactVersion = moduleArtifact.getVersion(); String artifactClassifier = moduleArtifact.getClassifier(); String artifactExtension = moduleArtifact.getArtifactHandler().getExtension(); String type = getTypeString(moduleArtifact.getType(), artifactClassifier, artifactExtension); String artifactName = getArtifactName(artifactId, artifactVersion, artifactClassifier, artifactExtension); ArtifactBuilder artifactBuilder = new ArtifactBuilder(artifactName).type(type); File artifactFile = moduleArtifact.getFile(); // for pom projects take the file from the project if the artifact file is null if (isPomProject(moduleArtifact) && moduleArtifact.equals(project.getArtifact())) { artifactFile = project.getFile(); // project.getFile() returns the project pom file } org.jfrog.build.api.Artifact artifact = artifactBuilder.build(); String groupId = moduleArtifact.getGroupId(); String deploymentPath = getDeploymentPath(groupId, artifactId, artifactVersion, artifactClassifier, artifactExtension); // If excludeArtifactsFromBuild and the PatternMatcher found conflict, add the excluded artifact to the excluded artifact set. if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) { module.addExcludedArtifact(artifact); } else { module.addArtifact(artifact); } if (isPublishArtifacts(artifactFile)) { addDeployableArtifact(artifact, artifactFile, moduleArtifact.getGroupId(), artifactId, artifactVersion, artifactClassifier, artifactExtension); } /* * In case of non packaging Pom project module, we need to create the pom file from the ProjectArtifactMetadata on the Artifact */ if (!isPomProject(moduleArtifact)) { for (ArtifactMetadata metadata : moduleArtifact.getMetadataList()) { if (metadata instanceof ProjectArtifactMetadata) { // the pom metadata File pomFile = ((ProjectArtifactMetadata) metadata).getFile(); artifactBuilder.type("pom"); String pomFileName = StringUtils.removeEnd(artifactName, artifactExtension) + "pom"; artifactBuilder.name(pomFileName); org.jfrog.build.api.Artifact pomArtifact = artifactBuilder.build(); deploymentPath = getDeploymentPath(groupId, artifactId, artifactVersion, artifactClassifier, "pom"); if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) { module.addExcludedArtifact(pomArtifact); } else { module.addArtifact(pomArtifact); } if (isPublishArtifacts(pomFile)) { addDeployableArtifact(pomArtifact, pomFile, moduleArtifact.getGroupId(), artifactId, artifactVersion, artifactClassifier, "pom"); } break; } } } } }
From source file:org.jfrog.hudson.ArtifactoryServer.java
@DataBoundConstructor public ArtifactoryServer(String serverId, String artifactoryUrl, CredentialsConfig deployerCredentialsConfig, CredentialsConfig resolverCredentialsConfig, int timeout, boolean bypassProxy) { this.url = StringUtils.removeEnd(artifactoryUrl, "/"); this.deployerCredentialsConfig = deployerCredentialsConfig; this.resolverCredentialsConfig = resolverCredentialsConfig; this.timeout = timeout > 0 ? timeout : DEFAULT_CONNECTION_TIMEOUT; this.bypassProxy = bypassProxy; this.id = serverId; }
From source file:org.jfrog.hudson.gradle.ArtifactoryGradleConfigurator.java
private String cleanString(String artifactPattern) { return StringUtils.removeEnd(StringUtils.removeStart(artifactPattern, "\""), "\""); }