List of usage examples for org.eclipse.jdt.core JavaCore newVariableEntry
public static IClasspathEntry newVariableEntry(IPath variablePath, IPath variableSourceAttachmentPath, IPath sourceAttachmentRootPath)
CPE_VARIABLE
for the given path. From source file:ariba.ideplugin.eclipse.wizards.CreateProject.java
License:Apache License
public void updateClasspath(IJavaProject proj, File root, String projectName, IProgressMonitor monitor) { try {// ww w. j av a 2 s.c o m File buildFile = new File(root, "build.xml"); List<String> paths = _connector.getRequiredLibs(buildFile); IClasspathEntry jreEntry = JavaCore .newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); IClasspathEntry srcEntry = JavaCore.newSourceEntry(new Path("/" + projectName)); ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(srcEntry); entries.add(jreEntry); String awhome = new File(_connector.getAWHome()).getCanonicalPath(); String fileSeperator = System.getProperty("file.separator"); int len = awhome.endsWith(fileSeperator) ? awhome.length() - 1 : awhome.length(); for (int i = 0; i < paths.size(); i++) { String path = new File(paths.get(i)).getCanonicalPath(); if (path.startsWith(awhome)) { path = Activator.ClasspathAWHome + path.substring(len); } if (fileSeperator.equals("\\") && path.indexOf('\\') > -1) { path = path.replace('\\', '/'); } if (path.endsWith(".jar") || path.endsWith(".zip")) { Path src = null; if (paths.get(i).indexOf("ariba.appcore") > -1) { src = new Path(Activator.ClasspathAWHome + "/lib/ariba.appcore-src.jar"); } else if (paths.get(i).indexOf("ariba.") > -1) { src = new Path(Activator.ClasspathAWHome + "/lib/ariba.aw-all-src.jar"); } if (path.startsWith(Activator.ClasspathAWHome)) { entries.add(JavaCore.newVariableEntry(new Path(path), src, null)); } else { entries.add(JavaCore.newLibraryEntry(new Path(path), src, null)); } } } IClasspathEntry[] centries = new IClasspathEntry[entries.size()]; proj.setRawClasspath(entries.toArray(centries), monitor); } catch (JavaModelException e) { throw new WrapperRuntimeException(e); } catch (IOException e) { throw new WrapperRuntimeException(e); } }
From source file:at.spardat.xma.gui.projectw.cp.BasicClassPathProvider.java
License:Open Source License
public IClasspathEntry[] provideCP() { if (cpEntries == null) { ClassPathConfig config = ClassPathConfig.getInstance(); cpEntries = new IClasspathEntry[config.getCPEntryCount()]; int i = 0; for (Iterator it = config.getCPEnum(); it.hasNext(); i++) { String key = (String) it.next(); cpEntries[i] = JavaCore.newVariableEntry(new Path(config.getCPEntry(key)), new Path(config.getSrcEntry(key)), null); }// w w w. jav a2s . c o m } return cpEntries; }
From source file:ca.mcgill.sable.soot.examples.NewSootExampleWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean performFinish = super.performFinish(); if (performFinish) { IJavaProject newProject = (IJavaProject) getCreatedElement(); try {// w ww . j av a 2s . co m IClasspathEntry[] originalCP = newProject.getRawClasspath(); IClasspathEntry ajrtLIB = JavaCore.newVariableEntry( new Path(SootClasspathVariableInitializer.VARIABLE_NAME_CLASSES), new Path(SootClasspathVariableInitializer.VARIABLE_NAME_SOURCE), null); // Update the raw classpath with the new entry int originalCPLength = originalCP.length; IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1]; System.arraycopy(originalCP, 0, newCP, 0, originalCPLength); newCP[originalCPLength] = ajrtLIB; newProject.setRawClasspath(newCP, new NullProgressMonitor()); } catch (JavaModelException e) { } String templateFilePath = fromFile; InputStream is = null; FileOutputStream fos = null; try { is = SootPlugin.getDefault().getBundle().getResource(templateFilePath).openStream(); if (is == null) { new RuntimeException("Resource " + templateFilePath + " not found!").printStackTrace(); } else { IClasspathEntry[] resolvedClasspath = newProject.getResolvedClasspath(true); IClasspathEntry firstSourceEntry = null; for (IClasspathEntry classpathEntry : resolvedClasspath) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { firstSourceEntry = classpathEntry; break; } } if (firstSourceEntry != null) { IPath path = SootPlugin.getWorkspace().getRoot().getFile(firstSourceEntry.getPath()) .getLocation(); String srcPath = path.toString(); String newfileName = toFile; final IPath newFilePath = firstSourceEntry.getPath().append(newfileName); fos = new FileOutputStream(srcPath + File.separator + newfileName); int temp = is.read(); while (temp > -1) { fos.write(temp); temp = is.read(); } fos.close(); //refresh project newProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); final IWorkbenchPage activePage = JavaPlugin.getActivePage(); if (activePage != null) { final Display display = getShell().getDisplay(); if (display != null) { display.asyncExec(new Runnable() { public void run() { try { IResource newResource = SootPlugin.getWorkspace().getRoot() .findMember(newFilePath); IDE.openEditor(activePage, (IFile) newResource, true); } catch (PartInitException e) { JavaPlugin.log(e); } } }); } } } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); if (fos != null) fos.close(); } catch (IOException e) { } } } return performFinish; }
From source file:com.google.gdt.eclipse.designer.core.util.UtilsTest.java
License:Open Source License
/** * Test for {@link Utils#getGWTLocation(IProject)}.<br> * Use <code>GWT_HOME</code> variable in classpath. *///ww w.ja v a 2 s. co m @DisposeProjectAfter public void test_getGWTLocation_from_GWT_HOME() throws Exception { // recreate project, so it will not use any gwt-user.jar at all do_projectDispose(); do_projectCreate(); // use GWT_HOME variable { IJavaProject javaProject = m_testProject.getJavaProject(); IClasspathEntry entry = JavaCore.newVariableEntry(new Path("GWT_HOME/gwt-user.jar"), null, null); ProjectUtils.addClasspathEntry(javaProject, entry); } // do check String location_20 = GTestUtils.getLocation_20(); Activator.getStore().setValue(Constants.P_GWT_LOCATION, location_20); assertEquals(location_20, Utils.getGWTLocation(m_project)); assertEquals(location_20 + "/gwt-user.jar", Utils.getUserLibPath(m_project).toPortableString()); }
From source file:com.google.gdt.eclipse.designer.wizards.model.project.ProjectWizard.java
License:Open Source License
/** * Configures given {@link IJavaProject} as GWT project - adds GWT library and nature. *//* www .j a va 2 s .c om*/ public static final void configureProjectAsGWTProject(IJavaProject javaProject) throws Exception { IProject project = javaProject.getProject(); // add GWT classpath if (!ProjectUtils.hasType(javaProject, "com.google.gwt.core.client.GWT")) { IClasspathEntry entry; if (Utils.hasGPE()) { entry = JavaCore.newContainerEntry(new Path("com.google.gwt.eclipse.core.GWT_CONTAINER")); } else { entry = JavaCore.newVariableEntry(new Path("GWT_HOME/gwt-user.jar"), null, null); } ProjectUtils.addClasspathEntry(javaProject, entry); } // add GWT nature { ProjectUtils.addNature(project, Constants.NATURE_ID); if (Utils.hasGPE()) { ProjectUtils.addNature(project, "com.google.gwt.eclipse.core.gwtNature"); } } // continue { String webFolderName = WebUtils.getWebFolderName(project); // create folders ensureCreateFolder(project, webFolderName); ensureCreateFolder(project, webFolderName + "/WEB-INF"); IFolder classesFolder = ensureCreateFolder(project, webFolderName + "/WEB-INF/classes"); IFolder libFolder = ensureCreateFolder(project, webFolderName + "/WEB-INF/lib"); // set output javaProject.setOutputLocation(classesFolder.getFullPath(), null); // copy gwt-servlet.jar if (!libFolder.getFile("gwt-servlet.jar").exists()) { String servletJarLocation = Utils.getGWTLocation(project) + "/gwt-servlet.jar"; File srcFile = new File(servletJarLocation); File destFile = new File(libFolder.getLocation().toFile(), "gwt-servlet.jar"); FileUtils.copyFile(srcFile, destFile); libFolder.refreshLocal(IResource.DEPTH_INFINITE, null); } } }
From source file:com.liferay.ide.core.util.RuntimeClasspathModel.java
License:Open Source License
public IClasspathEntry[] getEntries(int type, ILaunchConfiguration config) { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); // if( type == BOOTSTRAP ) // {/*from w ww . j av a2 s . com*/ // for( Object entry : bootstrapEntries ) // { // System.out.println(entry); // } // } /*else*/ if (type == USER) { for (Object entry : userEntries) { if (entry instanceof VariableClasspathEntry) { VariableClasspathEntry runtimeClasspathEntry = (VariableClasspathEntry) entry; IClasspathEntry newEntry = JavaCore .newLibraryEntry(new Path(runtimeClasspathEntry.getVariableString()), null, null); entries.add(newEntry); } else if (entry instanceof IRuntimeClasspathEntry2) { IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2) entry; try { IRuntimeClasspathEntry[] runtimeEntries = entry2.getRuntimeClasspathEntries(config); for (IRuntimeClasspathEntry e : runtimeEntries) { IClasspathEntry newEntry = null; if (e.getType() == IRuntimeClasspathEntry.VARIABLE) { newEntry = JavaCore.newLibraryEntry(e.getPath(), null, null); } else if (e.getType() == IRuntimeClasspathEntry.ARCHIVE) { newEntry = JavaCore.newLibraryEntry(e.getPath(), null, null); } else if (e instanceof VariableClasspathEntry) { VariableClasspathEntry vce = (VariableClasspathEntry) e; newEntry = JavaCore.newLibraryEntry(new Path(vce.getVariableString()), null, null); } if (newEntry != null) { entries.add(newEntry); } } } catch (CoreException e) { LiferayCore.logError("error creating runtime classpath entry", e); //$NON-NLS-1$ } } else if (entry instanceof IRuntimeClasspathEntry) { IRuntimeClasspathEntry rEntry = (IRuntimeClasspathEntry) entry; IClasspathEntry newEntry = null; if (rEntry.getType() == IRuntimeClasspathEntry.VARIABLE) { newEntry = JavaCore.newVariableEntry(rEntry.getPath(), null, null); } else if (rEntry.getType() == IRuntimeClasspathEntry.ARCHIVE) { newEntry = JavaCore.newLibraryEntry(rEntry.getPath(), null, null); } else { System.out.println(rEntry.getType()); } if (newEntry != null) { entries.add(newEntry); } } else { System.out.println(entry); } } } return entries.toArray(new IClasspathEntry[0]); }
From source file:com.liferay.poshi.ide.core.RuntimeClasspathModel.java
License:Open Source License
public IClasspathEntry[] getEntries(int type, ILaunchConfiguration config) { List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); if (type == USER) { for (Object entry : userEntries) { if (entry instanceof VariableClasspathEntry) { VariableClasspathEntry runtimeClasspathEntry = (VariableClasspathEntry) entry; IClasspathEntry newEntry = JavaCore .newLibraryEntry(new Path(runtimeClasspathEntry.getVariableString()), null, null); entries.add(newEntry);//from w w w . ja v a2 s. com } else if (entry instanceof IRuntimeClasspathEntry2) { IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2) entry; try { IRuntimeClasspathEntry[] runtimeEntries = entry2.getRuntimeClasspathEntries(config); for (IRuntimeClasspathEntry e : runtimeEntries) { IClasspathEntry newEntry = null; if (e.getType() == IRuntimeClasspathEntry.VARIABLE) { newEntry = JavaCore.newLibraryEntry(e.getPath(), null, null); } else if (e.getType() == IRuntimeClasspathEntry.ARCHIVE) { newEntry = JavaCore.newLibraryEntry(e.getPath(), null, null); } else if (e instanceof VariableClasspathEntry) { VariableClasspathEntry vce = (VariableClasspathEntry) e; newEntry = JavaCore.newLibraryEntry(new Path(vce.getVariableString()), null, null); } if (newEntry != null) { entries.add(newEntry); } } } catch (CoreException e) { PoshiCore.logError("error creating runtime classpath entry", e); //$NON-NLS-1$ } } else if (entry instanceof IRuntimeClasspathEntry) { IRuntimeClasspathEntry rEntry = (IRuntimeClasspathEntry) entry; IClasspathEntry newEntry = null; if (rEntry.getType() == IRuntimeClasspathEntry.VARIABLE) { newEntry = JavaCore.newVariableEntry(rEntry.getPath(), null, null); } else if (rEntry.getType() == IRuntimeClasspathEntry.ARCHIVE) { newEntry = JavaCore.newLibraryEntry(rEntry.getPath(), null, null); } else { System.out.println(rEntry.getType()); } if (newEntry != null) { entries.add(newEntry); } } else { System.out.println(entry); } } } return entries.toArray(new IClasspathEntry[0]); }
From source file:com.windowtester.codegen.util.BuildPathUtil.java
License:Open Source License
public static IClasspathEntry getEntry(String workspaceProject, String variable, String jarName) { IProject wsJavaProject = ResourcesPlugin.getWorkspace().getRoot().getProject(workspaceProject); IClasspathEntry entry;/*from w ww .j a v a 2s .c o m*/ if (wsJavaProject.exists()) { entry = JavaCore.newProjectEntry(wsJavaProject.getFullPath()); } else { IPath variablePath = new Path(variable); if (jarName != null) variablePath = variablePath.append(jarName); entry = JavaCore.newVariableEntry(variablePath, null, null); } return entry; }
From source file:com.windowtester.eclipse.ui.wizard.NewExampleProjectWizard.java
License:Open Source License
private void importProject(String projectName, IProgressMonitor monitor) throws CoreException { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(null);/*from w w w . j a v a2 s . com*/ project.create(description, new SubProgressMonitor(monitor, 1)); project.open(new SubProgressMonitor(monitor, 1)); // Direct ECLIPSE_HOME references are different each Eclipse installation // so adjust the classpath accordingly IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); boolean modified = false; for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) continue; IPath path = entry.getPath(); if (path.segmentCount() != 3) continue; if (!path.segment(0).equals("ECLIPSE_HOME")) continue; if (!path.segment(1).equals("plugins")) continue; String jarName = path.segment(2); path = path.removeLastSegments(1); IPath pluginsPath = JavaCore.getResolvedVariablePath(path); if (pluginsPath == null) { Logger.log("Failed to resolve " + path); continue; } File pluginsDir = pluginsPath.toFile(); String jarPrefix = jarName.substring(0, jarName.indexOf('_') + 1); String[] childNames = pluginsDir.list(); if (childNames == null) { Logger.log("Failed to obtain children for " + pluginsDir.getPath()); continue; } for (int j = 0; j < childNames.length; j++) { String name = childNames[j]; if (name.startsWith(jarPrefix)) { modified = true; classpath[i] = JavaCore.newVariableEntry(path.append(name), null, null); break; } } } if (modified) javaProject.setRawClasspath(classpath, new NullProgressMonitor()); }
From source file:eldaEditor.dialogs.TransitionPropertiesInputDialog.java
License:Open Source License
private List fillExceptionCombo(Combo exceptionComnbo) { List exceptionList = new ArrayList<String>(); // creo il javaProject IJavaProject jProject = JavaCore.create(project); try {/*from w w w . java 2 s . com*/ // recupero il jar di actiware IPackageFragmentRoot jar = jProject.findPackageFragmentRoot(JavaCore.getResolvedVariablePath( JavaCore.newVariableEntry(CodeGenerator.frameworkPath, null, null).getPath())); for (int i = 1; i < jar.getChildren().length; i++) { IPackageFragment jarFragment = (IPackageFragment) JavaCore .create(jar.getChildren()[i].getHandleIdentifier()); if (jarFragment.getElementName().startsWith("eldaframework.eldaevent.exception")) { IClassFile[] classArray = jarFragment.getClassFiles(); for (int j = 0; j < classArray.length; j++) { String name = classArray[j].getElementName().replaceAll(".class", ""); exceptionComnbo.add(name); exceptionList.add(name); } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return exceptionList; }