1 
   2 /*
   3  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 8192837
  28  * @summary Test to verify release file does not contain closed repo info if it's open bundle
  29  * @run testing NegReleaseSOURCE
  30  */
  31 
  32 import java.io.BufferedReader;
  33 import java.io.File;
  34 import java.io.FileReader;
  35 import java.io.FileNotFoundException;
  36 import java.io.IOException;
  37 
  38 public class NegReleaseSOURCE {
  39 
  40     NegReleaseSOURCE(String dataFile) {
  41         // Read data files
  42         readFile(dataFile);
  43     }
  44 
  45     private void readFile(String fileName) {
  46         String fishForSOURCE = null;
  47 
  48         File file = new File(fileName);
  49 
  50         // open the stream to read in for Entries
  51         try (BufferedReader buffRead =
  52             new BufferedReader(new FileReader(fileName))) {
  53 
  54             // this is the string read
  55             String readIn;
  56 
  57             // let's read some strings!
  58             while ((readIn = buffRead.readLine()) != null) {
  59                 readIn = readIn.trim();
  60 
  61                 // throw out blank lines
  62                 if (readIn.length() == 0)
  63                     continue;
  64 
  65                 // grab SOURCE line
  66                 if (readIn.startsWith("SOURCE=")) {
  67                     fishForSOURCE = readIn;
  68                     break;
  69                 }
  70             }
  71         } catch (FileNotFoundException fileExcept) {
  72             throw new RuntimeException("File " + fileName +
  73                                        " not found reading data!", fileExcept);
  74         } catch (IOException ioExcept) {
  75             throw new RuntimeException("Unexpected problem reading data!",
  76                                        ioExcept);
  77         }
  78 
  79         // was SOURCE even found?
  80         if (fishForSOURCE == null) {
  81             throw new RuntimeException("SOURCE line was not found!");
  82         } else {
  83             // OK it was found, did it have closed/open in it?
  84             if (fishForSOURCE.contains("closed") || fishForSOURCE.contains("open")) {
  85                 System.out.println("The offending string: " + fishForSOURCE);
  86                 throw new RuntimeException("The test failed, closed/open found!");
  87             }
  88         }
  89 
  90         // Everything was fine
  91         System.out.println("The test passed!");
  92     }
  93 
  94     public static void main(String args[]) {
  95         String jdkPath = System.getProperty("test.jdk");
  96         String runtime = System.getProperty("java.runtime.name");
  97 
  98         System.out.println("JDK Path : " + jdkPath);
  99         System.out.println("Runtime Name : " + runtime);
 100 
 101         if (runtime.contains("OpenJDK"))
 102             new NegReleaseSOURCE(jdkPath + "/release");
 103         else
 104             System.out.println("Test skipped: not an OpenJDK build.");
 105     }
 106 }