krysalis-update/src/java/org/krysalis/depot/update/ant/sync SynchronizeTask.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:21 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/ant/sync
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/ant/sync

Added Files:
	SynchronizeTask.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: SynchronizeTask.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.depot.update.ant.sync;



import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.krysalis.depot.common.ant.util.AntLogListener;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.update.ArtifactUpdater;
import org.krysalis.depot.update.ArtifactUpdaterFactory;
import org.krysalis.depot.update.UpdateException;
import org.krysalis.depot.update.artifact.ArtifactGroup;
import org.krysalis.depot.update.repository.DefaultRepository;
import org.krysalis.depot.update.util.UpdateConstants;

/**
 * @author ajack
 */
public class SynchronizeTask extends Task {

	private String m_group = null;
	private String m_updater = UpdateConstants.DEFAULT;
	private String m_target = UpdateConstants.LIBRARY;
	private String m_repositories = UpdateConstants.DEFAULT;

	/**
	 * @param string
	 */
	public void setRepositories(String string) {
		m_repositories = string;
	}

	/**
	 * @param string
	 */
	public void setUpdater(String updater) {
		m_updater = updater;
	}

	/**
	 * @return
	 */
	public String getGroup() {
		return m_group;
	}

	/**
	 * @param string
	 */
	public void setGroup(String groupd) {
		m_group = groupd;
	}

	/**
	 * @param string
	 */
	public void setTarget(String target) {
		m_target = target;
	}

	/* (non-Javadoc)
	 * @see org.apache.tools.ant.Task#execute()
	 */
	public void execute() throws BuildException {

		log("Execute Synchronize...");

		// Set logging context..
		Logger logger = Logger.pushContext(new AntLogListener(this));

		try {
			//
			// This uses default or configured stuff..
			//
			if (!UpdateConstants.DEFAULT.equals(m_updater))
				log("Resource Updater: " + m_updater, Project.MSG_INFO);

			// Get the Resource Updater asked for
			ArtifactUpdater updater = ArtifactUpdaterFactory.getUpdater(m_updater);

			if (!UpdateConstants.LIBRARY.equals(m_target))
				log("Target Repository: " + m_target, Project.MSG_INFO);

			// Assigned the target (to copy into)
			updater.setTargetRepository(
				DefaultRepository.getRepository(m_target, true));

			if (null != m_group) {

				log("Update Group: " + m_group, Project.MSG_INFO);
				ArtifactGroup group = new ArtifactGroup(m_group);
				
				// Update...
				updater.getArtifacts(group);
				
				// Cleanup (to remove duplicates)
				updater.cleanTarget(group);
			}
			else
				throw new BuildException("Missing mandatory attribute 'group' required.");
		}
		catch (UpdateException re) {
			throw new BuildException("Failed to <reposync " + m_group, re);
		}
		finally {
			Logger.popContext(logger);
		}
	}
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/