List of usage examples for org.eclipse.jdt.core JavaCore newLibraryEntry
public static IClasspathEntry newLibraryEntry(IPath path, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath)
CPE_LIBRARY
for the JAR or folder identified by the given absolute 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 {// www. j ava 2s. c om 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:byke.tests.workspaceutils.JavaProject.java
License:Open Source License
private void addClasspathEntry(IPath absolutePath) throws JavaModelException { IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(absolutePath, null, null); addClasspathEntry(newLibraryEntry);/* w ww .j a va 2 s . c om*/ }
From source file:ca.ubc.cs.ferret.tests.support.TestProject.java
License:Open Source License
public void addJar(Plugin plugin, String jar) throws MalformedURLException, IOException, JavaModelException { Path result = findFileInPlugin(plugin, jar); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newLibraryEntry(result, null, null); javaProject.setRawClasspath(newEntries, null); }
From source file:cn.dockerfoundry.ide.eclipse.server.core.internal.DockerFoundryRuntimeClasspathProvider.java
License:Open Source License
public IClasspathEntry[] resolveClasspathContainer(IProject project, IRuntime runtime) { List<IClasspathEntry> cp = new ArrayList<IClasspathEntry>(2); for (String id : CP_BUNDLES) { Bundle bundle = Platform.getBundle(id); try {/*w ww . jav a 2s.c o m*/ File file = FileLocator.getBundleFile(bundle); Path path = new Path(file.getCanonicalPath()); cp.add(JavaCore.newLibraryEntry(path, null, null)); } catch (IOException e) { // ignore } } return cp.toArray(new IClasspathEntry[0]); }
From source file:com.aliyun.odps.eclipse.create.wizard.ProjectNature.java
License:Apache License
/** * Configures an Eclipse project as a Map/Reduce project by adding the Hadoop libraries to a * project's classpath./*from www . j av a2 s . c om*/ */ public void configure() throws CoreException { String path = project.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "ODPS.runtime.path")); File dir = new File(path); final ArrayList<File> coreJars = new ArrayList<File>(); dir.listFiles(new FileFilter() { public boolean accept(File pathname) { String fileName = pathname.getName(); // get the hadoop core jar without touching test or examples // older version of hadoop don't use the word "core" -- eyhung if ((fileName.indexOf("hadoop") != -1) && (fileName.endsWith("jar")) && (fileName.indexOf("test") == -1) && (fileName.indexOf("examples") == -1)) { coreJars.add(pathname); } return false; // we don't care what this returns } }); File dir2 = new File(path + File.separatorChar + "lib"); if (dir2.exists() && dir2.isDirectory()) { dir2.listFiles(new FileFilter() { public boolean accept(File pathname) { if ((!pathname.isDirectory()) && (pathname.getName().endsWith("jar"))) { coreJars.add(pathname); } return false; // we don't care what this returns } }); } // Add Hadoop libraries onto classpath IJavaProject javaProject = JavaCore.create(getProject()); // Bundle bundle = Activator.getDefault().getBundle(); try { IClasspathEntry[] currentCp = javaProject.getRawClasspath(); IClasspathEntry[] newCp = new IClasspathEntry[currentCp.length + coreJars.size() + 1]; System.arraycopy(currentCp, 0, newCp, 0, currentCp.length); final Iterator<File> i = coreJars.iterator(); int count = 0; while (i.hasNext()) { // for (int i = 0; i < s_coreJarNames.length; i++) { final File f = (File) i.next(); // URL url = FileLocator.toFileURL(FileLocator.find(bundle, new // Path("lib/" + s_coreJarNames[i]), null)); URL url = f.toURI().toURL(); log.finer("hadoop library url.getPath() = " + url.getPath()); newCp[newCp.length - 2 - count] = JavaCore.newLibraryEntry(new Path(url.getPath()), null, null); count++; } // add examples to class-path IPath sourceFolderPath = new Path(javaProject.getProject().getName()).makeAbsolute(); IPath exampleSrc = sourceFolderPath.append(new Path(CONST.EXAMPLE_SRC_PATH)); IPath exampleClasses = sourceFolderPath.append(new Path(CONST.EXAMPLE_BIN)); IClasspathEntry exampleSrcEntry = JavaCore.newSourceEntry(exampleSrc, new IPath[] {}, exampleClasses); newCp[newCp.length - 1] = exampleSrcEntry; javaProject.setRawClasspath(newCp, new NullProgressMonitor()); } catch (Exception e) { log.log(Level.SEVERE, "IOException generated in " + this.getClass().getCanonicalName(), e); } }
From source file:com.android.ide.eclipse.adt.internal.actions.AddCompatibilityJarAction.java
License:Open Source License
/** * Install the compatibility jar into the given project. * * @param project The Android project to install the compatibility jar into * @param waitForFinish If true, block until the task has finished * @return true if the installation was successful (or if <code>waitForFinish</code> * is false, if the installation is likely to be successful - e.g. the user has * at least agreed to all installation prompts.) *///from www. j a v a 2 s.co m public static boolean install(final IProject project, boolean waitForFinish) { final IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { // Should not happen. AdtPlugin.log(IStatus.ERROR, "JavaProject is null for %1$s", project); //$NON-NLS-1$ } final Sdk sdk = Sdk.getCurrent(); if (sdk == null) { AdtPlugin.printErrorToConsole(AddCompatibilityJarAction.class.getSimpleName(), // tag "Error: Android SDK is not loaded yet."); //$NON-NLS-1$ return false; } // TODO: For the generic action, check the library isn't in the project already. // First call the package manager to make sure the package is installed // and get the installation path of the library. AdtUpdateDialog window = new AdtUpdateDialog(AdtPlugin.getDisplay().getActiveShell(), new AdtConsoleSdkLog(), sdk.getSdkLocation()); Pair<Boolean, File> result = window.installExtraPackage("android", "compatibility"); //$NON-NLS-1$ //$NON-NLS-2$ if (!result.getFirst().booleanValue()) { AdtPlugin.printErrorToConsole("Failed to install Android Compatibility library"); return false; } // TODO these "v4" values needs to be dynamic, e.g. we could try to match // vN/android-support-vN.jar. Eventually we'll want to rely on info from the // package manifest anyway so this is irrelevant. File path = new File(result.getSecond(), "v4"); //$NON-NLS-1$ final File jarPath = new File(path, "android-support-v4.jar"); //$NON-NLS-1$ if (!jarPath.isFile()) { AdtPlugin.printErrorToConsole("Android Compatibility JAR not found:", jarPath.getAbsolutePath()); return false; } // Then run an Eclipse asynchronous job to update the project Job job = new Job("Add Compatibility Library to Project") { @Override protected IStatus run(IProgressMonitor monitor) { try { monitor.beginTask("Add library to project build path", 3); IResource jarRes = copyJarIntoProject(project, jarPath, monitor); monitor.worked(1); IClasspathEntry libEntry = JavaCore.newLibraryEntry(jarRes.getFullPath(), null /*sourceAttachmentPath*/, null /*sourceAttachmentRootPath*/ ); if (!ProjectHelper.isEntryInClasspath(javaProject, libEntry)) { ProjectHelper.addEntryToClasspath(javaProject, libEntry); } monitor.worked(1); return Status.OK_STATUS; } catch (JavaModelException e) { return e.getJavaModelStatus(); } catch (CoreException e) { return e.getStatus(); } catch (Exception e) { return new Status(Status.ERROR, AdtPlugin.PLUGIN_ID, Status.ERROR, "Failed", e); //$NON-NLS-1$ } finally { if (monitor != null) { monitor.done(); } } } }; job.schedule(); if (waitForFinish) { try { job.join(); return job.getState() == IStatus.OK; } catch (InterruptedException e) { AdtPlugin.log(e, null); } } return true; }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
/** * JST source code associations are stored here: * [Workspace]/.metadata/.plugins/org.eclipse.jst.j2ee/classpath.decorations.xml *///from w w w . ja va 2 s.co m public void createFrameworkSourceCodeAssociations(Shell shell, IProgressMonitor monitor) throws CoreException { if (monitor == null) monitor = new NullProgressMonitor(); // source code attachments String[] changedAttributes = { CPListElement.SOURCEATTACHMENT }; if (project.isEarProject()) { String appInfLibDir = project.getEarContentFolder().getFullPath().toString() + "/APP-INF/lib/"; IPath containerPath = new Path("org.eclipse.jst.j2ee.internal.module.container"); for (File libFile : project.getAppInfLibFiles()) { String libFileName = libFile.getName(); if (libFileName.startsWith("MDW") && !libFileName.equals("MDWDesignerResources.jar") && libFileName.endsWith(".jar") && !libFileName.endsWith("_src.jar")) { String srcJarFileName = libFileName.replaceFirst("\\.jar", "_src.jar"); IClasspathEntry cpEntry = JavaCore.newLibraryEntry(new Path(appInfLibDir + libFileName), new Path(appInfLibDir + srcJarFileName), null); BuildPathSupport.modifyClasspathEntry(shell, cpEntry, changedAttributes, project.getSourceJavaProject(), containerPath, false, monitor); } } String earContent = project.getEarContentFolder().getFullPath().toString() + "/"; for (File servicesLibFile : project.getServicesLibFiles()) { String srcJarFileName = servicesLibFile.getName().replaceFirst("\\.jar", "_src.jar"); IClasspathEntry cpEntry = JavaCore.newLibraryEntry(new Path(earContent + servicesLibFile.getName()), new Path(earContent + srcJarFileName), null); BuildPathSupport.modifyClasspathEntry(shell, cpEntry, changedAttributes, project.getSourceJavaProject(), containerPath, false, monitor); } } else if (project.isCloudProject()) { // handled by maven } else { IFolder libFolder = project.getSourceProject().getFolder("lib"); createSourceCodeAssociations(shell, libFolder, monitor); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
private void createSourceCodeAssociations(Shell shell, IFolder libFolder, IProgressMonitor monitor) throws CoreException { if (project.isOsgi()) { // handled by Maven } else {//from w w w . j av a 2 s. c om String[] changedAttributes = { CPListElement.SOURCEATTACHMENT }; if (libFolder.exists()) { String libDir = libFolder.getFullPath().toString() + "/"; for (File libFile : new File(libFolder.getLocation().toString()).listFiles()) { String libFileName = libFile.getName(); if (libFileName.startsWith("MDW") && !libFileName.equals("MDWDesignerResources.jar") && libFileName.endsWith(".jar") && !libFileName.endsWith("_src.jar")) { String srcJarFileName = libFileName.replaceFirst("\\.jar", "_src.jar"); IClasspathEntry cpEntry = JavaCore.newLibraryEntry(new Path(libDir + libFileName), new Path(libDir + srcJarFileName), null); BuildPathSupport.modifyClasspathEntry(shell, cpEntry, changedAttributes, project.getSourceJavaProject(), null, false, monitor); } else if (libFileName.equals("mdwweb.jar")) { IClasspathEntry cpEntry = JavaCore.newLibraryEntry(new Path(libDir + libFileName), new Path(libDir + "MDWWeb_src.jar"), null); BuildPathSupport.modifyClasspathEntry(shell, cpEntry, changedAttributes, project.getSourceJavaProject(), null, false, monitor); } } } } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
public void createWebProjectSourceCodeAssociations(Shell shell, IProgressMonitor monitor) throws CoreException { IPath containerPath = new Path("org.eclipse.jst.j2ee.internal.web.container"); String[] changedAttributes = { CPListElement.SOURCEATTACHMENT }; for (File webappLibFile : project.getWebappLibFiles()) { String webInfLib = project.getWebContentFolder().getRawLocation().toString() + "/WEB-INF/lib/"; String srcJarFileName = null; if (webappLibFile.getName().equals("mdwweb.jar")) srcJarFileName = "MDWWeb_src.jar"; else/*from www .j a v a 2 s . c om*/ srcJarFileName = webappLibFile.getName().replaceFirst("\\.jar", "_src.jar"); IClasspathEntry cpEntry = JavaCore.newLibraryEntry(new Path(webInfLib + webappLibFile.getName()), new Path(webInfLib + srcJarFileName), null); BuildPathSupport.modifyClasspathEntry(shell, cpEntry, changedAttributes, project.getWebJavaProject(), containerPath, false, monitor); } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
private void updateSourceProjectClasspath(IProgressMonitor monitor, WorkflowProject workflowProject) { List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); try {/*from ww w. jav a2 s . c o m*/ for (IClasspathEntry existingEntry : workflowProject.getSourceJavaProject().getRawClasspath()) { classpathEntries.add(existingEntry); } for (File file : workflowProject.getServicesLibFiles()) { String jarFileName = file.getName(); int dotIdx = jarFileName.indexOf('.'); String sourceFileName = jarFileName.substring(0, dotIdx) + "_src" + jarFileName.substring(dotIdx); IPath jarFilePath = workflowProject.getEarContentFolder().getFile(jarFileName).getFullPath(); IPath sourceFilePath = workflowProject.getEarContentFolder().getFile(sourceFileName).getFullPath(); classpathEntries.add(JavaCore.newLibraryEntry(jarFilePath, sourceFilePath, null)); } workflowProject.getSourceJavaProject().setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor); } catch (JavaModelException ex) { PluginMessages.log(ex); } }