Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SHRINKRES-325] Migrating Java language level to Java 8 #189

Merged
merged 3 commits into from
Apr 16, 2024
Merged
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
38 changes: 4 additions & 34 deletions api/src/main/java/org/jboss/shrinkwrap/resolver/api/Invokable.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,8 @@ Object invokeMethod(String name, Class<?>[] parameterTypes, Object instance, Obj
throws InvocationException {
try {
return findMethod(name, parameterTypes).invoke(instance, parameters);
} catch (IllegalAccessException e) {
throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name,
parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters);
} catch (IllegalArgumentException e) {
throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name,
parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters);
} catch (InvocationTargetException e) {
throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name,
parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters);
} catch (SecurityException e) {
throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name,
parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters);
} catch (InvocationException e) {
} catch (IllegalAccessException | InvocationException | SecurityException | InvocationTargetException |
IllegalArgumentException e) {
throw new InvocationException(e, "Unable to invoke {0}({1}) on object {2} with parameters {3}", name,
parameterTypes, instance == null ? "" : instance.getClass().getName(), parameters);
}
Expand All @@ -129,27 +118,8 @@ Object invokeConstructor(Class<?>[] parameterTypes, Object[] parameters) throws
try {
Constructor<?> con = classType.getConstructor(parameterTypes);
return con.newInstance(parameters);
} catch (NoSuchMethodException e) {
throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}",
classType.getSimpleName(),
parameterTypes, parameters);
} catch (SecurityException e) {
throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}",
classType.getSimpleName(),
parameterTypes, parameters);
} catch (InstantiationException e) {
throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}",
classType.getSimpleName(),
parameterTypes, parameters);
} catch (IllegalAccessException e) {
throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}",
classType.getSimpleName(),
parameterTypes, parameters);
} catch (IllegalArgumentException e) {
throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}",
classType.getSimpleName(),
parameterTypes, parameters);
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException | InvocationTargetException | IllegalArgumentException | IllegalAccessException |
InstantiationException | SecurityException e) {
throw new InvocationException(e, "Unable to invoke constructor {0}({1}) with parameters {3}",
classType.getSimpleName(),
parameterTypes, parameters);
Expand Down
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 @@ -28,12 +28,12 @@ private AssertArchive() {
throw new UnsupportedOperationException("Utils class");
}

public static void assertContains(Archive archive, String path) {
public static void assertContains(Archive<?> archive, String path) {
assertThat(archive.contains(path)).as(path + " should be included in archive " + archive.toString(true))
.isTrue();
}

public static void assertNotContains(Archive archive, String path) {
public static void assertNotContains(Archive<?> archive, String path) {
assertThat(archive.contains(path)).as(path + " should NOT be included in archive " + archive.toString(true))
.isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public List<File> getDependenciesByScope(final ScopeType scopeType) {
if (effectiveModelGroupedByScope.containsKey(scopeType)) {
return Collections.unmodifiableList(effectiveModelGroupedByScope.get(scopeType));
} else {
return Collections.unmodifiableList(new ArrayList<File>());
return Collections.unmodifiableList(new ArrayList<>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public GradleStrategyStage(final String projectDirectory, final Set<ScopeType> s
* @param archive ShrinkWrap archive.
* @return Array of dependencies and transitive ones for configured state.
*/
public Archive[] as(final Class<? extends Archive> archive) {
final List<? extends Archive> archives = asList(archive);
public Archive<?>[] as(final Class<? extends Archive<?>> archive) {
final List<? extends Archive<?>> archives = asList(archive);
return archives.toArray(new Archive[archives.size()]);
}

Expand All @@ -40,16 +40,16 @@ public Archive[] as(final Class<? extends Archive> archive) {
* @param archive ShrinkWrap archive.
* @return List of dependencies and transitive ones for configured state.
*/
public List<? extends Archive> asList(final Class<? extends Archive> archive) {
public List<? extends Archive<?>> asList(final Class<? extends Archive<?>> archive) {

final List<Archive> archives = new ArrayList<>();
final List<Archive<?>> archives = new ArrayList<>();
final GradleEffectiveDependencies gradleEffectiveDependencies = GradleRunner.getEffectiveDependencies(projectDirectory);

for (ScopeType scopeType : scopeTypesDependencies) {
final List<File> dependenciesByScope = gradleEffectiveDependencies.getDependenciesByScope(scopeType);
for (File dependency : dependenciesByScope) {
try {
final Archive dep = ShrinkWrap.create(ZipImporter.class, dependency.getName()).importFrom(dependency).as(archive);
final Archive<?> dep = ShrinkWrap.create(ZipImporter.class, dependency.getName()).importFrom(dependency).as(archive);
archives.add(dep);
} catch (Exception e) {
log.log(Level.WARNING, "Cannot import gradle dependency " + dependency + ". Not a zip-like format", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ShrinkWrapGradleTestCase {

@Test
public void should_return_dependencies_by_scope_in_simple_build_script() {
final List<? extends Archive> archives = Gradle.resolver().forProjectDirectory("src/test/resources/simple")
final List<? extends Archive<?>> archives = Gradle.resolver().forProjectDirectory("src/test/resources/simple")
.importCompileAndRuntime()
.resolve().asList(JavaArchive.class);

Expand All @@ -21,7 +21,7 @@ public void should_return_dependencies_by_scope_in_simple_build_script() {

@Test
public void should_return_dependencies_by_scope_in_dependency_management_build_script() {
final List<? extends Archive> archives = Gradle.resolver().forProjectDirectory("src/test/resources/dependencymanager")
final List<? extends Archive<?>> archives = Gradle.resolver().forProjectDirectory("src/test/resources/dependencymanager")
.importRuntime()
.resolve().asList(JavaArchive.class);

Expand All @@ -30,7 +30,7 @@ public void should_return_dependencies_by_scope_in_dependency_management_build_s

@Test
public void should_skip_non_zip_files_in_depchain_build_script() {
final List<? extends Archive> archives = Gradle.resolver().forProjectDirectory("src/test/resources/depchain")
final List<? extends Archive<?>> archives = Gradle.resolver().forProjectDirectory("src/test/resources/depchain")
.importCompileAndRuntime()
.resolve().asList(JavaArchive.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface BuiltProject {
*
* @return An {@link Archive} with a default name. If no archive is found then null is returned
*/
Archive getDefaultBuiltArchive();
Archive<?> getDefaultBuiltArchive();

/**
* Returns an instance of {@link BuiltProject} representing module with the given name.
Expand Down Expand Up @@ -59,7 +59,7 @@ public interface BuiltProject {
* @return A list of all supported {@link Archive}s found in the first level of the build target directory.
* If no target directory is present then null is returned.
*/
List<Archive> getArchives();
List<Archive<?>> getArchives();

/**
* Returns a list of all {@link Archive}s of the given type of {@link Archive} found in the first level of the build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import org.jboss.shrinkwrap.resolver.api.maven.embedded.BuildStage;
import org.jboss.shrinkwrap.resolver.api.maven.embedded.BuiltProject;
import org.jboss.shrinkwrap.resolver.api.maven.embedded.daemon.DaemonBuildTrigger;
import org.jboss.shrinkwrap.resolver.api.maven.embedded.daemon.WithTimeoutDaemonBuilder;

/**
* @author <a href="mailto:mjobanek@gmail.com">Matous Jobanek</a>
*/
public interface ConfigurationStage<DIST_OR_CONFIG extends ConfigurationStage, DAEMON_TRIGGER_TYPE extends DaemonBuildTrigger>
extends BuildStage<DAEMON_TRIGGER_TYPE> {
public interface ConfigurationStage<DIST_OR_CONFIG extends ConfigurationStage<ConfigurationDistributionStage, WithTimeoutDaemonBuilder>
, DAEMON_TRIGGER_TYPE extends DaemonBuildTrigger> extends BuildStage<DAEMON_TRIGGER_TYPE> {

/**
* Sets the interaction mode of the Maven invocation. Equivalent of {@code -B} and {@code --batch-mode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class PackagingType {

private static final ConcurrentHashMap<String, PackagingType> cache = new ConcurrentHashMap<String, PackagingType>();
private static final ConcurrentHashMap<String, PackagingType> cache = new ConcurrentHashMap<>();

public static final PackagingType POM = new PackagingType("pom");
public static final PackagingType JAR = new PackagingType("jar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RejectDependenciesFilter(final boolean rejectTransitives, final String...
throw new IllegalArgumentException("There must be at least one coordinate specified to be rejected.");
}

final Set<MavenDependency> bannedDependencies = new HashSet<MavenDependency>(coordinates.length);
final Set<MavenDependency> bannedDependencies = new HashSet<>(coordinates.length);
for (final String coords : coordinates) {
final MavenCoordinate coordinate = MavenCoordinates.createCoordinate(coords);
final MavenDependency dependency = MavenDependencies.createDependency(coordinate, ScopeType.COMPILE, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AcceptScopesStrategy(final ScopeType... scopes) throws IllegalArgumentExc
if (scopes == null || scopes.length == 0) {
throw new IllegalArgumentException("at least one scope must be specified");
}
final Set<ScopeType> allowedScopes = new HashSet<ScopeType>(scopes.length);
final Set<ScopeType> allowedScopes = new HashSet<>(scopes.length);
allowedScopes.addAll(Arrays.asList(scopes));
this.resolutionFilters = new MavenResolutionFilter[] { new ScopeFilter(
allowedScopes.toArray(new ScopeType[] {})) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CombinedStrategy(final MavenResolutionStrategy... strategies) {
if (strategies.length == 0) {
throw new IllegalArgumentException("There must be at least one strategy for a combined strategy.");
}
final List<MavenResolutionFilter[]> resolutionFilterChains = new ArrayList<MavenResolutionFilter[]>();
final List<MavenResolutionFilter[]> resolutionFilterChains = new ArrayList<>();
for (final MavenResolutionStrategy strategy : strategies) {
resolutionFilterChains.add(strategy.getResolutionFilters());
}
Expand All @@ -54,7 +54,7 @@ public MavenResolutionFilter[] getResolutionFilters() {
}

private MavenResolutionFilter[] combine(final MavenResolutionFilter[]... inputFilterChains) {
final List<MavenResolutionFilter> combinedFilters = new ArrayList<MavenResolutionFilter>();
final List<MavenResolutionFilter> combinedFilters = new ArrayList<>();
for (final MavenResolutionFilter[] filterChain : inputFilterChains) {
combinedFilters.addAll(Arrays.asList(filterChain));
}
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() {
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 @@ -46,18 +46,12 @@ class ManifestAsset extends StringAsset {
* @return String representation of the Manifest
*/
private static String manifestAsString(Manifest manifest) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

try {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
manifest.write(baos);
return baos.toString("UTF-8");
} catch (IOException e) {
throw new IllegalStateException("Unable to write MANIFEST.MF to an archive Asset", e);
} finally {
try {
baos.close();
} catch (IOException e) {
}
}
}

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
Loading
Loading