Search in sources :

Example 46 with IClasspathAttribute

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);
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 47 with IClasspathAttribute

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;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 48 with IClasspathAttribute

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);
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 49 with IClasspathAttribute

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);
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 50 with IClasspathAttribute

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);
        }
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) FileSetRepository(aQute.bnd.repository.fileset.FileSetRepository) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)52 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)37 IPath (org.eclipse.core.runtime.IPath)26 ArrayList (java.util.ArrayList)17 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 Path (org.eclipse.core.runtime.Path)11 HashMap (java.util.HashMap)9 CoreException (org.eclipse.core.runtime.CoreException)9 IAccessRule (org.eclipse.jdt.core.IAccessRule)9 File (java.io.File)6 LinkedHashMap (java.util.LinkedHashMap)6 IProject (org.eclipse.core.resources.IProject)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 Bundle (org.osgi.framework.Bundle)5 Iterator (java.util.Iterator)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 URL (java.net.URL)3 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)3