Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

In this page you can find the example usage for java.io File getAbsoluteFile.

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.redhat.rcm.version.mgr.VersionManager.java

public Set<File> modifyVersions(final File dir, final String pomNamePattern, final String pomExcludePattern,
        final List<String> boms, final String toolchain, final VersionManagerSession session)
        throws VManException {
    final String[] includedSubpaths = getIncludedSubpaths(dir, pomNamePattern, pomExcludePattern, session);
    final List<File> pomFiles = new ArrayList<File>();

    for (final String subpath : includedSubpaths) {
        File pom = new File(dir, subpath);
        try {/*  w  ww  . j  av  a 2s  . com*/
            pom = pom.getCanonicalFile();
        } catch (final IOException e) {
            pom = pom.getAbsoluteFile();
        }

        if (!pomFiles.contains(pom)) {
            logger.info("Loading POM: '" + pom + "'");
            pomFiles.add(pom);
        }
    }

    final File[] pomFileArray = pomFiles.toArray(new File[] {});

    configureSession(boms, toolchain, session, pomFileArray);

    final Set<File> outFiles = modVersions(dir, session, session.isPreserveFiles(), pomFileArray);

    logger.info("Modified " + outFiles.size() + " POM versions in directory.\n\n\tDirectory: " + dir
            + "\n\tBOMs:\t" + StringUtils.join(boms.iterator(), "\n\t\t") + "\n\tPOM Backups: "
            + session.getBackups() + "\n\n");

    return outFiles;
}

From source file:hydrograph.ui.expression.editor.composites.CategoriesDialogSourceComposite.java

private void createBrowseButton(Composite headerComposite) {
    Button browseButton = new Button(headerComposite, SWT.NONE);
    browseButton.setText("Browse");
    browseButton.setToolTipText(Messages.EXTERNAL_JAR_DIALOG_BROWSE_BUTTON_TOOLTIP);
    browseButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IFolder libsFolder = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()
                    .getFolder(PathConstant.PROJECT_LIB_FOLDER);
            FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OK);
            dialog.setFilterExtensions(filters);
            String path = dialog.open();
            if (path != null) {
                File file = new File(path);
                if (file.isFile()) {
                    IFile newFile = libsFolder.getFile(file.getName());
                    if (!newFile.exists()) {
                        try (InputStream fis = new FileInputStream(file.getAbsoluteFile())) {
                            newFile.create(fis, true, null);
                            addFileToBuildPath(newFile);
                            loadComboJarListFromBuildPath(comboJarList, newFile.getName());

                        } catch (CoreException | IOException e1) {
                            LOGGER.error(
                                    "Exception occurred while copying jar file from local-file-system to project",
                                    e1);
                            new CustomMessageBox(SWT.ERROR, Messages.JAR_FILE_COPY_ERROR, Messages.ERROR_TITLE)
                                    .open();
                        }//from  ww w  . j av  a 2 s.  c  o m
                    } else {
                        new CustomMessageBox(SWT.ERROR, Messages.DUPLICATE_JAR_FILE_COPY_ERROR,
                                Messages.ERROR_TITLE).open();
                    }
                }
            }
        }

        private void addFileToBuildPath(IFile jarFile) throws CoreException {
            LOGGER.error("Adding jar file " + jarFile.getName() + " to build Path");
            IJavaProject javaProject = JavaCore
                    .create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject());
            IClasspathEntry[] oldClasspathEntry = javaProject.getRawClasspath();
            IClasspathEntry[] newClasspathEntry = new IClasspathEntry[oldClasspathEntry.length + 1];
            for (int index = 0; index < oldClasspathEntry.length; index++) {
                if (oldClasspathEntry[index].getPath().equals(jarFile.getFullPath()))
                    return;
                newClasspathEntry[index] = javaProject.getRawClasspath()[index];
            }
            newClasspathEntry[oldClasspathEntry.length] = JavaCore.newLibraryEntry(jarFile.getFullPath(), null,
                    null);
            javaProject.setRawClasspath(newClasspathEntry, new NullProgressMonitor());
            javaProject.close();
        }
    });
}

From source file:com.twineworks.kettle.ruby.step.execmodels.SimpleExecutionModel.java

