List of usage examples for org.apache.commons.vfs2 FileSystemException getMessage
@Override
public String getMessage()
From source file:org.cloudifysource.esc.installer.filetransfer.VfsFileTransfer.java
@Override public void copyFiles(final InstallationDetails details, final Set<String> excludedFiles, final List<File> additionalFiles, final long endTimeMillis) throws TimeoutException, InstallerException { logger.fine("Copying files to: " + host + " from local dir: " + localDir.getName().getPath() + " excluding " + excludedFiles.toString()); try {/* www .ja v a2 s . c o m*/ if (remoteDir.exists()) { FileType type = remoteDir.getType(); if (!type.equals(FileType.FOLDER)) { throw new InstallerException("The remote location: " + remoteDir.getName().getFriendlyURI() + " exists but is not a directory"); } if (deleteRemoteDirectoryContents) { logger.info("Deleting contents of remote directory: " + remoteDir.getName().getFriendlyURI()); remoteDir.delete(new FileDepthSelector(1, Integer.MAX_VALUE)); } FileObject[] children = remoteDir.getChildren(); if (children.length > 0) { throw new InstallerException( "The remote directory: " + remoteDir.getName().getFriendlyURI() + " is not empty"); } } remoteDir.copyFrom(localDir, new FileSelector() { @Override public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { if (excludedFiles.contains(fileInfo.getFile().getName().getBaseName())) { logger.fine(fileInfo.getFile().getName().getBaseName() + " excluded"); return false; } final FileObject remoteFile = fileSystemManager.resolveFile(remoteDir, localDir.getName().getRelativeName(fileInfo.getFile().getName())); if (!remoteFile.exists()) { logger.fine(fileInfo.getFile().getName().getBaseName() + " missing on server"); return true; } if (fileInfo.getFile().getType() == FileType.FILE) { final long remoteSize = remoteFile.getContent().getSize(); final long localSize = fileInfo.getFile().getContent().getSize(); final boolean res = localSize != remoteSize; if (res) { logger.fine(fileInfo.getFile().getName().getBaseName() + " different on server"); } return res; } return false; } @Override public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception { return true; } }); for (final File file : additionalFiles) { logger.fine("copying file: " + file.getAbsolutePath() + " to remote directory"); final FileObject fileObject = fileSystemManager.resolveFile("file:" + file.getAbsolutePath()); final FileObject remoteFile = remoteDir.resolveFile(file.getName()); remoteFile.copyFrom(fileObject, new AllFileSelector()); } logger.fine("Copying files to: " + host + " completed."); } catch (final FileSystemException e) { throw new InstallerException("Failed to copy files to remote host " + host + ": " + e.getMessage(), e); } checkTimeout(endTimeMillis); }
From source file:org.cloudifysource.esc.installer.filetransfer.VfsFileTransfer.java
@Override public void initialize(final InstallationDetails details, final long endTimeMillis) throws TimeoutException, InstallerException { this.installerConfiguration = details.getInstallerConfiguration(); this.deleteRemoteDirectoryContents = details.isDeleteRemoteDirectoryContents(); if (details.isConnectedToPrivateIp()) { host = details.getPrivateIp();//from w ww . java 2 s. co m } else { host = details.getPublicIp(); } checkTimeout(endTimeMillis); initVFSManager(details, endTimeMillis); createTargetURI(details); final FileSystemManager mng = fileSystemManager; mng.setLogger(org.apache.commons.logging.LogFactory.getLog(logger.getName())); // when bootstrapping a management machine, pass all of the cloud // configuration, including all template // for an agent machine, just pass the upload dir fot the specific // template. String localDirPath = details.getLocalDir(); if (details.isManagement()) { if (details.getCloudFile() == null) { throw new IllegalArgumentException("While bootstrapping a management machine, cloud file is null"); } localDirPath = details.getCloudFile().getParentFile().getAbsolutePath(); } try { localDir = mng.resolveFile("file:" + localDirPath); remoteDir = resolveTargetDirectory(opts, targetURI, mng); } catch (final FileSystemException e) { throw new InstallerException("Failed to set up file transfer: " + e.getMessage(), e); } }
From source file:org.codehaus.mojo.vfs.internal.DefaultMergeVfsMavenRepositories.java
private void mergeTargetMetadataToStageMetaData(FileObject targetRepo, FileObject stagingRepo) throws IOException, XmlPullParserException { VfsFileSet fileset = new VfsFileSet(); fileset.setSource(stagingRepo);/* w w w . j ava 2 s . c om*/ String[] includes = { "**/" + MAVEN_METADATA }; fileset.setIncludes(includes); VfsFileSetManager fileSetManager = new DefaultVfsFileSetManager(); List<FileObject> targetMetaFileObjects = fileSetManager.list(fileset); // Merge all metadata files for (FileObject sourceMetaFileObject : targetMetaFileObjects) { String relativeMetaPath = VfsUtils.getRelativePath(stagingRepo, sourceMetaFileObject); FileObject targetMetaFile = targetRepo.resolveFile(relativeMetaPath); FileObject stagingTargetMetaFileObject = stagingRepo.resolveFile(relativeMetaPath + IN_PROCESS_MARKER); try { stagingTargetMetaFileObject.copyFrom(targetMetaFile, Selectors.SELECT_ALL); } catch (FileSystemException e) { // We don't have an equivalent on the targetRepositoryUrl side because we have something // new on the sourceRepositoryUrl side so just skip the metadata merging. continue; } try { File targetMetaData = new File(stagingTargetMetaFileObject.getName().getPath()); File sourceMetaData = new File(sourceMetaFileObject.getName().getPath()); MavenMetadataUtils mavenMetadataUtils = new MavenMetadataUtils(); mavenMetadataUtils.merge(targetMetaData, sourceMetaData); targetMetaData.delete(); } catch (XmlPullParserException e) { throw new IOException( "Metadata file is corrupt " + sourceMetaFileObject + " Reason: " + e.getMessage()); } } }
From source file:org.datacleaner.windows.OpenAnalysisJobAsTemplateDialogTest.java
private OpenAnalysisJobAsTemplateDialog getDialog() { if (_dialog == null) { try {//from w ww.j a v a 2 s. c o m final WindowContext windowContext = new SimpleWindowContext(); final Datastore datastore = TestHelper.createSampleDatabaseDatastore("orderdb"); final DatastoreCatalog datastoreCatalog = new DatastoreCatalogImpl(datastore); final SimpleDescriptorProvider descriptorProvider = new SimpleDescriptorProvider(); final DataCleanerConfiguration configuration = new DataCleanerConfigurationImpl() .withDatastoreCatalog(datastoreCatalog).withEnvironment( new DataCleanerEnvironmentImpl().withDescriptorProvider(descriptorProvider)); final FileObject file = VFSUtils.getFileSystemManager() .resolveFile("src/test/resources/cli-examples/date_analysis_job.xml"); final Provider<OpenAnalysisJobActionListener> providerMock = Providers.of(null); _dialog = new OpenAnalysisJobAsTemplateDialog(windowContext, configuration, file, createMetadata(), providerMock); } catch (final FileSystemException e) { logger.error("Problem occurred while creating dialog instance. \n" + e.getMessage()); } } return _dialog; }
From source file:org.eobjects.datacleaner.Main.java
/** * Initializes logging, specifically by looking for log4j.xml or * log4j.properties file in DataCleaner's home directory. * /* w w w . j a va2s . c o m*/ * @return true if a logging configuration file was found, or false * otherwise */ protected static boolean initializeLogging() { try { // initial logging config, used before anything else { final URL url = Main.class.getResource("log4j-initial.xml"); assert url != null; DOMConfigurator.configure(url); } if (ClassLoaderUtils.IS_WEB_START) { final URL url = Main.class.getResource("log4j-jnlp.xml"); assert url != null; println("Using JNLP log configuration: " + url); DOMConfigurator.configure(url); return true; } final FileObject dataCleanerHome = DataCleanerHome.get(); try { final FileObject xmlConfigurationFile = dataCleanerHome.resolveFile("log4j.xml"); if (xmlConfigurationFile.exists() && xmlConfigurationFile.getType() == FileType.FILE) { println("Using custom log configuration: " + xmlConfigurationFile); DOMConfigurator.configure(xmlConfigurationFile.getURL()); return true; } } catch (FileSystemException e) { // no xml logging found, ignore } try { final FileObject propertiesConfigurationFile = dataCleanerHome.resolveFile("log4j.properties"); if (propertiesConfigurationFile.exists() && propertiesConfigurationFile.getType() == FileType.FILE) { println("Using custom log configuration: " + propertiesConfigurationFile); PropertyConfigurator.configure(propertiesConfigurationFile.getURL()); return true; } } catch (FileSystemException e) { // no xml logging found, ignore } // fall back to default log4j.xml file in classpath final URL url = Main.class.getResource("log4j-default.xml"); assert url != null; println("Using default log configuration: " + url); DOMConfigurator.configure(url); return false; } catch (NoClassDefFoundError e) { // can happen if log4j is not on the classpath println("Failed to initialize logging, class not found: " + e.getMessage()); return false; } }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public boolean remove(String path, SharedUserPortletParameters userParameters) { boolean success = false; FileObject file;//w ww .ja v a 2 s . com try { file = cd(path, userParameters); success = file.delete(); } catch (FileSystemException e) { log.info("can't delete file because of FileSystemException : " + e.getMessage(), e); } log.debug("remove file " + path + ": " + success); return success; }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public String createFile(String parentPath, String title, String type, SharedUserPortletParameters userParameters) { try {/*from w ww .ja va2s .c om*/ FileObject parent = cd(parentPath, userParameters); FileObject child = parent.resolveFile(title); if (!child.exists()) { if ("folder".equals(type)) { child.createFolder(); log.info("folder " + title + " created"); } else { child.createFile(); log.info("file " + title + " created"); } return child.getName().getPath(); } else { log.info("file " + title + " already exists !"); } } catch (FileSystemException e) { log.info("can't create file because of FileSystemException : " + e.getMessage(), e); } return null; }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public boolean renameFile(String path, String title, SharedUserPortletParameters userParameters) { try {// w w w . j a v a 2 s. co m FileObject file = cd(path, userParameters); FileObject newFile = file.getParent().resolveFile(title); if (!newFile.exists()) { file.moveTo(newFile); return true; } else { log.info("file " + title + " already exists !"); } } catch (FileSystemException e) { log.info("can't rename file because of FileSystemException : " + e.getMessage(), e); } return false; }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public boolean moveCopyFilesIntoDirectory(String dir, List<String> filesToCopy, boolean copy, SharedUserPortletParameters userParameters) { try {/*from w w w .java2s. c o m*/ FileObject folder = cd(dir, userParameters); for (String fileToCopyPath : filesToCopy) { FileObject fileToCopy = cd(fileToCopyPath, userParameters); FileObject newFile = folder.resolveFile(fileToCopy.getName().getBaseName()); if (copy) { newFile.copyFrom(fileToCopy, Selectors.SELECT_ALL); } else { fileToCopy.moveTo(newFile); } } return true; } catch (FileSystemException e) { log.warn("can't move/copy file because of FileSystemException : " + e.getMessage(), e); } return false; }
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public DownloadFile getFile(String dir, SharedUserPortletParameters userParameters) { try {/*from ww w . ja va 2s .c o m*/ FileObject file = cd(dir, userParameters); FileContent fc = file.getContent(); int size = new Long(fc.getSize()).intValue(); String baseName = fc.getFile().getName().getBaseName(); // fc.getContentInfo().getContentType() use URLConnection.getFileNameMap, // we prefer here to use our getMimeType : for Excel files and co // String contentType = fc.getContentInfo().getContentType(); String contentType = JsTreeFile.getMimeType(baseName.toLowerCase()); InputStream inputStream = fc.getInputStream(); DownloadFile dlFile = new DownloadFile(contentType, size, baseName, inputStream); return dlFile; } catch (FileSystemException e) { log.warn("can't download file : " + e.getMessage(), e); } return null; }