aboutsummaryrefslogtreecommitdiffstats
path: root/config-class-plugin
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon.hallingstad@gmail.com>2020-10-31 13:38:23 +0100
committerHåkon Hallingstad <hakon.hallingstad@gmail.com>2020-10-31 13:38:23 +0100
commit2f45d465a580a20f52fea466e7a6e3729829d6c5 (patch)
tree4cee5845712cf5fba42e5b60fe0efe11db08f4a8 /config-class-plugin
parent01de6039781e8064d0846b41843b1b26133319cc (diff)
Use javadoc-no-fork and various fixes
Diffstat (limited to 'config-class-plugin')
-rw-r--r--config-class-plugin/pom.xml2
-rw-r--r--config-class-plugin/src/main/java/com/yahoo/vespa/CloverChecker.java53
-rw-r--r--config-class-plugin/src/main/java/com/yahoo/vespa/ConfigGenMojo.java66
3 files changed, 26 insertions, 95 deletions
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 @@
<artifactId>config-class-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>7-SNAPSHOT</version>
- <name>Vespa ConfigGen Plugin</name>
+ <name>config-class-plugin (Vespa ConfigGen Plugin)</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
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<String>
- 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<String> 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<String> 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<String> defFileNames) {
- long oldestGeneratedModifiedTime = Long.MAX_VALUE;
- try {
- List<File> 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<Path> 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);