Skip to content

Commit

Permalink
[SHRINKRES-325] Migrating Java language level to Java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
petrberan committed Dec 1, 2023
1 parent 56db390 commit 8e5391d
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.jboss.shrinkwrap.impl.gradle.archive.importer.embedded;

import java.io.File;
import java.io.FilenameFilter;
import java.net.URI;

import org.gradle.tooling.BuildLauncher;
Expand Down Expand Up @@ -112,12 +111,7 @@ private File importFromDefaultLibsDirectory() {
final GradleProject currentGradleProject = findCurrentGradleProject();
final File buildDir = currentGradleProject.getBuildDirectory();
final File libsDir = new File(buildDir, "libs");
final File[] results = libsDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.startsWith(currentGradleProject.getName());
}
});
final File[] results = libsDir.listFiles((dir, name) -> name.startsWith(currentGradleProject.getName()));

if (results == null || results.length == 0) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ static ClassLoader getThreadContextClassLoader() {

static String getProperty(final String key) {
try {
String value = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
@Override
public String run() {
return System.getProperty(key);
}
});
String value = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> System.getProperty(key));
return value;
}
// Unwrap
Expand Down Expand Up @@ -93,12 +88,7 @@ public String run() {

static Properties getProperties() {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() {
@Override
public Properties run() {
return System.getProperties();
}
});
return AccessController.doPrivileged((PrivilegedExceptionAction<Properties>) System::getProperties);
}
// Unwrap
catch (final PrivilegedActionException pae) {
Expand Down Expand Up @@ -128,13 +118,8 @@ static URL getResource(final String resource) {
// AccessController.doPrivileged(SecurityActions.GetTcclAction.INSTANCE).getResource(resourceName);

try {
URL value = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() {
@Override
public URL run() throws Exception {
return getThreadContextClassLoader().getResource(resource);
}

});
URL value = AccessController.doPrivileged((PrivilegedExceptionAction<URL>)
() -> getThreadContextClassLoader().getResource(resource));

return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.codehaus.plexus.util.SelectorUtils;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.Filter;
import org.jboss.shrinkwrap.api.Node;
import org.jboss.shrinkwrap.api.ShrinkWrap;

Expand All @@ -44,32 +43,28 @@ public static <T extends Archive<?>> T filterArchiveContent(T archive, Class<T>
final List<String> excludes) {

// get all files that should be included in archive
Map<ArchivePath, Node> includePart = archive.getContent(new Filter<ArchivePath>() {
@Override
public boolean include(ArchivePath path) {
Map<ArchivePath, Node> includePart = archive.getContent(path -> {

// trim first slash
String pathAsString = path.get();
pathAsString = pathAsString.startsWith("/") ? pathAsString.substring(1) : pathAsString;
// trim first slash
String pathAsString = path.get();
pathAsString = pathAsString.startsWith("/") ? pathAsString.substring(1) : pathAsString;

boolean include = false;
// include all files that should be included
includesLoop: for (String i : includes) {
// paths in ShrinkWrap archives are always "/" separated
if (SelectorUtils.matchPath(i, pathAsString, "/", true)) {
// if file should be included, check also for excludes
for (String e : excludes) {
if (SelectorUtils.matchPath(e, pathAsString, "/", true)) {
break includesLoop;
}
boolean include = false;
// include all files that should be included
includesLoop: for (String i : includes) {
// paths in ShrinkWrap archives are always "/" separated
if (SelectorUtils.matchPath(i, pathAsString, "/", true)) {
// if file should be included, check also for excludes
for (String e : excludes) {
if (SelectorUtils.matchPath(e, pathAsString, "/", true)) {
break includesLoop;
}
include = true;
break;
}
include = true;
break;
}

return include;
}
return include;
});

// create new archive and merge content together
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,17 @@ public WarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy)
protected Filter<ArchivePath> createFilter(WarPluginConfiguration configuration) {
final List<String> filesToIncludes = Arrays.asList(getFilesToIncludes(configuration.getWarSourceDirectory(),
configuration.getIncludes(), configuration.getExcludes()));
return new Filter<ArchivePath>() {
@Override
public boolean include(ArchivePath archivePath) {
final String stringifiedPath = archivePath.get();
if (filesToIncludes.contains(stringifiedPath)) {
return archivePath -> {
final String stringifiedPath = archivePath.get();
if (filesToIncludes.contains(stringifiedPath)) {
return true;
}
for (String fileToInclude : filesToIncludes) {
if (fileToInclude.startsWith(stringifiedPath)) {
return true;
}
for (String fileToInclude : filesToIncludes) {
if (fileToInclude.startsWith(stringifiedPath)) {
return true;
}
}
return false;
}
return false;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ private SecurityActions() {

static String getProperty(final String key) {
try {
String value = AccessController.doPrivileged(new PrivilegedExceptionAction<String>() {
@Override
public String run() {
return System.getProperty(key);
}
});
String value = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> System.getProperty(key));
return value;
}
// Unwrap
Expand Down Expand Up @@ -74,12 +69,7 @@ public String run() {

static Properties getProperties() {
try {
Properties value = AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() {
@Override
public Properties run() {
return System.getProperties();
}
});
Properties value = AccessController.doPrivileged((PrivilegedExceptionAction<Properties>) System::getProperties);
return value;
}
// Unwrap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jboss.shrinkwrap.resolver.impl.maven.embedded;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -59,13 +58,7 @@ public NEXT_STEP useDistribution(URL mavenDistribution, boolean useCache) {
}

private File retrieveBinDirectory(File uncompressed) {
File[] extracted = uncompressed.listFiles(new FileFilter() {

@Override
public boolean accept(File file) {
return file.isDirectory();
}
});
File[] extracted = uncompressed.listFiles(File::isDirectory);
if (extracted.length == 0) {
throw new IllegalArgumentException("No directory has been extracted from the archive: " + uncompressed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ private void verifyOneOccurrenceInLog(String expMsg){
}

private Thread createThreadWithDownload(final CountDownLatch startLatch, final CountDownLatch stopLatch) {
return new Thread(new Runnable() {
@Override
public void run() {
try {
startLatch.await();
downloadAndExtractMavenBinaryArchive();
stopLatch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
return new Thread(() -> {
try {
startLatch.await();
downloadAndExtractMavenBinaryArchive();
stopLatch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ public void testDownloadDefaultMavenAndExtractUsingMultipleThreads() throws IOEx

private Thread createThreadWithExtract(final CountDownLatch startLatch, final CountDownLatch stopLatch,
final File downloaded) {
return new Thread(new Runnable() {
@Override
public void run() {
try {
startLatch.await();
FileExtractor.extract(downloaded,
Paths.get(MAVEN_TARGET_DIR, "948110de4aab290033c23bf4894f7d9a").toFile());
stopLatch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Thread(() -> {
try {
startLatch.await();
FileExtractor.extract(downloaded,
Paths.get(MAVEN_TARGET_DIR, "948110de4aab290033c23bf4894f7d9a").toFile());
stopLatch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jboss.shrinkwrap.resolver.impl.maven.embedded;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -97,16 +96,13 @@ public void testDownloadInMultipleThreads() throws InterruptedException {
}

private Thread createThreadWithDownload(final CountDownLatch startLatch, final CountDownLatch stopLatch) {
return new Thread(new Runnable() {
@Override
public void run() {
try {
startLatch.await();
downloadSWRArchive("3.0.0-alpha-1");
stopLatch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Thread(() -> {
try {
startLatch.await();
downloadSWRArchive("3.0.0-alpha-1");
stopLatch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
Expand Down Expand Up @@ -190,11 +186,7 @@ public void shouldExtractZipInDirWithNameMD5HashOfFile() {
}

private void verifyExtraction(int expectedNumberOfDirs, String... expectedDirNames) {
File[] dirsForExtraction = targetMavenDir.listFiles(new FileFilter() {
@Override public boolean accept(File file) {
return !file.getName().equals("downloaded");
}
});
File[] dirsForExtraction = targetMavenDir.listFiles(file -> !file.getName().equals("downloaded"));

assertThat(dirsForExtraction)
.as("there should be " + expectedNumberOfDirs + " dir(s) containing extraction")
Expand All @@ -205,11 +197,7 @@ private void verifyExtraction(int expectedNumberOfDirs, String... expectedDirNam
File[] allFiles = dirsForExtraction[i].listFiles();
assertThat(allFiles).as("there should be one dir with extracted files").hasSize(1);

File[] extractedDir = dirsForExtraction[i].listFiles(new FileFilter() {
@Override public boolean accept(File file) {
return file.isDirectory();
}
});
File[] extractedDir = dirsForExtraction[i].listFiles(File::isDirectory);
assertTrue("the name of the extracted dir has to be in the list of expected names: " + allExpectedDirNames,
allExpectedDirNames.remove(extractedDir[0].getName()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.DefaultInvoker;
Expand Down Expand Up @@ -51,20 +50,12 @@ public void testWhenDaemonIsUsedEndOfTheBuildIsNotReached() throws InterruptedEx
.useAsDaemon()
.build();

Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return outContent.toString().contains("Embedded Maven build started");
}
});
Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS)
.until(() -> outContent.toString().contains("Embedded Maven build started"));
Assertions.assertThat(outContent.toString()).doesNotContain("Embedded Maven build stopped");

Awaitility.await("Wait till project is not be null").atMost(20, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return daemonBuild.getBuiltProject() != null;
}
});
Awaitility.await("Wait till project is not be null").atMost(20, TimeUnit.SECONDS)
.until(() -> daemonBuild.getBuiltProject() != null);

Assertions.assertThat(daemonBuild.isAlive()).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jboss.shrinkwrap.resolver.impl.maven.embedded.pom.equipped;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.assertj.core.api.Assertions;
Expand Down Expand Up @@ -34,12 +33,8 @@ public void testDaemonShouldWaitForBuildSuccess() throws TimeoutException, Inter
.withWaitUntilOutputLineMathes(".*BUILD SUCCESS.*")
.build();

Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return !daemonBuild.isAlive();
}
});
Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS)
.until(() -> !daemonBuild.isAlive());

Assertions.assertThat(daemonBuild.getBuiltProject()).isNotNull();
verifyJarSampleSimpleBuild(daemonBuild.getBuiltProject());
Expand All @@ -55,23 +50,15 @@ public void testDaemonWithoutWaitShouldNotReachTheEndOfTheBuild() throws Interru
.useAsDaemon()
.build();

Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return systemOutRule.getLog().contains("Embedded Maven build started");
}
});
Awaitility.await("Wait till maven build is started").atMost(5, TimeUnit.SECONDS)
.until(() -> systemOutRule.getLog().contains("Embedded Maven build started"));
Assertions.assertThat(systemOutRule.getLog()).doesNotContain("Embedded Maven build stopped");
Assertions.assertThat(systemOutRule.getLog()).doesNotContain("Embedded Maven build stopped");
Assertions.assertThat(daemonBuild.isAlive()).isTrue();
Assertions.assertThat(daemonBuild.getBuiltProject()).isNull();

Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return !daemonBuild.isAlive();
}
});
Awaitility.await("Wait till thread is not be alive").atMost(20, TimeUnit.SECONDS)
.until(() -> !daemonBuild.isAlive());

Assertions.assertThat(daemonBuild.isAlive()).isFalse();
verifyJarSampleSimpleBuild(daemonBuild.getBuiltProject());
Expand Down
Loading

0 comments on commit 8e5391d

Please sign in to comment.