Example usage for org.eclipse.jdt.core IClasspathContainer IClasspathContainer

List of usage examples for org.eclipse.jdt.core IClasspathContainer IClasspathContainer

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathContainer IClasspathContainer.

Prototype

IClasspathContainer

Source Link

Usage

From source file:com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer.java

License:Open Source License

/**
 * Allocates and returns an {@link AndroidClasspathContainer} object with the proper
 * path to the framework jar file.// w  w w.ja va  2 s.  co  m
 * @param javaProject The java project that will receive the container.
 */
private static IClasspathContainer allocateAndroidContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();

    String markerMessage = null;
    boolean outputToConsole = true;
    IAndroidTarget target = null;

    try {
        AdtPlugin plugin = AdtPlugin.getDefault();
        if (plugin == null) { // This is totally weird, but I've seen it happen!
            return null;
        }

        synchronized (Sdk.getLock()) {
            boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED;

            // check if the project has a valid target.
            ProjectState state = Sdk.getProjectState(iProject);
            if (state == null) {
                // looks like the project state (project.properties) couldn't be read!
                markerMessage = String.format(
                        "Project has no %1$s file! Edit the project properties to set one.",
                        SdkConstants.FN_PROJECT_PROPERTIES);
            } else {
                // this might be null if the sdk is not yet loaded.
                target = state.getTarget();

                // if we are loaded and the target is non null, we create a valid
                // ClassPathContainer
                if (sdkIsLoaded && target != null) {
                    // check the renderscript support mode. If support mode is enabled,
                    // target API must be 18+
                    if (!state.getRenderScriptSupportMode() || target.getVersion().getApiLevel() >= 18) {
                        // first make sure the target has loaded its data
                        Sdk.getCurrent().checkAndLoadTargetData(target, null /*project*/);

                        String targetName = target.getClasspathName();

                        return new AndroidClasspathContainer(
                                createClasspathEntries(iProject, target, targetName),
                                new Path(AdtConstants.CONTAINER_FRAMEWORK), targetName,
                                IClasspathContainer.K_DEFAULT_SYSTEM);
                    } else {
                        markerMessage = "Renderscript support mode requires compilation target API to be 18+.";
                    }
                } else {
                    // In case of error, we'll try different thing to provide the best error message
                    // possible.
                    // Get the project's target's hash string (if it exists)
                    String hashString = state.getTargetHashString();

                    if (hashString == null || hashString.length() == 0) {
                        // if there is no hash string we only show this if the SDK is loaded.
                        // For a project opened at start-up with no target, this would be displayed
                        // twice, once when the project is opened, and once after the SDK has
                        // finished loading.
                        // By testing the sdk is loaded, we only show this once in the console.
                        if (sdkIsLoaded) {
                            markerMessage = String.format(
                                    "Project has no target set. Edit the project properties to set one.");
                        }
                    } else if (sdkIsLoaded) {
                        markerMessage = String.format("Unable to resolve target '%s'", hashString);
                    } else {
                        // this is the case where there is a hashString but the SDK is not yet
                        // loaded and therefore we can't get the target yet.
                        // We check if there is a cache of the needed information.
                        AndroidClasspathContainer container = getContainerFromCache(iProject, target);

                        if (container == null) {
                            // either the cache was wrong (ie folder does not exists anymore), or
                            // there was no cache. In this case we need to make sure the project
                            // is resolved again after the SDK is loaded.
                            plugin.setProjectToResolve(javaProject);

                            markerMessage = String.format(
                                    "Unable to resolve target '%s' until the SDK is loaded.", hashString);

                            // let's not log this one to the console as it will happen at
                            // every boot, and it's expected. (we do keep the error marker though).
                            outputToConsole = false;

                        } else {
                            // we created a container from the cache, so we register the project
                            // to be checked for cache validity once the SDK is loaded
                            plugin.setProjectToCheck(javaProject);

                            // and return the container
                            return container;
                        }
                    }
                }
            }

            // return a dummy container to replace the one we may have had before.
            // It'll be replaced by the real when if/when the target is resolved if/when the
            // SDK finishes loading.
            return new IClasspathContainer() {
                @Override
                public IClasspathEntry[] getClasspathEntries() {
                    return new IClasspathEntry[0];
                }

                @Override
                public String getDescription() {
                    return "Unable to get system library for the project";
                }

                @Override
                public int getKind() {
                    return IClasspathContainer.K_DEFAULT_SYSTEM;
                }

                @Override
                public IPath getPath() {
                    return null;
                }
            };
        }
    } finally {
        processError(iProject, markerMessage, AdtConstants.MARKER_TARGET, outputToConsole);
    }
}

