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

7179006: [macosx] Print-to-file doesn't work: printing to the default printer instead. #339

Closed
wants to merge 3 commits into from

Conversation

prrace
Copy link
Contributor

@prrace prrace commented Sep 24, 2020

A long-standing bug on macOS: https://bugs.openjdk.java.net/browse/JDK-7179006

The fix is to propagate whatever is set as the Destination down to native and set it on the native printing object.

Also if using the native dialog, but with attributes, copy back the destination from native to the Java attribute set.

The new test can directly test printing to file in an automated way - so long as there is a printer.

The updated manual test can be used to verify the cross-platform dialog case.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-7179006: [macosx] Print-to-file doesn't work: printing to the default printer instead ⚠️ Title mismatch between PR and JBS.

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/339/head:pull/339
$ git checkout pull/339

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 24, 2020

👋 Welcome back prr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Sep 24, 2020
@openjdk
Copy link

openjdk bot commented Sep 24, 2020

@prrace The following label will be automatically applied to this pull request: awt.

When this pull request is ready to be reviewed, an RFR email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label (add|remove) "label" command.

@openjdk openjdk bot added the awt label Sep 24, 2020
@prrace
Copy link
Contributor Author

prrace commented Sep 24, 2020

label /remove awt

@prrace
Copy link
Contributor Author

prrace commented Sep 24, 2020

/label add 2d

@openjdk openjdk bot added the 2d label Sep 24, 2020
@openjdk
Copy link

openjdk bot commented Sep 24, 2020

@prrace
The 2d label was successfully added.

@prrace
Copy link
Contributor Author

prrace commented Sep 24, 2020

/label remove awt

@openjdk openjdk bot removed the awt label Sep 24, 2020
@openjdk
Copy link

openjdk bot commented Sep 24, 2020

@prrace
The awt label was successfully removed.

@mlbridge
Copy link

mlbridge bot commented Sep 24, 2020

Webrevs

//NSURL *nsURL = [NSURL URLWithString:nsDestStr];
NSURL *nsURL = [NSURL fileURLWithPath:nsDestStr isDirectory:NO];
[printingDictionary setObject:nsURL forKey:NSPrintJobSavingURL];
// JNFCallVoidMethod(env, dstPrinterJob, jm_setPrintToFile, true);
Copy link
Member

@mrserb mrserb Sep 25, 2020

Choose a reason for hiding this comment

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

Does it look like the commented lines are not needed?

Copy link
Contributor Author

@prrace prrace Sep 25, 2020

Choose a reason for hiding this comment

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

Hmm. I could swear I removed those and re-ordered the first two lines as well.

pj.print(pSet);
if (!file.exists()) {
throw new RuntimeException("No file created");
}
Copy link
Contributor

@prsadhuk prsadhuk Sep 25, 2020

Choose a reason for hiding this comment

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

I guess we need to delete the file in finally block, if created.

Copy link
Contributor Author

@prrace prrace Sep 25, 2020

Choose a reason for hiding this comment

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

I meant to leave it. So we can look at it if we need to.

@@ -251,6 +253,22 @@ private void setPrintToFile(boolean printToFile) {
isPrintToFile = printToFile;
}

