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
This commit is contained in:
Vladimir Lagunov
2024-05-03 15:52:46 +02:00
committed by intellij-monorepo-bot
parent 7159d220f2
commit 8d1744cd88
5 changed files with 33 additions and 29 deletions

View File

@@ -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; package org.jetbrains.jps.model.serialization;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public interface JpsPathMapper { public interface JpsPathMapper {
@Contract("null->null; !null->!null")
@Nullable String mapUrl(@Nullable String url); @Nullable String mapUrl(@Nullable String url);
JpsPathMapper IDENTITY = new JpsPathMapper() { JpsPathMapper IDENTITY = new JpsPathMapper() {

View File

@@ -417,7 +417,8 @@ f:org.jetbrains.jps.model.serialization.java.compiler.RmicCompilerOptionsSeriali
a:org.jetbrains.jps.model.serialization.library.JpsLibraryPropertiesSerializer a:org.jetbrains.jps.model.serialization.library.JpsLibraryPropertiesSerializer
- org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer - org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer
- <init>(org.jetbrains.jps.model.library.JpsLibraryType,java.lang.String):V - <init>(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 f:org.jetbrains.jps.model.serialization.library.JpsLibraryRootTypeSerializer
- java.lang.Comparable - java.lang.Comparable
- <init>(java.lang.String,org.jetbrains.jps.model.library.JpsOrderRootType,Z):V - <init>(java.lang.String,org.jetbrains.jps.model.library.JpsOrderRootType,Z):V

View File

@@ -23,6 +23,7 @@ import org.jetbrains.jps.model.module.JpsModuleReference;
import org.jetbrains.jps.model.module.JpsModuleSourceRootType; import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
import org.jetbrains.jps.model.serialization.JDomSerializationUtil; import org.jetbrains.jps.model.serialization.JDomSerializationUtil;
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension; 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.JpsProjectExtensionSerializer;
import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementSerializer; import org.jetbrains.jps.model.serialization.artifact.JpsPackagingElementSerializer;
import org.jetbrains.jps.model.serialization.java.compiler.*; import org.jetbrains.jps.model.serialization.java.compiler.*;
@@ -327,12 +328,12 @@ public final class JpsJavaModelSerializerExtension extends JpsModelSerializerExt
} }
@Override @Override
public JpsSimpleElement<JpsMavenRepositoryLibraryDescriptor> loadProperties(@Nullable Element elem) { public JpsSimpleElement<JpsMavenRepositoryLibraryDescriptor> loadProperties(@Nullable Element elem, @NotNull JpsPathMapper pathMapper) {
return JpsElementFactory.getInstance().createSimpleElement(loadDescriptor(elem)); return JpsElementFactory.getInstance().createSimpleElement(loadDescriptor(elem, pathMapper));
} }
@NotNull @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); if (elem == null) return new JpsMavenRepositoryLibraryDescriptor(null);
String mavenId = elem.getAttributeValue(MAVEN_ID_ATTRIBUTE, (String)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); Element excludeTag = elem.getChild(EXCLUDE_TAG);
List<Element> dependencyTags = excludeTag != null ? excludeTag.getChildren(DEPENDENCY_TAG) : Collections.emptyList(); List<Element> dependencyTags = excludeTag != null ? excludeTag.getChildren(DEPENDENCY_TAG) : Collections.emptyList();
List<String> excludedDependencies = ContainerUtil.map(dependencyTags, it -> it.getAttributeValue(MAVEN_ID_ATTRIBUTE)); List<String> 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, return new JpsMavenRepositoryLibraryDescriptor(mavenId,
includeTransitiveDependencies, excludedDependencies, includeTransitiveDependencies, excludedDependencies,
verificationProperties, verificationProperties,
jarRepositoryId); jarRepositoryId);
} }
private static List<ArtifactVerification> loadArtifactsVerificationProperties(@Nullable String mavenId, @Nullable Element element) { private static List<ArtifactVerification> loadArtifactsVerificationProperties(@Nullable String mavenId, @Nullable Element element,
@NotNull JpsPathMapper pathMapper) {
if (element == null) { if (element == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -366,7 +368,7 @@ public final class JpsJavaModelSerializerExtension extends JpsModelSerializerExt
if (sha256sum == null) { if (sha256sum == null) {
LOG.warn("Missing sha256sum attribute for verification artifact tag for descriptor maven-id=" + mavenId); LOG.warn("Missing sha256sum attribute for verification artifact tag for descriptor maven-id=" + mavenId);
} else { } else {
result.add(new ArtifactVerification(artifactUrl, sha256sum)); result.add(new ArtifactVerification(pathMapper.mapUrl(artifactUrl), sha256sum));
} }
} else { } else {
LOG.warn("Missing url attribute for verification artifact tag for descriptor maven-id=" + mavenId); LOG.warn("Missing url attribute for verification artifact tag for descriptor maven-id=" + mavenId);

View File

@@ -1,30 +1,28 @@
/* // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
* 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.
*/
package org.jetbrains.jps.model.serialization.library; package org.jetbrains.jps.model.serialization.library;
import org.jdom.Element; import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement; import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.library.JpsLibraryType; import org.jetbrains.jps.model.library.JpsLibraryType;
import org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer; import org.jetbrains.jps.model.serialization.JpsElementPropertiesSerializer;
import org.jetbrains.jps.model.serialization.JpsPathMapper;
public abstract class JpsLibraryPropertiesSerializer<P extends JpsElement> extends JpsElementPropertiesSerializer<P, JpsLibraryType<P>> { public abstract class JpsLibraryPropertiesSerializer<P extends JpsElement> extends JpsElementPropertiesSerializer<P, JpsLibraryType<P>> {
public JpsLibraryPropertiesSerializer(JpsLibraryType<P> type, String typeId) { public JpsLibraryPropertiesSerializer(JpsLibraryType<P> type, String typeId) {
super(type, 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);
}
} }

View File

@@ -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; package org.jetbrains.jps.model.serialization.library;
import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.JDOMUtil;
@@ -33,7 +33,7 @@ public final class JpsLibraryTableSerializer {
private static final JpsLibraryPropertiesSerializer<JpsDummyElement> JAVA_LIBRARY_PROPERTIES_SERIALIZER = private static final JpsLibraryPropertiesSerializer<JpsDummyElement> JAVA_LIBRARY_PROPERTIES_SERIALIZER =
new JpsLibraryPropertiesSerializer<JpsDummyElement>(JpsJavaLibraryType.INSTANCE, null) { new JpsLibraryPropertiesSerializer<JpsDummyElement>(JpsJavaLibraryType.INSTANCE, null) {
@Override @Override
public JpsDummyElement loadProperties(@Nullable Element propertiesElement) { public JpsDummyElement loadProperties(@Nullable Element propertiesElement, @NotNull JpsPathMapper pathMapper) {
return JpsElementFactory.getInstance().createDummyElement(); return JpsElementFactory.getInstance().createDummyElement();
} }
}; };
@@ -56,7 +56,7 @@ public final class JpsLibraryTableSerializer {
public static JpsLibrary loadLibrary(Element libraryElement, String name, @NotNull JpsPathMapper pathMapper) { public static JpsLibrary loadLibrary(Element libraryElement, String name, @NotNull JpsPathMapper pathMapper) {
String typeId = libraryElement.getAttributeValue(TYPE_ATTRIBUTE); String typeId = libraryElement.getAttributeValue(TYPE_ATTRIBUTE);
final JpsLibraryPropertiesSerializer<?> loader = getLibraryPropertiesSerializer(typeId); 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<JpsOrderRootType, String> jarDirectories = new MultiMap<>(); MultiMap<JpsOrderRootType, String> jarDirectories = new MultiMap<>();
MultiMap<JpsOrderRootType, String> recursiveJarDirectories = new MultiMap<>(); MultiMap<JpsOrderRootType, String> recursiveJarDirectories = new MultiMap<>();
@@ -92,8 +92,9 @@ public final class JpsLibraryTableSerializer {
} }
private static <P extends JpsElement> JpsLibrary createLibrary(String name, JpsLibraryPropertiesSerializer<P> loader, private static <P extends JpsElement> JpsLibrary createLibrary(String name, JpsLibraryPropertiesSerializer<P> loader,
final Element propertiesElement) { final Element propertiesElement,
return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(propertiesElement)); @NotNull JpsPathMapper pathMapper) {
return JpsElementFactory.getInstance().createLibrary(name, loader.getType(), loader.loadProperties(propertiesElement, pathMapper));
} }
private static JpsOrderRootType getRootType(String rootTypeId) { private static JpsOrderRootType getRootType(String rootTypeId) {