From source file:com.android.ide.eclipse.adt.project.internal.AndroidClasspathContainerInitializer.java

License:Open Source License

/**
 * Allocates and returns an {@link AndroidClasspathContainer} object with the proper
 * path to the framework jar file.//ww  w  . java2  s.  c o  m
 * @param javaProject The java project that will receive the container.
 */
private static IClasspathContainer allocateAndroidContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();

    String markerMessage = null;
    boolean outputToConsole = true;

    try {
        AdtPlugin plugin = AdtPlugin.getDefault();

        // get the lock object for project manipulation during SDK load.
        Object lock = plugin.getSdkLockObject();
        synchronized (lock) {
            boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED;

            // check if the project has a valid target.
            IAndroidTarget target = null;
            if (sdkIsLoaded) {
                target = Sdk.getCurrent().getTarget(iProject);
            }

            // if we are loaded and the target is non null, we create a valid ClassPathContainer
            if (sdkIsLoaded && target != null) {

                String targetName = target.getClasspathName();

                return new AndroidClasspathContainer(createClasspathEntries(iProject, target, targetName),
                        new Path(CONTAINER_ID), targetName);
            }

            // In case of error, we'll try different thing to provide the best error message
            // possible.
            // Get the project's target's hash string (if it exists)
            String hashString = Sdk.getProjectTargetHashString(iProject);

            if (hashString == null || hashString.length() == 0) {
                // if there is no hash string we only show this if the SDK is loaded.
                // For a project opened at start-up with no target, this would be displayed
                // twice, once when the project is opened, and once after the SDK has
                // finished loading.
                // By testing the sdk is loaded, we only show this once in the console.
                if (sdkIsLoaded) {
                    markerMessage = String
                            .format("Project has no target set. Edit the project properties to set one.");
                }
            } else if (sdkIsLoaded) {
                markerMessage = String.format("Unable to resolve target '%s'", hashString);
            } else {
                // this is the case where there is a hashString but the SDK is not yet
                // loaded and therefore we can't get the target yet.
                // We check if there is a cache of the needed information.
                AndroidClasspathContainer container = getContainerFromCache(iProject);

                if (container == null) {
                    // either the cache was wrong (ie folder does not exists anymore), or 
                    // there was no cache. In this case we need to make sure the project
                    // is resolved again after the SDK is loaded.
                    plugin.setProjectToResolve(javaProject);

                    markerMessage = String.format("Unable to resolve target '%s' until the SDK is loaded.",
                            hashString);

                    // let's not log this one to the console as it will happen at every boot,
                    // and it's expected. (we do keep the error marker though).
                    outputToConsole = false;

                } else {
                    // we created a container from the cache, so we register the project
                    // to be checked for cache validity once the SDK is loaded
                    plugin.setProjectToCheck(javaProject);

                    // and return the container
                    return container;
                }

            }

            // return a dummy container to replace the one we may have had before.
            // It'll be replaced by the real when if/when the target is resolved if/when the
            // SDK finishes loading.
            return new IClasspathContainer() {
                public IClasspathEntry[] getClasspathEntries() {
                    return new IClasspathEntry[0];
                }

                public String getDescription() {
                    return "Unable to get system library for the project";
                }

                public int getKind() {
                    return IClasspathContainer.K_DEFAULT_SYSTEM;
                }

                public IPath getPath() {
                    return null;
                }
            };
        }
    } finally {
        if (markerMessage != null) {
            // log the error and put the marker on the project if we can.
            if (outputToConsole) {
                AdtPlugin.printErrorToConsole(iProject, markerMessage);
            }

            try {
                BaseProjectHelper.addMarker(iProject, AdtConstants.MARKER_TARGET, markerMessage, -1,
                        IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH);
            } catch (CoreException e) {
                // In some cases, the workspace may be locked for modification when we
                // pass here.
                // We schedule a new job to put the marker after.
                final String fmessage = markerMessage;
                Job markerJob = new Job("Android SDK: Resolving error markers") {
                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        try {
                            BaseProjectHelper.addMarker(iProject, AdtConstants.MARKER_TARGET, fmessage, -1,
                                    IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH);
                        } catch (CoreException e2) {
                            return e2.getStatus();
                        }

                        return Status.OK_STATUS;
                    }
                };

                // build jobs are run after other interactive jobs
                markerJob.setPriority(Job.BUILD);
                markerJob.schedule();
            }
        } else {
            // no error, remove potential MARKER_TARGETs.
            try {
                if (iProject.exists()) {
                    iProject.deleteMarkers(AdtConstants.MARKER_TARGET, true, IResource.DEPTH_INFINITE);
                }
            } catch (CoreException ce) {
                // In some cases, the workspace may be locked for modification when we pass
                // here, so we schedule a new job to put the marker after.
                Job markerJob = new Job("Android SDK: Resolving error markers") {
                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        try {
                            iProject.deleteMarkers(AdtConstants.MARKER_TARGET, true, IResource.DEPTH_INFINITE);
                        } catch (CoreException e2) {
                            return e2.getStatus();
                        }

                        return Status.OK_STATUS;
                    }
                };

                // build jobs are run after other interactive jobs
                markerJob.setPriority(Job.BUILD);
                markerJob.schedule();
            }
        }
    }
}

