From 8d1744cd88c1b184dee1aa24b477d794743b3415 Mon Sep 17 00:00:00 2001 From: Vladimir Lagunov Date: Fri, 3 May 2024 15:52:46 +0200 Subject: [PATCH] JPS: apply path mapper to Maven Artifactory URLs Now, if JPS runs in a WSL container, it mangles paths to JARs from `~\.m2`. JPS uses JARs from the Windows disk. Although it would be more performant to use JARs from the Linux drive, this commit makes JPS at least work on WSL. GitOrigin-RevId: 9c9d6dc378f03cc7e992b9fca8b639ccb709fd2b --- .../model/serialization/JpsPathMapper.java | 4 ++- .../api-dump-unreviewed.txt | 3 +- .../java/JpsJavaModelSerializerExtension.java | 14 +++++---- .../JpsLibraryPropertiesSerializer.java | 30 +++++++++---------- .../library/JpsLibraryTableSerializer.java | 11 +++---- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/jps/model-api/src/org/jetbrains/jps/model/serialization/JpsPathMapper.java b/jps/model-api/src/org/jetbrains/jps/model/serialization/JpsPathMapper.java index 7a5629aad67e..fad95d81fec6 100644 --- a/jps/model-api/src/org/jetbrains/jps/model/serialization/JpsPathMapper.java +++ b/jps/model-api/src/org/jetbrains/jps/model/serialization/JpsPathMapper.java @@ -1,9 +1,11 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.jps.model.serialization; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; public interface JpsPathMapper { + @Contract("null->null; !null->!null") @Nullable String mapUrl(@Nullable String url); JpsPathMapper IDENTITY = new JpsPathMapper() { diff --git a/jps/model-serialization/api-dump-unreviewed.txt b/jps/model-serialization/api-dump-unreviewed.txt index acb428641460..7eaa47db2c67 100644 --- a/jps/model-serialization/api-dump-unreviewed.txt +++ b/jps/model-serialization/api-dump-unreviewed.txt @@ -417,7 +417,8 @@ f:org.jetbrains.jps.model.serialization.java.compiler.RmicCompilerOptionsSeriali a:org.jetbrains.jps.model.serialization.library.JpsLibraryPropertiesSerializer - org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer - (org.jetbrains.jps.model.library.JpsLibraryType,java.lang.String):V -- a:loadProperties(org.jdom.Element):org.jetbrains.jps.model.JpsElement +- loadProperties(org.jdom.Element):org.jetbrains.jps.model.JpsElement +- loadProperties(org.jdom.Element,org.jetbrains.jps.model.serialization.JpsPathMapper):org.jetbrains.jps.model.JpsElement f:org.jetbrains.jps.model.serialization.library.JpsLibraryRootTypeSerializer - java.lang.Comparable - (java.lang.String,org.jetbrains.jps.model.library.JpsOrderRootType,Z):V diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/JpsJavaModelSerializerExtension.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/JpsJavaModelSerializerExtension.java index 2a588ad0cbf3..6ce9daa8cc16 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/JpsJavaModelSerializerExtension.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/JpsJavaModelSerializerExtension.java @@ -23,6 +23,7 @@ import org.jetbrains.jps.model.module.JpsModuleReference; import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import org.jetbrains.jps.model.serialization.JDomSerializationUtil; import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; +import org.jetbrains.jps.model.serialization.JpsPathMapper; import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer; import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementSerializer; import org.jetbrains.jps.model.serialization.java.compiler.*; @@ -327,12 +328,12 @@ public final class JpsJavaModelSerializerExtension extends JpsModelSerializerExt } @Override - public JpsSimpleElement loadProperties(@Nullable Element elem) { - return JpsElementFactory.getInstance().createSimpleElement(loadDescriptor(elem)); + public JpsSimpleElement loadProperties(@Nullable Element elem, @NotNull JpsPathMapper pathMapper) { + return JpsElementFactory.getInstance().createSimpleElement(loadDescriptor(elem, pathMapper)); } @NotNull - private static JpsMavenRepositoryLibraryDescriptor loadDescriptor(@Nullable Element elem) { + private static JpsMavenRepositoryLibraryDescriptor loadDescriptor(@Nullable Element elem, @NotNull JpsPathMapper pathMapper) { if (elem == null) return new JpsMavenRepositoryLibraryDescriptor(null); String mavenId = elem.getAttributeValue(MAVEN_ID_ATTRIBUTE, (String)null); @@ -343,14 +344,15 @@ public final class JpsJavaModelSerializerExtension extends JpsModelSerializerExt Element excludeTag = elem.getChild(EXCLUDE_TAG); List dependencyTags = excludeTag != null ? excludeTag.getChildren(DEPENDENCY_TAG) : Collections.emptyList(); List excludedDependencies = ContainerUtil.map(dependencyTags, it -> it.getAttributeValue(MAVEN_ID_ATTRIBUTE)); - var verificationProperties = loadArtifactsVerificationProperties(mavenId, elem.getChild(VERIFICATION_TAG)); + var verificationProperties = loadArtifactsVerificationProperties(mavenId, elem.getChild(VERIFICATION_TAG), pathMapper); return new JpsMavenRepositoryLibraryDescriptor(mavenId, includeTransitiveDependencies, excludedDependencies, verificationProperties, jarRepositoryId); } - private static List loadArtifactsVerificationProperties(@Nullable String mavenId, @Nullable Element element) { + private static List loadArtifactsVerificationProperties(@Nullable String mavenId, @Nullable Element element, + @NotNull JpsPathMapper pathMapper) { if (element == null) { return Collections.emptyList(); } @@ -366,7 +368,7 @@ public final class JpsJavaModelSerializerExtension extends JpsModelSerializerExt if (sha256sum == null) { LOG.warn("Missing sha256sum attribute for verification artifact tag for descriptor maven-id=" + mavenId); } else { - result.add(new ArtifactVerification(artifactUrl, sha256sum)); + result.add(new ArtifactVerification(pathMapper.mapUrl(artifactUrl), sha256sum)); } } else { LOG.warn("Missing url attribute for verification artifact tag for descriptor maven-id=" + mavenId); diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryPropertiesSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryPropertiesSerializer.java index 674b4455673c..c30924d1f40d 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryPropertiesSerializer.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryPropertiesSerializer.java @@ -1,30 +1,28 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.jps.model.serialization.library; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.JpsElement; import org.jetbrains.jps.model.library.JpsLibraryType; import org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer; +import org.jetbrains.jps.model.serialization.JpsPathMapper; public abstract class JpsLibraryPropertiesSerializer

extends JpsElementPropertiesSerializer> { public JpsLibraryPropertiesSerializer(JpsLibraryType

type, String typeId) { super(type, typeId); } - public abstract P loadProperties(@Nullable Element propertiesElement); + /** + * @deprecated Override {@link #loadProperties(Element, JpsPathMapper)} instead of this method. + */ + @Deprecated + public P loadProperties(@Nullable Element propertiesElement) { + throw new AbstractMethodError(); + }; + + public P loadProperties(@Nullable Element propertiesElement, @NotNull JpsPathMapper pathMapper) { + return loadProperties(propertiesElement); + } } diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java index d9bf0a9407e5..8a34c1fd9a6f 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/library/JpsLibraryTableSerializer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.jps.model.serialization.library; import com.intellij.openapi.util.JDOMUtil; @@ -33,7 +33,7 @@ public final class JpsLibraryTableSerializer { private static final JpsLibraryPropertiesSerializer JAVA_LIBRARY_PROPERTIES_SERIALIZER = new JpsLibraryPropertiesSerializer(JpsJavaLibraryType.INSTANCE, null) { @Override - public JpsDummyElement loadProperties(@Nullable Element propertiesElement) { + public JpsDummyElement loadProperties(@Nullable Element propertiesElement, @NotNull JpsPathMapper pathMapper) { return JpsElementFactory.getInstance().createDummyElement(); } }; @@ -56,7 +56,7 @@ public final class JpsLibraryTableSerializer { public static JpsLibrary loadLibrary(Element libraryElement, String name, @NotNull JpsPathMapper pathMapper) { String typeId = libraryElement.getAttributeValue(TYPE_ATTRIBUTE); final JpsLibraryPropertiesSerializer loader = getLibraryPropertiesSerializer(typeId); - JpsLibrary library = createLibrary(name, loader, libraryElement.getChild(PROPERTIES_TAG)); + JpsLibrary library = createLibrary(name, loader, libraryElement.getChild(PROPERTIES_TAG), pathMapper); MultiMap jarDirectories = new MultiMap<>(); MultiMap recursiveJarDirectories = new MultiMap<>(); @@ -92,8 +92,9 @@ public final class JpsLibraryTableSerializer { } private static

JpsLibrary createLibrary(String name, JpsLibraryPropertiesSerializer

loader, - final Element propertiesElement) { - return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(propertiesElement)); + final Element propertiesElement, + @NotNull JpsPathMapper pathMapper) { + return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(propertiesElement, pathMapper)); } private static JpsOrderRootType getRootType(String rootTypeId) {