maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Casey <jdca...@commonjava.org>
Subject Re: AW: MRELEASE-261 - Fix for Maven2 Release Plugin concerning flat multi-project structures does not work for us
Date Thu, 27 Aug 2009 21:38:59 GMT
Are you having trouble attaching this to the issue in JIRA?

johannes.konstantinidis@capgemini-sdm.com wrote:
> Ok, this is the patch, as attachments don't work...
>  
>  
>  
> Index: maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java
> ===================================================================
> --- maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java
(revision 778269)
> +++ maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java
(working copy)
> @@ -78,8 +78,20 @@
>                      throw new ReleaseExecutionException( "Cannot find Maven executor
with id: " + releaseEnvironment.getMavenExecutorId() );
>                  }
>  
> -                mavenExecutor.executeGoals( determineWorkingDirectory( workingDirectory,
> -                                            releaseDescriptor.getScmRelativePathProjectDirectory(),
releaseDescriptor.getRootProjectPath() ),
> +                // We have the problem that the determined working directory sometimes
does not exist!
> +                File newWorkingDirectory = determineWorkingDirectory( workingDirectory,
> +                        releaseDescriptor.getScmRelativePathProjectDirectory(), releaseDescriptor.getRootProjectPath()
);
> +                
> +                if (!newWorkingDirectory.exists())
> +                {
> +                    try {
> +                        newWorkingDirectory.mkdirs();
> +                    } catch (Exception e) {
> +                        // we ignore the exception, just as maven does it now.
> +                    }
> +                }
> +                
> +                mavenExecutor.executeGoals( newWorkingDirectory,
>                                              goals, releaseEnvironment, releaseDescriptor.isInteractive(),
>                                              additionalArguments, result );
>              }
> @@ -136,7 +148,25 @@
>          
>          if( StringUtils.isNotEmpty( rootProjectPath ) )
>          {
> -            workingDirectory = new File( workingDirectory, rootProjectPath );
> +            // Is the beginning of the rootProjectPath the end of the workingDirectory?
> +            String tmpWorkingDirectoryPath = workingDirectory.getAbsolutePath();
> +            String tmpRootProjectPath = rootProjectPath;
> +            // First of all we have to make the directory delimiters equal
> +            tmpWorkingDirectoryPath = tmpWorkingDirectoryPath.replaceAll("\\\\", "/");
> +            tmpRootProjectPath = tmpRootProjectPath.replaceAll("\\\\", "/");
> +            
> +            // Is there a standard solution for this problem?
> +            int matchAt = 1;    // We have to start at 1 or we have an instant match
:-)
> +            boolean found = false;
> +            while(tmpWorkingDirectoryPath.length() > matchAt && tmpRootProjectPath.length()
> matchAt && !found)
> +            {
> +                found = tmpWorkingDirectoryPath.regionMatches(tmpWorkingDirectoryPath.length()
- matchAt , tmpRootProjectPath, 0, matchAt);
> +                if (!found)
> +                {
> +                    matchAt++;
> +                }
> +            }
> +            workingDirectory = new File( workingDirectory, rootProjectPath.substring(matchAt)
);
>          }
>          
>          return workingDirectory;
> Index: maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
> ===================================================================
> --- maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
(revision 778269)
> +++ maven-release-manager/src/main/java/org/apache/maven/shared/release/util/ReleaseUtil.java
(working copy)
> @@ -194,23 +194,55 @@
>       * @param path2 The second path
>       * @return The common path of the two paths.
>       */
> -    public static String getCommonPath( String path1, String path2 )
> +    public static String getCommonPath( String path1, String path2)
>      {
> +        return ReleaseUtil.getCommonPath(path1, path2, null, false);
> +    }
> +    
> +    /**
> +     * Returns the common path of the two paths specified.
> +     * The paths are split by the separator. 
> +     * Only whole segments are added to the resulting path.
> +     * 
> +     * @param path1 The first path
> +     * @param path2 The second path
> +     * @param separator The separator. Can be null. In this case each letter is handled
as a segment.
> +     * @param reverse Affects the position of the separator in case if a segment comparison
> +     * @return The common path of the two paths.
> +     */
> +    public static String getCommonPath( String path1, String path2, String separator,
boolean reverse)
> +    {
>          if ( path2 == null || path2.equals( "" ) )
>          {
>              return path1;
>          }
>          else
>          {
> -            int indexDiff = StringUtils.indexOfDifference( path1, path2 );         
  
> -            if( indexDiff > 0 )
> +            if (separator == null) 
>              {
> -                return path1.substring( 0, indexDiff );
> +                // With no separator specified we compare the whole strings
> +                int indexDiff = StringUtils.indexOfDifference( path1, path2 );     
      
> +                if( indexDiff > 0 )
> +                {
> +                    return path1.substring( 0, indexDiff );
> +                }
> +                else
> +                {
> +                    return path1;
> +                }
> +            } else {
> +                // We split the paths and just take the segments that are equal up to
the first difference
> +                String[] splittedPath1 = path1.split(separator);
> +                String[] splittedPath2 = path2.split(separator);
> +                StringBuffer commonPathSB = new StringBuffer();
> +                int indexSP = 0;
> +                while(indexSP < splittedPath1.length && indexSP < splittedPath2.length
&& splittedPath1[indexSP].equals(splittedPath2[indexSP]))
> +                {
> +                    commonPathSB.append(reverse ? "" : separator) .append(splittedPath1[indexSP]).append(reverse
? separator : "");
> +                    indexSP++;
> +                }
> +                return commonPathSB.toString();
>              }
> -            else
> -            {
> -                return path1;
> -            }
>          }
>      }
>      
> @@ -262,9 +294,13 @@
>               String scmConnection = project.getScm().getConnection();
>               scmConnection = StringUtils.replace( scmConnection, "\\", "/" );
>               
> +             // We have to take care of the SCM delimiters : and |
> +             String[] splitScmConnection = scmConnection.split("[:\\|]");
> +             String tmpScmConnection = splitScmConnection[splitScmConnection.length
- 1];
> +             
>                  projectPath =
>                      ReleaseUtil.getCommonPath( StringUtils.reverse( StringUtils.chomp(
projectBaseDir, "/" ) ),
> -                                               StringUtils.reverse( StringUtils.chomp(
scmConnection, "/" ) ) );
> +                                               StringUtils.reverse( StringUtils.chomp(
tmpScmConnection, "/" ) ), "/", true);
>              }
>              
>              relPath = StringUtils.reverse( projectPath );
> Index: maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java
> ===================================================================
> --- maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java
(revision 778269)
> +++ maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java
(working copy)
> @@ -138,6 +138,70 @@
>          assertEquals( "/root-project", ReleaseUtil.getRootProjectPath( project ) );
>      }
>      
> +    public void testGetRootProjectPathFlatStructureWithSegments()
> +        throws Exception
> +    {   
> +        MavenProject project = new MavenProject()
> +        {
> +            public List getModules()
> +            {
> +                List modules = new ArrayList();
> +                modules.add( "../core" );
> +                modules.add( "../webapp" );
> +                modules.add( "../commons" );
> +                
> +                return modules;
> +            }
> +            
> +            public File getBasedir()
> +            {
> +                return new File( "/dev/root-project" );
> +            }
> +            
> +            public Scm getScm()
> +            {
> +                Scm scm = new Scm();
> +                scm.setConnection( "scm:cvs:pserver:username@host:port:repository:anythingdev/root-project"
);
> +                
> +                return scm;
> +            }
> +        };
> +        
> +        assertEquals( "/root-project", ReleaseUtil.getRootProjectPath( project ) );
> +    }
> +    
> +    public void testGetRootProjectPathFlatStructureWithSegmentsAndSCMDelimiters()
> +        throws Exception
> +    {   
> +        MavenProject project = new MavenProject()
> +        {
> +            public List getModules()
> +            {
> +                List modules = new ArrayList();
> +                modules.add( "../core" );
> +                modules.add( "../webapp" );
> +                modules.add( "../commons" );
> +                
> +                return modules;
> +            }
> +            
> +            public File getBasedir()
> +            {
> +                return new File( "/dev/root-project" );
> +            }
> +            
> +            public Scm getScm()
> +            {
> +                Scm scm = new Scm();
> +                scm.setConnection( "scm:cvs:pserver:username@host:port:repository:dev/root-project"
);
> +                
> +                return scm;
> +            }
> +        };
> +        
> +        assertEquals( "/dev/root-project", ReleaseUtil.getRootProjectPath( project )
);
> +    }
> +
>      public void testGetRootProjectPathRegularMultiModuleStructure()
>          throws Exception
>      {   
> Index: maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java
> ===================================================================
> --- maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java
(revision 778269)
> +++ maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java
(working copy)
> @@ -40,6 +40,13 @@
>  {
>  
>      /**
> +     * Commits to do are atomic or by project.
> +     * 
> +     * @parameter expression="${commitByProject}" default-value="false"
> +     */
> +    private boolean commitByProject;
> +    
> +    /**
>       * {@inheritDoc}
>       */
>      public void execute()
> @@ -48,6 +55,8 @@
>          super.execute();
>  
>          ReleaseDescriptor config = createReleaseDescriptor();
> +        // If a preparation can be committed by project, also a rollback should be committed
by project
> +        config.setCommitByProject( commitByProject );
>  
>          try
>          {
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Mime
View raw message