Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,8 @@ public String addPlugin(final String pluginRootFile) {
return pluginId;
}

// Container lifecycle is owned by ContainerManager (registered on create, closed via removePlugin)
@SuppressWarnings({ "resource", "java:S2095" })
final String id = this.container
.builder(pluginRootFile)
.withCustomizer(createContainerCustomizer(pluginRootFile))
Expand All @@ -1053,6 +1055,8 @@ private String findPluginId(final String pluginRootFile) {
}

public String addWithLocationPlugin(final String location, final String pluginRootFile) {
// Container lifecycle is owned by ContainerManager (registered on create, closed via removePlugin)
@SuppressWarnings({ "resource", "java:S2095" })
final String id = this.container
.builder(pluginRootFile)
.withCustomizer(createContainerCustomizer(location))
Expand All @@ -1064,6 +1068,8 @@ public String addWithLocationPlugin(final String location, final String pluginRo
}

protected String addPlugin(final String forcedId, final String pluginRootFile) {
// Container lifecycle is owned by ContainerManager (registered on create, closed via removePlugin)
@SuppressWarnings({ "resource", "java:S2095" })
final String id = this.container
.builder(forcedId, pluginRootFile)
.withCustomizer(createContainerCustomizer(forcedId))
Expand Down Expand Up @@ -1831,21 +1837,23 @@ private Archive toArchive(final String module, final String moduleId, final Conf
final URL nestedJar =
loader.getParent().getResource(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + module);
if (nestedJar != null) {
InputStream nestedStream = null;
final JarInputStream jarStream;
final InputStream nestedStream;
try {
nestedStream = nestedJar.openStream();
jarStream = new JarInputStream(nestedStream);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
try {
final JarInputStream jarStream = new JarInputStream(nestedStream);
log.debug("Found a nested resource for " + module);
return new NestedJarArchive(nestedJar, jarStream, loader);
} catch (final IOException e) {
if (nestedStream != null) {
try { // normally not needed
nestedStream.close();
} catch (final IOException e1) {
// no-op
}
try { // normally not needed
nestedStream.close();
} catch (final IOException e1) {
// no-op
}
throw new IllegalStateException(e);
}
}
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonReader;
import javax.json.JsonString;
import javax.json.JsonValue;
import javax.json.spi.JsonProvider;
Expand Down Expand Up @@ -75,8 +76,9 @@ public SchemaConverter() {
@Override
public Object toObjectImpl(final String s) {
if (!s.isEmpty()) {
final JsonObject json = JsonProvider.provider().createReader(new StringReader(s)).readObject();
return toSchema(json);
try (final JsonReader reader = JsonProvider.provider().createReader(new StringReader(s))) {
return toSchema(reader.readObject());
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ private File buildSparkHome(final Version version) {
fail(e.getMessage());
}

try (final JarOutputStream file = new JarOutputStream(new FileOutputStream(new File(sparkHome,
version.libFolder() + "/spark-assembly-" + sparkVersion + "-hadoop2.6.0.jar")))) {
try (final FileOutputStream fos = new FileOutputStream(new File(sparkHome,
version.libFolder() + "/spark-assembly-" + sparkVersion + "-hadoop2.6.0.jar"));
final JarOutputStream file = new JarOutputStream(fos)) {
file.putNextEntry(new ZipEntry("META-INF/marker"));
file.write("just to let spark find the jar".getBytes(StandardCharsets.UTF_8));
} catch (final IOException e) {
Expand Down Expand Up @@ -452,6 +453,9 @@ public void submit(final Class<?> main, final String... args) {
args == null ? Stream.empty() : Stream.of(args))
.toArray(String[]::new);
LOGGER.info("Submitting: " + asList(submitArgs));
// Monitor is a long-running Thread; closed in the success branch below
// and via the cleanup task / shutdown hook fallback (see config.cleanupTasks).
@SuppressWarnings({ "resource", "java:S2095" })
final SparkProcessMonitor monitor = new SparkProcessMonitor(config.get(),
"spark-submit-" + main.getSimpleName() + "-monitor", () -> true, submitArgs);
final Thread hook = new Thread(monitor::close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ private byte[] generateConfigurationJar(final String family, final Properties us
mainAttributes.putValue("Created-By", "Talend Component Kit Server");
mainAttributes.putValue("Talend-Time", Long.toString(System.currentTimeMillis()));
mainAttributes.putValue("Talend-Family-Name", family);
try (final JarOutputStream jar = new JarOutputStream(new BufferedOutputStream(outputStream), manifest)) {
try (final BufferedOutputStream buffered = new BufferedOutputStream(outputStream);
final JarOutputStream jar = new JarOutputStream(buffered, manifest)) {
jar.putNextEntry(new JarEntry("TALEND-INF/local-configuration.properties"));
userConfiguration.store(jar, "Configuration of the family " + family);
jar.closeEntry();
Expand Down Expand Up @@ -300,9 +301,8 @@ private Map<Artifact, Path> findJars(final Path familyFolder, final String famil
if (!Files.isDirectory(familyFolder)) {
return emptyMap();
}
try {
return Files
.list(familyFolder)
try (final Stream<Path> files = Files.list(familyFolder)) {
return files
.filter(file -> file.getFileName().toString().endsWith(".jar"))
.collect(toMap(it -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@
final Path adoc = PathFactory.get(args[0]).toAbsolutePath();
final File output =
adoc.getParent().resolve(args.length > 1 ? args[1] : args[0].replace(".adoc", ".pdf")).toFile();
final List<String> lines = Files.lines(adoc).collect(toList());
final List<String> lines;
try (final Stream<String> stream = Files.lines(adoc)) {
lines = stream.collect(toList());

Check warning on line 91 in component-tools/src/main/java/org/talend/sdk/component/tools/AsciidoctorExecutor.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

component-tools/src/main/java/org/talend/sdk/component/tools/AsciidoctorExecutor.java#L91

Replace this usage of 'Stream.collect(Collectors.toList())' with 'Stream.toList()' and ensure that the list is unmodified.
}
final String version = lines
.stream()
.filter(it -> it.startsWith("v"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -53,7 +54,10 @@ public void close() throws IOException {
}

private boolean isDifferent(final byte[] bytes) throws IOException {
final String source = Files.lines(destination.toPath()).collect(joining("\n")).trim();
final String source;
try (final Stream<String> lines = Files.lines(destination.toPath())) {
source = lines.collect(joining("\n")).trim();
}
final String target = new String(bytes, StandardCharsets.UTF_8).trim();
return !source.equals(target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@

@Override
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
if (Files.list(dir).count() == 0) {
final boolean empty;
try (final Stream<Path> entries = Files.list(dir)) {
empty = entries.findAny().isEmpty();
}
if (empty) {
Files.delete(dir);
}
return super.postVisitDirectory(dir, exc);
Expand Down Expand Up @@ -342,7 +346,7 @@

private InputStream findTemplate(final String name) {
final Path override =
this.project.getBasedir().toPath().resolve("templates").resolve(websiteDir).resolve(name + ".mustache");

Check failure on line 349 in talend-component-maven-plugin/src/main/java/org/talend/sdk/component/maven/WebsiteBuilderMojo.java

View check run for this annotation

sonar-rnd / SonarQube Code Analysis

talend-component-maven-plugin/src/main/java/org/talend/sdk/component/maven/WebsiteBuilderMojo.java#L349

Define a constant instead of duplicating this literal ".mustache" 3 times.
if (Files.exists(override)) {
try {
return Files.newInputStream(override);
Expand All @@ -364,17 +368,21 @@
}

try {
Files.list(templatesDir).filter(it -> it.endsWith(".mustache")).forEach(template -> {
final String name = template.getFileName().toString();
try (final Reader tpl = Files.newBufferedReader(template);
final Writer writer = Files
.newBufferedWriter(
dir.resolve(name.substring(0, name.length() - "mustache".length()) + "html"))) {
mustacheFactory.compile(tpl, dir.getFileName().toString() + '_' + name).execute(writer, context);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
try (final Stream<Path> templates = Files.list(templatesDir)) {
templates.filter(it -> it.endsWith(".mustache")).forEach(template -> {
final String name = template.getFileName().toString();
try (final Reader tpl = Files.newBufferedReader(template);
final Writer writer = Files
.newBufferedWriter(
dir.resolve(name.substring(0, name.length() - "mustache".length())
+ "html"))) {
mustacheFactory.compile(tpl, dir.getFileName().toString() + '_' + name)
.execute(writer, context);
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
Expand Down
Loading