From 28d3f54688a8c9435bcd805abfacbc38ff89c765 Mon Sep 17 00:00:00 2001 From: Bartosz Spyrko-Smietanko Date: Fri, 11 Aug 2023 12:31:14 +0100 Subject: [PATCH] Fix some static analysis warnings --- .../wildfly/prospero/it/cli/ApplyUpdateTest.java | 1 + .../cli/UpdateWithAdditionalRepositoryTest.java | 1 + .../commonapi/InstallationHistoryActionTest.java | 1 + .../commonapi/InstallationRestoreActionTest.java | 1 + .../it/commonapi/SimpleProvisionTest.java | 1 + .../prospero/it/commonapi/WfCoreTestBase.java | 1 + pom.xml | 2 +- .../org/wildfly/prospero/cli/CliConsole.java | 2 +- .../cli/commands/PrintLicensesCommand.java | 3 ++- .../commands/channel/ChannelPromoteCommand.java | 2 +- .../cli/commands/ApplyUpdateCommandTest.java | 2 +- .../cli/commands/InstallCommandTest.java | 16 ++-------------- .../channel/ChannelInitializeCommandTest.java | 2 +- .../org/wildfly/prospero/ProsperoLogger.java | 3 ++- .../prospero/actions/ApplyCandidateAction.java | 10 ++++++---- .../actions/InstallationHistoryAction.java | 7 ++++--- .../wildfly/prospero/actions/MetadataAction.java | 3 +-- .../org/wildfly/prospero/api/ArtifactUtils.java | 7 ++----- .../prospero/api/InstallationMetadata.java | 4 ++-- .../ChannelMavenArtifactRepositoryManager.java | 6 +----- .../prospero/galleon/GalleonCallbackAdapter.java | 3 +-- .../wildfly/prospero/galleon/GalleonUtils.java | 2 +- .../prospero/licenses/LicenseManager.java | 2 +- .../prospero/promotion/ArtifactBundle.java | 13 +++---------- .../prospero/promotion/ArtifactPromoter.java | 13 +++++++------ .../spi/ProsperoInstallationManager.java | 2 +- .../wildfly/prospero/test/MetadataTestUtils.java | 7 ------- .../wildfly/prospero/updates/UpdateFinder.java | 11 +---------- .../actions/ApplyCandidateActionTest.java | 5 ++++- .../wildfly/prospero/api/ChannelChangeTest.java | 1 + .../galleon/CachedVersionResolverTest.java | 1 + .../galleon/inspect/GalleonPackInspector.java | 2 +- .../LocalInstallationHistoryTest.java | 1 + .../installation/git/GitStorageTest.java | 5 +++-- .../model/ManifestVersionRecordTest.java | 1 + .../prospero/promotion/ArtifactPromoterTest.java | 2 +- .../spi/ProsperoInstallationManagerTest.java | 1 + .../prospero/updates/UpdateFinderTest.java | 1 + .../metadata/ManifestVersionResolver.java | 9 +++++---- 39 files changed, 68 insertions(+), 89 deletions(-) diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/ApplyUpdateTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/ApplyUpdateTest.java index 5df8805e1..ec860d6dd 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/ApplyUpdateTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/ApplyUpdateTest.java @@ -37,6 +37,7 @@ import static org.junit.Assert.assertEquals; import static org.wildfly.prospero.test.MetadataTestUtils.upgradeStreamInManifest; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class ApplyUpdateTest extends CliTestBase { @Rule diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/UpdateWithAdditionalRepositoryTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/UpdateWithAdditionalRepositoryTest.java index 55f3d98df..22572944e 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/cli/UpdateWithAdditionalRepositoryTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/cli/UpdateWithAdditionalRepositoryTest.java @@ -40,6 +40,7 @@ import static org.junit.Assert.assertEquals; import static org.wildfly.prospero.test.MetadataTestUtils.upgradeStreamInManifest; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class UpdateWithAdditionalRepositoryTest extends CliTestBase { private File targetDir; diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationHistoryActionTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationHistoryActionTest.java index 708aeba77..6981b4ee2 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationHistoryActionTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationHistoryActionTest.java @@ -58,6 +58,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class InstallationHistoryActionTest extends WfCoreTestBase { private Path channelsFile; diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationRestoreActionTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationRestoreActionTest.java index 4a252ace9..b6a7a6d95 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationRestoreActionTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/InstallationRestoreActionTest.java @@ -48,6 +48,7 @@ import static org.junit.Assert.assertEquals; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class InstallationRestoreActionTest extends WfCoreTestBase { private Path restoredServerDir; diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/SimpleProvisionTest.java b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/SimpleProvisionTest.java index 604f95a4c..c1a18bf6b 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/SimpleProvisionTest.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/SimpleProvisionTest.java @@ -55,6 +55,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class SimpleProvisionTest extends WfCoreTestBase { @Test diff --git a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/WfCoreTestBase.java b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/WfCoreTestBase.java index 00a4af95b..7ad776213 100644 --- a/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/WfCoreTestBase.java +++ b/integration-tests/src/test/java/org/wildfly/prospero/it/commonapi/WfCoreTestBase.java @@ -65,6 +65,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class WfCoreTestBase { public static final String BASE_VERSION = "20.0.0.Beta5"; diff --git a/pom.xml b/pom.xml index f2ac44b88..0d1e1eb41 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 4.4.16 1.8 3.0.2 - 3.16.0 + 3.21.0 3.1.2 1.9.10 3.6.3 diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/CliConsole.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/CliConsole.java index 829a509be..00f924130 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/CliConsole.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/CliConsole.java @@ -236,7 +236,7 @@ public InputStream getInput() { } public void error(String message, String... args) { - getErrOut().println(String.format(message, args)); + getErrOut().println(String.format(message, (Object[]) args)); } @Override diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/PrintLicensesCommand.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/PrintLicensesCommand.java index 630102f57..28946814b 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/PrintLicensesCommand.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/PrintLicensesCommand.java @@ -17,6 +17,7 @@ package org.wildfly.prospero.cli.commands; +import org.apache.commons.io.FileUtils; import org.jboss.galleon.config.ProvisioningConfig; import org.wildfly.channel.Channel; import org.wildfly.prospero.actions.ProvisioningAction; @@ -69,7 +70,7 @@ public Integer call() throws Exception { } return ReturnCodes.SUCCESS; } finally { - tempDirectory.toFile().delete(); + FileUtils.deleteQuietly(tempDirectory.toFile()); } } } diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/channel/ChannelPromoteCommand.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/channel/ChannelPromoteCommand.java index 867c28fc0..e7b1062b8 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/channel/ChannelPromoteCommand.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/channel/ChannelPromoteCommand.java @@ -165,7 +165,7 @@ private Optional readSetting(ThrowableFunction { diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ApplyUpdateCommandTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ApplyUpdateCommandTest.java index 0797188b9..3affb53db 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ApplyUpdateCommandTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ApplyUpdateCommandTest.java @@ -187,7 +187,7 @@ public void testAskForConfirmationIfConflictsPresent() throws Exception { private Path mockInstallation(String target) throws IOException, MetadataException, XMLStreamException { final Path targetPath = temp.newFolder(target).toPath(); - MetadataTestUtils.createInstallationMetadata(targetPath); + MetadataTestUtils.createInstallationMetadata(targetPath).close(); MetadataTestUtils.createGalleonProvisionedState(targetPath, UpdateCommand.PROSPERO_FP_GA); new MarkerFile("abcd1234", ApplyCandidateAction.Type.UPDATE).write(targetPath); diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java index dd03ee899..bccdeabb2 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/InstallCommandTest.java @@ -97,7 +97,7 @@ public void setUp() throws Exception { public void errorIfTargetPathIsNotPresent() { int exitCode = commandLine.execute(CliConstants.Commands.INSTALL); Assert.assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode); - assertTrue(getErrorOutput().contains(String.format("Missing required option: '--dir='", + assertTrue(getErrorOutput().contains(String.format("Missing required option: '%s='", CliConstants.DIR))); } @@ -219,19 +219,6 @@ public void fplAndDefinitionAreNotAllowedTogether() throws Exception { assertEquals(ReturnCodes.INVALID_ARGUMENTS, exitCode); } -// @Test -// public void passChannelReposToProvisionDef() throws Exception { -// int exitCode = commandLine.execute(CliConstants.Commands.INSTALL, CliConstants.DIR, "test", -// CliConstants.FPL, KNOWN_FPL, CliConstants.REMOTE_REPOSITORIES, "http://test.repo1,http://test.repo2"); -// -// assertEquals(ReturnCodes.SUCCESS, exitCode); -// Mockito.verify(provisionAction).provision(serverDefiniton.capture()); -// assertThat(serverDefiniton.getValue().getRepositories().stream().map(RemoteRepository::getUrl)).contains( -// "http://test.repo1", -// "http://test.repo2" -// ); -// } - @Test public void provisionConfigAndChannelSet() throws IOException { final File channelsFile = temporaryFolder.newFile(); @@ -263,6 +250,7 @@ public void provisionConfigAndRemoteRepoSet() throws Exception { .containsOnly("file:/test"); } + @SuppressWarnings("unchecked") @Test public void passShadowRepositories() throws Exception { Path channelsFile = temporaryFolder.newFile().toPath(); diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/channel/ChannelInitializeCommandTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/channel/ChannelInitializeCommandTest.java index e37f13976..4a71e5d35 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/channel/ChannelInitializeCommandTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/channel/ChannelInitializeCommandTest.java @@ -168,7 +168,7 @@ public void localCustomRepoDirIsWriteProtected() throws Exception { final Path base = tempFolder.newFolder().toPath(); try { - base.toFile().setWritable(false); + assertTrue("Unable to mark the file as un-writable, failing test", base.toFile().setWritable(false)); final Path repositoryPath = base.resolve("test-dir").resolve("repository"); final String customRepoUrl = repositoryPath.toUri().toURL().toString(); diff --git a/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java b/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java index cb84a3768..a7d685312 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/ProsperoLogger.java @@ -217,7 +217,8 @@ public interface ProsperoLogger extends BasicLogger { MetadataException unableToSaveConfiguration(Path path, @Cause Exception e); @Message(id = 218, value = "Unable to close the update store.") - MetadataException unableToCloseStore(@Cause Exception e); + @LogMessage(level = Logger.Level.WARN) + void unableToCloseStore(@Cause Exception e); @Message(id = 219, value = "Unable to create history store at [%s]") MetadataException unableToCreateHistoryStorage(Path path, @Cause Exception e); diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/ApplyCandidateAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/ApplyCandidateAction.java index 1e1b2f0b0..720345347 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/actions/ApplyCandidateAction.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/ApplyCandidateAction.java @@ -201,11 +201,13 @@ public ValidationResult verifyCandidate(Type operation) throws InvalidUpdateCand final MarkerFile marker = MarkerFile.read(updateDir); final String hash = marker.getState(); - if (!InstallationMetadata.loadInstallation(installationDir).getRevisions().get(0).getName().equals(hash)) { - if (ProsperoLogger.ROOT_LOGGER.isDebugEnabled()) { - ProsperoLogger.ROOT_LOGGER.debugf("The installation state has changed from the candidate [%s].", updateDir); + try(InstallationMetadata metadata = InstallationMetadata.loadInstallation(installationDir)) { + if (!metadata.getRevisions().get(0).getName().equals(hash)) { + if (ProsperoLogger.ROOT_LOGGER.isDebugEnabled()) { + ProsperoLogger.ROOT_LOGGER.debugf("The installation state has changed from the candidate [%s].", updateDir); + } + return ValidationResult.STALE; } - return ValidationResult.STALE; } if (marker.getOperation() != operation) { diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java index 16ced54b4..dd8f03174 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/InstallationHistoryAction.java @@ -62,8 +62,9 @@ public InstallationChanges compare(SavedState savedState) throws MetadataExcepti public List getRevisions() throws MetadataException { ProsperoLogger.ROOT_LOGGER.listHistory(installation); - final InstallationMetadata installationMetadata = InstallationMetadata.loadInstallation(installation); - return installationMetadata.getRevisions(); + try(InstallationMetadata installationMetadata = InstallationMetadata.loadInstallation(installation)) { + return installationMetadata.getRevisions(); + } } public void rollback(SavedState savedState, MavenOptions mavenOptions, List overrideRepositories) throws OperationException, ProvisioningException { @@ -137,7 +138,7 @@ private static void revertCurrentVersions(Path targetDir, InstallationMetadata r } private static void verifyStateExists(SavedState savedState, InstallationMetadata metadata) throws MetadataException { - if (!metadata.getRevisions().stream().filter(s->s.getName().equals(savedState.getName())).findFirst().isPresent()) { + if (metadata.getRevisions().stream().noneMatch(s->s.getName().equals(savedState.getName()))) { throw ProsperoLogger.ROOT_LOGGER.savedStateNotFound(savedState.getName()); } } diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/MetadataAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/MetadataAction.java index da39bc8a8..2dffe07b8 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/actions/MetadataAction.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/MetadataAction.java @@ -47,7 +47,7 @@ public void addChannel(Channel channel) throws MetadataException { final ProsperoConfig prosperoConfig = installationMetadata.getProsperoConfig(); final List channels = prosperoConfig.getChannels(); - if (channels.stream().filter(c->c.getName().equals(channel.getName())).findAny().isPresent()) { + if (channels.stream().anyMatch(c->c.getName().equals(channel.getName()))) { ProsperoLogger.ROOT_LOGGER.existingChannel(channel.getName()); throw ProsperoLogger.ROOT_LOGGER.channelExists(channel.getName()); } @@ -78,7 +78,6 @@ public void changeChannel(String channelName, Channel newChannel) throws Metadat final List channels = prosperoConfig.getChannels(); final Optional modifiedChannel = channels.stream().filter(c -> c.getName().equals(channelName)).findAny(); if (modifiedChannel.isEmpty()) { - ProsperoLogger.ROOT_LOGGER.channelNotFound(channelName); throw ProsperoLogger.ROOT_LOGGER.channelNotFound(channelName); } channels.set(channels.indexOf(modifiedChannel.get()), newChannel); diff --git a/prospero-common/src/main/java/org/wildfly/prospero/api/ArtifactUtils.java b/prospero-common/src/main/java/org/wildfly/prospero/api/ArtifactUtils.java index c9b5853c2..0dc9d89a3 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/api/ArtifactUtils.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/api/ArtifactUtils.java @@ -83,11 +83,8 @@ public static boolean isValidCoordinate(String gav) { return false; } } - if (parts.length != 2 && parts.length != 3) { // GA or GAV - return false; - } - - return true; + // GA or GAV + return parts.length == 2 || parts.length == 3; } public static String printStream(ArtifactCoordinate coord) { diff --git a/prospero-common/src/main/java/org/wildfly/prospero/api/InstallationMetadata.java b/prospero-common/src/main/java/org/wildfly/prospero/api/InstallationMetadata.java index 8fbe10bd5..dba9df274 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/api/InstallationMetadata.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/api/InstallationMetadata.java @@ -81,7 +81,7 @@ public static InstallationMetadata loadInstallation(Path base) throws MetadataEx ChannelManifest manifest; ProsperoConfig prosperoConfig; - Optional currentVersion = Optional.empty(); + Optional currentVersion; try { manifest = ManifestYamlSupport.parse(manifestFile.toFile()); @@ -193,7 +193,7 @@ protected InstallationMetadata(Path base, ChannelManifest manifest, ProsperoConf this.prosperoConfig = new ProsperoConfig(new ArrayList<>(prosperoConfig.getChannels()), prosperoConfig.getMavenOptions()); final List channels = prosperoConfig.getChannels(); - if (channels != null && channels.stream().filter(c-> StringUtils.isEmpty(c.getName())).findAny().isPresent()) { + if (channels != null && channels.stream().anyMatch(c-> StringUtils.isEmpty(c.getName()))) { throw ProsperoLogger.ROOT_LOGGER.emptyChannelName(); } diff --git a/prospero-common/src/main/java/org/wildfly/prospero/galleon/ChannelMavenArtifactRepositoryManager.java b/prospero-common/src/main/java/org/wildfly/prospero/galleon/ChannelMavenArtifactRepositoryManager.java index 9a9cb17cb..72ddebfcb 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/galleon/ChannelMavenArtifactRepositoryManager.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/galleon/ChannelMavenArtifactRepositoryManager.java @@ -157,11 +157,7 @@ private org.wildfly.channel.MavenArtifact resolveFromPreparedManifest(MavenArtif private boolean requiresChannel(MavenArtifact artifact) { boolean requireChannel = Boolean.parseBoolean(artifact.getMetadata().get(REQUIRE_CHANNEL_FOR_ALL_ARTIFACT)); try { - if (!requireChannel && ! fpRequireChannel(artifact)) { - return false; - } else { - return true; - } + return requireChannel || fpRequireChannel(artifact); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonCallbackAdapter.java b/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonCallbackAdapter.java index 13744e212..137f91355 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonCallbackAdapter.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonCallbackAdapter.java @@ -21,7 +21,6 @@ import org.jboss.galleon.progresstracking.ProgressTracker; import org.jboss.galleon.state.ProvisionedConfig; import org.jboss.galleon.universe.FeaturePackLocation; -import org.jboss.galleon.universe.maven.MavenArtifact; import org.wildfly.prospero.ProsperoLogger; import org.wildfly.prospero.api.Console; import org.wildfly.prospero.api.ProvisioningProgressEvent; @@ -127,7 +126,7 @@ public void processing(ProgressTracker tracker) { } break; case GalleonEnvironment.TRACK_JB_ARTIFACTS_RESOLVE: - item = tracker.getItem() != null?((MavenArtifact)tracker.getItem()).toString():""; + item = tracker.getItem() != null?tracker.getItem().toString():""; break; } final ProvisioningProgressEvent progress = new ProvisioningProgressEvent(id, ProvisioningProgressEvent.EventType.UPDATE, diff --git a/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonUtils.java b/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonUtils.java index ee48edc5d..caf7481c1 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonUtils.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/galleon/GalleonUtils.java @@ -98,7 +98,7 @@ public static void executeGalleon(GalleonExecution execution, Path localReposito logger.trace(" " + key + ": " + System.getenv().get(key)); } logger.trace("Galleon options:"); - for (Object key : options.keySet()) { + for (String key : options.keySet()) { logger.trace(" " + key + ": " + options.get(key)); } } diff --git a/prospero-common/src/main/java/org/wildfly/prospero/licenses/LicenseManager.java b/prospero-common/src/main/java/org/wildfly/prospero/licenses/LicenseManager.java index a5a3f1ca9..95900108d 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/licenses/LicenseManager.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/licenses/LicenseManager.java @@ -47,7 +47,7 @@ public class LicenseManager { private static final String LICENSE_DEFINITION_EXTENSION = ".yaml"; private static final String DEFAULT_LICENSE_DEFINITION = LICENSE_DEFINITION_NAME + LICENSE_DEFINITION_EXTENSION; protected static final String LICENSE_AGREEMENT_FILENAME= "license_accepted.properties"; - private final HashMap> nameMap = new HashMap(); + private final HashMap> nameMap = new HashMap<>(); public LicenseManager() { this(getLicensesFile()); diff --git a/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactBundle.java b/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactBundle.java index ca9e6becd..8d3f21f26 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactBundle.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactBundle.java @@ -67,16 +67,9 @@ public void close() { } public static ArtifactBundle extract(Path archivePath) throws IOException { - Path extracted = null; - try { - // TODO: validate content?? - - return new ArtifactBundle(unzipArchive(archivePath.toFile())); - } finally { - if (extracted != null) { - FileUtils.deleteQuietly(extracted.toFile()); - } - } + // TODO: validate content?? + + return new ArtifactBundle(unzipArchive(archivePath.toFile())); } public static Path createCustomizationArchive(List artifacts, File archive) throws IOException { diff --git a/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactPromoter.java b/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactPromoter.java index 12501886b..f30c26556 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactPromoter.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/promotion/ArtifactPromoter.java @@ -121,7 +121,7 @@ private void deployResolvedArtifacts(List results) throws Deploy log.debugf("Deploying %s artifacts from custom bundle to %s", results.size(), targetRepository.getUrl()); final DeployRequest deployRequest = new DeployRequest(); deployRequest.setRepository(targetRepository); - results.stream().forEach(result -> deployRequest.setArtifacts(Arrays.asList(result.getArtifact()))); + results.forEach(result -> deployRequest.setArtifacts(Arrays.asList(result.getArtifact()))); system.deploy(session, deployRequest); } @@ -142,13 +142,14 @@ private ChannelManifest resolveDeployedChannel(ChannelCoordinate coordinate, Opt if (version.isPresent()) { log.debugf("Found existing customization channel with version %s", version.get()); - ChannelCoordinate fullCoordinate = new ChannelCoordinate(coordinate.getGroupId(), coordinate.getArtifactId(), version.get()); - final MavenVersionsResolver resolver = new VersionResolverFactory(system, session).create(Arrays.asList(new Repository(targetRepository.getId(), targetRepository.getUrl()))); + try(VersionResolverFactory versionResolverFactory = new VersionResolverFactory(system, session)) { + final MavenVersionsResolver resolver = versionResolverFactory.create(Arrays.asList(new Repository(targetRepository.getId(), targetRepository.getUrl()))); - final File file = resolver.resolveArtifact(coordinate.getGroupId(), coordinate.getArtifactId(), - ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, version.get()); - return ChannelManifestMapper.fromString(Files.readString(file.toPath())); + final File file = resolver.resolveArtifact(coordinate.getGroupId(), coordinate.getArtifactId(), + ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER, version.get()); + return ChannelManifestMapper.fromString(Files.readString(file.toPath())); + } } else { log.debugf("No existing customization channel found, creating new channel"); return new ChannelManifest("custom-channel", "custom-channel", "Customization channel", new ArrayList<>()); diff --git a/prospero-common/src/main/java/org/wildfly/prospero/spi/ProsperoInstallationManager.java b/prospero-common/src/main/java/org/wildfly/prospero/spi/ProsperoInstallationManager.java index 643473e5b..e1e644257 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/spi/ProsperoInstallationManager.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/spi/ProsperoInstallationManager.java @@ -86,7 +86,7 @@ public InstallationChanges revisionDetails(String revision) throws MetadataExcep final org.wildfly.prospero.api.InstallationChanges changes = historyAction.compare(new SavedState(revision)); if (changes.isEmpty()) { - return new InstallationChanges(Collections.EMPTY_LIST, Collections.EMPTY_LIST); + return new InstallationChanges(Collections.emptyList(), Collections.emptyList()); } else { final List artifacts = changes.getArtifactChanges().stream() .map(ProsperoInstallationManager::mapArtifactChange) diff --git a/prospero-common/src/main/java/org/wildfly/prospero/test/MetadataTestUtils.java b/prospero-common/src/main/java/org/wildfly/prospero/test/MetadataTestUtils.java index f7392c414..044631a36 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/test/MetadataTestUtils.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/test/MetadataTestUtils.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -52,7 +51,6 @@ import org.wildfly.channel.Repository; import org.wildfly.channel.Stream; import org.wildfly.prospero.api.InstallationMetadata; -import org.wildfly.prospero.api.SavedState; import org.wildfly.prospero.api.exceptions.MetadataException; import org.wildfly.prospero.metadata.ProsperoMetadataUtils; import org.wildfly.prospero.model.ProsperoConfig; @@ -183,9 +181,4 @@ public static void upgradeStreamInManifest(Path manifestPath, Artifact upgrade) .collect(Collectors.toList()); Files.writeString(manifestPath, ChannelManifestMapper.toYaml(new ChannelManifest(manifest.getName(), manifest.getId(), manifest.getDescription(), updatedStreams))); } - - public static String getLatestRevision(Path installationPath) throws MetadataException { - final InstallationMetadata im = InstallationMetadata.loadInstallation(installationPath); - return im.getRevisions().stream().sorted(Comparator.comparing(SavedState::getTimestamp)).findFirst().get().getName(); - } } diff --git a/prospero-common/src/main/java/org/wildfly/prospero/updates/UpdateFinder.java b/prospero-common/src/main/java/org/wildfly/prospero/updates/UpdateFinder.java index 5b13abcab..f868bd9e7 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/updates/UpdateFinder.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/updates/UpdateFinder.java @@ -91,19 +91,10 @@ private Optional findUpdates(Artifact artifact) throws ArtifactR } final Artifact latest = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(), latestVersion); - if (latestVersion == null || latest.getVersion().equals(artifact.getVersion())) { return Optional.empty(); } else { - ArtifactChange change; - if (artifact == null) { - change = ArtifactChange.added(latest); - } else if (latest == null) { - change = ArtifactChange.removed(latest); - } else { - change = ArtifactChange.updated(artifact, latest); - } - return Optional.of(change); + return Optional.of(ArtifactChange.updated(artifact, latest)); } } diff --git a/prospero-common/src/test/java/org/wildfly/prospero/actions/ApplyCandidateActionTest.java b/prospero-common/src/test/java/org/wildfly/prospero/actions/ApplyCandidateActionTest.java index fd7f3b7d7..821b641b1 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/actions/ApplyCandidateActionTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/actions/ApplyCandidateActionTest.java @@ -62,6 +62,7 @@ import static org.wildfly.prospero.metadata.ProsperoMetadataUtils.CURRENT_VERSION_FILE; import static org.wildfly.prospero.metadata.ProsperoMetadataUtils.METADATA_DIR; +@SuppressWarnings({"OptionalGetWithoutIsPresent", "ResultOfMethodCallIgnored"}) public class ApplyCandidateActionTest { private static final String FPL_100 = "org.test:pack-one:1.0.0:zip"; @@ -244,7 +245,9 @@ public void testMetadataUpdated() throws Exception { assertTrue(Files.readString(installationPath.resolve(Constants.PROVISIONED_STATE_DIR).resolve(Constants.PROVISIONED_STATE_XML)) .contains(FPL_101)); // verify update was recorded - assertEquals(2, new GitStorage(installationPath).getRevisions().size()); + try(GitStorage gitStorage = new GitStorage(installationPath)) { + assertEquals(2, gitStorage.getRevisions().size()); + } } @Test diff --git a/prospero-common/src/test/java/org/wildfly/prospero/api/ChannelChangeTest.java b/prospero-common/src/test/java/org/wildfly/prospero/api/ChannelChangeTest.java index f601f25d9..23d0ae5c7 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/api/ChannelChangeTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/api/ChannelChangeTest.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class ChannelChangeTest { private final Channel channel1 = new Channel("channel-1", null, null, diff --git a/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java b/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java index a84890505..69e476c73 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/galleon/CachedVersionResolverTest.java @@ -49,6 +49,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@SuppressWarnings("OptionalGetWithoutIsPresent") @RunWith(MockitoJUnitRunner.class) public class CachedVersionResolverTest { @Mock diff --git a/prospero-common/src/test/java/org/wildfly/prospero/galleon/inspect/GalleonPackInspector.java b/prospero-common/src/test/java/org/wildfly/prospero/galleon/inspect/GalleonPackInspector.java index 63b426c27..1cd95ee48 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/galleon/inspect/GalleonPackInspector.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/galleon/inspect/GalleonPackInspector.java @@ -192,7 +192,7 @@ private Map readProperties(Path propsFile) throws ProvisioningEx String line = reader.readLine(); while(line != null) { line = line.trim(); - if(line.charAt(0) != '#' && !line.isEmpty()) { + if(!line.isEmpty() && line.charAt(0) != '#') { final int i = line.indexOf('='); if(i < 0) { throw new ProvisioningException("Failed to parse property " + line + " from " + propsFile); diff --git a/prospero-common/src/test/java/org/wildfly/prospero/installation/LocalInstallationHistoryTest.java b/prospero-common/src/test/java/org/wildfly/prospero/installation/LocalInstallationHistoryTest.java index 6c7cfb9bc..0a3f30f43 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/installation/LocalInstallationHistoryTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/installation/LocalInstallationHistoryTest.java @@ -44,6 +44,7 @@ import static org.junit.Assert.assertEquals; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class LocalInstallationHistoryTest { @Rule diff --git a/prospero-common/src/test/java/org/wildfly/prospero/installation/git/GitStorageTest.java b/prospero-common/src/test/java/org/wildfly/prospero/installation/git/GitStorageTest.java index a3cdf13a8..595f7b235 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/installation/git/GitStorageTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/installation/git/GitStorageTest.java @@ -59,6 +59,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class GitStorageTest { @Rule @@ -372,14 +373,14 @@ record = new ManifestVersionRecord(); final Path revertedMetadata = revertPath.resolve(ProsperoMetadataUtils.METADATA_DIR); assertTrue(ManifestYamlSupport.parse(revertedMetadata.resolve(ProsperoMetadataUtils.MANIFEST_FILE_NAME).toFile()) .getStreams().stream() - .filter(s->s.getArtifactId().equals("test") && s.getVersion().equals("1.2.3")).findFirst().isPresent()); + .anyMatch(s->s.getArtifactId().equals("test") && s.getVersion().equals("1.2.3"))); assertEquals("1.0.0", ManifestVersionRecord.read(revertedMetadata.resolve(ProsperoMetadataUtils.CURRENT_VERSION_FILE)) .get().getMavenManifests().get(0).getVersion()); // verify the base folder has not been changed assertTrue(ManifestYamlSupport.parse(base.resolve(ProsperoMetadataUtils.MANIFEST_FILE_NAME).toFile()) .getStreams().stream() - .filter(s->s.getArtifactId().equals("test") && s.getVersion().equals("1.2.4")).findFirst().isPresent()); + .anyMatch(s->s.getArtifactId().equals("test") && s.getVersion().equals("1.2.4"))); assertEquals("1.0.1", ManifestVersionRecord.read(base.resolve(ProsperoMetadataUtils.CURRENT_VERSION_FILE)) .get().getMavenManifests().get(0).getVersion()); } diff --git a/prospero-common/src/test/java/org/wildfly/prospero/model/ManifestVersionRecordTest.java b/prospero-common/src/test/java/org/wildfly/prospero/model/ManifestVersionRecordTest.java index f065558bd..51d95632f 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/model/ManifestVersionRecordTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/model/ManifestVersionRecordTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertEquals; import static org.wildfly.prospero.metadata.ProsperoMetadataUtils.CURRENT_VERSION_FILE; +@SuppressWarnings("OptionalGetWithoutIsPresent") public class ManifestVersionRecordTest { @Rule diff --git a/prospero-common/src/test/java/org/wildfly/prospero/promotion/ArtifactPromoterTest.java b/prospero-common/src/test/java/org/wildfly/prospero/promotion/ArtifactPromoterTest.java index 31c307ef5..3ab9c68ec 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/promotion/ArtifactPromoterTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/promotion/ArtifactPromoterTest.java @@ -262,7 +262,7 @@ private ChannelManifest getManifest(ChannelCoordinate channelGa) throws IOExcept final Set allVersions = resolver.getAllVersions(channelGa.getGroupId(), channelGa.getArtifactId(), ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER); - final Optional latestVersion = allVersions.stream().sorted(VersionMatcher.COMPARATOR.reversed()).findFirst(); + final Optional latestVersion = allVersions.stream().max(VersionMatcher.COMPARATOR); if (latestVersion.isEmpty()) { throw new ArtifactTransferException("No latestVersion", Collections.emptySet(), Collections.emptySet()); diff --git a/prospero-common/src/test/java/org/wildfly/prospero/spi/ProsperoInstallationManagerTest.java b/prospero-common/src/test/java/org/wildfly/prospero/spi/ProsperoInstallationManagerTest.java index eb6df6352..c7335f492 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/spi/ProsperoInstallationManagerTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/spi/ProsperoInstallationManagerTest.java @@ -47,6 +47,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@SuppressWarnings("OptionalGetWithoutIsPresent") @RunWith(MockitoJUnitRunner.class) public class ProsperoInstallationManagerTest { private static final Channel CHANNEL_1 = new Channel("channel-1", null, null, diff --git a/prospero-common/src/test/java/org/wildfly/prospero/updates/UpdateFinderTest.java b/prospero-common/src/test/java/org/wildfly/prospero/updates/UpdateFinderTest.java index ce55ea158..bf47b4242 100644 --- a/prospero-common/src/test/java/org/wildfly/prospero/updates/UpdateFinderTest.java +++ b/prospero-common/src/test/java/org/wildfly/prospero/updates/UpdateFinderTest.java @@ -36,6 +36,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.when; +@SuppressWarnings("OptionalGetWithoutIsPresent") @RunWith(MockitoJUnitRunner.class) public class UpdateFinderTest { diff --git a/prospero-metadata/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java b/prospero-metadata/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java index 907f0390d..ec5483ad6 100644 --- a/prospero-metadata/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java +++ b/prospero-metadata/src/main/java/org/wildfly/prospero/metadata/ManifestVersionResolver.java @@ -103,10 +103,11 @@ public ManifestVersionRecord getCurrentVersions(List channels) throws I } private String read(URL url) throws IOException { - final InputStream inputStream = url.openStream(); - final OutputStream outputStream = new ByteArrayOutputStream(); - inputStream.transferTo(outputStream); - return outputStream.toString(); + try(InputStream inputStream = url.openStream(); + OutputStream outputStream = new ByteArrayOutputStream()) { + inputStream.transferTo(outputStream); + return outputStream.toString(); + } } private static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system,