redhat-developer / redhat-developer/vscode-java

Incorrect value of classpathentry element in the .classpath file if in pom.xml the build.sourceDirectory is relative

オープン
#2,216 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

configuration Maven
主要言語
TypeScript
スター
2.3k
フォーク
546
平均マージ
20時間 1分
マージ済み PR(30日)
11

説明

Short description:
A pom file with a source directory containing "../" isn't imported correctly

Long drescription:
We have a maven "tree" of projects in which some source files have to be shared.
The project is split into components and each component has hundredths of modules (but this doesn't matter for the bug, however that's the reason why we open the code "by components", it's too big to work at the root level).
The simplified version looks like this:

ROOT
  ├ A (component)
  | └ interface
  |   └ src
  |     ├ file1.java
  |     └ file2.java
  └ B (component)
    ├ B1 (module 1)
    | └ pom.xml (child 1)
    ├ B2 (module 2)
    | ├ src
    | |  └ file3.java
    | └ pom.xml (child 2)
    └ pom.xml (parent)

I open, in VS code, the folder B saying that I trust everything which is in the parent folder (so trusting everything which is in ROOT).
It starts importing the projects.

The B1 module is a library which doesn't contain any source files (locally) but, in its pom.xml has

<build>
   <sourceDirectory>${basedir}/../../A/interface/src</sourceDirectory>
</build>

The B2 is a normal module in which file3.java
imports A.interface.class1
The B2 module, in its pom, has a dependency on B1.

When I build on maven the build creates these:

B  [pom]
B1 [jar]
B2 [jar]

and everything works fine.

Visual studio code, however complains that file3.java has an import that can not be resolved.
This is due to the fact that the module B1 is not "common" because it doesn't have any code in the B1 folder but points to a relative path (which, by the way is one level above the one opened by vscode, but still in the trusted area)

The problem seems to be that in the .classpath file I have this wrong path:

<classpath>
	<classpathentry kind="src" output="target/classes" path="/A/interface/src">
		<attributes>
			<attribute name="optional" value="true"/>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>

which is wrong because everything with "../../" has been stripped out.

workaround tried:

  • Editing the .classpath file manually and changing the path. Doesn't work.
  • Adding the sources dynamically (with the maven build helper). Doesn't work.

The only solution is to copy everything in A/interface/src during the sources generation phase into the B1/target/generated-sources folder. This, of course, wastes lots of times if the sources to copy are a lot.

Environment
  • Operating System: Win10
  • JDK version: 1.8.0.292 (project) 11.0.10.0 (language server)
  • Visual Studio Code version: 1.62.2
  • Java extension version: 1.0.0
Steps To Reproduce

import a pom.xml which changes the sourceDirectory
Logs are too big to be attached.

Current Result

False error in sources

Expected Result

No error

Additional Informations

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、説明されている Maven ツリーでインポートを再現し、pom.xml 内の相対 build.sourceDirectory に対して生成された .classpath エントリを調べます。プロジェクトのインポート中に sourceDirectory パスがどのように変換されるかを追跡します。classpath が相対ソースパスを保持し、file3.java が誤って未解決の import を報告しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。