1 /******************************************************************************* 2 * Copyright (c) 2008, 2018 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.pde.api.tools.tests.util; 15 16 import java.io.BufferedInputStream; 17 import java.io.DataInputStream; 18 import java.io.File; 19 import java.io.FileInputStream; 20 import java.io.FileNotFoundException; 21 import java.io.IOException; 22 import java.io.PrintWriter; 23 import java.io.StringWriter; 24 25 import org.eclipse.pde.api.tools.internal.builder.BuildState; 26 import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; 27 import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta; 28 29 /** 30 * Class used to decode what is in an API tool build state 31 */ 32 public class DecodeBuildState { 33 main(String[] args)34 public static void main(String[] args) { 35 if (args.length != 1) { 36 System.err.println("Usage: <path to build state>"); //$NON-NLS-1$ 37 return; 38 } 39 String fileName = args[0]; 40 File file = new File(fileName); 41 if (!file.exists()) { 42 System.err.println("Build state file : " + fileName + " doesn't exist"); //$NON-NLS-1$ //$NON-NLS-2$ 43 return; 44 } 45 BuildState state = null; 46 try (DataInputStream inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(file)))) { 47 state = BuildState.read(inputStream); 48 } catch (FileNotFoundException e) { 49 ApiPlugin.log(e); 50 } catch (IOException e) { 51 ApiPlugin.log(e); 52 } 53 if (state != null) { 54 printBuildState(state); 55 } 56 } 57 printBuildState(BuildState state)58 private static void printBuildState(BuildState state) { 59 StringWriter stringWriter = new StringWriter(); 60 try (PrintWriter writer = new PrintWriter(stringWriter)) { 61 writer.println("Breaking changes"); //$NON-NLS-1$ 62 IDelta[] breakingChanges = state.getBreakingChanges(); 63 int length = breakingChanges.length; 64 if (length != 0) { 65 for (int i = 0; i < length; i++) { 66 IDelta delta = breakingChanges[i]; 67 writer.println(delta); 68 writer.println(delta.getMessage()); 69 } 70 } else { 71 writer.println("No breaking changes"); //$NON-NLS-1$ 72 } 73 writer.println("Compatible changes"); //$NON-NLS-1$ 74 IDelta[] compatibleChanges = state.getCompatibleChanges(); 75 length = compatibleChanges.length; 76 if (length != 0) { 77 for (int i = 0; i < length; i++) { 78 IDelta delta = compatibleChanges[i]; 79 writer.println(delta); 80 writer.println(delta.getMessage()); 81 } 82 } else { 83 writer.println("No compatible changes"); //$NON-NLS-1$ 84 } 85 writer.flush(); 86 } 87 System.out.println("Build state:" + String.valueOf(stringWriter.getBuffer())); //$NON-NLS-1$ 88 } 89 90 91 } 92