use of org.eclipse.core.runtime.IPath in project generator by mybatis.
the class MyBatisGeneratorClasspathResolver method getGeneratorPath.
public static IPath getGeneratorPath() {
//$NON-NLS-1$
Bundle bundle = Platform.getBundle("org.mybatis.generator.core");
if (bundle == null) {
return null;
}
try {
//$NON-NLS-1$
URL devPath = bundle.getEntry("bin/");
File fullPath;
if (devPath != null) {
devPath = FileLocator.toFileURL(devPath);
fullPath = new File(devPath.toURI());
} else {
fullPath = FileLocator.getBundleFile(bundle);
}
return new Path(fullPath.getAbsolutePath());
} catch (IOException e) {
return null;
} catch (URISyntaxException e) {
return null;
}
}
use of org.eclipse.core.runtime.IPath in project generator by mybatis.
the class RunGeneratorThread method setClassLoader.
private void setClassLoader() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IJavaProject javaProject = getJavaProject();
try {
if (javaProject != null) {
List<URL> entries = new ArrayList<URL>();
IPath path = javaProject.getOutputLocation();
IResource iResource = root.findMember(path);
path = iResource.getLocation();
path = path.addTrailingSeparator();
entries.add(path.toFile().toURI().toURL());
IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
for (IClasspathEntry cpEntry : cpEntries) {
switch(cpEntry.getEntryKind()) {
case IClasspathEntry.CPE_SOURCE:
path = cpEntry.getOutputLocation();
if (path != null) {
iResource = root.findMember(path);
path = iResource.getLocation();
path = path.addTrailingSeparator();
entries.add(path.toFile().toURI().toURL());
}
break;
case IClasspathEntry.CPE_LIBRARY:
iResource = root.findMember(cpEntry.getPath());
if (iResource == null) {
// resource is not in workspace, must be an external JAR
path = cpEntry.getPath();
} else {
path = iResource.getLocation();
}
entries.add(path.toFile().toURI().toURL());
break;
}
}
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
URL[] entryArray = new URL[entries.size()];
entries.toArray(entryArray);
ClassLoader newCl = new URLClassLoader(entryArray, oldCl);
Thread.currentThread().setContextClassLoader(newCl);
oldClassLoader = oldCl;
}
} catch (Exception e) {
// ignore - something too complex is wrong
;
}
}
use of org.eclipse.core.runtime.IPath in project mechanoid by robotoworks.
the class MechanoidLibsInstaller method installLibs.
protected void installLibs(IJavaProject javaProject, IProgressMonitor monitor) throws URISyntaxException, IOException, CoreException {
Bundle bundle = Platform.getBundle(ANDROID_LIBS_PLUGIN_RESOURCE_BUNDLE);
IPath location = javaProject.getProject().getLocation();
File libsFolder = new File(location.toOSString(), ANDROID_LIBS_DIR_NAME);
if (!libsFolder.exists()) {
libsFolder.mkdirs();
}
for (String libFileName : LIB_FILE_BUNDLE_PATHS) {
final URL url = FileLocator.resolve(bundle.getEntry(MECHANOID_LIB_PATH + libFileName));
File targetFile = new File(libsFolder, libFileName);
if (targetFile.exists()) {
targetFile.delete();
}
Files.copy(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return url.openStream();
}
}, targetFile);
}
javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
use of org.eclipse.core.runtime.IPath in project mechanoid by robotoworks.
the class NewMechanoidElementWizard method performFinish.
@Override
public boolean performFinish() {
final IPath newFilePath = createNewResourceFilePath();
onBeforeCreateElementResource();
WorkspaceModifyDelegatingOperation op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
mNewResource = createElementResource(monitor, newFilePath);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
});
try {
getContainer().run(true, true, op);
selectAndReveal(mNewResource);
openResource(mNewResource);
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), Messages.NewMechanoidElementWizard_Dialog_CreateResourceError_Title, realException.getMessage());
return false;
} catch (InterruptedException e) {
return false;
}
return true;
}
use of org.eclipse.core.runtime.IPath in project mechanoid by robotoworks.
the class ContainerBrowserField method onTextChanged.
@Override
protected void onTextChanged(ModifyEvent e) {
super.onTextChanged(e);
mSelectedPath = Path.fromPortableString(getTextField().getText());
if (mSelectedPath.segmentCount() > 0) {
IPath firstPart = mSelectedPath.uptoSegment(1);
IContainer container = (IContainer) mWorkspaceRoot.findMember(firstPart);
if (container != null && container instanceof IProject) {
mSelectedProject = (IProject) container;
} else {
mSelectedProject = null;
}
}
}
Aggregations