com.exasol.projectkeeper.ProjectKeeper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of project-keeper-core Show documentation
Show all versions of project-keeper-core Show documentation
Project keeper is a tool that verifies and fixes project setups.
package com.exasol.projectkeeper;
import static com.exasol.projectkeeper.ApStyleFormatter.humanReadable;
import static com.exasol.projectkeeper.shared.config.SourceType.MAVEN;
import static com.exasol.projectkeeper.validators.finding.SimpleValidationFinding.blockers;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.ValidationPhase.Provision;
import com.exasol.projectkeeper.config.ProjectKeeperConfigReader;
import com.exasol.projectkeeper.shared.config.*;
import com.exasol.projectkeeper.sources.AnalyzedSource;
import com.exasol.projectkeeper.sources.SourceAnalyzer;
import com.exasol.projectkeeper.sources.analyze.generic.RepoNameReader;
import com.exasol.projectkeeper.validators.*;
import com.exasol.projectkeeper.validators.changelog.ChangelogFileValidator;
import com.exasol.projectkeeper.validators.changesfile.ChangesFileValidator;
import com.exasol.projectkeeper.validators.dependencies.DependenciesValidator;
import com.exasol.projectkeeper.validators.files.LatestChangesFileValidator;
import com.exasol.projectkeeper.validators.files.ProjectFilesValidator;
import com.exasol.projectkeeper.validators.finding.*;
import com.exasol.projectkeeper.validators.pom.PomFileValidator;
/**
* This is the entry-point class of project-keeper-core.
*/
public class ProjectKeeper {
private static final String INVALID_STRUCTURE_MESSAGE = "This projects structure does not conform with the template.";
private final Logger logger;
private final Path projectDir;
private final Path mvnRepo;
private final ProjectKeeperConfig config;
private final String ownVersion;
private final String repoName;
private ProjectKeeper(final Logger logger, final Path projectDir, final Path mvnRepo,
final ProjectKeeperConfig config, final String ownVersion) {
this.logger = logger;
this.projectDir = projectDir;
this.mvnRepo = mvnRepo;
this.config = config;
this.ownVersion = ownVersion;
this.repoName = RepoNameReader.getRepoName(projectDir);
}
/**
* Create a new instance of {@link ProjectKeeper}.
*
* @param logger logger
* @param projectDir project directory
* @param mvnRepo maven repository (null if unknown)
* @return built {@link ProjectKeeper}
*/
public static ProjectKeeper createProjectKeeper(final Logger logger, final Path projectDir, final Path mvnRepo) {
return new ProjectKeeper(logger, projectDir, mvnRepo, readConfig(projectDir), getOwnVersion());
}
private static String getOwnVersion() {
final String packageVersion = ProjectKeeper.class.getPackage().getImplementationVersion();
if (packageVersion != null) {
return packageVersion;
}
final String versionFromProperty = System.getProperty("com.exasol.projectkeeper.ownVersion");
if (versionFromProperty != null) {
return versionFromProperty;
}
return "(unknownVersion)";
}
/**
* Create a new instance of {@link ProjectKeeper}.
*
* This factory method is for testing only!
*
*
* @param logger logger
* @param projectDir project directory
* @param mvnRepo maven repository (null if unknown)
* @param ownVersion version of project-keeper
* @return built {@link ProjectKeeper}
*/
static ProjectKeeper createProjectKeeper(final Logger logger, final Path projectDir, final Path mvnRepo,
final String ownVersion) {
return new ProjectKeeper(logger, projectDir, mvnRepo, readConfig(projectDir), ownVersion);
}
private List> getValidationPhases() {
return List.of(this::phase0, this::phase1, this::phase2, this::phase3);
}
/*
* Phase 0 must run before the project file validation, because the project file validation depends on them.
*/
private ValidationPhase phase0(final ValidationPhase.Provision provision) {
return ValidationPhase.from(new LicenseFileValidator(this.projectDir));
}
/*
* Phase 1 validates the build files like for example the pom.xml. In that phase analyzedSources is not yet
* available.
*/
private ValidationPhase phase1(final ValidationPhase.Provision provision) {
final String licenseName = new LicenseNameReader().readLicenseName(this.projectDir);
final List validators = new ArrayList<>();
for (final Source source : this.config.getSources()) {
if (source.getType().equals(MAVEN)) {
validators.add(new PomFileValidator(this.projectDir, source.getModules(), source.getPath(),
source.getParentPom(), new RepoInfo(this.repoName, licenseName)));
} else {
validators.add(OwnVersionValidator.forCli(this.ownVersion));
}
}
return new ValidationPhase(null, validators);
}
/*
* Phase 2 finally analyzes the sources and detects the version of the current project.
*/
private ValidationPhase phase2(final ValidationPhase.Provision provision) {
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy