From: <fg...@us...> - 2008-04-28 22:17:51
|
Revision: 798 http://openutils.svn.sourceforge.net/openutils/?rev=798&view=rev Author: fgiust Date: 2008-04-28 15:17:55 -0700 (Mon, 28 Apr 2008) Log Message: ----------- changes for 3.5.1 Modified Paths: -------------- trunk/openutils-mgnltasks/src/site/changes/changes.xml Added Paths: ----------- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java 2008-04-28 22:17:55 UTC (rev 798) @@ -0,0 +1,68 @@ +package it.openutils.mgnltasks; + +import info.magnolia.module.DefaultModuleVersionHandler; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.Delta; +import info.magnolia.module.delta.DeltaBuilder; +import info.magnolia.module.model.Version; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.ObjectUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * A base module version handler that re-bootstrap its configuration each time the version number changes. Can be used + * as is or subclassed (usually overriding getStartupTasks() for configuration tweacks). + * @author fgiust + * @version $Id: $ + */ +public class SimpleModuleVersionHandler extends DefaultModuleVersionHandler +{ + + /** + * Logger. + */ + protected Logger log = LoggerFactory.getLogger(getClass()); + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + public List<Delta> getDeltas(InstallContext ctx, Version from) + { + if (from == null) + { + log.info("Actual version not set"); + return super.getDeltas(ctx, from); + } + + Version to = ctx.getCurrentModuleDefinition().getVersionDefinition(); + + List<Delta> deltas = new ArrayList<Delta>(); + + if (!to.isEquivalent(from) + || "${project.version}".equals(ObjectUtils.toString(from)) + || "SNAPSHOT".equals(from.getClassifier())) + { + log.info("Updating from version {}", from); + + Delta delta = DeltaBuilder.update(to, "Update to current version"); + delta.getTasks().add(new ModuleConfigBootstrapTask(ctx.getCurrentModuleDefinition().getName())); + delta.getTasks().add(new UpdateModuleVersionTask()); + + deltas.add(delta); + } + else + { + log.info("Version {} already installed, no update tasks to run", from); + } + + return deltas; + } + +} Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/SimpleModuleVersionHandler.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java =================================================================== --- trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java (rev 0) +++ trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java 2008-04-28 22:17:55 UTC (rev 798) @@ -0,0 +1,63 @@ +/** + * Copyright Openmind http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package it.openutils.mgnltasks; + +import info.magnolia.cms.core.Content; +import info.magnolia.cms.core.HierarchyManager; +import info.magnolia.cms.core.ItemType; +import info.magnolia.cms.core.NodeData; +import info.magnolia.cms.util.NodeDataUtil; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.AbstractRepositoryTask; +import info.magnolia.module.delta.TaskExecutionException; + +import javax.jcr.RepositoryException; + + +/** + * A task that updates the current version of a module stored in the config repository. + * @author fgiust + * @version $Id: $ + */ +public class UpdateModuleVersionTask extends AbstractRepositoryTask +{ + + public UpdateModuleVersionTask() + { + super("Version number", "Sets installed module version number"); + } + + /** + * {@inheritDoc} + */ + @Override + protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException + { + // make sure we have the /modules node + if (!ctx.hasModulesNode()) + { + final HierarchyManager hm = ctx.getConfigHierarchyManager(); + hm.createContent("/", "modules", ItemType.CONTENT.getSystemName()); + } + + final Content moduleNode = ctx.getOrCreateCurrentModuleNode(); + final NodeData nodeData = NodeDataUtil.getOrCreate(moduleNode, "version"); + nodeData.setValue(ctx.getCurrentModuleDefinition().getVersionDefinition().toString()); + } + +} \ No newline at end of file Property changes on: trunk/openutils-mgnltasks/src/main/java/it/openutils/mgnltasks/UpdateModuleVersionTask.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Modified: trunk/openutils-mgnltasks/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-04-27 21:45:51 UTC (rev 797) +++ trunk/openutils-mgnltasks/src/site/changes/changes.xml 2008-04-28 22:17:55 UTC (rev 798) @@ -8,6 +8,10 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> + <release version="3.5.1" date="2008-04-28" description="3.5.1"> + <action type="add" dev="fgiust">Added UpdateModuleVersionTask.</action> + <action type="add" dev="fgiust">Added SimpleModuleVersionHandler.</action> + </release> <release version="3.5" date="2008-04-27" description="first release"> <action type="add" dev="fgiust">First public release. The version is labeled "3.5" in order to make clear which version of magnolia is required.</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |