From: <pb...@fe...> - 2012-12-16 19:05:21
|
Author: pboy Date: 2012-12-16 19:05:12 +0000 (Sun, 16 Dec 2012) New Revision: 2384 Added: releases/2.0.0/ccm-cms/src/com/arsdigita/cms/contenttypes/upgrades/Upgrade664to665.java Modified: releases/2.0.0/ccm-core/src/com/arsdigita/packaging/Upgrade.java Log: Fixed upgrade scripts (backport r2370) (on behalf of JensP). Added: releases/2.0.0/ccm-cms/src/com/arsdigita/cms/contenttypes/upgrades/Upgrade664to665.java =================================================================== --- releases/2.0.0/ccm-cms/src/com/arsdigita/cms/contenttypes/upgrades/Upgrade664to665.java (rev 0) +++ releases/2.0.0/ccm-cms/src/com/arsdigita/cms/contenttypes/upgrades/Upgrade664to665.java 2012-12-16 19:05:12 UTC (rev 2384) @@ -0,0 +1,40 @@ +package com.arsdigita.cms.contenttypes.upgrades; + +import com.arsdigita.cms.contenttypes.XMLContentTypeHandler; +import com.arsdigita.util.cmd.Program; +import com.arsdigita.xml.XML; +import org.apache.commons.cli.CommandLine; + +/** + * + * @author Jens Pelzetter <je...@jp...> + * @version $Id$ + */ +public class Upgrade664to665 extends Program { + + public Upgrade664to665() { + super("Upgrade664to665", "1.0.0", "", true, true); + } + + @Override + protected void doRun(CommandLine cmdLine) { + new CreateContactBundles().doUpgrade(); + new CreateOrgaUnitBundles().doUpgrade(); + new CreatePersonBundles().doUpgrade(); + new GenericContactGenericPersonAssocUpgrade().doUpgrade(); + new GenericOrgaUnitGenericContactAssocUpgrade().doUpgrade(); + new GenericOrgaUnitGenericOrgaUnitAssocUpgrade().doUpgrade(); + new GenericOrgaUnitGenericPersonAssocUpgrade().doUpgrade(); + + //Reload authoring steps + XMLContentTypeHandler handler = new XMLContentTypeHandler(); + XML.parseResource("/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericContact.xml", handler); + XML.parseResource("/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.xml", handler); + XML.parseResource("/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericPerson.xml", handler); + } + + public static void main(final String[] args) { + new Upgrade664to665().run(args); + } + +} Modified: releases/2.0.0/ccm-core/src/com/arsdigita/packaging/Upgrade.java =================================================================== --- releases/2.0.0/ccm-core/src/com/arsdigita/packaging/Upgrade.java 2012-12-16 18:29:36 UTC (rev 2383) +++ releases/2.0.0/ccm-core/src/com/arsdigita/packaging/Upgrade.java 2012-12-16 19:05:12 UTC (rev 2384) @@ -55,33 +55,18 @@ private static final Logger logger = Logger.getLogger(Upgrade.class); private static final Options s_options = getOptions(); - private String m_from; private String m_to; private final List m_scripts; static { logger.debug("Static initalizer starting..."); - s_options.addOption - (OptionBuilder - .isRequired() - .hasArg() - .withLongOpt("from-version") - .withDescription("Upgrade from version VERSION") - .create()); - s_options.addOption - (OptionBuilder - .isRequired() - .hasArg() - .withLongOpt("to-version") - .withDescription("Upgrade to version VERSION") - .create()); - s_options.addOption - (OptionBuilder - .hasArg() - .withLongOpt("parameters") - .withDescription("Parameters to pass to upgrade scripts") - .create()); + s_options.addOption(OptionBuilder.isRequired().hasArg().withLongOpt("from-version").withDescription( + "Upgrade from version VERSION").create()); + s_options.addOption(OptionBuilder.isRequired().hasArg().withLongOpt("to-version").withDescription( + "Upgrade to version VERSION").create()); + s_options.addOption(OptionBuilder.hasArg().withLongOpt("parameters").withDescription( + "Parameters to pass to upgrade scripts").create()); logger.debug("Static initalizer finished."); } @@ -147,8 +132,7 @@ final String spec = key + ".upgrade"; - final InputStream in = Thread.currentThread().getContextClassLoader - ().getResourceAsStream(spec); + final InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(spec); if (in == null) { System.err.println("Cannot find " + spec); @@ -158,20 +142,19 @@ XML.parse(in, new Parser()); if (m_scripts.isEmpty()) { - System.err.println("No appropriate upgrades found; make sure " + - "that your 'to' and 'from' versions match " + - "the intended upgrade exactly"); + System.err.println("No appropriate upgrades found; make sure " + "that your 'to' and 'from' versions match " + + "the intended upgrade exactly"); return false; } else { - System.out.println("Number of scripts: " + m_scripts.size() ); + System.out.println("Number of scripts: " + m_scripts.size()); } //Iterator iter = m_scripts.iterator(); //while (iter.hasNext()) { - for(int k = 0; k < m_scripts.size(); k++) { - + for (int k = 0; k < m_scripts.size(); k++) { + System.out.printf("Running script %d/%d\n", (k + 1), m_scripts.size()); - final String[] parts = (String[]) m_scripts.get(k); //(String[]) iter.next(); + final String[] parts = (String[]) m_scripts.get(k); //(String[]) iter.next(); final String classname = parts[0]; final String sql = parts[1]; @@ -185,7 +168,7 @@ try { method = clacc.getMethod("main", - new Class[] {String[].class}); + new Class[]{String[].class}); } catch (NoSuchMethodException nsme) { throw new UncheckedWrapperException(nsme); } catch (SecurityException se) { @@ -196,29 +179,27 @@ LinkedList ll = new LinkedList(); if (params != null) { for (int i = 0; i < params.length; i++) { - String[] split = StringUtils.split(params[i],','); + String[] split = StringUtils.split(params[i], ','); for (int j = 0; j < split.length; j++) { ll.add(split[j]); } } } - try { - method.invoke(null, new Object[] {ll.toArray(new String[] {})}); - } catch (IllegalAccessException iae) { + try { + method.invoke(null, new Object[]{ll.toArray(new String[]{})}); + } catch (IllegalAccessException iae) { throw new UncheckedWrapperException(iae); - } catch (InvocationTargetException ite) { + } catch (InvocationTargetException ite) { throw new UncheckedWrapperException(ite); } - + } else if (sql != null) { final SchemaLoader loader = new SchemaLoader(sql); - System.out.println("Running SQL upgrade " + loader + ", " + - "loaded from the classpath"); + System.out.println("Running SQL upgrade " + loader + ", " + "loaded from the classpath"); - final Connection conn = Connections.acquire - (RuntimeConfig.getConfig().getJDBCURL()); + final Connection conn = Connections.acquire(RuntimeConfig.getConfig().getJDBCURL()); loader.run(conn); @@ -229,16 +210,18 @@ } } else { throw new IllegalStateException(); - } + } + } return true; } /** - * + * */ private class Parser extends DefaultHandler { + private String m_version; @Override @@ -266,14 +249,12 @@ final String sql = attrs.getValue(uri, "sql"); if (classname == null && sql == null - || classname != null && sql != null) { - throw new IllegalArgumentException - ("The script element must have a 'class' " + - "argument or a 'sql' argument; it may not " + - "have both"); + || classname != null && sql != null) { + throw new IllegalArgumentException("The script element must have a 'class' " + + "argument or a 'sql' argument; it may not " + "have both"); } - m_scripts.add(new String[] {classname, sql}); + m_scripts.add(new String[]{classname, sql}); } } } @@ -286,5 +267,6 @@ m_version = null; } } + } } |