/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.test.escaping.framework;

import org.xwiki.test.integration.XWikiExecutor;

/**
 * Starts and stops exactly one XWiki instance. The methods {@link #start()} and {@link #stop()}
 * allow to call them multiple times, starting and stopping the server only on the first and
 * last call respectively.
 * 
 * @version $Id$
 * @since 2.5M1
 */
public final class SingleXWikiExecutor extends XWikiExecutor
{
    /** Singleton instance. */
    private static SingleXWikiExecutor executor = null;

    /** Call counter. */
    private static int counter = 0;

    /**
     * Create new SingleXWikiExecutor.
     */
    private SingleXWikiExecutor()
    {
        super(0);
    }

    /**
     * Get the executor instance.
     * 
     * @return XWiki server executor
     */
    public static synchronized SingleXWikiExecutor getExecutor()
    {
        if (SingleXWikiExecutor.executor == null) {
            SingleXWikiExecutor.executor = new SingleXWikiExecutor();
        }
        return SingleXWikiExecutor.executor;
    }

    /**
     * {@inheritDoc}
     * 
     * Starts the server on the first call, subsequent calls only increase the internal counter by one.
     */
    @Override
    public synchronized void start() throws Exception
    {
        if (counter == 0) {
            super.start();
        }
        counter++;
    }

    /**
     * {@inheritDoc}
     * 
     * Decreases the internal counter, stops the server when it reaches 0.
     */
    @Override
    public synchronized void stop() throws Exception
    {
        if (counter == 1) {
            super.stop();
        }
        counter--;
    }
}


@@ -931,16 +931,46 @@
 ework;%0A%0A
+import java.util.Properties;%0A%0A
 import o
@@ -2203,24 +2203,346 @@
 ter == 0) %7B%0A
+            // Disable extensions manager external repositories%0A            Properties properties = loadXWikiProperties();%0A            if (!properties.containsKey(%22extension.repositories%22)) %7B%0A                properties.setProperty(%22extension.repositories%22, %22%22);%0A            %7D%0A            saveXWikiProperties(properties);%0A%0A
             

Disable external extensions repositories for tests