From 5734827cde26860ca6a7454f2e583e4ef53d431b Mon Sep 17 00:00:00 2001 From: jakobbraun Date: Wed, 9 Jun 2021 15:29:03 +0200 Subject: [PATCH] #131: Fixed dependency crawling for artifact that are not on maven central (#133) * #131: Fixed dependency crawling for artifact that are not on maven central --- dependencies.md | 6 +-- doc/changes/changelog.md | 1 + doc/changes/changes_0.7.2.md | 28 ++++++++++ error_code_config.yml | 4 ++ pom.xml | 18 +++---- .../AbstractProjectKeeperMojo.java | 11 ++-- .../pom/DefaultMavenArtifactModelReader.java | 39 -------------- ...=> DefaultMavenProjectFromFileReader.java} | 15 +++--- .../pom/MavenArtifactModelReader.java | 22 -------- .../pom/MavenModelFromRepositoryReader.java | 53 +++++++++++++++++++ ...r.java => MavenProjectFromFileReader.java} | 10 ++-- .../changesfile/ChangesFileValidator.java | 6 +-- .../changesfile/DependencySectionFixer.java | 14 ++--- .../dependencies/DependenciesValidator.java | 16 +++--- .../dependencies/ProjectDependencyReader.java | 28 +++++----- .../validators/pom/AbstractPomValidator.java | 6 +-- .../AbstractDependencyValidator.java | 6 +-- .../plugin/AbstractPluginPomValidator.java | 8 ++- .../xpath/XPathErrorHandlingWrapper.java | 2 +- .../xpath/XPathSplitter.java | 2 +- ... => SimpleMavenProjectFromFileReader.java} | 11 ++-- .../changesfile/ChangesFileValidatorTest.java | 6 +-- .../DependencySectionFixerTest.java | 6 +-- .../dependencies/DependenciesValidatorIT.java | 22 ++++++++ .../validators/pom/PomFileIOTest.java | 2 +- .../validators/pom/PomTesting.java | 2 +- .../JacocoAgentDependencyValidatorTest.java | 2 +- .../AbstractMavenPluginPomValidatorTest.java | 2 +- .../xpath/XPathSplitterTest.java | 2 +- 29 files changed, 194 insertions(+), 156 deletions(-) create mode 100644 doc/changes/changes_0.7.2.md create mode 100644 error_code_config.yml delete mode 100644 src/main/java/com/exasol/projectkeeper/pom/DefaultMavenArtifactModelReader.java rename src/main/java/com/exasol/projectkeeper/pom/{DefaultMavenFileModelReader.java => DefaultMavenProjectFromFileReader.java} (63%) delete mode 100644 src/main/java/com/exasol/projectkeeper/pom/MavenArtifactModelReader.java create mode 100644 src/main/java/com/exasol/projectkeeper/pom/MavenModelFromRepositoryReader.java rename src/main/java/com/exasol/projectkeeper/pom/{MavenFileModelReader.java => MavenProjectFromFileReader.java} (68%) rename src/main/java/com/exasol/{ => projectkeeper}/xpath/XPathErrorHandlingWrapper.java (96%) rename src/main/java/com/exasol/{ => projectkeeper}/xpath/XPathSplitter.java (97%) rename src/test/java/com/exasol/projectkeeper/validators/{SimpleMavenFileModelReader.java => SimpleMavenProjectFromFileReader.java} (74%) rename src/test/java/com/exasol/{ => projectkeeper}/xpath/XPathSplitterTest.java (95%) diff --git a/dependencies.md b/dependencies.md index 4d7e61c7..8dabd13b 100644 --- a/dependencies.md +++ b/dependencies.md @@ -85,11 +85,10 @@ [24]: http://junit.org [39]: https://www.eclipse.org/legal/epl-2.0/ [13]: https://www.xmlunit.org/ -[20]: https://maven.apache.org/ref/3.6.3/maven-core/ +[37]: https://github.com/mockito/mockito/blob/main/LICENSE [74]: http://zlika.github.io/reproducible-build-maven-plugin [35]: http://www.opensource.org/licenses/mit-license.php [6]: https://github.com/classgraph/classgraph -[37]: https://github.com/mockito/mockito/blob/release/3.x/LICENSE [8]: https://github.com/eclipse-ee4j/jaxb-api [26]: https://junit.org/junit5/ [46]: https://maven.apache.org/plugin-tools/maven-plugin-plugin @@ -99,11 +98,11 @@ [80]: http://maven.apache.org/plugins/maven-resources-plugin/ [0]: https://maven.apache.org/plugin-tools/maven-plugin-annotations [70]: http://www.sonatype.com/public-parent/nexus-maven-plugins/nexus-staging/nexus-staging-maven-plugin/ +[20]: https://maven.apache.org/ref/3.8.1/maven-core/ [48]: https://maven.apache.org/surefire/maven-failsafe-plugin/ [76]: http://maven.apache.org/plugins/maven-dependency-plugin/ [7]: http://opensource.org/licenses/MIT [25]: http://www.eclipse.org/legal/epl-v10.html -[2]: https://maven.apache.org/ref/3.6.3/maven-plugin-api/ [82]: http://maven.apache.org/plugins/maven-jar-plugin/ [12]: http://www.eclipse.org/org/documents/edl-v10.php [1]: https://www.apache.org/licenses/LICENSE-2.0.txt @@ -115,5 +114,6 @@ [40]: https://github.com/exasol/maven-plugin-integration-testing [68]: http://maven.apache.org/plugins/maven-deploy-plugin/ [86]: http://maven.apache.org/plugins/maven-site-plugin/ +[2]: https://maven.apache.org/ref/3.8.1/maven-plugin-api/ [58]: https://maven.apache.org/plugins/maven-javadoc-plugin/ [72]: https://github.com/exasol/error-code-crawler-maven-plugin diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index a92a0dbd..481bb878 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,5 +1,6 @@ # Changes +* [0.7.2](changes_0.7.2.md) * [0.7.1](changes_0.7.1.md) * [0.7.0](changes_0.7.0.md) * [0.6.1](changes_0.6.1.md) diff --git a/doc/changes/changes_0.7.2.md b/doc/changes/changes_0.7.2.md new file mode 100644 index 00000000..c3766492 --- /dev/null +++ b/doc/changes/changes_0.7.2.md @@ -0,0 +1,28 @@ +# Project keeper maven plugin 0.7.2, released 2021-06-09 + +Code name: Bug Fix: Dependency crawling for non maven central dependencies + +## Bug Fixes + +* #131: Fixed dependency crawling for artifact that are not on maven central + +## Dependency Updates + +### Compile Dependency Updates + +* Updated `io.github.classgraph:classgraph:4.8.102` to `4.8.108` +* Updated `org.apache.maven:maven-core:3.6.3` to `3.8.1` +* Updated `org.apache.maven:maven-plugin-api:3.6.3` to `3.8.1` +* Updated `org.eclipse.jgit:org.eclipse.jgit:5.11.0.202103091610-r` to `5.11.1.202105131744-r` +* Updated `org.glassfish.jaxb:jaxb-runtime:3.0.0` to `3.0.1` + +### Test Dependency Updates + +* Updated `org.junit.jupiter:junit-jupiter-engine:5.7.1` to `5.7.2` +* Updated `org.junit.jupiter:junit-jupiter-params:5.7.1` to `5.7.2` +* Updated `org.mockito:mockito-core:3.8.0` to `3.11.0` + +### Plugin Dependency Updates + +* Updated `com.exasol:error-code-crawler-maven-plugin:0.1.1` to `0.4.0` +* Updated `com.exasol:project-keeper-maven-plugin:0.7.1` to `0.7.2` diff --git a/error_code_config.yml b/error_code_config.yml new file mode 100644 index 00000000..b470cc29 --- /dev/null +++ b/error_code_config.yml @@ -0,0 +1,4 @@ +error-tags: + PK: + packages: + - com.exasol.projectkeeper \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f3fb8e5..77c0fe66 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.exasol project-keeper-maven-plugin maven-plugin - 0.7.1 + 0.7.2 Project keeper maven plugin This maven plugin checks and unifies a project's structure according to the Exasol integration team's repository standards. @@ -45,8 +45,8 @@ - 3.6.3 - 5.7.1 + 3.8.1 + 5.7.2 11 1.6.2 0.8.6 @@ -58,7 +58,7 @@ org.apache.maven.plugin-tools maven-plugin-annotations - 3.6.0 + 3.6.1 provided @@ -74,7 +74,7 @@ io.github.classgraph classgraph - 4.8.102 + 4.8.108 javax.xml.bind @@ -84,7 +84,7 @@ org.glassfish.jaxb jaxb-runtime - 3.0.0 + 3.0.1 org.xmlunit @@ -99,7 +99,7 @@ org.eclipse.jgit org.eclipse.jgit - 5.11.0.202103091610-r + 5.11.1.202105131744-r net.steppschuh.markdowngenerator @@ -165,7 +165,7 @@ org.mockito mockito-core - 3.8.0 + 3.11.0 test @@ -453,7 +453,7 @@ com.exasol error-code-crawler-maven-plugin - 0.1.1 + 0.4.0 diff --git a/src/main/java/com/exasol/projectkeeper/AbstractProjectKeeperMojo.java b/src/main/java/com/exasol/projectkeeper/AbstractProjectKeeperMojo.java index 1953e3cb..883fa9d4 100644 --- a/src/main/java/com/exasol/projectkeeper/AbstractProjectKeeperMojo.java +++ b/src/main/java/com/exasol/projectkeeper/AbstractProjectKeeperMojo.java @@ -13,9 +13,8 @@ import org.apache.maven.project.ProjectBuilder; import org.apache.maven.repository.RepositorySystem; -import com.exasol.projectkeeper.pom.DefaultMavenArtifactModelReader; -import com.exasol.projectkeeper.pom.DefaultMavenFileModelReader; -import com.exasol.projectkeeper.pom.MavenArtifactModelReader; +import com.exasol.projectkeeper.pom.DefaultMavenProjectFromFileReader; +import com.exasol.projectkeeper.pom.MavenModelFromRepositoryReader; import com.exasol.projectkeeper.validators.DeletedFilesValidator; import com.exasol.projectkeeper.validators.changesfile.ChangesFileValidator; import com.exasol.projectkeeper.validators.dependencies.DependenciesValidator; @@ -76,9 +75,9 @@ protected List getValidators() { final var brokenLinkReplacer = new BrokenLinkReplacer(this.linkReplacements); final Set enabledModules = getEnabledModules(); final var excludedFilesMatcher = new ExcludedFilesMatcher(this.excludedFiles); - final var mavenModelReader = new DefaultMavenFileModelReader(this.mavenProjectBuilder, this.session); - final MavenArtifactModelReader artifactReader = new DefaultMavenArtifactModelReader(this.mavenProjectBuilder, - this.session, this.repositorySystem); + final var mavenModelReader = new DefaultMavenProjectFromFileReader(this.mavenProjectBuilder, this.session); + final MavenModelFromRepositoryReader artifactReader = new MavenModelFromRepositoryReader( + this.mavenProjectBuilder, this.session, this.repositorySystem); final var pomFile = this.project.getModel().getPomFile(); return List.of(new ProjectFilesValidator(enabledModules, this.project.getBasedir(), excludedFilesMatcher), new PomFileValidator(enabledModules, this.excludedPlugins, pomFile), diff --git a/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenArtifactModelReader.java b/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenArtifactModelReader.java deleted file mode 100644 index af985b54..00000000 --- a/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenArtifactModelReader.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.exasol.projectkeeper.pom; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Model; -import org.apache.maven.project.*; -import org.apache.maven.repository.RepositorySystem; - -/** - * Implementation of {@link MavenArtifactModelReader} using the {@link ProjectBuilder} that is injected by Maven core to - * Mojo. - */ -public class DefaultMavenArtifactModelReader implements MavenArtifactModelReader { - private final ProjectBuilder mavenProjectBuilder; - private final MavenSession session; - private final RepositorySystem repositorySystem; - - /** - * Create a new instance of {@link DefaultMavenArtifactModelReader}. - * - * @param mavenProjectBuilder maven project builder - * @param session maven session - * @param repositorySystem maven repository system - */ - public DefaultMavenArtifactModelReader(final ProjectBuilder mavenProjectBuilder, final MavenSession session, - final RepositorySystem repositorySystem) { - this.mavenProjectBuilder = mavenProjectBuilder; - this.session = session; - this.repositorySystem = repositorySystem; - } - - @Override - public Model readModel(final String artifactId, final String groupId, final String version) - throws ProjectBuildingException { - final var artifact = this.repositorySystem.createProjectArtifact(groupId, artifactId, version); - final ProjectBuildingResult build = this.mavenProjectBuilder.build(artifact, - this.session.getProjectBuildingRequest()); - return build.getProject().getModel(); - } -} diff --git a/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenFileModelReader.java b/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenProjectFromFileReader.java similarity index 63% rename from src/main/java/com/exasol/projectkeeper/pom/DefaultMavenFileModelReader.java rename to src/main/java/com/exasol/projectkeeper/pom/DefaultMavenProjectFromFileReader.java index 305c9b87..b886a6e2 100644 --- a/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenFileModelReader.java +++ b/src/main/java/com/exasol/projectkeeper/pom/DefaultMavenProjectFromFileReader.java @@ -3,36 +3,35 @@ import java.io.File; import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Model; import org.apache.maven.project.*; import com.exasol.errorreporting.ExaError; /** - * Implementation of {@link MavenFileModelReader} using the {@link ProjectBuilder} that is injected by Maven core to - * Mojo. + * Implementation of {@link MavenProjectFromFileReader} using the {@link ProjectBuilder} that is injected by Maven core + * to Mojo. */ -public class DefaultMavenFileModelReader implements MavenFileModelReader { +public class DefaultMavenProjectFromFileReader implements MavenProjectFromFileReader { private final ProjectBuilder mavenProjectBuilder; private final MavenSession session; /** - * Create a new instance of {@link DefaultMavenFileModelReader}. + * Create a new instance of {@link DefaultMavenProjectFromFileReader}. * * @param mavenProjectBuilder maven project builder * @param session maven session */ - public DefaultMavenFileModelReader(final ProjectBuilder mavenProjectBuilder, final MavenSession session) { + public DefaultMavenProjectFromFileReader(final ProjectBuilder mavenProjectBuilder, final MavenSession session) { this.mavenProjectBuilder = mavenProjectBuilder; this.session = session; } @Override - public Model readModel(final File pomFile) throws ReadFailedException { + public MavenProject readProject(final File pomFile) throws ReadFailedException { try { final ProjectBuildingResult build = this.mavenProjectBuilder.build(pomFile, this.session.getProjectBuildingRequest()); - return build.getProject().getModel(); + return build.getProject(); } catch (final ProjectBuildingException exception) { throw new ReadFailedException( ExaError.messageBuilder("E-PK-46").message("Failed to build maven model.").toString(), exception); diff --git a/src/main/java/com/exasol/projectkeeper/pom/MavenArtifactModelReader.java b/src/main/java/com/exasol/projectkeeper/pom/MavenArtifactModelReader.java deleted file mode 100644 index 5b870dc7..00000000 --- a/src/main/java/com/exasol/projectkeeper/pom/MavenArtifactModelReader.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.exasol.projectkeeper.pom; - -import org.apache.maven.model.Model; -import org.apache.maven.project.ProjectBuildingException; - -/** - * Interface for readers that read a maven {@link Model} from an artifact of the maven repository. - */ -public interface MavenArtifactModelReader { - - /** - * Read the {@link Model} of an artifact of the maven repository. - * - * @param artifactId maven artifact id - * @param groupId maven groupId - * @param version version - * @return read maven model - * @throws ProjectBuildingException if reading fails - */ - public Model readModel(final String artifactId, final String groupId, final String version) - throws ProjectBuildingException; -} diff --git a/src/main/java/com/exasol/projectkeeper/pom/MavenModelFromRepositoryReader.java b/src/main/java/com/exasol/projectkeeper/pom/MavenModelFromRepositoryReader.java new file mode 100644 index 00000000..e2d71661 --- /dev/null +++ b/src/main/java/com/exasol/projectkeeper/pom/MavenModelFromRepositoryReader.java @@ -0,0 +1,53 @@ +package com.exasol.projectkeeper.pom; + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Model; +import org.apache.maven.project.*; +import org.apache.maven.repository.RepositorySystem; + +/** + * Read a maven {@link Model} from an artifact of the maven repository using the {@link ProjectBuilder} that is injected + * by Maven core to Mojo. + */ +public class MavenModelFromRepositoryReader { + private final ProjectBuilder mavenProjectBuilder; + private final MavenSession session; + private final RepositorySystem repositorySystem; + + /** + * Create a new instance of {@link MavenModelFromRepositoryReader}. + * + * @param mavenProjectBuilder maven project builder + * @param session maven session + * @param repositorySystem maven repository system + */ + public MavenModelFromRepositoryReader(final ProjectBuilder mavenProjectBuilder, final MavenSession session, + final RepositorySystem repositorySystem) { + this.mavenProjectBuilder = mavenProjectBuilder; + this.session = session; + this.repositorySystem = repositorySystem; + } + + /** + * Read the {@link Model} of an artifact of the maven repository. + * + * @param artifactId maven artifact id + * @param groupId maven groupId + * @param version version + * @param remoteRepositories list of remote repositories + * @return read maven model + * @throws ProjectBuildingException if reading fails + */ + public Model readModel(final String artifactId, final String groupId, final String version, + final List remoteRepositories) throws ProjectBuildingException { + final Artifact artifactDescription = this.repositorySystem.createProjectArtifact(groupId, artifactId, version); + final ProjectBuildingRequest projectBuildingRequest = this.session.getProjectBuildingRequest(); + projectBuildingRequest.setRemoteRepositories(remoteRepositories); + final ProjectBuildingResult build = this.mavenProjectBuilder.build(artifactDescription, projectBuildingRequest); + return build.getProject().getModel(); + } +} diff --git a/src/main/java/com/exasol/projectkeeper/pom/MavenFileModelReader.java b/src/main/java/com/exasol/projectkeeper/pom/MavenProjectFromFileReader.java similarity index 68% rename from src/main/java/com/exasol/projectkeeper/pom/MavenFileModelReader.java rename to src/main/java/com/exasol/projectkeeper/pom/MavenProjectFromFileReader.java index 74049036..c4a86d2e 100644 --- a/src/main/java/com/exasol/projectkeeper/pom/MavenFileModelReader.java +++ b/src/main/java/com/exasol/projectkeeper/pom/MavenProjectFromFileReader.java @@ -2,20 +2,20 @@ import java.io.File; -import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; /** - * Interfaces for classes that read a maven {@link Model} from a pom.xml file. + * Interfaces for classes that read a {@link MavenProject} from a pom.xml file. */ -public interface MavenFileModelReader { +public interface MavenProjectFromFileReader { /** - * Read a maven model. + * Read a {@link MavenProject} from pom.xml file. * * @param pomFile pom.xml file to read * @return read model * @throws ReadFailedException if reading failed */ - Model readModel(File pomFile) throws ReadFailedException; + MavenProject readProject(File pomFile) throws ReadFailedException; /** * Exception that is thrown if the reading failed. diff --git a/src/main/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidator.java b/src/main/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidator.java index 5c677f44..f0c4cff3 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidator.java +++ b/src/main/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidator.java @@ -10,7 +10,7 @@ import com.exasol.errorreporting.ExaError; import com.exasol.projectkeeper.ValidationFinding; import com.exasol.projectkeeper.Validator; -import com.exasol.projectkeeper.pom.MavenFileModelReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; /** * Validator that checks the existence of the doc/changes/changes_X.X.X.md file for the current project's version. @@ -21,7 +21,7 @@ public class ChangesFileValidator implements Validator { private final Path changesFileAbsolutePath; private final Path projectDirectory; private final String projectVersion; - private final MavenFileModelReader mavenModelReader; + private final MavenProjectFromFileReader mavenModelReader; /** * Create a new instance of {@link ChangesFileValidator} @@ -32,7 +32,7 @@ public class ChangesFileValidator implements Validator { * @param mavenModelReader reader for maven models */ public ChangesFileValidator(final String projectVersion, final String projectName, final Path projectDirectory, - final MavenFileModelReader mavenModelReader) { + final MavenProjectFromFileReader mavenModelReader) { this.projectVersion = projectVersion; this.relativePathToChangesFile = Path.of("doc", "changes", "changes_" + projectVersion + ".md"); this.projectName = projectName; diff --git a/src/main/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixer.java b/src/main/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixer.java index d5b9b967..03ca9aad 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixer.java +++ b/src/main/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixer.java @@ -9,14 +9,14 @@ import org.apache.maven.model.Model; import com.exasol.errorreporting.ExaError; -import com.exasol.projectkeeper.pom.MavenFileModelReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; import com.exasol.projectkeeper.validators.changesfile.dependencies.*; /** * This class fixes the dependency section of a {@link ChangesFile}. */ class DependencySectionFixer { - private final MavenFileModelReader mavenModelReader; + private final MavenProjectFromFileReader mavenModelReader; private final Path projectDirectory; private final Model currentMavenModel; @@ -26,7 +26,7 @@ class DependencySectionFixer { * @param mavenModelReader reader for maven model * @param projectDirectory projects root directory */ - public DependencySectionFixer(final MavenFileModelReader mavenModelReader, final Path projectDirectory) { + public DependencySectionFixer(final MavenProjectFromFileReader mavenModelReader, final Path projectDirectory) { this.mavenModelReader = mavenModelReader; this.projectDirectory = projectDirectory; this.currentMavenModel = parseCurrentPomFile(projectDirectory.resolve("pom.xml")); @@ -34,8 +34,8 @@ public DependencySectionFixer(final MavenFileModelReader mavenModelReader, final private Model parseCurrentPomFile(final Path pomFile) { try { - return this.mavenModelReader.readModel(pomFile.toFile()); - } catch (final MavenFileModelReader.ReadFailedException exception) { + return this.mavenModelReader.readProject(pomFile.toFile()).getModel(); + } catch (final MavenProjectFromFileReader.ReadFailedException exception) { throw new IllegalStateException( ExaError.messageBuilder("E-PK-42").message("Failed to parse current pom file.").toString(), exception); @@ -77,8 +77,8 @@ private Model getOldModel() { private Model parseOldPomFile(final String pomFileContents) { try (final var temporaryPomFile = new TemporaryPomFile(pomFileContents)) { - return this.mavenModelReader.readModel(temporaryPomFile.getPomFile().toFile()); - } catch (final MavenFileModelReader.ReadFailedException exception) { + return this.mavenModelReader.readProject(temporaryPomFile.getPomFile().toFile()).getModel(); + } catch (final MavenProjectFromFileReader.ReadFailedException exception) { throw new IllegalStateException(ExaError.messageBuilder("E-PK-38") .message("Failed to parse pom file of previous release.").toString(), exception); } diff --git a/src/main/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidator.java b/src/main/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidator.java index 1ad8afe2..18bb999b 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidator.java +++ b/src/main/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidator.java @@ -2,18 +2,14 @@ import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; +import java.nio.file.*; import java.util.Collections; import java.util.List; import com.exasol.errorreporting.ExaError; -import com.exasol.projectkeeper.BrokenLinkReplacer; -import com.exasol.projectkeeper.ValidationFinding; -import com.exasol.projectkeeper.Validator; -import com.exasol.projectkeeper.pom.MavenArtifactModelReader; -import com.exasol.projectkeeper.pom.MavenFileModelReader; +import com.exasol.projectkeeper.*; +import com.exasol.projectkeeper.pom.MavenModelFromRepositoryReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; import com.exasol.projectkeeper.validators.dependencies.renderer.DependencyPageRenderer; /** @@ -34,8 +30,8 @@ public class DependenciesValidator implements Validator { * @param projectDirectory project root directory * @param brokenLinkReplacer dependency injection for broken link replacer */ - public DependenciesValidator(final MavenFileModelReader fileModelReader, - final MavenArtifactModelReader artifactModelReader, final File pomFile, final Path projectDirectory, + public DependenciesValidator(final MavenProjectFromFileReader fileModelReader, + final MavenModelFromRepositoryReader artifactModelReader, final File pomFile, final Path projectDirectory, final BrokenLinkReplacer brokenLinkReplacer) { this.brokenLinkReplacer = brokenLinkReplacer; this.projectDependencyReader = new ProjectDependencyReader(fileModelReader, artifactModelReader); diff --git a/src/main/java/com/exasol/projectkeeper/validators/dependencies/ProjectDependencyReader.java b/src/main/java/com/exasol/projectkeeper/validators/dependencies/ProjectDependencyReader.java index d8d4a6fa..0d5f0e55 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/dependencies/ProjectDependencyReader.java +++ b/src/main/java/com/exasol/projectkeeper/validators/dependencies/ProjectDependencyReader.java @@ -8,18 +8,19 @@ import java.util.stream.Stream; import org.apache.maven.model.*; +import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; import com.exasol.errorreporting.ExaError; -import com.exasol.projectkeeper.pom.MavenArtifactModelReader; -import com.exasol.projectkeeper.pom.MavenFileModelReader; +import com.exasol.projectkeeper.pom.MavenModelFromRepositoryReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; /** * This class reads all dependencies of a pom file (including the plugins) together with their license. */ public class ProjectDependencyReader { - private final MavenFileModelReader fileModelReader; - private final MavenArtifactModelReader artifactModelReader; + private final MavenProjectFromFileReader fileModelReader; + private final MavenModelFromRepositoryReader artifactModelReader; /** * Create a new instance of {@link ProjectDependencyReader}. @@ -27,8 +28,8 @@ public class ProjectDependencyReader { * @param fileModelReader pom file parser * @param artifactModelReader maven dependency reader */ - public ProjectDependencyReader(final MavenFileModelReader fileModelReader, - final MavenArtifactModelReader artifactModelReader) { + public ProjectDependencyReader(final MavenProjectFromFileReader fileModelReader, + final MavenModelFromRepositoryReader artifactModelReader) { this.fileModelReader = fileModelReader; this.artifactModelReader = artifactModelReader; } @@ -40,8 +41,9 @@ public ProjectDependencyReader(final MavenFileModelReader fileModelReader, * @return list of dependencies */ public List readDependencies(final File pomFile) { - final var model = parsePomFile(pomFile); - return getDependenciesIncludingPlugins(model).map(this::getDependenciesLicense).collect(Collectors.toList()); + final var project = readProjectFromPomFile(pomFile); + return getDependenciesIncludingPlugins(project.getModel()).map(dependency -> getLicense(dependency, project)) + .collect(Collectors.toList()); } private Stream getDependenciesIncludingPlugins(final Model model) { @@ -58,10 +60,10 @@ private Dependency convertPluginToDependency(final Plugin plugin) { return dependency; } - private ProjectDependency getDependenciesLicense(final Dependency dependency) { + private ProjectDependency getLicense(final Dependency dependency, final MavenProject project) { try { final var dependenciesPom = this.artifactModelReader.readModel(dependency.getArtifactId(), - dependency.getGroupId(), dependency.getVersion()); + dependency.getGroupId(), dependency.getVersion(), project.getRemoteArtifactRepositories()); final List licenses = dependenciesPom.getLicenses().stream() .map(license -> new License(license.getName(), license.getUrl())).collect(Collectors.toList()); return new ProjectDependency(getDependencyName(dependenciesPom), dependenciesPom.getUrl(), licenses, @@ -105,10 +107,10 @@ private ProjectDependency.Type mapScopeToDependencyType(final String scope) { } } - private Model parsePomFile(final File pomFile) { + private MavenProject readProjectFromPomFile(final File pomFile) { try { - return this.fileModelReader.readModel(pomFile); - } catch (final MavenFileModelReader.ReadFailedException exception) { + return this.fileModelReader.readProject(pomFile); + } catch (final MavenProjectFromFileReader.ReadFailedException exception) { throw new IllegalStateException( ExaError.messageBuilder("E-PK-48").message("Failed to parse pom.xml file.").toString(), exception); } diff --git a/src/main/java/com/exasol/projectkeeper/validators/pom/AbstractPomValidator.java b/src/main/java/com/exasol/projectkeeper/validators/pom/AbstractPomValidator.java index 17f7980b..af1acd29 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/pom/AbstractPomValidator.java +++ b/src/main/java/com/exasol/projectkeeper/validators/pom/AbstractPomValidator.java @@ -1,14 +1,12 @@ package com.exasol.projectkeeper.validators.pom; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import java.util.List; import org.w3c.dom.Node; import org.xmlunit.builder.DiffBuilder; -import org.xmlunit.diff.DefaultNodeMatcher; -import org.xmlunit.diff.Diff; -import org.xmlunit.diff.ElementSelectors; +import org.xmlunit.diff.*; /** * Abstract basis for {@link PomValidator}s. diff --git a/src/main/java/com/exasol/projectkeeper/validators/pom/dependencies/AbstractDependencyValidator.java b/src/main/java/com/exasol/projectkeeper/validators/pom/dependencies/AbstractDependencyValidator.java index 0b433524..cb353ba0 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/pom/dependencies/AbstractDependencyValidator.java +++ b/src/main/java/com/exasol/projectkeeper/validators/pom/dependencies/AbstractDependencyValidator.java @@ -1,15 +1,13 @@ package com.exasol.projectkeeper.validators.pom.dependencies; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import java.util.Collection; import java.util.List; import java.util.function.Consumer; import org.apache.maven.plugin.logging.Log; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; +import org.w3c.dom.*; import com.exasol.errorreporting.ExaError; import com.exasol.projectkeeper.ProjectKeeperModule; diff --git a/src/main/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractPluginPomValidator.java b/src/main/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractPluginPomValidator.java index 1b26d878..af4fd38e 100644 --- a/src/main/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractPluginPomValidator.java +++ b/src/main/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractPluginPomValidator.java @@ -1,6 +1,6 @@ package com.exasol.projectkeeper.validators.pom.plugin; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import java.io.IOException; import java.util.Collection; @@ -19,10 +19,8 @@ import com.exasol.errorreporting.ExaError; import com.exasol.projectkeeper.ProjectKeeperModule; import com.exasol.projectkeeper.ValidationFinding; -import com.exasol.projectkeeper.validators.pom.AbstractPomValidator; -import com.exasol.projectkeeper.validators.pom.PomFileValidator; -import com.exasol.projectkeeper.validators.pom.PomValidator; -import com.exasol.xpath.XPathSplitter; +import com.exasol.projectkeeper.validators.pom.*; +import com.exasol.projectkeeper.xpath.XPathSplitter; /** * Abstract basis for maven plugin configuration validation. diff --git a/src/main/java/com/exasol/xpath/XPathErrorHandlingWrapper.java b/src/main/java/com/exasol/projectkeeper/xpath/XPathErrorHandlingWrapper.java similarity index 96% rename from src/main/java/com/exasol/xpath/XPathErrorHandlingWrapper.java rename to src/main/java/com/exasol/projectkeeper/xpath/XPathErrorHandlingWrapper.java index 34b23597..6c9ae2ca 100644 --- a/src/main/java/com/exasol/xpath/XPathErrorHandlingWrapper.java +++ b/src/main/java/com/exasol/projectkeeper/xpath/XPathErrorHandlingWrapper.java @@ -1,4 +1,4 @@ -package com.exasol.xpath; +package com.exasol.projectkeeper.xpath; import javax.xml.xpath.*; diff --git a/src/main/java/com/exasol/xpath/XPathSplitter.java b/src/main/java/com/exasol/projectkeeper/xpath/XPathSplitter.java similarity index 97% rename from src/main/java/com/exasol/xpath/XPathSplitter.java rename to src/main/java/com/exasol/projectkeeper/xpath/XPathSplitter.java index e39db961..ee66a41a 100644 --- a/src/main/java/com/exasol/xpath/XPathSplitter.java +++ b/src/main/java/com/exasol/projectkeeper/xpath/XPathSplitter.java @@ -1,4 +1,4 @@ -package com.exasol.xpath; +package com.exasol.projectkeeper.xpath; import java.util.ArrayList; import java.util.List; diff --git a/src/test/java/com/exasol/projectkeeper/validators/SimpleMavenFileModelReader.java b/src/test/java/com/exasol/projectkeeper/validators/SimpleMavenProjectFromFileReader.java similarity index 74% rename from src/test/java/com/exasol/projectkeeper/validators/SimpleMavenFileModelReader.java rename to src/test/java/com/exasol/projectkeeper/validators/SimpleMavenProjectFromFileReader.java index fd058d5a..43bb6e10 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/SimpleMavenFileModelReader.java +++ b/src/test/java/com/exasol/projectkeeper/validators/SimpleMavenProjectFromFileReader.java @@ -5,17 +5,18 @@ import org.apache.maven.model.Model; import org.apache.maven.model.building.*; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import com.exasol.errorreporting.ExaError; -import com.exasol.projectkeeper.pom.MavenFileModelReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; /** - * Simplified {@link MavenFileModelReader} that works without injected dependencies. + * Simplified {@link MavenProjectFromFileReader} that works without injected dependencies. */ -public class SimpleMavenFileModelReader implements MavenFileModelReader { +public class SimpleMavenProjectFromFileReader implements MavenProjectFromFileReader { @Override - public Model readModel(final File pomFile) throws ReadFailedException { + public MavenProject readProject(final File pomFile) throws ReadFailedException { try (final FileReader reader = new FileReader(pomFile)) { final Model rawModel = new MavenXpp3Reader().read(reader); final ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); @@ -25,7 +26,7 @@ public Model readModel(final File pomFile) throws ReadFailedException { modelRequest.setSystemProperties(System.getProperties()); // for Java version property final DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance(); final ModelBuildingResult result = modelBuilder.build(modelRequest); - return result.getEffectiveModel(); + return new MavenProject(result.getEffectiveModel()); } catch (final IOException | ModelBuildingException | XmlPullParserException exception) { throw new ReadFailedException( ExaError.messageBuilder("E-PK-47").message("Failed to build maven model.").toString(), exception); diff --git a/src/test/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidatorTest.java b/src/test/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidatorTest.java index bdc100d7..fe7985d2 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidatorTest.java +++ b/src/test/java/com/exasol/projectkeeper/validators/changesfile/ChangesFileValidatorTest.java @@ -21,14 +21,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import com.exasol.projectkeeper.pom.MavenFileModelReader; -import com.exasol.projectkeeper.validators.SimpleMavenFileModelReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; +import com.exasol.projectkeeper.validators.SimpleMavenProjectFromFileReader; import com.exasol.projectkeeper.validators.TestMavenModel; class ChangesFileValidatorTest { private static final String A_VERSION = "1.2.3"; private static final String A_PROJECT_NAME = "my-project"; - private static final MavenFileModelReader MAVEN_MODEL_READER = new SimpleMavenFileModelReader(); + private static final MavenProjectFromFileReader MAVEN_MODEL_READER = new SimpleMavenProjectFromFileReader(); @TempDir File tempDir; diff --git a/src/test/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixerTest.java b/src/test/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixerTest.java index 2effcc88..56df2f54 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixerTest.java +++ b/src/test/java/com/exasol/projectkeeper/validators/changesfile/DependencySectionFixerTest.java @@ -18,14 +18,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import com.exasol.projectkeeper.pom.MavenFileModelReader; -import com.exasol.projectkeeper.validators.SimpleMavenFileModelReader; +import com.exasol.projectkeeper.pom.MavenProjectFromFileReader; +import com.exasol.projectkeeper.validators.SimpleMavenProjectFromFileReader; import com.exasol.projectkeeper.validators.TestMavenModel; class DependencySectionFixerTest { @TempDir static Path tempDir; - private static final MavenFileModelReader MAVEN_MODEL_READER = new SimpleMavenFileModelReader(); + private static final MavenProjectFromFileReader MAVEN_MODEL_READER = new SimpleMavenProjectFromFileReader(); @BeforeAll static void beforeAll() throws GitAPIException, IOException { diff --git a/src/test/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidatorIT.java b/src/test/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidatorIT.java index a5a2785c..9679d66c 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidatorIT.java +++ b/src/test/java/com/exasol/projectkeeper/validators/dependencies/DependenciesValidatorIT.java @@ -10,6 +10,7 @@ import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; +import org.apache.maven.model.Repository; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -40,6 +41,17 @@ void testWrongContent() throws IOException, VerificationException { assertThat(output, containsString("[ERROR] E-PK-53: The dependencies.md file has outdated content.")); } + @Test + void testWrongContentWithNonDefaultRepository() throws IOException, VerificationException { + createExamplePomFileWithNonDefaultRepo(); + Files.writeString(this.projectDir.resolve("dependencies.md"), "wrong content"); + final Verifier verifier = getVerifier(); + final VerificationException verificationException = assertThrows(VerificationException.class, + () -> verifier.executeGoal("project-keeper:verify")); + final String output = verificationException.getMessage(); + assertThat(output, containsString("[ERROR] E-PK-53: The dependencies.md file has outdated content.")); + } + @Test void testFix() throws IOException, VerificationException { createExamplePomFile(); @@ -69,4 +81,14 @@ private void createExamplePomFile() throws IOException { pomModel.addDependency("error-reporting-java", "com.exasol", "compile", "0.1.0"); pomModel.writeAsPomToProject(this.projectDir); } + + private void createExamplePomFileWithNonDefaultRepo() throws IOException { + final TestMavenModel pomModel = getTestMavenModelWithProjectKeeperPlugin(); + final Repository exasolRepo = new Repository(); + exasolRepo.setUrl("https://maven.exasol.com/artifactory/exasol-releases"); + exasolRepo.setId("maven.exasol.com"); + pomModel.addRepository(exasolRepo); + pomModel.addDependency("exasol-jdbc", "com.exasol", "compile", "7.0.4"); + pomModel.writeAsPomToProject(this.projectDir); + } } diff --git a/src/test/java/com/exasol/projectkeeper/validators/pom/PomFileIOTest.java b/src/test/java/com/exasol/projectkeeper/validators/pom/PomFileIOTest.java index 37816527..5df661cc 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/pom/PomFileIOTest.java +++ b/src/test/java/com/exasol/projectkeeper/validators/pom/PomFileIOTest.java @@ -2,7 +2,7 @@ import static com.exasol.projectkeeper.validators.pom.PomTesting.POM_WITH_NO_PLUGINS; import static com.exasol.projectkeeper.validators.pom.PomTesting.writeResourceToTempFile; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import static org.hamcrest.MatcherAssert.assertThat; import static org.xmlunit.matchers.HasXPathMatcher.hasXPath; diff --git a/src/test/java/com/exasol/projectkeeper/validators/pom/PomTesting.java b/src/test/java/com/exasol/projectkeeper/validators/pom/PomTesting.java index f2ab21b3..d94440c1 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/pom/PomTesting.java +++ b/src/test/java/com/exasol/projectkeeper/validators/pom/PomTesting.java @@ -1,6 +1,6 @@ package com.exasol.projectkeeper.validators.pom; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import java.io.*; import java.nio.file.Files; diff --git a/src/test/java/com/exasol/projectkeeper/validators/pom/dependencies/JacocoAgentDependencyValidatorTest.java b/src/test/java/com/exasol/projectkeeper/validators/pom/dependencies/JacocoAgentDependencyValidatorTest.java index ed97a993..9cab6ea7 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/pom/dependencies/JacocoAgentDependencyValidatorTest.java +++ b/src/test/java/com/exasol/projectkeeper/validators/pom/dependencies/JacocoAgentDependencyValidatorTest.java @@ -2,7 +2,7 @@ import static com.exasol.projectkeeper.HasValidationFindingWithMessageMatcher.hasValidationFindingWithMessage; import static com.exasol.projectkeeper.validators.pom.PomTesting.*; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; diff --git a/src/test/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractMavenPluginPomValidatorTest.java b/src/test/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractMavenPluginPomValidatorTest.java index fddeb35f..6c189ffd 100644 --- a/src/test/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractMavenPluginPomValidatorTest.java +++ b/src/test/java/com/exasol/projectkeeper/validators/pom/plugin/AbstractMavenPluginPomValidatorTest.java @@ -3,7 +3,7 @@ import static com.exasol.projectkeeper.HasValidationFindingWithMessageMatcher.hasNoValidationFindings; import static com.exasol.projectkeeper.HasValidationFindingWithMessageMatcher.hasValidationFindings; import static com.exasol.projectkeeper.validators.pom.PomTesting.*; -import static com.exasol.xpath.XPathErrorHandlingWrapper.runXPath; +import static com.exasol.projectkeeper.xpath.XPathErrorHandlingWrapper.runXPath; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.Mockito.mock; diff --git a/src/test/java/com/exasol/xpath/XPathSplitterTest.java b/src/test/java/com/exasol/projectkeeper/xpath/XPathSplitterTest.java similarity index 95% rename from src/test/java/com/exasol/xpath/XPathSplitterTest.java rename to src/test/java/com/exasol/projectkeeper/xpath/XPathSplitterTest.java index 11a849bc..6ae3b054 100644 --- a/src/test/java/com/exasol/xpath/XPathSplitterTest.java +++ b/src/test/java/com/exasol/projectkeeper/xpath/XPathSplitterTest.java @@ -1,4 +1,4 @@ -package com.exasol.xpath; +package com.exasol.projectkeeper.xpath; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains;