2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.updatecenter.common;
22 import org.apache.commons.lang.StringUtils;
27 public final class PluginKeyUtils {
29 private PluginKeyUtils() {
30 // only static methods
33 public static String sanitize(String mavenArtifactId) {
34 if (mavenArtifactId == null) {
38 String key = mavenArtifactId;
39 if (StringUtils.startsWith(mavenArtifactId, "sonar-") && StringUtils.endsWith(mavenArtifactId, "-plugin")) {
40 key = StringUtils.removeEnd(StringUtils.removeStart(mavenArtifactId, "sonar-"), "-plugin");
41 } else if (StringUtils.endsWith(mavenArtifactId, "-sonar-plugin")) {
42 key = StringUtils.removeEnd(mavenArtifactId, "-sonar-plugin");
44 return keepLettersAndDigits(key);
47 private static String keepLettersAndDigits(String key) {
48 StringBuilder sb = new StringBuilder();
49 for (int index = 0; index < key.length(); index++) {
50 char character = key.charAt(index);
51 if (Character.isLetter(character) || Character.isDigit(character)) {
58 public static boolean isValid(String pluginKey) {
59 return StringUtils.isNotBlank(pluginKey) && StringUtils.isAlphanumeric(pluginKey);