Search in sources :

Example 1 with RuntimeClasspathEntry

use of org.eclipse.jdt.internal.launching.RuntimeClasspathEntry in project jbosstools-hibernate by jbosstools.

the class RefactoringTest method setUp.

@Before
public void setUp() throws Exception {
    oldPathStr = oldPathElements[0];
    String notChangedPathStr = oldPathElements[0] + 1;
    for (int i = 1; i < oldPathElements.length; i++) {
        // $NON-NLS-1$
        oldPathStr += "/" + oldPathElements[i];
        // $NON-NLS-1$
        notChangedPathStr += "/" + oldPathElements[i] + 1;
    }
    Map<String, Object> testStrAttr = new HashMap<String, Object>();
    Map<String, Object> testStrListAttr = new HashMap<String, Object>();
    Map<String, Object> testNotChangedAttr = new HashMap<String, Object>();
    Map<String, Object> testCodeGenerationAttr = new HashMap<String, Object>();
    Map<String, Object> testNotChangedCodeGenerationAttr = new HashMap<String, Object>();
    testStrAttr.put(IConsoleConfigurationLaunchConstants.CFG_XML_FILE, oldPathStr);
    testStrListAttr.put(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS, Arrays.asList(new String[] { oldPathStr }));
    testNotChangedAttr.put(IConsoleConfigurationLaunchConstants.CFG_XML_FILE, notChangedPathStr);
    testNotChangedAttr.put(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS, Arrays.asList(new String[] { notChangedPathStr }));
    testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, generateOldPathForSegment(2).toString());
    testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_OUTPUT_DIR, generateOldPathForSegment(2).toString());
    testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS, oldPathStr.toString());
    testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_EXPORTERS, Collections.singletonList(HBMTEMPLATE0));
    Map<String, String> expProps = new HashMap<String, String>();
    expProps.put(OUTDIR, generateOldPathForSegment(2).toString());
    testCodeGenerationAttr.put(HBMTEMPLATE0_PROPERTIES, expProps);
    testNotChangedCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, notChangedPathStr.toString());
    testNotChangedCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_OUTPUT_DIR, notChangedPathStr.toString());
    testNotChangedCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS, notChangedPathStr.toString());
    testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_EXPORTERS, Collections.singletonList(HBMTEMPLATE0));
    Map<String, String> expProps2 = new HashMap<String, String>();
    expProps2.put(OUTDIR, generateOldPathForSegment(2).toString());
    testNotChangedCodeGenerationAttr.put(HBMTEMPLATE0_PROPERTIES, expProps2);
    testStrConfig = new TestLaunchConfig(testStrAttr);
    testStrListConfig = new TestLaunchConfig(testStrListAttr);
    testNotChangedConfig = new TestLaunchConfig(testNotChangedAttr);
    testCodeGenerationConfig = new TestLaunchConfig(testCodeGenerationAttr);
    testNotChangedCodeGenerationConfig = new TestLaunchConfig(testNotChangedCodeGenerationAttr);
    project = new SimpleTestProject(oldPathElements[0]);
    IJavaProject proj = project.getIJavaProject();
    {
        // initialize IRuntimeClassPathEntry[] and affectSegmentsCount for it
        runtimeClasspathEntries = new IRuntimeClasspathEntry[5];
        affectSegmentsCount = new int[runtimeClasspathEntries.length];
        affectSegmentsCount[0] = 0;
        affectSegmentsCount[1] = 0;
        affectSegmentsCount[2] = 1;
        affectSegmentsCount[3] = 2;
        // all changes
        affectSegmentsCount[4] = oldPathElements.length - 1;
        // project
        runtimeClasspathEntries[0] = new DefaultProjectClasspathEntry(proj);
        runtimeClasspathEntries[1] = new RuntimeClasspathEntry(JavaCore.newProjectEntry(generateOldPathForSegment(affectSegmentsCount[1]).makeAbsolute()));
        runtimeClasspathEntries[2] = new RuntimeClasspathEntry(JavaCore.newVariableEntry(generateOldPathForSegment(affectSegmentsCount[2]).makeAbsolute(), null, null));
        runtimeClasspathEntries[3] = new RuntimeClasspathEntry(JavaCore.newVariableEntry(generateOldPathForSegment(affectSegmentsCount[3]).makeAbsolute(), null, null));
        runtimeClasspathEntries[4] = new RuntimeClasspathEntry(JavaCore.newLibraryEntry(generateOldPathForSegment(affectSegmentsCount[4]).makeAbsolute(), null, null));
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) RuntimeClasspathEntry(org.eclipse.jdt.internal.launching.RuntimeClasspathEntry) DefaultProjectClasspathEntry(org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry) TestLaunchConfig(org.jboss.tools.hibernate.orm.test.utils.TestLaunchConfig) SimpleTestProject(org.jboss.tools.hibernate.orm.test.utils.project.SimpleTestProject) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) Before(org.junit.Before)

