Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv20296/src/java/org/krysalis/version/impl
Modified Files:
KrysalisVersion.java
Added Files:
VersionImporter.java
Log Message:
First stab at replacing Formats with Specifications for "non-Krysalis" formats.
Fixed some bugs via new tests.
--- NEW FILE: VersionImporter.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name, without
prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in respect
of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.impl;
import java.util.Iterator;
import org.krysalis.version.Version;
import org.krysalis.version.exception.VersionException;
import org.krysalis.version.formatting.VersionFormat;
import org.krysalis.version.formatting.exception.VersionFormatException;
import org.krysalis.version.internal.VersionIdentifier;
import org.krysalis.version.internal.data.VersionData;
import org.krysalis.version.specification.VersionSpecification;
import org.krysalis.version.specification.VersionSpecificationFactory;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.note.AnnotationScratchpad;
/**
*
* @author $Author: arb_jack $
* @version $Revision: 1.1 $
*
*/
public class VersionImporter {
public static Version importVersion(String id, String data)
throws VersionException {
return importVersion(new VersionIdentifier(id), data);
}
public static Version importVersion(VersionIdentifier id, String data)
throws VersionException {
return importKrysalisVersion(id, data);
}
public static KrysalisVersion importKrysalisVersion(String id, String data)
throws VersionException {
return importKrysalisVersion(new VersionIdentifier(id), data);
}
public static KrysalisVersion importKrysalisVersion(
VersionIdentifier id,
String data)
throws VersionException {
KrysalisVersion version = null;
AnnotationScratchpad pad = new AnnotationScratchpad();
VersionException lastVersionException = null;
//
// Favour our specification
//
VersionSpecification krysalisSpecification =
VersionSpecificationFactory.createKrysalisVersionSpecification();
try {
VersionFormat format = krysalisSpecification.getVersionFormat();
VersionData versionData = format.parseVersion(data);
version =
new KrysalisVersion(id, krysalisSpecification, versionData);
}
catch (VersionFormatException vfe) {
lastVersionException = vfe;
}
catch (VersionException ve) {
lastVersionException = ve;
}
//
// Try all other specifications...
//
if (null == version)
for (Iterator i =
VersionSpecificationFactory.getRegisteredSpecificationIds();
i.hasNext();
) {
String specId = (String) i.next();
VersionSpecification spec =
VersionSpecificationFactory
.createVersionSpecificationFromId(
specId);
try {
VersionFormat format = spec.getVersionFormat();
VersionData versionData = format.parseVersion(data);
version = new KrysalisVersion(id, spec, versionData);
}
catch (VersionFormatException vfe) {
lastVersionException = vfe;
}
catch (VersionException ve) {
lastVersionException = ve;
}
}
if ((null == version) && (null != lastVersionException))
throw lastVersionException;
return version;
}
public static KrysalisVersion importKrysalisVersion(
String id,
VersionSpecification specification,
String data)
throws VersionException {
return importKrysalisVersion(
new VersionIdentifier(id),
specification,
data);
}
public static KrysalisVersion importKrysalisVersion(
VersionIdentifier id,
VersionSpecification specification,
String data)
throws VersionException {
KrysalisVersion version = null;
VersionFormat format = specification.getVersionFormat();
VersionData versionData = format.parseVersion(data);
version = new KrysalisVersion(id, specification, versionData);
return version;
}
public static void main(String args[]) throws VersionException {
if (args.length == 0)
System.err.println("Pass formatted versions (e.g.\"1.0\") as args");
for (int i = 0; i < args.length; ++i) {
String data = args[i];
KrysalisVersion version =
VersionImporter.importKrysalisVersion(
VersionIdentifier.BOGUS,
data);
System.out.println("========================================");
System.out.println("Format [" + data + "]");
DebugUtils.dump(version);
}
}
}
Index: KrysalisVersion.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/impl/KrysalisVersion.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** KrysalisVersion.java 7 Mar 2003 20:01:38 -0000 1.24
--- KrysalisVersion.java 10 Mar 2003 20:44:10 -0000 1.25
***************
*** 62,67 ****
import org.krysalis.version.Version;
import org.krysalis.version.exception.VersionException;
- import org.krysalis.version.formatting.VersionFormat;
- import org.krysalis.version.formatting.VersionFormatFactory;
import org.krysalis.version.formatting.exception.VersionFormatException;
import org.krysalis.version.internal.VersionIdentifier;
--- 62,65 ----
***************
*** 70,74 ****
--- 68,75 ----
import org.krysalis.version.internal.data.VersionData;
import org.krysalis.version.internal.data.VersionDataElement;
+ import org.krysalis.version.internal.data.VersionDataElementSet;
import org.krysalis.version.internal.data.util.VersionDataIncrementor;
+ import org.krysalis.version.specification.VersionSpecification;
+ import org.krysalis.version.specification.VersionSpecificationFactory;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.debug.Dumpable;
***************
*** 80,86 ****
private final VersionIdentifier m_identifier;
! private final VersionFormat m_format;
private final VersionData m_data;
/**
* Constructor for Version.
--- 81,126 ----
private final VersionIdentifier m_identifier;
! private final VersionSpecification m_specification;
private final VersionData m_data;
+ public static KrysalisVersion fromVersion(Version version) throws VersionException {
+ if (version instanceof KrysalisVersion)
+ return (KrysalisVersion) version;
+ else if (version instanceof CompoundVersion) {
+ return new KrysalisVersion((CompoundVersion) version);
+ }
+
+ return VersionImporter.importKrysalisVersion(
+ version.getId(),
+ version.getVersion());
+
+ }
+ /**
+ * Constructor for Version.
+ * @param other
+ */
+ public KrysalisVersion(KrysalisVersion other) {
+ super();
+
+ m_identifier = other.m_identifier;
+ m_specification = other.m_specification;
+ m_data = other.m_data;
+ }
+
+ public KrysalisVersion(CompoundVersion version) throws VersionException {
+ m_identifier = new VersionIdentifier(version.getId());
+ m_specification = VersionSpecificationFactory.createDefaultVersionSpecification();
+ m_data =
+ new VersionData(
+ VersionDataElementSet.DEFAULT,
+ version.getMajor(),
+ version.getMinor(),
+ version.getReleaseLevel(),
+ version.getReleaseQualifier(),
+ version.getPoint(),
+ version.getBuildNumber(),
+ version.getAttributes());
+ }
+
/**
* Constructor for Version.
***************
*** 91,95 ****
m_identifier = new VersionIdentifier(identifier);
! m_format = VersionFormatFactory.createDefaultVersionFormat();
m_data = new VersionData();
}
--- 131,136 ----
m_identifier = new VersionIdentifier(identifier);
! m_specification =
! VersionSpecificationFactory.createDefaultVersionSpecification();
m_data = new VersionData();
}
***************
*** 103,107 ****
m_identifier = new VersionIdentifier(identifier);
! m_format = VersionFormatFactory.createDefaultVersionFormat();
m_data = data;
}
--- 144,149 ----
m_identifier = new VersionIdentifier(identifier);
! m_specification =
! VersionSpecificationFactory.createDefaultVersionSpecification();
m_data = data;
}
***************
*** 115,119 ****
m_identifier = identifier;
! m_format = VersionFormatFactory.createDefaultVersionFormat();
m_data = data;
}
--- 157,162 ----
m_identifier = identifier;
! m_specification =
! VersionSpecificationFactory.createDefaultVersionSpecification();
m_data = data;
}
***************
*** 128,132 ****
m_identifier =
VersionIdentifierHelper.extractVersionIdentifier(getClass());
! m_format = VersionFormatFactory.createDefaultVersionFormat();
m_data = data;
}
--- 171,176 ----
m_identifier =
VersionIdentifierHelper.extractVersionIdentifier(getClass());
! m_specification =
! VersionSpecificationFactory.createDefaultVersionSpecification();
m_data = data;
}
***************
*** 136,146 ****
* @param other
*/
! public KrysalisVersion(String id, String data)
! throws VersionFormatException {
! super();
!
! m_identifier = VersionIdentifierHelper.extractVersionIdentifier(id);
! m_format = VersionFormatFactory.createDefaultVersionFormat();
! m_data = m_format.parseVersion(data);
}
--- 180,188 ----
* @param other
*/
! public KrysalisVersion(String id, String data) throws VersionException {
! this(
! VersionImporter.importKrysalisVersion(
! VersionIdentifierHelper.extractVersionIdentifier(id),
! data));
}
***************
*** 149,159 ****
* @param other
*/
! public KrysalisVersion(String id, VersionFormat format, String data)
! throws VersionFormatException {
! super();
! m_identifier = VersionIdentifierHelper.extractVersionIdentifier(id);
! m_format = format;
! m_data = m_format.parseVersion(data);
}
--- 191,213 ----
* @param other
*/
! public KrysalisVersion(VersionIdentifier id, String data)
! throws VersionException {
! this(VersionImporter.importKrysalisVersion(id, data));
! }
! /**
! * Constructor for Version.
! * @param other
! */
! public KrysalisVersion(
! String id,
! VersionSpecification specification,
! String data)
! throws VersionException {
! this(
! VersionImporter.importKrysalisVersion(
! VersionIdentifierHelper.extractVersionIdentifier(id),
! specification,
! data));
}
***************
*** 164,176 ****
public KrysalisVersion(
String id,
! VersionFormat format,
String data,
Map properties)
throws VersionFormatException, VersionException {
! super();
- m_identifier = VersionIdentifierHelper.extractVersionIdentifier(id);
- m_format = format;
- m_data = m_format.parseVersion(data);
m_data.importFromProperties(properties);
}
--- 218,227 ----
public KrysalisVersion(
String id,
! VersionSpecification specification,
String data,
Map properties)
throws VersionFormatException, VersionException {
! this(VersionImporter.importKrysalisVersion(id, specification, data));
m_data.importFromProperties(properties);
}
***************
*** 182,190 ****
public KrysalisVersion(String id, String data, Map properties)
throws VersionFormatException, VersionException {
! super();
!
! m_identifier = VersionIdentifierHelper.extractVersionIdentifier(id);
! m_format = VersionFormatFactory.createDefaultVersionFormat();
! m_data = m_format.parseVersion(data);
m_data.importFromProperties(properties);
}
--- 233,237 ----
public KrysalisVersion(String id, String data, Map properties)
throws VersionFormatException, VersionException {
! this(VersionImporter.importKrysalisVersion(id, data));
m_data.importFromProperties(properties);
}
***************
*** 198,206 ****
* @param other
*/
public KrysalisVersion(String id, Map properties) throws VersionException {
super();
m_identifier = VersionIdentifierHelper.extractVersionIdentifier(id);
! m_format = VersionFormatFactory.createDefaultVersionFormat();
m_data = new VersionData(properties);
}
--- 245,268 ----
* @param other
*/
+ public KrysalisVersion(VersionIdentifier id, Map properties) throws VersionException {
+ super();
+
+ m_identifier = id;
+ m_specification =
+ VersionSpecificationFactory.createDefaultVersionSpecification();
+ m_data = new VersionData(properties);
+ }
+
+
+ /**
+ * Constructor for Version.
+ * @param other
+ */
public KrysalisVersion(String id, Map properties) throws VersionException {
super();
m_identifier = VersionIdentifierHelper.extractVersionIdentifier(id);
! m_specification =
! VersionSpecificationFactory.createDefaultVersionSpecification();
m_data = new VersionData(properties);
}
***************
*** 341,345 ****
public KrysalisVersion(
String id,
! VersionFormat format,
int major,
int minor,
--- 403,407 ----
public KrysalisVersion(
String id,
! VersionSpecification format,
int major,
int minor,
***************
*** 422,428 ****
KrysalisVersion(
final String identifier,
! final VersionFormat format,
final VersionData data) {
! this(new VersionIdentifier(identifier), format, data);
}
--- 484,490 ----
KrysalisVersion(
final String identifier,
! final VersionSpecification specification,
final VersionData data) {
! this(new VersionIdentifier(identifier), specification, data);
}
***************
*** 435,442 ****
KrysalisVersion(
final VersionIdentifier identifier,
! final VersionFormat format,
final VersionData data) {
m_identifier = identifier;
! m_format = format;
m_data = data;
}
--- 497,504 ----
KrysalisVersion(
final VersionIdentifier identifier,
! final VersionSpecification format,
final VersionData data) {
m_identifier = identifier;
! m_specification = format;
m_data = data;
}
***************
*** 457,461 ****
public String getVersion() {
! return m_format.toVersionString(m_data);
}
--- 519,523 ----
public String getVersion() {
! return m_specification.getVersionFormat().toVersionString(m_data);
}
***************
*** 477,482 ****
if (null != m_identifier)
hashCode = m_identifier.hashCode();
! if (null != m_format)
! hashCode += m_format.hashCode();
if (null != m_data)
hashCode = m_data.hashCode();
--- 539,544 ----
if (null != m_identifier)
hashCode = m_identifier.hashCode();
! if (null != m_specification)
! hashCode += m_specification.hashCode();
if (null != m_data)
hashCode = m_data.hashCode();
***************
*** 496,500 ****
equal = otherVersion.m_data.equals(m_data);
! // :TODO: Format?
}
else
--- 558,562 ----
equal = otherVersion.m_data.equals(m_data);
! // :TODO: Specification?
}
else
***************
*** 551,558 ****
/**
* Returns the format.
! * @return VersionFormat
*/
! public VersionFormat getFormat() {
! return m_format;
}
--- 613,620 ----
/**
* Returns the format.
! * @return VersionSpecification
*/
! public VersionSpecification getSpecification() {
! return m_specification;
}
***************
*** 610,613 ****
--- 672,683 ----
/**
+ * Returns the releaseLevel.
+ * @return ReleaseLevel
+ */
+ public ReleaseLevel getReleaseLevelObject() {
+ return m_data.getReleaseLevel();
+ }
+
+ /**
* Returns the releaseQualifier.
* @return ReleaseQualifier
***************
*** 640,644 ****
// Construct the new immutable version
! return new KrysalisVersion(m_identifier, m_format, nextVersionData);
}
--- 710,717 ----
// Construct the new immutable version
! return new KrysalisVersion(
! m_identifier,
! m_specification,
! nextVersionData);
}
***************
*** 657,665 ****
}
! if (null != m_format) {
if (buffer.length() > 0)
buffer.append("|");
! buffer.append(m_format.toString());
}
--- 730,738 ----
}
! if (null != m_specification) {
if (buffer.length() > 0)
buffer.append("|");
! buffer.append(m_specification.toString());
}
***************
*** 676,683 ****
}
! if (null != m_format) {
out.print(indent);
! out.println("Format:");
! m_format.dump(out, depth + 1);
}
--- 749,756 ----
}
! if (null != m_specification) {
out.print(indent);
! out.println("Specification:");
! m_specification.dump(out, depth + 1);
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.