Search in sources :

Example 6 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class Util method loadProperties.

/**
     * Loads the properties from file.
     * 
     * @param filePath The file path
     * @return The properties, or <tt>null</tt> if loading properties fails
     */
public static Properties loadProperties(IPath filePath) {
    Properties props = new Properties();
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(filePath);
    try {
        InputStream in = fileStore.openInputStream(EFS.NONE, null);
        props.loadFromXML(in);
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(org.talend.designer.runtime.visualization.Messages.openInputStreamFailedMsg, filePath.toOSString()), e);
        return null;
    } catch (IOException e) {
        Activator.log(IStatus.ERROR, NLS.bind(org.talend.designer.runtime.visualization.Messages.loadPropertiesFileFailedMsg, filePath.toOSString()), e);
        return null;
    }
    return props;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Properties(java.util.Properties)

Example 7 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class CpuProfiler method dump.

/*
     * @see ICpuProfiler#dump()
     */
@Override
public IFileStore dump() throws JvmCoreException {
    String dump = cpuModel.getCpuDumpString(//$NON-NLS-1$
    jvm.getPid() + "@" + jvm.getHost().getName(), jvm.getMainClass(), jvm.getMBeanServer().getJvmArguments());
    StringBuffer fileName = new StringBuffer();
    fileName.append(new Date().getTime()).append('.').append(SnapshotType.Cpu.getExtension());
    IFileStore fileStore = Util.getFileStore(fileName.toString(), jvm.getBaseDirectory());
    // restore the terminated JVM if already removed
    AbstractJvm abstractJvm = jvm;
    if (!((Host) jvm.getHost()).getJvms().contains(jvm)) {
        jvm.saveJvmProperties();
        abstractJvm = (AbstractJvm) ((Host) jvm.getHost()).addTerminatedJvm(jvm.getPid(), jvm.getPort(), jvm.getMainClass());
    }
    OutputStream os = null;
    try {
        os = fileStore.openOutputStream(EFS.NONE, null);
        os.write(dump.getBytes());
        Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
        abstractJvm.addSnapshot(snapshot);
        JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, jvm, snapshot));
    } catch (CoreException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.dumpCpuProfileDataFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return fileStore;
}
Also used : Snapshot(org.talend.designer.runtime.visualization.internal.core.Snapshot) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) AbstractJvm(org.talend.designer.runtime.visualization.internal.core.AbstractJvm) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) Host(org.talend.designer.runtime.visualization.internal.core.Host) IOException(java.io.IOException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 8 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tesb-studio-se by Talend.

the class Activator method copyConfigs.

private void copyConfigs() throws CoreException, IOException, URISyntaxException {
    // find ESB configuration files folder in plug-in
    URL esbConfigsFolderUrl = FileLocator.find(getBundle(), new Path("esb"), null);
    if (null == esbConfigsFolderUrl) {
        getLog().log(new Status(IStatus.WARNING, getBundle().getSymbolicName(), "cannot find ESB configuration files"));
        return;
    }
    // resolve plug-in ESB config folder URL into file protocol URL
    esbConfigsFolderUrl = FileLocator.toFileURL(esbConfigsFolderUrl);
    // create ESB configuration folder under Studio instalation
    IFileSystem fileSystem = EFS.getLocalFileSystem();
    IFileStore esbConfigsTargetFolder = fileSystem.getStore(EsbConfigUtils.getEclipseEsbFolder().toURI());
    esbConfigsTargetFolder = esbConfigsTargetFolder.mkdir(EFS.SHALLOW, null);
    // retrieve all ESB configuration files packed inside plug-in
    File fileEsbConfigFolder = new File(esbConfigsFolderUrl.getPath());
    IFileStore esbConfigsFolderStore = fileSystem.getStore(fileEsbConfigFolder.toURI());
    IFileStore[] esbConfigsFolderStoreChildren = esbConfigsFolderStore.childStores(EFS.NONE, null);
    if (0 == esbConfigsFolderStoreChildren.length) {
        getLog().log(new Status(IStatus.WARNING, getBundle().getSymbolicName(), "cannot find any ESB configuration files"));
        return;
    }
    // try to copy ESB configuration files (without overwriting)
    for (IFileStore esbConfigFileStore : esbConfigsFolderStoreChildren) {
        if (!esbConfigFileStore.fetchInfo().isDirectory()) {
            String esbConfigFileName = esbConfigFileStore.fetchInfo().getName();
            try {
                esbConfigFileStore.copy(esbConfigsTargetFolder.getChild(esbConfigFileName), EFS.NONE, null);
            } catch (CoreException e) {
                // ignore to do not overwrite possible user changes in configuration files
                return;
            }
        } else {
            String esbConfigFileName = esbConfigFileStore.fetchInfo().getName();
            if ("microservice".equals(esbConfigFileName) && PluginChecker.isTIS()) {
                try {
                    esbConfigFileStore.copy(esbConfigsTargetFolder.getChild(esbConfigFileName), EFS.NONE, null);
                } catch (CoreException e) {
                    // ignore to do not overwrite possible user changes in configuration files
                    return;
                }
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IFileSystem(org.eclipse.core.filesystem.IFileSystem) IFileStore(org.eclipse.core.filesystem.IFileStore) File(java.io.File) URL(java.net.URL)

Example 9 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class MBeanServer method dump.

/**
     * Dumps the profile data into file.
     * 
     * @param type The snapshot type
     * @param dumpFileName The dump file name
     * @param monitor The progress monitor
     * @return The file store
     * @throws JvmCoreException
     */
private IFileStore dump(SnapshotType type, String dumpFileName, IProgressMonitor monitor) throws JvmCoreException {
    String simpleFileName;
    if (dumpFileName == null) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(new Date().getTime()).append('.').append(type.getExtension());
        simpleFileName = stringBuffer.toString();
    } else {
        simpleFileName = new File(dumpFileName).getName();
    }
    IFileStore fileStore = Util.getFileStore(simpleFileName, jvm.getBaseDirectory());
    // restore the terminated JVM if already removed
    AbstractJvm abstractJvm = jvm;
    if (!((Host) jvm.getHost()).getJvms().contains(jvm)) {
        jvm.saveJvmProperties();
        abstractJvm = (AbstractJvm) ((Host) jvm.getHost()).addTerminatedJvm(jvm.getPid(), jvm.getPort(), jvm.getMainClass());
    }
    OutputStream os = null;
    try {
        if (type == SnapshotType.Heap || type == SnapshotType.Thread) {
            String dump = getDumpString(type);
            os = fileStore.openOutputStream(EFS.NONE, null);
            os.write(dump.getBytes());
        } else if (type == SnapshotType.Hprof && jvm.isRemote()) {
            ObjectName objectName = getObjectName(DATA_TRANSFER_MXBEAN_NAME);
            os = fileStore.openOutputStream(EFS.NONE, null);
            byte[] bytes;
            int offset = 0;
            final int SIZE = 4096;
            //$NON-NLS-1$ //$NON-NLS-2$
            final String[] SIGNATURES = new String[] { String.class.getCanonicalName(), "int", "int" };
            do {
                bytes = (byte[]) invoke(objectName, "read", new Object[] { //$NON-NLS-1$
                dumpFileName, offset, SIZE }, SIGNATURES);
                os.write(bytes);
                offset += SIZE;
                if (monitor != null && monitor.isCanceled()) {
                    break;
                }
            } while (bytes.length > 0);
        }
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
        abstractJvm.addSnapshot(snapshot);
        JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, abstractJvm, snapshot));
    } catch (CoreException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.dumpFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return fileStore;
}
Also used : OutputStream(java.io.OutputStream) IHost(org.talend.designer.runtime.visualization.IHost) IOException(java.io.IOException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date) ObjectName(javax.management.ObjectName) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) File(java.io.File)

Example 10 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class MBeanServer method dumpHprof.

/*
     * @see IMBeanServer#dumpHprof(String, boolean, IProgressMonitor)
     */
@Override
public IFileStore dumpHprof(String hprofFileName, boolean transfer, IProgressMonitor monitor) throws JvmCoreException {
    if (!checkReachability()) {
        throw new JvmCoreException(IStatus.WARNING, Messages.jvmNotReachableMsg, null);
    }
    IFileStore fileStore = null;
    String fileName;
    if (jvm.isRemote()) {
        fileName = hprofFileName;
    } else {
        fileStore = dump(SnapshotType.Hprof, null, null);
        fileName = fileStore.toString();
    }
    if (monitor.isCanceled()) {
        return null;
    }
    //$NON-NLS-1$
    ObjectName objectName = jvm.getMBeanServer().getObjectName("com.sun.management:type=HotSpotDiagnostic");
    invoke(//$NON-NLS-1$
    objectName, //$NON-NLS-1$
    "dumpHeap", //$NON-NLS-1$
    new Object[] { fileName, Boolean.TRUE }, //$NON-NLS-1$
    new String[] { String.class.getCanonicalName(), "boolean" });
    if (jvm.isRemote() && transfer) {
        fileStore = dump(SnapshotType.Hprof, hprofFileName, monitor);
    }
    return fileStore;
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) ObjectName(javax.management.ObjectName)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)178 CoreException (org.eclipse.core.runtime.CoreException)80 IOException (java.io.IOException)49 IPath (org.eclipse.core.runtime.IPath)42 IFileInfo (org.eclipse.core.filesystem.IFileInfo)33 URI (java.net.URI)30 Path (org.eclipse.core.runtime.Path)30 IFile (org.eclipse.core.resources.IFile)28 PartInitException (org.eclipse.ui.PartInitException)25 File (java.io.File)22 InputStream (java.io.InputStream)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)21 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 InputStreamReader (java.io.InputStreamReader)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)14 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)14 BufferedInputStream (java.io.BufferedInputStream)13 BufferedReader (java.io.BufferedReader)13 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)11 IStatus (org.eclipse.core.runtime.IStatus)11