Skip to content

Commit

Permalink
[SHRINKRES-326] Resolve some performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
petrberan committed Feb 20, 2024
1 parent 56db390 commit 4201b57
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jboss.shrinkwrap.resolver.api.maven.strategy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency;
Expand Down Expand Up @@ -55,9 +56,7 @@ public MavenResolutionFilter[] getResolutionFilters() {
private MavenResolutionFilter[] combine(final MavenResolutionFilter[]... inputFilterChains) {
final List<MavenResolutionFilter> combinedFilters = new ArrayList<MavenResolutionFilter>();
for (final MavenResolutionFilter[] filterChain : inputFilterChains) {
for (int i = 0; i < filterChain.length; i++) {
combinedFilters.add(filterChain[i]);
}
combinedFilters.addAll(Arrays.asList(filterChain));
}
return combinedFilters.toArray(EMPTY_FILTER_ARRAY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -115,8 +115,7 @@ static Map<String, Object> valueAsMap(Map<String, Object> map, Key key, Map<Stri
* @return Map representation of the values mapped into Strings
*/
static Map<String, String> valueAsMapOfStrings(Map<String, Object> map, Key key, Map<String, String> defaultValue) {
Map<String, Object> castedDefaultValue = new HashMap<String, Object>();
castedDefaultValue.putAll(defaultValue);
Map<String, Object> castedDefaultValue = new HashMap<String, Object>(defaultValue);

Map<String, Object> uncastedResult = valueAsMap(map, key, castedDefaultValue);
Map<String, String> castedResult = new HashMap<String, String>();
Expand Down Expand Up @@ -153,7 +152,7 @@ static List<String> valueAsStringList(Map<String, Object> map, Key key, List<Str
return defaultValue;

} else if (!(rawMapOrObject instanceof Map)) {
return Arrays.asList(rawMapOrObject.toString());
return Collections.singletonList(rawMapOrObject.toString());
}

// 1/ we can either have <excludes>foo,bar</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.jboss.shrinkwrap.resolver.impl.maven.archive.plugins;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

Expand All @@ -39,7 +38,7 @@ public JarPluginConfiguration(ParsedPomFile pomFile) {
super(pomFile);

Map<String, Object> rawValues = pomFile.getPluginConfiguration(JAR_PLUGIN_GA);
this.includes = ConfigurationUtils.valueAsStringList(rawValues, new Key("includes", "include"), Arrays.asList("**/**"))
this.includes = ConfigurationUtils.valueAsStringList(rawValues, new Key("includes", "include"), Collections.singletonList("**/**"))
.toArray(new String[0]);
this.excludes = ConfigurationUtils.valueAsStringList(rawValues, new Key("excludes", "exclude"),
Collections.<String> emptyList()).toArray(new String[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package org.jboss.shrinkwrap.resolver.impl.maven.archive.plugins;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.nio.file.Files;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -161,7 +160,7 @@ private Map<String, Map<String, String>> parseManifestSections(Map<String, Objec
Object sections = ((Map<String, Object>) rawOrSectionMap).get("manifestSection");
if (sections instanceof Map<?, ?>) {
// if single section was defined, wrap it into iterable element
sections = Arrays.asList(sections);
sections = Collections.singletonList(sections);
} else if (sections == null || !(sections instanceof Iterable<?>)) {
return Collections.<String, Map<String, String>> emptyMap();
}
Expand Down Expand Up @@ -202,7 +201,7 @@ ManifestBuilder loadFile() throws MavenImporterException {
if (Validate.isReadable(getManifestFile())) {
InputStream is = null;
try {
is = new FileInputStream(getManifestFile());
is = Files.newInputStream(getManifestFile().toPath());
Manifest userSupplied = new Manifest(is);
this.manifest = ManifestMerger.merge(userSupplied, manifest);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,7 +58,7 @@ public WarPluginConfiguration(ParsedPomFile pomFile) {

// includes
List<String> includes = new ArrayList<String>();
includes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("includes", "include"), Arrays.asList("**/**")));
includes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("includes", "include"), Collections.singletonList("**/**")));
includes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("packagingIncludes"),
Collections.<String> emptyList()));
includes.addAll(ConfigurationUtils.valueAsStringList(rawValues, new Key("warSourceIncludes"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void extractFileInDestinationDir() {
+ "For more information see the stacktrace", ee);
}
markerFileHandler.deleteMarkerFile();
System.out.println(String.format("Resolver: Successfully extracted maven binaries from %s", fileToExtract));
System.out.printf("Resolver: Successfully extracted maven binaries from %s%n", fileToExtract);
}

private File checkIfItIsAlreadyExtracted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ boolean waitTillMarkerFileIsGone(long timeoutInMilliseconds, String processName)
int count = 0;
while (isMarkerFilePresent() && count < timeoutInMilliseconds / 100) {
if (count == 0) {
System.out.println(
String.format(
"There is marker file %s, which means that some other process is already processing the %s -"
+ " waiting to be completed.", markerFile, processName));
System.out.printf("There is marker file %s, which means that some other process is already processing the %s -"
+ " waiting to be completed.%n", markerFile, processName);
}
System.out.print(".");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -192,7 +192,7 @@ static void packageDirectories(final File outputFile, final File... directories)

Validate.notNullAndNoNullValues(directories, "Directories to be packaged must be specified");

final ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(outputFile));
final ZipOutputStream zipFile = new ZipOutputStream(Files.newOutputStream(outputFile.toPath()));

for (File directory : directories) {
for (String entry : fileListing(directory)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected Settings getSettings() {
* @param programmaticOffline whether the resolver should work in offline mode or not
*/
protected void setOffline(Boolean programmaticOffline) {
this.programmaticOffline = new Boolean(programmaticOffline);
this.programmaticOffline = programmaticOffline;
// propagate offline(boolean) into settings if previously created
propagateProgrammaticOfflineIntoSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package org.jboss.shrinkwrap.resolver.impl.maven.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;

/**
* Simple shared utility to convert {@link URL} instances to {@link File} representation
Expand Down Expand Up @@ -96,7 +96,7 @@ private String getLocalResourcePathFromResourceName(final String resourceName, f
try {
File localResource = temporaryFile(resourceName);
localResource.deleteOnExit();
IOUtil.copyWithClose(resourceUrl.openStream(), new FileOutputStream(localResource));
IOUtil.copyWithClose(resourceUrl.openStream(), Files.newOutputStream(localResource.toPath()));
return localResource.getAbsolutePath();
} catch (IOException e) {
throw new IllegalArgumentException("Unable to open resource name specified by " + resourceName, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.jboss.shrinkwrap.resolver.impl.maven;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.eclipse.aether.repository.RemoteRepository;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void shouldGiveNewIndependentRepositories() throws NoSuchFieldException,
final String initialId = "id";
RemoteRepository remoteRepository = new RemoteRepository.Builder(initialId, "type", "url").build();
final MavenModelResolver mavenModelResolver = new MavenModelResolver(new MavenRepositorySystem(), null,
Arrays.asList(remoteRepository));
Collections.singletonList(remoteRepository));

// when
final MavenModelResolver mavenModelResolverCopy = (MavenModelResolver) mavenModelResolver.newCopy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand Down Expand Up @@ -70,7 +70,7 @@ private boolean canUnzip(File zipFile, File outputFolder) {
byte[] buffer = new byte[1024];

try (ZipInputStream zis =
new ZipInputStream(new FileInputStream(zipFile))) {
new ZipInputStream(Files.newInputStream(zipFile.toPath()))) {

//get the zipped file list entry
ZipEntry ze = zis.getNextEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public class ValidationUtil {
*/
public ValidationUtil(final String... requiredFileNamePrefixes) {
this.requiredFileNamePrefixes = new ArrayList<String>(requiredFileNamePrefixes.length);
for (final String file : requiredFileNamePrefixes) {
this.requiredFileNamePrefixes.add(file);
}
this.requiredFileNamePrefixes.addAll(Arrays.asList(requiredFileNamePrefixes));
}

/**
Expand Down Expand Up @@ -174,6 +172,7 @@ public void validate(final boolean validateOrder, final List<File> resolvedFiles
for (final String requiredFileName : this.requiredFileNamePrefixes) {
if (resolvedFileName.startsWith(requiredFileName)) {
found = true;
break;
}
}
if (!found) {
Expand Down

0 comments on commit 4201b57

Please sign in to comment.