Example usage for java.io File isAbsolute

List of usage examples for java.io File isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Tests whether this abstract pathname is absolute.

Usage

From source file:com.netflix.imfutility.AbstractFormatBuilder.java

private boolean doDeleteTmpFile(String paramValue) {
    boolean success = true;

    File tmpFile = new File(paramValue);
    if (!tmpFile.isAbsolute() || !tmpFile.isFile()) {
        tmpFile = new File(contextProvider.getWorkingDir().getAbsoluteFile(), paramValue);
    }/*  w  ww  .  j  a  v a  2  s . c o  m*/

    if (!tmpFile.isAbsolute() || !tmpFile.isFile()) {
        tmpFile = null;
    }

    if (tmpFile != null) {
        if (!tmpFile.delete()) {
            success = false;
            logger.warn("Couldn't delete tmp file {}", tmpFile.getAbsolutePath());
        }
    }

    return success;
}

From source file:net.grinder.engine.agent.AgentImplementationEx.java

private Properties rebaseSystemClassPath(Properties properties, File curDir) {
    Properties newProperties = new Properties();
    newProperties.putAll(properties);//from   w w  w .j a v a  2s . c  om
    StringBuilder newClassPath = new StringBuilder();
    boolean isFirst = true;
    for (String each : StringUtils.split(properties.getProperty("java.class.path"), File.pathSeparator)) {
        File file = new File(each);
        if (!file.isAbsolute()) {
            file = new File(curDir, each);
        }
        if (!isFirst) {
            newClassPath.append(File.pathSeparator);
        }
        isFirst = false;
        newClassPath.append(FilenameUtils.normalize(file.getAbsolutePath()));
    }
    newProperties.put("java.class.path", newClassPath.toString());
    return newProperties;
}

From source file:org.duniter.elasticsearch.PluginSettings.java

@Override
protected void doStart() {

    // get all config providers
    Set<ApplicationConfigProvider> providers = ImmutableSet.of(new ConfigurationProvider());

    // load all default options
    ApplicationConfigHelper.loadAllDefaultOption(applicationConfig, providers);

    // Ovverides defaults
    String baseDir = settings.get("path.home");
    applicationConfig.setDefaultOption(ConfigurationOption.BASEDIR.getKey(), baseDir);
    applicationConfig.setDefaultOption(ConfigurationOption.NODE_HOST.getKey(), getNodeBmaHost());
    applicationConfig.setDefaultOption(ConfigurationOption.NODE_PORT.getKey(),
            String.valueOf(getNodeBmaPort()));
    applicationConfig.setDefaultOption(ConfigurationOption.NETWORK_TIMEOUT.getKey(),
            String.valueOf(getNetworkTimeout()));
    applicationConfig.setDefaultOption(ConfigurationOption.NETWORK_MAX_CONNECTIONS.getKey(),
            String.valueOf(getNetworkMaxConnections()));
    applicationConfig.setDefaultOption(ConfigurationOption.NETWORK_MAX_CONNECTIONS_PER_ROUTE.getKey(),
            String.valueOf(getNetworkMaxConnectionsPerRoute()));

    try {/*  w  w  w . j a v  a  2s. c  om*/
        applicationConfig.parse(new String[] {});

    } catch (ArgumentsParserException e) {
        throw new TechnicalException(t("duniter4j.config.parse.error"), e);
    }

    File appBasedir = applicationConfig.getOptionAsFile(ConfigurationOption.BASEDIR.getKey());

    if (appBasedir == null) {
        appBasedir = new File("");
    }
    if (!appBasedir.isAbsolute()) {
        appBasedir = new File(appBasedir.getAbsolutePath());
    }
    if (appBasedir.getName().equals("..")) {
        appBasedir = appBasedir.getParentFile().getParentFile();
    }
    if (appBasedir.getName().equals(".")) {
        appBasedir = appBasedir.getParentFile();
    }
    applicationConfig.setOption(ConfigurationOption.BASEDIR.getKey(), appBasedir.getAbsolutePath());

    // Init i18n
    try {
        initI18n();
    } catch (IOException e) {
        logger.error(String.format("Could not init i18n: %s", e.getMessage()), e);
    }

    initVersion(applicationConfig);
}

From source file:helma.main.ApplicationManager.java

private String findResource(String path) {
    File file = new File(path);
    if (!file.isAbsolute() && !file.exists()) {
        file = new File(server.getHopHome(), path);
    }//from   w  ww.j  a  v  a2 s  .c  o  m
    return file.getAbsolutePath();
}

