Skip to content

Commit

Permalink
- added ScmCommentPrefix configuration
Browse files Browse the repository at this point in the history
- added rollback feature in release-manager
- added release:rollback mojo
- also updated the site docs/apt

git-svn-id: https://svn.apache.org/repos/asf/maven/release/trunk/maven-release-manager@492945 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Edwin L. Punzalan committed Jan 5, 2007
1 parent c705c91 commit de9aad0
Show file tree
Hide file tree
Showing 33 changed files with 1,348 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -64,6 +65,11 @@ public class DefaultReleaseManager
//todo implement
private List performPhases;

/**
* The phases of release to run to rollback changes
*/
private List rollbackPhases;

/**
* The available phases.
*/
Expand Down Expand Up @@ -145,14 +151,7 @@ private void prepare( ReleaseDescriptor releaseDescriptor, Settings settings, Li
ReleaseDescriptor config;
if ( resume )
{
try
{
config = configStore.read( releaseDescriptor );
}
catch ( ReleaseDescriptorStoreException e )
{
throw new ReleaseExecutionException( "Error reading stored configuration: " + e.getMessage(), e );
}
config = loadReleaseDescriptor( releaseDescriptor, listener );
}
else
{
Expand Down Expand Up @@ -231,6 +230,26 @@ else if ( index >= 0 )
updateListener( listener, "prepare", GOAL_END );
}

public void rollback( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException
{
releaseDescriptor = loadReleaseDescriptor( releaseDescriptor, null );

for( Iterator phases = rollbackPhases.iterator(); phases.hasNext(); )
{
String name = (String) phases.next();

ReleasePhase phase = (ReleasePhase) releasePhases.get( name );

if ( phase == null )
{
throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" );
}

phase.execute( releaseDescriptor, settings, reactorProjects );
}
}

public void perform( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects,
File checkoutDirectory, String goals, boolean useReleaseProfile )
throws ReleaseExecutionException, ReleaseFailureException
Expand Down Expand Up @@ -289,17 +308,7 @@ private void perform( ReleaseDescriptor releaseDescriptor, Settings settings, Li

updateListener( listener, "verify-release-configuration", PHASE_START );

ReleaseDescriptor config;
try
{
config = configStore.read( releaseDescriptor );
}
catch ( ReleaseDescriptorStoreException e )
{
updateListener( listener, e.getMessage(), ERROR );

throw new ReleaseExecutionException( "Error reading stored configuration: " + e.getMessage(), e );
}
ReleaseDescriptor config = loadReleaseDescriptor( releaseDescriptor, listener );

updateListener( listener, "verify-release-configuration", PHASE_END );
updateListener( listener, "verify-completed-prepare-phases", PHASE_START );
Expand Down Expand Up @@ -425,6 +434,21 @@ private void perform( ReleaseDescriptor releaseDescriptor, Settings settings, Li
updateListener( listener, "perform", GOAL_END );
}

private ReleaseDescriptor loadReleaseDescriptor( ReleaseDescriptor releaseDescriptor, ReleaseManagerListener listener )
throws ReleaseExecutionException
{
try
{
return configStore.read( releaseDescriptor );
}
catch ( ReleaseDescriptorStoreException e )
{
updateListener( listener, e.getMessage(), ERROR );

throw new ReleaseExecutionException( "Error reading stored configuration: " + e.getMessage(), e );
}
}

public void clean( ReleaseDescriptor releaseDescriptor, List reactorProjects )
{
getLogger().info( "Cleaning up after release..." );
Expand Down Expand Up @@ -490,8 +514,12 @@ else if ( "perform".equals( name ) )
{
phases.addAll( this.performPhases );
}
else if ( "rollback".equals( name ) )
{
phases.addAll( this.rollbackPhases );
}

return phases;
return Collections.unmodifiableList( phases );
}

private void logInfo( ReleaseResult result, String message )
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/apache/maven/shared/release/ReleaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void prepare( ReleaseDescriptor releaseDescriptor, Settings settings, List react
*
* @param releaseDescriptor the configuration to use for release
* @param settings the settings.xml configuration
* @param reactorProjects the reactor projects
* @param checkoutDirectory the location to checkout to and build from
* @param goals the goals to execute
* @param useReleaseProfile whether to use the release profile from the super POM or not
Expand All @@ -87,6 +88,18 @@ void perform( ReleaseDescriptor releaseDescriptor, Settings settings, List react
*/
void clean( ReleaseDescriptor releaseDescriptor, List reactorProjects );

/**
* Rollback changes made by the previous release
*
* @param releaseDescriptor the configuration to use for release
* @param settings the settings.xml configuration
* @param reactorProjects the reactor projects
* @throws ReleaseExecutionException if there is a problem during release rollback
* @throws ReleaseFailureException if there is a problem during release rollback
*/
void rollback( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException;

void prepare( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects, boolean resume,
boolean dryRun, ReleaseManagerListener listener )
throws ReleaseExecutionException, ReleaseFailureException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.apache.maven.shared.release.phase;

/*
* 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;

import java.io.File;

/**
* @author Edwin Punzalan
*/
public abstract class AbstractBackupPomsPhase
extends AbstractReleasePhase
{
private final String backupPrefix = ".releaseBackup";

protected File getPomBackup( MavenProject project )
{
File pomFile = project.getFile();

return new File( pomFile.getAbsolutePath() + backupPrefix );
}

protected void deletePomBackup( MavenProject project )
{
File pomBackup = getPomBackup( project );

if ( pomBackup.exists() )
{
pomBackup.delete();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.apache.maven.shared.release.phase;

/*
* 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.shared.release.ReleaseResult;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.settings.Settings;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;

import java.util.List;
import java.util.Iterator;
import java.io.IOException;

/**
* @author Edwin Punzalan
*/
public class CreateBackupPomsPhase
extends AbstractBackupPomsPhase
{
public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException
{
ReleaseResult result = new ReleaseResult();

//remove previous backups, if any
clean( reactorProjects );

for( Iterator projects = reactorProjects.iterator(); projects.hasNext(); )
{
MavenProject project = (MavenProject) projects.next();

createPomBackup( project );
}

result.setResultCode( ReleaseResult.SUCCESS );

return result;
}

public ReleaseResult clean( List reactorProjects )
{
ReleaseResult result = new ReleaseResult();

for( Iterator projects = reactorProjects.iterator(); projects.hasNext(); )
{
MavenProject project = (MavenProject) projects.next();

deletePomBackup( project );
}

result.setResultCode( ReleaseResult.SUCCESS );

return result;
}

public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException
{
return execute( releaseDescriptor, settings, reactorProjects );
}

private void createPomBackup( MavenProject project )
throws ReleaseExecutionException
{
//delete any existing backup first
deletePomBackup( project );

try
{
FileUtils.copyFile( project.getFile(), getPomBackup( project ) );
}
catch ( IOException e )
{
throw new ReleaseExecutionException( "Error creating backup POM: " + e.getMessage(), e );
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.apache.maven.shared.release.phase;

import org.apache.maven.shared.release.ReleaseResult;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.settings.Settings;

import java.util.List;

/*
* 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.
*/

/**
* @author Edwin Punzalan
*/
public class RemoveScmTagPhase
extends AbstractReleasePhase
{
public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException
{
ReleaseResult result = new ReleaseResult();

// TODO [!]: implement

result.setResultCode( ReleaseResult.SUCCESS );

return result;
}

public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException
{
return execute( releaseDescriptor, settings, reactorProjects );
}
}
Loading

0 comments on commit de9aad0

Please sign in to comment.