use of org.eclipse.jdt.core.IClasspathEntry in project bndtools by bndtools.
the class NewBndProjectWizardPageOne method getSourceClasspathEntries.
@Override
public IClasspathEntry[] getSourceClasspathEntries() {
IPath projectPath = new Path(getProjectName()).makeAbsolute();
ProjectPaths projectPaths = ProjectPaths.DEFAULT;
List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(2);
newEntries.add(JavaCore.newSourceEntry(projectPath.append(projectPaths.getSrc()), null, projectPath.append(projectPaths.getBin())));
boolean enableTestSrcDir;
try {
if (template == null)
enableTestSrcDir = true;
else {
ObjectClassDefinition templateMeta = template.getMetadata();
enableTestSrcDir = findAttribute(templateMeta, ProjectTemplateParam.TEST_SRC_DIR.getString()) != null;
}
} catch (Exception e) {
Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error accessing template parameters", e));
enableTestSrcDir = true;
}
if (enableTestSrcDir)
newEntries.add(JavaCore.newSourceEntry(projectPath.append(projectPaths.getTestSrc()), null, projectPath.append(projectPaths.getTestBin())));
return newEntries.toArray(new IClasspathEntry[0]);
}
use of org.eclipse.jdt.core.IClasspathEntry in project bndtools by bndtools.
the class NewBndProjectWizardPageTwo method isPageComplete.
@Override
public boolean isPageComplete() {
boolean resultFromSuperClass = super.isPageComplete();
int nr = 0;
try {
IClasspathEntry[] entries = getJavaProject().getResolvedClasspath(true);
for (IClasspathEntry entry : entries) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
nr++;
// here we could do more validation on the paths if we want to
// for now we just count pages
}
}
} catch (Exception e) {
// if for some reason we cannot access the resolved classpath
// we simply set an error message
setErrorMessage("Could not access resolved classpaths: " + e);
}
// have the test source set
return resultFromSuperClass && (1 <= nr) && (nr <= 2);
}
use of org.eclipse.jdt.core.IClasspathEntry in project bndtools by bndtools.
the class BndContainerSourceManager method loadAttachedSources.
/**
* Return (a potentially modified) list of {@link IClasspathEntry} instances that will have any previously persisted
* attached sources added.
*/
public static List<IClasspathEntry> loadAttachedSources(final IProject project, final List<IClasspathEntry> classPathEntries) throws CoreException {
if (classPathEntries.isEmpty()) {
return classPathEntries;
}
final Properties props = loadSourceAttachmentProperties(project);
final List<IClasspathEntry> configuredClassPathEntries = new ArrayList<IClasspathEntry>(classPathEntries.size());
for (final IClasspathEntry entry : classPathEntries) {
if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY || entry.getSourceAttachmentPath() != null) {
configuredClassPathEntries.add(entry);
continue;
}
final String key = entry.getPath().toPortableString();
IPath srcPath = null;
IPath srcRoot = null;
// Retrieve the saved source attachment information
if (props != null && props.containsKey(key + PROPERTY_SRC_PATH)) {
srcPath = Path.fromPortableString((String) props.get(key + PROPERTY_SRC_PATH));
if (props.containsKey(key + PROPERTY_SRC_ROOT)) {
srcRoot = Path.fromPortableString((String) props.get(key + PROPERTY_SRC_ROOT));
}
} else {
// If there is no saved source attachment, then try and find a source bundle
Map<String, String> extraProps = new HashMap<String, String>();
for (IClasspathAttribute attr : entry.getExtraAttributes()) {
extraProps.put(attr.getName(), attr.getValue());
}
File sourceBundle = getSourceBundle(entry.getPath(), extraProps);
if (sourceBundle != null) {
srcPath = new Path(sourceBundle.getAbsolutePath());
}
}
if (srcPath != null || srcRoot != null) {
configuredClassPathEntries.add(JavaCore.newLibraryEntry(entry.getPath(), srcPath, srcRoot, entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()));
} else {
configuredClassPathEntries.add(entry);
}
}
return configuredClassPathEntries;
}
use of org.eclipse.jdt.core.IClasspathEntry in project bndtools by bndtools.
the class BndProjectNature method removeBndClasspath.
private void removeBndClasspath() throws CoreException {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(classpath.length);
boolean changed = false;
for (IClasspathEntry entry : classpath) {
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath())) {
changed = true;
} else {
newEntries.add(entry);
}
}
if (changed)
javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null);
}
use of org.eclipse.jdt.core.IClasspathEntry in project bndtools by bndtools.
the class BndProjectNature method installBndClasspath.
private void installBndClasspath() throws CoreException {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
for (IClasspathEntry entry : classpath) {
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath()))
// already installed
return;
}
IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1];
System.arraycopy(classpath, 0, newEntries, 0, classpath.length);
newEntries[classpath.length] = JavaCore.newContainerEntry(BndtoolsConstants.BND_CLASSPATH_ID);
javaProject.setRawClasspath(newEntries, null);
}
Aggregations