From source file:com.android.ide.eclipse.auidt.internal.project.AndroidClasspathContainerInitializer.java

License:Open Source License

/**
 * Allocates and returns an {@link AndroidClasspathContainer} object with the proper
 * path to the framework jar file./*w  ww .  jav  a2s  .  c om*/
 * @param javaProject The java project that will receive the container.
 */
private static IClasspathContainer allocateAndroidContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();

    String markerMessage = null;
    boolean outputToConsole = true;
    IAndroidTarget target = null;

    try {
        AdtPlugin plugin = AdtPlugin.getDefault();
        if (plugin == null) { // This is totally weird, but I've seen it happen!
            return null;
        }

        synchronized (Sdk.getLock()) {
            boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED;

            // check if the project has a valid target.
            ProjectState state = Sdk.getProjectState(iProject);
            if (state == null) {
                // looks like the project state (project.properties) couldn't be read!
                markerMessage = String.format(
                        "Project has no %1$s file! Edit the project properties to set one.",
                        SdkConstants.FN_PROJECT_PROPERTIES);
            } else {
                // this might be null if the sdk is not yet loaded.
                target = state.getTarget();

                // if we are loaded and the target is non null, we create a valid
                // ClassPathContainer
                if (sdkIsLoaded && target != null) {
                    // first make sure the target has loaded its data
                    Sdk.getCurrent().checkAndLoadTargetData(target, null /*project*/);

                    String targetName = target.getClasspathName();

                    return new AndroidClasspathContainer(createClasspathEntries(iProject, target, targetName),
                            new Path(AdtConstants.CONTAINER_FRAMEWORK), targetName,
                            IClasspathContainer.K_DEFAULT_SYSTEM);
                }

                // In case of error, we'll try different thing to provide the best error message
                // possible.
                // Get the project's target's hash string (if it exists)
                String hashString = state.getTargetHashString();

                if (hashString == null || hashString.length() == 0) {
                    // if there is no hash string we only show this if the SDK is loaded.
                    // For a project opened at start-up with no target, this would be displayed
                    // twice, once when the project is opened, and once after the SDK has
                    // finished loading.
                    // By testing the sdk is loaded, we only show this once in the console.
                    if (sdkIsLoaded) {
                        markerMessage = String
                                .format("Project has no target set. Edit the project properties to set one.");
                    }
                } else if (sdkIsLoaded) {
                    markerMessage = String.format("Unable to resolve target '%s'", hashString);
                } else {
                    // this is the case where there is a hashString but the SDK is not yet
                    // loaded and therefore we can't get the target yet.
                    // We check if there is a cache of the needed information.
                    AndroidClasspathContainer container = getContainerFromCache(iProject, target);

                    if (container == null) {
                        // either the cache was wrong (ie folder does not exists anymore), or
                        // there was no cache. In this case we need to make sure the project
                        // is resolved again after the SDK is loaded.
                        plugin.setProjectToResolve(javaProject);

                        markerMessage = String.format("Unable to resolve target '%s' until the SDK is loaded.",
                                hashString);

                        // let's not log this one to the console as it will happen at
                        // every boot, and it's expected. (we do keep the error marker though).
                        outputToConsole = false;

                    } else {
                        // we created a container from the cache, so we register the project
                        // to be checked for cache validity once the SDK is loaded
                        plugin.setProjectToCheck(javaProject);

                        // and return the container
                        return container;
                    }
                }
            }

            // return a dummy container to replace the one we may have had before.
            // It'll be replaced by the real when if/when the target is resolved if/when the
            // SDK finishes loading.
            return new IClasspathContainer() {
                @Override
                public IClasspathEntry[] getClasspathEntries() {
                    return new IClasspathEntry[0];
                }

                @Override
                public String getDescription() {
                    return "Unable to get system library for the project";
                }

                @Override
                public int getKind() {
                    return IClasspathContainer.K_DEFAULT_SYSTEM;
                }

                @Override
                public IPath getPath() {
                    return null;
                }
            };
        }
    } finally {
        processError(iProject, markerMessage, AdtConstants.MARKER_TARGET, outputToConsole);
    }
}

