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:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.WinAutConfigComponent.java

/**
 * The action of the working directory field.
 * @return <code>null</code> if the new value is valid. Otherwise, returns
 *         a status parameter indicating the cause of the problem.
 *//* w ww  . j  av  a 2 s.  co m*/
DialogStatusParameter modifyExecTextField() {
    DialogStatusParameter error = null;
    m_isExecFieldValid = true;
    isExecFieldEmpty = m_execTextField.getText().length() == 0;
    String filename = m_execTextField.getText();
    if (isValid(m_execTextField, true) && !isExecFieldEmpty) {
        if (checkLocalhostServer()) {
            File file = new File(filename);
            if (!file.isAbsolute()) {
                String workingDirString = getConfigValue(AutConfigConstants.WORKING_DIR);
                if (workingDirString != null && workingDirString.length() != 0) {

                    filename = workingDirString + "/" + filename; //$NON-NLS-1$
                    file = new File(filename);
                }
            }

            try {
                if (!file.isFile()) {
                    error = createWarningStatus(
                            NLS.bind(Messages.AUTConfigComponentFileNotFound, file.getCanonicalPath()));
                }
            } catch (IOException e) {
                // could not find file
                error = createWarningStatus(NLS.bind(Messages.AUTConfigComponentFileNotFound, filename));
            }
        }
    } else if (!isExecFieldEmpty) {
        error = createErrorStatus(Messages.AUTConfigComponentWrongExecutable);
    }
    if (error != null) {
        m_isExecFieldValid = false;
    }
    putConfigValue(AutConfigConstants.EXECUTABLE, m_execTextField.getText());
    executablePath = filename;
    return error;
}

From source file:de.uni_hildesheim.sse.easy_producer.instantiator.model.buildlangModel.BuildlangExecution.java

/**
 * Makes <code>path</code> absolute with respect to <code>base</code> if necessary.
 * /*from  w w w.ja v  a2 s  . c om*/
 * @param path the file to be made absolute
 * @param base the base path
 * @return the absolute file
 */
private static File absolute(String path, File base) {
    File result = new File(path);
    if (!result.isAbsolute()) {
        result = new File(base, path);
    }
    return result;
}

From source file:org.ebayopensource.turmeric.plugins.maven.stubs.TurmericProjectStub.java

private File ensureDirExists(String dirname, String defaultname) {
    File dir;

    if (StringUtils.isBlank(dirname)) {
        dir = new File(getBasedir(), toOS(defaultname));
    } else {/*from  w  ww  .ja  v a  2 s  . c  o m*/
        dir = new File(dirname);
        if (!dir.isAbsolute()) {
            dir = new File(getBasedir(), dirname);
        }
    }

    ensureDirExists(dir);
    return dir;
}

From source file:adalid.util.meta.sql.MetaFolderSql.java

public MetaFolderSql(String path) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(1);/*from   www .ja  va 2 s.c om*/
    nf.setMaximumFractionDigits(2);
    logger.info("max-file-size=" + nf.format(MAX_FILE_SIZE_MEGAS) + "MB");
    rootFolder = PropertiesHandler.getRootFolder();
    if (rootFolder == null) {
        throw new RuntimeException("root folder is missing or invalid");
    }
    rootFolderPath = Paths.get(rootFolder.getPath());
    logger.info("root-folder=" + rootFolderPath);
    if (path == null) {
        throw new IllegalArgumentException("null folder path");
    } else {
        File file = new File(path);
        if (file.isAbsolute()) {
            metaFolder = file;
        } else {
            metaFolder = new File(rootFolder.getAbsolutePath(), path);
        }
    }
    metaFolderPath = Paths.get(metaFolder.getPath());
    logger.info("meta-folder=" + metaFolderPath);
    if (metaFolder.isDirectory()) {
        if (metaFolder.isHidden()) {
            throw new IllegalArgumentException(metaFolderPath + " is a hidden directory");
        }
    } else {
        throw new IllegalArgumentException(metaFolderPath + " is not a directory");
    }
    baseFolder = metaFolder.getParentFile();
    baseFolderPath = Paths.get(baseFolder.getPath());
    logger.info("base-folder=" + baseFolderPath);
    files = new TreeMap<>();
    folders = new TreeMap<>();
    fileTypes = new TreeMap<>();
    metaFolderWrapper = new FolderWrapper(metaFolder);
    folders.put(getRelativeToBasePath(metaFolder), metaFolderWrapper);
}

From source file:de.pdark.dsmp.Config.java

private File getCacheDirectory(Element root) {
    String defaultValue = "cache";

    String s = getStringProperty(root, "directories", "cache", defaultValue);
    File f = new File(s);
    if (!f.isAbsolute())
        f = new File(getBaseDirectory(), s);

    IOUtils.mkdirs(f);//  www . ja v a2s . com

    return f;
}

From source file:de.pdark.dsmp.Config.java

private File getPatchesDirectory(Element root) {
    String defaultValue = "patches";

    String s = getStringProperty(root, "directories", "patches", defaultValue);
    File f = new File(s);
    if (!f.isAbsolute())
        f = new File(getBaseDirectory(), s);

    IOUtils.mkdirs(f);//w w  w.  j  a va2  s  .c  o m

    return f;
}

From source file:jenkins.plugins.coverity.CoverityLauncher.java

/**
 * Sets the value of environment variable "COV_IDIR" and creates necessary directories. This variable is used as argument of "--dir" for
 * cov-build./* w  w w.jav a  2  s. c  o m*/
 *
 * If the environment variable has already being set then that value is used. Otherwise, the value of
 * this variable is set to either a temporary directory or the idir specified on the UI under the
 * Intermediate Directory option.
 *
 * Notice this variable must be resolved before running cov-build. Also this method creates necessary directories.
 */
public void setupIntermediateDirectory(@Nonnull AbstractBuild<?, ?> build, @Nonnull TaskListener listener,
        @Nonnull Node node) {
    Validate.notNull(build, AbstractBuild.class.getName() + " object can't be null");
    Validate.notNull(listener, TaskListener.class.getName() + " object can't be null");
    Validate.notNull(node, Node.class.getName() + " object can't be null");
    Validate.notNull(envVars, EnvVars.class.getName() + " object can't be null");
    if (!envVars.containsKey("COV_IDIR")) {
        FilePath temp;
        InvocationAssistance invocationAssistance = CoverityUtils.getInvocationAssistance(build);
        try {
            if (invocationAssistance == null || invocationAssistance.getIntermediateDir() == null
                    || invocationAssistance.getIntermediateDir().isEmpty()) {
                FilePath coverityDir = node.getRootPath().child("coverity");
                coverityDir.mkdirs();
                temp = coverityDir.createTempDir("temp-", null);
            } else {
                // Gets a not null nor empty intermediate directory.
                temp = resolveIntermediateDirectory(build, listener, node,
                        invocationAssistance.getIntermediateDir());
                if (temp != null) {
                    File idir = new File(temp.getRemote());
                    String workspace = envVars.get("WORKSPACE");
                    if (idir != null && !idir.isAbsolute() && !StringUtils.isEmpty(workspace)) {
                        String path = FilenameUtils.concat(workspace, temp.getRemote());
                        if (!StringUtils.isEmpty(path)) {
                            temp = new FilePath(temp.getChannel(), path);
                        }
                    }
                    temp.mkdirs();
                }
            }

            if (invocationAssistance != null) {
                build.addAction(new CoverityTempDir(temp, invocationAssistance.getIntermediateDir() == null));
            } else {
                build.addAction(new CoverityTempDir(temp, true));
            }
        } catch (IOException e) {
            throw new RuntimeException("Error while creating temporary directory for Coverity", e);
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted while creating temporary directory for Coverity");
        }
        if (temp != null) {
            envVars.put("COV_IDIR", temp.getRemote());
        }
    }
}

From source file:org.dvcama.lodview.conf.ConfigurationBean.java

