michael-o commented on code in PR #736:
URL: https://github.com/apache/maven/pull/736#discussion_r873995380
##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java:
##########
@@ -220,20 +223,43 @@ private void execute( MavenSession session, MojoExecution
mojoExecution, Project
* TODO: ideally, the builder should take care of the ordering in a
smarter way
* TODO: and concurrency issues fixed with MNG-7157
*/
- private static class ProjectLock implements AutoCloseable
+ private class ProjectLock implements AutoCloseable
{
final Lock acquiredAggregatorLock;
- final Lock acquiredProjectLock;
+ final OwnerReentrantLock acquiredProjectLock;
- ProjectLock( MavenSession session, MojoDescriptor mojoDescriptor,
ReadWriteLock aggregatorLock )
+ ProjectLock( MavenSession session, MojoDescriptor mojoDescriptor )
{
+ mojos.put( Thread.currentThread(), mojoDescriptor );
if ( session.getRequest().getDegreeOfConcurrency() > 1 )
{
- boolean aggregator = mojoDescriptor.isAggregator();
- acquiredAggregatorLock = aggregator ?
aggregatorLock.writeLock() : aggregatorLock.readLock();
+ acquiredAggregatorLock = mojoDescriptor.isAggregator()
+ ? aggregatorLock.writeLock() :
aggregatorLock.readLock();
+ if ( !acquiredAggregatorLock.tryLock() )
+ {
+ Thread owner = aggregatorLock.getOwner();
+ MojoDescriptor ownerMojo = owner != null ? mojos.get(
owner ) : null;
+ String str = ownerMojo != null ? " The " +
ownerMojo.getId() : "An ";
+ String msg = str + " aggregator mojo is already being
executed "
+ + "in this parallel build, those kind of mojos
require exclusive access to "
+ + "reactor to prevent race conditions. This mojo
execution will be blocked "
+ + "until the aggregator mojo is done.";
+ warn( msg );
+ acquiredAggregatorLock.lock();
+ }
acquiredProjectLock = getProjectLock( session );
- acquiredAggregatorLock.lock();
- acquiredProjectLock.lock();
+ if ( !acquiredProjectLock.tryLock() )
+ {
+ Thread owner = acquiredProjectLock.getOwner();
+ MojoDescriptor ownerMojo = owner != null ? mojos.get(
owner ) : null;
+ String str = ownerMojo != null ? " The " +
ownerMojo.getId() : "An ";
+ String msg = str + " mojo is already being executed "
+ + "on the project " +
session.getCurrentProject().toString() + ". "
Review Comment:
toString() is redundant. It will be called by Java automatically.
##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java:
##########
@@ -282,6 +308,32 @@ private Lock getProjectLock( MavenSession session )
}
}
+ static class OwnerReentrantLock extends ReentrantLock
+ {
+ @Override
+ public Thread getOwner()
+ {
+ return super.getOwner();
+ }
+ }
+
+ static class OwnerReentrantReadWriteLock extends ReentrantReadWriteLock
+ {
+ @Override
+ public Thread getOwner()
+ {
+ return super.getOwner();
+ }
+ }
+
+ private static void warn( String msg )
+ {
+ for ( String s : MessageHelper.formatWarning( msg ) )
+ {
+ LOGGER.warn( s );
+ }
Review Comment:
In a concurrent build may it happen that interleaving threads might break
this message as a whole?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]