List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:org.bigmouth.nvwa.zookeeper.config.ZkPropertyPlaceholderConfigurer.java
private void fillRemoteProperties(Properties props) { String cfg = props.getProperty(KEY_ZOOKEEPER_SERVERS); String servers = ReaderFactory.matching(cfg).read(); if (StringUtils.isNotBlank(servers)) { zkClientHolder = new ZkClientHolder(servers); zkClientHolder.init();//from w ww.j av a 2 s .co m } if (null == zkClientHolder) { return; } CuratorFramework zk = zkClientHolder.get(); if (null == zk) { return; } String paths = props.getProperty(KEY_ZOOKEEPER_NODE_PATHS); if (StringUtils.isNotBlank(paths)) { String[] nodePaths = paths.split(PATH_SPLIT); for (String path : nodePaths) { path = StringUtils.removeStart(path, "!"); try { PathUtils.validatePath(path); if (LOGGER.isInfoEnabled()) { LOGGER.info("Loading properties file from ZooKeeper [{}]", path); } byte[] data = getData(zk, path); if (!ArrayUtils.isEmpty(data)) { Properties properties = convert(data); props.putAll(properties); } } catch (IllegalArgumentException e) { LOGGER.warn("Illegal path: {}, Has been ignored!", path); } } } }
From source file:org.broadleafcommerce.core.web.api.endpoint.order.CartEndpoint.java
protected HashMap<String, String> getOptions(MultiValueMap<String, String> requestParams) { HashMap<String, String> productOptions = new HashMap<String, String>(); //Fill up a map of key values that will represent product options Set<String> keySet = requestParams.keySet(); for (String key : keySet) { if (requestParams.getFirst(key) != null) { //Product options should be returned with "productOption." as a prefix. We'll look for those, and //remove the prefix. if (key.startsWith("productOption.")) { productOptions.put(StringUtils.removeStart(key, "productOption."), requestParams.getFirst(key)); }// w w w. j a v a2 s.c o m } } return productOptions; }
From source file:org.codehaus.groovy.grails.support.MockApplicationContext.java
/** * Registers a mock resource. Path separator: "/" * @param location the location of the resource. Example: /WEB-INF/grails-app/i18n/messages.properties *///from w ww .jav a 2 s.c om public void registerMockResource(String location) { resources.add(new ClassPathResource(StringUtils.removeStart(location, "/"))); }
From source file:org.codehaus.groovy.grails.support.MockApplicationContext.java
/** * Registers a mock resource. Path separator: "/" * @param location the location of the resource. Example: /WEB-INF/grails-app/i18n/messages.properties *///from www. j a va 2 s .com public void registerMockResource(String location, String contents) { resources.add(new MockResource(StringUtils.removeStart(location, "/"), contents)); }
From source file:org.codehaus.groovy.grails.support.MockApplicationContext.java
public Resource[] getResources(String locationPattern) throws IOException { if (locationPattern.startsWith("classpath:") || locationPattern.startsWith("file:")) { throw new UnsupportedOperationException( "Location patterns 'classpath:' and 'file:' not supported by implementation"); }//from w w w. j a va 2 s .c o m locationPattern = StringUtils.removeStart(locationPattern, "/"); // starting with "**/" is OK List<Resource> result = new ArrayList<Resource>(); for (Resource res : resources) { String path = res instanceof ClassPathResource ? ((ClassPathResource) res).getPath() : res.getDescription(); if (pathMatcher.match(locationPattern, path)) { result.add(res); } } return result.toArray(new Resource[0]); }
From source file:org.codehaus.groovy.grails.support.MockApplicationContext.java
public Resource getResource(String location) { for (Resource mockResource : resources) { if (pathMatcher.match(mockResource.getDescription(), StringUtils.removeStart(location, "/"))) { return mockResource; }//from w w w .j a v a 2 s . c o m } // Check for ignored resources and return null instead of a classpath resource in that case. for (String resourceLocation : ignoredClassLocations) { if (pathMatcher.match(StringUtils.removeStart(location, "/"), StringUtils.removeStart(resourceLocation, "/"))) { return null; } } return new ClassPathResource(location); }
From source file:org.codehaus.mojo.mrm.impl.maven.MemoryArtifactStore.java
/** * {@inheritDoc}//from w w w. j av a2 s .c o m */ public synchronized Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { Metadata metadata = new Metadata(); boolean foundMetadata = false; path = StringUtils.stripEnd(StringUtils.stripStart(path, "/"), "/"); String groupId = path.replace('/', '.'); Set pluginArtifactIds = getArtifactIds(groupId); if (pluginArtifactIds != null) { List plugins = new ArrayList(); for (Iterator i = pluginArtifactIds.iterator(); i.hasNext();) { String artifactId = (String) i.next(); Set pluginVersions = getVersions(groupId, artifactId); if (pluginVersions == null || pluginVersions.isEmpty()) { continue; } String[] versions = (String[]) pluginVersions.toArray(new String[pluginVersions.size()]); Arrays.sort(versions, new VersionComparator()); MavenXpp3Reader reader = new MavenXpp3Reader(); for (int j = versions.length - 1; j >= 0; j--) { InputStream inputStream = null; try { inputStream = get(new Artifact(groupId, artifactId, versions[j], "pom")); Model model = reader.read(new XmlStreamReader(inputStream)); if (model == null || !"maven-plugin".equals(model.getPackaging())) { continue; } Plugin plugin = new Plugin(); plugin.setArtifactId(artifactId); plugin.setName(model.getName()); // TODO proper goal-prefix determination // ugh! this is incredibly hacky and does not handle some fool that sets the goal prefix in // a parent pom... ok unlikely, but stupid is as stupid does boolean havePrefix = false; final Build build = model.getBuild(); if (build != null && build.getPlugins() != null) { havePrefix = setPluginGoalPrefixFromConfiguration(plugin, build.getPlugins()); } if (!havePrefix && build != null && build.getPluginManagement() != null && build.getPluginManagement().getPlugins() != null) { havePrefix = setPluginGoalPrefixFromConfiguration(plugin, build.getPluginManagement().getPlugins()); } if (!havePrefix && artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { plugin.setPrefix(StringUtils.removeStart(StringUtils.removeEnd(artifactId, "-plugin"), "maven-")); havePrefix = true; } if (!havePrefix && artifactId.endsWith("-maven-plugin")) { plugin.setPrefix(StringUtils.removeEnd(artifactId, "-maven-plugin")); havePrefix = true; } if (!havePrefix) { plugin.setPrefix(artifactId); } plugins.add(plugin); foundMetadata = true; break; } catch (ArtifactNotFoundException e) { // ignore } catch (XmlPullParserException e) { // ignore } finally { IOUtils.closeQuietly(inputStream); } } } if (!plugins.isEmpty()) { metadata.setPlugins(plugins); } } int index = path.lastIndexOf('/'); groupId = (index == -1 ? groupId : groupId.substring(0, index)).replace('/', '.'); String artifactId = (index == -1 ? null : path.substring(index + 1)); if (artifactId != null) { Set artifactVersions = getVersions(groupId, artifactId); if (artifactVersions != null && !artifactVersions.isEmpty()) { metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); Versioning versioning = new Versioning(); List versions = new ArrayList(artifactVersions); Collections.sort(versions, new VersionComparator()); // sort the Maven way long lastUpdated = 0; for (Iterator i = versions.iterator(); i.hasNext();) { String version = (String) i.next(); try { long lastModified = getLastModified(new Artifact(groupId, artifactId, version, "pom")); versioning.addVersion(version); if (lastModified >= lastUpdated) { lastUpdated = lastModified; versioning.setLastUpdatedTimestamp(new Date(lastModified)); versioning.setLatest(version); if (!version.endsWith("-SNAPSHOT")) { versioning.setRelease(version); } } } catch (ArtifactNotFoundException e) { // ignore } } metadata.setVersioning(versioning); foundMetadata = true; } } int index2 = index == -1 ? -1 : path.lastIndexOf('/', index - 1); groupId = index2 == -1 ? groupId : groupId.substring(0, index2).replace('/', '.'); artifactId = index2 == -1 ? artifactId : path.substring(index2 + 1, index); String version = index2 == -1 ? null : path.substring(index + 1); if (version != null && version.endsWith("-SNAPSHOT")) { Map artifactMap = (Map) contents.get(groupId); Map versionMap = (Map) (artifactMap == null ? null : artifactMap.get(artifactId)); Map filesMap = (Map) (versionMap == null ? null : versionMap.get(version)); if (filesMap != null) { List snapshotVersions = new ArrayList(); int maxBuildNumber = 0; long lastUpdated = 0; String timestamp = null; boolean found = false; for (Iterator i = filesMap.entrySet().iterator(); i.hasNext();) { final Map.Entry entry = (Map.Entry) i.next(); final Artifact artifact = (Artifact) entry.getKey(); final Content content = (Content) entry.getValue(); SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String lastUpdatedTime = fmt.format(new Date(content.getLastModified())); try { Maven3.addSnapshotVersion(snapshotVersions, artifact, lastUpdatedTime); } catch (LinkageError e) { // Maven 2 } if ("pom".equals(artifact.getType())) { if (artifact.getBuildNumber() != null && maxBuildNumber < artifact.getBuildNumber().intValue()) { maxBuildNumber = artifact.getBuildNumber().intValue(); timestamp = artifact.getTimestampString(); } else { maxBuildNumber = Math.max(1, maxBuildNumber); } lastUpdated = Math.max(lastUpdated, content.getLastModified()); found = true; } } if (!snapshotVersions.isEmpty() || found) { Versioning versioning = metadata.getVersioning(); if (versioning == null) { versioning = new Versioning(); } metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); metadata.setVersion(version); try { Maven3.addSnapshotVersions(versioning, snapshotVersions); } catch (LinkageError e) { // Maven 2 } if (maxBuildNumber > 0) { Snapshot snapshot = new Snapshot(); snapshot.setBuildNumber(maxBuildNumber); snapshot.setTimestamp(timestamp); versioning.setSnapshot(snapshot); } versioning.setLastUpdatedTimestamp(new Date(lastUpdated)); metadata.setVersioning(versioning); foundMetadata = true; } } } if (!foundMetadata) { throw new MetadataNotFoundException(path); } return metadata; }
From source file:org.codehaus.mojo.mrm.impl.maven.MockArtifactStore.java
/** * {@inheritDoc}//w w w . j av a 2 s . c om */ public synchronized Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { Metadata metadata = new Metadata(); boolean foundMetadata = false; path = StringUtils.stripEnd(StringUtils.stripStart(path, "/"), "/"); String groupId = path.replace('/', '.'); Set<String> pluginArtifactIds = getArtifactIds(groupId); if (pluginArtifactIds != null) { List<Plugin> plugins = new ArrayList<Plugin>(); for (String artifactId : pluginArtifactIds) { Set<String> pluginVersions = getVersions(groupId, artifactId); if (pluginVersions == null || pluginVersions.isEmpty()) { continue; } String[] versions = pluginVersions.toArray(new String[pluginVersions.size()]); Arrays.sort(versions, new VersionComparator()); MavenXpp3Reader reader = new MavenXpp3Reader(); for (int j = versions.length - 1; j >= 0; j--) { InputStream inputStream = null; try { inputStream = get(new Artifact(groupId, artifactId, versions[j], "pom")); Model model = reader.read(new XmlStreamReader(inputStream)); if (model == null || !"maven-plugin".equals(model.getPackaging())) { continue; } Plugin plugin = new Plugin(); plugin.setArtifactId(artifactId); plugin.setName(model.getName()); // TODO proper goal-prefix determination // ugh! this is incredibly hacky and does not handle some fool that sets the goal prefix in // a parent pom... ok unlikely, but stupid is as stupid does boolean havePrefix = false; final Build build = model.getBuild(); if (build != null && build.getPlugins() != null) { havePrefix = setPluginGoalPrefixFromConfiguration(plugin, build.getPlugins()); } if (!havePrefix && build != null && build.getPluginManagement() != null && build.getPluginManagement().getPlugins() != null) { havePrefix = setPluginGoalPrefixFromConfiguration(plugin, build.getPluginManagement().getPlugins()); } if (!havePrefix && artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { plugin.setPrefix(StringUtils.removeStart(StringUtils.removeEnd(artifactId, "-plugin"), "maven-")); havePrefix = true; } if (!havePrefix && artifactId.endsWith("-maven-plugin")) { plugin.setPrefix(StringUtils.removeEnd(artifactId, "-maven-plugin")); havePrefix = true; } if (!havePrefix) { plugin.setPrefix(artifactId); } plugins.add(plugin); foundMetadata = true; break; } catch (ArtifactNotFoundException e) { // ignore } catch (XmlPullParserException e) { // ignore } finally { IOUtils.closeQuietly(inputStream); } } } if (!plugins.isEmpty()) { metadata.setPlugins(plugins); } } int index = path.lastIndexOf('/'); groupId = (index == -1 ? groupId : groupId.substring(0, index)).replace('/', '.'); String artifactId = (index == -1 ? null : path.substring(index + 1)); if (artifactId != null) { Set<String> artifactVersions = getVersions(groupId, artifactId); if (artifactVersions != null && !artifactVersions.isEmpty()) { metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); Versioning versioning = new Versioning(); List<String> versions = new ArrayList<String>(artifactVersions); Collections.sort(versions, new VersionComparator()); // sort the Maven way long lastUpdated = 0; for (String version : versions) { try { long lastModified = getLastModified(new Artifact(groupId, artifactId, version, "pom")); versioning.addVersion(version); if (lastModified >= lastUpdated) { lastUpdated = lastModified; versioning.setLastUpdatedTimestamp(new Date(lastModified)); versioning.setLatest(version); if (!version.endsWith("-SNAPSHOT")) { versioning.setRelease(version); } } } catch (ArtifactNotFoundException e) { // ignore } } metadata.setVersioning(versioning); foundMetadata = true; } } int index2 = index == -1 ? -1 : path.lastIndexOf('/', index - 1); groupId = index2 == -1 ? groupId : groupId.substring(0, index2).replace('/', '.'); artifactId = index2 == -1 ? artifactId : path.substring(index2 + 1, index); String version = index2 == -1 ? null : path.substring(index + 1); if (version != null && version.endsWith("-SNAPSHOT")) { Map<String, Map<String, Map<Artifact, Content>>> artifactMap = contents.get(groupId); Map<String, Map<Artifact, Content>> versionMap = (artifactMap == null ? null : artifactMap.get(artifactId)); Map<Artifact, Content> filesMap = (versionMap == null ? null : versionMap.get(version)); if (filesMap != null) { List<SnapshotVersion> snapshotVersions = new ArrayList<SnapshotVersion>(); int maxBuildNumber = 0; long lastUpdated = 0; String timestamp = null; boolean found = false; for (final Map.Entry<Artifact, Content> entry : filesMap.entrySet()) { final Artifact artifact = entry.getKey(); final Content content = entry.getValue(); SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String lastUpdatedTime = fmt.format(new Date(content.getLastModified())); try { Maven3.addSnapshotVersion(snapshotVersions, artifact, lastUpdatedTime); } catch (LinkageError e) { // Maven 2 } if ("pom".equals(artifact.getType())) { if (artifact.getBuildNumber() != null && maxBuildNumber < artifact.getBuildNumber().intValue()) { maxBuildNumber = artifact.getBuildNumber().intValue(); timestamp = artifact.getTimestampString(); } else { maxBuildNumber = Math.max(1, maxBuildNumber); } lastUpdated = Math.max(lastUpdated, content.getLastModified()); found = true; } } if (!snapshotVersions.isEmpty() || found) { Versioning versioning = metadata.getVersioning(); if (versioning == null) { versioning = new Versioning(); } metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); metadata.setVersion(version); try { Maven3.addSnapshotVersions(versioning, snapshotVersions); } catch (LinkageError e) { // Maven 2 } if (maxBuildNumber > 0) { Snapshot snapshot = new Snapshot(); snapshot.setBuildNumber(maxBuildNumber); snapshot.setTimestamp(timestamp); versioning.setSnapshot(snapshot); } versioning.setLastUpdatedTimestamp(new Date(lastUpdated)); metadata.setVersioning(versioning); foundMetadata = true; } } } if (!foundMetadata) { throw new MetadataNotFoundException(path); } return metadata; }
From source file:org.codehaus.mojo.versions.BumpMojo.java
public void gitLastTags() throws MojoExecutionException { try {/* w ww . ja v a2s.c om*/ List<Ref> list = git.tagList().call(); Map<String, List<String>> u = new TreeMap<String, List<String>>(); for (Ref r : list) { String tag = StringUtils.removeStart(r.getName(), "refs/tags/"); tag = SwitchReleaseMojo.release(tag); String tt = tag.split("-")[0]; List<String> list2 = u.get(tt); if (list2 == null) { list2 = new ArrayList<String>(); } list2.add(tag); u.put(tt, list2); } for (String tt : u.keySet()) { List<String> list2 = u.get(tt); Collections.sort(list2, new VersionSort()); for (int i = Math.max(0, list2.size() - 3); i < list2.size(); i++) { out(list2.get(i)); } } } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.codehaus.mojo.versions.BumpMojo.java
public boolean gitTagExists(String tag) throws MojoExecutionException { try {/* w ww . j av a 2 s. c o m*/ List<Ref> list = git.tagList().call(); for (Ref r : list) { String tag2 = StringUtils.removeStart(r.getName(), "refs/tags/"); if (tag2.equals(tag)) return true; } return false; } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } }