Example usage for java.io File getCanonicalFile

List of usage examples for java.io File getCanonicalFile

Introduction

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

Prototype

public File getCanonicalFile() throws IOException 

Source Link

Document

Returns the canonical form of this abstract pathname.

Usage

From source file:com.liferay.blade.cli.command.CreateCommand.java

private File _getDefaultWarsDir() throws Exception {
    BladeCLI bladeCLI = getBladeCLI();// ww  w  .ja  va  2  s. c om

    BaseArgs args = bladeCLI.getArgs();

    File base = new File(args.getBase());

    File baseDir = base.getCanonicalFile();

    if (!isWorkspace(baseDir)) {
        return baseDir;
    }

    Properties properties = getWorkspaceProperties();

    String warsDirValue = (String) properties.get(WorkspaceConstants.DEFAULT_WARS_DIR_PROPERTY);

    if (warsDirValue == null) {
        warsDirValue = WorkspaceConstants.DEFAULT_WARS_DIR;
    }

    if (warsDirValue.contains(",")) {
        warsDirValue = warsDirValue.split(",")[0];
    }

    WorkspaceProvider workspaceProvider = bladeCLI.getWorkspaceProvider(baseDir);

    File projectDir = workspaceProvider.getWorkspaceDir(baseDir);

    File warsDir = new File(projectDir, warsDirValue);

    if (_containsDir(baseDir, warsDir)) {
        return baseDir;
    }

    return warsDir;
}

From source file:com.liferay.blade.cli.command.CreateCommand.java

private File _getDefaultModulesDir() throws Exception {
    BladeCLI bladeCLI = getBladeCLI();//w  w  w  .  ja v  a2  s .  co  m

    BaseArgs args = bladeCLI.getArgs();

    File base = new File(args.getBase());

    File baseDir = base.getCanonicalFile();

    if (!isWorkspace(baseDir)) {
        return baseDir;
    }

    Properties properties = getWorkspaceProperties();

    String modulesDirValue = (String) properties.get(WorkspaceConstants.DEFAULT_MODULES_DIR_PROPERTY);

    if (modulesDirValue == null) {
        modulesDirValue = WorkspaceConstants.DEFAULT_MODULES_DIR;
    }

    if (modulesDirValue.contains(",")) {
        bladeCLI.out("WARNING: " + WorkspaceConstants.DEFAULT_MODULES_DIR_PROPERTY + " has multiple values: "
                + modulesDirValue);
        modulesDirValue = modulesDirValue.substring(0, modulesDirValue.indexOf(","));

        bladeCLI.out("WARNING: using " + modulesDirValue);
    }

    WorkspaceProvider workspaceProvider = bladeCLI.getWorkspaceProvider(baseDir);

    File projectDir = workspaceProvider.getWorkspaceDir(baseDir);

    File modulesDir = new File(projectDir, modulesDirValue);

    if (_containsDir(baseDir, modulesDir)) {
        return baseDir;
    }

    return modulesDir;
}

From source file:org.rhq.plugins.jslee.JainSleeServerDiscoveryComponent.java

public DiscoveredResourceDetails discoverResource(Configuration pluginConfig,
        ResourceDiscoveryContext<JainSleeServerComponent> context) throws InvalidPluginConfigurationException {

    ProcessInfo processInfo = null;/*from www . java  2 s  . co m*/
    String jbossHomeDir = pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.SERVER_HOME_DIR)
            .getStringValue();

    String mobicentsJSleeHome = jbossHomeDir + File.separator + "deploy" + File.separator + "mobicents-slee";

    File mobicentsSlee = new File(mobicentsJSleeHome);

    try {
        if (!mobicentsSlee.getCanonicalFile().isDirectory()) {
            log.warn("Skipping manuall add for Mobicents JAIN SLEE Server " + mobicentsJSleeHome
                    + ", because Mobicents dir 'mobicents-slee' does not exist or is not a directory.");

        }
    } catch (IOException e) {
        log.error("Skipping discovery for Mobicents JAIN SLEE Server " + mobicentsJSleeHome
                + ", because Mobicents dir could not be canonicalized.", e);
        throw new InvalidPluginConfigurationException(e);
    }

    pluginConfig.put(new PropertySimple(MobicentsJSleeProperties.JSLEE_HOME_DIR, mobicentsJSleeHome));

    JBossInstallationInfo installInfo;
    try {
        installInfo = new JBossInstallationInfo(new File(jbossHomeDir));
    } catch (IOException e) {
        throw new InvalidPluginConfigurationException(e);
    }

    DiscoveredResourceDetails resourceDetails;
    try {
        resourceDetails = createResourceDetails(context, pluginConfig, processInfo, installInfo);
    } catch (Exception e) {
        throw new InvalidPluginConfigurationException(e);
    }
    return resourceDetails;
}

From source file:com.simiacryptus.util.io.HtmlNotebookOutput.java

@Override
public String link(@javax.annotation.Nonnull final File file, final String text) {
    @Nullable// w  w w. j  a  v  a  2s  .co  m
    String path = null;
    try {
        path = workingDir.getCanonicalFile().toPath().relativize(file.getCanonicalFile().toPath()).normalize()
                .toString().replaceAll("\\\\", "/");
    } catch (@javax.annotation.Nonnull final IOException e) {
        throw new RuntimeException(e);
    }
    return String.format("<a href=\"%s\">%s</a>", path, text);
}

From source file:kenh.xscript.elements.Include.java

@Processing
public void processFile(@Attribute(ATTRIBUTE_FILE) String file,
        @Attribute(ATTRIBUTE_LOAD_PUBLIC) boolean loadPublics,
        @Attribute(ATTRIBUTE_LOAD_METHOD) boolean loadMethods, @Attribute(ATTRIBUTE_METHODS) String methodNames)
        throws UnsupportedScriptException {
    File f = null;
    try {/*from   www  .  jav a  2 s  . c om*/
        f = new File(file);
        if (!f.isAbsolute() && this.getEnvironment().containsVariable(Constant.VARIABLE_HOME)) {
            Object obj = this.getEnvironment().getVariable(Constant.VARIABLE_HOME);
            if (obj instanceof String)
                f = new File((String) obj, file);
        }
        f = f.getCanonicalFile();

    } catch (Exception e) {
        throw new UnsupportedScriptException(this, e);
    }

    Element element = ScriptUtils.getInstance(f, this.getEnvironment());
    if (element == null)
        throw new UnsupportedScriptException(this, "Unabled to load script. [" + f.getPath() + "]");

    handleScript(element, loadPublics, loadMethods, methodNames);
}

From source file:org.jruyi.launcher.Main.java

public void init(String[] args) throws Exception {
    ClassLoader classLoader = Main.class.getClassLoader();
    if (!(classLoader instanceof URLClassLoader))
        classLoader = new URLClassLoader(new URL[0], classLoader);

    final Method addUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
    boolean accessible = addUrl.isAccessible();
    if (!accessible)
        addUrl.setAccessible(true);/*from  w  w  w .j  a v a 2  s  .c  om*/

    final ArrayList<String> pkgList = new ArrayList<>();
    final File[] jars = getLibJars();
    for (final File jar : jars) {
        final String exportPackages;
        try (JarFile jf = new JarFile(jar)) {
            exportPackages = jf.getManifest().getMainAttributes().getValue("Export-Package");
        }
        if (exportPackages != null)
            pkgList.add(exportPackages);
        addUrl.invoke(classLoader, jar.getCanonicalFile().toURI().toURL());
    }

    if (!accessible)
        addUrl.setAccessible(false);

    final int n = pkgList.size();
    if (n < 1)
        return;

    final StringBuilder builder = new StringBuilder(pkgList.get(0));
    for (int i = 1; i < n; ++i)
        builder.append(',').append(pkgList.get(i));

    final HashMap<String, String> props = new HashMap<>(3);
    props.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, builder.toString());

    final Class<?> clazz = classLoader.loadClass("org.jruyi.system.main.Ruyi");
    final Object ruyi = clazz.getMethod("getInstance").invoke(null);
    clazz.getMethod("setProperties", Map.class).invoke(ruyi, props);
    final String instConfUrl = (String) clazz.getMethod(RUYI_PROPERTY, String.class).invoke(ruyi,
            JRUYI_INST_CONF_URL);

    System.setProperty(ShutdownCallbackRegistry.SHUTDOWN_CALLBACK_REGISTRY, Log4jCallback.class.getName());
    final String confFile = System.getProperty(LOG4J_CONF);
    if (confFile == null || confFile.trim().isEmpty())
        System.setProperty(LOG4J_CONF, instConfUrl + "log4j2.xml");

    m_ruyi = ruyi;
}

