From 19b47a8c475a282317812660ff963ca42d597c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 5 Feb 2023 17:10:53 +0100 Subject: [PATCH] Don't use RepositorySystem in compiler-jdt --- .../tycho/compiler/jdt/JDTCompiler.java | 10 +++++-- .../compiler/jdt/JdkLibraryInfoProvider.java | 29 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java index 85a02887db..583aed351f 100644 --- a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java +++ b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java @@ -46,6 +46,7 @@ import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; +import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.batch.Main; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -376,7 +377,11 @@ CompilerResult compileInProcess(String[] args, CompilerConfiguration config, Cus if (custom.javaHome != null) { String sourceLevel = config.getSourceVersion(); if (sourceLevel == null || CompilerOptions.versionToJdkLevel(sourceLevel) <= ClassFileConstants.JDK1_8) { - addExternalJavaHomeArgs(jdtCompilerArgs, custom.javaHome); + try { + addExternalJavaHomeArgs(jdtCompilerArgs, custom.javaHome); + } catch (ArtifactResolutionException e) { + throw new CompilerException("can't determine required options", e); + } } else { addToCompilerArgumentsIfNotSet("--system", custom.javaHome, jdtCompilerArgs); } @@ -398,7 +403,8 @@ CompilerResult compileInProcess(String[] args, CompilerConfiguration config, Cus return new CompilerResult(success, messages); } - private void addExternalJavaHomeArgs(List jdtCompilerArgs, String javaHome) { + private void addExternalJavaHomeArgs(List jdtCompilerArgs, String javaHome) + throws ArtifactResolutionException { LibraryInfo jdkLibInfo = jdkLibInfoProvider.getLibraryInfo(javaHome); if (jdkLibInfo.getBootpath().length > 0) { addToCompilerArgumentsIfNotSet("-bootclasspath", String.join(File.pathSeparator, jdkLibInfo.getBootpath()), diff --git a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java index e27b4df05e..3e8d8f5fb4 100644 --- a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java +++ b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java @@ -29,13 +29,15 @@ import org.apache.commons.exec.ExecuteWatchdog; import org.apache.commons.exec.PumpStreamHandler; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; +import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.tycho.compiler.jdt.copied.LibraryInfo; +import org.eclipse.tycho.core.maven.MavenDependenciesResolver; import org.eclipse.tycho.core.utils.TychoVersion; /** @@ -46,10 +48,10 @@ public class JdkLibraryInfoProvider { @Requirement - private RepositorySystem repositorySystem; + private LegacySupport legacySupport; @Requirement - private LegacySupport legacySupport; + private MavenDependenciesResolver dependenciesResolver; @Requirement private Logger log; @@ -58,7 +60,7 @@ public class JdkLibraryInfoProvider { private File libDetectorJar; private Boolean isRunningOnJava9orLater; - public LibraryInfo getLibraryInfo(String javaHome) { + public LibraryInfo getLibraryInfo(String javaHome) throws ArtifactResolutionException { LibraryInfo libInfo = libraryInfoCache.get(javaHome); if (libInfo == null) { libInfo = generateLibraryInfo(javaHome); @@ -67,7 +69,7 @@ public LibraryInfo getLibraryInfo(String javaHome) { return libInfo; } - private LibraryInfo generateLibraryInfo(String javaHome) { + private LibraryInfo generateLibraryInfo(String javaHome) throws ArtifactResolutionException { String executable = javaHome + File.separator + "bin" + File.separator + "java"; if (File.separatorChar == '\\') { executable = executable + ".exe"; @@ -188,13 +190,18 @@ protected Logger getLog() { return log; } - protected File getLibDetectorJar() { + protected File getLibDetectorJar() throws ArtifactResolutionException { if (libDetectorJar != null) { return libDetectorJar; } - Artifact libDetectorArtifact = repositorySystem.createArtifact("org.eclipse.tycho", "tycho-lib-detector", - TychoVersion.getTychoVersion(), "jar"); - ArtifactRepository localRepository = legacySupport.getSession().getLocalRepository(); - return libDetectorJar = new File(localRepository.getBasedir(), localRepository.pathOf(libDetectorArtifact)); + + MavenSession mavenSession = legacySupport.getSession(); + Dependency dependency = new Dependency(); + dependency.setGroupId("org.eclipse.tycho"); + dependency.setArtifactId("tycho-lib-detector"); + dependency.setVersion(TychoVersion.getTychoVersion()); + Artifact artifact = dependenciesResolver.resolveArtifact(mavenSession.getCurrentProject(), mavenSession, + dependency); + return libDetectorJar = artifact.getFile(); } }