You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/12/03 00:33:32 UTC
[commons-compress] 03/04: Sort members.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 2e4b0d67233a1547d038edce374fdb3a2bb513e8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 2 19:11:50 2021 -0500
Sort members.
---
.../compress/harmony/pack200/PackingOptions.java | 318 ++++++++++-----------
1 file changed, 159 insertions(+), 159 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java b/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java
index fdb9df8..19b33f4 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/PackingOptions.java
@@ -53,89 +53,144 @@ public class PackingOptions {
private Attribute[] unknownAttributeTypes;
- public boolean isGzip() {
- return gzip;
+ public void addClassAttributeAction(final String attributeName, final String action) {
+ classAttributeActions.put(attributeName, action);
}
- public void setGzip(final boolean gzip) {
- this.gzip = gzip;
+ public void addCodeAttributeAction(final String attributeName, final String action) {
+ codeAttributeActions.put(attributeName, action);
}
- public boolean isStripDebug() {
- return stripDebug;
+ public void addFieldAttributeAction(final String attributeName, final String action) {
+ fieldAttributeActions.put(attributeName, action);
+ }
+
+ public void addMethodAttributeAction(final String attributeName, final String action) {
+ methodAttributeActions.put(attributeName, action);
+ }
+
+ private void addOrUpdateAttributeActions(final List<Attribute> prototypes, final Map<String, String> attributeActions, final int tag) {
+ if ((attributeActions != null) && (attributeActions.size() > 0)) {
+ NewAttribute newAttribute;
+ for (String name : attributeActions.keySet()) {
+ String action = attributeActions.get(name);
+ boolean prototypeExists = false;
+ for (Object prototype : prototypes) {
+ newAttribute = (NewAttribute) prototype;
+ if (newAttribute.type.equals(name)) {
+ // if the attribute exists, update its context
+ newAttribute.addContext(tag);
+ prototypeExists = true;
+ break;
+ }
+ }
+ // if no attribute is found, add a new attribute
+ if (!prototypeExists) {
+ if (ERROR.equals(action)) {
+ newAttribute = new NewAttribute.ErrorAttribute(name, tag);
+ } else if (STRIP.equals(action)) {
+ newAttribute = new NewAttribute.StripAttribute(name, tag);
+ } else if (PASS.equals(action)) {
+ newAttribute = new NewAttribute.PassAttribute(name, tag);
+ } else {
+ newAttribute = new NewAttribute(name, action, tag);
+ }
+ prototypes.add(newAttribute);
+ }
+ }
+ }
}
/**
- * Set strip debug attributes. If true, all debug attributes (i.e. LineNumberTable, SourceFile, LocalVariableTable
- * and LocalVariableTypeTable attributes) are stripped when reading the input class files and not included in the
- * output archive.
+ * Tell the compressor to pass the file with the given name, or if the name is a directory name all files under that
+ * directory will be passed.
*
- * @param stripDebug If true, all debug attributes.
+ * @param passFileName the file name
*/
- public void setStripDebug(final boolean stripDebug) {
- this.stripDebug = stripDebug;
+ public void addPassFile(String passFileName) {
+ String fileSeparator = System.getProperty("file.separator");
+ if (fileSeparator.equals("\\")) {
+ // Need to escape backslashes for replaceAll(), which uses regex
+ fileSeparator += "\\";
+ }
+ passFileName = passFileName.replaceAll(fileSeparator, "/");
+ passFiles.add(passFileName);
}
- public boolean isKeepFileOrder() {
- return keepFileOrder;
+ public String getDeflateHint() {
+ return deflateHint;
}
- public void setKeepFileOrder(final boolean keepFileOrder) {
- this.keepFileOrder = keepFileOrder;
+ public int getEffort() {
+ return effort;
+ }
+
+ public String getLogFile() {
+ return logFile;
+ }
+
+ public String getModificationTime() {
+ return modificationTime;
}
public long getSegmentLimit() {
return segmentLimit;
}
- /**
- * Set the segment limit (equivalent to -S command line option)
- *
- * @param segmentLimit - the limit in bytes
- */
- public void setSegmentLimit(final long segmentLimit) {
- this.segmentLimit = segmentLimit;
+ public String getUnknownAttributeAction() {
+ return unknownAttributeAction;
}
- public int getEffort() {
- return effort;
+ public Attribute[] getUnknownAttributePrototypes() {
+ if (unknownAttributeTypes == null) {
+ final List<Attribute> prototypes = new ArrayList<>();
+ addOrUpdateAttributeActions(prototypes, classAttributeActions, AttributeDefinitionBands.CONTEXT_CLASS);
+ addOrUpdateAttributeActions(prototypes, methodAttributeActions, AttributeDefinitionBands.CONTEXT_METHOD);
+ addOrUpdateAttributeActions(prototypes, fieldAttributeActions, AttributeDefinitionBands.CONTEXT_FIELD);
+ addOrUpdateAttributeActions(prototypes, codeAttributeActions, AttributeDefinitionBands.CONTEXT_CODE);
+ unknownAttributeTypes = prototypes.toArray(new Attribute[0]);
+ }
+ return unknownAttributeTypes;
}
- /**
- * Sets the compression effort level (0-9, equivalent to -E command line option)
- *
- * @param effort the compression effort level, 0-9.
- */
- public void setEffort(final int effort) {
- this.effort = effort;
+ public String getUnknownClassAttributeAction(final String type) {
+ if (classAttributeActions == null) {
+ return unknownAttributeAction;
+ }
+ return classAttributeActions.getOrDefault(type, unknownAttributeAction);
}
- public String getDeflateHint() {
- return deflateHint;
+ public String getUnknownCodeAttributeAction(final String type) {
+ if (codeAttributeActions == null) {
+ return unknownAttributeAction;
+ }
+ return codeAttributeActions.getOrDefault(type, unknownAttributeAction);
}
- public boolean isKeepDeflateHint() {
- return KEEP.equals(deflateHint);
+ public String getUnknownFieldAttributeAction(final String type) {
+ if (fieldAttributeActions == null) {
+ return unknownAttributeAction;
+ }
+ return fieldAttributeActions.getOrDefault(type, unknownAttributeAction);
}
- public void setDeflateHint(final String deflateHint) {
- if (!KEEP.equals(deflateHint) && !"true".equals(deflateHint) && !"false".equals(deflateHint)) {
- throw new IllegalArgumentException(
- "Bad argument: -H " + deflateHint + " ? deflate hint should be either true, false or keep (default)");
+ public String getUnknownMethodAttributeAction(final String type) {
+ if (methodAttributeActions == null) {
+ return unknownAttributeAction;
}
- this.deflateHint = deflateHint;
+ return methodAttributeActions.getOrDefault(type, unknownAttributeAction);
}
- public String getModificationTime() {
- return modificationTime;
+ public boolean isGzip() {
+ return gzip;
}
- public void setModificationTime(final String modificationTime) {
- if (!KEEP.equals(modificationTime) && !"latest".equals(modificationTime)) {
- throw new IllegalArgumentException("Bad argument: -m " + modificationTime
- + " ? transmit modtimes should be either latest or keep (default)");
- }
- this.modificationTime = modificationTime;
+ public boolean isKeepDeflateHint() {
+ return KEEP.equals(deflateHint);
+ }
+
+ public boolean isKeepFileOrder() {
+ return keepFileOrder;
}
public boolean isPassFile(final String passFileName) {
@@ -157,149 +212,94 @@ public class PackingOptions {
return false;
}
- /**
- * Tell the compressor to pass the file with the given name, or if the name is a directory name all files under that
- * directory will be passed.
- *
- * @param passFileName the file name
- */
- public void addPassFile(String passFileName) {
- String fileSeparator = System.getProperty("file.separator");
- if (fileSeparator.equals("\\")) {
- // Need to escape backslashes for replaceAll(), which uses regex
- fileSeparator += "\\";
- }
- passFileName = passFileName.replaceAll(fileSeparator, "/");
- passFiles.add(passFileName);
+ public boolean isStripDebug() {
+ return stripDebug;
+ }
+
+ public boolean isVerbose() {
+ return verbose;
}
public void removePassFile(final String passFileName) {
passFiles.remove(passFileName);
}
- public String getUnknownAttributeAction() {
- return unknownAttributeAction;
+ public void setDeflateHint(final String deflateHint) {
+ if (!KEEP.equals(deflateHint) && !"true".equals(deflateHint) && !"false".equals(deflateHint)) {
+ throw new IllegalArgumentException(
+ "Bad argument: -H " + deflateHint + " ? deflate hint should be either true, false or keep (default)");
+ }
+ this.deflateHint = deflateHint;
}
/**
- * Tell the compressor what to do if an unknown attribute is encountered
+ * Sets the compression effort level (0-9, equivalent to -E command line option)
*
- * @param unknownAttributeAction - the action to perform
+ * @param effort the compression effort level, 0-9.
*/
- public void setUnknownAttributeAction(final String unknownAttributeAction) {
- this.unknownAttributeAction = unknownAttributeAction;
- if (!PASS.equals(unknownAttributeAction) && !ERROR.equals(unknownAttributeAction)
- && !STRIP.equals(unknownAttributeAction)) {
- throw new RuntimeException("Incorrect option for -U, " + unknownAttributeAction);
- }
- }
-
- public void addClassAttributeAction(final String attributeName, final String action) {
- classAttributeActions.put(attributeName, action);
- }
-
- public void addFieldAttributeAction(final String attributeName, final String action) {
- fieldAttributeActions.put(attributeName, action);
- }
-
- public void addMethodAttributeAction(final String attributeName, final String action) {
- methodAttributeActions.put(attributeName, action);
- }
-
- public void addCodeAttributeAction(final String attributeName, final String action) {
- codeAttributeActions.put(attributeName, action);
- }
-
- public boolean isVerbose() {
- return verbose;
- }
-
- public void setVerbose(final boolean verbose) {
- this.verbose = verbose;
+ public void setEffort(final int effort) {
+ this.effort = effort;
}
- public void setQuiet(final boolean quiet) {
- this.verbose = !quiet;
+ public void setGzip(final boolean gzip) {
+ this.gzip = gzip;
}
- public String getLogFile() {
- return logFile;
+ public void setKeepFileOrder(final boolean keepFileOrder) {
+ this.keepFileOrder = keepFileOrder;
}
public void setLogFile(final String logFile) {
this.logFile = logFile;
}
- private void addOrUpdateAttributeActions(final List<Attribute> prototypes, final Map<String, String> attributeActions, final int tag) {
- if ((attributeActions != null) && (attributeActions.size() > 0)) {
- NewAttribute newAttribute;
- for (String name : attributeActions.keySet()) {
- String action = attributeActions.get(name);
- boolean prototypeExists = false;
- for (Object prototype : prototypes) {
- newAttribute = (NewAttribute) prototype;
- if (newAttribute.type.equals(name)) {
- // if the attribute exists, update its context
- newAttribute.addContext(tag);
- prototypeExists = true;
- break;
- }
- }
- // if no attribute is found, add a new attribute
- if (!prototypeExists) {
- if (ERROR.equals(action)) {
- newAttribute = new NewAttribute.ErrorAttribute(name, tag);
- } else if (STRIP.equals(action)) {
- newAttribute = new NewAttribute.StripAttribute(name, tag);
- } else if (PASS.equals(action)) {
- newAttribute = new NewAttribute.PassAttribute(name, tag);
- } else {
- newAttribute = new NewAttribute(name, action, tag);
- }
- prototypes.add(newAttribute);
- }
- }
+ public void setModificationTime(final String modificationTime) {
+ if (!KEEP.equals(modificationTime) && !"latest".equals(modificationTime)) {
+ throw new IllegalArgumentException("Bad argument: -m " + modificationTime
+ + " ? transmit modtimes should be either latest or keep (default)");
}
+ this.modificationTime = modificationTime;
}
- public Attribute[] getUnknownAttributePrototypes() {
- if (unknownAttributeTypes == null) {
- final List<Attribute> prototypes = new ArrayList<>();
- addOrUpdateAttributeActions(prototypes, classAttributeActions, AttributeDefinitionBands.CONTEXT_CLASS);
- addOrUpdateAttributeActions(prototypes, methodAttributeActions, AttributeDefinitionBands.CONTEXT_METHOD);
- addOrUpdateAttributeActions(prototypes, fieldAttributeActions, AttributeDefinitionBands.CONTEXT_FIELD);
- addOrUpdateAttributeActions(prototypes, codeAttributeActions, AttributeDefinitionBands.CONTEXT_CODE);
- unknownAttributeTypes = prototypes.toArray(new Attribute[0]);
- }
- return unknownAttributeTypes;
+ public void setQuiet(final boolean quiet) {
+ this.verbose = !quiet;
}
- public String getUnknownClassAttributeAction(final String type) {
- if (classAttributeActions == null) {
- return unknownAttributeAction;
- }
- return classAttributeActions.getOrDefault(type, unknownAttributeAction);
+ /**
+ * Set the segment limit (equivalent to -S command line option)
+ *
+ * @param segmentLimit - the limit in bytes
+ */
+ public void setSegmentLimit(final long segmentLimit) {
+ this.segmentLimit = segmentLimit;
}
- public String getUnknownMethodAttributeAction(final String type) {
- if (methodAttributeActions == null) {
- return unknownAttributeAction;
- }
- return methodAttributeActions.getOrDefault(type, unknownAttributeAction);
+ /**
+ * Set strip debug attributes. If true, all debug attributes (i.e. LineNumberTable, SourceFile, LocalVariableTable
+ * and LocalVariableTypeTable attributes) are stripped when reading the input class files and not included in the
+ * output archive.
+ *
+ * @param stripDebug If true, all debug attributes.
+ */
+ public void setStripDebug(final boolean stripDebug) {
+ this.stripDebug = stripDebug;
}
- public String getUnknownFieldAttributeAction(final String type) {
- if (fieldAttributeActions == null) {
- return unknownAttributeAction;
+ /**
+ * Tell the compressor what to do if an unknown attribute is encountered
+ *
+ * @param unknownAttributeAction - the action to perform
+ */
+ public void setUnknownAttributeAction(final String unknownAttributeAction) {
+ this.unknownAttributeAction = unknownAttributeAction;
+ if (!PASS.equals(unknownAttributeAction) && !ERROR.equals(unknownAttributeAction)
+ && !STRIP.equals(unknownAttributeAction)) {
+ throw new RuntimeException("Incorrect option for -U, " + unknownAttributeAction);
}
- return fieldAttributeActions.getOrDefault(type, unknownAttributeAction);
}
- public String getUnknownCodeAttributeAction(final String type) {
- if (codeAttributeActions == null) {
- return unknownAttributeAction;
- }
- return codeAttributeActions.getOrDefault(type, unknownAttributeAction);
+ public void setVerbose(final boolean verbose) {
+ this.verbose = verbose;
}
}