public void populateBean() throws IOException, Exception {
    System.out.println("Initializing configuration " + confFile);
    File configFile = new File(confFile);
    if (!configFile.isAbsolute()) {
        configFile = new File(context.getRealPath("/") + "/WEB-INF/" + confFile);
    }//from w w w.j ava2  s.  c o  m
    if (!configFile.exists()) {
        throw new Exception("Configuration file not found (" + configFile.getAbsolutePath() + ")");
    }
    confModel = RDFDataMgr.loadModel(configFile.getAbsolutePath());

    endPointUrl = getSingleConfValue("endpoint");
    endPointType = getSingleConfValue("endpointType", "");
    authPassword = getSingleConfValue("authPassword");
    authUsername = getSingleConfValue("authUsername");
    forceIriEncoding = getSingleConfValue("forceIriEncoding", "auto");
    redirectionStrategy = getSingleConfValue("redirectionStrategy", "");

    IRInamespace = getSingleConfValue("IRInamespace", "<not provided>");

    httpRedirectSuffix = getSingleConfValue("httpRedirectSuffix", "");
    httpRedirectPrefix = getSingleConfValue("httpRedirectPrefix", "");
    httpRedirectExcludeList = getSingleConfValue("httpRedirectExcludeList", "");

    publicUrlPrefix = getSingleConfValue("publicUrlPrefix", "");
    publicUrlPrefix = publicUrlPrefix.replaceAll(".+/auto$", context.getContextPath() + "/");

    contentEncoding = getSingleConfValue("contentEncoding");
    staticResourceURL = getSingleConfValue("staticResourceURL", "");
    homeUrl = getSingleConfValue("homeUrl", "/");
    staticResourceURL = staticResourceURL.replaceAll(".+/auto$",
            context.getContextPath() + "/staticResources/");

    preferredLanguage = getSingleConfValue("preferredLanguage");

    typeProperties = getMultiConfValue("typeProperties");
    titleProperties = getMultiConfValue("titleProperties");
    descriptionProperties = getMultiConfValue("descriptionProperties");
    imageProperties = getMultiConfValue("imageProperties");
    audioProperties = getMultiConfValue("audioProperties");
    videoProperties = getMultiConfValue("videoProperties");
    linkingProperties = getMultiConfValue("linkingProperties");
    longitudeProperties = getMultiConfValue("longitudeProperties");
    latitudeProperties = getMultiConfValue("latitudeProperties");

    defaultQueries = getMultiConfValue("defaultQueries");
    defaultRawDataQueries = getMultiConfValue("defaultRawDataQueries");

    defaultInversesQueries = getMultiConfValue("defaultInversesQueries");
    defaultInversesTest = getMultiConfValue("defaultInversesTest");
    defaultInversesCountQueries = getMultiConfValue("defaultInversesCountQueries");

    defaultInverseBehaviour = getSingleConfValue("defaultInverseBehaviour", defaultInverseBehaviour);
    mainOntologiesPrefixes = getMultiConfValue("mainOntologiesPrefixes");

    license = getSingleConfValue("license", "");

    colorPair = getMultiConfValue("colorPair");

    if (colorPair != null && colorPair.size() == 1 && colorPair.get(0).startsWith("http://")) {
        colorPairMatcher = populateColorPairMatcher();
    }

    skipDomains = getMultiConfValue("skipDomains");
}

From source file:net.sf.jabref.gui.FileListEntryEditor.java

private void storeSettings(FileListEntry entry) {
    String descriptionText = this.description.getText().trim();
    String link = "";
    // See if we should trim the file link to be relative to the file directory:
    try {/*from  www  . j  a v a2 s  . c o m*/
        List<String> dirs = databaseContext.getFileDirectory();
        if (dirs.isEmpty()) {
            link = this.link.getText().trim();
        } else {
            boolean found = false;
            for (String dir : dirs) {
                String canPath = (new File(dir)).getCanonicalPath();
                File fl = new File(this.link.getText().trim());
                if (fl.isAbsolute()) {
                    String flPath = fl.getCanonicalPath();
                    if ((flPath.length() > canPath.length()) && (flPath.startsWith(canPath))) {
                        link = fl.getCanonicalPath().substring(canPath.length() + 1);
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                link = this.link.getText().trim();
            }
        }
    } catch (IOException ex) {
        // Don't think this should happen, but set the file link directly as a fallback:
        link = this.link.getText().trim();
    }

    ExternalFileType type = (ExternalFileType) types.getSelectedItem();

    entry.description = descriptionText;
    entry.type = Optional.ofNullable(type);
    entry.link = link;
}

From source file:com.netspective.commons.xml.ParseContext.java

public File resolveFile(String src) {
    File file = new File(src);
    if (file.isAbsolute())
        return file;
    else/*from  w  w w .  jav  a  2 s . c  o  m*/
        return inputSrcTracker != null && inputSrcTracker instanceof FileTracker
                ? new File(((FileTracker) inputSrcTracker).getFile().getParent(), src)
                : file;
}