Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete classpath argument files upon shutdown. Fixes #240 #242

Merged
merged 3 commits into from
Jun 16, 2023

Conversation

diti0023
Copy link
Contributor

@diti0023 diti0023 commented Apr 21, 2023

View also original issue for more information.

What it does

In the dialog Run Configurations, click on "Show Comandline". If there are many or long classpaths, they are collected in a file in order not to exceed the maximum command length (on a Linux system check with getconf ARG_MAX). This is also done for actually launching the run, but in that case these files are removed on terminating the launch. When just showing the command line these files remain, in order to have them accessible later (i.e. after closing the dialog). In this case, i.e. without any process, the GUI has no access to these files. This change marks the files as to be deleted on shutdown of the JVM, and handles them via a .gitignore in order to prevent accidentally committing them.

How to test

Create a project with many JAR files and long paths to them. When the command length of the OS is about to be exceeded, the resulting command changes from listing all files as parameters (-classpath) to a single entry like

@/home/.../.temp-Main--module-path-arg-1681985065801.txt

The files resulting from just showing the commandline are deleted when the JVM is terminated.

Author checklist

@diti0023 diti0023 marked this pull request as ready for review April 24, 2023 10:45
@@ -313,6 +317,25 @@ private void shortenPathUsingClasspathArgumentFile(int modulePathArgumentIndex,
addProcessTempFile(file);
}

