Skip to content

Commit

Permalink
If there is only a single jar use the default output folder as source
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laeubi committed Nov 10, 2023
1 parent da66543 commit ac3bcbf
Showing 1 changed file with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ private BundleComponent importProject() throws CoreException, IOException {
}

private void createOutputFolder(IProject project, IPath projectPath) throws IOException, CoreException {
Map<String, String> outputJars = computeOutputJars(project);
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null) {
Map<String, String> 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
Expand All @@ -258,7 +258,7 @@ private void createOutputFolder(IProject project, IPath projectPath) throws IOEx
}
}

private Map<String, String> computeOutputJars(IProject project) throws CoreException {
private Map<String, String> computeOutputJars(IProject project, IJavaProject javaProject) throws CoreException {
Map<String, String> outputJars = new HashMap<String, String>();
IPluginModelBase base = PluginRegistry.findModel(project);
if (base != null) {
Expand All @@ -271,30 +271,27 @@ private Map<String, String> 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.<jar> should have a corresponding output.<jar> 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);
}
}
}
Expand All @@ -306,6 +303,13 @@ private Map<String, String> 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<String, String> outputJars, IFolder mavenOutputFolder) {
if (eclipseOutputLocation == null) {
return null;
Expand All @@ -315,7 +319,9 @@ private IPath getRealPath(IPath eclipseOutputLocation, Map<String, String> 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()
Expand Down

0 comments on commit ac3bcbf

Please sign in to comment.