Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/files
In directory sc8-pr-cvs1:/tmp/cvs-serv14802/src/java/core/org/krysalis/ruper2/files
Modified Files:
ExtensionTable.java DefaultResourceFilenameAnalyzer.java
Log Message:
1) Made ResourceAnalysis extract the group (from grandparent dir)
2) Added some unit tests for this.
Index: ExtensionTable.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/files/ExtensionTable.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ExtensionTable.java 29 Sep 2003 18:09:16 -0000 1.1
--- ExtensionTable.java 8 Oct 2003 18:28:34 -0000 1.2
***************
*** 7,10 ****
--- 7,12 ----
import java.util.Map;
+ import org.krysalis.ruper2.resource.ResourceType;
+
/**
* @author arb_jack
***************
*** 18,55 ****
String m_description;
String m_mime;
! ExtensionEntry(String extn, String description, String mime) {
m_extn = extn;
m_description = description;
m_mime = mime;
}
-
}
! public boolean hasExtension(String extension)
! {
return m_extnMap.containsKey(extension);
}
!
! public static ExtensionTable EXTENSION_TABLE = null;
static {
! EXTENSION_TABLE = new ExtensionTable();
! EXTENSION_TABLE.register("jar", "Java Archive", "TODO");
! EXTENSION_TABLE.register("tar", "Tape Archive", "TODO");
! EXTENSION_TABLE.register("zip", "ZIP Archive", "TODO");
! EXTENSION_TABLE.register("tar.Z", "Compressed Tape Archive", "TODO");
}
! private void register(String extn, String desc, String mime) {
! registerEntry(new ExtensionTable.ExtensionEntry(extn, desc, mime));
}
! private void registerEntry(ExtensionEntry entry) {
m_extnMap.put(entry.m_extn, entry);
m_mimeMap.put(entry.m_mime, entry);
! }
private ExtensionEntry getEntryByExtension(String extn) {
--- 20,84 ----
String m_description;
String m_mime;
+ ResourceType m_type;
! ExtensionEntry(
! String extn,
! String description,
! String mime,
! ResourceType type) {
m_extn = extn;
m_description = description;
m_mime = mime;
+ m_type = type;
}
}
! public boolean hasExtension(String extension) {
return m_extnMap.containsKey(extension);
}
! public static ExtensionTable DEFAULT_EXTENSION_TABLE = null;
static {
! DEFAULT_EXTENSION_TABLE = new ExtensionTable();
! DEFAULT_EXTENSION_TABLE.register(
! "jar",
! "Java Archive",
! "TODO",
! ResourceType.JAVA_BINARY);
! DEFAULT_EXTENSION_TABLE.register("tar", "Tape Archive", "TODO", null);
! DEFAULT_EXTENSION_TABLE.register("zip", "ZIP Archive", "TODO", null);
! DEFAULT_EXTENSION_TABLE.register(
! "tar.Z",
! "Compressed Tape Archive",
! "TODO",
! null);
}
! public void register(
! String extn,
! String desc,
! String mime,
! ResourceType type) {
! registerEntry(
! new ExtensionTable.ExtensionEntry(extn, desc, mime, type));
}
! public ResourceType getTypeFromExtension(String extn) {
! ResourceType type = ResourceType.UNKNOWN;
!
! ExtensionEntry entry = getEntryByExtension(extn);
!
! if ((null != entry) && (null != entry.m_type))
! type = entry.m_type;
!
! return type;
! }
!
! public void registerEntry(ExtensionEntry entry) {
m_extnMap.put(entry.m_extn, entry);
m_mimeMap.put(entry.m_mime, entry);
! }
private ExtensionEntry getEntryByExtension(String extn) {
***************
*** 60,62 ****
--- 89,92 ----
return (ExtensionEntry) m_mimeMap.get(mime);
}
+
}
Index: DefaultResourceFilenameAnalyzer.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/files/DefaultResourceFilenameAnalyzer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DefaultResourceFilenameAnalyzer.java 8 Oct 2003 13:23:22 -0000 1.3
--- DefaultResourceFilenameAnalyzer.java 8 Oct 2003 18:28:34 -0000 1.4
***************
*** 18,21 ****
--- 18,22 ----
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.resource.Resource;
+ import org.krysalis.ruper2.resource.ResourceGroup;
import org.krysalis.ruper2.resource.ResourceType;
import org.krysalis.ruper2.util.RuperConstants;
***************
*** 32,38 ****
--- 33,48 ----
implements ResourceFilenameAnalyzer {
private VirtualResourceLocator m_base = null;
+ private ExtensionTable m_extensionTable = null;
public DefaultResourceFilenameAnalyzer(VirtualResourceLocator base) {
m_base = base;
+ m_extensionTable = ExtensionTable.DEFAULT_EXTENSION_TABLE;
+ }
+
+ public DefaultResourceFilenameAnalyzer(
+ VirtualResourceLocator base,
+ ExtensionTable extns) {
+ m_base = base;
+ m_extensionTable = extns;
}
***************
*** 73,77 ****
extension.length() - RuperConstants.MD5_EXTN.length());
orig.setExtension(newExtn);
!
m_md5map.put(orig, resource.getLocation());
}
--- 83,87 ----
extension.length() - RuperConstants.MD5_EXTN.length());
orig.setExtension(newExtn);
!
m_md5map.put(orig, resource.getLocation());
}
***************
*** 191,207 ****
ResourceWorkingStore store)
throws RuperException {
! String name = resourceVRL.toExternalForm();
! int sepPosn = name.lastIndexOf('/');
! String baseName = (-1 == sepPosn) ? name : name.substring(sepPosn + 1);
! processString(baseName, resourceVRL, store);
}
void processFile(File resource, ResourceWorkingStore store)
throws RuperException {
String name = resource.getName().toString();
int sepPosn = name.lastIndexOf(File.pathSeparator);
String baseName = (-1 == sepPosn) ? name : name.substring(sepPosn + 1);
! processString(baseName, new VirtualResourceLocator(resource), store);
}
--- 201,258 ----
ResourceWorkingStore store)
throws RuperException {
!
! // :TODO: Hacky
! String group = null;
! VirtualResourceLocator parentVRL = resourceVRL.getParent();
! if (null != parentVRL) {
! VirtualResourceLocator grandparentVRL = parentVRL.getParent();
! if (null != grandparentVRL) {
! group = grandparentVRL.getBasename();
! }
! }
!
! processString(resourceVRL.getBasename(), group, resourceVRL, store);
}
void processFile(File resource, ResourceWorkingStore store)
throws RuperException {
+
+ // Get file basename
String name = resource.getName().toString();
int sepPosn = name.lastIndexOf(File.pathSeparator);
String baseName = (-1 == sepPosn) ? name : name.substring(sepPosn + 1);
! // :TODO: Hacky
! String group = null;
! File parent = resource.getParentFile();
! if (null != parent) {
! File grandparent = parent.getParentFile();
! if (null != grandparent) {
!
! String gname = grandparent.getName().toString();
! int gsepPosn = name.lastIndexOf(File.pathSeparator);
! String gbaseName =
! (-1 == sepPosn) ? name : name.substring(sepPosn + 1);
!
! group = gbaseName;
! }
! }
!
! processString(
! baseName,
! group,
! new VirtualResourceLocator(resource),
! store);
! }
!
! //
! //
! //
! void processString(
! String resourceName,
! VirtualResourceLocator location,
! ResourceWorkingStore store)
! throws RuperException {
! processString(resourceName, null, location, store);
}
***************
*** 212,215 ****
--- 263,267 ----
void processString(
String resourceName,
+ String groupStr,
VirtualResourceLocator location,
ResourceWorkingStore store)
***************
*** 239,243 ****
// Type is anything after the last - or _ so long as
// it doesn't start with a digit (i.e. is the version)
! // .. and so long as it isn't a release level
//
int typePosn = findLastSeparator(remainder);
--- 291,300 ----
// Type is anything after the last - or _ so long as
// it doesn't start with a digit (i.e. is the version)
! // .. and/or release level
! //
! // Hmm, but what of filenames w/ no version, where the
! // name contains one of these. Let's check that what we
! // get is a 'known' type, e.g. src/docs/etc. Not pretty,
! // but...
//
int typePosn = findLastSeparator(remainder);
***************
*** 251,254 ****
--- 308,316 ----
type = null; // ResourceType.JAVA_BINARY;
}
+ else if (
+ ResourceType.UNKNOWN.equals(
+ ResourceType.getFromString(type))) {
+ type = null;
+ }
else {
***************
*** 257,265 ****
//
remainder = remainder.substring(0, typePosn);
-
}
}
}
//
// Version is anything after the first - or _ followed
--- 319,331 ----
//
remainder = remainder.substring(0, typePosn);
}
}
}
+ // Take a stab...
+ if (null == type) {
+ type = m_extensionTable.getTypeFromExtension(extension).toString();
+ }
+
//
// Version is anything after the first - or _ followed
***************
*** 277,281 ****
Messages.getString(
MessageConstants.EXTRACTED,
! new Object[] { name, version, type, extension }));
//
--- 343,347 ----
Messages.getString(
MessageConstants.EXTRACTED,
! new Object[] { groupStr, name, version, type, extension }));
//
***************
*** 287,292 ****
--- 353,362 ----
if (!ignore)
try {
+ ResourceGroup group =
+ new ResourceGroup((null == groupStr) ? name : groupStr);
+
Resource temp =
new Resource(
+ group,
name,
(null == version ? null : new KrysalisVersion(version)),
***************
*** 389,393 ****
String extn = (String) i.next();
! if (ExtensionTable.EXTENSION_TABLE.hasExtension(extn))
extension = extn;
}
--- 459,463 ----
String extn = (String) i.next();
! if (m_extensionTable.hasExtension(extn))
extension = extn;
}
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
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.