public void checkIfMigrationNeeded(Project rootProject) {
ResourceModel model = session.getSingleResult(ResourceModel.class, "key", rootProject.getEffectiveKey());
if (model != null && StringUtils.isBlank(model.getDeprecatedKey())) {
- logger.info("Resources keys of project '" + rootProject.getName() + "' should be migrated");
this.migrationNeeded = true;
}
}
void migrateIfNeeded(Project module, Iterable<InputFile> inputFiles) {
if (migrationNeeded) {
- logger.info("Starting migration of resource keys");
+ logger.info("Update component keys");
Map<String, InputFile> deprecatedFileKeyMapper = new HashMap<String, InputFile>();
Map<String, InputFile> deprecatedTestKeyMapper = new HashMap<String, InputFile>();
Map<String, String> deprecatedDirectoryKeyMapper = new HashMap<String, String>();
for (InputFile inputFile : inputFiles) {
String deprecatedKey = ((DefaultInputFile) inputFile).deprecatedKey();
if (deprecatedKey != null) {
- if (InputFile.Type.TEST == inputFile.type()) {
+ if (InputFile.Type.TEST == inputFile.type() && !deprecatedTestKeyMapper.containsKey(deprecatedKey)) {
deprecatedTestKeyMapper.put(deprecatedKey, inputFile);
- } else {
+ } else if (InputFile.Type.MAIN == inputFile.type() && !deprecatedFileKeyMapper.containsKey(deprecatedKey)) {
deprecatedFileKeyMapper.put(deprecatedKey, inputFile);
}
}
.append(ResourceModel.class.getSimpleName())
.append(" where enabled = true ")
.append(" and rootId = :rootId ")
- .append(" and scope = '").append(Scopes.FILE).append("' order by key");
+ .append(" and scope = '").append(Scopes.FILE).append("' order by qualifier, key");
List<ResourceModel> resources = session.createQuery(hql.toString()).setParameter("rootId", moduleId).getResultList();
for (ResourceModel resourceModel : resources) {
String oldEffectiveKey = resourceModel.getKey();
}
resourceModel.setKey(newEffectiveKey);
resourceModel.setDeprecatedKey(oldEffectiveKey);
- logger.info("Migrated resource {} to {}", oldEffectiveKey, newEffectiveKey);
+ logger.info("Component {} changed to {}", oldEffectiveKey, newEffectiveKey);
} else {
- logger.warn("Unable to migrate resource {}. No match was found.", oldEffectiveKey);
+ logger.warn("Unable to update component {}. No match was found.", oldEffectiveKey);
}
}
}
.append(ResourceModel.class.getSimpleName())
.append(" where enabled = true ")
.append(" and rootId = :rootId ")
- .append(" and qualifier = '").append(Qualifiers.DIRECTORY).append("')");
+ .append(" and qualifier = '").append(Qualifiers.DIRECTORY).append("'");
List<ResourceModel> resources = session.createQuery(hql.toString()).setParameter("rootId", moduleId).getResultList();
for (ResourceModel resourceModel : resources) {
String oldEffectiveKey = resourceModel.getKey();
String newEffectiveKey = deprecatedDirectoryKeyMapper.get(oldEffectiveKey);
resourceModel.setKey(newEffectiveKey);
resourceModel.setDeprecatedKey(oldEffectiveKey);
- logger.info("Migrated resource {} to {}", oldEffectiveKey, newEffectiveKey);
+ logger.info("Component {} changed to {}", oldEffectiveKey, newEffectiveKey);
} else {
- logger.warn("Unable to migrate resource {}. No match was found.", oldEffectiveKey);
+ logger.warn("Unable to update component {}. No match was found.", oldEffectiveKey);
}
}
}
Logger logger = mock(Logger.class);
ResourceKeyMigration migration = new ResourceKeyMigration(getSession(), logger);
migration.checkIfMigrationNeeded(multiModuleProject);
- verify(logger).info("Resources keys of project 'Root' should be migrated");
-
+
migration.migrateIfNeeded(javaModule, javaInputFiles);
migration.migrateIfNeeded(phpModule, phpInputFiles);
- verify(logger).info("Migrated resource {} to {}", "b:org.foo.Bar", "b:src/main/java/org/foo/Bar.java");
+ verify(logger).info("Component {} changed to {}", "b:org.foo.Bar", "b:src/main/java/org/foo/Bar.java");
verify(logger).warn("Directory with key b:org/foo matches both b:src/main/java/org/foo and b:src/test/java/org/foo. First match is arbitrary chosen.");
- verify(logger).info("Migrated resource {} to {}", "b:org.foo.BarTest", "b:src/test/java/org/foo/BarTest.java");
- verify(logger).info("Migrated resource {} to {}", "b:[default].RootBar", "b:src/main/java/RootBar.java");
- verify(logger).info("Migrated resource {} to {}", "b:org/foo", "b:src/main/java/org/foo");
- verify(logger).info("Migrated resource {} to {}", "b:[root]", "b:src/main/java");
+ verify(logger).info("Component {} changed to {}", "b:org.foo.BarTest", "b:src/test/java/org/foo/BarTest.java");
+ verify(logger).info("Component {} changed to {}", "b:[default].RootBar", "b:src/main/java/RootBar.java");
+ verify(logger).info("Component {} changed to {}", "b:org/foo", "b:src/main/java/org/foo");
+ verify(logger).info("Component {} changed to {}", "b:[root]", "b:src/main/java");
checkTables("shouldMigrateResourceKeys", new String[]{"build_date", "created_at"}, "projects");
}