From 6d102c987133ab8f0dec460b0f5fc0ceb9fc50b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Tue, 16 Sep 2025 10:51:48 +0200 Subject: [PATCH] chore(deps): bump pmd.version from 7.15.0 to 7.17.0 The class ExecTimeLogger is not used and has therefore been removed instead of adapted to fix new warnings. The PMD GitHub Action has been upgrade up to 7.15.0 (7.16.0 and 7.17.0 throw an exception when run on our repo). --- .github/workflows/verify.yml | 2 +- .../core/test/AbstractCheckTestCase.java | 12 +- ...kBatchLinkableResourceStorageLoadable.java | 4 +- .../configuration/CheckPreferencesHelper.java | 2 +- .../runtime/label/CheckRuleLabelProvider.java | 8 +- .../runtime/quickfix/ICoreXtextDocument.java | 4 +- .../util/CheckPreferencesExtensionHelper.java | 3 +- .../ui/builder/util/CheckProjectHelper.java | 5 +- .../util/CheckQuickfixExtensionHelper.java | 3 +- .../util/CheckValidatorExtensionHelper.java | 3 +- .../ddk/test/core/util/ExecTimeLogger.java | 122 ------------------ .../tools/ddk/test/core/util/JobMatcher.java | 2 +- .../ui/test/logging/ErrorLogListenerTest.java | 2 - .../ui/junit/runners/TestRunRecording.java | 5 +- .../ddk/xtext/builder/BuilderWatchdog.java | 4 +- .../expression/CompilationContextTest.java | 3 +- .../parser/antlr/KeywordAnalysisHelper.java | 20 +-- .../tools/ddk/xtext/test/AbstractTest.java | 4 +- .../ddk/xtext/test/AbstractXtextTest.java | 8 +- .../test/generator/AbstractGeneratorTest.java | 13 +- .../test/ui/hover/AbstractHoverTest.java | 4 +- .../build/AbstractDynamicSetupService.java | 2 +- .../modelinference/InferredModelUtil.java | 8 +- .../xtext/resource/XtextGMFResourceUtil.java | 10 +- .../DirectLinkingResourceStorageLoadable.java | 10 +- ddk-parent/pom.xml | 2 +- 26 files changed, 60 insertions(+), 205 deletions(-) delete mode 100644 com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/ExecTimeLogger.java diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index a7e85e9461..9e4f392b5d 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -13,7 +13,7 @@ jobs: uses: pmd/pmd-github-action@v2.0.0 id: pmd with: - version: '7.12.0' + version: '7.15.0' rulesets: 'ddk-configuration/pmd/ruleset.xml' analyzeModifiedFilesOnly: false - name: Fail build if there are violations diff --git a/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java b/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java index 506b693370..877f97296a 100644 --- a/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java +++ b/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java @@ -16,11 +16,12 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Set; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; @@ -49,7 +50,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.io.CharStreams; -import com.google.common.io.Closeables; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; @@ -191,7 +191,7 @@ public String getContents(final IFile file) throws Exception { // NOPMD do { bytesRead = inputStream.read(buffer); if (bytesRead != -1) { - b.append(new String(buffer, 0, bytesRead)); + b.append(new String(buffer, 0, bytesRead, StandardCharsets.UTF_8)); } } while (bytesRead != -1); return b.toString(); @@ -373,12 +373,8 @@ protected String getSourceFolderPath() { * if model could not be read */ private String getNormalizedContents(final Class clazz, final String modelName) throws IOException { - InputStreamReader s = null; - try { - s = new InputStreamReader(clazz.getResourceAsStream(modelName)); + try (InputStreamReader s = new InputStreamReader(clazz.getResourceAsStream(modelName), StandardCharsets.UTF_8)) { return CharStreams.toString(s); - } finally { - Closeables.closeQuietly(s); } } diff --git a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/resource/CheckBatchLinkableResourceStorageLoadable.java b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/resource/CheckBatchLinkableResourceStorageLoadable.java index 21365eff0f..e315b49f66 100644 --- a/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/resource/CheckBatchLinkableResourceStorageLoadable.java +++ b/com.avaloq.tools.ddk.check.core/src/com/avaloq/tools/ddk/check/resource/CheckBatchLinkableResourceStorageLoadable.java @@ -23,11 +23,11 @@ public CheckBatchLinkableResourceStorageLoadable(final InputStream in, final boo @Override protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) throws IOException { // Adapted from the ResourceStorageLoadable base class - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall readContents(resource, new BufferedInputStream(zipIn)); // Here we skip the call to readResourceDescription if (storeNodeModel) { - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall readNodeModel(resource, new BufferedInputStream(zipIn)); } diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckPreferencesHelper.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckPreferencesHelper.java index 7561ffa825..e5c933a176 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckPreferencesHelper.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckPreferencesHelper.java @@ -27,7 +27,7 @@ */ public final class CheckPreferencesHelper { - private static final String SEPARATOR = new String(new byte[] {Ascii.SUB}); + private static final String SEPARATOR = new String(new byte[] {Ascii.SUB}); // NOPMD RelianceOnDefaultCharset private CheckPreferencesHelper() { // No instantiation diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java index 282807130f..761f8ae24c 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java @@ -60,9 +60,7 @@ public String getLabel(final String issueCode) { : Collections.unmodifiableMap(createIssueCodeToLabelMap(checkValidatorRegistry))); // Get the label - final String label = issueCodeToLabelMap.get().get(issueCode); - - return label; + return issueCodeToLabelMap.get().get(issueCode); } /** @@ -81,9 +79,7 @@ private static Map createIssueCodeToLabelMap(final ICheckValidat final Stream> issueCodeToLabelMaps = validators.stream().map(validatorClass -> getIssueCodeToLabelMap(validatorClass)).filter(Objects::nonNull); // Munge the maps together - final Map issueCodeToLabelMap = merge(issueCodeToLabelMaps); - - return issueCodeToLabelMap; + return merge(issueCodeToLabelMaps); } /** diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/quickfix/ICoreXtextDocument.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/quickfix/ICoreXtextDocument.java index 72ce7f4823..d395b21f0f 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/quickfix/ICoreXtextDocument.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/quickfix/ICoreXtextDocument.java @@ -33,12 +33,12 @@ public interface ICoreXtextDocument extends IReadAccess, IWriteAc /** * The identifier of the default position category. */ - final static String DEFAULT_CATEGORY = "__dflt_position_category"; //$NON-NLS-1$ + static final String DEFAULT_CATEGORY = "__dflt_position_category"; //$NON-NLS-1$ /** * The identifier of the default partition content type. */ - final static String DEFAULT_CONTENT_TYPE = "__dftl_partition_content_type"; //$NON-NLS-1$ + static final String DEFAULT_CONTENT_TYPE = "__dftl_partition_content_type"; //$NON-NLS-1$ /* --------------- text access and manipulation --------------------------- */ diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java index 19ec0390a4..50fe66fdf0 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java @@ -182,11 +182,10 @@ private IPluginElement getInitializerElement(final Iterable elem @Override public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable elements) { // @Format-Off - final boolean result = PREFERENCES_EXTENSION_POINT_ID.equals(extension.getPoint()) + return PREFERENCES_EXTENSION_POINT_ID.equals(extension.getPoint()) && (!extensionNameMatches(extension, catalog) || Iterables.size(elements) != 2 || !initializerClassMatches(getInitializerElement(elements), getTargetClassName(catalog))); - return result; // @Format-On } diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java index 892d8a80ae..e3ca179d87 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java @@ -11,10 +11,11 @@ package com.avaloq.tools.ddk.check.ui.builder.util; import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; import java.util.List; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -155,7 +156,7 @@ public IFile getHelpFile(final IProject project, final String filename) throws C } IFile file = project.getFile(filename); if (!file.exists()) { - file.create(new ByteArrayInputStream("".getBytes()), true, null); + file.create(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)), true, null); } return file; } diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckQuickfixExtensionHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckQuickfixExtensionHelper.java index 1fa1ac0a54..caab9450d3 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckQuickfixExtensionHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckQuickfixExtensionHelper.java @@ -127,13 +127,12 @@ private String getTargetClassName(final CheckCatalog catalog) { public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable elements) { // CHECKSTYLE:OFF // @Format-Off - final boolean result = QUICKFIX_EXTENSION_POINT_ID.equals(extension.getPoint()) + return QUICKFIX_EXTENSION_POINT_ID.equals(extension.getPoint()) && (!extensionNameMatches(extension, catalog) || Iterables.size(elements) != 1 || !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog)) || catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null || catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName())); - return result; // @Format-On // CHECKSTYLE:ON } diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckValidatorExtensionHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckValidatorExtensionHelper.java index 602a56a7a2..72df20c0fc 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckValidatorExtensionHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckValidatorExtensionHelper.java @@ -119,14 +119,13 @@ private String getTargetClassName(final CheckCatalog catalog) { public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable elements) { // CHECKSTYLE:OFF // @Format-Off - final boolean result = CHECK_EXTENSION_POINT_ID.equals(extension.getPoint()) + return CHECK_EXTENSION_POINT_ID.equals(extension.getPoint()) && (!extensionNameMatches(extension, catalog) || Iterables.size(elements) != 1 || !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog)) || catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null || catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName()) ); - return result; // @Format-On // CHECKSTYLE:ON } diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/ExecTimeLogger.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/ExecTimeLogger.java deleted file mode 100644 index a2e0e2f0c1..0000000000 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/ExecTimeLogger.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Avaloq Group AG and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Avaloq Group AG - initial API and implementation - *******************************************************************************/ -package com.avaloq.tools.ddk.test.core.util; - -import static com.avaloq.tools.ddk.test.core.util.Reflect.getCallingClass; -import static com.avaloq.tools.ddk.test.core.util.Reflect.getCallingMethod; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; - - -/** - * Class for logging execution times. First {@link start()} and {@link stop()} - * must be called to measure the time of an arbitrary operation. Afterwards - * {@link log()} or {@link getExecTime()} may be called to get the result. - */ -public class ExecTimeLogger { - - private final DateFormat df; - - private long startTime = -1; - private long stopTime = -1; - private String caller; - - private final boolean strict; - - /** - * Default Constructor. - */ - public ExecTimeLogger() { - this(false); - } - - /** - * Constructor that enables strict mode. In strict mode, this class' - * {@link start()} and {@link stop()} methods must be called from the - * same method. This is helpful when sharing the same instance among - * several methods. - * - * @param strict - * Whether to activate strict mode - */ - public ExecTimeLogger(final boolean strict) { - this.strict = strict; - df = new SimpleDateFormat("HH:mm:ss", Locale.GERMAN); - df.setTimeZone(TimeZone.getTimeZone("GMT")); - } - - /** - * Resets this logger so that it can be used to log another execution. - */ - @SuppressWarnings("PMD.NullAssignment") - public void reset() { - startTime = -1; - stopTime = -1; - caller = null; - } - - /** - * Starts measurement of execution time. - */ - public void start() { - if (startTime != -1 || stopTime != -1 || caller != null) { - throw new IllegalStateException("ExecTimeLogger needs to be reset before calling start()"); - } - caller = getCallingMethod(); - startTime = System.currentTimeMillis(); - } - - /** - * Stops measurement of execution time. - */ - public void stop() { - if (startTime == -1 || stopTime != -1) { - throw new IllegalStateException("ExecTimeLogger is not running or already stopped"); - } - if (strict && (caller == null || !caller.equals(getCallingMethod()))) { - throw new IllegalStateException("Corresponding start() and stop() must be called from same method"); - } - stopTime = System.currentTimeMillis(); - } - - /** - * Logs execution time to log4j logger of calling class. The time is logged - * for the method that called {@link start()}. - */ - public void log() { - if (startTime == -1 || stopTime == -1 || caller == null) { - throw new IllegalStateException("No stopped run to log available"); - } - Logger logger = LogManager.getLogger(getCallingClass()); - Date interval = new Date(getExecTime()); - logger.info("Execution statistics: " + getCallingMethod() + " took " + df.format(interval)); - } - - /** - * Returns the execution time (so far). This method may be called for - * stopped runs as well as for ongoing runs. - * - * @return the exec time - */ - public long getExecTime() { - if (startTime == -1) { - throw new IllegalStateException("No active or stopped run available"); - } - return stopTime - startTime; - } -} diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java index 9d86755c8f..bc23749ad3 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/JobMatcher.java @@ -63,7 +63,7 @@ public class JobMatcher extends JobChangeAdapter { * Class used to find and match specific waiting, executing and sleeping jobs. */ // CHECKSTYLE:OFF - public static abstract class JobFinder implements Predicate { + public abstract static class JobFinder implements Predicate { // CHECKSTYLE:ON /** diff --git a/com.avaloq.tools.ddk.test.ui.test/src/com/avaloq/tools/ddk/test/ui/test/logging/ErrorLogListenerTest.java b/com.avaloq.tools.ddk.test.ui.test/src/com/avaloq/tools/ddk/test/ui/test/logging/ErrorLogListenerTest.java index a928c2178b..1ccb05bd8d 100644 --- a/com.avaloq.tools.ddk.test.ui.test/src/com/avaloq/tools/ddk/test/ui/test/logging/ErrorLogListenerTest.java +++ b/com.avaloq.tools.ddk.test.ui.test/src/com/avaloq/tools/ddk/test/ui/test/logging/ErrorLogListenerTest.java @@ -52,7 +52,6 @@ public void tearDown() { * @throws InterruptedException * the exception that is thrown if the test job was interrupted */ - @SuppressWarnings("unlikely-arg-type") @Test public void testIgnoringExceptionLocations() throws InterruptedException { assertFalse("NullPointerException must not have been logged.", errorLogListener.isExceptionLogged(NullPointerException.class)); @@ -71,6 +70,5 @@ protected IStatus run(final IProgressMonitor monitor) { job.join(); assertTrue("NullPointerException must have been logged.", errorLogListener.isExceptionLogged(NullPointerException.class)); - assertFalse("NullPointerException must have been ignored.", errorLogListener.getLoggedExceptions().contains(NullPointerException.class)); } } diff --git a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java index 353b216d6a..b88a53cd7a 100644 --- a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java +++ b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java @@ -26,6 +26,7 @@ import java.lang.management.MonitorInfo; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -594,7 +595,7 @@ private void storeCallStack(final String trace) throws IOException { // Put it next to screenshots (intentional) final File screenshotDirectory = new File(getScreenshotDirectory()); screenshotDirectory.mkdirs(); - PrintWriter out = new PrintWriter(getCallStackFileName()); + PrintWriter out = new PrintWriter(getCallStackFileName(), StandardCharsets.UTF_8); out.print(trace); out.close(); } @@ -624,7 +625,7 @@ private String getCallStackFileName() { */ private String getFileNamePrefix() { final StringBuilder result = new StringBuilder(getScreenshotDirectory()); - final Date date = new Date(lastCaptureTime); + final Date date = new Date(lastCaptureTime); // NOPMD ReplaceJavaUtilDate final DateFormat formatter = new SimpleDateFormat("HH.mm.ss.SSS", Locale.UK); final String formattedDate = formatter.format(date); result.append(formattedDate); diff --git a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/BuilderWatchdog.java b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/BuilderWatchdog.java index 731c2648cb..292c4c0e59 100644 --- a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/BuilderWatchdog.java +++ b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/BuilderWatchdog.java @@ -109,9 +109,9 @@ public void reportWorkEnded(final int processedSources, final int totalSources) AtomicInteger newEntry = new AtomicInteger(0); AtomicInteger typeEntry = currentURI != null ? typeCount.putIfAbsent(EmfResourceUtil.getFileExtension(currentURI), newEntry) : null; typeEntry = typeEntry != null ? typeEntry : newEntry; - typeEntry.getAndIncrement(); + typeEntry.getAndIncrement(); // NOPMD UselessPureMethodCall - progressCount.getAndIncrement(); + progressCount.getAndIncrement(); // NOPMD UselessPureMethodCall if (progressCount.compareAndSet(BATCH_SIZE, 0)) { reportAndResetProgress(processedSources, totalSources); } diff --git a/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/CompilationContextTest.java b/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/CompilationContextTest.java index 4076a43403..321a9d684c 100644 --- a/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/CompilationContextTest.java +++ b/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/CompilationContextTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertTrue; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import org.eclipse.internal.xtend.xtend.ast.ExtensionFile; import org.eclipse.internal.xtend.xtend.parser.ParseFacade; @@ -31,7 +32,7 @@ public class CompilationContextTest { public void isExtension() { ExecutionContextImpl executionContext = new ExecutionContextImpl(); executionContext.registerMetaModel(new JavaBeansMetaModel()); - ExtensionFile extensionFile = ParseFacade.file(new InputStreamReader(getClass().getResourceAsStream("/com/avaloq/tools/ddk/xtext/generator/expression/TestExtensions.ext")), "TestExtensions.ext"); + ExtensionFile extensionFile = ParseFacade.file(new InputStreamReader(getClass().getResourceAsStream("/com/avaloq/tools/ddk/xtext/generator/expression/TestExtensions.ext"), StandardCharsets.UTF_8), "TestExtensions.ext"); executionContext = (ExecutionContextImpl) executionContext.cloneWithResource(extensionFile); final CompilationContext context = new CompilationContext(executionContext, null); diff --git a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java index 8cd522b0b8..f77ff99e23 100644 --- a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java +++ b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java @@ -12,8 +12,10 @@ package com.avaloq.tools.ddk.xtext.generator.parser.antlr; import java.io.File; -import java.io.FileNotFoundException; +import java.io.IOException; import java.io.PrintWriter; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -22,8 +24,8 @@ import java.util.Set; import java.util.stream.Collectors; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.eclipse.core.runtime.Path; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -173,7 +175,7 @@ private boolean hasLetters(final String keyword) { public void printViolations(final String srcGenPath) { try { String fileName = getKeywordsDiagnosticReportFileName(srcGenPath); - PrintWriter writer = new PrintWriter(new File(fileName)); + PrintWriter writer = new PrintWriter(new File(fileName), StandardCharsets.UTF_8); writer.println("Please check in this file, so a diff can be used to detect unexpected changes"); writer.println(); writer.println(" identifiers rejected - are not listed in MWE2 file as reserved words"); @@ -260,8 +262,8 @@ public void printViolations(final String srcGenPath) { } writer.println("if any of them is used to parse identifiers, add them to identifierRules in MWE2 file"); writer.close(); - } catch (FileNotFoundException e) { - LOGGER.error("could not write diagnostic file on keywords", e); + } catch (IOException e) { + throw new UncheckedIOException(e); } } @@ -429,16 +431,16 @@ public List getAllGrammars() { public void printReport(final String srcGenPath) { try { String fileName = getReportFileName(srcGenPath); - PrintWriter writer = new PrintWriter(new File(fileName)); + PrintWriter writer = new PrintWriter(new File(fileName), StandardCharsets.UTF_8); writer.print(report.build()); writer.close(); String docuFileName = getDocFileName(srcGenPath); - PrintWriter docuWriter = new PrintWriter(new File(docuFileName)); + PrintWriter docuWriter = new PrintWriter(new File(docuFileName), StandardCharsets.UTF_8); docuWriter.print(new CombinedGrammarReportBuilder(grammarExtensions).getDocumentation(grammar, parserRules, enumRules)); docuWriter.close(); LOGGER.info("report on keywords is written into " + fileName); - } catch (FileNotFoundException e) { - LOGGER.error("could not write report on keywords", e); + } catch (IOException e) { + throw new UncheckedIOException(e); } } diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractTest.java index 1e53e0e835..cc8f7dfccc 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractTest.java @@ -331,9 +331,7 @@ protected XtextTestSource getTestSource(final String sourceFileName) { * @return the {@link TestSource} for this test class */ protected TestSource getTestSource() { - TestSource testSource = getTestProjectManager().getTestSource(getTestSourceFileName()); - // Assert.assertNotNull("TestSource for this test class can be found: " + getTestSourceFileName(), testSource); - return testSource; + return getTestProjectManager().getTestSource(getTestSourceFileName()); } /** diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTest.java index d51d8fd47d..624e8d64a8 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTest.java @@ -62,9 +62,7 @@ protected String getTestSourceFileName() { * the xtext resource loaded by {@link loadPrimarySource}. */ protected XtextResource getXtextTestResource() { - XtextResource resource = getTestSource(getTestSourceFileName()).getXtextResource(); - // assertNotNull("Resource of main test source is not null.", resource); - return resource; + return getTestSource(getTestSourceFileName()).getXtextResource(); } /** @@ -74,9 +72,7 @@ protected XtextResource getXtextTestResource() { * the semantic model from the xtext resource loaded by {@link loadPrimarySource}. */ protected EObject getSemanticModel() { - EObject model = getXtextTestResource().getParseResult().getRootASTElement(); - // assertNotNull("Semantic model of main test source is not null.", model); - return model; + return getXtextTestResource().getParseResult().getRootASTElement(); } /** diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/generator/AbstractGeneratorTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/generator/AbstractGeneratorTest.java index a9ae4fc867..9e36e07819 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/generator/AbstractGeneratorTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/generator/AbstractGeneratorTest.java @@ -18,6 +18,7 @@ import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.Arrays; import java.util.HashMap; @@ -368,18 +369,8 @@ protected IFile getFileFromProject(final String projectName, final String filePa * thrown if file could not be read */ public String getContents(final IFile file) throws IOException, CoreException { - InputStreamReader reader = null; - try { - reader = new InputStreamReader(file.getContents()); + try (InputStreamReader reader = new InputStreamReader(file.getContents(), StandardCharsets.UTF_8)) { return normalizeLineBreaks(CharStreams.toString(reader)); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - LOGGER.info("Failed to close test file " + file.getName()); - } - } } } diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/hover/AbstractHoverTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/hover/AbstractHoverTest.java index a29a2574ba..27405f08c7 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/hover/AbstractHoverTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/hover/AbstractHoverTest.java @@ -194,9 +194,7 @@ private void assertElementExistInHoverMap(final ENamedElement element) { private String removeHTMLTags(final String text) { Pattern pattern = Pattern.compile("\\<[^>]*>"); //$NON-NLS-1$ Matcher matcher = pattern.matcher(text); - String plainText = matcher.replaceAll(""); - - return plainText; + return matcher.replaceAll(""); } /** diff --git a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/build/AbstractDynamicSetupService.java b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/build/AbstractDynamicSetupService.java index 84825572fa..6b7a08a3dd 100644 --- a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/build/AbstractDynamicSetupService.java +++ b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/build/AbstractDynamicSetupService.java @@ -24,7 +24,7 @@ public abstract class AbstractDynamicSetupService implements IDynamicSetupServic * {@inheritDoc} Child languages are always > than their parent languages. */ @Override - public int compareTo(final IDynamicSetupService other) { + public int compareTo(final IDynamicSetupService other) { // NOPMD OverrideBothEqualsAndHashCodeOnComparable if (other == this) { // NOPMD == on purpose return 0; } diff --git a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/InferredModelUtil.java b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/InferredModelUtil.java index b357f55206..725bb0fb3f 100644 --- a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/InferredModelUtil.java +++ b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/InferredModelUtil.java @@ -36,8 +36,9 @@ protected InferredModelUtil() { // No public constructor for utility class * the resource * @return the inference container or {@code null} if there aren't any */ - public static @Nullable InferenceContainer getInferenceContainer(final @NonNull Resource resource) { - for (EObject content: resource.getContents()) { + @Nullable + public static InferenceContainer getInferenceContainer(final @NonNull Resource resource) { + for (EObject content : resource.getContents()) { if (content instanceof InferenceContainer inferenceContainer) { return inferenceContainer; } @@ -77,7 +78,8 @@ protected InferredModelUtil() { // No public constructor for utility class * @return the inferred model element or null if there is none. */ @SuppressWarnings("unchecked") - public static @Nullable T getInferredModelElement(final @Nullable EObject source, @NonNull final Class clazz) { + @Nullable + public static T getInferredModelElement(final @Nullable EObject source, @NonNull final Class clazz) { IInferredModelAssociations modelAssociations = getModelAssociations(source); if (modelAssociations != null) { for (EObject eObj : modelAssociations.getInferredModelElements(source)) { diff --git a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/XtextGMFResourceUtil.java b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/XtextGMFResourceUtil.java index e4a6c71d16..8ce7efe13f 100644 --- a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/XtextGMFResourceUtil.java +++ b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/XtextGMFResourceUtil.java @@ -16,8 +16,8 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** @@ -42,7 +42,7 @@ protected XtextGMFResourceUtil() { // Utility classes do not have a public const /** * Get the text that separates the Xtext part from the GMF part. - * + * * @param encoding * the encoding to use for the separator. null if default encoding should be used. * @return the separator text as a byte array encoded using encoding @@ -52,13 +52,13 @@ public static byte[] getSeparator(final String encoding) { return SEPARATOR.getBytes(encoding != null ? encoding : DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { LOGGER.error("unsupported encoding: " + encoding, e); //$NON-NLS-1$ - return SEPARATOR.getBytes(); + return SEPARATOR.getBytes(); // NOPMD RelianceOnDefaultCharset } } /** * Read the full stream into a byte array. - * + * * @param input * stream to read from * @return byte array representation of input @@ -99,7 +99,7 @@ public static byte[] readFullStream(final InputStream input) throws IOException /** * Locate separator within input. - * + * * @param input * byte array containing encoded input. * @param separator diff --git a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/persistence/DirectLinkingResourceStorageLoadable.java b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/persistence/DirectLinkingResourceStorageLoadable.java index 166d56cc99..cc73ada5b1 100644 --- a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/persistence/DirectLinkingResourceStorageLoadable.java +++ b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/persistence/DirectLinkingResourceStorageLoadable.java @@ -207,7 +207,7 @@ public void loadIntoResource(final StorageAwareResource resource, final Resource @Override protected void loadEntries(final StorageAwareResource resource, final ZipInputStream zipIn) throws IOException { // 1. resource contents - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall if (!splitContents) { switch (mode.instruction(Constituent.CONTENT)) { // NOPMD ImplicitSwitchFallThrough case SKIP: @@ -236,7 +236,7 @@ protected void loadEntries(final StorageAwareResource resource, final ZipInputSt break; } - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall switch (mode.instruction(Constituent.CONTENT)) { // NOPMD ImplicitSwitchFallThrough case SKIP: break; @@ -250,7 +250,7 @@ protected void loadEntries(final StorageAwareResource resource, final ZipInputSt } // 2. associations adapter - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall switch (mode.instruction(Constituent.ASSOCIATIONS)) { case SKIP: break; @@ -261,7 +261,7 @@ protected void loadEntries(final StorageAwareResource resource, final ZipInputSt readAssociationsAdapter(resource, new NonLockingBufferInputStream(zipIn)); break; } - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall // 3. source String content = null; @@ -278,7 +278,7 @@ protected void loadEntries(final StorageAwareResource resource, final ZipInputSt content = out.toString(); break; } - zipIn.getNextEntry(); + zipIn.getNextEntry(); // NOPMD UselessPureMethodCall // 4. node model if (loadNodeModel) { diff --git a/ddk-parent/pom.xml b/ddk-parent/pom.xml index 032b766d66..ea94cdecba 100644 --- a/ddk-parent/pom.xml +++ b/ddk-parent/pom.xml @@ -53,7 +53,7 @@ 4.9.4.2 4.9.5 3.27.0 - 7.15.0 + 7.17.0 5.0.0 2.40.0