From source file:com.wrightfully.sonar.plugins.dotnet.resharper.ReSharperResultParser.java

private void createViolation(SMInputCursor violationsCursor, Rule currentRule) throws XMLStreamException {
    String relativeFilePath = violationsCursor.getAttrValue("File");

    //Paths in the resharper results file are relative to the Solution file
    LOG.debug("createViolation for relativePath: " + relativeFilePath);
    File sourceFile = new File(vsSolution.getSolutionDir(), relativeFilePath);

    final org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.fromIOFile(sourceFile, project);

    try {/*  w  w w.j  av a 2s .c o  m*/
        LOG.debug("searching for sourceFile " + sourceFile.getCanonicalFile().getPath() + " - Exists: "
                + sourceFile.exists());
    } catch (Exception ex) {
        LOG.warn("Exception: " + ex.getMessage());
    }

    if (context.isExcluded(sonarFile)) {
        LOG.debug("File is marked as excluded, so not reporting violation: {}", sonarFile.getName());
    } else if (includeAllFiles || vsProject.contains(sourceFile)) {
        IssueModel issue = new IssueModel(violationsCursor);
        greetVisitors(issue);
        ReSharperViolation violationBuilder = new ReSharperViolation(context, project, vsProject);
        violationBuilder.createFileOrProjectViolation(violationsCursor, currentRule, sourceFile);
    } else {
        LOG.debug("Violation not being saved for unsupported file {}", sourceFile.getName());
    }

}

From source file:org.ops4j.pax.runner.platform.ZipJavaRunner.java

/**
 * {@inheritDoc}//from   www.  ja  v  a  2s.  c o m
 */
public void exec(final String[] vmOptions, final String[] classpath, final String mainClass,
        final String[] programOptions, final String javaHome, final File workingDir,
        String[] environmentVariables) throws PlatformException {
    super.exec(vmOptions, classpath, mainClass, programOptions, javaHome, workingDir, environmentVariables);
    LOG.info("Now writing distribution zip..");
    ZipOutputStream dest = null;
    try {
        File destFile = new File("paxrunner-" + workingDir.getName() + ".zip");
        dest = new ZipOutputStream(new FileOutputStream(destFile));
        int baseIdx = workingDir.getCanonicalFile().getParentFile().getCanonicalPath().length() + 1;
        add(baseIdx, workingDir, dest);
        // delete folder:
        workingDir.deleteOnExit();
        LOG.info("Distribution written: " + destFile.getName());
    } catch (FileNotFoundException e) {
        throw new PlatformException(e.getMessage(), e);
    } catch (IOException e) {
        throw new PlatformException(e.getMessage(), e);
    } finally {
        try {
            if (dest != null) {
                dest.close();
            }
        } catch (IOException e) {
            // quiet.
        }
    }
}

From source file:org.sonar.dotnet.tools.commons.visualstudio.VisualStudioProject.java

/**
 * Sets the root directory of the project. For a regular project, this is where is located the csproj file.
 * /*from   w  ww  .  j a  v  a 2 s. c om*/
 * @param directory
 *          The directory to set.
 */
void setDirectory(File directory) {
    try {
        this.directory = directory.getCanonicalFile();
    } catch (IOException e) {
        LOG.warn("Invalid project directory : " + directory);
    }
}

From source file:org.sonar.dotnet.tools.commons.visualstudio.VisualStudioProject.java

/**
 * Checks if the project contains a given source file.
 * /*from w w  w .  j  ava2 s.  c om*/
 * @param file
 *          the file to check
 * @return <code>true</code> if the project contains the file
 */
public boolean contains(File file) {
    try {
        File currentFile = file.getCanonicalFile();
        // We ensure the source files are loaded
        getSourceFiles();
        return sourceFileMap.containsKey(currentFile);
    } catch (IOException e) {
        LOG.debug("file error", e);
    }

    return false;
}