@Test public void dockerfileToCommandListTest_2() throws Exception { File testFile = TestUtils.findTestFile( "/dockerfiles/dockerfile2" ); List<DockerfileParser.DockerCommand> ldc = DockerfileParser.dockerfileToCommandList( testFile ); Assert.assertEquals( 4, ldc.size()); Assert.assertEquals( DockerfileParser.DockerCommandType.RUN, ldc.get( 0 ).type ); Assert.assertEquals( "apt-get update", ldc.get( 0 ).argument ); Assert.assertEquals( DockerfileParser.DockerCommandType.RUN, ldc.get( 1 ).type ); Assert.assertEquals( "apt-get install -y python python-pip wget", ldc.get( 1 ).argument ); Assert.assertEquals( DockerfileParser.DockerCommandType.RUN, ldc.get( 2 ).type ); Assert.assertEquals( "pip install Flask", ldc.get( 2 ).argument ); Assert.assertEquals( DockerfileParser.DockerCommandType.ADD, ldc.get( 3 ).type ); Assert.assertEquals( "hello.py /home/hello.py", ldc.get( 3 ).argument ); }
public static List<DockerCommand> dockerfileToCommandList( File dockerfile ) throws IOException { List<DockerCommand> result = new ArrayList<>(); FileInputStream in = new FileInputStream( dockerfile ); Logger logger = Logger.getLogger( DockerfileParser.class.getName()); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 )); String line; while((line = br.readLine()) != null) { DockerCommand cmd = DockerCommand.guess(line); if( cmd != null ) result.add( cmd ); else logger.fine("Ignoring unsupported Docker instruction: " + line ); } } finally { Utils.closeQuietly( br ); Utils.closeQuietly( in ); } return result; }
DockerfileParser { public static List<DockerCommand> dockerfileToCommandList( File dockerfile ) throws IOException { List<DockerCommand> result = new ArrayList<>(); FileInputStream in = new FileInputStream( dockerfile ); Logger logger = Logger.getLogger( DockerfileParser.class.getName()); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 )); String line; while((line = br.readLine()) != null) { DockerCommand cmd = DockerCommand.guess(line); if( cmd != null ) result.add( cmd ); else logger.fine("Ignoring unsupported Docker instruction: " + line ); } } finally { Utils.closeQuietly( br ); Utils.closeQuietly( in ); } return result; } }
DockerfileParser { public static List<DockerCommand> dockerfileToCommandList( File dockerfile ) throws IOException { List<DockerCommand> result = new ArrayList<>(); FileInputStream in = new FileInputStream( dockerfile ); Logger logger = Logger.getLogger( DockerfileParser.class.getName()); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 )); String line; while((line = br.readLine()) != null) { DockerCommand cmd = DockerCommand.guess(line); if( cmd != null ) result.add( cmd ); else logger.fine("Ignoring unsupported Docker instruction: " + line ); } } finally { Utils.closeQuietly( br ); Utils.closeQuietly( in ); } return result; } private  DockerfileParser(); }
DockerfileParser { public static List<DockerCommand> dockerfileToCommandList( File dockerfile ) throws IOException { List<DockerCommand> result = new ArrayList<>(); FileInputStream in = new FileInputStream( dockerfile ); Logger logger = Logger.getLogger( DockerfileParser.class.getName()); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 )); String line; while((line = br.readLine()) != null) { DockerCommand cmd = DockerCommand.guess(line); if( cmd != null ) result.add( cmd ); else logger.fine("Ignoring unsupported Docker instruction: " + line ); } } finally { Utils.closeQuietly( br ); Utils.closeQuietly( in ); } return result; } private  DockerfileParser(); static List<DockerCommand> dockerfileToCommandList( File dockerfile ); }
DockerfileParser { public static List<DockerCommand> dockerfileToCommandList( File dockerfile ) throws IOException { List<DockerCommand> result = new ArrayList<>(); FileInputStream in = new FileInputStream( dockerfile ); Logger logger = Logger.getLogger( DockerfileParser.class.getName()); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 )); String line; while((line = br.readLine()) != null) { DockerCommand cmd = DockerCommand.guess(line); if( cmd != null ) result.add( cmd ); else logger.fine("Ignoring unsupported Docker instruction: " + line ); } } finally { Utils.closeQuietly( br ); Utils.closeQuietly( in ); } return result; } private  DockerfileParser(); static List<DockerCommand> dockerfileToCommandList( File dockerfile );  }