krysalis-version/src/java/org/krysalis/version/ant/stamp DefaultVersionMarkerAttributes.java,NONE,1.1 VersionMarkerAttribute.java,NONE,1.1 VersionIdentifierTask.java,1.1,1.2 VersionSourceGenerator.java,1.9,1.10 VersionMarkerTask.java,1.2,1.3 VersionGeneratorTask.java,1.2,1.3 AntTask.java,1.1,NONE VersionMarkerNestedElement.java,1.2,NONE VersionNestedElement.java,1.2,NONE NestedElement.java,1.1,NONE

Nick Chalko <[email protected]> Tue, 09 Nov 2004 07:36:29 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/ant/stamp
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30983/src/java/org/krysalis/version/ant/stamp

Modified Files:
	VersionIdentifierTask.java VersionSourceGenerator.java 
	VersionMarkerTask.java VersionGeneratorTask.java 
Added Files:
	DefaultVersionMarkerAttributes.java 
	VersionMarkerAttribute.java 
Removed Files:
	AntTask.java VersionMarkerNestedElement.java 
	VersionNestedElement.java NestedElement.java 
Log Message:
Everything at least compiles now.

Index: VersionIdentifierTask.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/ant/stamp/VersionIdentifierTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VersionIdentifierTask.java	4 Nov 2004 08:32:31 -0000	1.1
--- VersionIdentifierTask.java	9 Nov 2004 07:36:27 -0000	1.2
***************
*** 18,21 ****
--- 18,22 ----
  
  import org.apache.tools.ant.BuildException;
+ import org.krysalis.version.ant.AntTask;
  
  /**

Index: VersionMarkerTask.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/ant/stamp/VersionMarkerTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** VersionMarkerTask.java	9 Nov 2004 06:40:29 -0000	1.2
--- VersionMarkerTask.java	9 Nov 2004 07:36:27 -0000	1.3
***************
*** 33,87 ****
  public abstract class VersionMarkerTask extends VersionIdentifierTask {
  
! //:TODO: Deal better with cascading properties & user error dups, etc.
  
!     private VersionMarkerNestedElement m_versionMarkerBean = null;
  
!     public VersionMarkerTask() {
!         super();
!     }
  
!     public VersionMarkerNestedElement createVersionMarker() {
! 		if( null != m_versionMarkerBean)
! 			throw new BuildException("Only one nested <versionMarker tag allowed.", getLocation());
  		createVersionMarkerBeanOnDemand();
!         return m_versionMarkerBean;
!     }
  
  	public VersionNestedElement createVersion() {
! 		if( null != m_versionMarkerBean)
! 			throw new BuildException("Can't have nested <versionMarker and <version tags, use <versionMarker only.", getLocation());
  		createVersionMarkerBeanOnDemand();
  		return m_versionMarkerBean.createVersion();
  	}
! 	
!     public boolean hasVersionMarker()
!     {
!     	return isVersionMarkerSet();
!     }
!     
! 	public boolean hasVersion()
! 	{
  		return isVersionMarkerSet() && (m_versionMarkerBean.hasVersion());
  	}
-     
-     
-     public boolean isVersionMarkerSet() {
-         return (null != m_versionMarkerBean);
-     }
  
!     public Version getVersionObject() {
!         if (null == m_versionMarkerBean)
!             throw new BuildException(
!                 "Missing mandatory nested element <versionMarker...>",
!                 getLocation());
  
!         return m_versionMarkerBean.getVersionObject();
!     }
  
  	public CompoundVersion getCompoundVersion() {
  		if (null == m_versionMarkerBean)
  			throw new BuildException(
! 				"Missing mandatory nested element <versionMarker...>",
! 				getLocation());
  
  		return m_versionMarkerBean.getCompoundVersionObject();
--- 33,88 ----
  public abstract class VersionMarkerTask extends VersionIdentifierTask {
  
! 	//:TODO: Deal better with cascading properties & user error dups, etc.
  
! 	private VersionMarkerNestedElement m_versionMarkerBean = null;
  
! 	public VersionMarkerTask() {
! 		super();
! 	}
  
! 	public VersionMarkerNestedElement createVersionMarker() {
! 		if (null != m_versionMarkerBean)
! 			throw new BuildException(
! 					"Only one nested <versionMarker tag allowed.",
! 					getLocation());
  		createVersionMarkerBeanOnDemand();
! 		return m_versionMarkerBean;
! 	}
  
  	public VersionNestedElement createVersion() {
! 		if (null != m_versionMarkerBean)
! 			throw new BuildException(
! 					"Can't have nested <versionMarker and <version tags, use <versionMarker only.",
! 					getLocation());
  		createVersionMarkerBeanOnDemand();
  		return m_versionMarkerBean.createVersion();
  	}
! 
! 	public boolean hasVersionMarker() {
! 		return isVersionMarkerSet();
! 	}
! 
! 	public boolean hasVersion() {
  		return isVersionMarkerSet() && (m_versionMarkerBean.hasVersion());
  	}
  
! 	public boolean isVersionMarkerSet() {
! 		return (null != m_versionMarkerBean);
! 	}
  
! 	public Version getVersionObject() {
! 		if (null == m_versionMarkerBean)
! 			throw new BuildException(
! 					"Missing mandatory nested element <versionMarker...>",
! 					getLocation());
! 
! 		return m_versionMarkerBean.getVersionObject();
! 	}
  
  	public CompoundVersion getCompoundVersion() {
  		if (null == m_versionMarkerBean)
  			throw new BuildException(
! 					"Missing mandatory nested element <versionMarker...>",
! 					getLocation());
  
  		return m_versionMarkerBean.getCompoundVersionObject();
***************
*** 91,134 ****
  		if (null == m_versionMarkerBean)
  			throw new BuildException(
! 				"Missing mandatory nested element <versionMarker...>",
! 				getLocation());
  
  		return m_versionMarkerBean.getVersionMarker();
  	}
  
!     protected void validate() {
!         //:TODO: make VersionBean Validate Itself...
!         super.validate();
!     }
!     
!     /**
!      * Sets the versionId.
!      * @param versionId The versionId to set
!      */
!     public void setVersionId(String versionId) {
!         super.setVersionId(versionId);
!         
  		createVersionMarkerBeanOnDemand();
! 		 
!         if (!m_versionMarkerBean.isVersionIdSet())
!             m_versionMarkerBean.setVersionId(versionId);
!     }
!     
!     /**
!      * Sets the version.
!      * @param version The version to set
!      */
!     public void setVersion(String version) {
!         createVersionMarkerBeanOnDemand();
!         
!         if (!m_versionMarkerBean.isVersionSet())
!             m_versionMarkerBean.setVersion(version);
!     }
!     
!     private void createVersionMarkerBeanOnDemand()
!     {
! 		if ( null == m_versionMarkerBean)
! 					m_versionMarkerBean = new VersionMarkerNestedElement(this, getVersionIdIfSet());
!        
!     }
  }
