List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:ddf.security.pdp.realm.xacml.processor.XacmlClientTest.java
@Test(expected = IllegalStateException.class) public void testIllegalStateException() throws Exception { LOGGER.debug("\n\n\n##### testExecption"); File policyDir = folder.newFolder("tempDir"); // Perform Test XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), null); File srcFile = new File( projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE); FileUtils.copyFileToDirectory(srcFile, policyDir); RequestType xacmlRequestType = new RequestType(); xacmlRequestType.setCombinedDecision(false); xacmlRequestType.setReturnPolicyIdList(false); AttributesType actionAttributes = new AttributesType(); actionAttributes.setCategory(ACTION_CATEGORY); AttributeType actionAttribute = new AttributeType(); actionAttribute.setAttributeId(ACTION_ID); actionAttribute.setIncludeInResult(false); AttributeValueType actionValue = new AttributeValueType(); actionValue.setDataType(STRING_DATA_TYPE); actionValue.getContent().add(QUERY_ACTION); actionAttribute.getAttributeValue().add(actionValue); actionAttributes.getAttribute().add(actionAttribute); AttributesType subjectAttributes = new AttributesType(); subjectAttributes.setCategory(SUBJECT_CATEGORY); AttributeType subjectAttribute = new AttributeType(); subjectAttribute.setAttributeId(SUBJECT_ID); subjectAttribute.setIncludeInResult(false); AttributeValueType subjectValue = new AttributeValueType(); subjectValue.setDataType(STRING_DATA_TYPE); subjectValue.getContent().add(TEST_USER_1); subjectAttribute.getAttributeValue().add(subjectValue); subjectAttributes.getAttribute().add(subjectAttribute); AttributeType roleAttribute = new AttributeType(); roleAttribute.setAttributeId(ROLE_CLAIM); roleAttribute.setIncludeInResult(false); AttributeValueType roleValue = new AttributeValueType(); roleValue.setDataType(STRING_DATA_TYPE); roleValue.getContent().add(ROLE);/*w ww . j a va 2 s . c om*/ roleAttribute.getAttributeValue().add(roleValue); subjectAttributes.getAttribute().add(roleAttribute); AttributesType categoryAttributes = new AttributesType(); categoryAttributes.setCategory(PERMISSIONS_CATEGORY); AttributeType citizenshipAttribute = new AttributeType(); citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE); citizenshipAttribute.setIncludeInResult(false); AttributeValueType citizenshipValue = new AttributeValueType(); citizenshipValue.setDataType(STRING_DATA_TYPE); citizenshipValue.getContent().add(US_COUNTRY); citizenshipAttribute.getAttributeValue().add(citizenshipValue); categoryAttributes.getAttribute().add(citizenshipAttribute); xacmlRequestType.getAttributes().add(actionAttributes); xacmlRequestType.getAttributes().add(subjectAttributes); xacmlRequestType.getAttributes().add(categoryAttributes); // Perform Test pdp.evaluate(xacmlRequestType); }
From source file:ddf.security.pdp.realm.xacml.processor.BalanaClientTest.java
@Test(expected = IllegalStateException.class) public void testIllegalStateException() throws Exception { LOGGER.debug("\n\n\n##### testExecption"); File policyDir = folder.newFolder("tempDir"); // Perform Test BalanaClient pdp = new BalanaClient(policyDir.getCanonicalPath(), null); File srcFile = new File( projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE); FileUtils.copyFileToDirectory(srcFile, policyDir); RequestType xacmlRequestType = new RequestType(); xacmlRequestType.setCombinedDecision(false); xacmlRequestType.setReturnPolicyIdList(false); AttributesType actionAttributes = new AttributesType(); actionAttributes.setCategory(ACTION_CATEGORY); AttributeType actionAttribute = new AttributeType(); actionAttribute.setAttributeId(ACTION_ID); actionAttribute.setIncludeInResult(false); AttributeValueType actionValue = new AttributeValueType(); actionValue.setDataType(STRING_DATA_TYPE); actionValue.getContent().add(QUERY_ACTION); actionAttribute.getAttributeValue().add(actionValue); actionAttributes.getAttribute().add(actionAttribute); AttributesType subjectAttributes = new AttributesType(); subjectAttributes.setCategory(SUBJECT_CATEGORY); AttributeType subjectAttribute = new AttributeType(); subjectAttribute.setAttributeId(SUBJECT_ID); subjectAttribute.setIncludeInResult(false); AttributeValueType subjectValue = new AttributeValueType(); subjectValue.setDataType(STRING_DATA_TYPE); subjectValue.getContent().add(TEST_USER_1); subjectAttribute.getAttributeValue().add(subjectValue); subjectAttributes.getAttribute().add(subjectAttribute); AttributeType roleAttribute = new AttributeType(); roleAttribute.setAttributeId(ROLE_CLAIM); roleAttribute.setIncludeInResult(false); AttributeValueType roleValue = new AttributeValueType(); roleValue.setDataType(STRING_DATA_TYPE); roleValue.getContent().add(ROLE);//from www. j a v a2 s . co m roleAttribute.getAttributeValue().add(roleValue); subjectAttributes.getAttribute().add(roleAttribute); AttributesType categoryAttributes = new AttributesType(); categoryAttributes.setCategory(PERMISSIONS_CATEGORY); AttributeType citizenshipAttribute = new AttributeType(); citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE); citizenshipAttribute.setIncludeInResult(false); AttributeValueType citizenshipValue = new AttributeValueType(); citizenshipValue.setDataType(STRING_DATA_TYPE); citizenshipValue.getContent().add(US_COUNTRY); citizenshipAttribute.getAttributeValue().add(citizenshipValue); categoryAttributes.getAttribute().add(citizenshipAttribute); xacmlRequestType.getAttributes().add(actionAttributes); xacmlRequestType.getAttributes().add(subjectAttributes); xacmlRequestType.getAttributes().add(categoryAttributes); // Perform Test pdp.evaluate(xacmlRequestType); }
From source file:com.genericworkflownodes.knime.nodegeneration.NodeGenerator.java
/** * Copies the java sources needed to invoke a tool (described by a * {@link CTDFile}) to the specified {@link NodesBuildKnimeNodesDirectory}. * /*from ww w . j ava 2s.co m*/ * @param ctdFile * which described the wrapped tool * @param iconsDir * location where node icons reside * @param nodesDir * location where to create a sub directory containing the * generated sources * @param pluginMeta * meta information used to adapt the java files * @return the fully qualified name of the NodeFactory class able to build * instances of the node. * @throws IOException * @throws UnknownMimeTypeException */ public String copyNodeSources(CTDFile ctdFile) throws IOException, UnknownMimeTypeException { INodeConfiguration nodeConfiguration = ctdFile.getNodeConfiguration(); String nodeName = Utils.fixKNIMENodeName(nodeConfiguration.getName()); File nodeSourceDir = new File(pluginBuildDir.getKnimeNodesDirectory(), nodeName); nodeSourceDir.mkdirs(); File nodeIcon = srcDir.getIconsDirectory().getNodeIcon(nodeConfiguration); if (nodeIcon != null) { FileUtils.copyFileToDirectory(nodeIcon, nodeSourceDir); } else { // use generic icon copyAsset("generic_node.png", nodeSourceDir.getAbsolutePath()); nodeIcon = new File(nodeSourceDir, "generic_node.png"); } /* * all files placed into src/[PACKAGE]/knime/nodes/[NODE_NAME] */ new NodeDialogTemplate(generatedPluginMeta.getPackageRoot(), nodeName) .write(new File(nodeSourceDir, nodeName + "NodeDialog.java")); new NodeModelTemplate(generatedPluginMeta.getPackageRoot(), nodeName, nodeConfiguration) .write(new File(nodeSourceDir, nodeName + "NodeModel.java")); new NodeFactoryXMLTemplate(nodeName, nodeConfiguration, nodeIcon.getName()) .write(new File(nodeSourceDir, nodeName + "NodeFactory.xml")); new NodeFactoryTemplate(generatedPluginMeta.getPackageRoot(), nodeName) .write(new File(nodeSourceDir, nodeName + "NodeFactory.java")); File nodeConfigDir = new File(nodeSourceDir, "config"); nodeConfigDir.mkdirs(); /* * all files placed into src/[PACKAGE]/knime/nodes/[NODE_NAME]/config */ FileUtils.copyFile(ctdFile, new File(nodeConfigDir, "config.xml")); return generatedPluginMeta.getPackageRoot() + ".knime.nodes." + nodeName + "." + nodeName + "NodeFactory"; }
From source file:com.bladecoder.engineeditor.ui.PackageDialog.java
private String genDesktopJar(String projectName, String versionParam, String jarDir, String jarName) throws IOException { String msg = null;/* w ww.j a v a 2s. c o m*/ if (RunProccess.runGradle(Ctx.project.getProjectDir(), versionParam + "desktop:dist")) { File f = new File(jarDir + jarName); FileUtils.copyFileToDirectory(f, new File(dir.getText())); new File(jarDir, jarName).setExecutable(true); new File(dir.getText(), jarName).setExecutable(true); } else { msg = "Error Generating package"; } return msg; }
From source file:com.boundlessgeo.geoserver.bundle.BundleExporter.java
void persist(StyleInfo s) throws IOException { // grab the stylsheet File styleFile = sourceDataDir.style(s).file(); // if the style is global, convert it to a workpace local one if (s.getWorkspace() == null) { s = convertToWorkspaceLocal(s);//from w w w. j av a2 s.c om } File dir = exportDataDir.get(s).dir(); dir.mkdirs(); persist(s, exportDataDir.config(s).file()); FileUtils.copyFileToDirectory(styleFile, dir); //TODO: grab all of the icons }
From source file:com.aliyun.odps.local.common.WareHouse.java
/** * copy resource from warehouse/__resources__/ to temp/resource/ * * @param projName// w w w. j a va 2 s . c om * @param resourceName * @param resourceRootDir * @param limitDownloadRecordCount * @param inputColumnSeperator * @throws IOException * @throws OdpsException */ public void copyResource(String projName, String resourceName, File resourceRootDir, int limitDownloadRecordCount, char inputColumnSeperator) throws IOException, OdpsException { if (StringUtils.isBlank(projName) || StringUtils.isBlank(resourceName) || resourceRootDir == null) { return; } if (!resourceRootDir.exists()) { resourceRootDir.mkdirs(); } LOG.info("Start to copy resource: " + projName + "." + resourceName + "-->" + resourceRootDir.getAbsolutePath()); if (!existsResource(projName, resourceName)) { DownloadUtils.downloadResource(getOdps(), projName, resourceName, limitDownloadRecordCount, inputColumnSeperator); } File file = getReourceFile(projName, resourceName); // table resource if (file.isDirectory()) { File tableResourceDir = new File(resourceRootDir, resourceName); TableInfo refTableInfo = getReferencedTable(projName, resourceName); LinkedHashMap<String, String> partitions = refTableInfo.getPartSpec(); if (partitions != null && partitions.size() > 0) { PartitionSpec partSpec = new PartitionSpec(); for (String key : partitions.keySet()) { partSpec.set(key, partitions.get(key)); } copyTable(refTableInfo.getProjectName(), refTableInfo.getTableName(), partSpec, null, tableResourceDir, limitDownloadRecordCount, inputColumnSeperator); } else { copyTable(refTableInfo.getProjectName(), refTableInfo.getTableName(), null, null, tableResourceDir, limitDownloadRecordCount, inputColumnSeperator); } } else { // not table resource if (!existsResource(projName, resourceName)) { DownloadUtils.downloadResource(getOdps(), projName, resourceName, limitDownloadRecordCount, inputColumnSeperator); } FileUtils.copyFileToDirectory(file, resourceRootDir); } LOG.info("Finished copy resource: " + projName + "." + resourceName + "-->" + resourceRootDir.getAbsolutePath()); }
From source file:com.edgenius.wiki.service.impl.ExportServiceImpl.java
/** * @param cannoicalDir/* ww w .j a va 2 s . c om*/ * @param subdir * @param list * @param skinPath */ private void exportResources(String cannoicalDir, File subdir, Map<File, String> list, String skinPath) { try { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Styles File styleDir = new File(FileUtil.getFullPath(subdir.getPath(), "skins", skinPath, "styles")); if (!styleDir.exists()) styleDir.mkdirs(); //export render.css and print.css to export_files directory String path = FileUtil.getFullPath(Global.ServerInstallRealPath, "skins", skinPath, "/styles/render.css"); FileUtils.copyFileToDirectory(new File(path), styleDir); path = FileUtil.getFullPath(Global.ServerInstallRealPath, "skins", skinPath, "/styles/print.css"); FileUtils.copyFileToDirectory(new File(path), styleDir); list.put(styleDir, cannoicalDir); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // render resources, most for images etc. File renderResourceSrc = new File( FileUtil.getFullPath(Global.ServerInstallRealPath, "skins", skinPath, "render")); File renderResourceTgt = new File(FileUtil.getFullPath(subdir.getPath(), "skins", skinPath, "render")); if (!renderResourceTgt.exists()) renderResourceTgt.mkdirs(); FileUtils.copyDirectory(renderResourceSrc, renderResourceTgt); list.put(renderResourceTgt, cannoicalDir); Map<File, String> pluginResources = pluginService.getPluginResourceForExport(); if (pluginResources != null && pluginResources.size() > 0) { //We don't directory zip the file, as we need to add them under "export_files/" directory //so we copy them first, then zip for (Entry<File, String> entry : pluginResources.entrySet()) { File src = entry.getKey(); File tgt = new File(subdir.getPath(), entry.getValue()); if (!tgt.exists()) tgt.mkdirs(); if (src.isDirectory()) { FileUtils.copyDirectory(src, tgt); } else { FileUtils.copyFileToDirectory(src, tgt); } list.put(tgt, cannoicalDir); } } } catch (Exception e) { AuditLogger.error("Copy render resources failed for export with server install path:" + Global.ServerInstallRealPath, e); } }
From source file:es.bsc.servicess.ide.editors.deployers.LocalhostDeployer.java
private void deployWarDeps(List<Dependency> deps, String packageName, IFolder packageFolder, File ceDir, IProgressMonitor monitor) throws Exception { // TODO Auto-generated method stub for (Dependency d : deps) { log.debug("Analizing dependency " + d.getLocation() + " (Type: " + d.getType() + ")"); if (d.getType().equalsIgnoreCase(ProjectMetadata.WAR_DEP_TYPE)) { if (d.isImported()) { IFile properties = packageFolder.getFile("it.properties"); IFile war = packageFolder.getFolder(ProjectMetadata.EXTERNAL_PACKS_FOLDER) .getFolder(packageName) .getFile(PackagingUtils.getPackageNameWithExtension(d.getLocation())); PackagingUtils.addRuntimeConfigTojar(war, properties.getLocation().toFile(), packageFolder, PackagingUtils.WAR_CLASSES_PATH, monitor); File srcFile = war.getLocation().toFile(); File f = new File(ceDir.getAbsolutePath() + File.separator + packageName + ".war"); File dir = new File(ceDir.getAbsolutePath() + File.separator + packageName); if (f.exists()) { f.delete();// w ww . j av a2s. c o m } if (dir.exists()) { PackagingUtils.deleteDirectory(dir); } FileUtils.copyFileToDirectory(srcFile, ceDir); } else FileUtils.copyFileToDirectory(new File(d.getLocation()), ceDir); } } }
From source file:com.aliyun.odps.local.common.WareHouse.java
/** * copy output data files from job directory to warehouse * * @param srcDir/* w w w .j a v a 2 s . c o m*/ * @param indexes * @param destDir * @throws IOException */ public void copyDataFiles(File srcDir, List<Integer> indexes, File destDir, char inputColumnSeperator) throws IOException { if (indexes == null || indexes.isEmpty()) { for (File file : LocalRunUtils.listDataFiles(srcDir)) { FileUtils.copyFileToDirectory(file, destDir); } } else { for (File file : LocalRunUtils.listDataFiles(srcDir)) { CsvReader reader = DownloadUtils.newCsvReader(file.getAbsolutePath(), inputColumnSeperator, encoding); CsvWriter writer = new CsvWriter(new File(destDir, file.getName()).getAbsolutePath(), inputColumnSeperator, encoding); while (reader.readRecord()) { String[] vals = reader.getValues(); String[] newVals = new String[indexes.size()]; for (int i = 0; i < indexes.size(); ++i) { newVals[i] = vals[indexes.get(i)]; } writer.writeRecord(newVals); } writer.close(); reader.close(); } } }
From source file:com.alcatel_lucent.nz.wnmsextract.reader.FileUtilities.java
public boolean copyFile(File in, File out, boolean filesOnly) { if (in.isDirectory()) { try {//from w w w. j av a2s.co m if (filesOnly) { String[] params = { "zip", "gz" }; for (Object obj : FileUtils.listFiles(in, params, true)) { File x = (File) obj; if (x.getName().endsWith(".zip")) { decompressZip(x, out); } FileUtils.copyFileToDirectory(x, out); } } else { FileUtils.copyDirectory(in, out); } } catch (IOException e) { jlog.fatal("Failed to copy directory: " + in.getAbsolutePath()); return false; } } else { try { FileUtils.copyFile(in, out); } catch (IOException e) { jlog.fatal("Failed to copy file: " + in.getAbsolutePath()); return false; } } return true; }