From source file:org.apache.maven.plugin.javadoc.JavadocUtil.java

/**
 * Method that removes the invalid directories in the specified directories.
 * <b>Note</b>: All elements in <code>dirs</code> could be an absolute or relative against the project's base
 * directory <code>String</code> path.
 *
 * @param project the current Maven project not null
 * @param dirs the list of <code>String</code> directories path that will be validated.
 * @return a List of valid <code>String</code> directories absolute paths.
 *///from   w w w. j a va 2  s. c  om
public static List<String> pruneDirs(MavenProject project, List<String> dirs) {
    List<String> pruned = new ArrayList<String>(dirs.size());
    for (String dir : dirs) {
        if (dir == null) {
            continue;
        }

        File directory = new File(dir);
        if (!directory.isAbsolute()) {
            directory = new File(project.getBasedir(), directory.getPath());
        }

        if (directory.isDirectory() && !pruned.contains(directory.getAbsolutePath())) {
            pruned.add(directory.getAbsolutePath());
        }
    }

    return pruned;
}

From source file:helma.main.ApplicationManager.java

private File getAbsoluteFile(String path) {
    // make sure our directory has an absolute path,
    // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4117557
    File file = new File(path);
    if (file.isAbsolute()) {
        return file;
    } else {//w ww .  j a  va 2 s. c o m
        return file.getAbsoluteFile();
    }
}

From source file:com.npower.dm.setup.task.ModelTask.java

protected void processFirmwares() throws SetupException {
    List<String> filenames = this.getFilenames();
    ManagementBeanFactory factory = null;
    try {//from   w  w w  .  j  a va  2 s  . c o m
        factory = this.getManagementBeanFactory();
        ModelBean modelBean = factory.createModelBean();

        // Import Profile Mappings
        for (String filename : filenames) {
            // Process the file, and import data into database.
            File file = new File(filename);
            if (!file.isAbsolute()) {
                file = new File(this.getSetup().getWorkDir(), filename);
            }

            this.getSetup().getConsole().println("         Loading file [ " + file.getAbsolutePath() + " ]");
            List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath());
            for (ManufacturerItem manufacturerItem : items) {
                List<ModelItem> modelItems = manufacturerItem.getModels();
                Manufacturer manufacturer = modelBean
                        .getManufacturerByExternalID(manufacturerItem.getExternalID());
                for (ModelItem modelItem : modelItems) {
                    // Copy information from family
                    this.copyFromFamily(modelItem);

                    Model model = modelBean.getModelByManufacturerModelID(manufacturer,
                            modelItem.getExternalID());

                    if (!modelItem.getFirmwares().isEmpty()) {
                        this.getSetup().getConsole().println("         * Importing Firmwares for [ "
                                + manufacturer.getExternalId() + " " + model.getManufacturerModelId() + " ]");
                    }
                    for (FirmwareItem firmwareItem : modelItem.getFirmwares()) {
                        File firmwareFile = new File(firmwareItem.getFilename());
                        if (!firmwareFile.isAbsolute()) {
                            firmwareFile = new File(this.getSetup().getWorkDir(), firmwareItem.getFilename());
                        }
                        if (!firmwareFile.exists()) {
                            this.getSetup().getConsole()
                                    .println("Could not load firmware from: " + firmwareFile.getAbsolutePath());
                            continue;
                        }
                        String fromVersion = firmwareItem.getFromVersion();
                        String toVersion = firmwareItem.getToVersion();
                        this.importFirmware(manufacturer.getExternalId(), model.getManufacturerModelId(),
                                fromVersion, toVersion, firmwareFile.getAbsolutePath());
                    }

                }
            }
        }
    } catch (Exception ex) {
        throw new SetupException("Error in import models.", ex);
    } finally {
        if (factory != null) {
            factory.release();
        }
    }
}

From source file:com.streamsets.pipeline.lib.hdfs.common.HdfsBaseConfigBean.java

