/** * Localizes resources to the given local directory. For resources on the local directory already, a symlink will be * created. Otherwise, it will be copied. * * @param resources the set of resources that need to be localized. * @param targetDir the target directory for the resources to copy / link to. */ private void copyUserResources(Map<String, LocalizeResource> resources, File targetDir) throws IOException { for (Map.Entry<String, LocalizeResource> entry : resources.entrySet()) { LocalizationUtils.localizeResource(entry.getKey(), entry.getValue(), targetDir); } }
/** * Localizes resources to the given local directory. For resources on the local directory already, a symlink will be * created. Otherwise, it will be copied. * * @param resources the set of resources that need to be localized. * @param targetDir the target directory for the resources to copy / link to. */ private void copyUserResources(Map<String, LocalizeResource> resources, File targetDir) throws IOException { for (Map.Entry<String, LocalizeResource> entry : resources.entrySet()) { LocalizationUtils.localizeResource(entry.getKey(), entry.getValue(), targetDir); } }
/** * Localizes resources to the given local directory. For resources on the local directory already, a symlink will be * created. Otherwise, it will be copied. * * @param resources the set of resources that need to be localized. * @param targetDir the target directory for the resources to copy / link to. */ private void copyUserResources(Map<String, LocalizeResource> resources, File targetDir) throws IOException { for (Map.Entry<String, LocalizeResource> entry : resources.entrySet()) { LocalizationUtils.localizeResource(entry.getKey(), entry.getValue(), targetDir); } }
LocalizationUtils.localizeResource(entry.getKey(), entry.getValue(), targetDir).getAbsolutePath(); } else { URI uri = entry.getValue().getURI();
LocalizationUtils.localizeResource(entry.getKey(), entry.getValue(), targetDir).getAbsolutePath(); } else { URI uri = entry.getValue().getURI();
@Test public void testZip() throws IOException { String zipFileName = "target"; File directory = TEMP_FOLDER.newFolder("zip"); File file1 = File.createTempFile("file1", ".txt", directory); File file2 = File.createTempFile("file2", ".txt", directory); File zipFile = createZipFile(zipFileName, directory, false); File localizationDir = TEMP_FOLDER.newFolder("localZip"); File localizedResource = LocalizationUtils.localizeResource(zipFileName, new LocalizeResource(zipFile, true), localizationDir); Assert.assertTrue(localizedResource.isDirectory()); File[] files = localizedResource.listFiles(); Assert.assertNotNull(files); Assert.assertEquals(2, files.length); if (file1.getName().equals(files[0].getName())) { Assert.assertEquals(file2.getName(), files[1].getName()); } else { Assert.assertEquals(file1.getName(), files[1].getName()); Assert.assertEquals(file2.getName(), files[0].getName()); } }
@Test public void testJar() throws IOException { String jarFileName = "target"; File directory = TEMP_FOLDER.newFolder("jar"); File libDir = new File(directory, "lib"); Assert.assertTrue(libDir.mkdirs()); File someClassFile = File.createTempFile("SomeClass", ".class", directory); File someOtherClassFile = File.createTempFile("SomeOtherClass", ".class", directory); File jarFile = createZipFile(jarFileName, directory, true); File localizationDir = TEMP_FOLDER.newFolder("localJar"); File localizedResource = LocalizationUtils.localizeResource(jarFileName, new LocalizeResource(jarFile, true), localizationDir); Assert.assertTrue(localizedResource.isDirectory()); File[] files = localizedResource.listFiles(); Assert.assertNotNull(files); Assert.assertEquals(3, files.length); for (File file : files) { String name = file.getName(); if (libDir.getName().equals(name)) { Assert.assertTrue(file.isDirectory()); } else { Assert.assertTrue(someClassFile.getName().equals(name) || someOtherClassFile.getName().equals(name)); } } }
@Test(expected = IllegalArgumentException.class) public void testGz() throws IOException { String gzFileName = "target"; File directory = TEMP_FOLDER.newFolder("gz"); File source = File.createTempFile("source", ".txt", directory); File gzFile = createGzFile(gzFileName, source); File localizationDir = TEMP_FOLDER.newFolder("localGz"); LocalizationUtils.localizeResource(gzFileName, new LocalizeResource(gzFile, true), localizationDir); }
throw new IllegalArgumentException("Unexpected type: " + type); File localizedResource = LocalizationUtils.localizeResource(tarFileName, new LocalizeResource(tarFile, true), localizationDir); Assert.assertTrue(localizedResource.isDirectory());
@Test public void testRemoteFile() throws IOException { File directory = TEMP_FOLDER.newFolder("ftp"); File ftpFile = new File(directory, "ftp_file"); String ftpFileContents = "Contents of ftp_file"; FileSystem fileSystem = new UnixFakeFileSystem(); fileSystem.add(new FileEntry(ftpFile.getAbsolutePath(), ftpFileContents)); String user = "user"; String password = "password"; FakeFtpServer ftpServer = new FakeFtpServer(); // Use any available port ftpServer.setServerControlPort(0); ftpServer.addUserAccount(new UserAccount(user, password, directory.getAbsolutePath())); ftpServer.setFileSystem(fileSystem); ftpServer.start(); try { URI uri = URI.create(String.format("ftp://%s:%s@localhost:%d/%s", user, password, ftpServer.getServerControlPort(), ftpFile.getName())); File localizationDir = TEMP_FOLDER.newFolder("localRemote"); File localizedResource = LocalizationUtils.localizeResource("file1", new LocalizeResource(uri, false), localizationDir); Assert.assertTrue(localizedResource.exists()); Assert.assertTrue(localizedResource.isFile()); Assert.assertEquals(ftpFileContents, com.google.common.io.Files.toString(localizedResource, Charsets.UTF_8)); } finally { ftpServer.stop(); } }