-
-
Notifications
You must be signed in to change notification settings - Fork 190
Simplify startup code #5701
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
Draft
dizzzz
wants to merge
18
commits into
eXist-db:develop
Choose a base branch
from
dizzzz:feature/simplify_startup
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Simplify startup code #5701
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1a94855
[refactor] Reformatting code
dizzzz 88d82d9
[refactor] move class and methods to jnlp package
dizzzz 119c09b
[refactor] update Java version checker class
dizzzz 84118f1
[refactor] remove unused class
dizzzz 5a3e16b
[refactor] Isolate classloader in separate package as it is externall…
dizzzz 28ded37
[refactor] improve javadoc
dizzzz 063c9af
[refactor] simplify code
dizzzz fd65c57
[refactor] update javadoc
dizzzz 6ce0a16
[refactor] order declarations for readability
dizzzz b595488
[bugfix] make sure that for macos also java21 is enforced
dizzzz 48237ab
[refactor] improve readability of startup classes
dizzzz 189b96c
[bugfix] Fixed another javadoc
dizzzz 251ca0c
[refactor] Update licence check, extend javadoc
dizzzz c904065
[bugfix] address code quality issues
dizzzz fb099f3
[refactor] Address code review feedback
dizzzz 8892c1d
[refactor] update javadoc
dizzzz a5dbd30
[refactor] Remise classes more, added javadoc
dizzzz 0508daa
[refactor] Remise classes more, added javadoc
dizzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,47 +19,48 @@ | |
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
package org.exist.start; | ||
package org.exist.webstart; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* This class uses regex pattern matching to find the latest version of a | ||
* particular jar file. | ||
* | ||
* @see LatestFileResolver#getResolvedFileName(String) | ||
* | ||
* particular jar file. | ||
* | ||
* @author Ben Schmaus ([email protected]) | ||
* @version $Revision$ | ||
* @see LatestFileResolver#getResolvedFileName(String) | ||
*/ | ||
public class LatestFileResolver { | ||
|
||
// Pattern that can be used to indicate that the | ||
// latest version of a particular file should be added to the classpath. | ||
// E.g., commons-fileupload-%latest%.jar would resolve to something like | ||
// commons-fileupload-1.1.jar. | ||
private final static Pattern latestVersionPattern = Pattern.compile( | ||
"(%latest%)" | ||
); | ||
private final static Pattern latestVersionPattern = Pattern.compile("(%latest%)"); | ||
|
||
// Set debug mode for each file resolver instance based on whether or | ||
// not the system was started with debugging turned on. | ||
private static boolean _debug = Boolean.getBoolean("exist.start.debug"); | ||
private static final boolean _debug = Boolean.getBoolean("exist.start.debug"); | ||
|
||
/** | ||
* If the passed file name contains a %latest% token, | ||
* find the latest version of that file. Otherwise, return | ||
* the passed file name unmodified. | ||
* | ||
* | ||
* @param filename Path relative to exist home dir of | ||
* a jar file that should be added to the classpath. | ||
* a jar file that should be added to the classpath. | ||
* @return Resolved filename. | ||
*/ | ||
public String getResolvedFileName(final String filename) { | ||
|
@@ -72,9 +73,7 @@ public String getResolvedFileName(final String filename) { | |
final String uptoToken = fileinfo[0]; | ||
|
||
// Dir that should contain our jar. | ||
final String containerDirName = uptoToken.substring( | ||
0, uptoToken.lastIndexOf(File.separatorChar) | ||
); | ||
final String containerDirName = uptoToken.substring(0, uptoToken.lastIndexOf(File.separatorChar)); | ||
|
||
final Path containerDir = Paths.get(containerDirName); | ||
|
||
|
@@ -86,8 +85,8 @@ public String getResolvedFileName(final String filename) { | |
|
||
List<Path> jars; | ||
try { | ||
jars = Main.list(containerDir, p -> { | ||
matcher.reset(Main.fileName(p)); | ||
jars = list(containerDir, p -> { | ||
matcher.reset(fileName(p)); | ||
return matcher.find(); | ||
}); | ||
} catch (final IOException e) { | ||
|
@@ -99,20 +98,34 @@ public String getResolvedFileName(final String filename) { | |
if (!jars.isEmpty()) { | ||
final String actualFileName = jars.getFirst().toAbsolutePath().toString(); | ||
if (_debug) { | ||
System.err.println( | ||
"Found match: " + actualFileName | ||
+ " for jar file pattern: " + filename | ||
); | ||
System.err.println("Found match: " + actualFileName + " for jar file pattern: " + filename); | ||
} | ||
return actualFileName; | ||
} else { | ||
if (_debug) { | ||
System.err.println( | ||
"WARN: No latest version found for JAR file: '" | ||
+ filename + "'" | ||
); | ||
System.err.println("WARN: No latest version found for JAR file: '" + filename + "'"); | ||
} | ||
} | ||
return filename; | ||
} | ||
} | ||
|
||
/** | ||
* Copied from {@link org.exist.util.FileUtils#list(Path, Predicate)} | ||
* as org.exist.start is compiled into a separate Jar and doesn't have | ||
* the rest of eXist available on the classpath | ||
*/ | ||
static List<Path> list(final Path directory, final Predicate<Path> filter) throws IOException { | ||
try (final Stream<Path> entries = Files.list(directory).filter(filter)) { | ||
return entries.collect(Collectors.toList()); | ||
} | ||
} | ||
|
||
/** | ||
* Copied from {@link org.exist.util.FileUtils#fileName(Path)} | ||
* as org.exist.start is compiled into a separate Jar and doesn't have | ||
* the rest of eXist available on the classpath | ||
*/ | ||
static String fileName(final Path path) { | ||
return path.getFileName().toString(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG.error() can now be used