/** * Runs the compiler on the filename specified as a command-line argument. * * @param args The first argument should be a filename relative to the working directory. */ public static void main(String[] args) { Compilation compilation = null; try { FileReader myFile = new FileReader(args[0]); compilation = new Compilation(new File(args[0])); /* InputStream in = new SequenceInputStream(...); BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8")); */ CompilerLexer myLex = new CompilerLexer(myFile); myLex.compilation = compilation; CompilerParser myParser = new CompilerParser(myLex); myParser.compilation = compilation; try { myParser.parse(); System.out.println("Errors: " + compilation.errorMessages.size()); for (String message : compilation.errorMessages) { System.out.println(" " + message); } if (compilation.abstractSyntaxTree != null) { System.out.println(compilation.abstractSyntaxTree.toString()); } if (!compilation.errorTriggered) { Executable executable = new Executable(compilation); System.out.println("Intermediate code was generated: "); System.out.println("---------------------------------"); System.out.println(executable.toString()); System.out.println("---------------------------------"); System.out.println("Assembler code was generated:"); System.out.println("------------------------------"); String assemblerCode = executable.toMipsAssembler(); String[] lines = assemblerCode.split("\n"); for (int i = 0; i < lines.length; i++) { System.out.println((i + 1) + ": " + lines[i]); } System.out.println("------------------------------"); java.nio.file.Files.write(Paths.get(args[1]), assemblerCode.getBytes()); System.out.println("Assembler written to file '" + Paths.get(args[1]) + "'."); } } catch (Error t) { System.out.println("Error: " + t + "\n"); t.printStackTrace(); } } catch (Exception e) { System.out.println("Exception: " + e); if (compilation != null) { System.out.println("Errors: " + compilation.errorMessages.size()); for (String message : compilation.errorMessages) { System.out.println(" " + message); } } e.printStackTrace(); } catch (Error e) { System.out.println("Unexpected error."); } }
@Test public void testUncompress_withSymbolicLinks() throws IOException, ArchiveException { final File inputFile = new File(inputUrl.getPath(), "tarLink.tar.gz"); final File temporaryDirectory = Files.createTempDir(); temporaryDirectory.deleteOnExit(); final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory); final File file1 = new File(temporaryDirectory, "file1.txt"); final File file2 = new File(temporaryDirectory, "file1_link.txt"); assertTrue(file1.exists()); assertTrue(file2.exists()); assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1))); assertEquals("file1content", new String(FileUtils.readFileToByteArray(file2))); assertTrue(java.nio.file.Files.isSymbolicLink(Paths.get(file2.getPath()))); }