--- 92,139 ----
  		if (null == m_versionMarkerBean)
  			throw new BuildException(
! 					"Missing mandatory nested element <versionMarker...>",
! 					getLocation());
  
  		return m_versionMarkerBean.getVersionMarker();
  	}
  
! 	protected void validate() {
! 		//:TODO: make VersionBean Validate Itself...
! 		super.validate();
! 	}
! 
! 	/**
! 	 * Sets the versionId.
! 	 * 
! 	 * @param versionId
! 	 *            The versionId to set
! 	 */
! 	public void setVersionId(String versionId) {
! 		super.setVersionId(versionId);
! 
  		createVersionMarkerBeanOnDemand();
! 
! 		if (!m_versionMarkerBean.isVersionIdSet())
! 			m_versionMarkerBean.setVersionId(versionId);
! 	}
! 
! 	/**
! 	 * Sets the version.
! 	 * 
! 	 * @param version
! 	 *            The version to set
! 	 */
! 	public void setVersion(String version) {
! 		createVersionMarkerBeanOnDemand();
! 
! 		if (!m_versionMarkerBean.isVersionSet())
! 			m_versionMarkerBean.setVersion(version);
! 	}
! 
! 	private void createVersionMarkerBeanOnDemand() {
! 		if (null == m_versionMarkerBean)
! 			m_versionMarkerBean = new VersionMarkerNestedElement(this,
! 					getVersionIdIfSet());
! 
! 	}
  }

--- VersionNestedElement.java DELETED ---

Index: VersionGeneratorTask.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/ant/stamp/VersionGeneratorTask.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** VersionGeneratorTask.java	9 Nov 2004 06:40:29 -0000	1.2
--- VersionGeneratorTask.java	9 Nov 2004 07:36:27 -0000	1.3
***************
*** 24,29 ****
  import org.apache.tools.ant.BuildException;
  import org.krysalis.version.VersionMarker;