From source file:com.cisco.surf.jenkow.ide.config.UserLibConfigurator.java

License:Open Source License

private IClasspathContainer createClasspathContainer(final String name, final IClasspathEntry[] entries) {
    return new IClasspathContainer() {
        public IPath getPath() {
            return new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(name);
        }/*from w ww.j  ava 2s  .co m*/

        public int getKind() {
            return K_APPLICATION;
        }

        public String getDescription() {
            return name;
        }

        public IClasspathEntry[] getClasspathEntries() {
            return entries;
        }
    };
}

From source file:com.legstar.eclipse.plugin.common.AbstractClasspathInitializer.java

License:Open Source License

/** {@inheritDoc} */
public void initialize(final IPath containerPath, final IJavaProject project) throws CoreException {

    JavaCore.setClasspathContainer(new Path(mLibraryName), new IJavaProject[] { project },
            new IClasspathContainer[] { new IClasspathContainer() {
                public IClasspathEntry[] getClasspathEntries() {
                    return getLegStarClassPath();
                }/*from w w w .j  a  v a 2s .  c om*/

                public String getDescription() {
                    return mLibraryDescription;
                }

                public int getKind() {
                    return IClasspathContainer.K_SYSTEM;
                }

                public IPath getPath() {
                    return new Path(mLibraryName);
                }
            } }, null);

}

From source file:org.cubictest.exporters.selenium.runner.SeleniumClasspathContainerInitializer.java

License:Open Source License

@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {

    final IPath libPath = JavaCore.getClasspathVariable(CUBICTEST_SELENIUM);
    final IClasspathEntry cubicCoreEntry = JavaCore.newLibraryEntry(libPath.append(pluginName), null, null);
    final IClasspathEntry cubicSeleniumExporterEntry = JavaCore.newLibraryEntry(libPath.append(exporterName),
            libPath.append(exporterName), null);
    final IClasspathEntry cubicSeleniumExporterServerEntry = JavaCore
            .newLibraryEntry(libPath.append(seleniumRCName), libPath.append(seleniumRCName), null);
    final IClasspathEntry jUnitEntry = JavaCore.newLibraryEntry(libPath.append(junitName),
            libPath.append(junitSrcName), null);
    JavaCore.setClasspathContainer(new Path(CUBICTEST_SELENIUM), new IJavaProject[] { project }, // value for 'myProject'
            new IClasspathContainer[] { new IClasspathContainer() {
                public IClasspathEntry[] getClasspathEntries() {
                    return new IClasspathEntry[] { cubicCoreEntry, jUnitEntry, cubicSeleniumExporterEntry,
                            cubicSeleniumExporterServerEntry };
                }// w  w w.jav a 2s  .c o  m

                public String getDescription() {
                    return "CubicTest Selenium Library";
                }

                public int getKind() {
                    return IClasspathContainer.K_APPLICATION;
                }

                public IPath getPath() {
                    return libPath;
                }
            } }, null);
}

From source file:org.eclipse.ajdt.core.tests.builder.CoreOutputLocationManagerTest.java

License:Open Source License

