Commit Graph
241 Commits
Author SHA1 Message Date
Matt Sicker 1b23a9e119 Fix symlink check logic to support junctions again
Signed-off-by: Matt Sicker <boards@gmail.com>
2018-12-17 15:18:17 -06:00
Matt Sicker 2e8197a2c7 Complete refactoring of Util.delete methods
This removes duplicated tests from UtilTest that were added in PathRemoverTest. This also ports the sleep/gc strategy for use by default to preserve backward compatibility.

Signed-off-by: Matt Sicker <boards@gmail.com>
2018-12-14 10:33:18 -06:00
Sam Van Oort e0ed9a86e0 Micro-optimizations to Plugin data to reduce minimum memory for Jenkins (#3654)
* Reduce memory footprint for the plugin info by presizing hashmaps to reduce waste for small maps and interning commonly duplicated plugin strings

* Replace duplicated empty string arrays with the one in MemoryReductionUtil

* Fix interning where strings are null

* Fix to deal with the fact that we directly mutate dependency fields for UpdateSite, sigh

* Reduce starting HashMap size for some hashmaps likely to be empty or tiny

* Cleanup per review comments

* Trim some extra waste out of the UpdateSite warnings

* Fix count of optional dependencies

* Move predicates for dependency matching to top-level static final field so they are not duplicated
2018-10-06 12:49:07 +02:00
Oleg Nenashev f120484f84 Amend the Util#fixNull() Javadoc 2018-10-02 10:05:48 +02:00
Olivier Truong 149fd9b608 fix javadoc following PR comments 2018-10-01 23:14:00 +02:00
Olivier Truong 8a3bbdda2f [JENKINS-53847] Improve JavaDoc for Util.fixNull 2018-10-01 22:04:01 +02:00
Oleg Nenashev beadc5946f Util#fixNull: Address Javadoc comments and add annotations 2018-09-30 12:37:53 +02:00
Nicolas De Loof 179d597679 introduce hudson.Util#fixNull(value, defaultValue)
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2018-09-28 13:59:14 +02:00
Oleg Nenashev ba08ebc97a Refactoring: Cleanup <tt> tags from the Jenkins core Javadoc 2018-09-21 17:47:11 -07:00
Daniel Beck 86639c9007 Merge commit '31d7966e3896819a99b31f10e83e864e3805bcbd' into security-master 2018-07-16 11:42:43 +02:00
Wadeck Follonier e0cc790ee7 Address other comments
- also add translation for another creationDate
- and manage correctly the null creation date instead of 0
2018-06-26 17:33:05 +02:00
Wadeck Follonier 0a41e87b66 Address Josh's comments 2018-06-26 14:51:25 +02:00
Wadeck Follonier 5f7c50cd0d [JENKINS-52161] Improve creation-date value determination
- in case of migration we put null instead of now
- improve also the difference in days for the Xxx day(s) ago to take calendar day in difference and not the total duration (<24h = 0 days, which seems wrong in UI)
2018-06-26 13:06:16 +02:00
Daniel Beck 556d6f7036 Merge commit 'b92db0f04e64cdd7a815bd78a5dd3dd4cd7ead7c' of git://github.com/jenkinsci/jenkins 2018-04-25 23:11:13 +02:00
Jesse Glick d25c0b2c39 Merge branch 'master' into VirtualFile-JENKINS-49635 2018-04-13 12:32:38 -04:00
Daniel Beck bbe96187ab Merge branch 'security-stable-2.107' into security-master 2018-03-29 02:01:34 +02:00
Daniel Trebbien aa799e39ad [JENKINS-49971] Fix a race condition in Util.loadFile() (#3225)
* Fix a race condition in Util.loadFile()

If the file is deleted in between when its existence is checked and the
file is opened for reading, then the method will fail to return an empty
string.

* Switch to using FileUtils.readFileToString()

(cherry picked from commit aaae71af4b)
2018-03-25 20:17:21 +02:00
Jesse Glick c7372cc098 Merge branch 'master' into VirtualFile-JENKINS-49635 2018-03-12 13:56:15 -04:00
Daniel Trebbien aaae71af4b [JENKINS-49971] Fix a race condition in Util.loadFile() (#3225)
* Fix a race condition in Util.loadFile()

If the file is deleted in between when its existence is checked and the
file is opened for reading, then the method will fail to return an empty
string.

* Switch to using FileUtils.readFileToString()
2018-03-08 00:53:53 +01:00
Jesse Glick 23f12fd8f5 Merge branch 'master' into VirtualFile-JENKINS-49635 2018-03-05 10:02:42 -05:00
Daniel Trebbien 8f51260323 hudson.Util improvements (#3226)
* Organize imports

* Use StandardCharsets

* Delete a redundant cast

* Replace use of _ as an identifier

_ is a keyword in Java 9.

* Use Logger message formatting

* Use fileToPath()

* Switch to using Files.createTempDirectory()

* Document that Util.touch() will truncate an existing file

* Replace an unnecessary use of Throwable.initCause()

* Implement deprecated copyStream() using IOUtils

* Copy to NULL_OUTPUT_STREAM

Also, closing source is moved to a finally block, to guarantee that it
will be closed per the documentation; it was technically possible for
the input stream to not be closed if construction of the MessageDigest,
DigestInputStream, or byte[] buffer failed for some reason (e.g. out of
memory).

* Delete an unnecessary try-with-resources

* Throw an IllegalArgumentException if data has odd length

Previously, a StringIndexOutOfBoundsException would be thrown, which is
less clear.

* Specify expanded POSIX file permissions
2018-03-03 13:04:29 +01:00
Jesse Glick 9b9f81d4a5 Merge branch 'master' into VirtualFile-JENKINS-49635 2018-02-28 16:36:43 -05:00
Jesse Glick e3e6d570f7 VirtualFile.readLink 2018-02-21 15:55:38 -05:00
Jesse Glick 7f839d8277 Fixing nullability annotations on Util.escape. 2018-02-05 23:43:54 +01:00
Daniel Trebbien e798f64854 [JENKINS-49112] Revert use of Files.newBufferedReader() in Util.loadFile() (#3259)
* [JENKINS-49112] Revert use of Files.newBufferedReader() in Util.loadFile()

This partially reverts 67076834a2.

* Restore the use of StringBuilder and reading into buf
2018-01-26 18:35:20 +01:00
Daniel Trebbien e8c86a374f Use fileToPath() (#3219)
* Use fileToPath()

This is a follow-up to PR 3210 on GitHub. See:
https://github.com/jenkinsci/jenkins/pull/3210#discussion_r160045107

* Switch two File.toPath() calls to Util.fileToPath()

* Delete an unused import
2018-01-09 21:21:59 +01:00
Daniel Trebbien 67076834a2 Switch to calling Files.newBufferedReader
These changes were suggested by Extra Hints for NetBeans IDE:
http://plugins.netbeans.org/plugin/73447/
2017-12-27 19:45:30 -08:00
Devin Nusbaum 1270ba3b40 [JENKINS-48405] Use NIO in tryOnceDeleteFile and makeWritable (#3169)
* Use NIO in tryOnceDeleteFile and makeWritable

* Don't try to set PosixFileAttributes on Windows

* Do not create arbitrary exceptions in makeWritable to fix test failures on Windows

* Remove unhelpful layer of exception wrapping

* Add test exercising Util#makeWritable in Util#tryOnceDeleteFile

* Add test for deleting a non-existant file

* Return early if changing permissions with NIO succeeds
2017-12-16 09:23:41 +01:00
Devin Nusbaum fdccc0e838 [JENKINS-36088] Use NIO implementations of chmod and mode by default (#3135)
* Use NIO for FilePath#chmod and IOUtils#mode

* Add tests for NIO mode and chmod implementations

* Add test, remove new method, and update JavaDoc

* Provide system property to use native implementations of chmod and mode

* Revert unrelated whitespace modification

* Don't remove exception from throws and put imports in original location

* Fix broken JavaDoc links

* Ignore file type bits (above 0o7777) in Util#modeToPermission

* Use octal for constants and don't include file type bits

* Revert unnecessary changes to TarArchiverTest

* Add assertion that non-permission bits are ignored by chmod

* Use NIO copy with StandardCopyOption.COPY_ATTRIBUTES in copyToWithPermissions where possible

* Catch InvalidPathException and convert it to IOException

* Create utility method for File#toPath and use File#createDirectories after review

* Remove useless calls to toAbsolutePath and getAbsoluteFile

* Fix typos and use octal for constant after review

* Add test for behavior of copyToWithPermission with special bits
2017-12-01 10:01:34 +03:00
Devin Nusbaum 52fa4d90b9 [JENKINS-39179] [JENKINS-36088] Always use NIO to create and detect symbolic links and Windows junctions (#3133)
* Always use NIO to detect symlinks

* Make assertion failure message consistent

* Catch NoSuchFileException to keep tests passing

* Make method name more specific and simlify assumption

* Remove obsolete comment and reword the main comment in isSymlink

* Deprecate Kernel32Util#isJunctionOrSymlink

* Use assumptions for junction creation and add messages to assumptions

* Replace deprecated code with recommended alternative

* Add comment explaining call to DosFileAttributes#isOther

* Do not fall back to native code when creating symlinks

* Log FileSystemExceptions when creating symbolic links

* Catch InvalidPathException and rethrow as IOException

* Deprecate Kernel32Utils#createSymbolicLink and #getWin32FileAttributes

* Preserve original logging behavior on Windows and remove useless call to Util#displayIOException
2017-11-16 17:08:10 +01:00
Jesse Glick 6a4d800091 [JENKINS-44657] Noting when #2932 was merged. 2017-09-28 10:44:18 -04:00
Robert Sandell 3adfed4b06 [JENKINS-44657] Move sub-job's buildsdir when outside of itemrootdir (#2932)
* A test to verify JENKINS-44657 is working in core

* [JENKINS-44657] Move sub-job's buildsdir when outside of itemrootdir.

* [JENKINS-44657] Fix UsageStatisticsTest

Because we've added a test dependency that affects it.

* [JENKINS-44657] Normalize the path before comparing

* [JENKINS-44657] Use MockFolder instead of folders-plugin

for tests

* [JENKINS-44657] Document and annotate isDefaultBuildDir

* [JENKINS-44657] isDescendant doesn't throw IOException any more

* [JENKINS-44657] catch InvalidPathException and rethrow as IOException
2017-09-23 22:59:39 +03:00
Stephen Connolly 3871d7778e [JENKINS-43531] Plugins may not be expecting InvalidPathException
- Plugins should really be expecting it, but as historically they have not, may as well convert to IOE for them
2017-04-19 14:04:33 +01:00
Jesse Glick 23cb13aad0 Clean up usages of IOUtils.closeQuietly and related calls (#2830)
* Clean up usages of IOUtils.closeQuietly and related calls predating Java 7.

* Review comments from @oleg-nenashev.

* Noticed another place where try-with-resources would protect against a potential leak.
2017-04-08 00:41:27 +02:00
Stephen Connolly f0cd7ae8ff [JENKINS-42934] Avoid using new FileInputStream / new FileOutputStream 2017-03-20 12:50:46 +00:00
James Nord b6234721c1 kill those pesky hudson temp files 2017-03-06 17:34:16 +00:00
Jesse Glick 76aa0727f0 Functions.printStackTrace utility method. 2016-12-12 17:56:24 -05:00
Jesse Glick 24aa20635d Replaced other usages of printStackTrace. 2016-12-12 16:44:10 -05:00
Baptiste Mathus 5588df315d Add @since on Util.isSafeToRedirectTo() 2016-11-09 09:36:52 +01:00
Daniel Beck 72cb842b6c Cleaning up @since TODO / @since XXX 2016-10-15 23:22:20 +02:00
Oliver Gondža 7f6f495f86 Avoid deprecated findbugs annotations (#2144)
* Avoid deprecated findbugs annotations

* One more forgotten annotation
2016-10-15 12:53:56 -07:00
Nicolas De Loof 7b39424495 rely on try-with-resources 2016-10-03 15:12:48 +02:00
dbroady1 f4edf91782 [JENKINS-29956] Test Windows junctions before Java 7 symlink (#1787)
* Test Windows junctions before Java 7 symlink

Apparently Java 7 (and later) do not count Windows junctions as
symlinks.  When you drill down into the BasicFileAttributes structure,
reparse points are only counted under isOther.  So, since we already
have code that properly detects Windows Junctions, let's use that first
and then fallback to the Java 7 code.

* Add comment for change & link bug.

* Add test case

* Switch to Functions.isWindows().

* Use non-deprecated APIs for tmp file/dir mgmt

* Add better debugging.

* Allow spaces in junction name & dir name.

To do that, it was easier to use ProcessBuilder vs building up the correct
string in code to send to cmd.exe.

Also, I'll note that according to http://ss64.com/nt/syntax-internal.html,
mklink is in internal cmd.exe command.  So, it must be invoked through
"cmd.exe /c" for it to work.

* Remove comment mentioning bug number.

* Remove debugging output, per Baptiste's request

* Add newline at end of file.

* Make sure that the junction was removed.

* Use assertEquals to show retcode of Process.waitFor.

* Fix compilation errors by importing functions
2016-08-22 15:21:33 +02:00
Oleg Nenashev 96c97860b0 [FIXED JENKINS-37332] - Prevent File descriptor leaks when reading manifests from JARs (#2516)
* [JENKINS-37332] - Improve diagnostics of non-closed streams during reading of the manifests in PluginManager

* [JENKINS-37332] - Leakless processing of JarUrlConnection during Manifest parsing

* [JENKINS-37332] - Also implement leak-safe method for retrieving file modification date

* [JENKINS-37332] - Add spotcheck methods for manifest file access + Javadoc

* [JENKINS-37332] - Also test multi-line and empty attributes in the test
2016-08-21 00:00:41 +02:00
Oleg Nenashev 3c31cb9692 FindBugs: Suppress DM_GC in hudson.Util#pauseBetweenDeletes(), because it's a desired behavior for custom setting 2016-07-16 02:16:50 +03:00
Pavel Janousek b21ab921de [JENKINS-35570] List of computer's names extracted to Util (#2408)
* [JENKINS-35570] List of computer's names extracted to Util
2016-07-12 09:13:33 +02:00
Oleg Nenashev 1d2b15173c [JENKINS-34854] - Migrate missing settings to SystemProperties (#2362)
* [JENKINS-34854] - Migrate missing Integer and Boolean properties to SystemProperties

* [JENKINS-34854] - API methods for Long variables

* [JENKINS-34854] - Migrate Long settings to SystemProperties

* [JENKINS-34854] - Leftover change (I should use Save All)

* [JENKINS-34854] - Some fixes in Long methods Javadoc and log messages
2016-05-21 09:36:18 +04:00
Oleg Nenashev ce8922bd74 Merge branch 'master' into JENKINS-34755
Conflicts:
	core/src/main/java/hudson/Util.java
	core/src/main/java/hudson/WebAppMain.java
	core/src/main/java/hudson/model/Item.java
	core/src/main/java/hudson/model/Queue.java
	core/src/main/java/hudson/model/UpdateCenter.java
	core/src/main/java/hudson/security/csrf/DefaultCrumbIssuer.java
	core/src/main/java/hudson/slaves/NodeProvisioner.java
	core/src/main/java/jenkins/model/Jenkins.java
	core/src/main/java/jenkins/slaves/NioChannelSelector.java
	core/src/main/java/jenkins/util/xml/XMLUtils.java
2016-05-12 12:05:24 +02:00
Jesse Glick c2d0a5778e Merge commit '97a0fa0d036b9d3873c9b269123020a42e7ee3e9' into security-master 2016-05-11 12:07:25 -04:00
Daniel Beck 240405dfc3 Merge pull request #2026 from pjdarton/fix_jenkins_15331
[FIX JENKINS-15331] Windows file locking workaround
2016-05-04 01:32:27 +02:00