private void addDependenciesToClasspath(IProject project, IFolder folder, IProgressMonitor monitor) throws CoreException { List<IClasspathEntry> newEntries = new ArrayList<>(); IClasspathAttribute[] nonDependencyAttribute = new IClasspathAttribute[] {UpdateClasspathAttributeUtil.createNonDependencyAttribute()}; // Add all the jars under lib folder to the classpath File libFolder = folder.getLocation().toFile(); for (File file : libFolder.listFiles()) { IPath path = Path.fromOSString(file.toPath().toString()); newEntries.add(JavaCore.newLibraryEntry(path, null, null, new IAccessRule[0], nonDependencyAttribute, false /* isExported */)); } ClasspathUtil.addClasspathEntries(project, newEntries, monitor); }
@Test public void testCreateClasspathAttributesWithClassifier() { MavenCoordinates mavenCoordinates = builder.setClassifier("classifier").build(); List<IClasspathAttribute> classpathAttributes = MavenCoordinatesHelper.createClasspathAttributes(mavenCoordinates, "1.0.0"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.repository", "testRepo"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.groupid", "groupId"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.artifactId", "artifactId"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.type", "war"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.version", "1.0.0"); assertAttribute(classpathAttributes, "com.google.cloud.tools.eclipse.appengine.libraries.classifier", "classifier"); }
private static IClasspathAttribute[] getClasspathAttributes(LibraryFile libraryFile, Artifact artifact) throws CoreException { List<IClasspathAttribute> attributes = MavenCoordinatesHelper.createClasspathAttributes(libraryFile.getMavenCoordinates(), artifact.getVersion()); if (libraryFile.isExport()) { attributes.add(UpdateClasspathAttributeUtil.createDependencyAttribute(true /* isWebApp */)); } else { attributes.add(UpdateClasspathAttributeUtil.createNonDependencyAttribute()); } if (libraryFile.getSourceUri() != null) { addUriAttribute(attributes, CLASSPATH_ATTRIBUTE_SOURCE_URL, libraryFile.getSourceUri()); } if (libraryFile.getJavadocUri() != null) { addUriAttribute(attributes, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, libraryFile.getJavadocUri()); } return attributes.toArray(new IClasspathAttribute[0]); }
public static List<IClasspathAttribute> createClasspathAttributes(MavenCoordinates mavenCoordinates, String actualVersion) { List<IClasspathAttribute> attributes = Lists.newArrayList( JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_REPOSITORY, mavenCoordinates.getRepository()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_GROUP_ID, mavenCoordinates.getGroupId()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_ARTIFACT_ID, mavenCoordinates.getArtifactId()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_TYPE, mavenCoordinates.getType()), JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_VERSION, actualVersion) ); if (mavenCoordinates.getClassifier() != null) { attributes.add(JavaCore.newClasspathAttribute(CLASSPATH_ATTRIBUTE_CLASSIFIER, mavenCoordinates.getClassifier())); } return attributes; }
static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) { if (attributes == null) return NO_EXTRA_ATTRIBUTES; int length = attributes.getLength(); if (length == 0) return NO_EXTRA_ATTRIBUTES; IClasspathAttribute[] result = new IClasspathAttribute[length]; int index = 0; for (int i = 0; i < length; ++i) { Node node = attributes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element attribute = (Element) node; String name = attribute.getAttribute(TAG_ATTRIBUTE_NAME); if (name == null) continue; String value = attribute.getAttribute(TAG_ATTRIBUTE_VALUE); if (value == null) continue; result[index++] = new ClasspathAttribute(name, value); } } if (index != length) System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index); return result; }
/** * This function computes the URL of the index location for this classpath entry. It returns null * if the URL is invalid. */ public URL getLibraryIndexLocation() { switch (getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: break; default: return null; } if (this.extraAttributes == null) return null; for (int i = 0; i < this.extraAttributes.length; i++) { IClasspathAttribute attrib = this.extraAttributes[i]; if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { return new URL(value); } catch (MalformedURLException e) { return null; } } } return null; }
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); // $NON-NLS-1$ } int kind = entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException( "Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); // $NON-NLS-1$ } IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { return parseURL(attrib.getValue()); } } return null; }
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException { String encoding = ResourcesPlugin.getEncoding(); IClasspathEntry entry = root.getRawClasspathEntry(); if (entry != null) { int kind = entry.getEntryKind(); if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) { IClasspathAttribute[] extraAttributes = entry.getExtraAttributes(); for (int i = 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib = extraAttributes[i]; if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { return attrib.getValue(); } } } } return encoding; }
private static IClasspathAttribute[] buildClasspathAttributes( final IVMInstallType vm, final LibraryLocation lib, final boolean overrideJavaDoc) { List<IClasspathAttribute> classpathAttributes = new LinkedList<IClasspathAttribute>(); // process the javadoc location URL javadocLocation = lib.getJavadocLocation(); if (overrideJavaDoc && javadocLocation == null) { javadocLocation = null; // vm.getJavadocLocation(); } if (javadocLocation != null) { IClasspathAttribute javadocCPAttribute = JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation.toExternalForm()); classpathAttributes.add(javadocCPAttribute); } // process the index location URL indexLocation = lib.getIndexLocation(); if (indexLocation != null) { IClasspathAttribute indexCPLocation = JavaCore.newClasspathAttribute( IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, indexLocation.toExternalForm()); classpathAttributes.add(indexCPLocation); } return classpathAttributes.toArray(new IClasspathAttribute[classpathAttributes.size()]); }
private MavenArtifactKey getArtifactKey(IClasspathEntry classpathEntry) { IClasspathAttribute[] attributes = classpathEntry.getExtraAttributes(); String groupId = null; String artifactId = null; String version = null; String packaging = null; String classifier = null; for (IClasspathAttribute attribute : attributes) { if (ClasspathManager.GROUP_ID_ATTRIBUTE.equals(attribute.getName())) { groupId = attribute.getValue(); } else if (ClasspathManager.ARTIFACT_ID_ATTRIBUTE.equals(attribute.getName())) { artifactId = attribute.getValue(); } else if (ClasspathManager.VERSION_ATTRIBUTE.equals(attribute.getName())) { version = attribute.getValue(); } else if (ClasspathManager.PACKAGING_ATTRIBUTE.equals(attribute.getName())) { packaging = attribute.getValue(); } else if (ClasspathManager.CLASSIFIER_ATTRIBUTE.equals(attribute.getName())) { classifier = attribute.getValue(); } } if (groupId != null && artifactId != null && version != null) { return new MavenArtifactKey(groupId, artifactId, version, packaging, classifier); } return null; }
/** * Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the * gwt-user project. * * @throws Exception */ public void testFindSdkFor_GwtUserProject() throws Exception { GwtRuntimeTestUtilities.importGwtSourceProjects(); try { IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); IJavaProject javaProject = javaModel.getJavaProject("gwt-user"); GwtSdk sdk = GwtSdk.findSdkFor(javaProject); IClasspathEntry gwtUserEntry = JavaCore.newSourceEntry( javaModel.getJavaProject("gwt-user").getPath().append("core/src"), new IPath[] {new Path("**/super/**")}); /* * NOTE: Passing null for the IClasspathAttribute array tickles a bug in * eclipse 3.3. */ IClasspathEntry gwtDevEntry = JavaCore.newProjectEntry(javaModel.getJavaProject("gwt-dev").getPath(), null, false, new IClasspathAttribute[0] /* */, false); IClasspathEntry[] expected = new IClasspathEntry[] {gwtUserEntry, gwtDevEntry}; assertEquals(expected, sdk.getClasspathEntries()); } finally { GwtRuntimeTestUtilities.removeGwtSourceProjects(); } }
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } int kind= entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); for (int i= 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib= extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { return parseURL(attrib.getValue()); } } return null; }
private static String getSourceAttachmentEncoding(IPackageFragmentRoot root) throws JavaModelException { String encoding= ResourcesPlugin.getEncoding(); IClasspathEntry entry= root.getRawClasspathEntry(); if (entry != null) { int kind= entry.getEntryKind(); if (kind == IClasspathEntry.CPE_LIBRARY || kind == IClasspathEntry.CPE_VARIABLE) { IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); for (int i= 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib= extraAttributes[i]; if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { return attrib.getValue(); } } } } return encoding; }
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException { ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false))); return null; } String containerName= container.getDescription(); IStatus status= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_not_supported, containerName)); return null; } IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName)); fIsReadOnly= true; return entry; } Assert.isNotNull(entry); setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description); return entry; }
protected Link createIgnoreOptionalProblemsLink(Composite parent) { final IClasspathEntry sourceFolderEntry= getSourceFolderIgnoringOptionalProblems(); if (sourceFolderEntry != null) { Link link= new Link(parent, SWT.NONE); link.setText(PreferencesMessages.OptionsConfigurationBlock_IgnoreOptionalProblemsLink); link.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { HashMap<Object, Object> data= new HashMap<Object, Object>(1); data.put(BuildPathsPropertyPage.DATA_REVEAL_ENTRY, sourceFolderEntry); data.put(BuildPathsPropertyPage.DATA_REVEAL_ATTRIBUTE_KEY, IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS); getPreferenceContainer().openPage(BuildPathsPropertyPage.PROP_ID, data); } }); return link; } return null; }
public ClasspathAttributeAccess getClasspathAttributeAccess() { if (fCachedAccess == null) { fCachedAccess= new ClasspathAttributeAccess() { @Override public IClasspathAttribute getClasspathAttribute() { return CPListElementAttribute.this.getClasspathAttribute(); } @Override public IJavaProject getJavaProject() { return getParent().getJavaProject(); } @Override public IClasspathEntry getParentClasspassEntry() { return getParent().getClasspathEntry(); } }; } return fCachedAccess; }
@Override public IClasspathAttribute performEdit(Shell shell, ClasspathAttributeAccess attribute) { String initialLocation= attribute.getClasspathAttribute().getValue(); String elementName= attribute.getParentClasspassEntry().getPath().lastSegment(); try { URL locationURL= initialLocation != null ? new URL(initialLocation) : null; URL[] result= BuildPathDialogAccess.configureJavadocLocation(shell, elementName, locationURL); if (result != null) { URL newURL= result[0]; String string= newURL != null ? newURL.toExternalForm() : null; return JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, string); } } catch (MalformedURLException e) { // todo } return null; }
public static String getSourceAttachmentEncoding(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } int kind= entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); for (int i= 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib= extraAttributes[i]; if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { return attrib.getValue(); } } return null; }
static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) { if (attributes == null) return NO_EXTRA_ATTRIBUTES; int length = attributes.getLength(); if (length == 0) return NO_EXTRA_ATTRIBUTES; IClasspathAttribute[] result = new IClasspathAttribute[length]; int index = 0; for (int i = 0; i < length; ++i) { Node node = attributes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element attribute = (Element)node; String name = attribute.getAttribute(TAG_ATTRIBUTE_NAME); if (name == null) continue; String value = attribute.getAttribute(TAG_ATTRIBUTE_VALUE); if (value == null) continue; result[index++] = new ClasspathAttribute(name, value); } } if (index != length) System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index); return result; }
/** * This function computes the URL of the index location for this classpath entry. It returns null if the URL is * invalid. */ public URL getLibraryIndexLocation() { switch(getEntryKind()) { case IClasspathEntry.CPE_LIBRARY : case IClasspathEntry.CPE_VARIABLE : break; default : return null; } if (this.extraAttributes == null) return null; for (int i= 0; i < this.extraAttributes.length; i++) { IClasspathAttribute attrib= this.extraAttributes[i]; if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { return new URL(value); } catch (MalformedURLException e) { return null; } } } return null; }
private static Map getRawComponentClasspathDependencies(final IJavaProject javaProject) throws CoreException { if (javaProject == null) { return Collections.EMPTY_MAP; } final Map referencedRawEntries = new HashMap(); final IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IClasspathAttribute attrib = checkForComponentDependencyAttribute(entry,DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_DEPENDENCY); if (attrib != null) { referencedRawEntries.put(entry,attrib); } } return referencedRawEntries; }
private static String getRuntimePath(final IClasspathAttribute attrib, final boolean isWebApp, final boolean isClassFolder) { if (attrib != null && !attrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) { return null; } if (attrib == null || attrib.getValue() == null || attrib.getValue().length() == 0) { if (isWebApp) { return isClassFolder?"/WEB_INF/classes":"WEB-INF/lib"; } else { return isClassFolder?"/":"../"; } } return attrib.getValue(); }
public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } int kind= entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ } IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); for (int i= 0; i < extraAttributes.length; i++) { IClasspathAttribute attrib= extraAttributes[i]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { try { return new URL(attrib.getValue()); } catch (MalformedURLException e) { return null; } } } return null; }
public boolean performFinish() { containerPage.finish(); IClasspathEntry newEntry = containerPage.getSelection(); IPath path = newEntry.getPath(); IJavaProject project = containerPage.getProject(); try { IvyClasspathContainerImpl ivycp = new IvyClasspathContainerImpl(project, path, new IClasspathEntry[0], new IClasspathAttribute[0]); JavaCore.setClasspathContainer(path, new IJavaProject[] {project}, new IClasspathContainer[] {ivycp}, null); IClasspathEntry[] entries = project.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<>(Arrays.asList(entries)); newEntries.add(newEntry); entries = newEntries.toArray(new IClasspathEntry[newEntries.size()]); project.setRawClasspath(entries, project.getOutputLocation(), null); ivycp.launchResolve(false, null); } catch (JavaModelException e) { IvyPlugin.log(e); return false; } return true; }
/** * Just a verbatim copy of the internal Eclipse function: * org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations#getLibraryJavadocLocation(IClasspathEntry) * * @param entry IClasspathEntry * @return URL */ public static URL getLibraryJavadocLocation(IClasspathEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ } int kind = entry.getEntryKind(); if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { throw new IllegalArgumentException( "Entry must be of kind CPE_LIBRARY or " + "CPE_VARIABLE"); //$NON-NLS-1$ } for (IClasspathAttribute attrib : entry.getExtraAttributes()) { if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { try { return new URL(attrib.getValue()); } catch (MalformedURLException e) { return null; } } } return null; }
private IClasspathEntry doBuildEntry(ArtifactDownloadReport artifact, IPath classpathArtifact, IAccessRule[] rules) { IPath sourcesArtifact = getArtifactPath(artifact, sourceArtifactMatcher, mapping.isMapIfOnlyOneSource(), ""); IPath javadocArtifact = getArtifactPath(artifact, javadocArtifactMatcher, mapping.isMapIfOnlyOneJavadoc(), ""); IPath sources = attachmentManager.getSourceAttachment(classpathArtifact, sourcesArtifact); IPath sourcesRoot = attachmentManager.getSourceAttachmentRoot(classpathArtifact, sourcesArtifact); IClasspathAttribute[] att = getExtraAttribute(classpathArtifact, javadocArtifact); if (sources != null) { IvyDEMessage.debug("Attaching sources " + sources + " to " + classpathArtifact); } if (javadocArtifact != null) { IvyDEMessage.debug("Attaching javadoc " + javadocArtifact + " to " + classpathArtifact); } if (rules != null) { IvyDEMessage.debug("Setting OSGi access rules on " + classpathArtifact); } return JavaCore.newLibraryEntry(classpathArtifact, sources, sourcesRoot, rules, att, false); }
private void writeCpAttr(IvyClasspathContainerImpl ivycp, Document document, Node node, IClasspathAttribute[] attrs) { if (attrs == null) { return; } Node cpAttrsNode = document.createElement(CPATTRS); node.appendChild(cpAttrsNode); for (IClasspathAttribute attribute : attrs) { Node attrNode = document.createElement(ATTR); cpAttrsNode.appendChild(attrNode); NamedNodeMap attributes = attrNode.getAttributes(); Attr attr = document.createAttribute(NAME); attr.setValue(attribute.getName()); attributes.setNamedItem(attr); attr = document.createAttribute(VALUE); attr.setValue(attribute.getValue()); attributes.setNamedItem(attr); } }
private IClasspathEntry[] createClasspath(int option) throws LeJOSEV3Exception { ArrayList<File> entryList = new ArrayList<File>(); File ev3Home = LeJOSEV3Util.getEV3Home(); String subdir = getOptionKey(option); LeJOSEV3Util.buildClasspath(ev3Home, subdir, entryList); int len = entryList.size(); IClasspathEntry[] entryArray = new IClasspathEntry[entryList.size()]; for (int i=0; i<len; i++) { File lib = entryList.get(i); File src = guessSource(lib); IPath lib2 = LeJOSEV3Util.toPath(lib); IPath src2 = (src == null) ? null : LeJOSEV3Util.toPath(src); IAccessRule[] accessRules = { JavaCore.newAccessRule(new Path("**/internal/**"), IAccessRule.K_DISCOURAGED) }; IClasspathAttribute[] attributes = {}; entryArray[i] = JavaCore.newLibraryEntry(lib2, src2, null, accessRules, attributes, false); } return entryArray; }
public IClasspathEntry getLibraryEntry() { BundleInfo bundleInfo= P2Utils.findBundle(bundleId, versionRange, false); IPath bundleLocation= P2Utils.getBundleLocationPath(bundleInfo); if (bundleLocation != null) { IPath bundleRootLocation= getLibraryLocation(bundleInfo, bundleLocation); IPath srcLocation= getSourceLocation(bundleInfo); String javadocLocation= ""; if(javadoc != null) javadocLocation = Platform.getPreferencesService().getString(TestSpecPlugin.PLUGIN_ID, javadoc, "", null); //$NON-NLS-1$ IClasspathAttribute[] attributes; if (javadocLocation.length() == 0) { attributes= new IClasspathAttribute[0]; } else { attributes= new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation) }; } return JavaCore.newLibraryEntry(bundleRootLocation, srcLocation, null, getAccessRules(), attributes, false); } return null; }
public IClasspathEntry[] getClasspathEntries() { try { Config.Home home = RoboVMPlugin.getRoboVMHome(); File f = home.getRtPath(); IPath sourceAttachment = null; if (!home.isDev()) { // robovm-rt.jar. Use robovm-rt-sources.jar as source attachment. sourceAttachment = new Path(new File(f.getParentFile(), "robovm-rt-sources.jar").getAbsolutePath()); } else { // ROBOVM_DEV_ROOT has been set and rtPath is $ROBOVM_DEV_ROOT/rt/target/robovm-rt-<version>.jar. Use // $ROBOVM_DEV_ROOT/rt/target/robovm-rt-<version>-sources.jar as source attachment. sourceAttachment = new Path(f.getAbsolutePath().replaceAll("\\.jar$", "-sources.jar")); } return new IClasspathEntry[] { JavaCore.newLibraryEntry(new Path(f.getAbsolutePath()), sourceAttachment, new Path(""), new IAccessRule[] {}, new IClasspathAttribute[] {}, false) }; } catch (IOException e) { throw new RuntimeException(e); } }
private boolean isMavenPomDerived(final IClasspathEntry classpathEntry) { for (final IClasspathAttribute classpathAttribute : classpathEntry.getExtraAttributes()) { if (Objects.equals(classpathAttribute.getName(), "maven.pomderived")) { return Objects.equals(classpathAttribute.getValue(), "true"); } } return false; }
private boolean hasNonDependencyAttribute(File jar) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getPath().toFile().equals(jar)) { for (IClasspathAttribute attribute : entry.getExtraAttributes()) { if (isNonDependencyAttribute(attribute)) { return true; } } } } return false; }
private static void addJunit4ToClasspath(IProject newProject, IProgressMonitor monitor) throws CoreException { IClasspathAttribute nonDependencyAttribute = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); IClasspathEntry junit4Container = JavaCore.newContainerEntry( JUnitCore.JUNIT4_CONTAINER_PATH, new IAccessRule[0], new IClasspathAttribute[] {nonDependencyAttribute}, false); ClasspathUtil.addClasspathEntry(newProject, junit4Container, monitor); }