import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.batch.bootstrap.BootstrapSettings;
-import org.sonar.core.component.ComponentKeys;
import javax.annotation.CheckForNull;
checkMandatoryProperties(properties, MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT);
}
final String projectKey = properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY);
- checkProjectKeyValid(projectKey);
File workDir;
if (parent == null) {
validateDirectories(properties, baseDir, projectKey);
return definition;
}
- private void checkProjectKeyValid(String projectKey) {
- if (!ComponentKeys.isValidModuleKey(projectKey)) {
- throw new IllegalStateException(String.format(
- "Invalid project key '%s'.\n"
- + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", projectKey));
- }
- }
-
@VisibleForTesting
protected File initRootProjectWorkDir(File baseDir) {
String workDir = settings.property(CoreProperties.WORKING_DIRECTORY);
private void validateModule(ProjectDefinition moduleDef, List<String> validationMessages, @Nullable String branch, String rootProjectKey) {
if (!ComponentKeys.isValidModuleKey(moduleDef.getKey())) {
- validationMessages.add(String.format("\"%s\" is not a valid project or module key", moduleDef.getKey()));
+ validationMessages.add(String.format("\"%s\" is not a valid project or module key. "
+ + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", moduleDef.getKey()));
} else if (isSubProject(moduleDef)) {
// SONAR-4692 Validate root project is the same than previous analysis to avoid module with same key in different projects
String moduleKey = ComponentKeys.createKey(moduleDef.getKey(), branch);
private void validateBranch(List<String> validationMessages, @Nullable String branch) {
if (StringUtils.isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) {
- validationMessages.add(String.format("\"%s\" is not a valid branch name", branch));
+ validationMessages.add(String.format("\"%s\" is not a valid branch name. "
+ + "Allowed characters are alphanumeric, '-', '_' and '.'.", branch));
}
}
TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
}
- @Test
- public void shouldFailOnInvalidProjectKey() throws IOException {
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Invalid project key 'A key with spaces'.\nAllowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
- loadProjectDefinition("project-with-invalid-key");
- }
-
@Test
public void shouldFailIfUnexistingSourceDirectory() throws IOException {
thrown.expect(IllegalStateException.class);
+++ /dev/null
-sonar.projectKey=A key with spaces
-sonar.projectName=Foo Project
-sonar.projectVersion=1.0-SNAPSHOT
-sonar.projectDescription=Description of Foo Project
-
-sonar.sources=sources
-sonar.libraries=libs/*.txt