diff --git a/pomchecker-core/src/main/java/org/kordamp/maven/checker/MavenCentralChecker.java b/pomchecker-core/src/main/java/org/kordamp/maven/checker/MavenCentralChecker.java index 3e534791..bddd43d4 100644 --- a/pomchecker-core/src/main/java/org/kordamp/maven/checker/MavenCentralChecker.java +++ b/pomchecker-core/src/main/java/org/kordamp/maven/checker/MavenCentralChecker.java @@ -153,101 +153,106 @@ public static void check(Logger log, MavenProject project, Configuration configu } else if (fullModel.getVersion().contains("${")) { errors.add(" contains an unresolved expression: " + fullModel.getVersion()); } - - log.debug("Checking "); - if (isBlank(fullModel.getName())) { - String parentName = resolveParentName(project.getFile().getParentFile(), fullModel); - if (isBlank(parentName)) { - errors.add(" can not be blank."); - } else { - warnings.add(" is not defined in POM. Will use value from parent: " + - lineSeparator() + "\t" + parentName); + if (isRelocated(fullModel)) { + log.debug("Checking //"); + if (isBlank(fullModel.getDistributionManagement().getRelocation().getGroupId())) { + errors.add("// can not be blank."); + } + } else { + log.debug("Checking "); + if (isBlank(fullModel.getName())) { + String parentName = resolveParentName(project.getFile().getParentFile(), fullModel); + if (isBlank(parentName)) { + errors.add(" can not be blank."); + } else { + warnings.add(" is not defined in POM. Will use value from parent: " + + lineSeparator() + "\t" + parentName); + } } - } - log.debug("Checking "); - if (isBlank(fullModel.getDescription())) { - errors.add(" can not be blank."); - } - if (isBlank(originalModel.getDescription())) { - warnings.add(" is not defined in POM. Will use value from parent: " + - lineSeparator() + "\t" + fullModel.getDescription()); - } + log.debug("Checking "); + if (isBlank(fullModel.getDescription())) { + errors.add(" can not be blank."); + } + if (isBlank(originalModel.getDescription())) { + warnings.add(" is not defined in POM. Will use value from parent: " + + lineSeparator() + "\t" + fullModel.getDescription()); + } - log.debug("Checking "); - if (isBlank(fullModel.getUrl())) { - errors.add(" can not be blank."); - } - if (isBlank(originalModel.getUrl())) { - warnings.add(" is not defined in POM. Will use computed value from parent: " + - lineSeparator() + "\t" + fullModel.getUrl()); - } + log.debug("Checking "); + if (isBlank(fullModel.getUrl())) { + errors.add(" can not be blank."); + } + if (isBlank(originalModel.getUrl())) { + warnings.add(" is not defined in POM. Will use computed value from parent: " + + lineSeparator() + "\t" + fullModel.getUrl()); + } - if (configuration.isRelease()) log.debug("Checking if version is not snapshot"); - if (configuration.isRelease() && fullModel.getVersion().endsWith("-SNAPSHOT")) { - errors.add(" can not be -SNAPSHOT."); - } + if (configuration.isRelease()) log.debug("Checking if version is not snapshot"); + if (configuration.isRelease() && fullModel.getVersion().endsWith("-SNAPSHOT")) { + errors.add(" can not be -SNAPSHOT."); + } - log.debug("Checking "); - if (fullModel.getLicenses() != null) { - if (!fullModel.getLicenses().isEmpty()) { - // verify that all licenses have & - for (int i = 0; i < fullModel.getLicenses().size(); i++) { - License license = fullModel.getLicenses().get(i); - if (isBlank(license.getName()) && isBlank(license.getUrl())) { - errors.add("License " + i + " must define and ."); + log.debug("Checking "); + if (fullModel.getLicenses() != null) { + if (!fullModel.getLicenses().isEmpty()) { + // verify that all licenses have & + for (int i = 0; i < fullModel.getLicenses().size(); i++) { + License license = fullModel.getLicenses().get(i); + if (isBlank(license.getName()) && isBlank(license.getUrl())) { + errors.add("License " + i + " must define and ."); + } } + } else { + errors.add(" block is required but was left empty."); } } else { - errors.add(" block is required but was left empty."); + errors.add(" block is required but was left undefined."); } - } else { - errors.add(" block is required but was left undefined."); - } - log.debug("Checking "); - if (fullModel.getDevelopers() != null) { - if (!fullModel.getDevelopers().isEmpty()) { - // verify that all developers have at least one of [id, name, organization, organizationUrl] - for (int i = 0; i < fullModel.getDevelopers().size(); i++) { - Developer developer = fullModel.getDevelopers().get(i); - if (isBlank(developer.getId()) && - isBlank(developer.getName()) && - isBlank(developer.getOrganization()) && - isBlank(developer.getOrganizationUrl())) { - errors.add("Developer " + i + " must define at least one of , , , ."); + log.debug("Checking "); + if (fullModel.getDevelopers() != null) { + if (!fullModel.getDevelopers().isEmpty()) { + // verify that all developers have at least one of [id, name, organization, organizationUrl] + for (int i = 0; i < fullModel.getDevelopers().size(); i++) { + Developer developer = fullModel.getDevelopers().get(i); + if (isBlank(developer.getId()) && + isBlank(developer.getName()) && + isBlank(developer.getOrganization()) && + isBlank(developer.getOrganizationUrl())) { + errors.add("Developer " + i + " must define at least one of , , , ."); + } } + } else { + errors.add(" block is required but was left empty."); } } else { - errors.add(" block is required but was left empty."); + errors.add(" block is required but was left undefined."); } - } else { - errors.add(" block is required but was left undefined."); - } - log.debug("Checking "); - if (fullModel.getScm() == null) { - errors.add("The block is required."); - } + log.debug("Checking "); + if (fullModel.getScm() == null) { + errors.add("The block is required."); + } - log.debug("Checking "); - if (null != originalModel.getRepositories() && !originalModel.getRepositories().isEmpty()) { - if (configuration.isStrict()) { - errors.add("The block should not be present."); - } else { - warnings.add("The block should not be present."); + log.debug("Checking "); + if (null != originalModel.getRepositories() && !originalModel.getRepositories().isEmpty()) { + if (configuration.isStrict()) { + errors.add("The block should not be present."); + } else { + warnings.add("The block should not be present."); + } } - } - log.debug("Checking "); - if (null != originalModel.getPluginRepositories() && !originalModel.getPluginRepositories().isEmpty()) { - if (configuration.isStrict()) { - errors.add("The block should not be present."); - } else { - warnings.add("The block should not be present."); + log.debug("Checking "); + if (null != originalModel.getPluginRepositories() && !originalModel.getPluginRepositories().isEmpty()) { + if (configuration.isStrict()) { + errors.add("The block should not be present."); + } else { + warnings.add("The block should not be present."); + } } } - if (!warnings.isEmpty()) { if (configuration.isFailOnWarning()) { throw new PomCheckException(String.join(lineSeparator(), warnings)); @@ -258,12 +263,12 @@ public static void check(Logger log, MavenProject project, Configuration configu if (!errors.isEmpty()) { StringBuilder b = new StringBuilder(lineSeparator()) - .append("The POM file") - .append(lineSeparator()) - .append(project.getFile().getAbsolutePath()) - .append(lineSeparator()) - .append("cannot be uploaded to Maven Central due to the following reasons:") - .append(lineSeparator()); + .append("The POM file") + .append(lineSeparator()) + .append(project.getFile().getAbsolutePath()) + .append(lineSeparator()) + .append("cannot be uploaded to Maven Central due to the following reasons:") + .append(lineSeparator()); for (String s : errors) { b.append(" * ").append(s).append(lineSeparator()); } @@ -278,6 +283,16 @@ public static void check(Logger log, MavenProject project, Configuration configu } } + /** + * Checks if the model has been relocated. + * + * @param model the model to check + * @return {@code true} if the model has been relocated. + */ + private static boolean isRelocated(Model model) { + return model.getDistributionManagement() != null && model.getDistributionManagement().getRelocation() != null; + } + private static String resolveParentName(File directory, Model fullModel) { Parent parent = fullModel.getParent();