11/*
2- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525import java .io .InputStreamReader ;
2626import javax .print .PrintService ;
2727import javax .print .PrintServiceLookup ;
28- import javax . print . attribute . AttributeSet ;
29- import javax . print . attribute . HashAttributeSet ;
30- import javax . print . attribute . standard . PrinterName ;
28+ import java . io . IOException ;
29+
30+ import jtreg . SkippedException ;
3131
3232/*
3333 * @test
3434 * @bug 8032693
3535 * @key printer
36+ * @library /test/lib/
37+ * @requires (os.family == "linux")
3638 * @summary Test that lpstat and JDK agree whether there are printers.
3739 */
3840public class CountPrintServices {
3941
4042 public static void main (String [] args ) throws Exception {
41- String os = System .getProperty ("os.name" ).toLowerCase ();
42- System .out .println ("OS is " + os );
43- if (!os .equals ("linux" )) {
44- System .out .println ("Linux specific test. No need to continue" );
45- return ;
46- }
4743 PrintService services [] =
4844 PrintServiceLookup .lookupPrintServices (null , null );
4945 if (services .length > 0 ) {
5046 System .out .println ("Services found. No need to test further." );
5147 return ;
5248 }
5349 String [] lpcmd = { "lpstat" , "-a" };
54- Process proc = Runtime .getRuntime ().exec (lpcmd );
50+ Process proc ;
51+ try {
52+ proc = Runtime .getRuntime ().exec (lpcmd );
53+ } catch (IOException e ) {
54+ if (e .getMessage ().contains ("No such file or directory" )) {
55+ throw new SkippedException ("Cannot find lpstat" );
56+ } else {
57+ throw e ;
58+ }
59+ }
5560 proc .waitFor ();
5661 InputStreamReader ir = new InputStreamReader (proc .getInputStream ());
5762 BufferedReader br = new BufferedReader (ir );
@@ -66,4 +71,3 @@ public static void main(String[] args) throws Exception {
6671 }
6772 }
6873}
69-
0 commit comments