4545 *
4646 * @author Johannes Schindelin
4747 */
48- @ Mojo (name = "set-rootdir" , defaultPhase = LifecyclePhase .VALIDATE )
48+ @ Mojo (name = "set-rootdir" , defaultPhase = LifecyclePhase .VALIDATE , threadSafe = true )
4949public class SetRootDirPropertyMojo extends AbstractMojo {
5050
5151 /**
@@ -67,25 +67,40 @@ public class SetRootDirPropertyMojo extends AbstractMojo {
6767
6868 @ Override
6969 public void execute () throws MojoExecutionException {
70- if (currentProject . getProperties (). getProperty ( rootdirPropertyName ) != null )
71- {
72- getLog (). debug ( "Using previously defined rootdir" );
73- return ;
70+ if (isRootdirPropertyNameDefined ()) {
71+ logUsingPreviouslyDefinedRootdir ();
72+ } else {
73+ setRootdirPropertyName () ;
7474 }
75+ }
7576
76- if (!isLocalProject (currentProject )) return ;
77+ private synchronized void setRootdirPropertyName () {
78+ if (isRootdirPropertyNameDefined ()) {
79+ logUsingPreviouslyDefinedRootdir ();
80+ } else if (isLocalProject (currentProject )) {
81+ MavenProject project = currentProject ;
82+ for (;;) {
83+ final MavenProject parent = project .getParent ();
84+ if (parent == null || ! isLocalProject (parent )) {
85+ break ;
86+ }
87+ project = parent ;
88+ }
7789
78- MavenProject project = currentProject ;
79- for (;;) {
80- final MavenProject parent = project . getParent ();
81- if ( parent == null || ! isLocalProject ( parent )) break ;
82- project = parent ;
90+ final String rootdir = project . getBasedir (). getAbsolutePath () ;
91+ getLog (). info ( "Setting rootdir: " + rootdir );
92+ for ( final MavenProject reactorProject : reactorProjects ) {
93+ reactorProject . getProperties (). setProperty ( rootdirPropertyName , rootdir ) ;
94+ }
8395 }
96+ }
97+
98+ private boolean isRootdirPropertyNameDefined () {
99+ return currentProject .getProperties ().getProperty (rootdirPropertyName ) != null ;
100+ }
84101
85- final String rootdir = project .getBasedir ().getAbsolutePath ();
86- getLog ().info ("Setting rootdir: " + rootdir );
87- for (final MavenProject reactorProject : reactorProjects )
88- reactorProject .getProperties ().setProperty (rootdirPropertyName , rootdir );
102+ private void logUsingPreviouslyDefinedRootdir () {
103+ getLog ().debug ("Using previously defined rootdir" );
89104 }
90105
91106 /**
0 commit comments