This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
The following commit(s) were added to refs/heads/master by this push: new eee5c0ca Remove build resumption which was ported from master to support resumption with 3.x (#1275) eee5c0ca is described below commit eee5c0ca9b8030553caa4c5f25e511126dc64be2 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Mon Mar 3 08:36:10 2025 +0100 Remove build resumption which was ported from master to support resumption with 3.x (#1275) --- .../mvnd/execution/BuildResumptionAnalyzer.java | 57 -------- .../mvnd/execution/BuildResumptionData.java | 62 --------- .../execution/BuildResumptionDataRepository.java | 74 ---------- .../BuildResumptionPersistenceException.java | 49 ------- .../execution/DefaultBuildResumptionAnalyzer.java | 89 ------------ .../DefaultBuildResumptionDataRepository.java | 154 --------------------- 6 files changed, 485 deletions(-) diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java deleted file mode 100644 index c0c0ac26..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionAnalyzer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.execution; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.Optional; - -import org.apache.maven.execution.MavenExecutionResult; - -/** - * Instances of this class are responsible for determining whether it makes sense to "resume" a build (i.e., using - * the {@code --resume} flag. - */ -public interface BuildResumptionAnalyzer { - /** - * Construct an instance of {@link BuildResumptionData} based on the outcome of the current Maven build. - * - * @param result Outcome of the current Maven build. - * @return A {@link BuildResumptionData} instance or {@link Optional#empty()} if resuming the build is not - * possible. - */ - Optional<BuildResumptionData> determineBuildResumptionData(final MavenExecutionResult result); -} diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java deleted file mode 100644 index b9ae3eda..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionData.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.execution; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import java.util.List; - -/** - * This class holds the information required to enable resuming a Maven build with {@code --resume}. - */ -public class BuildResumptionData { - /** - * The list of projects that remain to be built. - */ - private final List<String> remainingProjects; - - public BuildResumptionData(final List<String> remainingProjects) { - this.remainingProjects = remainingProjects; - } - - /** - * Returns the projects that still need to be built when resuming. - * - * @return A list containing the group and artifact id of the projects. - */ - public List<String> getRemainingProjects() { - return this.remainingProjects; - } -} diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java deleted file mode 100644 index 6dbae8b8..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionDataRepository.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.execution; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.project.MavenProject; - -/** - * Instances of this interface retrieve and store data for the --resume / -r feature. This data is used to ensure newer - * builds of the same project, that have the -r command-line flag, skip successfully built projects during earlier - * invocations of Maven. - */ -public interface BuildResumptionDataRepository { - /** - * Persists any data needed to resume the build at a later point in time, using a new Maven invocation. This method - * may also decide it is not needed or meaningful to persist such data, and return <code>false</code> to indicate - * so. - * - * @param rootProject The root project that is being built. - * @param buildResumptionData Information needed to resume the build. - * @throws BuildResumptionPersistenceException When an error occurs while persisting data. - */ - void persistResumptionData(final MavenProject rootProject, final BuildResumptionData buildResumptionData) - throws BuildResumptionPersistenceException; - - /** - * Uses previously stored resumption data to enrich an existing execution request. - * - * @param request The execution request that will be enriched. - * @param rootProject The root project that is being built. - */ - void applyResumptionData(final MavenExecutionRequest request, final MavenProject rootProject); - - /** - * Removes previously stored resumption data. - * - * @param rootProject The root project that is being built. - */ - void removeResumptionData(final MavenProject rootProject); -} diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java deleted file mode 100644 index 00f99ca3..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/execution/BuildResumptionPersistenceException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.execution; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * This exception will be thrown when something fails while persisting build resumption data. - * - * @see BuildResumptionDataRepository#persistResumptionData - */ -public class BuildResumptionPersistenceException extends Exception { - public BuildResumptionPersistenceException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java deleted file mode 100644 index 6cd4f19b..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionAnalyzer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.execution; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import org.apache.maven.api.di.Named; -import org.apache.maven.api.di.Singleton; -import org.apache.maven.execution.BuildFailure; -import org.apache.maven.execution.BuildSuccess; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Default implementation of {@link BuildResumptionAnalyzer}. - */ -@Named -@Singleton -public class DefaultBuildResumptionAnalyzer implements BuildResumptionAnalyzer { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultBuildResumptionAnalyzer.class); - - @Override - public Optional<BuildResumptionData> determineBuildResumptionData(final MavenExecutionResult result) { - if (!result.hasExceptions()) { - return Optional.empty(); - } - - List<MavenProject> sortedProjects = result.getTopologicallySortedProjects(); - - boolean hasNoSuccess = - sortedProjects.stream().noneMatch(project -> result.getBuildSummary(project) instanceof BuildSuccess); - - if (hasNoSuccess) { - return Optional.empty(); - } - - List<String> remainingProjects = sortedProjects.stream() - .filter(project -> result.getBuildSummary(project) == null - || result.getBuildSummary(project) instanceof BuildFailure) - .map(project -> project.getGroupId() + ":" + project.getArtifactId()) - .collect(Collectors.toList()); - - if (remainingProjects.isEmpty()) { - LOGGER.info("No remaining projects found, resuming the build would not make sense."); - return Optional.empty(); - } - - return Optional.of(new BuildResumptionData(remainingProjects)); - } -} diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java b/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java deleted file mode 100644 index 9244376b..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/execution/DefaultBuildResumptionDataRepository.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.mvndaemon.mvnd.execution; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Properties; -import java.util.stream.Stream; - -import org.apache.maven.api.di.Named; -import org.apache.maven.api.di.Singleton; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This implementation of {@link BuildResumptionDataRepository} persists information in a properties file. The file is - * stored in the build output directory under the Maven execution root. - */ -@Named -@Singleton -public class DefaultBuildResumptionDataRepository implements BuildResumptionDataRepository { - private static final String RESUME_PROPERTIES_FILENAME = "resume.properties"; - private static final String REMAINING_PROJECTS = "remainingProjects"; - private static final String PROPERTY_DELIMITER = ", "; - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultBuildResumptionDataRepository.class); - - @Override - public void persistResumptionData(MavenProject rootProject, BuildResumptionData buildResumptionData) - throws BuildResumptionPersistenceException { - Path directory = Paths.get(rootProject.getBuild().getDirectory()); - persistResumptionData(directory, buildResumptionData); - } - - public void persistResumptionData(Path directory, BuildResumptionData buildResumptionData) - throws BuildResumptionPersistenceException { - Properties properties = convertToProperties(buildResumptionData); - - Path resumeProperties = directory.resolve(RESUME_PROPERTIES_FILENAME); - try { - Files.createDirectories(resumeProperties.getParent()); - try (Writer writer = Files.newBufferedWriter(resumeProperties)) { - properties.store(writer, null); - } - } catch (IOException e) { - String message = "Could not create " + RESUME_PROPERTIES_FILENAME + " file."; - throw new BuildResumptionPersistenceException(message, e); - } - } - - private Properties convertToProperties(final BuildResumptionData buildResumptionData) { - Properties properties = new Properties(); - - String value = String.join(PROPERTY_DELIMITER, buildResumptionData.getRemainingProjects()); - properties.setProperty(REMAINING_PROJECTS, value); - - return properties; - } - - @Override - public void applyResumptionData(MavenExecutionRequest request, MavenProject rootProject) { - Path directory = Paths.get(rootProject.getBuild().getDirectory()); - applyResumptionData(request, directory); - } - - public void applyResumptionData(MavenExecutionRequest request, Path directory) { - Properties properties = loadResumptionFile(directory); - applyResumptionProperties(request, properties); - } - - @Override - public void removeResumptionData(MavenProject rootProject) { - Path directory = Paths.get(rootProject.getBuild().getDirectory()); - removeResumptionData(directory); - } - - public void removeResumptionData(Path directory) { - Path resumeProperties = directory.resolve(RESUME_PROPERTIES_FILENAME); - try { - Files.deleteIfExists(resumeProperties); - } catch (IOException e) { - LOGGER.warn("Could not delete {} file. ", RESUME_PROPERTIES_FILENAME, e); - } - } - - private Properties loadResumptionFile(Path rootBuildDirectory) { - Properties properties = new Properties(); - Path path = rootBuildDirectory.resolve(RESUME_PROPERTIES_FILENAME); - if (!Files.exists(path)) { - LOGGER.warn("The {} file does not exist. The --resume / -r feature will not work.", path); - return properties; - } - - try (Reader reader = Files.newBufferedReader(path)) { - properties.load(reader); - } catch (IOException e) { - LOGGER.warn("Unable to read {}. The --resume / -r feature will not work.", path); - } - - return properties; - } - - // This method is made package-private for testing purposes - void applyResumptionProperties(MavenExecutionRequest request, Properties properties) { - if (properties.containsKey(REMAINING_PROJECTS) - && (request.getResumeFrom() == null || request.getResumeFrom().isEmpty())) { - String propertyValue = properties.getProperty(REMAINING_PROJECTS); - Stream.of(propertyValue.split(PROPERTY_DELIMITER)) - .filter(s -> s != null && !s.isEmpty()) - .forEach(request.getSelectedProjects()::add); - LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue); - } - } -}