krysalis-version/src/java/org/krysalis/version/ant/stamp AntTask.java,NONE,1.1 VersionMarkerNestedElement.java,NONE,1.1 VersionIdentifierTask.java,NONE,1.1 Skeleton.java,NONE,1.1 VersionNestedElement.java,NONE,1.1 NestedElement.java,NONE,1.1 VersionSourceGenerator.java,NONE,1.1 VersionMarkerTask.java,NONE,1.1 VersionGeneratorTask.java,NONE,1.1 DirectoryVersionMarkerTask.java,NONE,1.1
Nick Chalko <[email protected]> Thu, 04 Nov 2004 08:32:34 +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-serv2482/src/java/org/krysalis/version/ant/stamp
Added Files:
AntTask.java VersionMarkerNestedElement.java
VersionIdentifierTask.java Skeleton.java
VersionNestedElement.java NestedElement.java
VersionSourceGenerator.java VersionMarkerTask.java
VersionGeneratorTask.java DirectoryVersionMarkerTask.java
Log Message:
Moved some initial files over nothing compiles yet.
--- NEW FILE: VersionIdentifierTask.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;
/**
* @author: $Author: chalko $
* @version: $Revision: 1.1 $
*/
public abstract class VersionIdentifierTask extends AntTask {
private String m_versionId = null;
public VersionIdentifierTask() {
super();
}
protected void validate() {
//:TODO: make VersionIdentifierBean Validate Itself...
}
/**
* Returns the versionId.
* @return String
*/
public String getVersionId() {
if (null == m_versionId)
throw new BuildException(
"Missing manadtory setting 'versionId'",
getLocation());
return m_versionId;
}
/**
* Returns the versionId.
* @return String
*/
public String getVersionIdIfSet() {
return m_versionId;
}
public boolean isVersionIdSet() {
return (null != m_versionId);
}
/**
* Sets the versionId.
* @param versionId The versionId to set
*/
public void setVersionId(String versionId) {
m_versionId = versionId;
}
}
--- NEW FILE: VersionMarkerTask.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.depot.version.Version;
import org.apache.depot.version.VersionMarker;
import org.apache.depot.version.ant.nested.VersionMarkerNestedElement;
import org.apache.depot.version.ant.nested.VersionNestedElement;
import org.apache.depot.version.impl.CompoundVersion;
import org.apache.tools.ant.BuildException;
//
// :TODO: Create a version-available task w/ actions (like set property)
//
/**
* @author: $Author: chalko $
* @version: $Revision: 1.1 $
*/
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();
}
public VersionMarker getVersionMarker() {
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());
}
}
--- NEW FILE: DirectoryVersionMarkerTask.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.io.File;
import org.apache.tools.ant.BuildException;
/**
* @author [email protected]
*/
public abstract class DirectoryVersionMarkerTask extends VersionMarkerTask {
private File m_dest = null;
/**
* Constructor for VersionTask.
*/
public DirectoryVersionMarkerTask() {
}
/**
* Sets the dest.
* @param dest The dest to set
*/
public void setDest(File dest) {
m_dest = dest;
}
/**
* Returns the dest.
* @return File
*/
public File getDest() {
if ( null == m_dest )
throw new BuildException("Missing mandatory destination directory 'dest'", getLocation());
return m_dest;
}
}
--- NEW FILE: VersionNestedElement.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.util.Date;
import org.apache.depot.version.Version;
import org.apache.depot.version.VersionException;
import org.apache.depot.version.impl.ApacheVersion;
import org.apache.depot.version.impl.CompoundVersion;
import org.apache.depot.version.impl.data.ReleaseLevel;
import org.apache.depot.version.impl.data.VersionData;
import org.apache.depot.version.impl.data.VersionDataElement;
import org.apache.depot.version.specification.VersionSpecification;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
/**
*
* @author: $Author: chalko $
* @version: $Revision: 1.1 $
*/
public class VersionNestedElement extends NestedElement {
private VersionSpecificationNestedElement m_specificationBean = null;
private String m_releaseLevel = null;
private int m_releaseQualifier = VersionDataElement.UNSET_RELEASE_QUALIFIER;
private int m_major = VersionDataElement.UNSET_MAJOR;
private int m_minor = VersionDataElement.UNSET_MINOR;
private int m_point = VersionDataElement.UNSET_POINT;
private int m_buildNumber = VersionDataElement.UNSET_BUILD_NUMBER;
private Date m_buildDate = VersionDataElement.UNSET_BUILD_DATE;
private String m_version = null;
public VersionNestedElement(ProjectComponent component) {
super(component);
}
public CompoundVersion getCompoundVersionObject() {
Version version = getVersionObject();
CompoundVersion cv = null;
if (version instanceof CompoundVersion)
cv = (CompoundVersion) version;
if (null == cv)
throw new BuildException(
"Not a compound version: " + version,
m_ant.getLocation());
return cv;
}
//:TODO: Allow users to specific the class to use...
public Version getVersionObject() {
Version version = null;
try {
if (null != m_specificationBean) {
VersionSpecification specification =
m_specificationBean.getVersionSpecificationObject();
if (null != m_version)
version = new ApacheVersion(specification, m_version);
else
version =
new ApacheVersion(
specification,
new VersionData(m_major,
m_minor,
ReleaseLevel.getFromString(m_releaseLevel),
m_releaseQualifier,
m_point,
m_buildNumber,
m_buildDate));
}
else {
if (null != m_version)
version = new ApacheVersion(m_version);
else
version =
new ApacheVersion(
new VersionData(m_major,
m_minor,
ReleaseLevel.getFromString(m_releaseLevel),
m_releaseQualifier,
m_point,
m_buildNumber,
m_buildDate));
}
}
catch (VersionException ve) {
throw new BuildException(ve, m_ant.getLocation());
}
return version;
}
/**
* Gets the minor version number.
* @return Returns a java.lang.String
*/
public int getMinor() {
return m_minor;
}
/**
* Sets the minor version number.
* @param minor The minor to set
*/
public void setMinor(int minor) {
m_minor = minor;
}
/**
* Sets the major version number.
* @param major The major to set
*/
public void setMajor(int major) {
m_major = major;
}
/**
* Sets the point.
* @param point The point to set
*/
public void setPoint(int point) {
m_point = point;
}
/**
* Sets the releaseLevel.
* @param level The releaseLevel to set
*/
public void setReleaseLevel(String releaseLevel) {
m_releaseLevel = releaseLevel;
}
/**
* Sets the releaseQualifier.
* @param releaseQualifier The releaseQualifier to set
*/
public void setReleaseQualifier(int releaseQualifier) {
m_releaseQualifier = releaseQualifier;
}
/**
* Sets the level.
* @param level The level to set
*/
public void setBuildNumber(int buildNumber) {
m_buildNumber = buildNumber;
}
public boolean isVersionSet() {
return null != m_version;
}
/**
* Set the entire string. This overides other settings.
*
* @param version The version to set
*/
public void setVersion(String version) {
m_version = version;
}
public VersionSpecificationNestedElement createSpecification() {
//:TODO: Only one?
m_specificationBean =
new VersionSpecificationNestedElement(m_ant.getComponent());
return m_specificationBean;
}
/**
* Returns the buildNumber.
* @return String
*/
public int getBuildNumber() {
return m_buildNumber;
}
/**
* Returns the major.
* @return String
*/
public int getMajor() {
return m_major;
}
/**
* Returns the point.
* @return String
*/
public int getPoint() {
return m_point;
}
/**
* Returns the releaseLevel.
* @return String
*/
public String getReleaseLevel() {
return m_releaseLevel;
}
/**
* Returns the version.
* @return String
*/
public String getVersion() {
return m_version;
}
}
--- NEW FILE: VersionGeneratorTask.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.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import org.apache.depot.version.VersionMarker;
import org.apache.depot.version.ant.DirectoryVersionMarkerTask;
import org.apache.depot.version.generation.VersionSourceGenerator;
import org.apache.tools.ant.BuildException;
/**
* Generate VersionStamp java source file.
*
* @version: $ $
*/
public class VersionGeneratorTask extends DirectoryVersionMarkerTask {
public VersionGeneratorTask() {
super();
}
/**
* ant entry point: Creates the build version java file.
*/
public void performExecute() throws org.apache.tools.ant.BuildException {
Writer out = null;
try {
VersionMarker versionMarker = getVersionMarker();
String packageName = versionMarker.getId() + ".version";
VersionSourceGenerator vsg = new VersionSourceGenerator();
String className="Version";
String source = vsg.generate(packageName,className, versionMarker);
out = getFileWriter(packageName,className);
out.write(source);
} catch (BuildException e) {
throw e;
} catch (Exception e) {
throw new BuildException(e, getLocation());
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
throw new BuildException(e, getLocation());
}
}
}
}
/**
* @param packageName
* @return @throws
* IOException
*/
private FileWriter getFileWriter(String packageName, String className) throws IOException {
File fullPath = new File(getDest() ,packageName.replace('.', '/'));
if (!fullPath.exists()) {
if (!fullPath.mkdirs()) {
throw new BuildException("Unable to create dir " + fullPath);
}
}
File file = new File(fullPath, className+".java");
FileWriter fw = new FileWriter(file);
return fw;
}
}
--- NEW FILE: NestedElement.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.Location;
import org.apache.tools.ant.ProjectComponent;
public class NestedElement {
private final ProjectComponent rootComponent;
public NestedElement(ProjectComponent rootComponent) {
this.rootComponent=rootComponent;
}
/**
* Get the root component that owns this nested element.
* This will be a task or top level data type
* @return Root component
*/
public ProjectComponent getRootComponent() {
return rootComponent;
}
public Location getLocation() {
return null;}
}
--- NEW FILE: VersionMarkerNestedElement.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.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.depot.version.Version;
import org.apache.depot.version.VersionException;
import org.apache.depot.version.VersionMarker;
import org.apache.depot.version.impl.ApacheVersion;
import org.apache.depot.version.impl.ApacheVersionMarker;
import org.apache.depot.version.impl.CompoundVersion;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.Task;
/**
*
* @author: $Author: chalko $
* @version: $Revision: 1.1 $
*/
public class VersionMarkerNestedElement extends NestedElement {
private String m_versionId = null;
private String m_version = null;
private VersionNestedElement m_versionBean = null;
private DefaultVersionMarkerAttributes m_defaultAttributes = null;
private final List m_attributeList = new ArrayList();
//:TODO: Add These...
private final List m_annotationList = new ArrayList();
public VersionMarkerNestedElement(ProjectComponent component, String versionId) {
super(component);
m_versionId = versionId;
}
public VersionMarkerNestedElement(Task task) {
super(task);
}
//:TODO: If no version info, but version id -- then load it?
public VersionMarker getVersionMarker() {
VersionMarker versionMarker = null;
try {
HashMap attributes = getAttributes();
//
// One could embed a <version nested element
//
Version version = getVersionObject();
versionMarker =
new ApacheVersionMarker(
getVersionId(),
version,
attributes,
m_annotationList,new Date());
}
catch (VersionException ve) {
throw new BuildException(ve, m_ant.getLocation());
}
return versionMarker;
}
public CompoundVersion getCompoundVersionObject() {
return (CompoundVersion) getVersionObject();
}
public Version getVersionObject() {
Version version = null;
if ((null == m_versionBean) && (null == m_version))
throw new BuildException(
"Missing mandatory <version sub-element or 'version' attribute.",
m_ant.getLocation());
if ((null != m_versionBean) && (null != m_version))
throw new BuildException(
"Use one of <version sub-element or 'version' attribute, not both.",
m_ant.getLocation());
if (null != m_versionBean)
version = m_versionBean.getVersionObject();
else {
try {
//
// Attempt to parse the attribute
//
version = new ApacheVersion(m_version);
}
catch (VersionException ve) {
throw new BuildException(
"Invalid 'version' attribute : \"" + m_version + "\"",
ve,
m_ant.getLocation());
}
}
return version;
}
private HashMap getAttributes() {
HashMap attributes = new HashMap();
if (null != m_defaultAttributes)
for (Iterator i = m_defaultAttributes.getList().iterator();
i.hasNext();
) {
processAttribute(attributes, (VersionMarkerAttribute) i.next());
}
for (Iterator i = m_attributeList.iterator(); i.hasNext();) {
processAttribute(attributes, (VersionMarkerAttribute) i.next());
}
return attributes;
}
private void processAttribute(
HashMap attributes,
VersionMarkerAttribute attr) {
if (null != attr.getName()) {
if (null != attr.getValue())
attributes.put(attr.getName(), attr.getValue());
else
m_ant.log(
"Named attribute ["
+ attr.getName()
+ "] without value. Attributed ignored.",
Project.MSG_WARN);
}
else
throw new BuildException("Invalid *unnamed* attribute: " + attr);
}
/**
* Set the versionId.
*
* @param newName java.lang.String
*/
public void setVersionId(String versionId) {
m_versionId = versionId;
}
/**
* Returns the attributeList.
* @return List
*/
public List getAttributeList() {
return m_attributeList;
}
public boolean isVersionIdSet() {
return null != m_versionId;
}
/**
* Returns the versionId.
* @return String
*/
public String getVersionId() {
if (null == m_versionId)
throw new BuildException(
"Missing mandatory version identifier 'versionId'",
m_ant.getLocation());
return m_versionId;
}
// -------------------------------------------------------------
//
// Nested Sub-Elements:
//
// -------------------------------------------------------------
public VersionMarkerAttribute createAttribute() {
VersionMarkerAttribute attr =
new VersionMarkerAttribute(m_ant.getComponent());
m_attributeList.add(attr);
return attr;
}
public DefaultVersionMarkerAttributes createDefaultAttributes() {
if (null != m_defaultAttributes)
throw new BuildException(
"Only one nested <defaultAttributes tag allowed.",
getLocation());
m_defaultAttributes =
new DefaultVersionMarkerAttributes(m_ant.getComponent());
return m_defaultAttributes;
}
public VersionNestedElement createVersion() {
if (null != m_versionBean)
throw new BuildException(
"Only one nested <version tag allowed.",
getLocation());
m_versionBean = new VersionNestedElement(m_ant.getComponent());
return m_versionBean;
}
/**
* @param string
*/
public void setVersion(String string) {
m_version = string;
}
public boolean hasVersion() {
return isVersionSet();
}
public boolean isVersionSet() {
return ((null != m_version) || (null != m_versionBean));
}
}
--- NEW FILE: VersionSourceGenerator.java ---
package org.krysalis.version.ant.stamp;
import org.apache.depot.version.VersionMarker;
import java.util.Iterator;
import java.util.Map;
/*
* 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.
*/
public final class VersionSourceGenerator extends org.krysalis.version.ant.stamp.Skeleton
{
protected final String NL = System.getProperties().getProperty("line.separator");
protected final String TEXT_1 = "/* " + NL + " *" + NL + " * NOTE: Automatically Generated File (see Depot Version from the Apache Incubator)" + NL + " * NOTE: http://incubator.apache.org/depot/version" + NL + " * NOTE: Ant Task: version-stamp" + NL + " * NOTE: AntLib: apache-version" + NL + " *" + NL + " * $Header: ";
protected final String TEXT_2 = ".java $" + NL + " *" + NL + " */" + NL + "package ";
protected final String TEXT_3 = "; " + NL + "" + NL + "import java.util.Collections;" + NL + "import java.util.Date;" + NL + "import java.util.HashMap;" + NL + "import java.util.Map;" + NL + "/**" + NL + " * A autogenerated VersionStamp class for ";
protected final String TEXT_4 = " ." + NL + " * Generated at ";
protected final String TEXT_5 = " " + NL + " * on ";
protected final String TEXT_6 = NL + " * by ";
protected final String TEXT_7 = NL + " * @author <a href=\"http://incubator.apache.org/depot\">Depot Version</a> " + NL + " * from the <a href=\"http://incubator.apache.org/\">Apache Incubator</a>, " + NL + " version ";
protected final String TEXT_8 = NL + " * @version ";
protected final String TEXT_9 = NL + " * @generated" + NL + " */" + NL + "public final class ";
protected final String TEXT_10 = " { " + NL + "\t/* SINGLETON PATTERN */" + NL + "\tprivate final static ";
protected final String TEXT_11 = " INSTANCE = new ";
protected final String TEXT_12 = "();" + NL + "" + NL + "\t/**" + NL + "\t * Get the single instance of ";
protected final String TEXT_13 = "." + NL + "\t * @return the single instance of ";
protected final String TEXT_14 = "." + NL + "\t */" + NL + " public static ";
protected final String TEXT_15 = " getInstance() {return INSTANCE ;}" + NL + "" + NL + " " + NL + " private final Map attributes;" + NL + "\t" + NL + "\t/**" + NL + "\t * Private constructor for Singleton." + NL + "\t */" + NL + "\tprivate ";
protected final String TEXT_16 = "() {" + NL + "\tMap temp = new HashMap();" + NL + "\t";
protected final String TEXT_17 = NL + " temp.put(";
protected final String TEXT_18 = ",";
protected final String TEXT_19 = NL + " ";
protected final String TEXT_20 = ");// ";
protected final String TEXT_21 = NL + "\tattributes = Collections.unmodifiableMap(temp);" + NL + "\t" + NL + "\t}" + NL + "\t" + NL + "\t" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_22 = " is the Id of this project." + NL + "\t * @return the String \"";
protected final String TEXT_23 = "\"" + NL + "\t */" + NL + "\tpublic String getId() {return \"";
protected final String TEXT_24 = "\"; }" + NL + "\t" + NL + "\t\t" + NL + "\t/**" + NL + "\t * The user that built ";
protected final String TEXT_25 = " was ";
protected final String TEXT_26 = "." + NL + "\t * @return the String \"";
protected final String TEXT_27 = "\"" + NL + "\t */" + NL + "\tpublic String getUser() {return \"";
protected final String TEXT_28 = "\"; }" + NL + "\t" + NL + "\t\t" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_29 = " was built on ";
protected final String TEXT_30 = "." + NL + "\t * @return the String \"";
protected final String TEXT_31 = "\"" + NL + "\t */" + NL + "\tpublic String getHost() {return \"";
protected final String TEXT_32 = "\"; }" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_33 = " was built at ";
protected final String TEXT_34 = "." + NL + "\t * @return the Date \"";
protected final String TEXT_35 = "\"" + NL + "\t */" + NL + "\tpublic Date getDate() {return ";
protected final String TEXT_36 = "; }" + NL + "\t" + NL + "\t/**" + NL + "\t * The ID of the Version Specification." + NL + "\t * @return the String \"";
protected final String TEXT_37 = "\"." + NL + "\t * @see org.apache.depot.version.specification.VersionSpecificationFactory" + NL + "\t */" + NL + "\tpublic String getSpecificationId(){return \"";
protected final String TEXT_38 = "\";} " + NL + "\t" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_39 = " ";
protected final String TEXT_40 = "." + NL + "\t * @return the String \"";
protected final String TEXT_41 = "\"" + NL + "\t */" + NL + "\tpublic String getShortVersion() {return \"";
protected final String TEXT_42 = "\";}" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_43 = " ";
protected final String TEXT_44 = "." + NL + "\t * @return the String \"";
protected final String TEXT_45 = "\"" + NL + "\t */" + NL + "\tpublic String getLongVersion() {return \"";
protected final String TEXT_46 = "\";}" + NL + "" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_47 = " ";
protected final String TEXT_48 = "." + NL + "\t * @return the String \"";
protected final String TEXT_49 = "\"" + NL + "\t */" + NL + "\tpublic String getDefaultVersion() {return \"";
protected final String TEXT_50 = "\";}\t" + NL + "" + NL + "\t/**" + NL + "\t * Get the Unmodifiable map of attributes. \t" + NL + "\t * <dl>";
protected final String TEXT_51 = NL + " * <dt>";
protected final String TEXT_52 = "</dt>" + NL + " * <dd>";
protected final String TEXT_53 = "</dd>";
protected final String TEXT_54 = NL + " * </dl>" + NL + "\t * @return unmodifiable Map of attributes." + NL + "\t */" + NL + "\tpublic Map getAttributes () {return attributes;}" + NL + "" + NL + "" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
protected final String TEXT_55 = " ";
protected final String TEXT_56 = "." + NL + "\t * @return the String \"";
protected final String TEXT_57 = "\"" + NL + "\t */" + NL + "\tpublic String toString() {return \"";
protected final String TEXT_58 = "\";}" + NL + "} ";
public String generate(String packageName, String className, VersionMarker marker)
{
StringBuffer stringBuffer = new StringBuffer();
/*
* 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.
*/
/* NOTE this will also show up in VersionSourceGenerator.java but not in the
* Generated VersionStamp.
*/
stringBuffer.append(TEXT_1);
stringBuffer.append(className);
stringBuffer.append(TEXT_2);
stringBuffer.append(packageName);
stringBuffer.append(TEXT_3);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_4);
stringBuffer.append(new java.util.Date() );
stringBuffer.append(TEXT_5);
stringBuffer.append(getHost());
stringBuffer.append(TEXT_6);
stringBuffer.append(getUser());
stringBuffer.append(TEXT_7);
stringBuffer.append(depotVersion.getLongVersion() );
stringBuffer.append(TEXT_8);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_9);
stringBuffer.append(className);
stringBuffer.append(TEXT_10);
stringBuffer.append(className);
stringBuffer.append(TEXT_11);
stringBuffer.append(className);
stringBuffer.append(TEXT_12);
stringBuffer.append(className);
stringBuffer.append(TEXT_13);
stringBuffer.append(className);
stringBuffer.append(TEXT_14);
stringBuffer.append(className);
stringBuffer.append(TEXT_15);
stringBuffer.append(className);
stringBuffer.append(TEXT_16);
for (Iterator i = marker.getAttributes().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
// TODO need to escape key and value.
stringBuffer.append(TEXT_17);
stringBuffer.append(getValueFrom(entry.getKey()));
stringBuffer.append(TEXT_18);
stringBuffer.append(TEXT_19);
stringBuffer.append(getValueFrom(entry.getValue()));
stringBuffer.append(TEXT_20);
stringBuffer.append(entry.getValue());
}
stringBuffer.append(TEXT_21);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_22);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_23);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_24);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_25);
stringBuffer.append(getUser());
stringBuffer.append(TEXT_26);
stringBuffer.append(getUser());
stringBuffer.append(TEXT_27);
stringBuffer.append(getUser());
stringBuffer.append(TEXT_28);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_29);
stringBuffer.append(getHost());
stringBuffer.append(TEXT_30);
stringBuffer.append(getHost());
stringBuffer.append(TEXT_31);
stringBuffer.append(getHost());
stringBuffer.append(TEXT_32);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_33);
stringBuffer.append(getDate());
stringBuffer.append(TEXT_34);
stringBuffer.append(getDate());
stringBuffer.append(TEXT_35);
stringBuffer.append(getValueFrom(getDate()));
stringBuffer.append(TEXT_36);
stringBuffer.append(marker.getSpecification().getId());
stringBuffer.append(TEXT_37);
stringBuffer.append(marker.getSpecification().getId());
stringBuffer.append(TEXT_38);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_39);
stringBuffer.append(marker.getShortVersion());
stringBuffer.append(TEXT_40);
stringBuffer.append(marker.getShortVersion());
stringBuffer.append(TEXT_41);
stringBuffer.append(marker.getShortVersion());
stringBuffer.append(TEXT_42);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_43);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_44);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_45);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_46);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_47);
stringBuffer.append(marker.getDefaultVersion());
stringBuffer.append(TEXT_48);
stringBuffer.append(marker.getDefaultVersion());
stringBuffer.append(TEXT_49);
stringBuffer.append(marker.getDefaultVersion());
stringBuffer.append(TEXT_50);
for (Iterator i = marker.getAttributes().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
// TODO need to escape key and value.
stringBuffer.append(TEXT_51);
stringBuffer.append(entry.getKey());
stringBuffer.append(TEXT_52);
stringBuffer.append(entry.getValue());
stringBuffer.append(TEXT_53);
}
stringBuffer.append(TEXT_54);
stringBuffer.append(marker.getId());
stringBuffer.append(TEXT_55);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_56);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_57);
stringBuffer.append(marker.getLongVersion());
stringBuffer.append(TEXT_58);
return stringBuffer.toString();
}
}
--- NEW FILE: Skeleton.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.UnknownHostException;
import java.util.Date;
import org.apache.depot.version.VersionMarker;
/**
* The Skeleton for the VersionSourceGenerator
*
* @version
*/
public class Skeleton {
final VersionMarker depotVersion;
final Date date = new Date();
public Skeleton() {
VersionMarker temp = VersionMarker.UNKNOWN;
try {
temp = new org.apache.depot.version.version.Version();
} catch (org.apache.depot.version.VersionException e) {
// Ignore
}
depotVersion = temp;
}
/**
* The user name from the System Property user.name
*
* @return the user name as a String.
*/
String getUser() {
return System.getProperty("user.name");
}
/**
* The IP and hostname of this machine
*
* @return hostname/ip as a String.
*/
String getHost() {
try {
return java.net.InetAddress.getLocalHost().toString();
} catch (UnknownHostException e) {
return "UknownHost";
}
}
/**
* The date the build was started.
*
* @return Date the build was started.
*/
Date getDate() {
return date;
}
String getValueFrom(Object value) {
if (value instanceof String) {
return "\"" + value.toString() + "\"";
}
if (value instanceof Date) {
return "new java.util.Date(" + Long.toString(((Date) value).getTime()) + "L)";
}
if (value instanceof Integer) {
return value.toString();
}
return ((null == value) ? "null" : "\"" + value.getClass() + " = " + value.toString() + "\"");
// TODO better defualt case
}
}
--- NEW FILE: AntTask.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.Project;
import org.apache.tools.ant.Task;
/**
* @author [email protected]
*/
public abstract class AntTask extends Task {
private final static int DISPLAY_WIDTH = 50;
public void init() {
}
public void execute() throws BuildException {
log("Execute Synchronize...");
try {
performExecute();
}
finally {
}
}
public abstract void performExecute() throws BuildException;
protected void logPair(
String leftString,
String rightString,
boolean evenNotOdd) {
logPair(
Project.MSG_INFO,
leftString,
rightString,
DISPLAY_WIDTH,
evenNotOdd);
}
protected void logPair(
String leftString,
String rightString,
char ch) {
logPair(
Project.MSG_INFO,
leftString,
rightString,
DISPLAY_WIDTH,
ch);
}
protected void logPair(
String leftString,
String rightString,
int displayWidth,
boolean evenNotOdd) {
logPair(
Project.MSG_INFO,
leftString,
rightString,
displayWidth,
evenNotOdd);
}
protected void logPair(
String leftString,
String rightString,
int displayWidth,
char ch) {
logPair(
Project.MSG_INFO,
leftString,
rightString,
displayWidth,
ch);
}
protected void logPair(
int severity,
String leftString,
String rightString,
boolean evenNotOdd) {
logPair(severity, leftString, rightString, DISPLAY_WIDTH, evenNotOdd);
}
protected void logPair(
int severity,
String leftString,
String rightString,
int displayWidth,
boolean evenNotOdd) {
logPair(
severity,
leftString,
rightString,
displayWidth,
evenNotOdd ? '.' : '_');
}
protected void logPair(
int severity,
String leftString,
String rightString,
int displayWidth,
char ch) {
StringBuffer output = new StringBuffer();
int leftLength = leftString.length();
int rightLength = rightString.length();
int combinedLength = leftLength + rightLength;
// Format output
output.append(leftString);
int padding =
(combinedLength < displayWidth) ? displayWidth - combinedLength : 1;
for (int ii = 0; ii < padding; ++ii) {
output.append(ch);
}
output.append(rightString);
log(output.toString(), severity);
}
protected void logSeparator() {
logSeparator(Project.MSG_INFO, DISPLAY_WIDTH, true);
}
protected void logSeparator(boolean evenNotOdd) {
logSeparator(Project.MSG_INFO, DISPLAY_WIDTH, evenNotOdd);
}
protected void logSeparator(int severity, boolean evenNotOdd) {
logSeparator(severity, DISPLAY_WIDTH, evenNotOdd);
}
protected void logSeparator(
int severity,
int displayWidth,
boolean evenNotOdd) {
logSeparator(severity, displayWidth, evenNotOdd ? '.' : '_');
}
protected void logSeparator(
int severity,
int displayWidth,
char ch) {
StringBuffer output = new StringBuffer();
// Format output
for (int ii = 0; ii < displayWidth; ++ii) {
output.append(ch);
}
log(output.toString(), severity);
}
}
-------------------------------------------------------
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