Skip to content

Commit

Permalink
Don't use RepositorySystem in compiler-jdt
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Feb 5, 2023
1 parent 87267a1 commit 19b47a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -398,7 +403,8 @@ CompilerResult compileInProcess(String[] args, CompilerConfiguration config, Cus
return new CompilerResult(success, messages);
}

private void addExternalJavaHomeArgs(List<String> jdtCompilerArgs, String javaHome) {
private void addExternalJavaHomeArgs(List<String> jdtCompilerArgs, String javaHome)
throws ArtifactResolutionException {
LibraryInfo jdkLibInfo = jdkLibInfoProvider.getLibraryInfo(javaHome);
if (jdkLibInfo.getBootpath().length > 0) {
addToCompilerArgumentsIfNotSet("-bootclasspath", String.join(File.pathSeparator, jdkLibInfo.getBootpath()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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";
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 19b47a8

Please sign in to comment.