Skip to content

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

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

Closed
wants to merge 3 commits into from

Conversation

prrace
Copy link
Contributor

@prraceprrace 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

👋 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.

@openjdkopenjdkbot added the rfr Pull request is ready for review label Sep 24, 2020
@openjdk
Copy link

openjdkbot 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.

@openjdkopenjdkbot added the awt client-libs-dev@openjdk.org label Sep 24, 2020
@prrace
Copy link
ContributorAuthor

label /remove awt

@prrace
Copy link
ContributorAuthor

/label add 2d

@openjdkopenjdkbot added the 2d client-libs-dev@openjdk.org label Sep 24, 2020
@openjdk
Copy link

openjdkbot commented Sep 24, 2020

@prrace
The 2d label was successfully added.

@prrace
Copy link
ContributorAuthor

/label remove awt

@openjdkopenjdkbot removed the awt client-libs-dev@openjdk.org label Sep 24, 2020
@openjdk
Copy link

openjdkbot commented Sep 24, 2020

@prrace
The awt label was successfully removed.

@mlbridge
Copy link

mlbridgebot commented Sep 24, 2020

//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

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
ContributorAuthor

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

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
ContributorAuthor

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

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
ContributorAuthor

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

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
ContributorAuthor

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

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
ContributorAuthor

Updated with the comment moved.

@openjdk
Copy link

openjdkbot 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.

@openjdkopenjdkbot added the ready Pull request is ready to be integrated label Sep 26, 2020
@prrace
Copy link
ContributorAuthor

/integrate

@openjdkopenjdkbot closed this Sep 26, 2020
@openjdkopenjdkbot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 26, 2020
@openjdk
Copy link

openjdkbot 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.

@prraceprrace deleted the print_to_file branch October 2, 2020 22:18
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2dclient-libs-dev@openjdk.orgintegratedPull request has been integrated
3 participants
@prrace@mrserb@prsadhuk
close