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;
}
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;
}
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;
}
}
}
}
}
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;
}
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;
}
Aggregations