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  */
  30 
  31 import java.io.BufferedReader;
  32 import java.io.File;
  33 import java.io.FileReader;
  34 import java.io.FileNotFoundException;
  35 import java.io.IOException;
  36 
  37 public class NegSOURCE {
  38 
  39     NegSOURCE(String dataFile) {
  40         // Read data files
  41         readFile(dataFile);
  42     }
  43 
  44     private void readFile(String fileName) {
  45         String fishForSOURCE = null;
  46 
  47         File file = new File(fileName);
  48 
  49         // open the stream to read in for Entries
  50         try (BufferedReader buffRead = 
  51             new BufferedReader(new FileReader(fileName))) {
  52 
  53             // this is the string read
  54             String readIn;
  55 
  56             // let's read some strings!
  57             while ((readIn = buffRead.readLine()) != null) {
  58                 readIn = readIn.trim();
  59 
  60                 // throw out blank lines
  61                 if (readIn.length() == 0)
  62                     continue;
  63 
  64                 // grab SOURCE line
  65                 if (readIn.startsWith("SOURCE=")) {
  66                     fishForSOURCE = readIn;
  67                     break;
  68                 }
  69             }
  70         } catch (FileNotFoundException fileExcept) {
  71             throw new RuntimeException("File " + fileName + 
  72                 " not found reading data!", fileExcept);
  73         } catch (IOException ioExcept) {
  74             throw new RuntimeException("Unexpected problem reading data!",
  75             ioExcept);
  76         }
  77 
  78         // was SOURCE even found?
  79         if (fishForSOURCE == null) {
  80             throw new RuntimeException("SOURCE line was not found!");
  81         } else {
  82             // OK it was found, did it have closed/open in it?
  83             if (fishForSOURCE.contains("closed") || fishForSOURCE.contains("open")) {
  84                 System.out.println("The offending string: " + fishForSOURCE);
  85                 throw new RuntimeException("The test failed, closed/open found!");
  86             }
  87         }
  88 
  89         // Everything was fine
  90         System.out.println("The test passed!");
  91     }
  92 
  93     public static void main(String args[]) {
  94         String jdkPath = System.getProperty("test.jdk");
  95         String runtime = System.getProperty("java.runtime.name");
  96 
  97         System.out.println("JDK Path : " + jdkPath);
  98         System.out.println("Runtime Name : " + runtime);
  99 
 100         if (runtime.contains("OpenJDK"))
 101             new NegSOURCE(jdkPath + "/release");
 102         else
 103             System.out.println("Test skipped: not an OpenJDK build."); 
 104     }
 105 }