@Test public void backupComplexDir() throws IOException { Path dirToBkp = Files.createTempDirectory("dirToBkp4"); Path subDir1 = Files.createTempDirectory(dirToBkp, "subDir1"); Path subDir2 = Files.createTempDirectory(dirToBkp, "subDir2"); Path subDir3 = Files.createTempDirectory(subDir1, "subDir3"); Path parentdirfile1 = createTempFile(dirToBkp, "FILE_1", ".tmp"); Path parentdirfile2 = createTempFile(subDir1, "FILE_2", ".tmp"); Path parentdirfile3 = createTempFile(subDir3, "FILE_3", ".tmp"); new BackupHelper(conf).backupFileOrDir(dirToBkp); Path bkp = PathUtils.get(conf.getBackupDir(), dirToBkp); assertThat(exists(bkp), is(true)); assertThat(exists(PathUtils.get(bkp, parentdirfile1.getFileName())), is(true)); assertThat(exists(PathUtils.get(bkp, subDir1.getFileName())), is(true)); assertThat(exists(PathUtils.get(bkp, subDir2.getFileName())), is(true)); assertThat( exists( PathUtils.get(PathUtils.get(bkp, subDir1.getFileName()), parentdirfile2.getFileName())), is(true)); assertThat( exists(PathUtils.get(PathUtils.get(bkp, subDir1.getFileName()), subDir3.getFileName())), is(true)); assertThat( exists( PathUtils.get( PathUtils.get(PathUtils.get(bkp, subDir1.getFileName()), subDir3.getFileName()), parentdirfile3.getFileName())), is(true)); }
private Toolbox loadToolbox() throws IOException, URISyntaxException { Path foundPath = findToolsDir(); Toolbox box; if (Files.isDirectory(foundPath)) { box = new Toolbox(foundPath); Path tempDir = Files.createTempDirectory(TOOLS_DIR_NAME); Path tempZipFile = tempDir.resolve(TOOLS_ZIP_NAME); dirToZip(foundPath, tempZipFile); byte[] zipContents = Files.readAllBytes(tempZipFile); box.setZipContents(zipContents); Files.delete(tempZipFile); Files.delete(tempDir); } // found tools zip else { FileSystem fs = FileSystems.newFileSystem(foundPath, null); Path toolsPath = fs.getPath(TOOLS_DIR_NAME); box = new Toolbox(toolsPath); byte[] zipContents = Files.readAllBytes(foundPath); box.setZipContents(zipContents); } return box; }
public static void indexTargetPlatform( OutputStream outputStream, List<File> additionalJarFiles, long stopWaitTimeout, String... dirNames) throws Exception { Framework framework = null; Path tempPath = Files.createTempDirectory(null); ClassLoader classLoader = TargetPlatformIndexerUtil.class.getClassLoader(); try (InputStream inputStream = classLoader.getResourceAsStream("META-INF/system.packages.extra.mf")) { Map<String, String> properties = new HashMap<>(); properties.put(Constants.FRAMEWORK_STORAGE, tempPath.toString()); Manifest extraPackagesManifest = new Manifest(inputStream); Attributes attributes = extraPackagesManifest.getMainAttributes(); properties.put( Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, attributes.getValue("Export-Package")); ServiceLoader<FrameworkFactory> serviceLoader = ServiceLoader.load(FrameworkFactory.class); FrameworkFactory frameworkFactory = serviceLoader.iterator().next(); framework = frameworkFactory.newFramework(properties); framework.init(); BundleContext bundleContext = framework.getBundleContext(); Bundle systemBundle = bundleContext.getBundle(0); TargetPlatformIndexer targetPlatformIndexer = new TargetPlatformIndexer(systemBundle, additionalJarFiles, dirNames); targetPlatformIndexer.index(outputStream); } finally { framework.stop(); FrameworkEvent frameworkEvent = framework.waitForStop(stopWaitTimeout); if (frameworkEvent.getType() == FrameworkEvent.WAIT_TIMEDOUT) { throw new Exception( "OSGi framework event " + frameworkEvent + " triggered after a " + stopWaitTimeout + "ms timeout"); } PathUtil.deltree(tempPath); } }
Path genPythonToolkit(String module) throws IOException, InterruptedException { Path pubsub = Paths.get(getTestRoot().getAbsolutePath(), "python", "pubsub"); System.err.println("Pubsub:" + pubsub); Path pyTk = Files.createTempDirectory("pytk").toAbsolutePath(); System.err.println("PKTK:" + pyTk); Path pyPackages = Paths.get(System.getProperty("topology.toolkit.release"), "opt", "python", "packages") .toAbsolutePath(); String pythonversion = System.getProperty("topology.test.python"); ProcessBuilder pb = new ProcessBuilder(pythonversion, module, pyTk.toAbsolutePath().toString()); pb.redirectOutput(Redirect.INHERIT); pb.redirectError(Redirect.INHERIT); Map<String, String> env = pb.environment(); env.put("PYTHONPATH", pyPackages.toString()); pb.directory(pubsub.toFile()); Process proc = pb.start(); assertEquals(0, proc.waitFor()); return pyTk; }
@Test public void modifyingTheContentsOfTheFileChangesTheRuleKey() throws IOException { Path root = Files.createTempDirectory("root"); FakeProjectFilesystem filesystem = new FakeProjectFilesystem(root.toFile()); Path temp = Paths.get("example_file"); FileHashCache hashCache = new DefaultFileHashCache(filesystem); SourcePathResolver resolver = new SourcePathResolver(new BuildRuleResolver()); RuleKeyBuilderFactory ruleKeyFactory = new DefaultRuleKeyBuilderFactory(hashCache, resolver); filesystem.writeContentsToPath("I like cheese", temp); ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//some:file")) .setSrc(new PathSourcePath(filesystem, temp)); ExportFile rule = (ExportFile) builder.build(new BuildRuleResolver(), filesystem); RuleKey original = ruleKeyFactory.newInstance(rule).build(); filesystem.writeContentsToPath("I really like cheese", temp); // Create a new rule. The FileHashCache held by the existing rule will retain a reference to the // previous content of the file, so we need to create an identical rule. rule = (ExportFile) builder.build(new BuildRuleResolver(), filesystem); hashCache = new DefaultFileHashCache(filesystem); resolver = new SourcePathResolver(new BuildRuleResolver()); ruleKeyFactory = new DefaultRuleKeyBuilderFactory(hashCache, resolver); RuleKey refreshed = ruleKeyFactory.newInstance(rule).build(); assertNotEquals(original, refreshed); }
public static List<String> getMavenDependencies(Session session) throws IOException { List<String> dependencies = new ArrayList<>(); File[] files = Maven.resolver() .loadPomFromFile("pom.xml") .importTestDependencies() .resolve() .withoutTransitivity() .asFile(); for (File f : files) { if (f.getName().endsWith("jar") && hasKubernetesJson(f)) { Path dir = Files.createTempDirectory(session.getId()); try (FileInputStream fis = new FileInputStream(f); JarInputStream jis = new JarInputStream(fis)) { Zips.unzip(new FileInputStream(f), dir.toFile()); File jsonPath = dir.resolve(DEFAULT_CONFIG_FILE_NAME).toFile(); if (jsonPath.exists()) { dependencies.add(jsonPath.toURI().toString()); } } } else if (f.getName().endsWith(".json")) { dependencies.add(f.toURI().toString()); } } return dependencies; }
@Before public void SetUp() throws NoSuchAlgorithmException, IOException { mOutput = new ByteArrayOutputStream(2048); Path tempDirectory = Files.createTempDirectory("LFSTest"); mPointer = new LFSFilePointer(tempDirectory.toString(), new File("../testfiles/bigfile.bin")); }
static { try { sTempFolder = Files.createTempDirectory(GdbPlugin.PLUGIN_ID).toString() + '/'; } catch (IOException | IllegalArgumentException | UnsupportedOperationException e) { sTempFolder = System.getProperty("java.io.tmpdir"); // $NON-NLS-1$ } }
/** Creates the temp directory for the help files. */ public void createTempDir() { try { tmp_1 = Files.createTempDirectory(null); Files.createDirectory(Paths.get(tmp_1.toString(), "img")); asFile = tmp_1.toFile(); asFile.deleteOnExit(); filesToTemp("index.html"); filesToTemp("img/bg.png"); filesToTemp("img/bg25.png"); filesToTemp("img/bg50.png"); filesToTemp("img/bg80.png"); filesToTemp("img/buttons.jpg"); filesToTemp("img/team17.png"); filesToTemp("img/main_menu.jpg"); filesToTemp("img/random.jpg"); filesToTemp("img/ready.jpg"); filesToTemp("img/result.jpg"); filesToTemp("img/simulator.jpg"); filesToTemp("img/tokens.jpg"); filesToTemp("img/tourna.jpg"); filesToTemp("img/wait.jpg"); } catch (Exception e) { System.err.println(e); } }
/** * Unpacks a jar file to a temporary directory that will be removed when the VM exits. * * @param jarfilePath the path of the jar to unpack * @return the path of the temporary directory */ private static String explodeJarToTempDir(File jarfilePath) { try { final Path jarfileDir = Files.createTempDirectory(jarfilePath.getName()); Runtime.getRuntime() .addShutdownHook( new Thread() { @Override public void run() { delete(jarfileDir.toFile()); } }); jarfileDir.toFile().deleteOnExit(); JarFile jarfile = new JarFile(jarfilePath); Enumeration<JarEntry> entries = jarfile.entries(); while (entries.hasMoreElements()) { JarEntry e = entries.nextElement(); if (!e.isDirectory()) { File path = new File(jarfileDir.toFile(), e.getName().replace('/', File.separatorChar)); File dir = path.getParentFile(); dir.mkdirs(); assert dir.exists(); Files.copy(jarfile.getInputStream(e), path.toPath()); } } return jarfileDir.toFile().getAbsolutePath(); } catch (IOException e) { throw new AssertionError(e); } }
static { try { tmpDir = Files.createTempDirectory("armeria-test.").toFile(); } catch (Exception e) { throw new Error(e); } final ServerBuilder sb = new ServerBuilder(); try { sb.port(0, SessionProtocol.HTTP); final VirtualHostBuilder defaultVirtualHost = new VirtualHostBuilder(); defaultVirtualHost.serviceUnder( "/fs/", HttpFileService.forFileSystem(tmpDir.toPath()).decorate(LoggingService::new)); defaultVirtualHost.serviceUnder( "/", HttpFileService.forClassPath("/http_file_service").decorate(LoggingService::new)); sb.defaultVirtualHost(defaultVirtualHost.build()); } catch (Exception e) { throw new Error(e); } server = sb.build(); }
@Test public void testFactoryWithTransportClient() throws IOException { // setup client for testing http connection params Path baseDir = Paths.get("target/elasticsearch"); String dataPath = Files.createTempDirectory(baseDir, null).toAbsolutePath().toString(); Settings build = ImmutableSettings.builder().put("path.data", dataPath).build(); Node node = nodeBuilder().settings(build).node(); assertTrue(new ElasticDataStoreFactory().isAvailable()); scanForPlugins(); Map<String, Serializable> map = new HashMap<>(); map.put(ElasticDataStoreFactory.HOSTNAME.key, "localhost"); map.put(ElasticDataStoreFactory.HOSTPORT.key, String.valueOf(9300)); map.put(ElasticDataStoreFactory.INDEX_NAME.key, "sample"); Iterator<DataStoreFactorySpi> ps = getAvailableDataSources(); ElasticDataStoreFactory fac; while (ps.hasNext()) { fac = (ElasticDataStoreFactory) ps.next(); try { if (fac.canProcess(map)) { source = fac.createDataStore(map); } } catch (Throwable t) { LOGGER.log(Level.WARNING, "Could not acquire " + fac.getDescription() + ":" + t, t); } } assertNotNull(source); assertTrue(source instanceof ElasticDataStore); node.close(); }
public static void main(String[] args) { Stopwatch timer = Stopwatch.createStarted(); OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class); optionsParser.parseAndExitUponError(args); Options options = optionsParser.getOptions(Options.class); checkFlags(options); FileSystem fileSystem = FileSystems.getDefault(); Path working = fileSystem.getPath("").toAbsolutePath(); AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(new StdLogger(com.android.utils.StdLogger.Level.VERBOSE)); try { Path resourcesOut = Files.createTempDirectory("tmp-resources"); resourcesOut.toFile().deleteOnExit(); Path assetsOut = Files.createTempDirectory("tmp-assets"); assetsOut.toFile().deleteOnExit(); logger.fine(String.format("Setup finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); ImmutableList<DirectoryModifier> modifiers = ImmutableList.of( new PackedResourceTarExpander(working.resolve("expanded"), working), new FileDeDuplicator( Hashing.murmur3_128(), working.resolve("deduplicated"), working)); MergedAndroidData mergedData = resourceProcessor.mergeData( options.mainData, options.dependencyData, resourcesOut, assetsOut, modifiers, null, options.strictMerge); logger.info(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); writeAar(options.aarOutput, mergedData, options.manifest, options.rtxt, options.classes); logger.info( String.format("Packaging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); } catch (IOException | MergingException e) { logger.log(Level.SEVERE, "Error during merging resources", e); System.exit(1); } System.exit(0); }
static { try { additionalLevelsDirectory = Files.createTempDirectory(Constants.DIRECTORY_ADDITIONAL_LEVELS_PREFIX).toFile(); } catch (IOException e) { e.printStackTrace(); } }
private void createConfig() throws IOException, BadConfigException { String storagePath = Files.createTempDirectory(".xenon").toAbsolutePath().toString(); config = ConfigBuilder.build( CloudStoreConfig.class, CloudStoreServiceGroupTest.class.getResource(configFilePath).getPath()); config.getXenonConfig().setStoragePath(storagePath); }
@Test public void testFileRollover() throws IOException { Path homeDir = Files.createTempDirectory("logger"); Path statusPath = Files.createTempFile("status", "dat"); ProtoLogger p = new ProtoLogger(homeDir.toString()); p.setMaxLogFile(500); for (int i = 0; i < 1000; i++) { p.write("topic-1", ByteString.copyFromUtf8(i + "")); } p.close(); ProtoSpout ps = new ProtoSpout( new ProtoSpout.TupleParser() { @Override public List<Object> parse(ByteString buffer) { return Collections.<Object>singletonList(buffer.toStringUtf8()); } @Override public Fields getOutputFields() { throw new UnsupportedOperationException("Default operation"); } }, statusPath.toFile(), new File(homeDir.toFile(), "topic-1"), Pattern.compile("[0-9a-f]*")); final List<List<Object>> tuples = Lists.newArrayList(); SpoutOutputCollector collector = new SpoutOutputCollector(null) { @Override public List<Integer> emit(List<Object> tuple) { tuples.add(tuple); return null; } @Override public List<Integer> emit(List<Object> tuple, Object messageId) { return emit(tuple); } }; ps.open(null, null, collector); for (int i = 0; i < 1000; i++) { ps.nextTuple(); } assertEquals(1000, tuples.size()); Iterator<List<Object>> ix = tuples.iterator(); for (int i = 0; i < 1000; i++) { List<Object> x = ix.next(); assertEquals(1, x.size()); assertEquals(i + "", x.get(0)); } }
static { Path tempDataDir = null; // create data directory for shell try { tempDataDir = Files.createTempDirectory("VdbBuilderDataDir"); tempDataDir.toFile().deleteOnExit(); System.setProperty(SystemConstants.VDB_BUILDER_DATA_DIR, tempDataDir.toString()); LOGGER.debug("AbstractCommandTest:_shellDataDirectory = {0}", tempDataDir); final Path commandsDir = Paths.get(tempDataDir.toString() + "/commands"); commandsDir.toFile().deleteOnExit(); Files.createDirectory(commandsDir); System.setProperty("komodo.shell.commandsDir", commandsDir.toString()); LOGGER.debug("AbstractCommandTest: commands directory is {0}", commandsDir); { // find relational command provider jar and copy over to commands directory so it can be // discovered final String relativeTargetPath = "target"; final Path targetDir = Paths.get(relativeTargetPath); LOGGER.debug("AbstractCommandTest: Looking for jar here: {0}", targetDir); try (final DirectoryStream<Path> stream = Files.newDirectoryStream(targetDir, "*-with-dependencies.jar")) { final Iterator<Path> itr = stream.iterator(); if (itr.hasNext()) { final Path path = itr.next(); final String pathString = path.toString(); LOGGER.debug("AbstractCommandTest: found jar {0}", pathString); if (itr.hasNext()) { Assert.fail( "*** Found more than one relational command provider jar ***"); //$NON-NLS-1$ } // copy Path filePath = Paths.get(commandsDir.toString() + '/' + path.getFileName()); Files.copy(path, filePath); filePath.toFile().deleteOnExit(); LOGGER.debug( "AbstractCommandTest: copying jar to {0}", (commandsDir.toString() + '/' + path.getFileName())); } else { Assert.fail("*** Failed to find relational command provider jar ***"); // $NON-NLS-1$ } } catch (final IOException e) { Assert.fail("Failed to copy jar to commands directory: " + e.getMessage()); // $NON-NLS-1$ } } } catch (final Exception e) { Assert.fail(e.getLocalizedMessage()); } SHELL_DATA_DIRECTORY = tempDataDir; }
/** * Method to save the selected Experiment, in xml and xls (if possible), in a temporary folder. * The files will be contained inside a zip. * * @return String with the path of the zip file. * @throws IOException */ private String saveExpInTempFolder() throws IOException { String toRet = ""; // Create temporary File String filePath = Files.createTempDirectory("").toString() + "/"; filePath = filePath.replace("\\", "/"); // Get bioID String bioID = selExp.getBioID(); if (bioID.isEmpty()) { bioID = "bio_"; } DataToFile.saveXMLData(selExp, filePath + "xml"); // Only save in XLS if the Experiment is an IntraExperiment if (!isInter) { DataToFile.saveXLSData(selExp, filePath + "xls"); } // Generate ZIP file with Java 7 Map<String, String> zipProperties = new HashMap<>(); zipProperties.put("create", "true"); zipProperties.put("encoding", "UTF-8"); // Create zip file URI zipDisk; toRet = filePath + bioID + ".zip"; if (toRet.startsWith("/")) { zipDisk = URI.create("jar:file:" + toRet); } else { zipDisk = URI.create("jar:file:/" + toRet); } // Adding files to zip try (FileSystem zipfs = FileSystems.newFileSystem(zipDisk, zipProperties)) { // Create file inside zip Path zipFilePath = zipfs.getPath(bioID + ".xml"); // Path where the file to be added resides Path addNewFile = Paths.get(filePath + "xml.xml"); // Append file to ZIP File Files.copy(addNewFile, zipFilePath); if (!isInter) { // Now go for the xls file zipFilePath = zipfs.getPath(bioID + ".xls"); addNewFile = Paths.get(filePath + "xls.xls"); Files.copy(addNewFile, zipFilePath); } } // Delete temp files Files.deleteIfExists(Paths.get(filePath + "xml.xml")); Files.deleteIfExists(Paths.get(filePath + "xls.xls")); return toRet; }
@Test public void backupFile() throws IOException { Path dirToBkp = Files.createTempDirectory("dirToBkp3"); Path parentdirfile1 = createTempFile(dirToBkp, "FILE_1", ".tmp"); new BackupHelper(conf).backupFile(parentdirfile1); Path bkp = PathUtils.get(conf.getBackupDir(), parentdirfile1); assertThat(exists(bkp), is(true)); }
private static Path createTmpDir(List<Path> files) throws IOException { Path tmpDir = Files.createTempDirectory("eligibilityToolTestFileNames"); tmpDir.toFile().deleteOnExit(); for (Path tmpFile : files) { touchTmpFile(tmpDir, tmpFile); } return tmpDir; }
public void testKryoSerializationRoundtrip() throws IOException { Path testDir = Files.createTempDirectory("test"); try { SliceManager sliceManager = new SliceManager(new KryoSliceSerializer(), new FileStorageManager(testDir)); doSerializationRoundtrip("kryo", sliceManager); } finally { FileHelper.delete(testDir.toFile()); } }
public Parameter(FileSystem fileSystem, String root) { this( fileSystem, s -> { try { return Files.createTempDirectory(fileSystem.getPath(root), s); } catch (IOException e) { throw new RuntimeException(e); } }); }
@Test public void testDirNotExist() throws IOException { final File tempDir = Files.createTempDirectory("vold-launch").toFile(); tempDir.delete(); try { launchVold(new String[] {tempDir.getAbsolutePath()}); throw new AssertionError("Not reached"); } catch (final RunCmdErrorException e) { Assert.assertEquals(1, e.getExitValue()); } }
/** When packaged into JAR extracts DLLs, places these into */ private static void loadFromJar() { // put all DLLs to temp dir try { tempPath = Files.createTempDirectory(TEMPDIR, (FileAttribute<?>[]) null); } catch (IOException e) { logger.info("Cannot create temp directory"); } loadLib(JINPUT); loadLib(LWJGL); loadLib(OPENAL); }
/** * Saves byte code to a temporary directory prefixed with "skylarkbytecode" in the system default * temporary directory. */ private void saveByteCode(Unloaded<CompiledFunction> unloadedImplementation) { if (debugCompiler) { try { if (debugFolder == null) { debugFolder = Files.createTempDirectory("skylarkbytecode").toFile(); } unloadedImplementation.saveIn(debugFolder); } catch (IOException e) { throw new RuntimeException(e); } } }
@Test public void testConfigNotExist() throws IOException { final Path tempDirPath = Files.createTempDirectory("vold-launch"); try { final File tempDir = tempDirPath.toFile(); launchVold(new String[] {tempDir.getAbsolutePath()}); throw new AssertionError("Not reached"); } catch (final RunCmdErrorException e) { Assert.assertEquals(2, e.getExitValue()); } finally { com.oodrive.nuage.utils.Files.deleteRecursive(tempDirPath); } }
private static void startXmlRpcWorkflowManager() { System.setProperty( "java.util.logging.config.file", new File("./src/main/resources/logging.properties").getAbsolutePath()); try { System.getProperties().load(new FileInputStream("./src/main/resources/workflow.properties")); } catch (Exception e) { fail(e.getMessage()); } try { luceneCatLoc = Files.createTempDirectory("repo").toString(); LOG.log(Level.INFO, "Lucene instance repository: [" + luceneCatLoc + "]"); } catch (Exception e) { fail(e.getMessage()); } if (new File(luceneCatLoc).exists()) { // blow away lucene cat LOG.log(Level.INFO, "Removing workflow instance repository: [" + luceneCatLoc + "]"); try { FileUtils.deleteDirectory(new File(luceneCatLoc)); } catch (IOException e) { fail(e.getMessage()); } } System.setProperty( "workflow.engine.instanceRep.factory", "org.apache.oodt.cas.workflow.instrepo.LuceneWorkflowInstanceRepositoryFactory"); System.setProperty("org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath", luceneCatLoc); try { System.setProperty( "org.apache.oodt.cas.workflow.repo.dirs", "file://" + new File("./src/main/resources/examples").getCanonicalPath()); System.setProperty( "org.apache.oodt.cas.workflow.lifecycle.filePath", new File("./src/main/resources/examples/workflow-lifecycle.xml").getCanonicalPath()); } catch (Exception e) { fail(e.getMessage()); } try { wmgr = new XmlRpcWorkflowManager(WM_PORT); Thread.sleep(MILLIS); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); fail(e.getMessage()); } }
@Test public void notExistingBackupDir() throws Exception { Path dirToBkp = Files.createTempDirectory("dirToBkp2"); Path parentdirfile1 = createTempFile(dirToBkp, "FILE_1", ".tmp"); Path parentdirfile2 = createTempFile(dirToBkp, "FILE_2", ".tmp"); new BackupHelper(conf).backupFileOrDir(dirToBkp); Path bkp = PathUtils.get(conf.getBackupDir(), dirToBkp); assertThat(exists(bkp), is(true)); assertThat(exists(PathUtils.get(bkp, parentdirfile1.getFileName())), is(true)); assertThat(exists(PathUtils.get(bkp, parentdirfile2.getFileName())), is(true)); }
/* * For running the tests we have to copy the * files under RSC to a work directory, as the the HL7 importer moves the * incoming files to files containing a timestamp * * @author: Niklaus Giger * @return: The path of the temp directory */ static Path copyRscToTempDirectory() { Path path = null; try { path = Files.createTempDirectory("HL7_Test"); File src = new File(PlatformHelper.getBasePath("ch.elexis.core.ui.importer.div.tests"), "rsc"); System.out.println("src: " + src.toString()); FileUtils.copyDirectory(src, path.toFile()); } catch (IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } return path; }
@Override public ResourceMap generateOutputs(Map<String, List<Object>> parameters, IProgressMonitor monitor) throws Exception { File workingDir = null; File gitDir = null; // Get existing checkout if available synchronized (this) { if (checkedOut != null) { workingDir = checkedOut.getWorkTree(); gitDir = new File(workingDir, ".git"); } } if (workingDir == null) { // Need to do a new checkout workingDir = Files.createTempDirectory("checkout").toFile(); gitDir = new File(workingDir, ".git"); String branch = params.branch != null ? params.branch : GitCloneTemplateParams.DEFAULT_BRANCH; try { CloneCommand cloneCmd = Git.cloneRepository() .setURI(params.cloneUrl) .setDirectory(workingDir) .setNoCheckout(true); cloneCmd.setProgressMonitor(new EclipseGitProgressTransformer(monitor)); cloneCmd.setBranchesToClone(Collections.singleton(branch)); Git git = cloneCmd.call(); git.checkout().setCreateBranch(true).setName("_tmp").setStartPoint(branch).call(); checkedOut = git.getRepository(); } catch (JGitInternalException e) { Throwable cause = e.getCause(); if (cause instanceof Exception) throw (Exception) cause; throw e; } } final File exclude = gitDir; FileFilter filter = new FileFilter() { @Override public boolean accept(File path) { return !path.equals(exclude); } }; return toResourceMap(workingDir, filter); }