private void setDestinationFile(String dest) {
System.out.println("dest="+dest+" attrs="+attributes);
Copy link
Contributor

@prsadhuk prsadhuk Sep 25, 2020

Choose a reason for hiding this comment

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

Probably this println should be removed.

Copy link
Contributor Author

@prrace prrace Sep 25, 2020

Choose a reason for hiding this comment

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

oops

try {
URI destURI = new URI(dest);
attributes.add(new Destination(destURI));
destinationAttr = "" + destURI.getSchemeSpecificPart();
Copy link
Member

@mrserb mrserb Sep 25, 2020

Choose a reason for hiding this comment

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

This destinationAttr in the RasterPrinterJob is usually assigned to:
destinationAttr = "" + new File(destination.getURI().
getSchemeSpecificPart());
Do we need to do the same here?

Copy link
Contributor Author

@prrace prrace Sep 25, 2020

Choose a reason for hiding this comment

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

I see that in WPrinterJob.java we do the same as I am doing here.
I think the difference in RPJ may bethat we want to get a full path name which is what the new File did.
Here macOS gives us a full path name already. So I don't think it is needed.
It gave the required value for sure.

NSURL *url = [printingDictionary objectForKey:NSPrintJobSavingURL];
NSString *nsStr = [url absoluteString];
jstring str = JNFNSToJavaString(env, nsStr);
JNFCallVoidMethod(env, dstPrinterJob, jm_setDestinationFile, str);
} else {
JNFCallVoidMethod(env, dstPrinterJob, jm_setPrintToFile, false);
}

// get the selected printer's name, and set the appropriate PrintService on the Java side
Copy link
Member

@mrserb mrserb Sep 25, 2020

Choose a reason for hiding this comment

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

The comment need to be moved up as well?

@prrace
Copy link
Contributor Author

prrace commented Sep 25, 2020

Updated with the comment moved.

mrserb
mrserb approved these changes Sep 26, 2020
@openjdk
Copy link

openjdk bot commented Sep 26, 2020

@prrace This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for more details.

After integration, the commit message for the final commit will be:

7179006: [macosx] Print-to-file doesn't work: printing to the default printer instead.

Reviewed-by: serb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 52 new commits pushed to the master branch:

  • b66fa8f: 8253572: [windows] CDS archive may fail to open with long file names
  • 4167540: 8253647: Remove dead code in os::create_thread() on Linux/BSD
  • 5a57945: 8231591: [TESTBUG] Create additional two phase jpackage tests
  • b159e4e: 8253149: Building an installer from invalid app image fails on Window…
  • 0e855fe: 8252377: Incorrect encoding for EC AlgorithmIdentifier
  • 9150b90: 8253659: ProblemList sun/security/ec/TestEC.java on linux-aarch64
  • 0187567: 8250984: Memory Docker tests fail on some Linux kernels w/o cgroupv1 …
  • a75edc2: 8251188: Update LDAP tests not to use wildcard addresses
  • 1f5a033: 8253555: Make ByteSize and WordSize typed scoped enums
  • f62eefc: 8253469: ARM32 Zero: replace usages of __sync_synchronize() with OrderAccess::fence
  • ... and 42 more: https://git.openjdk.java.net/jdk/compare/0f26ab16ddf10cefc0b528aa12c7c2378a864063...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Sep 26, 2020
@prrace
Copy link
Contributor Author

prrace commented Sep 26, 2020

/integrate

@openjdk openjdk bot closed this Sep 26, 2020
@openjdk openjdk bot added integrated and removed ready rfr labels Sep 26, 2020
@openjdk
Copy link

openjdk bot commented Sep 26, 2020

@prrace Since your change was applied there have been 52 commits pushed to the master branch:

  • b66fa8f: 8253572: [windows] CDS archive may fail to open with long file names
  • 4167540: 8253647: Remove dead code in os::create_thread() on Linux/BSD
  • 5a57945: 8231591: [TESTBUG] Create additional two phase jpackage tests
  • b159e4e: 8253149: Building an installer from invalid app image fails on Window…
  • 0e855fe: 8252377: Incorrect encoding for EC AlgorithmIdentifier
  • 9150b90: 8253659: ProblemList sun/security/ec/TestEC.java on linux-aarch64
  • 0187567: 8250984: Memory Docker tests fail on some Linux kernels w/o cgroupv1 …
  • a75edc2: 8251188: Update LDAP tests not to use wildcard addresses
  • 1f5a033: 8253555: Make ByteSize and WordSize typed scoped enums
  • f62eefc: 8253469: ARM32 Zero: replace usages of __sync_synchronize() with OrderAccess::fence
  • ... and 42 more: https://git.openjdk.java.net/jdk/compare/0f26ab16ddf10cefc0b528aa12c7c2378a864063...master

Your commit was automatically rebased without conflicts.

Pushed as commit ea7c47c.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@prrace prrace deleted the print_to_file branch Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2d integrated
3 participants