List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:gov.redhawk.ide.codegen.java.JavaGeneratorUtils.java
License:Open Source License
/** * @deprecated The code in {@link #addRedhawkJavaClassPaths} will correctly include all of the .jar files * @param jproject//from ww w . j ava 2 s.c o m * @param ports * @param monitor * @throws CoreException */ @Deprecated public static void addRedhawkPortClassPaths(final IJavaProject jproject, final Ports ports, final IProgressMonitor monitor) throws CoreException { final Set<String> packages = new LinkedHashSet<String>(); for (final Provides p : ports.getProvides()) { final String[] ints = p.getRepID().split(":")[1].split("/"); packages.add(ints[ints.length - 2]); } for (final Uses u : ports.getUses()) { final String[] ints = u.getRepID().split(":")[1].split("/"); packages.add(ints[ints.length - 2]); } final SubMonitor progress = SubMonitor.convert(monitor, packages.size() + 1); final Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>( Arrays.asList(jproject.getRawClasspath())); for (final String pack : packages) { final String jarFile = "OSSIEHOME/lib/" + pack + "Interfaces.jar"; final IClasspathEntry e = JavaCore.newVariableEntry(new Path(jarFile), null, null); if (!entries.contains(e)) { entries.add(e); } progress.worked(1); } jproject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), progress.newChild(1)); }
From source file:gov.redhawk.ide.codegen.java.JavaGeneratorUtils.java
License:Open Source License
public static void addSourceClassPaths(final IJavaProject jproject, final IPath srcPath, final IPath binPath, final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 1); final Set<IClasspathEntry> entries = new LinkedHashSet<IClasspathEntry>( Arrays.asList(jproject.getRawClasspath())); // Add source code to the java project classpath for (final IClasspathEntry path : entries) { if ((path.getEntryKind() == IClasspathEntry.CPE_SOURCE) && path.getPath().equals(jproject.getProject().getFullPath())) { continue; }// w ww. j a v a 2s . c o m entries.add(path); } final IClasspathEntry e = JavaCore.newSourceEntry(srcPath, new Path[0], binPath); entries.add(e); jproject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), progress.newChild(1)); }
From source file:gov.redhawk.ide.codegen.jet.java.template.StartJavaShTemplate.java
License:Open Source License
/** * {@inheritDoc}//from w ww . java2 s . c o m */ public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); JavaTemplateParameter template = (JavaTemplateParameter) argument; ImplementationSettings implSettings = template.getImplSettings(); Implementation impl = template.getImpl(); SoftPkg softPkg = (SoftPkg) impl.eContainer(); IResource resource = ModelUtil.getResource(implSettings); IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); String implName = gov.redhawk.ide.codegen.util.CodegenFileHelper.safeGetImplementationName(impl, implSettings); String jarPrefix = gov.redhawk.ide.codegen.util.CodegenFileHelper.getPreferredFilePrefix(softPkg, implSettings); String pkg = template.getPackage(); String mainClass = gov.redhawk.ide.codegen.jet.java.JavaGeneratorProperties.getMainClass(impl, implSettings); String projDir = "/" + project.getName() + "/" + implSettings.getOutputDir(); String libs = ""; String vars = ""; try { for (final IClasspathEntry path : javaProject.getRawClasspath()) { if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { final String lib = path.getPath().toString(); libs += lib.replaceAll(projDir, "\\$myDir") + ":"; } else if (path.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { vars += "$" + path.getPath().toString() + ":"; } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } stringBuffer.append(TEXT_1); stringBuffer.append(libs); stringBuffer.append(TEXT_2); stringBuffer.append(vars); stringBuffer.append(TEXT_3); stringBuffer.append(jarPrefix); stringBuffer.append(TEXT_4); stringBuffer.append(mainClass); stringBuffer.append(TEXT_5); stringBuffer.append(libs); stringBuffer.append(TEXT_6); stringBuffer.append(vars); stringBuffer.append(TEXT_7); stringBuffer.append(jarPrefix); stringBuffer.append(TEXT_8); stringBuffer.append(mainClass); stringBuffer.append(TEXT_9); stringBuffer.append(TEXT_10); return stringBuffer.toString(); }
From source file:hydrograph.ui.expression.editor.composites.CategoriesDialogSourceComposite.java
License:Apache License
private void createBrowseButton(Composite headerComposite) { Button browseButton = new Button(headerComposite, SWT.NONE); browseButton.setText("Browse"); browseButton.setToolTipText(Messages.EXTERNAL_JAR_DIALOG_BROWSE_BUTTON_TOOLTIP); browseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IFolder libsFolder = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject() .getFolder(PathConstant.PROJECT_LIB_FOLDER); FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OK); dialog.setFilterExtensions(filters); String path = dialog.open(); if (path != null) { File file = new File(path); if (file.isFile()) { IFile newFile = libsFolder.getFile(file.getName()); if (!newFile.exists()) { try (InputStream fis = new FileInputStream(file.getAbsoluteFile())) { newFile.create(fis, true, null); addFileToBuildPath(newFile); loadComboJarListFromBuildPath(comboJarList, newFile.getName()); } catch (CoreException | IOException e1) { LOGGER.error( "Exception occurred while copying jar file from local-file-system to project", e1); new CustomMessageBox(SWT.ERROR, Messages.JAR_FILE_COPY_ERROR, Messages.ERROR_TITLE) .open(); }/*from w ww. j a va2 s .c om*/ } else { new CustomMessageBox(SWT.ERROR, Messages.DUPLICATE_JAR_FILE_COPY_ERROR, Messages.ERROR_TITLE).open(); } } } } private void addFileToBuildPath(IFile jarFile) throws CoreException { LOGGER.error("Adding jar file " + jarFile.getName() + " to build Path"); IJavaProject javaProject = JavaCore .create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()); IClasspathEntry[] oldClasspathEntry = javaProject.getRawClasspath(); IClasspathEntry[] newClasspathEntry = new IClasspathEntry[oldClasspathEntry.length + 1]; for (int index = 0; index < oldClasspathEntry.length; index++) { if (oldClasspathEntry[index].getPath().equals(jarFile.getFullPath())) return; newClasspathEntry[index] = javaProject.getRawClasspath()[index]; } newClasspathEntry[oldClasspathEntry.length] = JavaCore.newLibraryEntry(jarFile.getFullPath(), null, null); javaProject.setRawClasspath(newClasspathEntry, new NullProgressMonitor()); javaProject.close(); } }); }
From source file:hydrograph.ui.expression.editor.composites.CategoriesDialogSourceComposite.java
License:Apache License
private void createDelButton(Composite headerComposite) { deleteButton = new Button(headerComposite, SWT.NONE); deleteButton.setBounds(0, 0, 75, 25); deleteButton.setToolTipText(Messages.EXTERNAL_JAR_DIALOG_DELETE_BUTTON_TOOLTIP); try {/*from w ww . ja va 2 s. c o m*/ deleteButton.setImage(ImagePathConstant.DELETE_BUTTON.getImageFromRegistry()); } catch (Exception exception) { LOGGER.error("Exception occurred while attaching image to button", exception); deleteButton.setText("Delete"); } deleteButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { if (comboJarList.getSelectionIndex() > -1) { String jarName = comboJarList.getItem(comboJarList.getSelectionIndex()); if (userIsSure(jarName)) { try { removeJarFromBuildPath(jarName); comboJarList.remove(jarName); sourcePackageList.removeAll(); refresh(jarName); enableOrDisableAddLabelsOnComboSelection(); } catch (CoreException e1) { LOGGER.error( "Exception occurred while removing jar file" + jarName + "from build Path"); } } } } private boolean userIsSure(String jarName) { MessageBox messageBox = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); messageBox.setMessage("Do you really want to remove " + jarName + " file?\nCannot be undone."); messageBox.setText("Remove Resource"); int response = messageBox.open(); if (response == SWT.YES) return true; return false; } private void refresh(String jarName) { boolean isAnyItemRemovedFromTargetList = false; String[] items = targetComposite.getTargetList().getItems(); targetComposite.getTargetList().removeAll(); for (String item : items) { String jarFileName = StringUtils.trim(StringUtils.substringAfter(item, Constants.DASH)); if (!StringUtils.equalsIgnoreCase(jarFileName, jarName)) { targetComposite.getTargetList().add(item); } else isAnyItemRemovedFromTargetList = true; } if (isAnyItemRemovedFromTargetList) { addCategoreisDialog.createPropertyFileForSavingData(); } } private void removeJarFromBuildPath(String jarName) throws CoreException { LOGGER.debug("Removing jar file" + jarName + "from build Path"); IJavaProject javaProject = JavaCore .create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()); IFile jarFile = javaProject.getProject().getFolder(PathConstant.PROJECT_LIB_FOLDER) .getFile(jarName); IClasspathEntry[] oldClasspathEntry = javaProject.getRawClasspath(); IClasspathEntry[] newClasspathEntry = new IClasspathEntry[oldClasspathEntry.length - 1]; if (jarFile.exists()) { int index = 0; for (IClasspathEntry classpathEntry : oldClasspathEntry) { if (classpathEntry.getPath().equals(jarFile.getFullPath())) { continue; } newClasspathEntry[index] = classpathEntry; index++; } javaProject.setRawClasspath(newClasspathEntry, new NullProgressMonitor()); jarFile.delete(true, new NullProgressMonitor()); } javaProject.close(); } @Override public void widgetDefaultSelected(SelectionEvent e) {/* Do-Nothing */ } }); }
From source file:hydrograph.ui.expression.editor.launcher.LaunchExpressionEditor.java
License:Apache License
private void addClassPathEntry(IPath tempSrcFolder) throws JavaModelException { IJavaProject javaProject = JavaCore.create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()); oldClasspathEntry = javaProject.getRawClasspath(); IClasspathEntry[] newClasspathEntry = new IClasspathEntry[oldClasspathEntry.length + 1]; for (int index = 0; index < newClasspathEntry.length - 1; index++) { if (oldClasspathEntry[index].getPath().equals(tempSrcFolder)) return; newClasspathEntry[index] = javaProject.getRawClasspath()[index]; }// w ww . j a v a 2s . co m newClasspathEntry[newClasspathEntry.length - 1] = JavaCore.newSourceEntry(tempSrcFolder); javaProject.setRawClasspath(newClasspathEntry, new NullProgressMonitor()); }
From source file:hydrograph.ui.project.structure.wizard.ProjectStructureCreator.java
License:Apache License
/** * Sets the <b>src</b> folder as the source folder in project * @param project/*from w w w .j av a 2 s . c om*/ * @param javaProject * @return IClasspathEntry[] * @throws JavaModelException */ private IClasspathEntry[] setSourceFolderInClassPath(IProject project, IJavaProject javaProject) throws JavaModelException { IFolder sourceFolder = project.getFolder(Constants.ProjectSupport_SRC); //$NON-NLS-1$ IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); return newEntries; }
From source file:in.cypal.studio.gwt.core.common.Util.java
License:Apache License
/** * @param file/*from www . j ava 2 s. c o m*/ * @return */ private static String[] getSegmentsFromSourceFolder(IFile file) { int removeCount = 1;// by default, just remove the source folder; try { IJavaProject javaProject = JavaCore.create(file.getProject()); IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (int i = 0; i < classpathEntries.length; i++) { if (classpathEntries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) continue;// we are interested only in source folders IPath path = classpathEntries[i].getPath(); if (path.isPrefixOf(file.getFullPath())) { removeCount = path.segmentCount() - 1; } } } catch (Throwable e) { Activator.logException(new Exception(e)); } IPath filePath = file.getProjectRelativePath().removeFirstSegments(removeCount); return filePath.segments(); }
From source file:in.cypal.studio.gwt.core.facet.InstallDelegate.java
License:Apache License
public static void addUserLibToClassPath(IProject project, IProgressMonitor monitor) { monitor = Util.getNonNullMonitor(monitor); try {/*from www. j a va 2 s . co m*/ IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1]; System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length); IClasspathEntry gwtuserJarEntry = JavaCore.newVariableEntry(Util.getGwtUserLibPath(), null, null); gwtuserJarEntry = JavaCore.newVariableEntry(gwtuserJarEntry.getPath(), null, null, new IAccessRule[0], new IClasspathAttribute[0], false); newClasspath[oldClasspath.length] = gwtuserJarEntry; javaProject.setRawClasspath(newClasspath, monitor); } catch (CoreException e) { // the jar is already in the classpath. Activator.logException(e); } finally { monitor.done(); } }
From source file:in.cypal.studio.gwt.core.facet.InstallDelegate.java
License:Apache License
public static void addServletLibToWebInf(IProject project, IProgressMonitor monitor) { monitor = Util.getNonNullMonitor(monitor); try {// www . j a v a2s . c o m monitor.beginTask("", 1); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1]; System.arraycopy(oldClasspath, 0, newClasspath, 0, oldClasspath.length); IClasspathEntry gwtServletJarEntry = JavaCore.newVariableEntry(Util.getGwtServletLibPath(), null, null); IClasspathAttribute attr = JavaCore.newClasspathAttribute("org.eclipse.jst.component.dependency", "/WEB-INF/lib"); gwtServletJarEntry = JavaCore.newVariableEntry(gwtServletJarEntry.getPath(), null, null, new IAccessRule[0], new IClasspathAttribute[] { attr }, false); newClasspath[oldClasspath.length] = gwtServletJarEntry; javaProject.setRawClasspath(newClasspath, monitor); } catch (JavaModelException e) { // the jar is already in the classpath. Activator.logException(e); } finally { monitor.done(); } }