private IClasspathContainer createContainer(IProject base) throws JavaModelException {
    final IClasspathEntry entry = JavaCore.newLibraryEntry(base.getFile("myJarContainer.jar").getFullPath(),
            null, null);/*from w  w  w  .ja  v a2 s  .c  o m*/

    IClasspathContainer container = new IClasspathContainer() {
        public IClasspathEntry[] getClasspathEntries() {
            return new IClasspathEntry[] { entry };
        }

        public String getDescription() {
            return "org.eclipse.jdt.USER_LIBRARY/DECLARING_PROJECT_CONTAINER"; //$NON-NLS-1$
        }

        public int getKind() {
            return IClasspathContainer.K_APPLICATION;
        }

        public IPath getPath() {
            return new Path("org.eclipse.jdt.USER_LIBRARY/DECLARING_PROJECT_CONTAINER"); //$NON-NLS-1$
        }
    };
    JavaCore.setClasspathContainer(container.getPath(), new IJavaProject[] { JavaCore.create(base) },
            new IClasspathContainer[] { container }, null);
    return container;
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuildPathTests.java

License:Open Source License

public void testInpath() throws Exception {

    // create container
    IPath containerPath = new Path("org.eclipse.jdt.USER_LIBRARY/Aspect_Path_Lib"); //$NON-NLS-1$
    IJavaProject inpathJProj = JavaCore.create(hasInpath);
    IClasspathContainer containerHint = new IClasspathContainer() {
        public IPath getPath() {
            return new Path("org.eclipse.jdt.USER_LIBRARY/Aspect_Path_Lib"); //$NON-NLS-1$
        }/*from  w w  w.  j  a  va  2  s.  c o m*/

        public int getKind() {
            return IClasspathContainer.K_APPLICATION;
        }

        public String getDescription() {
            return ""; //$NON-NLS-1$
        }

        public IClasspathEntry[] getClasspathEntries() {
            return new IClasspathEntry[] {
                    JavaCore.newLibraryEntry(containerProj.getLocation().append("container.jar"), null, null) }; //$NON-NLS-1$
        }

    };
    UserLibraryClasspathContainerInitializer initializer = new UserLibraryClasspathContainerInitializer();
    initializer.initialize(containerPath, inpathJProj);
    initializer.requestClasspathContainerUpdate(containerPath, inpathJProj, containerHint);
    waitForJobsToComplete();
    hasInpath.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);

    waitForJobsToComplete();

    // do launch
    AspectJApplicationLaunchShortcut launcher = new AspectJApplicationLaunchShortcut();
    launcher.launch(openFileInAspectJEditor(hasInpath.getFile("src/aspects/AdviseClassOnInpath.aj"), true), //$NON-NLS-1$
            ILaunchManager.RUN_MODE);
    waitForJobsToComplete();
    String console = getConsoleViewContents();
    String exp = "advised container!"; //$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
    exp = "advised project!";//$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
    exp = "advised variable!";//$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
    exp = "advised jar!";//$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
}

From source file:org.eclipse.ajdt.ui.tests.builder.BuildPathTests.java

License:Open Source License

public void testAspectPath() throws Exception {
    // Ignore these tests on Linux because not passing
    if (System.getProperty("os.name").equals("Linux")) {
        return;/* w  w w. j ava  2 s .  c o m*/
    }

    // create container
    IPath containerPath = new Path("org.eclipse.jdt.USER_LIBRARY/Aspect_Path_Lib"); //$NON-NLS-1$
    IJavaProject aspectpathJProj = JavaCore.create(hasAspectpath);
    IClasspathContainer containerHint = new IClasspathContainer() {
        public IPath getPath() {
            return new Path("org.eclipse.jdt.USER_LIBRARY/Aspect_Path_Lib"); //$NON-NLS-1$
        }

        public int getKind() {
            return IClasspathContainer.K_APPLICATION;
        }

        public String getDescription() {
            return ""; //$NON-NLS-1$
        }

        public IClasspathEntry[] getClasspathEntries() {
            return new IClasspathEntry[] {
                    JavaCore.newLibraryEntry(containerProj.getLocation().append("container.jar"), null, null) }; //$NON-NLS-1$
        }
    };
    UserLibraryClasspathContainerInitializer initializer = new UserLibraryClasspathContainerInitializer();
    initializer.initialize(containerPath, aspectpathJProj);
    initializer.requestClasspathContainerUpdate(containerPath, aspectpathJProj, containerHint);

    waitForJobsToComplete();

    hasAspectpath.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);

    // do launch
    AspectJApplicationLaunchShortcut launcher = new AspectJApplicationLaunchShortcut();
    launcher.launch(openFileInAspectJEditor(hasAspectpath.getFile("src/main/Main.java"), true), //$NON-NLS-1$
            ILaunchManager.RUN_MODE);
    waitForJobsToComplete();
    String console = getConsoleViewContents();
    String exp = "from project aspect"; //$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
    exp = "from jar aspect"; //$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
    exp = "from variable aspect"; //$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
    exp = "from container aspect"; //$NON-NLS-1$
    assertTrue("Did not find expected string '" + exp + "' in console output:\n" + console, //$NON-NLS-1$//$NON-NLS-2$
            console.indexOf(exp) != -1);
}

