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

Fix output path when provided classes have same length #654

Merged
merged 3 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix `Builder` default output path for class names with the same length ([pull #654](https://github.com/bytedeco/javacpp/pull/654))
* Add `Info.friendly` to have `Parser` map some `friend` functions to Java methods ([pull #649](https://github.com/bytedeco/javacpp/pull/649))
* Add `Loader.loadProperties(boolean forceReload)` to reset platform properties ([issue deepjavalibrary/djl#2318](https://github.com/deepjavalibrary/djl/issues/2318))
* Prevent `TokenIndexer` from recursively expanding macros
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/bytedeco/javacpp/tools/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ int compile(String[] sourceFilenames, String outputFilename, ClassProperties pro
/**
* Creates and returns the directory where output files should be placed.
* Uses {@link #outputDirectory} as is when available, but falls back
* on the shortest common path to the classes as well as the platform
* on the longest common path to the classes as well as the platform
* specific library path when available, or the platform name itself
* and the user provided extension when not.
*
Expand All @@ -476,12 +476,12 @@ File getOutputPath(Class[] classes, String[] sourcePrefixes) throws IOException
String resourceURL = Loader.findResource(classes[0], resourceName).toString();
String packageURI = resourceURL.substring(0, resourceURL.lastIndexOf('/') + 1);
for (int i = 1; i < classes.length; i++) {
// Use shortest common package name among all classes as default output path
// Use the longest common package name among all classes as default output path
String resourceName2 = '/' + classes[i].getName().replace('.', '/') + ".class";
String resourceURL2 = Loader.findResource(classes[i], resourceName2).toString();
String packageURI2 = resourceURL2.substring(0, resourceURL2.lastIndexOf('/') + 1);

String longest = packageURI2.length() > packageURI.length() ? packageURI2 : packageURI;
String longest = packageURI2.length() >= packageURI.length() ? packageURI2 : packageURI;
String shortest = packageURI2.length() < packageURI.length() ? packageURI2 : packageURI;
while (!longest.startsWith(shortest) && shortest.lastIndexOf('/') > 0) {
shortest = shortest.substring(0, shortest.lastIndexOf('/'));
Expand Down