Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class BuildCacheMojosExecutionStrategy implements MojosExecutionStrategy
private final MojoParametersListener mojoListener;
private final LifecyclePhasesHelper lifecyclePhasesHelper;
private final MavenPluginManager mavenPluginManager;
private MojoExecutionScope mojoExecutionScope;
private final MojoExecutionScope mojoExecutionScope;

@Inject
public BuildCacheMojosExecutionStrategy(
Expand Down Expand Up @@ -434,6 +434,6 @@ private static String normalizedPath(Path path, Path baseDirPath) {
private enum CacheRestorationStatus {
SUCCESS,
FAILURE,
FAILURE_NEEDS_CLEAN;
FAILURE_NEEDS_CLEAN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class CacheControllerImpl implements CacheController {
* (ex : generated source basedir).
* Used to link the resource to its path on disk
*/
private Map<String, Path> attachedResourcesPathsById = new HashMap<>();
private final Map<String, Path> attachedResourcesPathsById = new HashMap<>();

private int attachedResourceCounter = 0;

Expand Down Expand Up @@ -467,7 +467,7 @@ private Future<File> createDownloadTask(
if (!Files.exists(artifactFile)) {
throw new FileNotFoundException("Missing file for cached build, cannot restore. File: " + artifactFile);
}
LOGGER.debug("Downloaded artifact " + artifact.getArtifactId() + " to: " + artifactFile);
LOGGER.debug("Downloaded artifact {} to: {}", artifact.getArtifactId(), artifactFile);
return restoreArtifactHandler
.adjustArchiveArtifactVersion(project, originalVersion, artifactFile)
.toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -132,7 +133,7 @@ private synchronized void buildModel(MavenSession session) {
File multiModulePomFile = getMultiModulePomFile(session);

ProjectBuildingRequest projectBuildingRequest = currentProject.getProjectBuildingRequest();
boolean profilesMatched = projectBuildingRequest.getActiveProfileIds().containsAll(scanProfiles);
boolean profilesMatched = new HashSet<>(projectBuildingRequest.getActiveProfileIds()).containsAll(scanProfiles);

// we are building from root with the same profiles, no need to re-scan the whole multi-module project
if (currentProject.getFile().getAbsolutePath().equals(multiModulePomFile.getAbsolutePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
Expand Down Expand Up @@ -96,7 +96,7 @@ public Path adjustArchiveArtifactVersion(MavenProject project, String originalAr
String pomPropsVersion = "version=" + currentVersion;
try (JarFile jarFile = new JarFile(artifactFile.toFile())) {
try (JarOutputStream jos =
new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tmpJarFile)))) {
new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(tmpJarFile.toPath())))) {
// Copy original jar file to the temporary one.
Enumeration<JarEntry> jarEntries = jarFile.entries();
byte[] buffer = new byte[1024];
Expand Down Expand Up @@ -140,7 +140,7 @@ public Path adjustArchiveArtifactVersion(MavenProject project, String originalAr
private static void replaceEntry(
JarFile jarFile, JarEntry entry, String toReplace, String replacement, JarOutputStream jos)
throws IOException {
String fullManifest = IOUtils.toString(jarFile.getInputStream(entry), StandardCharsets.UTF_8.name());
String fullManifest = IOUtils.toString(jarFile.getInputStream(entry), StandardCharsets.UTF_8);
String modified = fullManifest.replaceAll(toReplace, replacement);

byte[] bytes = modified.getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public boolean getArtifactContent(
return false;
}

@Nonnull
@Override
public String getResourceUrl(CacheContext context, String filename) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import org.apache.maven.model.Resource;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.WriterFactory;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.artifact.DefaultArtifactType;
Expand Down Expand Up @@ -344,19 +343,13 @@ private boolean checkItemMatchesBaseline(ProjectsInputInfo baselineBuild, Digest
private String getEffectivePom(Model prototype) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();

Writer writer = null;
try {
writer = WriterFactory.newXmlWriter(output);
try (Writer writer = WriterFactory.newXmlWriter(output)) {
new MavenXpp3Writer().write(writer, prototype);

// normalize env specifics
final String[] searchList = {baseDirPath.toString(), "\\", "windows", "linux"};
final String[] replacementList = {"", "/", "os.classifier", "os.classifier"};

return replaceEachRepeatedly(output.toString(), searchList, replacementList);

} finally {
IOUtil.close(writer);
}
}

Expand Down Expand Up @@ -520,7 +513,7 @@ public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFil
return FileVisitResult.SKIP_SUBTREE;
}

walkDirectoryFiles(path, collectedFiles, key.getGlob(), entry -> exclusionResolver.excludesPath(entry));
walkDirectoryFiles(path, collectedFiles, key.getGlob(), exclusionResolver::excludesPath);

if (!key.isRecursive()) {
LOGGER.debug("Skipping subtree (non recursive): {}", path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ public boolean excludesPath(Path parentPath, Path path) {

public enum MatcherType {
FILENAME,
PATH;
PATH
}

public enum EntryType {
FILE,
DIRECTORY,
ALL;
ALL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@
*/
public class CloseableBuffer implements AutoCloseable {

private static final Cleaner CLEANER = doPrivileged(new PrivilegedAction<Cleaner>() {

@Override
public Cleaner run() {
final String jsv = System.getProperty("java.specification.version", "9");
if (jsv.startsWith("1.")) {
return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner();
} else {
return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner();
}
private static final Cleaner CLEANER = doPrivileged((PrivilegedAction<Cleaner>) () -> {
final String jsv = System.getProperty("java.specification.version", "9");
if (jsv.startsWith("1.")) {
return DirectCleaner.isSupported() ? new DirectCleaner() : new NoopCleaner();
} else {
return UnsafeCleaner.isSupported() ? new UnsafeCleaner() : new NoopCleaner();
}
});

Expand Down Expand Up @@ -75,13 +71,7 @@ public ByteBuffer getBuffer() {
@Override
public void close() {
// Java 8: () -> CLEANER.clean(buffer)
boolean done = doPrivileged(new PrivilegedAction<Boolean>() {

@Override
public Boolean run() {
return CLEANER.clean(buffer);
}
});
boolean done = doPrivileged((PrivilegedAction<Boolean>) () -> CLEANER.clean(buffer));
if (done) {
buffer = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public CacheState initialize() {
final boolean enabled = getProperty(CACHE_ENABLED_PROPERTY_NAME, true);

if (!rtInfo.isMavenVersion("[3.9.0,)")) {
LOGGER.warn("Cache requires Maven >= 3.9, but version is " + rtInfo.getMavenVersion()
+ ". Disabling cache.");
LOGGER.warn(
"Cache requires Maven >= 3.9, but version is {}. Disabling cache.",
rtInfo.getMavenVersion());
state = CacheState.DISABLED;
} else if (!enabled) {
LOGGER.info("Cache disabled by command line flag, project will be built fully and not cached");
Expand Down