Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-5760] Add --resume / -r switch #342

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
07b60e4
[MNG-5760] When a build fails, write file with properties to resume t…
MartinKanters May 4, 2020
fe48f1b
[MNG-5760] Refactored the getResumeFromSelector logic to be compliant…
MartinKanters May 22, 2020
883d806
[MNG-5760] Added JavaDoc to the method which determines whether a res…
MartinKanters May 22, 2020
c467598
[MNG-5760] Added license to BuildResumptionManagerTest
MartinKanters May 22, 2020
0dc3c0b
[MNG-5760] When -r is given, load resume.properties and apply it to t…
MartinKanters May 22, 2020
a65ecc3
[MNG-5760] Created unit tests for the resumeFromSelector method.
MartinKanters May 22, 2020
79df2e5
[MNG-5760] Removed dead code, as the `getResumeFrom` method has been …
MartinKanters May 22, 2020
8d7f51c
[MNG-5760] Fix bug where the build resume hint log could be logged in…
MartinKanters May 22, 2020
fe92235
[MNG-5760] Fixed a bug where a failed project would be excluded in th…
MartinKanters May 23, 2020
368b60b
[MNG-5760] Refactored to call the resumption manager from the Default…
MartinKanters May 23, 2020
712932d
[MNG-5760] Removing the resumption data when a build succeeded.
MartinKanters May 23, 2020
2763ee0
[MNG-5760] Extract public interface
mthmulders May 23, 2020
7bc1e06
[MNG-5760] Store information about resumption storage in execution re…
mthmulders May 23, 2020
c7fee3f
[MNG-5760] Replace Stream#filter#count with Stream#anyMatch
mthmulders May 25, 2020
b93dbfd
[MNG-5760] Avoid stringly-typed method signatures
mthmulders May 25, 2020
8bcaa9f
[MNG-5760] Rename resumptionDataStored to canResume
mthmulders May 25, 2020
77e5d53
[MNG-5760] Replace Plexus logger with SLF4J
mthmulders May 25, 2020
d33702d
[MNG-5760] Replace String#format with String concatenation
mthmulders May 25, 2020
40ab881
Merge remote-tracking branch 'origin/master' into mng-5760-resume-fea…
MartinKanters Jun 3, 2020
5a130ea
[MNG-5760] Renamed BuildResumptionManager to BuildResumer
MartinKanters Jun 5, 2020
7801922
[MNG-5760] Removed an unused mock for the plexus Logger, which is a l…
MartinKanters Jun 5, 2020
5a4a946
[MNG-5760] Resolving review comment; clearing up persistResumptionDat…
MartinKanters Jun 5, 2020
557ec1c
[MNG-5760] Review comment: Removed Guava's @VisibleForTesting
MartinKanters Jun 5, 2020
08e3a61
[MNG-5760] When something fails while persisting resumption data, thr…
MartinKanters Jun 5, 2020
c86da3b
[MNG-5760] Add a boolean to the setCanResume method, which denotes wh…
MartinKanters Jun 5, 2020
2d5c380
[MNG-5760] Fixed checkstyle findings
MartinKanters Jun 5, 2020
41faa43
[MNG-5760] Moved the -rf helper method, including the tests, back to …
MartinKanters Jun 6, 2020
d87dcbf
[MNG-5760] Rename interface and implementation
mthmulders Jun 17, 2020
4e35d21
[MNG-5760] Refactored `#determineProjectsToSkip` to return a list ins…
MartinKanters Jun 17, 2020
9a43e1a
[MNG-5760] Split off BuildResumptionAnalyzer from BuildResumptionData…
mthmulders Jun 17, 2020
adf8c6f
[MNG-5760] Persist method either succeeds or throws Exception, so ret…
mthmulders Jun 18, 2020
058fa9e
[MNG-5760] Removed unused import
MartinKanters Jun 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import javax.inject.Singleton;

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.execution.BuildResumptionAnalyzer;
import org.apache.maven.execution.BuildResumptionDataRepository;
import org.apache.maven.execution.BuildResumptionPersistenceException;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenExecutionRequest;
Expand All @@ -44,6 +47,7 @@
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.graph.GraphBuilder;
import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.lifecycle.internal.LifecycleStarter;
import org.apache.maven.model.Prerequisites;
Expand Down Expand Up @@ -99,6 +103,12 @@ public class DefaultMaven
@Named( GraphBuilder.HINT )
private GraphBuilder graphBuilder;

@Inject
private BuildResumptionAnalyzer buildResumptionAnalyzer;

@Inject
private BuildResumptionDataRepository buildResumptionDataRepository;

@Override
public MavenExecutionResult execute( MavenExecutionRequest request )
{
Expand Down Expand Up @@ -312,7 +322,16 @@ private MavenExecutionResult doExecute( MavenExecutionRequest request, MavenSess

if ( session.getResult().hasExceptions() )
{
return addExceptionToResult( result, session.getResult().getExceptions().get( 0 ) );
addExceptionToResult( result, session.getResult().getExceptions().get( 0 ) );
persistResumptionData( result, session );
return result;
}
else
{
session.getAllProjects().stream()
.filter( MavenProject::isExecutionRoot )
.findFirst()
.ifPresent( buildResumptionDataRepository::removeResumptionData );
}
}
finally
Expand Down Expand Up @@ -349,6 +368,33 @@ private void afterSessionEnd( Collection<MavenProject> projects, MavenSession se
}
}

private void persistResumptionData( MavenExecutionResult result, MavenSession session )
{
boolean hasLifecycleExecutionExceptions = result.getExceptions().stream()
.anyMatch( LifecycleExecutionException.class::isInstance );

if ( hasLifecycleExecutionExceptions )
{
MavenProject rootProject = session.getAllProjects().stream()
.filter( MavenProject::isExecutionRoot )
.findFirst()
.orElseThrow( () -> new IllegalStateException( "No project in the session is execution root" ) );

buildResumptionAnalyzer.determineBuildResumptionData( result ).ifPresent( resumption ->
{
try
{
buildResumptionDataRepository.persistResumptionData( rootProject, resumption );
result.setCanResume( true );
}
catch ( BuildResumptionPersistenceException e )
{
logger.warn( "Could not persist build resumption data", e );
}
} );
}
}

public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
return repositorySessionFactory.newRepositorySession( request );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.apache.maven.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;

/**
* 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 );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.apache.maven.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 project where the next build could resume from.
*/
private final String resumeFrom;

/**
* List of projects to skip if the build would be resumed from {@link #resumeFrom}.
*/
private final List<String> projectsToSkip;

public BuildResumptionData ( final String resumeFrom, final List<String> projectsToSkip )
{
this.resumeFrom = resumeFrom;
this.projectsToSkip = projectsToSkip;
}

public String getResumeFrom()
{
return this.resumeFrom;
}

public List<String> getProjectsToSkip()
{
return this.projectsToSkip;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.apache.maven.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.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 );

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.apache.maven.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 );
}
}
Loading