- import org.krysalis.version.ant.DirectoryVersionMarkerTask;
- import org.krysalis.version.generation.VersionSourceGenerator;
  
  /**
--- 24,27 ----

--- NestedElement.java DELETED ---

--- VersionMarkerNestedElement.java DELETED ---

Index: VersionSourceGenerator.java
===================================================================
RCS file: /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/ant/stamp/VersionSourceGenerator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** VersionSourceGenerator.java	9 Nov 2004 07:13:59 -0000	1.9
--- VersionSourceGenerator.java	9 Nov 2004 07:36:27 -0000	1.10
***************
*** 1,5 ****
  package org.krysalis.version.ant.stamp;
  
! import org.apache.depot.version.VersionMarker;
  import java.util.Iterator;
  import java.util.Map;
--- 1,5 ----
  package org.krysalis.version.ant.stamp;
  
! import org.krysalis.version.VersionMarker;
  import java.util.Iterator;
  import java.util.Map;

--- AntTask.java DELETED ---

--- NEW FILE: DefaultVersionMarkerAttributes.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.version.ant.stamp;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.krysalis.version.VersionConstants;
import org.krysalis.version.ant.nested.NestedElement;

/**
 * @author $Author: chalko $
 * @version $Revision: 1.1 $
 */
public class DefaultVersionMarkerAttributes extends NestedElement {

	private List<VersionMarkerAttribute> m_list = null;

	private static final HashMap<String, Object> DEFAULT_MAP;

	static {
		DEFAULT_MAP = new HashMap<String, Object>();

		DEFAULT_MAP.put("java.vm.version", VersionConstants.BUILD_JVM);
		DEFAULT_MAP.put("user.name", VersionConstants.BUILD_USER);
		DEFAULT_MAP.put("ant.version", VersionConstants.BUILD_ANT);

		// :TODO: Add more...
	}

	/**
	 * Constructor for VersionAttribute.
	 */
	public DefaultVersionMarkerAttributes(ProjectComponent component) {
		super(component);

		m_list = new ArrayList<VersionMarkerAttribute>();

		importProperties();

		generateProperties();
	}

	private void importProperties() {
		Hashtable properties = this.getRootComponent().getProject()
				.getProperties();

		for (Iterator i = DEFAULT_MAP.keySet().iterator(); i.hasNext();) {
			Object key = i.next();
			String vkey = (String) DEFAULT_MAP.get(key);
			Object value = properties.get(key);

			if (null != value) {
				m_list.add(new VersionMarkerAttribute(getRootComponent(), vkey,
						value.toString()));
			} else
				getRootComponent().log(
						"Attribute [" + vkey + "] without value",
						Project.MSG_WARN);
		}
	}

	private void generateProperties() {

		//
		// Hostname
		//
		String hostname = null;
		try {
			hostname = InetAddress.getLocalHost().getHostName();
		} catch (Exception e) {
			hostname = "Unknown Host";
		}

		m_list.add(new VersionMarkerAttribute(getRootComponent(),
				VersionConstants.BUILD_HOST, hostname));

		m_list.add(new VersionMarkerAttribute(getRootComponent(),
				VersionConstants.BUILD_DATETIME, new Date()));

	}

	public VersionMarkerAttribute createAttribute() {
		VersionMarkerAttribute attr = new VersionMarkerAttribute(
				getRootComponent());
		m_list.add(attr);
		return attr;
	}

	/**
	 * @return
	 */
	public List getList() {
		return m_list;
	}
}

--- NEW FILE: VersionMarkerAttribute.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.version.ant.stamp;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.krysalis.version.ant.nested.NestedElement;

/**
 * 
 * @author $Author: chalko $
 * @version $Revision: 1.1 $
 */
public class VersionMarkerAttribute extends NestedElement {
	String m_name = null;

	Object m_value = null;

	/**
	 * Constructor for VersionAttribute.
	 */
	public VersionMarkerAttribute(ProjectComponent component) {
		super(component);
	}

	/**
	 * Constructor for VersionAttribute.
	 */
	public VersionMarkerAttribute(ProjectComponent component, String name,
			String value) {
		super(component);
		m_name = name;
		m_value = value;
	}

	/**
	 * Constructor for VersionAttribute.
	 */
	public VersionMarkerAttribute(ProjectComponent component, String name,
			Object value) {
		super(component);
		m_name = name;
		m_value = value;
	}

	/**
	 * Returns the name.
	 * 
	 * @return String
	 */
	public String getName() {
		if (null == m_name)
			throw new BuildException("Missing mandatory attribute 'name'",
					getLocation());
		return m_name;
	}

	/**
	 * Returns the value.
	 * 
	 * @return Object
	 */
	public Object getValue() {
		if (null == m_value)
			throw new BuildException("Missing mandatory attribute 'value'",
					getLocation());
		return m_value;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            The name to set
	 */
	public void setName(String name) {
		m_name = name;
	}

	/**
	 * Sets the value.
	 * 
	 * @param value
	 *            The value to set
	 */
	public void setValue(String value) {
		m_value = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return m_name + " = " + m_value;
	}

}



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click