From source file:org.eclipse.andmore.internal.project.AndroidClasspathContainerInitializer.java

License:Open Source License

/**
 * Allocates and returns an {@link AndroidClasspathContainer} object with the proper
 * path to the framework jar file./*from  www.j  a  v a 2  s .c  om*/
 * @param javaProject The java project that will receive the container.
 */
private static IClasspathContainer allocateAndroidContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();

    String markerMessage = null;
    boolean outputToConsole = true;
    IAndroidTarget target = null;

    try {
        AndmoreAndroidPlugin plugin = AndmoreAndroidPlugin.getDefault();
        if (plugin == null) { // This is totally weird, but I've seen it happen!
            return null;
        }

        synchronized (Sdk.getLock()) {
            boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED;

            // check if the project has a valid target.
            ProjectState state = Sdk.getProjectState(iProject);
            if (state == null) {
                // looks like the project state (project.properties) couldn't be read!
                markerMessage = String.format(
                        "Project has no %1$s file! Edit the project properties to set one.",
                        SdkConstants.FN_PROJECT_PROPERTIES);
            } else {
                // this might be null if the sdk is not yet loaded.
                target = state.getTarget();

                // if we are loaded and the target is non null, we create a valid
                // ClassPathContainer
                if (sdkIsLoaded && target != null) {
                    // check the renderscript support mode. If support mode is enabled,
                    // target API must be 18+
                    if (!state.getRenderScriptSupportMode() || target.getVersion().getApiLevel() >= 18) {
                        // first make sure the target has loaded its data
                        Sdk.getCurrent().checkAndLoadTargetData(target, null /*project*/);

                        String targetName = target.getClasspathName();

                        return new AndroidClasspathContainer(
                                createClasspathEntries(iProject, target, targetName),
                                new Path(AndmoreAndroidConstants.CONTAINER_FRAMEWORK), targetName,
                                IClasspathContainer.K_DEFAULT_SYSTEM);
                    } else {
                        markerMessage = "Renderscript support mode requires compilation target API to be 18+.";
                    }
                } else {
                    // In case of error, we'll try different thing to provide the best error message
                    // possible.
                    // Get the project's target's hash string (if it exists)
                    String hashString = state.getTargetHashString();

                    if (hashString == null || hashString.length() == 0) {
                        // if there is no hash string we only show this if the SDK is loaded.
                        // For a project opened at start-up with no target, this would be displayed
                        // twice, once when the project is opened, and once after the SDK has
                        // finished loading.
                        // By testing the sdk is loaded, we only show this once in the console.
                        if (sdkIsLoaded) {
                            markerMessage = String.format(
                                    "Project has no target set. Edit the project properties to set one.");
                        }
                    } else if (sdkIsLoaded) {
                        markerMessage = String.format("Unable to resolve target '%s'", hashString);
                    } else {
                        // this is the case where there is a hashString but the SDK is not yet
                        // loaded and therefore we can't get the target yet.
                        // We check if there is a cache of the needed information.
                        AndroidClasspathContainer container = getContainerFromCache(iProject, target);

                        if (container == null) {
                            // either the cache was wrong (ie folder does not exists anymore), or
                            // there was no cache. In this case we need to make sure the project
                            // is resolved again after the SDK is loaded.
                            plugin.setProjectToResolve(javaProject);

                            markerMessage = String.format(
                                    "Unable to resolve target '%s' until the SDK is loaded.", hashString);

                            // let's not log this one to the console as it will happen at
                            // every boot, and it's expected. (we do keep the error marker though).
                            outputToConsole = false;

                        } else {
                            // we created a container from the cache, so we register the project
                            // to be checked for cache validity once the SDK is loaded
                            plugin.setProjectToCheck(javaProject);

                            // and return the container
                            return container;
                        }
                    }
                }
            }

            // return a dummy container to replace the one we may have had before.
            // It'll be replaced by the real when if/when the target is resolved if/when the
            // SDK finishes loading.
            return new IClasspathContainer() {
                @Override
                public IClasspathEntry[] getClasspathEntries() {
                    return new IClasspathEntry[0];
                }

                @Override
                public String getDescription() {
                    return "Unable to get system library for the project";
                }

                @Override
                public int getKind() {
                    return IClasspathContainer.K_DEFAULT_SYSTEM;
                }

                @Override
                public IPath getPath() {
                    return null;
                }
            };
        }
    } finally {
        processError(iProject, markerMessage, AndmoreAndroidConstants.MARKER_TARGET, outputToConsole);
    }
}