use of org.eclipse.jdt.core.IClasspathAttribute in project azure-tools-for-java by Microsoft.
the class ClasspathContainerPage method configureClasspathEntries.
/**
* Method adds entries into .classpath file.
*/
private void configureClasspathEntries() {
IJavaProject proj1 = JavaCore.create(getSelectedProject());
IClasspathEntry[] entries;
try {
entries = proj1.getRawClasspath();
IClasspathEntry[] newentries = new IClasspathEntry[entries.length];
for (int i = 0; i < entries.length; i++) {
if (entries[i].toString().contains(Messages.sdkContainer)) {
if (depCheck.getSelection()) {
IClasspathAttribute[] attr = new IClasspathAttribute[1];
attr[0] = JavaCore.newClasspathAttribute(Messages.jstDep, "/WEB-INF/lib");
newentries[i] = JavaCore.newContainerEntry(entry, null, attr, true);
} else {
newentries[i] = JavaCore.newContainerEntry(entry);
}
} else {
newentries[i] = entries[i];
}
}
proj1.setRawClasspath(newentries, null);
} catch (Exception e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
use of org.eclipse.jdt.core.IClasspathAttribute in project azure-tools-for-java by Microsoft.
the class ClasspathContainerPage method getSelection.
@Override
public IClasspathEntry getSelection() {
IClasspathEntry classPathEntry = null;
if (depCheck.getSelection()) {
IClasspathAttribute[] attr = new IClasspathAttribute[1];
attr[0] = JavaCore.newClasspathAttribute(Messages.jstDep, "/WEB-INF/lib");
classPathEntry = JavaCore.newContainerEntry(entry, null, attr, true);
} else {
classPathEntry = JavaCore.newContainerEntry(entry);
}
return classPathEntry;
}
use of org.eclipse.jdt.core.IClasspathAttribute in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method importSourceAndOutputFolders.
private void importSourceAndOutputFolders(Project bndProject, IProject workspaceProject, IJavaProject javaProject, IProgressMonitor monitor) throws Exception {
// remove defaults
removeClasspathDefaults(javaProject);
// Output
IFolder sourceOutput = workspaceProject.getFolder(URIUtil.toPath(bndProject.getSrcOutput().toURI()).makeRelativeTo(workspaceProject.getLocation()));
IPackageFragmentRoot outputRoot = javaProject.getPackageFragmentRoot(sourceOutput);
// Source (multiple possible)
for (File folder : bndProject.getSourcePath()) {
IFolder source = workspaceProject.getFolder(URIUtil.toPath(folder.toURI()).makeRelativeTo(workspaceProject.getLocation()));
// Now the created source folder should be added to the class entries of the project, otherwise compilation
// will fail
IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(source);
List<IClasspathEntry> entries = new ArrayList<>(Arrays.asList(javaProject.getRawClasspath()));
entries.add(JavaCore.newSourceEntry(root.getPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, outputRoot.getPath(), ClasspathEntry.NO_EXTRA_ATTRIBUTES));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), monitor);
createFolderIfNecessary(source, monitor);
}
// Test-Source
javaProject.setOutputLocation(sourceOutput.getFullPath(), null);
if (!bndProject.getSrcOutput().equals(bndProject.getTestOutput())) {
IFolder testOutput = workspaceProject.getFolder(URIUtil.toPath(bndProject.getTestOutput().toURI()).makeRelativeTo(workspaceProject.getLocation()));
IPackageFragmentRoot testOutputRoot = javaProject.getPackageFragmentRoot(testOutput);
IFolder testSource = workspaceProject.getFolder(URIUtil.toPath(bndProject.getTestSrc().toURI()).makeRelativeTo(workspaceProject.getLocation()));
// Now the created source folder should be added to the class entries of the project, otherwise compilation
// will fail
IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(testSource);
List<IClasspathEntry> entries = new ArrayList<>(Arrays.asList(javaProject.getRawClasspath()));
entries.add(JavaCore.newSourceEntry(root.getPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, testOutputRoot.getPath(), new IClasspathAttribute[] { TEST }));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), monitor);
createFolderIfNecessary(testSource, monitor);
}
// Generated Artifact
IFolder generated = workspaceProject.getFolder(URIUtil.toPath(bndProject.getTarget().toURI()).makeRelativeTo(workspaceProject.getLocation()));
createFolderIfNecessary(generated, monitor);
}
use of org.eclipse.jdt.core.IClasspathAttribute in project bndtools by bndtools.
the class MavenImplicitProjectRepository method getOutputFile.
private File getOutputFile(IClasspathAttribute[] extraAttributes) {
String groupId = null, artifactId = null, version = null;
for (IClasspathAttribute attribute : extraAttributes) {
if ("maven.groupId".equals(attribute.getName())) {
groupId = attribute.getValue();
} else if ("maven.artifactId".equals(attribute.getName())) {
artifactId = attribute.getValue();
} else if ("maven.version".equals(attribute.getName())) {
version = attribute.getValue();
}
}
IMavenProjectFacade mavenProjectFacade = mavenProjectRegistry.getMavenProject(groupId, artifactId, version);
return guessBundleFile(mavenProjectFacade);
}
use of org.eclipse.jdt.core.IClasspathAttribute in project bndtools by bndtools.
the class MavenImplicitProjectRepository method createRepo.
private void createRepo(IMavenProjectFacade mavenProjectFacade, IProgressMonitor monitor) {
try {
List<File> toIndex = new ArrayList<>();
File file = guessBundleFile(mavenProjectFacade);
if (file != null) {
toIndex.add(file);
}
IClasspathEntry[] classpath = buildpathManager.getClasspath(mavenProjectFacade.getProject(), IClasspathManager.CLASSPATH_RUNTIME, true, monitor);
for (IClasspathEntry cpe : classpath) {
IClasspathAttribute[] extraAttributes = cpe.getExtraAttributes();
for (IClasspathAttribute ea : extraAttributes) {
if (ea.getName().equals("maven.scope") && (ea.getValue().equals("compile") || ea.getValue().equals("runtime"))) {
if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
file = getOutputFile(extraAttributes);
if (file != null) {
toIndex.add(file);
}
} else if ((cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) && (cpe.getContentKind() == IPackageFragmentRoot.K_BINARY)) {
file = cpe.getPath().toFile();
if (file != null) {
toIndex.add(file);
}
}
}
}
}
fileSetRepository = new FileSetRepository(getName(), toIndex);
Central.refreshPlugin(this);
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Failed to create implicit repository for m2e project {}", getName(), e);
}
}
}
Aggregations