From 5fd8e756ef3d5c0936b662e1f131146be5689cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 10 Nov 2023 07:00:02 +0100 Subject: [PATCH] If there is only a single jar use the default output folder as source If there is only a single jar specified, Tycho uses the default output folder instead of a special class folder. This checks if there is only a single folder and then uses that one instead. --- .../eclipse/tycho/apitools/ApiAnalysis.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java index 4f5aebd540..c9c0ca4692 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java @@ -236,9 +236,9 @@ private BundleComponent importProject() throws CoreException, IOException { } private void createOutputFolder(IProject project, IPath projectPath) throws IOException, CoreException { - Map outputJars = computeOutputJars(project); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { + Map outputJars = computeOutputJars(project, javaProject); IFolder outputFolder = project.getFolder(outputDir); // FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/801 // it can happen that project output location != maven compiled classes, usually @@ -258,7 +258,7 @@ private void createOutputFolder(IProject project, IPath projectPath) throws IOEx } } - private Map computeOutputJars(IProject project) throws CoreException { + private Map computeOutputJars(IProject project, IJavaProject javaProject) throws CoreException { Map outputJars = new HashMap(); IPluginModelBase base = PluginRegistry.findModel(project); if (base != null) { @@ -271,30 +271,27 @@ private Map computeOutputJars(IProject project) throws CoreExcep if (name.startsWith(IBuildEntry.OUTPUT_PREFIX)) { String key = name.substring(IBuildEntry.OUTPUT_PREFIX.length()); for (String token : entry.getTokens()) { - outputJars.put(token, key); + outputJars.put(normalizeOutputPath(token), key); } } else if (name.startsWith(IBuildEntry.JAR_PREFIX)) { // Actually each source. should have a corresponding output. but there // are some cases where this is not true... lets cheat and look at the // classpath instead... String key = name.substring(IBuildEntry.JAR_PREFIX.length()); - IJavaProject javaProject = JavaCore.create(project); - if (javaProject != null) { - IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); - for (String token : entry.getTokens()) { - IPath srcPath = project.getFolder(token).getFullPath(); - for (IClasspathEntry classpathEntry : rawClasspath) { - if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { - IPath path = classpathEntry.getPath(); - if (srcPath.equals(path)) { - IPath outputLocation = classpathEntry.getOutputLocation(); - if (outputLocation == null) { - outputLocation = javaProject.getOutputLocation(); - } - IFolder folder = getProjectFolder(outputLocation); - String output = folder.getProjectRelativePath().toString(); - outputJars.putIfAbsent(output, key); + IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); + for (String token : entry.getTokens()) { + IPath srcPath = project.getFolder(token).getFullPath(); + for (IClasspathEntry classpathEntry : rawClasspath) { + if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { + IPath path = classpathEntry.getPath(); + if (srcPath.equals(path)) { + IPath outputLocation = classpathEntry.getOutputLocation(); + if (outputLocation == null) { + outputLocation = javaProject.getOutputLocation(); } + IFolder folder = getProjectFolder(outputLocation); + String tokenOutput = folder.getProjectRelativePath().toString(); + outputJars.putIfAbsent(normalizeOutputPath(tokenOutput), key); } } } @@ -306,6 +303,13 @@ private Map computeOutputJars(IProject project) throws CoreExcep return outputJars; } + private String normalizeOutputPath(String path) { + if (path != null && path.endsWith("/")) { + return path.substring(0, path.length() - 1); + } + return path; + } + private IPath getRealPath(IPath eclipseOutputLocation, Map outputJars, IFolder mavenOutputFolder) { if (eclipseOutputLocation == null) { return null; @@ -315,7 +319,9 @@ private IPath getRealPath(IPath eclipseOutputLocation, Map outpu IFolder jarFolder = projectFolder.getProject().getFolder(entry.getKey()); if (jarFolder.equals(projectFolder)) { String jarOutputPath = entry.getValue(); - if (".".equals(jarOutputPath)) { + if (".".equals(jarOutputPath) || outputJars.size() == 1) { + // special case of one classpath entry which is not ".", Tycho also use standard + // maven output dir return mavenOutputFolder.getFullPath(); } return mavenOutputFolder.getParent()