Commit 60c3a848 authored by Jonathan Doklovic's avatar Jonathan Doklovic

feature start extension working

parent 993599a7
package com.atlassian.maven.jgitflow.api;
public interface DeployBranchExtension extends MavenJGitFlowExtension
{
}
......@@ -3,7 +3,7 @@ package com.atlassian.maven.jgitflow.api;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
public interface StartProductionBranchExtension extends MavenJGitFlowExtension
public interface FinishBranchExtension extends MavenJGitFlowExtension
{
/**
* Called when the version changes on "topic" branches.
......
......@@ -3,7 +3,7 @@ package com.atlassian.maven.jgitflow.api;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
public interface FinishProductionBranchExtension extends MavenJGitFlowExtension
public interface FinishProductionBranchExtension extends FinishBranchExtension
{
/**
* Called when the version changes on the master branch.
......@@ -15,16 +15,4 @@ public interface FinishProductionBranchExtension extends MavenJGitFlowExtension
* @throws com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException
*/
void onMasterBranchVersionChange(String newVersion, String oldVersion, JGitFlowInfo flow) throws MavenJGitFlowExtensionException;
/**
* Called when the version changes on "topic" branches.
* These are release/hotfix/feature branches.
* <p></p>
* This method is called AFTER the poms have been committed.
* Any changes made to the project within this method will need to also be committed within this method.
* A helper class is provided to make this easier. {@link com.atlassian.maven.jgitflow.api.util.JGitFlowCommitHelper}
*
* @throws com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException
*/
void onTopicBranchVersionChange(String newVersion, String oldVersion, JGitFlowInfo flow) throws MavenJGitFlowExtensionException;
}
package com.atlassian.maven.jgitflow.api;
public interface MavenFeatureDeployExtension
{
}
package com.atlassian.maven.jgitflow.api;
public interface MavenFeatureFinishExtension extends FinishBranchExtension
{
}
package com.atlassian.maven.jgitflow.api;
public interface MavenFeatureStartExtension extends StartBranchExtension
{
}
package com.atlassian.maven.jgitflow.api;
public interface MavenHotfixStartExtension extends StartProductionBranchExtension
public interface MavenHotfixStartExtension extends StartBranchExtension
{
}
......@@ -3,7 +3,7 @@ package com.atlassian.maven.jgitflow.api;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
public interface MavenReleaseStartExtension extends StartProductionBranchExtension
public interface MavenReleaseStartExtension extends StartBranchExtension
{
/**
* Called when the version changes on the develop branch.
......
package com.atlassian.maven.jgitflow.api;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
public interface StartBranchExtension extends MavenJGitFlowExtension
{
/**
* Called when the version changes on "topic" branches.
* These are release/hotfix/feature branches.
* <p></p>
* This method is called AFTER the poms have been committed.
* Any changes made to the project within this method will need to also be committed within this method.
* A helper class is provided to make this easier. {@link com.atlassian.maven.jgitflow.api.util.JGitFlowCommitHelper}
*
* @throws com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException
*/
void onTopicBranchVersionChange(String newVersion, String oldVersion, JGitFlowInfo flow) throws MavenJGitFlowExtensionException;
}
package com.atlassian.maven.plugins.jgitflow;
import com.atlassian.jgitflow.core.InitContext;
import com.atlassian.maven.jgitflow.api.MavenHotfixFinishExtension;
import com.atlassian.maven.jgitflow.api.MavenHotfixStartExtension;
import com.atlassian.maven.jgitflow.api.MavenReleaseFinishExtension;
import com.atlassian.maven.jgitflow.api.MavenReleaseStartExtension;
import com.atlassian.maven.jgitflow.api.*;
import com.google.common.base.Strings;
import java.io.File;
......@@ -60,6 +57,9 @@ public class ReleaseContext
private MavenReleaseFinishExtension releaseFinishExtension;
private MavenHotfixStartExtension hotfixStartExtension;
private MavenHotfixFinishExtension hotfixFinishExtension;
private MavenFeatureStartExtension featureStartExtension;
private MavenFeatureFinishExtension featureFinishExtension;
private MavenFeatureDeployExtension featureDeployExtension;
private String eol;
private boolean releaseSnapshots;
......@@ -655,4 +655,37 @@ public class ReleaseContext
this.hotfixFinishExtension = hotfixFinishExtension;
return this;
}
public MavenFeatureStartExtension getFeatureStartExtension()
{
return featureStartExtension;
}
public ReleaseContext setFeatureStartExtension(MavenFeatureStartExtension featureStartExtension)
{
this.featureStartExtension = featureStartExtension;
return this;
}
public MavenFeatureFinishExtension getFeatureFinishExtension()
{
return featureFinishExtension;
}
public ReleaseContext setFeatureFinishExtension(MavenFeatureFinishExtension featureFinishExtension)
{
this.featureFinishExtension = featureFinishExtension;
return this;
}
public MavenFeatureDeployExtension getFeatureDeployExtension()
{
return featureDeployExtension;
}
public ReleaseContext setFeatureDeployExtension(MavenFeatureDeployExtension featureDeployExtension)
{
this.featureDeployExtension = featureDeployExtension;
return this;
}
}
package com.atlassian.maven.plugins.jgitflow.extension;
import com.atlassian.jgitflow.core.extension.impl.EmptyFeatureStartExtension;
import com.atlassian.jgitflow.core.extension.FeatureStartExtension;
import com.atlassian.jgitflow.core.extension.impl.EmptyBranchCreatingExtension;
import com.atlassian.maven.jgitflow.api.MavenJGitFlowExtension;
import com.atlassian.maven.plugins.jgitflow.extension.command.CacheVersionsCommand;
import com.atlassian.maven.plugins.jgitflow.extension.command.UpdateFeaturePomsWithSnapshotsCommand;
import com.atlassian.maven.plugins.jgitflow.extension.command.external.StartBranchExternalExecutor;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@Component(role = FeatureStartPluginExtension.class)
public class FeatureStartPluginExtension extends EmptyFeatureStartExtension implements InitializingExtension
public class FeatureStartPluginExtension extends EmptyBranchCreatingExtension implements ExternalInitializingExtension, FeatureStartExtension
{
@Requirement
private UpdateFeaturePomsWithSnapshotsCommand updateFeaturePomsWithSnapshotsCommand;
@Requirement
protected CacheVersionsCommand cacheVersionsCommand;
@Requirement
protected StartBranchExternalExecutor startBranchExecutor;
@Override
public void init()
public void init(MavenJGitFlowExtension externalExtension)
{
addAfterCreateBranchCommands(updateFeaturePomsWithSnapshotsCommand);
startBranchExecutor.init(externalExtension);
addAfterCreateBranchCommands(
cacheVersionsCommand
, updateFeaturePomsWithSnapshotsCommand
, startBranchExecutor
);
}
}
......@@ -4,7 +4,7 @@ import com.atlassian.jgitflow.core.extension.impl.EmptyBranchCreatingExtension;
import com.atlassian.maven.jgitflow.api.MavenJGitFlowExtension;
import com.atlassian.maven.plugins.jgitflow.extension.command.CacheVersionsCommand;
import com.atlassian.maven.plugins.jgitflow.extension.command.UpdatePomsWithSnapshotsCommand;
import com.atlassian.maven.plugins.jgitflow.extension.command.external.StartProductionExternalExecutor;
import com.atlassian.maven.plugins.jgitflow.extension.command.external.StartBranchExternalExecutor;
import org.codehaus.plexus.component.annotations.Requirement;
......@@ -17,7 +17,7 @@ public abstract class ProductionBranchCreatingPluginExtension extends EmptyBranc
protected CacheVersionsCommand cacheVersionsCommand;
@Requirement
protected StartProductionExternalExecutor productionExecutor;
protected StartBranchExternalExecutor productionExecutor;
@Override
public void init(MavenJGitFlowExtension externalExtension)
......
......@@ -3,36 +3,26 @@ package com.atlassian.maven.plugins.jgitflow.extension.command.external;
import com.atlassian.jgitflow.core.BranchType;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.MavenJGitFlowExtension;
import com.atlassian.maven.jgitflow.api.StartProductionBranchExtension;
import com.atlassian.maven.jgitflow.api.StartBranchExtension;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
import org.codehaus.plexus.component.annotations.Component;
@Component(role = StartProductionExternalExecutor.class)
public class StartProductionExternalExecutor extends CachedVersionExternalExecutor
@Component(role = StartBranchExternalExecutor.class)
public class StartBranchExternalExecutor extends CachedVersionExternalExecutor
{
@Override
public void execute(MavenJGitFlowExtension extension, String newVersion, String oldVersion, JGitFlowInfo flow) throws MavenJGitFlowExtensionException
{
if (null == extension || !StartProductionBranchExtension.class.isAssignableFrom(extension.getClass()))
if (null == extension || !StartBranchExtension.class.isAssignableFrom(extension.getClass()))
{
return;
}
StartProductionBranchExtension startExtension = (StartProductionBranchExtension) extension;
StartBranchExtension startExtension = (StartBranchExtension) extension;
try
{
BranchType type = branchHelper.getCurrentBranchType();
switch (type)
{
case HOTFIX:
startExtension.onTopicBranchVersionChange(newVersion, oldVersion, flow);
break;
case RELEASE:
startExtension.onTopicBranchVersionChange(newVersion, oldVersion, flow);
break;
}
startExtension.onTopicBranchVersionChange(newVersion, oldVersion, flow);
}
catch (Exception e)
{
......
......@@ -63,7 +63,7 @@ public class DefaultFlowFeatureManager extends AbstractFlowReleaseManager
flow = jGitFlowProvider.gitFlow();
startExtension.init();
startExtension.init(ctx.getFeatureStartExtension());
flow.featureStart(featureName)
.setAllowUntracked(ctx.isAllowUntracked())
......
package com.atlassian.maven.plugins.jgitflow.mojo;
import com.atlassian.maven.jgitflow.api.MavenFeatureDeployExtension;
import com.atlassian.maven.jgitflow.api.MavenReleaseStartExtension;
import com.atlassian.maven.plugins.jgitflow.ReleaseContext;
import com.atlassian.maven.plugins.jgitflow.exception.MavenJGitFlowException;
import com.atlassian.maven.plugins.jgitflow.manager.FlowReleaseManager;
......@@ -38,9 +40,24 @@ public class FeatureDeployMojo extends AbstractJGitFlowMojo
@Component(hint = "feature")
FlowReleaseManager releaseManager;
/**
* A FQCN of a compatible feature deploy extension.
* Extensions are used to run custom code at various points in the jgitflow lifecycle.
*
* More documentation on using extensions will be available in the future
*/
@Parameter(defaultValue = "")
private String featureDeployExtension = "";
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassloader(getClasspath()));
MavenFeatureDeployExtension extensionObject = (MavenFeatureDeployExtension) getExtensionInstance(featureDeployExtension);
ReleaseContext ctx = new ReleaseContext(getBasedir());
ctx.setInteractive(getSettings().isInteractiveMode())
.setNoDeploy(false)
......@@ -65,5 +82,9 @@ public class FeatureDeployMojo extends AbstractJGitFlowMojo
{
throw new MojoExecutionException("Error finishing feature: " + e.getMessage(), e);
}
finally
{
Thread.currentThread().setContextClassLoader(oldClassloader);
}
}
}
package com.atlassian.maven.plugins.jgitflow.mojo;
import com.atlassian.maven.jgitflow.api.MavenFeatureFinishExtension;
import com.atlassian.maven.jgitflow.api.MavenReleaseStartExtension;
import com.atlassian.maven.plugins.jgitflow.ReleaseContext;
import com.atlassian.maven.plugins.jgitflow.exception.MavenJGitFlowException;
import com.atlassian.maven.plugins.jgitflow.manager.FlowReleaseManager;
......@@ -82,9 +84,24 @@ public class FeatureFinishMojo extends AbstractJGitFlowMojo
@Component(hint = "feature")
FlowReleaseManager releaseManager;
/**
* A FQCN of a compatible feature finish extension.
* Extensions are used to run custom code at various points in the jgitflow lifecycle.
*
* More documentation on using extensions will be available in the future
*/
@Parameter(defaultValue = "")
private String featureFinishExtension = "";
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassloader(getClasspath()));
MavenFeatureFinishExtension extensionObject = (MavenFeatureFinishExtension) getExtensionInstance(featureFinishExtension);
ReleaseContext ctx = new ReleaseContext(getBasedir());
ctx.setInteractive(getSettings().isInteractiveMode())
.setNoDeploy(true)
......@@ -122,5 +139,9 @@ public class FeatureFinishMojo extends AbstractJGitFlowMojo
{
throw new MojoExecutionException("Error finishing feature: " + e.getMessage(), e);
}
finally
{
Thread.currentThread().setContextClassLoader(oldClassloader);
}
}
}
package com.atlassian.maven.plugins.jgitflow.mojo;
import com.atlassian.maven.jgitflow.api.MavenFeatureStartExtension;
import com.atlassian.maven.jgitflow.api.MavenReleaseStartExtension;
import com.atlassian.maven.plugins.jgitflow.ReleaseContext;
import com.atlassian.maven.plugins.jgitflow.exception.MavenJGitFlowException;
import com.atlassian.maven.plugins.jgitflow.manager.FlowReleaseManager;
......@@ -44,9 +46,24 @@ public class FeatureStartMojo extends AbstractJGitFlowMojo
@Component(hint = "feature")
FlowReleaseManager releaseManager;
/**
* A FQCN of a compatible feature start extension.
* Extensions are used to run custom code at various points in the jgitflow lifecycle.
*
* More documentation on using extensions will be available in the future
*/
@Parameter(defaultValue = "")
private String featureStartExtension = "";
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassloader(getClasspath()));
MavenFeatureStartExtension extensionObject = (MavenFeatureStartExtension) getExtensionInstance(featureStartExtension);
ReleaseContext ctx = new ReleaseContext(getBasedir());
ctx.setInteractive(getSettings().isInteractiveMode())
.setDefaultFeatureName(featureName)
......@@ -66,7 +83,8 @@ public class FeatureStartMojo extends AbstractJGitFlowMojo
.setUseReleaseProfile(false)
.setUsername(username)
.setPassword(password)
.setEol(eol)
.setFeatureStartExtension(extensionObject)
.setEol(eol)
.setFlowInitContext(getFlowInitContext().getJGitFlowContext());
try
......@@ -77,5 +95,9 @@ public class FeatureStartMojo extends AbstractJGitFlowMojo
{
throw new MojoExecutionException("Error starting feature: " + e.getMessage(), e);
}
finally
{
Thread.currentThread().setContextClassLoader(oldClassloader);
}
}
}
package ut.com.atlassian.maven.plugins.jgitflow;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.jgitflow.core.extension.BranchCreatingExtension;
import com.atlassian.maven.jgitflow.api.StartBranchExtension;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
public class NoopBranchCreateExtension implements StartBranchExtension
{
@Override
public void onTopicBranchVersionChange(String newVersion, String oldVersion, JGitFlowInfo flow) throws MavenJGitFlowExtensionException {
}
}
package ut.com.atlassian.maven.plugins.jgitflow;
import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.MavenFeatureStartExtension;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
public class TestFeatureStartExtension extends NoopBranchCreateExtension implements MavenFeatureStartExtension
{
private String oldVersion;
private String newVersion;
@Override
public void onTopicBranchVersionChange(String newVersion, String oldVersion, JGitFlowInfo flow) throws MavenJGitFlowExtensionException
{
this.oldVersion = oldVersion;
this.newVersion = newVersion;
}
public String getOldVersion() {
return oldVersion;
}
public String getNewVersion() {
return newVersion;
}
}
......@@ -4,7 +4,7 @@ import com.atlassian.jgitflow.core.JGitFlowInfo;
import com.atlassian.maven.jgitflow.api.exception.MavenJGitFlowExtensionException;
import com.atlassian.maven.jgitflow.api.impl.NoopMavenReleaseFinishExtension;
public class TestFinishExtension extends NoopMavenReleaseFinishExtension
public class TestReleaseFinishExtension extends NoopMavenReleaseFinishExtension
{
private String oldVersion;
private String newVersion;
......
......@@ -15,7 +15,10 @@ import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.eclipse.jgit.api.Git;
import org.junit.Test;
import ut.com.atlassian.maven.plugins.jgitflow.TestFeatureStartExtension;
import ut.com.atlassian.maven.plugins.jgitflow.TestReleaseFinishExtension;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
......@@ -101,5 +104,35 @@ public class FeatureManagerStartFeatureTest extends AbstractFlowManagerTest
String pom = FileUtils.readFileToString(projects.get(0).getFile());
assertTrue(pom.contains("1.0-" + UNDERSCORED_FEATURE_NAME + "-SNAPSHOT"));
}
@Test
public void startFeatureWithExternalExtension() throws Exception
{
String projectSubdir = "basic-pom";
List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectSubdir);
File projectRoot = projects.get(0).getBasedir();
JGitFlow flow = JGitFlow.getOrInit(projectRoot);
flow.git().checkout().setName(flow.getDevelopBranchName()).call();
assertOnDevelop(flow);
initialCommitAll(flow);
FlowReleaseManager relman = getFeatureManager();
TestFeatureStartExtension extension = new TestFeatureStartExtension();
ReleaseContext ctx = new ReleaseContext(projectRoot);
ctx.setInteractive(false).setDefaultFeatureName(FEATURE_NAME).setFeatureStartExtension(extension).setEnableFeatureVersions(true);
MavenSession session = new MavenSession(getContainer(), new Settings(), localRepository, null, null, null, projectRoot.getAbsolutePath(), new Properties(), new Properties(), null);
relman.start(ctx, projects, session);
assertEquals("old version incorrect", "1.0-SNAPSHOT", extension.getOldVersion());
assertEquals("new version incorrect", "1.0-" + UNDERSCORED_FEATURE_NAME + "-SNAPSHOT", extension.getNewVersion());
}
}
......@@ -21,7 +21,7 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Ref;
import org.junit.Test;
import ut.com.atlassian.maven.plugins.jgitflow.TestFinishExtension;
import ut.com.atlassian.maven.plugins.jgitflow.TestReleaseFinishExtension;
import ut.com.atlassian.maven.plugins.jgitflow.testutils.RepoUtil;
import static org.junit.Assert.*;
......@@ -175,7 +175,7 @@ public class ReleaseManagerFinishReleaseTest extends AbstractFlowManagerTest
MavenSession session = new MavenSession(getContainer(), new Settings(), localRepository, null, null, null, projectRoot.getAbsolutePath(), new Properties(), new Properties(), null);
TestFinishExtension extension = new TestFinishExtension();
TestReleaseFinishExtension extension = new TestReleaseFinishExtension();
ReleaseContext ctx = new ReleaseContext(projectRoot);
ctx.setInteractive(false)
......@@ -203,7 +203,7 @@ public class ReleaseManagerFinishReleaseTest extends AbstractFlowManagerTest
MavenSession session = new MavenSession(getContainer(), new Settings(), localRepository, null, null, null, projectRoot.getAbsolutePath(), new Properties(), new Properties(), null);
TestFinishExtension extension = new TestFinishExtension();
TestReleaseFinishExtension extension = new TestReleaseFinishExtension();
ReleaseContext ctx = new ReleaseContext(projectRoot);
ctx.setInteractive(false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment