Skip to content

Commit

Permalink
clean up system properties, deprecate javax/jakarta ones
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Dec 20, 2022
1 parent 8065afc commit 5c6d8cb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -23,12 +23,11 @@ class LogSupport {

static {
try {
debug = Boolean.getBoolean("jakarta.activation.debug") ||
Boolean.getBoolean("javax.activation.debug");
debug = Boolean.getBoolean("angus.activation.debug");
} catch (Throwable t) {
// ignore any errors
}
logger = Logger.getLogger("jakarta.activation");
logger = Logger.getLogger("angus.activation");
}

/**
Expand All @@ -39,12 +38,18 @@ private LogSupport() {
}

public static void log(String msg) {
if (!isLoggable()) {
return;
}
if (debug)
System.out.println(msg);
logger.log(level, msg);
}

public static void log(String msg, Throwable t) {
if (!isLoggable()) {
return;
}
if (debug)
System.out.println(msg + "; Exception: " + t);
logger.log(level, msg, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ public class MailcapFile implements MailcapRegistry {

static {
try {
addReverse = Boolean.getBoolean("jakarta.activation.addreverse") ||
Boolean.getBoolean("javax.activation.addreverse");
addReverse = Boolean.getBoolean("angus.activation.addreverse");
// deprecated in 1.1.0:
String prop = System.getProperty("jakarta.activation.addreverse");
if (prop != null) {
LogSupport.log("'jakarta.activation.addreverse' property is deprecated, use 'angus.activation.addreverse' instead");
addReverse = Boolean.parseBoolean(prop);
}
prop = System.getProperty("javax.activation.addreverse");
if (prop != null) {
LogSupport.log("'javax.activation.addreverse' property is deprecated, use 'angus.activation.addreverse' instead");
addReverse = Boolean.parseBoolean(prop);
}
} catch (Throwable t) {
// ignore any errors
}
Expand All @@ -68,8 +78,7 @@ public class MailcapFile implements MailcapRegistry {
* @throws IOException for I/O errors
*/
public MailcapFile(String new_fname) throws IOException {
if (LogSupport.isLoggable())
LogSupport.log("new MailcapFile: file " + new_fname);
LogSupport.log("new MailcapFile: file " + new_fname);
try (BufferedReader reader = new BufferedReader(new FileReader(new_fname))) {
parse(reader);
}
Expand All @@ -82,17 +91,15 @@ public MailcapFile(String new_fname) throws IOException {
* @throws IOException for I/O errors
*/
public MailcapFile(InputStream is) throws IOException {
if (LogSupport.isLoggable())
LogSupport.log("new MailcapFile: InputStream");
LogSupport.log("new MailcapFile: InputStream");
parse(new BufferedReader(new InputStreamReader(is, StandardCharsets.ISO_8859_1)));
}

/**
* Mailcap file default constructor.
*/
public MailcapFile() {
if (LogSupport.isLoggable())
LogSupport.log("new MailcapFile: default");
LogSupport.log("new MailcapFile: default");
}

/**
Expand Down Expand Up @@ -232,8 +239,7 @@ private Map<String, List<String>> mergeResults(Map<String, List<String>> first,
* @param mail_cap the mailcap string
*/
public void appendToMailcap(String mail_cap) {
if (LogSupport.isLoggable())
LogSupport.log("appendToMailcap: " + mail_cap);
LogSupport.log("appendToMailcap: " + mail_cap);
try {
parse(new BufferedReader(new StringReader(mail_cap)));
} catch (IOException ex) {
Expand Down Expand Up @@ -300,8 +306,7 @@ protected void parseLine(String mailcapEntry)
MailcapTokenizer tokenizer = new MailcapTokenizer(mailcapEntry);
tokenizer.setIsAutoquoting(false);

if (LogSupport.isLoggable())
LogSupport.log("parse: " + mailcapEntry);
LogSupport.log("parse: " + mailcapEntry);
// parse the primary type
int currentToken = tokenizer.nextToken();
if (currentToken != MailcapTokenizer.STRING_TOKEN) {
Expand Down Expand Up @@ -339,8 +344,7 @@ protected void parseLine(String mailcapEntry)

String mimeType = primaryType + "/" + subType;

if (LogSupport.isLoggable())
LogSupport.log(" Type: " + mimeType);
LogSupport.log(" Type: " + mimeType);

// now setup the commands hashtable
Map<String, List<String>> commands = new LinkedHashMap<>(); // keep commands in order found
Expand Down Expand Up @@ -435,8 +439,7 @@ protected void parseLine(String mailcapEntry)
} else {

// setup the class entry list
if (LogSupport.isLoggable())
LogSupport.log(" Command: " + commandName +
LogSupport.log(" Command: " + commandName +
", Class: " + paramValue);
List<String> classes = commands.computeIfAbsent(commandName, k -> new ArrayList<>());
if (addReverse)
Expand All @@ -456,8 +459,7 @@ protected void parseLine(String mailcapEntry)
if (curcommands == null) {
masterHash.put(mimeType, commands);
} else {
if (LogSupport.isLoggable())
LogSupport.log("Merging commands for type " + mimeType);
LogSupport.log("Merging commands for type " + mimeType);
// have to merge current and new commands
// first, merge list of classes for commands already known
Iterator<String> cn = curcommands.keySet().iterator();
Expand Down Expand Up @@ -516,13 +518,6 @@ protected static void reportParseError(int expectedToken,
protected static void reportParseError(int expectedToken,
int otherExpectedToken, int anotherExpectedToken, int actualToken,
String actualTokenValue) throws MailcapParseException {
if (LogSupport.isLoggable())
LogSupport.log("PARSE ERROR: " + "Encountered a " +
MailcapTokenizer.nameForToken(actualToken) + " token (" +
actualTokenValue + ") while expecting a " +
MailcapTokenizer.nameForToken(expectedToken) + ", a " +
MailcapTokenizer.nameForToken(otherExpectedToken) + ", or a " +
MailcapTokenizer.nameForToken(anotherExpectedToken) + " token.");
throw new MailcapParseException("Encountered a " +
MailcapTokenizer.nameForToken(actualToken) + " token (" +
actualTokenValue + ") while expecting a " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ private void parseEntry(String line) {
lt.hasMoreTokens())
value = lt.nextToken();
if (value == null) {
if (LogSupport.isLoggable())
LogSupport.log("Bad .mime.types entry: " + line);
LogSupport.log("Bad .mime.types entry: " + line);
return;
}
if (name.equals("type"))
Expand All @@ -179,8 +178,7 @@ else if (name.equals("exts")) {
MimeTypeEntry entry =
new MimeTypeEntry(mime_type, file_ext);
type_hash.put(file_ext, entry);
if (LogSupport.isLoggable())
LogSupport.log("Added: " + entry);
LogSupport.log("Added: " + entry);
}
}
}
Expand All @@ -201,8 +199,7 @@ else if (name.equals("exts")) {
file_ext = strtok.nextToken();
entry = new MimeTypeEntry(mime_type, file_ext);
type_hash.put(file_ext, entry);
if (LogSupport.isLoggable())
LogSupport.log("Added: " + entry);
LogSupport.log("Added: " + entry);
}
}
}
Expand Down Expand Up @@ -294,7 +291,7 @@ public String nextToken() {
String s;

if (filter) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = start + 1; i < currentPosition - 1; i++) {
c = str.charAt(i);
if (c != '\\')
Expand Down
10 changes: 9 additions & 1 deletion docs/src/main/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ to `org.eclipse.angus.activation` and package name from

## December TBD, 2022 - Angus Activation 1.1.0 Final Release

Adds built-in support for GraalVM native-image, support for OSGi Mediator Specification.
Adds built-in support for GraalVM native-image, support for OSGi Mediator Specification,
clean up supported system properties.

| system property | description | value |
|:----------------------------|:------------------------------------------------------|:----------------------------|
| angus.activation.addreverse | Read mailcap file from the end | **false** (default) / true |
| angus.activation.debug | Print log messages, logger name is `angus.activation` | **false** (default) / true |


| native-image option | description | value |
|:-------------------------------------|:------------------------------------------|:---------------------------|
| angus.activation.native-image.enable | Turn on built-in support for native image | false / **true** (default) |
| angus.activation.native-image.trace | Print log messages to `System.out` | **false** (default) / true |

System properties with `jakarta.activation`/`javax.activation` prefix are deprecated and future
versions of Angus Activation ignore them.

## December 14, 2021 - Angus Activation 1.0.0 Final Release

Expand Down

0 comments on commit 5c6d8cb

Please sign in to comment.