private void setGemHome() {

    // if specified directly, take it
    String gemHomeString = step.environmentSubstitute(meta.getGemHome());

    // if not, fall back to RUBY_GEM_HOME
    if (Const.isEmpty(gemHomeString) && !Const.isEmpty(step.getVariable("RUBY_GEM_HOME"))) {
        gemHomeString = step.environmentSubstitute("${RUBY_GEM_HOME}");
    }//from w w w  . ja va  2  s  . c  o m

    // if that fails, use the standard one
    if (Const.isEmpty(gemHomeString)) {
        gemHomeString = step.getPluginDir() + Const.FILE_SEPARATOR + "gems";
    }

    if (!Const.isEmpty(gemHomeString)) {

        File gemHomePath = new File(gemHomeString);
        gemHomePath = gemHomePath.getAbsoluteFile();

        String gemHome = gemHomePath.getAbsolutePath();
        data.container.runScriptlet("require 'rubygems/defaults/jruby';Gem::Specification.add_dir '" + gemHome
                + "' unless Gem::Specification.dirs.member?( '" + gemHome + "' )");

    }
}

From source file:de.dentrassi.build.apt.repo.AptWriter.java

private File makeTargetFile(final Component component, final File packageFile, final String packageName) {
    File targetFile = new File(this.pool, component.getName());
    targetFile = new File(targetFile, packageName.substring(0, 1));
    targetFile = new File(targetFile, packageName);
    targetFile = new File(targetFile, packageFile.getName());
    return targetFile.getAbsoluteFile();
}

From source file:fi.helsinki.cs.iot.hub.jsengine.DuktapeJavascriptEngineWrapper.java

public String getEcmaEventLoopFilename() {

    File file = Paths.get(libdir.toString(), "ecma_eventloop.js").toFile();
    if (!file.exists()) {
        try {//ww  w . ja v  a2  s.c  o  m
            InputStream link = (DuktapeJavascriptEngineWrapper.class.getResourceAsStream("/ecma_eventloop.js"));
            Files.copy(link, file.getAbsoluteFile().toPath());
            return file.getAbsolutePath();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
    }
    return file.getAbsolutePath();
}

From source file:maspack.fileutil.FileCacher.java

public File cache(URIx uri, File cacheFile, FileTransferMonitor monitor) throws FileSystemException {

    // For atomic operation, first download to temporary directory
    File tmpCacheFile = new File(cacheFile.getAbsolutePath() + TMP_EXTENSION);
    URIx cacheURI = new URIx(cacheFile.getAbsoluteFile());
    URIx tmpCacheURI = new URIx(tmpCacheFile.getAbsoluteFile());
    FileObject localTempFile = manager.resolveFile(tmpCacheURI.toString(true));
    FileObject localCacheFile = manager.resolveFile(cacheURI.toString(true));

    FileObject remoteFile = null; // will resolve next

    // loop through authenticators until we either succeed or cancel
    boolean cancel = false;
    while (remoteFile == null && cancel == false) {
        remoteFile = resolveRemote(uri);
    }/*  w  ww  . j  a  v  a2  s . c  o m*/

    if (remoteFile == null || !remoteFile.exists()) {
        throw new FileSystemException("Cannot find remote file <" + uri.toString() + ">",
                new FileNotFoundException("<" + uri.toString() + ">"));
    }

    // monitor the file transfer progress
    if (monitor != null) {
        monitor.monitor(localTempFile, remoteFile, -1, cacheFile.getName());
        monitor.start();
        monitor.fireStartEvent(localTempFile);
    }

    // transfer content
    try {
        if (remoteFile.isFile()) {
            localTempFile.copyFrom(remoteFile, Selectors.SELECT_SELF);
        } else if (remoteFile.isFolder()) {
            // final FileObject fileSystem = manager.createFileSystem(remoteFile);
            localTempFile.copyFrom(remoteFile, new AllFileSelector());
            // fileSystem.close();
        }

        if (monitor != null) {
            monitor.fireCompleteEvent(localTempFile);
        }
    } catch (Exception e) {
        // try to delete local file
        localTempFile.delete();
        throw new RuntimeException(
                "Failed to complete transfer of " + remoteFile.getURL() + " to " + localTempFile.getURL(), e);
    } finally {
        // close files if we need to
        localTempFile.close();
        remoteFile.close();
        if (monitor != null) {
            monitor.release(localTempFile);
            monitor.stop();
        }

    }

    // now that the copy is complete, do a rename operation
    try {
        if (tmpCacheFile.isDirectory()) {
            SafeFileUtils.moveDirectory(tmpCacheFile, cacheFile);
        } else {
            SafeFileUtils.moveFile(tmpCacheFile, cacheFile);
        }
    } catch (Exception e) {
        localCacheFile.delete(); // delete if possible
        throw new RuntimeException("Failed to atomically move " + "to " + localCacheFile.getURL(), e);
    }

    return cacheFile;

}

From source file:interactivespaces.launcher.bootstrap.InteractiveSpacesFrameworkBootstrap.java

/**
 * Get all jars from the bootstrap folder.
 *
 * @param folder/*from   w w w  . j  a  v  a 2 s .c om*/
 *          the folder containing the bootstrap bundles
 */
private void getBootstrapBundleJars(File folder) {
    // Look in the specified bundle directory to create a list
    // of all JAR files to install.
    File[] files = folder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            String filename = name.toLowerCase();
            return filename.endsWith(".jar") || filename.endsWith(".war");
        }
    });

    for (File f : files) {
        initialBundles.add(f.getAbsoluteFile());
    }
}