Example 2 with RuntimeClasspathEntry

use of org.eclipse.jdt.internal.launching.RuntimeClasspathEntry in project bndtools by bndtools.

the class BndContainerRuntimeClasspathEntryResolver method resolveRuntimeClasspathEntry.

@Override
public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entryToResolve, IJavaProject entryProject) throws CoreException {
    if (entryToResolve == null || entryProject == null) {
        return new IRuntimeClasspathEntry[0];
    }
    final List<IRuntimeClasspathEntry> resolvedRuntimeClasspathEntries = new ArrayList<>();
    final IClasspathContainer container = JavaCore.getClasspathContainer(entryToResolve.getPath(), entryProject);
    if (container == null) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Could not resolve Bnd classpath container", null));
    }
    final IClasspathEntry[] classpathEntries = container.getClasspathEntries();
    List<IJavaProject> projects = resolvingProjects.get();
    Integer count = resolvingCount.get();
    if (projects == null) {
        projects = new ArrayList<>();
        resolvingProjects.set(projects);
        count = 0;
    }
    int intCount = count.intValue();
    intCount++;
    resolvingCount.set(intCount);
    try {
        for (IClasspathEntry classpathEntry : classpathEntries) {
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(classpathEntry.getPath().segment(0));
                final IJavaProject javaProject = JavaCore.create(project);
                if (!projects.contains(javaProject)) {
                    projects.add(javaProject);
                    final IRuntimeClasspathEntry2 defaultProjectClasspathEntry = (IRuntimeClasspathEntry2) JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
                    final IRuntimeClasspathEntry[] projectRuntimeClasspathEntries = defaultProjectClasspathEntry.getRuntimeClasspathEntries(null);
                    for (IRuntimeClasspathEntry projectRuntimeClasspathEntry : projectRuntimeClasspathEntries) {
                        // instead of resolving all output locations we simply just return the project runtime classpath entry itself
                        if (projectRuntimeClasspathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
                            IResource resource = projectRuntimeClasspathEntry.getResource();
                            if (resource instanceof IProject) {
                                resolvedRuntimeClasspathEntries.add(projectRuntimeClasspathEntry);
                            }
                        } else {
                            IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeClasspathEntry, javaProject);
                            for (IRuntimeClasspathEntry resolvedEntry : resolvedEntries) {
                                resolvedRuntimeClasspathEntries.add(resolvedEntry);
                            }
                        }
                    }
                }
            } else {
                final IRuntimeClasspathEntry runtimeClasspathEntry = new RuntimeClasspathEntry(classpathEntry);
                if (!resolvedRuntimeClasspathEntries.contains(runtimeClasspathEntry)) {
                    resolvedRuntimeClasspathEntries.add(runtimeClasspathEntry);
                }
            }
        }
    } finally {
        intCount--;
        if (intCount == 0) {
            resolvingProjects.set(null);
            resolvingCount.set(null);
        } else {
            resolvingCount.set(intCount);
        }
    }
    for (IRuntimeClasspathEntry resolvedRuntimeClasspathEntry : resolvedRuntimeClasspathEntries) {
        resolvedRuntimeClasspathEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    }
    return resolvedRuntimeClasspathEntries.toArray(new IRuntimeClasspathEntry[0]);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) RuntimeClasspathEntry(org.eclipse.jdt.internal.launching.RuntimeClasspathEntry) ArrayList(java.util.ArrayList) IRuntimeClasspathEntry2(org.eclipse.jdt.launching.IRuntimeClasspathEntry2) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)2 RuntimeClasspathEntry (org.eclipse.jdt.internal.launching.RuntimeClasspathEntry)2 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 DefaultProjectClasspathEntry (org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry)1 IRuntimeClasspathEntry2 (org.eclipse.jdt.launching.IRuntimeClasspathEntry2)1 TestLaunchConfig (org.jboss.tools.hibernate.orm.test.utils.TestLaunchConfig)1 SimpleTestProject (org.jboss.tools.hibernate.orm.test.utils.project.SimpleTestProject)1 Before (org.junit.Before)1