krysalis-update/src/java/org/krysalis/depot/update/impl/util DiffTool.java,NONE,1.1

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

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

--- NEW FILE: DiffTool.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.impl.util;

import org.krysalis.depot.update.Artifact;
import org.krysalis.depot.update.ArtifactInstance;
import org.krysalis.depot.update.artifact.ArtifactGroup;
import org.krysalis.depot.update.artifact.ArtifactLocator;
import org.krysalis.depot.update.artifact.ArtifactType;
import org.krysalis.depot.common.util.note.AnnotationScratchpad;
import org.krysalis.version.Version;

/**
 * @author [email protected]
 */
public class DiffTool {

	/**
	 * Perform a difference on two ArtifactInstance
	 * 
	 * @param ai1
	 * @param ai2
	 * @return the AnnotationScratchpad
	 * @see AnnotationScratchpad
	 */
	public static AnnotationScratchpad diff(
		ArtifactInstance ai1,
		ArtifactInstance ai2) {
		AnnotationScratchpad pad = new AnnotationScratchpad();

		diff(pad, ai1, ai2);

		return pad;
	}

	/**
	 * Difference two ArtifactInstance
	 * @param pad where to write into
	 * @param ai1
	 * @param ai2
	 * @see AnnotationScratchpad
	 */
	public static void diff(
		AnnotationScratchpad pad,
		ArtifactInstance ai1,
		ArtifactInstance ai2) {

		pad.info("Artifact Instance #1: " + ai1);
		pad.info("Artifact Instance #2: " + ai2);

		if (ai1.equals(ai2))
			pad.info(" * Artifact Instances Reported as Equal *");
		else
			pad.info(" * Artifact Instances Reported as NOT Equal *");

		Artifact a1 = ai1.getArtifact();
		Artifact a2 = ai2.getArtifact();

		boolean ae = a1.equals(a2);
		if (ae) {
			pad.debug(" * Artifacts Reported as Equal *");
		}
		else {
			pad.info(" * Artifacts Reported as NOT Equal *");
		}
		pad.info("Artifact #1: " + a1);
		pad.info("Artifact #2: " + a2);
		if (!ae)
			diff(pad, a1, a2);

		ArtifactLocator l1 = ai1.getLocator();
		ArtifactLocator l2 = ai2.getLocator();
		
		if (l1.equals(l2)) {
			pad.debug(" * ArtifactLocators Reported as Equal *");
		}
		else {
			pad.info(" * ArtifactLocators Reported as NOT Equal *");
		}
		pad.info("ArtifactLocator #1: " + l1);
		pad.info("ArtifactLocator #2: " + l2);

	}
	
	/**
	 * Perform a difference on two Artifact
	 * 
	 * @param a1
	 * @param a2
	 * @return the AnnotationScratchpad
	 * @see AnnotationScratchpad
	 */
	public static AnnotationScratchpad diff(
		Artifact a1,
		Artifact a2) {
		AnnotationScratchpad pad = new AnnotationScratchpad();

		diff(pad, a1, a2);

		return pad;
	}

	/**
	 * Difference two Artifact
	 * @param pad where to write into
	 * @param a1
	 * @param a2
	 * @see AnnotationScratchpad
	 */
	public static void diff(
		AnnotationScratchpad pad,
		Artifact a1,
		Artifact a2) {

		pad.info("Artifact  #1: " + a1);
		pad.info("Artifact  #2: " + a2);

		if (a1.equals(a2))
			pad.info(" * Artifact s Reported as Equal *");
		else
			pad.info(" * Artifact s Reported as NOT Equal *");

		ArtifactGroup g1 = a1.getGroup();
		ArtifactGroup g2 = a2.getGroup();

		if (g1.equals(g2)) {
			pad.debug(" * ArtifactGroups Reported as Equal *");
		}
		else {
			pad.info(" * ArtifactGroups Reported as NOT Equal *");
		}
		pad.info("ArtifactGroup #1: " + a1);
		pad.info("ArtifactGroup #2: " + a2);
		
		ArtifactType t1 = a1.getType();
		ArtifactType t2 = a2.getType();
		
		if (t1.equals(t2)) {
			pad.debug(" * ArtifactTypes Reported as Equal *");
		}
		else {
			pad.info(" * ArtifactTypes Reported as NOT Equal *");
		}
		pad.info("ArtifactType #1: " + t1);
		pad.info("ArtifactType #2: " + t2);

		Version v1 = a1.getVersion();
		Version v2 = a2.getVersion();
		
		if (v1.equals(v2)) {
			pad.debug(" * Versions Reported as Equal *");
		}
		else {
			pad.info(" * Versions Reported as NOT Equal *");
		}
		pad.info("Version #1: " + v1);
		pad.info("Version #2: " + v2);

	}
}



-------------------------------------------------------
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/