From source file:com.ideateam.plugin.Version.java

private String getCurrentVersionZip(File wwwFolder) {
    String version = null;//from  w ww.  j  a  va2  s . com

    File indexFile = new File(wwwFolder.getAbsoluteFile() + "/index.html");

    try {
        FileInputStream fin = new FileInputStream(wwwFolder.getAbsoluteFile() + "/index.html");
        BufferedReader r = new BufferedReader(new InputStreamReader(fin));

        String line;
        while ((line = r.readLine()) != null) {
            if (line.indexOf("src=\"app.js?") != -1) {
                int start = line.indexOf("?");
                int end = line.lastIndexOf("-");

                version = line.substring(start + 1, end);

                break;
            }
        }

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //   BufferedReader r = new BufferedReader(new InputStreamReader(openFileInput(wwwFolder.getName()+"/index.html") ));
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return version;
}

From source file:de.smartics.maven.plugin.jboss.modules.JandexMojo.java

private void writeIndex(final Indexer indexer) throws MojoExecutionException {
    final File indexFile = new File(outputDirectory, "META-INF/jandex.idx");
    indexFile.getParentFile().mkdirs();//from  w ww . jav  a2  s  .c o m

    FileOutputStream indexOutput = null;
    try {
        indexOutput = FileUtils.openOutputStream(indexFile);
        final IndexWriter writer = new IndexWriter(indexOutput);
        final Index index = indexer.complete();
        writer.write(index);
    } catch (final IOException e) {
        throw new MojoExecutionException(
                String.format("Cannot write index file '%s'.", indexFile.getAbsoluteFile()), e);
    } finally {
        IOUtils.closeQuietly(indexOutput);
    }
}

From source file:com.fides.GrinderPropertiesConfigure.java

/**
 * Initialize configuration directory// w w w  .  jav  a 2s  . c  o  m
 */
private void initConfigurationDirectory() {
    // make sure the configDirectory exists
    File configDirectory = new File(CONFIG);
    if (configDirectory != null && !configDirectory.exists()) {
        configDirectory.mkdirs();
    }

    BufferedWriter out;

    try {

        for (String fileName : grinderScripts) {
            logger.debug("using file {} for copy", fileName);
            File file = new File(CONFIG,
                    "grinder_agent_" + FilenameUtils.getBaseName(fileName) + ".properties");
            File scriptDest = new File(CONFIG, fileName);
            propertiesFiles.add(file.getAbsoluteFile());
            out = new BufferedWriter(new FileWriter(file));
            // need to iterate keys and copy to new propertes

            propertiesPlugin.put("grinder.script", scriptDest.getAbsolutePath());

            propertiesPlugin.store(out, "Grinder Agent Properties for " + fileName);

            FileUtils.copyFile(new File(pathTest, fileName), scriptDest);
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
        logConfigErrorAndExit("Could not copy files: {}", grinderScripts);
    }

    logger.debug("--- Grinderplugin to be configured ---");
}