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);
ResourceDto rootInDB = resourceDao.getRootProjectByComponentKey(moduleKey);
if (rootInDB == null || Qualifiers.LIBRARY.equals(rootInDB.getQualifier())) {
// This is a new module or previously a library so OK
return;
}
if (rootInDB.getKey().equals(moduleKey)) {
// SONAR-4245 current subproject is actually a root project in SQ DB
throw new SonarException(
String.format("The project '%s' is already defined in SonarQube but not as a module of project '%s'. "
+ "If you really want to stop directly analysing project '%s', please first delete it from SonarQube and then relaunch the analysis of project '%s'.",
moduleKey, rootProjectKey, moduleKey, rootProjectKey));
}
if (!rootProjectKey.equals(rootInDB.getKey())) {
// SONAR-4692 current subproject is already a subproject in another project
throw new SonarException(String.format("Module \"%s\" is already part of project \"%s\"", moduleDef.getKey(), rootInDB.getKey()));
}
}
}