package org.gradle.plugin.release.action;

import static org.tmatesoft.svn.core.wc.SVNClientManager.newInstance;

import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.InvalidUserDataException;
import org.gradle.plugin.release.SVNInfo;
import org.tmatesoft.svn.core.ISVNDirEntryHandler;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

/**
 * {@link ReleaseAction} implementation used to verify if all relevant SVN
 * folders are present.
 * 
 * @author christian.weber
 * @since 1.0
 */
public abstract class VerifySvnFolderReleaseAction implements ReleaseAction {

	private static final SVNRevision HEAD = SVNRevision.HEAD;

	@Override
	public void action(SVNInfo info) {

		final String us = info.getUsername();
		final String pw = info.getPassword();

		try {
			// create a SVN client manager instance
			DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
			SVNClientManager cm = newInstance(options, us, pw);

			// create a SVNLogClient instance
			SVNLogClient client = cm.getLogClient();

			// list the SVN entries
			ISVNDirEntryHandler handler = new MuteSVNDirEntryHandler();

			SVNURL svnUrl = SVNURL.parseURIEncoded(info.getUrl());
			svnUrl = svnUrl.removePathTail();
			svnUrl = svnUrl.appendPath(getSvnFolder(), true);

			client.doList(svnUrl, HEAD, HEAD, false, SVNDepth.UNKNOWN,
					SVNDirEntry.DIRENT_TIME, handler);

		} catch (SVNException e) {
			Project project = info.getProject();
			Logger logger = project.getLogger();
			logger.error("--> " + info.getProjectName() + "/" + getSvnFolder()
					+ " SVN folder not found", e);

			throw new InvalidUserDataException();
		}

	}

	/**
	 * {@link ISVNDirEntryHandler} implementation with null operation.
	 * 
	 * @author christian.weber
	 */
	private class MuteSVNDirEntryHandler implements ISVNDirEntryHandler {

		@Override
		public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
			// do nothing
		}

	}

	/**
	 * Returns the SVN folder name.
	 * 
	 * @return String
	 */
	protected abstract String getSvnFolder();

	/**
	 * {@link VerifySvnFolderReleaseAction} implementation used to verify if the
	 * 'tags' folder exists.
	 * 
	 * @author christian.weber
	 */
	public static class VerifyTagFolderReleaseAction extends
			VerifySvnFolderReleaseAction {

		@Override
		protected String getSvnFolder() {
			return "tags";
		}

	}

	/**
	 * {@link VerifySvnFolderReleaseAction} implementation used to verify if the
	 * 'branches' folder exists.
	 * 
	 * @author christian.weber
	 */
	public static class VerifyBranchFolderReleaseAction extends
			VerifySvnFolderReleaseAction {

		@Override
		protected String getSvnFolder() {
			return "branches";
		}

	}

}

@@ -1841,200 +1841,8 @@
  %7B%0D%0A
-%09%09%09Project project = info.getProject();%0D%0A%09%09%09Logger logger = project.getLogger();%0D%0A%09%09%09logger.error(%22--%3E %22 + info.getProjectName() + %22/%22 + getSvnFolder()%0D%0A%09%09%09%09%09+ %22 SVN folder not found%22, e);%0D%0A%0D%0A
 %09%09%09t
@@ -1875,16 +1875,17 @@
 ception(
+e
 );%0D%0A%09%09%7D%0D

Update VerifySvnFolderReleaseAction.java