Skip to content

Commit

Permalink
JDO-823: Fix sonarcloud issues of type Code Smells (#67)
Browse files Browse the repository at this point in the history
* JDO-823: Methods should not be empty

* JDO-823: Child class fields should not shadow parent class fields

* JDO-823: Tests should include assertions

* JDO-823: String literals should not be duplicated

* JDO-823: A conditionally executed single line should be denoted by indentation

* JDO-823: Constant names should comply with a naming convention

* JDO-823: "switch" statements should have "default" clauses

* JDO-823: "@OverRide" should be used on overriding and implementing methods

* JDO-823: JUnit assertTrue/assertFalse should be simplified to the corresponding dedicated assertion

* JDO-823: Using Constants prefix when accessing constants from the Constants interface

* JDO-823: Sections of code should not be commented out

* JDO-823: Nested blocks of code should not be left empty

* JDO-823: "toString()" should never be called on a String object

* JDO-823: Local variables should not be declared and then immediately returned or thrown

* JDO-823: Field names should comply with a naming convention

* JDO-823: Collection.isEmpty() should be used to test for emptiness

* JDO-823: Deprecated "${pom}" properties should not be used

* JDO-823: Jump statements should not be redundant

* JDO-823: Review comments from Tilman
  • Loading branch information
mboapache authored Jan 12, 2023
1 parent 3b0d34a commit f748519
Show file tree
Hide file tree
Showing 36 changed files with 536 additions and 367 deletions.
41 changes: 23 additions & 18 deletions api/src/main/java/javax/jdo/Enhancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class Enhancer {
/** Class file suffix */
private static final String CLASS_FILE_SUFFIX = ".class"; // NOI18N

private static final String MSG_ENHANCER_CLASS_PATH = "MSG_EnhancerClassPath"; // NOI18N
private static final String MSG_ENHANCER_PROCESSING = "MSG_EnhancerProcessing"; // NOI18N
private static final String MSG_ENHANCER_PROPERTY = "MSG_EnhancerProperty"; // NOI18N
private static final String MSG_ENHANCER_USAGE = "MSG_EnhancerUsage"; // NOI18N

/** Error indicator */
private boolean error = false;
/** If set, process parameters, print usage, and exit. */
Expand Down Expand Up @@ -155,19 +160,19 @@ private void run(String[] args) {
properties = enhancer.getProperties();
addVerboseMessage("MSG_EnhancerClass", enhancer.getClass().getName()); // NOI18N
addVerboseMessage(
"MSG_EnhancerProperty",
PROPERTY_ENHANCER_VENDOR_NAME, // NOI18N
MSG_ENHANCER_PROPERTY,
PROPERTY_ENHANCER_VENDOR_NAME,
properties.getProperty(PROPERTY_ENHANCER_VENDOR_NAME));
addVerboseMessage(
"MSG_EnhancerProperty",
MSG_ENHANCER_PROPERTY,
PROPERTY_ENHANCER_VERSION_NUMBER, // NOI18N
properties.getProperty(PROPERTY_ENHANCER_VERSION_NUMBER));
Set<Entry<Object, Object>> props = properties.entrySet();
for (Entry<Object, Object> entry : props) {
if (!(PROPERTY_ENHANCER_VENDOR_NAME.equals(entry.getKey())
|| PROPERTY_ENHANCER_VERSION_NUMBER.equals(entry.getKey()))) {
addVerboseMessage(
"MSG_EnhancerProperty",
MSG_ENHANCER_PROPERTY,
(String) entry.getKey(), // NOI18N
(String) entry.getValue());
}
Expand All @@ -185,7 +190,7 @@ private void run(String[] args) {
if (numberOfFiles != 0) {
enhancer.addFiles(jdoFileNames.toArray(new String[numberOfFiles]));
}
if (0 < jarFileNames.size()) {
if (!jarFileNames.isEmpty()) {
for (String jarFileName : jarFileNames) {
enhancer.addJar(jarFileName);
}
Expand Down Expand Up @@ -222,11 +227,11 @@ private void processArgs(String[] args) {
parseFiles(fileNames.toArray(new String[fileNames.size()]), true, recurse);
loader = prepareClassLoader(classPath);
if (error) {
addErrorMessage(msg.msg("MSG_EnhancerUsage")); // NOI18N
addErrorMessage(msg.msg(MSG_ENHANCER_USAGE)); // NOI18N
exit(ENHANCER_USAGE_ERROR); // error exit
}
if (printAndExit) {
addVerboseMessage("MSG_EnhancerUsage"); // NOI18N
addVerboseMessage(MSG_ENHANCER_USAGE); // NOI18N
exit(0); // good exit
}
}
Expand All @@ -250,44 +255,44 @@ private void parseArgs(String[] args) {
if (arg.startsWith("-")) { // NOI18N
String option = arg.substring(1);
if ("help".equals(option)) { // NOI18N
addVerboseMessage("MSG_EnhancerProcessing", "-help"); // NOI18N
addVerboseMessage(MSG_ENHANCER_PROCESSING, "-help"); // NOI18N
setPrintAndExit();
} else if ("h".equals(option)) { // NOI18N
addVerboseMessage("MSG_EnhancerProcessing", "-h"); // NOI18N
addVerboseMessage(MSG_ENHANCER_PROCESSING, "-h"); // NOI18N
setPrintAndExit();
} else if ("v".equals(option)) { // NOI18N
addVerboseMessage("MSG_EnhancerProcessing", "-v"); // NOI18N
addVerboseMessage(MSG_ENHANCER_PROCESSING, "-v"); // NOI18N
verbose = true;
} else if ("verbose".equals(option)) { // NOI18N
addVerboseMessage("MSG_EnhancerProcessing", "-verbose"); // NOI18N
addVerboseMessage(MSG_ENHANCER_PROCESSING, "-verbose"); // NOI18N
verbose = true;
} else if ("pu".equals(option)) { // NOI18N
if (hasNextArgument("MSG_EnhancerProcessing", "-pu", i, args.length)) { // NOI18N
if (hasNextArgument(MSG_ENHANCER_PROCESSING, "-pu", i, args.length)) { // NOI18N
String puName = args[++i];
addVerboseMessage("MSG_EnhancerPersistenceUnitName", puName); // NOI18N
persistenceUnitNames.add(puName);
} else {
setError();
}
} else if ("cp".equals(option)) { // NOI18N
if (hasNextArgument("MSG_EnhancerProcessing", "-cp", i, args.length)) { // NOI18N
if (hasNextArgument(MSG_ENHANCER_PROCESSING, "-cp", i, args.length)) { // NOI18N
classPath = args[++i];
addVerboseMessage("MSG_EnhancerClassPath", classPath); // NOI18N
addVerboseMessage(MSG_ENHANCER_CLASS_PATH, classPath); // NOI18N
} else {
setError();
}
} else if ("d".equals(option)) { // NOI18N
if (hasNextArgument("MSG_EnhancerProcessing", "-d", i, args.length)) { // NOI18N
if (hasNextArgument(MSG_ENHANCER_PROCESSING, "-d", i, args.length)) { // NOI18N
directoryName = args[++i];
addVerboseMessage("MSG_EnhancerOutputDirectory", directoryName); // NOI18N
} else {
setError();
}
} else if ("checkonly".equals(option)) { // NOI18N
addVerboseMessage("MSG_EnhancerProcessing", "-checkonly"); // NOI18N
addVerboseMessage(MSG_ENHANCER_PROCESSING, "-checkonly"); // NOI18N
checkOnly = true;
} else if ("r".equals(option)) { // NOI18N
addVerboseMessage("MSG_EnhancerProcessing", "-r"); // NOI18N
addVerboseMessage(MSG_ENHANCER_PROCESSING, "-r"); // NOI18N
recurse = true;
} else {
setError();
Expand Down Expand Up @@ -386,7 +391,7 @@ private ClassLoader prepareClassLoader(String classPath) {
URI uri = file.toURI();
try {
URL url = uri.toURL();
addVerboseMessage("MSG_EnhancerClassPath", url.toString());
addVerboseMessage(MSG_ENHANCER_CLASS_PATH, url.toString());
urls.add(url);
} catch (MalformedURLException e) {
setError();
Expand Down
Loading

0 comments on commit f748519

Please sign in to comment.