protected Configuration getHadoopConfiguration(Stage.Context context, List<Stage.ConfigIssue> issues) {
    Configuration conf = new Configuration();
    conf.setClass("fs.file.impl", RawLocalFileSystem.class, FileSystem.class);
    //We handle the file system close ourselves in destroy
    //If enabled, Also this will cause issues (not allow us to rename the files on destroy call)
    // when we run a shutdown hook on app kill
    //See https://issues.streamsets.com/browse/SDC-4057
    conf.setBoolean("fs.automatic.close", false);

    // See SDC-5451, we set hadoop.treat.subject.external automatically to take advantage of HADOOP-13805
    HadoopConfigurationUtils.configureHadoopTreatSubjectExternal(conf);

    if (hdfsKerberos) {
        conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION,
                UserGroupInformation.AuthenticationMethod.KERBEROS.name());
        try {/* w ww  .  j  a  va 2  s  . c  o  m*/
            conf.set(DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY,
                    "hdfs/_HOST@" + HadoopSecurityUtil.getDefaultRealm());
        } catch (Exception ex) {
            if (!hdfsConfigs.stream().anyMatch(i -> DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY.equals(i.key))) {
                issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(), null, Errors.HADOOPFS_28,
                        ex.toString()));
            }
        }
    }
    if (hdfsConfDir != null && !hdfsConfDir.isEmpty()) {
        File hadoopConfigDir = new File(hdfsConfDir);
        if ((context.getExecutionMode() == ExecutionMode.CLUSTER_BATCH
                || context.getExecutionMode() == ExecutionMode.CLUSTER_YARN_STREAMING
                || context.getExecutionMode() == ExecutionMode.CLUSTER_MESOS_STREAMING)
                && hadoopConfigDir.isAbsolute()) {
            //Do not allow absolute hadoop config directory in cluster mode
            issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(), getConfigBeanPrefix() + "hdfsConfDir",
                    Errors.HADOOPFS_45, hdfsConfDir));
        } else {
            if (!hadoopConfigDir.isAbsolute()) {
                hadoopConfigDir = new File(context.getResourcesDirectory(), hdfsConfDir).getAbsoluteFile();
            }
            if (!hadoopConfigDir.exists()) {
                issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(),
                        getConfigBeanPrefix() + "hdfsConfDir", Errors.HADOOPFS_25, hadoopConfigDir.getPath()));
            } else if (!hadoopConfigDir.isDirectory()) {
                issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(),
                        getConfigBeanPrefix() + "hdfsConfDir", Errors.HADOOPFS_26, hadoopConfigDir.getPath()));
            } else {
                File coreSite = new File(hadoopConfigDir, "core-site.xml");
                if (coreSite.exists()) {
                    if (!coreSite.isFile()) {
                        issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(),
                                getConfigBeanPrefix() + "hdfsConfDir", Errors.HADOOPFS_27, coreSite.getPath()));
                    }
                    conf.addResource(new Path(coreSite.getAbsolutePath()));
                }
                File hdfsSite = new File(hadoopConfigDir, "hdfs-site.xml");
                if (hdfsSite.exists()) {
                    if (!hdfsSite.isFile()) {
                        issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(),
                                getConfigBeanPrefix() + "hdfsConfDir", Errors.HADOOPFS_27, hdfsSite.getPath()));
                    }
                    conf.addResource(new Path(hdfsSite.getAbsolutePath()));
                }
            }
        }
    } else {
        Optional<HadoopConfigBean> fsDefaultFS = hdfsConfigs.stream()
                .filter(item -> CommonConfigurationKeys.FS_DEFAULT_NAME_KEY.equals(item.key)).findFirst();
        if (StringUtils.isEmpty(hdfsUri) && !fsDefaultFS.isPresent()) {
            // No URI, no config dir, and no fs.defaultFS config param
            // Avoid defaulting to writing to file:/// (SDC-5143)
            issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(), getConfigBeanPrefix() + "hdfsUri",
                    Errors.HADOOPFS_61));
        }
    }

    for (HadoopConfigBean configBean : hdfsConfigs) {
        try {
            conf.set(configBean.key, configBean.value.get());
        } catch (StageException e) {
            issues.add(context.createConfigIssue(Groups.HADOOP_FS.name(), getConfigBeanPrefix() + "hdfsConfigs",
                    Errors.HADOOPFS_62, e.toString()));
        }
    }

    return conf;
}

From source file:org.apache.jmeter.services.FileServer.java

/**
 * Resolves file name into {@link File} instance.
 * When filename is not absolute and not found from current workind dir,
 * it tries to find it under current base directory
 * @param filename original file name/*from  w ww  . ja v  a 2  s .c  o m*/
 * @return {@link File} instance
 */
private File resolveFileFromPath(String filename) {
    File f = new File(filename);
    if (f.isAbsolute() || f.exists()) {
        return f;
    } else {
        return new File(base, filename);
    }
}