mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
IDEA-23484 Merge META-INF/services properly
(cherry picked from commit b9756e1b9029254b128ac0b7a13fe46ace38d344) IJ-CR-166327 GitOrigin-RevId: 8d9203d5940fe9f3be0d53e0dcbc81c435835938
This commit is contained in:
committed by
intellij-monorepo-bot
parent
aa6e4499c5
commit
55838a9540
@@ -7,6 +7,7 @@ import com.intellij.openapi.util.Ref;
|
|||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
|
import com.intellij.util.containers.MultiMap;
|
||||||
import com.intellij.util.graph.CachingSemiGraph;
|
import com.intellij.util.graph.CachingSemiGraph;
|
||||||
import com.intellij.util.graph.DFSTBuilder;
|
import com.intellij.util.graph.DFSTBuilder;
|
||||||
import com.intellij.util.graph.GraphGenerator;
|
import com.intellij.util.graph.GraphGenerator;
|
||||||
@@ -157,6 +158,7 @@ public final class JarsBuilder {
|
|||||||
|
|
||||||
final Set<String> writtenPaths = new HashSet<>();
|
final Set<String> writtenPaths = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
|
MultiMap<String, String> serviceMap = new MultiMap<>();
|
||||||
if (manifest != null) {
|
if (manifest != null) {
|
||||||
addManifestEntry(jarOutputStream, manifest, writtenPaths);
|
addManifestEntry(jarOutputStream, manifest, writtenPaths);
|
||||||
}
|
}
|
||||||
@@ -167,14 +169,15 @@ public final class JarsBuilder {
|
|||||||
final ArtifactRootDescriptor descriptor = (ArtifactRootDescriptor)pair.getSecond();
|
final ArtifactRootDescriptor descriptor = (ArtifactRootDescriptor)pair.getSecond();
|
||||||
final int rootIndex = descriptor.getRootIndex();
|
final int rootIndex = descriptor.getRootIndex();
|
||||||
if (descriptor instanceof FileBasedArtifactRootDescriptor) {
|
if (descriptor instanceof FileBasedArtifactRootDescriptor) {
|
||||||
addFileToJar(jarOutputStream, jarFile, descriptor.getRootFile(), descriptor.getFilter(), relativePath, targetJarPath, writtenPaths,
|
addFileToJar(jarOutputStream, jarFile, descriptor.getRootFile(), descriptor.getFilter(),
|
||||||
packedFilePaths, rootIndex);
|
relativePath, targetJarPath, writtenPaths,
|
||||||
|
packedFilePaths, rootIndex, serviceMap);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final String filePath = FileUtil.toSystemIndependentName(descriptor.getRootFile().getAbsolutePath());
|
final String filePath = FileUtil.toSystemIndependentName(descriptor.getRootFile().getAbsolutePath());
|
||||||
packedFilePaths.add(filePath);
|
packedFilePaths.add(filePath);
|
||||||
myOutSrcMapping.appendData(targetJarPath, rootIndex, filePath);
|
myOutSrcMapping.appendData(targetJarPath, rootIndex, filePath);
|
||||||
extractFileAndAddToJar(jarOutputStream, (JarBasedArtifactRootDescriptor)descriptor, relativePath, writtenPaths);
|
extractFileAndAddToJar(jarOutputStream, (JarBasedArtifactRootDescriptor)descriptor, relativePath, writtenPaths, serviceMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -182,13 +185,24 @@ public final class JarsBuilder {
|
|||||||
File nestedJarFile = myBuiltJars.get(nestedJar);
|
File nestedJarFile = myBuiltJars.get(nestedJar);
|
||||||
if (nestedJarFile != null) {
|
if (nestedJarFile != null) {
|
||||||
addFileToJar(jarOutputStream, jarFile, nestedJarFile, SourceFileFilter.ALL, relativePath, targetJarPath, writtenPaths,
|
addFileToJar(jarOutputStream, jarFile, nestedJarFile, SourceFileFilter.ALL, relativePath, targetJarPath, writtenPaths,
|
||||||
packedFilePaths, -1);
|
packedFilePaths, -1, serviceMap);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG.debug("nested JAR file " + relativePath + " for " + jar.getPresentableDestination() + " not found");
|
LOG.debug("nested JAR file " + relativePath + " for " + jar.getPresentableDestination() + " not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (String relativePath : serviceMap.keySet()) {
|
||||||
|
File file = File.createTempFile("service", "tmp");
|
||||||
|
try {
|
||||||
|
FileUtil.writeToFile(file, StringUtil.join(serviceMap.get(relativePath), "\n"));
|
||||||
|
long timestamp = buildDateInMillis != null ? buildDateInMillis : FSOperations.lastModified(file);
|
||||||
|
ZipUtil.addFileToZip(jarOutputStream, file, relativePath, writtenPaths, null, timestamp);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (writtenPaths.isEmpty()) {
|
if (writtenPaths.isEmpty()) {
|
||||||
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.getBuilderName(), BuildMessage.Kind.WARNING, emptyArchiveMessage));
|
myContext.processMessage(new CompilerMessage(IncArtifactBuilder.getBuilderName(), BuildMessage.Kind.WARNING, emptyArchiveMessage));
|
||||||
@@ -289,8 +303,11 @@ public final class JarsBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractFileAndAddToJar(final JarOutputStream jarOutputStream, final JarBasedArtifactRootDescriptor root,
|
private void extractFileAndAddToJar(final JarOutputStream jarOutputStream,
|
||||||
final String relativeOutputPath, final Set<? super String> writtenPaths)
|
final JarBasedArtifactRootDescriptor root,
|
||||||
|
final String relativeOutputPath,
|
||||||
|
final Set<? super String> writtenPaths,
|
||||||
|
MultiMap<String, String> serviceMap)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final long timestamp = buildDateInMillis != null ? buildDateInMillis : FSOperations.lastModified(root.getRootFile());
|
final long timestamp = buildDateInMillis != null ? buildDateInMillis : FSOperations.lastModified(root.getRootFile());
|
||||||
root.processEntries(new JarBasedArtifactRootDescriptor.EntryProcessor() {
|
root.processEntries(new JarBasedArtifactRootDescriptor.EntryProcessor() {
|
||||||
@@ -304,6 +321,11 @@ public final class JarsBuilder {
|
|||||||
addDirectoryEntry(jarOutputStream, pathInJar + "/", writtenPaths);
|
addDirectoryEntry(jarOutputStream, pathInJar + "/", writtenPaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (pathInJar.contains("META-INF/services/")) {
|
||||||
|
for (String line : StringUtil.splitByLines(FileUtil.loadTextAndClose(inputStream), false)) {
|
||||||
|
serviceMap.putValue(relativePath, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (writtenPaths.add(pathInJar)) {
|
else if (writtenPaths.add(pathInJar)) {
|
||||||
ZipEntry newEntry = new ZipEntry(pathInJar);
|
ZipEntry newEntry = new ZipEntry(pathInJar);
|
||||||
newEntry.setTime(timestamp);
|
newEntry.setTime(timestamp);
|
||||||
@@ -332,13 +354,14 @@ public final class JarsBuilder {
|
|||||||
|
|
||||||
private void addFileToJar(final @NotNull JarOutputStream jarOutputStream, final @NotNull File jarFile, @NotNull File file,
|
private void addFileToJar(final @NotNull JarOutputStream jarOutputStream, final @NotNull File jarFile, @NotNull File file,
|
||||||
SourceFileFilter filter, @NotNull String relativePath, String targetJarPath,
|
SourceFileFilter filter, @NotNull String relativePath, String targetJarPath,
|
||||||
final @NotNull Set<? super String> writtenPaths, List<? super String> packedFilePaths, final int rootIndex) throws IOException {
|
final @NotNull Set<? super String> writtenPaths, List<? super String> packedFilePaths, final int rootIndex,
|
||||||
|
MultiMap<String, String> serviceMap) throws IOException {
|
||||||
if (!file.exists() || FileUtil.isAncestor(file, jarFile, false)) {
|
if (!file.exists() || FileUtil.isAncestor(file, jarFile, false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
relativePath = addParentDirectories(jarOutputStream, writtenPaths, relativePath);
|
relativePath = addParentDirectories(jarOutputStream, writtenPaths, relativePath);
|
||||||
addFileOrDirRecursively(jarOutputStream, file, filter, relativePath, targetJarPath, writtenPaths, packedFilePaths, rootIndex);
|
addFileOrDirRecursively(jarOutputStream, file, filter, relativePath, targetJarPath, writtenPaths, packedFilePaths, rootIndex, serviceMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFileOrDirRecursively(@NotNull ZipOutputStream jarOutputStream,
|
private void addFileOrDirRecursively(@NotNull ZipOutputStream jarOutputStream,
|
||||||
@@ -348,7 +371,8 @@ public final class JarsBuilder {
|
|||||||
String targetJarPath,
|
String targetJarPath,
|
||||||
@NotNull Set<? super String> writtenItemRelativePaths,
|
@NotNull Set<? super String> writtenItemRelativePaths,
|
||||||
List<? super String> packedFilePaths,
|
List<? super String> packedFilePaths,
|
||||||
int rootIndex) throws IOException {
|
int rootIndex,
|
||||||
|
MultiMap<String, String> serviceMap) throws IOException {
|
||||||
final String filePath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
|
final String filePath = FileUtil.toSystemIndependentName(file.getAbsolutePath());
|
||||||
if (!filter.accept(filePath) || !filter.shouldBeCopied(filePath, myContext.getProjectDescriptor())) {
|
if (!filter.accept(filePath) || !filter.shouldBeCopied(filePath, myContext.getProjectDescriptor())) {
|
||||||
return;
|
return;
|
||||||
@@ -363,14 +387,23 @@ public final class JarsBuilder {
|
|||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (File child : children) {
|
for (File child : children) {
|
||||||
addFileOrDirRecursively(jarOutputStream, child, filter, directoryPath + child.getName(), targetJarPath, writtenItemRelativePaths,
|
addFileOrDirRecursively(jarOutputStream, child, filter, directoryPath + child.getName(), targetJarPath, writtenItemRelativePaths,
|
||||||
packedFilePaths, rootIndex);
|
packedFilePaths, rootIndex, serviceMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long timestamp = buildDateInMillis != null ? buildDateInMillis : FSOperations.lastModified(file);
|
boolean added;
|
||||||
final boolean added = ZipUtil.addFileToZip(jarOutputStream, file, relativePath, writtenItemRelativePaths, null, timestamp);
|
if (relativePath.startsWith("META-INF/services/")) {
|
||||||
|
for (String line : StringUtil.splitByLines(FileUtil.loadFile(file), false)) {
|
||||||
|
serviceMap.putValue(relativePath, line);
|
||||||
|
}
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
long timestamp = buildDateInMillis != null ? buildDateInMillis : FSOperations.lastModified(file);
|
||||||
|
added = ZipUtil.addFileToZip(jarOutputStream, file, relativePath, writtenItemRelativePaths, null, timestamp);
|
||||||
|
}
|
||||||
if (rootIndex != -1) {
|
if (rootIndex != -1) {
|
||||||
myOutSrcMapping.appendData(targetJarPath, rootIndex, filePath);
|
myOutSrcMapping.appendData(targetJarPath, rootIndex, filePath);
|
||||||
if (added) {
|
if (added) {
|
||||||
|
|||||||
Reference in New Issue
Block a user