Skip to content

Commit

Permalink
bug/170: Fixed excludedFiles for README.md validation (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbraun authored Aug 23, 2021
1 parent 818a43f commit 7c33e20
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 35 deletions.
4 changes: 2 additions & 2 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changes

* [0.11.0](changes_0.11.0.md)
* [1.0.0](changes_1.0.0.md)
* [0.10.0](changes_0.10.0.md)
* [0.9.0](changes_0.9.0.md)
* [0.8.0](changes_0.8.0.md)
Expand All @@ -16,4 +16,4 @@
* [0.4.0](changes_0.4.0.md)
* [0.3.0](changes_0.3.0.md)
* [0.2.0](changes_0.2.0.md)
* [0.1.0](changes_0.1.0.md)
* [0.1.0](changes_0.1.0.md)
10 changes: 7 additions & 3 deletions doc/changes/changes_0.11.0.md → doc/changes/changes_1.0.0.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Project keeper maven plugin 0.11.0, released 2021-??-??
# Project keeper maven plugin 1.0.0, released 2021-08-23

Code name:
Code name: Changelog validation

## Features

* #69: Made copyright-year in license variable
* #164: Added validation for changelog.md file
* #166: Update for release_droid_upload_github_release_assets.yml file

## Bug Fixes:

* #170: Fixed excludedFiles for README.md validation

## Dependency Updates

### Compile Dependency Updates
Expand All @@ -16,4 +20,4 @@ Code name:

### Plugin Dependency Updates

* Updated `com.exasol:project-keeper-maven-plugin:0.10.0` to `0.11.0`
* Updated `com.exasol:project-keeper-maven-plugin:0.10.0` to `1.0.0`
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.exasol</groupId>
<artifactId>project-keeper-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.11.0</version>
<version>1.0.0</version>
<name>Project keeper maven plugin</name>
<description>This maven plugin checks and unifies a project's structure according to the Exasol integration team's
repository standards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ protected List<Validator> getValidators() {
final var pomFile = this.project.getModel().getPomFile();
return List.of(new ProjectFilesValidator(enabledModules, this.project.getBasedir(), excludedFilesMatcher),
new ReadmeFileValidator(projectDir, this.project.getName(), this.project.getArtifactId(),
gitRepository.getRepoNameFromRemote().orElse(this.project.getArtifactId()), enabledModules),
new LicenseFileValidator(projectDir),
gitRepository.getRepoNameFromRemote().orElse(this.project.getArtifactId()), enabledModules,
excludedFilesMatcher),
new LicenseFileValidator(projectDir, excludedFilesMatcher),
new PomFileValidator(enabledModules, this.excludedPlugins, pomFile),
new ChangesFileValidator(this.project.getVersion(), this.project.getName(), projectDir,
mavenModelReader),
new ChangelogFileValidator(projectDir),
mavenModelReader, excludedFilesMatcher),
new ChangelogFileValidator(projectDir, excludedFilesMatcher),
new DependenciesValidator(mavenModelReader, artifactReader, pomFile, projectDir, brokenLinkReplacer),
new DeletedFilesValidator(projectDir, excludedFilesMatcher));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import java.util.List;

import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.ValidationFinding;
import com.exasol.projectkeeper.Validator;
import com.exasol.projectkeeper.*;

