Skip to content

Instantly share code, notes, and snippets.

@mkorman
Created February 29, 2016 16:37
Show Gist options
  • Save mkorman/d81fae873c08b78761f2 to your computer and use it in GitHub Desktop.
Save mkorman/d81fae873c08b78761f2 to your computer and use it in GitHub Desktop.
public abstract class InstallHandlerBase implements InstallHandler
{
public abstract Version GetLastPackageVersionWithoutFeature ();
public void onInstall(InstallContext context)
{
if (isFreshInstall (context))
{
OnFreshInstall (context);
}
else if (previousVersionContainsFeature(context))
{
OnUpgradeFromRecentPackage (context);
}
else
{
OnUpgradeFromOldPackage (context);
}
}
protected Boolean isFreshInstall (InstallContext context)
{
return context.previousVersion() == null;
}
protected boolean previousVersionContainsFeature(InstallContext context)
{
Version previousVersion = context.PreviousVersion();
return previousVersion.compareTo (GetLastPackageVersionWithoutFeature()) > 0;
}
public virtual void OnUpgradeFromOldPackage (InstallContext context) {}
public virtual void OnUpgradeFromRecentPackage (InstallContext context) {}
public virtual void OnFreshInstall (InstallContext context) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment