From 2f45d465a580a20f52fea466e7a6e3729829d6c5 Mon Sep 17 00:00:00 2001 From: HÃ¥kon Hallingstad Date: Sat, 31 Oct 2020 13:38:23 +0100 Subject: Use javadoc-no-fork and various fixes --- config-class-plugin/pom.xml | 2 +- .../main/java/com/yahoo/vespa/CloverChecker.java | 53 ----------------- .../main/java/com/yahoo/vespa/ConfigGenMojo.java | 66 ++++++++-------------- 3 files changed, 26 insertions(+), 95 deletions(-) delete mode 100644 config-class-plugin/src/main/java/com/yahoo/vespa/CloverChecker.java (limited to 'config-class-plugin') diff --git a/config-class-plugin/pom.xml b/config-class-plugin/pom.xml index 4809db247d4..08ae440e35d 100644 --- a/config-class-plugin/pom.xml +++ b/config-class-plugin/pom.xml @@ -11,7 +11,7 @@ config-class-plugin maven-plugin 7-SNAPSHOT - Vespa ConfigGen Plugin + config-class-plugin (Vespa ConfigGen Plugin) org.apache.maven diff --git a/config-class-plugin/src/main/java/com/yahoo/vespa/CloverChecker.java b/config-class-plugin/src/main/java/com/yahoo/vespa/CloverChecker.java deleted file mode 100644 index 5b9e1d9a408..00000000000 --- a/config-class-plugin/src/main/java/com/yahoo/vespa/CloverChecker.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa; - -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.function.Predicate; - -/** - * @author Tony Vaagenes - */ -class CloverChecker { - private final Log log; - - CloverChecker(Log log) { - this.log = log; - } - - @SuppressWarnings("unchecked") //getCompileSourceRoots() returns List instead of List - public boolean isForkedCloverLifecycle(MavenProject project, Path outputDirectory) { - return "clover".equals(project.getArtifact().getClassifier()) && - project.getCompileSourceRoots().stream().anyMatch( - equalsPathAbsolutely(regularOutputDirectory(project, outputDirectory))); - } - - /* - * Regular output directory for generated classes, - * i.e. not the clover output directory. - * - * Example: - * If outputDirectory is target/clover/generated-sources/vespa-configgen-plugin, - * return target/generated-sources/vespa-configgen-plugin. - */ - private Path regularOutputDirectory(MavenProject project, Path outputDirectory) { - Path cloverTargetPath = Paths.get(project.getBuild().getDirectory()); - Path targetPath = cloverTargetPath.getParent(); - - if (!targetPath.endsWith("target")) { - log.warn("Guessing that target directory is " + targetPath + ", this might not be correct."); - } - - Path outputDirectoryRelativeToCloverDirectory = cloverTargetPath.relativize(outputDirectory); - return targetPath.resolve(outputDirectoryRelativeToCloverDirectory); - } - - private Predicate equalsPathAbsolutely(Path path) { - Path absolutePath = path.toAbsolutePath(); - - return candidateStringPath -> Paths.get(candidateStringPath).toAbsolutePath().equals(absolutePath); - } -} diff --git a/config-class-plugin/src/main/java/com/yahoo/vespa/ConfigGenMojo.java b/config-class-plugin/src/main/java/com/yahoo/vespa/ConfigGenMojo.java index 9930d53ca6c..df2359a8129 100644 --- a/config-class-plugin/src/main/java/com/yahoo/vespa/ConfigGenMojo.java +++ b/config-class-plugin/src/main/java/com/yahoo/vespa/ConfigGenMojo.java @@ -19,7 +19,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.yahoo.config.codegen.DefParser.DEFAULT_PACKAGE_PREFIX; @@ -36,8 +36,7 @@ public class ConfigGenMojo extends AbstractMojo { * Generate source to here. */ @Parameter(property = "plugin.configuration.outputDirectory", - defaultValue = "${project.build.directory}/generated-sources/vespa-configgen-plugin", - required = true) + defaultValue = "${project.build.directory}/generated-sources/vespa-configgen-plugin") private File outputDirectory; /** @@ -69,7 +68,7 @@ public class ConfigGenMojo extends AbstractMojo { * If true, the config sources are only intended for use during testing. * */ - @Parameter(property = "plugin.configuration.testConfig", defaultValue = "false", required = true) + @Parameter(property = "plugin.configuration.testConfig", defaultValue = "false") private boolean testConfig; /** @@ -103,11 +102,6 @@ public class ConfigGenMojo extends AbstractMojo { public void execute() throws MojoExecutionException { - if (new CloverChecker(getLog()).isForkedCloverLifecycle(project, outputDirectory.toPath())) { - getLog().info("Skipping config generation in forked clover lifecycle."); - return; - } - List defFileNames = getDefFileNames(); // Silent failure when there are no def-files to process... @@ -115,13 +109,7 @@ public class ConfigGenMojo extends AbstractMojo { return; } - // append all def-file names together - StringBuilder configSpec = new StringBuilder(); - boolean notFirst = false; - for (String defFile : defFileNames) { - if (notFirst) { configSpec.append(","); } else { notFirst = true; } - configSpec.append(defFile); - } + String configSpec = String.join(",", defFileNames); boolean generateSources; // optionally create the output directory @@ -139,7 +127,7 @@ public class ConfigGenMojo extends AbstractMojo { getLog().debug("Will generate config class files"); try { MakeConfigProperties config = new MakeConfigProperties(outputDirectory.toString(), - configSpec.toString(), + configSpec, null, null, null, @@ -160,37 +148,33 @@ public class ConfigGenMojo extends AbstractMojo { } private boolean isSomeGeneratedFileStale(File outputDirectory, List defFileNames) { - long oldestGeneratedModifiedTime = Long.MAX_VALUE; - try { - List files = Files.walk(outputDirectory.toPath()) + long oldestGeneratedModifiedTime = walk(outputDirectory.toPath()) .filter(Files::isRegularFile) .map(Path::toFile) - .collect(Collectors.toList()); - for (File f : files) { - getLog().debug("Checking generated file " + f); - final long l = f.lastModified(); - if (l < oldestGeneratedModifiedTime) { - oldestGeneratedModifiedTime = l; - } - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } - - long lastModifiedSource = 0; - for (String sourceFile : defFileNames) { - getLog().debug("Checking source file " + sourceFile); - File f = new File(sourceFile); - final long l = f.lastModified(); - if (l > lastModifiedSource) { - lastModifiedSource = l; - } - } + .peek(f -> getLog().debug("Checking generated file " + f)) + .mapToLong(File::lastModified) + .min() + .orElse(Long.MAX_VALUE); + + long lastModifiedSource = defFileNames.stream() + .peek(sourceFile -> getLog().debug("Checking source file " + sourceFile)) + .map(File::new) + .mapToLong(File::lastModified) + .max() + .orElse(0L); getLog().debug("lastModifiedSource: " + lastModifiedSource + ", oldestTGeneratedModified: " + oldestGeneratedModifiedTime); return lastModifiedSource > oldestGeneratedModifiedTime; } + private static Stream walk(Path path) { + try { + return Files.walk(path); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + private void addSourceRoot(String outputDirectory) { if (testConfig) { project.addTestCompileSourceRoot(outputDirectory); -- cgit v1.2.3