/**
* This class is a abstract basis for {@link Validator}s that validate a files content as string.
Expand All @@ -18,9 +17,11 @@ public abstract class AbstractFileContentValidator extends AbstractFileValidator
*
* @param projectDirectory project's root directory
* @param filePath path of the file to validate relative to projectDirectory
* @param excludedFiles matcher for excluded files
*/
protected AbstractFileContentValidator(final Path projectDirectory, final Path filePath) {
super(projectDirectory, filePath);
protected AbstractFileContentValidator(final Path projectDirectory, final Path filePath,
final ExcludedFilesMatcher excludedFiles) {
super(projectDirectory, filePath, excludedFiles);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@
import org.apache.maven.plugin.logging.Log;

import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.ValidationFinding;
import com.exasol.projectkeeper.Validator;
import com.exasol.projectkeeper.*;

/**
* This class is a abstract basis for {@link Validator}s that validate files.
*/
public abstract class AbstractFileValidator implements Validator {
private final Path absoluteFilePath;
private final Path relativeFilePath;
private final ExcludedFilesMatcher excludedFiles;

/**
* Create a new instance of {@link AbstractFileValidator}.
*
* @param projectDirectory project's root directory
* @param filePath path of the file to validate relative to projectDirectory
* @param excludedFiles matcher for excluded files
*/
protected AbstractFileValidator(final Path projectDirectory, final Path filePath) {
protected AbstractFileValidator(final Path projectDirectory, final Path filePath,
final ExcludedFilesMatcher excludedFiles) {
this.relativeFilePath = filePath;
this.excludedFiles = excludedFiles;
this.absoluteFilePath = projectDirectory.resolve(filePath);
}

@Override
public final List<ValidationFinding> validate() {
if (isValidationEnabled()) {
if (!this.excludedFiles.isFileExcluded(this.relativeFilePath) && isValidationEnabled()) {
return runValidation();
} else {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.*;

import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.ExcludedFilesMatcher;
import com.exasol.projectkeeper.ValidationFinding;

/**
Expand All @@ -22,9 +23,10 @@ public class LicenseFileValidator extends AbstractFileContentValidator {
* Create a new instance of {@link LicenseFileValidator}.
*
* @param projectDirectory project's root directory
* @param excludedFiles matcher for excluded files
*/
public LicenseFileValidator(final Path projectDirectory) {
super(projectDirectory, Path.of("LICENSE"));
public LicenseFileValidator(final Path projectDirectory, final ExcludedFilesMatcher excludedFiles) {
super(projectDirectory, Path.of("LICENSE"), excludedFiles);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public class ReadmeFileValidator extends AbstractFileContentValidator {
* @param artifactId artifact id of the maven artifact
* @param repoName name of the repository
* @param enabledModules list of enable modules
* @param excludedFiles matcher for excluded files
*/
public ReadmeFileValidator(final Path projectDirectory, final String projectName, final String artifactId,
final String repoName, final Collection<ProjectKeeperModule> enabledModules) {
super(projectDirectory, Path.of("README.md"));
final String repoName, final Collection<ProjectKeeperModule> enabledModules,
final ExcludedFilesMatcher excludedFiles) {
super(projectDirectory, Path.of("README.md"), excludedFiles);
this.projectName = projectName;
this.artifactId = artifactId;
this.repoName = repoName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.ExcludedFilesMatcher;
import com.exasol.projectkeeper.ValidationFinding;
import com.exasol.projectkeeper.validators.AbstractFileContentValidator;
import com.exasol.projectkeeper.validators.VersionCollector;
Expand All @@ -17,9 +18,10 @@ public class ChangelogFileValidator extends AbstractFileContentValidator {
* Create a new instance of {@link ChangelogFileValidator}.
*
* @param projectDirectory project's root directory
* @param excludedFiles matcher for excluded files
*/
public ChangelogFileValidator(final Path projectDirectory) {
super(projectDirectory, Path.of("doc/changes/changelog.md"));
public ChangelogFileValidator(final Path projectDirectory, final ExcludedFilesMatcher excludedFiles) {
super(projectDirectory, Path.of("doc/changes/changelog.md"), excludedFiles);
this.projectDirectory = projectDirectory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;

import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.ExcludedFilesMatcher;
import com.exasol.projectkeeper.ValidationFinding;
import com.exasol.projectkeeper.pom.MavenProjectFromFileReader;
import com.exasol.projectkeeper.validators.AbstractFileValidator;
Expand All @@ -27,10 +28,11 @@ public class ChangesFileValidator extends AbstractFileValidator {
* @param projectName name of the maven project
* @param projectDirectory root directory of the maven project
* @param mavenModelReader reader for maven models
* @param excludedFiles matcher for excluded files
*/
public ChangesFileValidator(final String projectVersion, final String projectName, final Path projectDirectory,
final MavenProjectFromFileReader mavenModelReader) {
super(projectDirectory, Path.of("doc", "changes", "changes_" + projectVersion + ".md"));
final MavenProjectFromFileReader mavenModelReader, final ExcludedFilesMatcher excludedFiles) {
super(projectDirectory, Path.of("doc", "changes", "changes_" + projectVersion + ".md"), excludedFiles);
this.projectVersion = projectVersion;
this.projectName = projectName;
this.projectDirectory = projectDirectory;
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/exasol/projectkeeper/ProjectKeeperIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,21 @@ void testVerifyReadme() throws IOException {
() -> assertThat(output, containsString("E-PK-62"))//
);
}

@Test
void testExcludedReadme() throws IOException {
final var pom = new TestMavenModel();
pom.addProjectKeeperPlugin(new ProjectKeeperPluginDeclaration(CURRENT_VERSION)
.withEnabledModules(MAVEN_CENTRAL, INTEGRATION_TESTS, JAR_ARTIFACT, UDF_COVERAGE)
.withExcludedFiles("README.md"));
pom.writeAsPomToProject(this.projectDir);
final Verifier verifier = getVerifier();
final VerificationException verificationException = assertThrows(VerificationException.class,
() -> verifier.executeGoal("project-keeper:verify"));
final String output = verificationException.getMessage();
assertAll(//
() -> assertThat(output, not(containsString("README.md"))), //
() -> assertThat(output, not(containsString("README.md")))//
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Calendar;
import java.util.Collections;

import org.apache.maven.plugin.logging.Log;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import com.exasol.projectkeeper.ExcludedFilesMatcher;

//[utest->dsn~license-file-validator~1]
class LicenseFileValidatorTest {
@Test
Expand All @@ -24,6 +27,6 @@ void testCreateFile(@TempDir final Path tempDir) throws IOException {
}

private LicenseFileValidator getValidator(final Path tempDir) {
return new LicenseFileValidator(tempDir);
return new LicenseFileValidator(tempDir, new ExcludedFilesMatcher(Collections.emptyList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

import org.apache.maven.plugin.logging.Log;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import com.exasol.projectkeeper.ExcludedFilesMatcher;

// [utest->dsn~readme-validator~1]
class ReadmeFileValidatorTest {
@Test
Expand All @@ -42,7 +45,8 @@ void testCreateFile(@TempDir final Path tempDir) throws IOException {
}

private ReadmeFileValidator getValidator(final Path tempDir) {
return new ReadmeFileValidator(tempDir, "My Project", "my-project", "my-project-repo", List.of(MAVEN_CENTRAL));
return new ReadmeFileValidator(tempDir, "My Project", "my-project", "my-project-repo", List.of(MAVEN_CENTRAL),
new ExcludedFilesMatcher(Collections.emptyList()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

import org.apache.maven.plugin.logging.Log;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import com.exasol.projectkeeper.ExcludedFilesMatcher;
import com.exasol.projectkeeper.ValidationFinding;

//[utest->dsn~verify-changelog-file~1]
Expand All @@ -32,16 +34,19 @@ void beforeEach() throws IOException {

@Test
void testValidateWrongContent() {
final List<ValidationFinding> findings = new ChangelogFileValidator(this.tempDir).validate();
final List<ValidationFinding> findings = getValidator().validate();
assertThat(findings.get(0).getMessage(),
startsWith("E-PK-69: The changelog.md file has an outdated content. Expected content:"));
}

private ChangelogFileValidator getValidator() {
return new ChangelogFileValidator(this.tempDir, new ExcludedFilesMatcher(Collections.emptyList()));
}

@Test
void testFix() {
new ChangelogFileValidator(this.tempDir).validate()
.forEach(finding -> finding.getFix().fixError(mock(Log.class)));
final List<ValidationFinding> findingsInSecondRun = new ChangelogFileValidator(this.tempDir).validate();
getValidator().validate().forEach(finding -> finding.getFix().fixError(mock(Log.class)));
final List<ValidationFinding> findingsInSecondRun = getValidator().validate();
assertThat(findingsInSecondRun.size(), equalTo(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;

import org.apache.maven.plugin.logging.Log;
import org.eclipse.jgit.api.Git;
Expand All @@ -21,6 +22,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import com.exasol.projectkeeper.ExcludedFilesMatcher;
import com.exasol.projectkeeper.pom.MavenProjectFromFileReader;
import com.exasol.projectkeeper.validators.SimpleMavenProjectFromFileReader;
import com.exasol.projectkeeper.validators.TestMavenModel;
Expand Down Expand Up @@ -48,8 +50,10 @@ void testValidation() throws IOException {
@Test
void testValidationForSnapshotVersion() throws IOException {
createTestSetup();
assertThat(new ChangesFileValidator(A_VERSION + "-SNAPSHOT", A_PROJECT_NAME, this.tempDir.toPath(),
MAVEN_MODEL_READER), hasNoValidationFindings());
assertThat(
new ChangesFileValidator(A_VERSION + "-SNAPSHOT", A_PROJECT_NAME, this.tempDir.toPath(),
MAVEN_MODEL_READER, new ExcludedFilesMatcher(Collections.emptyList())),
hasNoValidationFindings());
}

@Test
Expand Down Expand Up @@ -84,7 +88,8 @@ void testValidationOnFixedFile() throws IOException {
}

private ChangesFileValidator createValidator() {
return new ChangesFileValidator(A_VERSION, A_PROJECT_NAME, this.tempDir.toPath(), MAVEN_MODEL_READER);
return new ChangesFileValidator(A_VERSION, A_PROJECT_NAME, this.tempDir.toPath(), MAVEN_MODEL_READER,
new ExcludedFilesMatcher(Collections.emptyList()));
}

private void createTestSetup() throws IOException {
Expand Down

0 comments on commit 7c33e20

Please sign in to comment.