private void createOrUpdateGitIgnore() {
File gitIgnore = new File(processTempFilesDir, ".gitignore"); //$NON-NLS-1$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of touching gitignore, one can contribute something like:

  <extension
        point="org.eclipse.team.core.ignore">
     <ignore
           enabled="true"
           pattern=".temp-*path-arg-*.txt"/>
  </extension>

Copy link
Contributor Author

@diti0023 diti0023 May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately neither ".temp-*path-arg-*.txt" nor "**/.temp-*path-arg-*.txt" actually hides these files in the Package Explorer; I guess I have to investigate further.
So this is just to actually have these files ignored by version control, right?
The original intention was to hide them, so which solution is better?

Copy link
Contributor

@jukzi jukzi May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also note that there are multiple ways to call org.eclipse.jdt.internal.launching.JavaLaunchingUtils.createFileForArgument(String, File, String, String)
which may result in different patterns. As far as i remember one usecase is to have a long classpath while another usecase is more general to have over-long parameters at all.
@iloveeclipse would it be feasible to use a dedicated temp path below
workspace\.metadata\.plugins\org.eclipse.jdt.launching?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be feasible to use a dedicated temp path below
workspace.metadata.plugins\org.eclipse.jdt.launching?

Technically we can create these temp files there, yes. I wonder why that wasn't done and if there is a catch (like having them in the base directory etc).

@iloveeclipse
Copy link
Member

Merge branch 'eclipse-jdt:master' into issue#240

@diti0023 : please don't use merge to get latest state from master, please use rebase.
Merge commits are not allowed to get clean git history.

@diti0023
Copy link
Contributor Author

Merge branch 'eclipse-jdt:master' into issue#240

@diti0023 : please don't use merge to get latest state from master, please use rebase. Merge commits are not allowed to get clean git history.

@iloveeclipse Thanks -- obviously I'm still a newbie ...

@diti0023 diti0023 force-pushed the issue#240 branch 2 times, most recently from ea40335 to 6be5268 Compare May 17, 2023 12:52
@diti0023
Copy link
Contributor Author

Current solution:
For "Show command line" the temp files are stored in the metadata of the respective plug-in, so outside the workspace. Additionally the files are deleted at shutdown of the Eclipse instance.

@iloveeclipse
Copy link
Member

Note: we are in 4.28 RC phase now and I personally would prefer that we would postpone this PR to 4.29 M1.

@diti0023
Copy link
Contributor Author

/rebase
My latest rebase attempt seems to show a temporary build problem. How can I proceed?

@iloveeclipse
Copy link
Member

seems to show a temporary build problem. How can I proceed?

It is not temporary issue.

Only qualifier changed for (org.eclipse.jdt.launching/3.20.0.v20230614-0628). Expected to have bigger x.y.z than what is available in baseline (3.20.0.v20230425-1118)

If this is the first change in 4.29 on org.eclipse.jdt.launching project, the version should be bumped by +100.

@iloveeclipse iloveeclipse merged commit 5163d81 into eclipse-jdt:master Jun 16, 2023
@diti0023 diti0023 deleted the issue#240 branch July 20, 2023 05:16
SarikaSinha added a commit that referenced this pull request Aug 1, 2023
* Remove use of OPTION_JdtDebugCompileMode with
OPTION_IgnoreUnnamedModuleForSplitPackage

This change replaces use of OPTION_JdtDebugCompileMode with
OPTION_IgnoreUnnamedModuleForSplitPackage, since the latter does what we
need better and doesn't cause the side effects that the first option
causes. Goal is to later on remove OPTION_JdtDebugCompileMode in JDT
core.

Fixes: #260
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>

* Detect JVM installs at startup (#231)

* Detect JVM installs at startup

Fixes #230

* Delete classpath argument files upon shutdown. Fixes #240 (#242)

Store classpath argument files in bundle state location, not in workspace

- Avoids that workspace is contaminated with temporary files.
- Delete classpath argument files upon shutdown.
- Version bump org.eclipse.jdt.launching.

See https://github.com/eclipse-platform/eclipse.platform.debug/issues/84
Fixes #240

* Avoid reusing of not thread-safe SimpleDateFormat

  SimpleDateFormat.format(new Date());
returns same string as immutable and thread-safe
  DateTimeFormatter.format(new Date().toInstant())

* Avoid potential Threadlocal.set(null) memory leak (#249)

Threadlocal.set(null) keeps a reference to ThreadLocal.this
see https://rules.sonarsource.com/java/RSPEC-5164

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* Change how JrtPackageFragmentRoots are printed in Source tab (#266)

- currently all JrtPackageFragmentRoots are printed using the
  path which is the same for all modules extracted from a jrt-fs.jar
- change this to print the module name followed by the full
  jrt-fs.jar path
- fixes #633

* JavaSnippetEditor: fix missing synchronize (#259)

* JavaSnippetEditor: fix missing synchronize

* JavaSnippetEditor: Adding "this." for non static field access

---------

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* LaunchingPlugin: use try-with-resource (#252)

to close streams in case of Exceptions.

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* Add missing "static" modifier for constants (#256)

To reduce memory per instance

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* [trivial] Fixed "Redundant specification of type arguments" warnings

Reported by official SDK build since 4.29 for whatever reason

See for example
https://download.eclipse.org/eclipse/downloads/drops4/I20230621-1800/compilelogs/plugins/org.eclipse.jdt.debug.jdi.tests_1.1.0.v20230328-1614/@dot.html#OTHER_WARNINGS

* Records with inner records breaks breakpoint toggling
fixes #270

Boundary for Breakpoint should be checked

* Touch bundles affected by the new ecj version

See eclipse-platform/eclipse.platform.releng.aggregator#1184

* Fix html links in VMInstall(Type) Extension-Point documentation

* Re-throw underlying exceptions in OpenFromClipboardTests #27 (#279)

Replace call to Display::syncExec with call to Display::syncCall in the
private method getJavaElementMatches. snycCall does not hide exceptions,
it re-throws them to the calling thread (which helps debugging).

Don't catch exceptions in the helper class "Accessor", re-throw them so
the calling tests can show a more meaningful stack-trace when they fail.

* Use typed for-each loop

Avoiding type-casts makes code easier to read.

* Avoid wrapping primitives for toString()

see https://rules.sonarsource.com/java/RSPEC-2131

* ReferenceTypeImpl: compare Array content

instead of instance comparison.
https://stackoverflow.com/questions/8777257/equals-vs-arrays-equals-in-java

* VMInstallTests: fix random ConcurrentModificationException #202

by using threadsafe datastructures.

* Set console stream encoding for java >= 19 - eclipse.platform.debug#124

https://github.com/eclipse-platform/eclipse.platform.debug/issues/124

* FileHashing: avoid getCanonicalFile()

getCanonicalFile() is slow on windows / JDK17 - can costs even more then
calculating the SHA1 of the file content, which it is supposed to avoid.

* Instead use normalized path. It does not matter that multiple files
could be the same due to symbolic links, it will just recalculate their
SHA1 for all of them - which is still faster.
* Also read all file attributes at once.

* Refactor XML parsing

* Fix path decoding of URL to File containing space (fixes #64)

A space in an URL is encoded as "%20" and has to be decoded to " ".

Otherwise a debugged JAR rooted in a path containing space is not
opening class file but java file editor.

* Add MacOS support for detecting VM installs at start up (#276)

- fixes #265

* require org.eclipse.core.runtime 3.29.0

---------

Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Co-authored-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Co-authored-by: Mickael Istria <mistria@redhat.com>
Co-authored-by: Diethard Ohrt <130975899+diti0023@users.noreply.github.com>
Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>
Co-authored-by: Jörg Kubitz <51790620+jukzi@users.noreply.github.com>
Co-authored-by: Jeff Johnston <jjohnstn@redhat.com>
Co-authored-by: Andrey Loskutov <loskutov@gmx.de>
Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Co-authored-by: Federico Jeanne <2205684+fedejeanne@users.noreply.github.com>
SarikaSinha added a commit that referenced this pull request Aug 1, 2023
* Remove use of OPTION_JdtDebugCompileMode with
OPTION_IgnoreUnnamedModuleForSplitPackage

This change replaces use of OPTION_JdtDebugCompileMode with
OPTION_IgnoreUnnamedModuleForSplitPackage, since the latter does what we
need better and doesn't cause the side effects that the first option
causes. Goal is to later on remove OPTION_JdtDebugCompileMode in JDT
core.

Fixes: #260
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>

* Detect JVM installs at startup (#231)

* Detect JVM installs at startup

Fixes #230

* Delete classpath argument files upon shutdown. Fixes #240 (#242)

Store classpath argument files in bundle state location, not in workspace

- Avoids that workspace is contaminated with temporary files.
- Delete classpath argument files upon shutdown.
- Version bump org.eclipse.jdt.launching.

See https://github.com/eclipse-platform/eclipse.platform.debug/issues/84
Fixes #240

* Avoid reusing of not thread-safe SimpleDateFormat

  SimpleDateFormat.format(new Date());
returns same string as immutable and thread-safe
  DateTimeFormatter.format(new Date().toInstant())

* Avoid potential Threadlocal.set(null) memory leak (#249)

Threadlocal.set(null) keeps a reference to ThreadLocal.this
see https://rules.sonarsource.com/java/RSPEC-5164

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* Change how JrtPackageFragmentRoots are printed in Source tab (#266)

- currently all JrtPackageFragmentRoots are printed using the
  path which is the same for all modules extracted from a jrt-fs.jar
- change this to print the module name followed by the full
  jrt-fs.jar path
- fixes #633

* JavaSnippetEditor: fix missing synchronize (#259)

* JavaSnippetEditor: fix missing synchronize

* JavaSnippetEditor: Adding "this." for non static field access

---------

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* LaunchingPlugin: use try-with-resource (#252)

to close streams in case of Exceptions.

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* Add missing "static" modifier for constants (#256)

To reduce memory per instance

Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>

* [trivial] Fixed "Redundant specification of type arguments" warnings

Reported by official SDK build since 4.29 for whatever reason

See for example
https://download.eclipse.org/eclipse/downloads/drops4/I20230621-1800/compilelogs/plugins/org.eclipse.jdt.debug.jdi.tests_1.1.0.v20230328-1614/@dot.html#OTHER_WARNINGS

* Records with inner records breaks breakpoint toggling
fixes #270

Boundary for Breakpoint should be checked

* Touch bundles affected by the new ecj version

See eclipse-platform/eclipse.platform.releng.aggregator#1184

* Fix html links in VMInstall(Type) Extension-Point documentation

* Re-throw underlying exceptions in OpenFromClipboardTests #27 (#279)

Replace call to Display::syncExec with call to Display::syncCall in the
private method getJavaElementMatches. snycCall does not hide exceptions,
it re-throws them to the calling thread (which helps debugging).

Don't catch exceptions in the helper class "Accessor", re-throw them so
the calling tests can show a more meaningful stack-trace when they fail.

* Use typed for-each loop

Avoiding type-casts makes code easier to read.

* Avoid wrapping primitives for toString()

see https://rules.sonarsource.com/java/RSPEC-2131

* ReferenceTypeImpl: compare Array content

instead of instance comparison.
https://stackoverflow.com/questions/8777257/equals-vs-arrays-equals-in-java

* VMInstallTests: fix random ConcurrentModificationException #202

by using threadsafe datastructures.

* Set console stream encoding for java >= 19 - eclipse.platform.debug#124

https://github.com/eclipse-platform/eclipse.platform.debug/issues/124

* FileHashing: avoid getCanonicalFile()

getCanonicalFile() is slow on windows / JDK17 - can costs even more then
calculating the SHA1 of the file content, which it is supposed to avoid.

* Instead use normalized path. It does not matter that multiple files
could be the same due to symbolic links, it will just recalculate their
SHA1 for all of them - which is still faster.
* Also read all file attributes at once.

* Refactor XML parsing

* Fix path decoding of URL to File containing space (fixes #64)

A space in an URL is encoded as "%20" and has to be decoded to " ".

Otherwise a debugged JAR rooted in a path containing space is not
opening class file but java file editor.

* Add MacOS support for detecting VM installs at start up (#276)

- fixes #265

* require org.eclipse.core.runtime 3.29.0

---------

Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Co-authored-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Co-authored-by: Mickael Istria <mistria@redhat.com>
Co-authored-by: Diethard Ohrt <130975899+diti0023@users.noreply.github.com>
Co-authored-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>
Co-authored-by: Jörg Kubitz <51790620+jukzi@users.noreply.github.com>
Co-authored-by: Jeff Johnston <jjohnstn@redhat.com>
Co-authored-by: Andrey Loskutov <loskutov@gmx.de>
Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Co-authored-by: Federico Jeanne <2205684+fedejeanne@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants