List of usage examples for org.eclipse.jdt.core ClasspathContainerInitializer initialize
public abstract void initialize(IPath containerPath, IJavaProject project) throws CoreException;
IClasspathContainer for a given project, or silently fails if unable to do so. From source file:ch.mlutz.plugins.t4e.handlers.ClasspathContainerHandler.java
License:Open Source License
private Object onAddClasspathContainer(ExecutionEvent event) throws ExecutionException { // boolean oldValue = HandlerUtil.toggleCommandState(event.getCommand()); String localRepositoryDir = MavenTools.getMavenLocalRepoPath(); log.info("LocalRepositoryDir: " + localRepositoryDir); /*/* w w w.j a va2s . c om*/ try { JavaCore.setClasspathContainer(containerSuggestion.getPath(), new IJavaProject[] {project}, new IClasspathContainer[] {new Maven2ClasspathContainer(containerPath, bundleUpdater.newEntries)}, null); } catch(JavaModelException ex) { Maven2Plugin.getDefault().getConsole().logError(ex.getMessage()); } */ // get workbench window IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); // set selection service ISelectionService service = window.getSelectionService(); // set structured selection IStructuredSelection structured = (IStructuredSelection) service.getSelection(); //check if it is an IFile Object el = structured.getFirstElement(); if (el instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) el; // Create new Classpath Container Entry IClasspathEntry containerEntry = JavaCore.newContainerEntry(CONTAINER_PATH); // Initialize Classpath Container ClasspathContainerInitializer containerInit = JavaCore .getClasspathContainerInitializer(Constants.CONTAINER_ID); try { containerInit.initialize(new Path(Constants.CONTAINER_ID), javaProject); // Set Classpath of Java Project List<IClasspathEntry> projectClassPath = new ArrayList<IClasspathEntry>( Arrays.asList(javaProject.getRawClasspath())); projectClassPath.add(containerEntry); javaProject.setRawClasspath(projectClassPath.toArray(new IClasspathEntry[projectClassPath.size()]), null); } catch (CoreException e) { log.error("Could not add Classpath container: ", e); } /* IClasspathEntry varEntry = JavaCore.newContainerEntry( new Path("JDKLIB/default"), // container 'JDKLIB' + hint 'default' false); //not exported try { JavaCore.setClasspathContainer( new Path("JDKLIB/default"), new IJavaProject[]{ (IJavaProject) el }, // value for 'myProject' new IClasspathContainer[] { new IClasspathContainer() { public IClasspathEntry[] getClasspathEntries() { return new IClasspathEntry[]{ JavaCore.newLibraryEntry(new Path("d:/rt.jar"), null, null, false) }; } public String getDescription() { return "Basic JDK library container"; } public int getKind() { return IClasspathContainer.K_SYSTEM; } public IPath getPath() { return new Path("JDKLIB/basic"); } } }, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } return null; }
From source file:com.gwtplatform.plugin.wizard.NewProjectWizard.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" })
protected boolean finish(IProgressMonitor desiredMonitor) {
IProgressMonitor monitor = desiredMonitor;
if (monitor == null) {
monitor = new NullProgressMonitor();
}/* ww w . j a va2s. co m*/
try {
if (GWTPreferences.getDefaultRuntime().getVersion().isEmpty()) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No default GWT SDK.");
ErrorDialog.openError(getShell(), null, null, status);
return false;
}
monitor.beginTask("GWT-Platform project creation", 4);
// Project base creation
monitor.subTask("Base project creation");
formattedName = projectNameToClassName(page.getProjectName(), page.isRemoveEnabled());
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(page.getProjectName());
// Project location
URI location = null;
String workspace = ResourcesPlugin.getWorkspace().getRoot().getLocationURI().toString() + "/";
if (page.getProjectLocation() != null && !workspace.equals(page.getProjectLocation().toString())) {
location = page.getProjectLocation();
}
IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName());
description.setLocationURI(location);
// Project natures and builders
ICommand javaBuilder = description.newCommand();
javaBuilder.setBuilderName(JavaCore.BUILDER_ID);
ICommand webAppBuilder = description.newCommand();
webAppBuilder.setBuilderName(WebAppProjectValidator.BUILDER_ID);
ICommand gwtBuilder = description.newCommand();
// TODO use the BUILDER_UI field
gwtBuilder.setBuilderName("com.google.gwt.eclipse.core.gwtProjectValidator");
if (page.useGAE()) {
ICommand gaeBuilder = description.newCommand();
gaeBuilder.setBuilderName(GaeProjectValidator.BUILDER_ID);
// TODO use the BUILDER_UI field
ICommand enhancer = description.newCommand();
// TODO use the BUILDER_UI field
enhancer.setBuilderName("com.google.appengine.eclipse.core.enhancerbuilder");
description.setBuildSpec(
new ICommand[] { javaBuilder, webAppBuilder, gwtBuilder, gaeBuilder, enhancer });
description.setNatureIds(
new String[] { JavaCore.NATURE_ID, GWTNature.NATURE_ID, GaeNature.NATURE_ID });
} else {
description.setBuildSpec(new ICommand[] { javaBuilder, webAppBuilder, gwtBuilder });
description.setNatureIds(new String[] { JavaCore.NATURE_ID, GWTNature.NATURE_ID });
}
project.create(description, monitor);
if (!project.isOpen()) {
project.open(monitor);
}
monitor.worked(1);
// Java Project creation
monitor.subTask("Classpath entries creation");
IJavaProject javaProject = JavaCore.create(project);
// war/WEB-INF/lib folder creation
IPath warPath = new Path("war");
project.getFolder(warPath).create(false, true, monitor);
IPath webInfPath = warPath.append("WEB-INF");
project.getFolder(webInfPath).create(false, true, monitor);
IPath libPath = webInfPath.append("lib");
project.getFolder(libPath).create(false, true, monitor);
Thread.sleep(1000);
Jar[] libs = VersionTool.getLibs(project, libPath);
// Classpath Entries creation
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
// Default output location
IPath outputPath = new Path("/" + page.getProjectName()).append(webInfPath).append("classes");
javaProject.setOutputLocation(outputPath, monitor);
// Source folder
IPath srcPath = new Path("src");
project.getFolder(srcPath).create(false, true, monitor);
entries.add(JavaCore.newSourceEntry(javaProject.getPath().append("src")));
// GWT SDK container
IPath gwtContainer = GWTRuntimeContainer.CONTAINER_PATH;
ClasspathContainerInitializer gwtInitializer = JavaCore
.getClasspathContainerInitializer(gwtContainer.segment(0));
gwtInitializer.initialize(gwtContainer, javaProject);
entries.add(JavaCore.newContainerEntry(gwtContainer));
// GAE SDK container
if (page.useGAE()) {
IPath gaeContainer = GaeSdkContainer.CONTAINER_PATH;
ClasspathContainerInitializer gaeInitializer = JavaCore
.getClasspathContainerInitializer(gaeContainer.segment(0));
gaeInitializer.initialize(gaeContainer, javaProject);
entries.add(JavaCore.newContainerEntry(gaeContainer));
}
// JRE container
entries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary()));
// GWTP libs
for (Jar lib : libs) {
entries.add(JavaCore.newLibraryEntry(lib.getFile().getFullPath(), null, null));
}
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
monitor.worked(1);
monitor.subTask("Default classes creation");
IPackageFragmentRoot root = javaProject.findPackageFragmentRoot(javaProject.getPath().append("src"));
// Create sources
if (page.useGAE()) {
Log4j log4j = new Log4j(project, srcPath);
log4j.createFile();
IPath metaInfPath = srcPath.append("META-INF");
project.getFolder(metaInfPath).create(false, true, monitor);
Jdoconfig jdoconfig = new Jdoconfig(project, metaInfPath);
jdoconfig.createFile();
}
IPackageFragment projectPackage = root.createPackageFragment(page.getProjectPackage(), false, monitor);
// Client package
IPackageFragment clientPackage = root.createPackageFragment(projectPackage.getElementName() + ".client",
false, monitor);
// Place package
IPackageFragment placePackage = root.createPackageFragment(clientPackage.getElementName() + ".place",
false, monitor);
PlaceAnnotation defaultPlace = new PlaceAnnotation(root, placePackage.getElementName(), "DefaultPlace",
sourceWriterFactory);
PlaceManager placeManager = new PlaceManager(root, placePackage.getElementName(), "ClientPlaceManager",
sourceWriterFactory);
IField defaultPlaceField = placeManager.createPlaceRequestField(defaultPlace.getType());
placeManager.createConstructor(new IType[] { defaultPlace.getType() },
new IField[] { defaultPlaceField });
placeManager.createRevealDefaultPlaceMethod(defaultPlaceField);
Tokens tokens = new Tokens(root, placePackage.getElementName(), "NameTokens", sourceWriterFactory);
// Gin package
IPackageFragment ginPackage = root.createPackageFragment(clientPackage.getElementName() + ".gin", false,
monitor);
PresenterModule presenterModule = new PresenterModule(root, ginPackage.getElementName(), "ClientModule",
sourceWriterFactory);
presenterModule.createConfigureMethod(placeManager.getType());
Ginjector ginjector = new Ginjector(root, ginPackage.getElementName(), "ClientGinjector",
presenterModule.getType(), sourceWriterFactory);
ginjector.createDefaultGetterMethods();
// Client package contents
EntryPoint entryPoint = new EntryPoint(root, clientPackage.getElementName(), formattedName,
sourceWriterFactory);
entryPoint.createGinjectorField(ginjector.getType());
entryPoint.createOnModuleLoadMethod();
// Project package contents
GwtXmlModule gwtXmlModule = new GwtXmlModule(root, projectPackage.getElementName(), formattedName);
gwtXmlModule.createFile(entryPoint.getType(), ginjector.getType());
// Server package
IPackageFragment serverPackage = root.createPackageFragment(projectPackage.getElementName() + ".server",
false, monitor);
// Guice package
IPackageFragment guicePackage = root.createPackageFragment(serverPackage.getElementName() + ".guice",
false, monitor);
String gwtVersion = GWTPreferences.getDefaultRuntime().getVersion();
ServletModule servletModule = new ServletModule(root, guicePackage.getElementName(),
"DispatchServletModule", sourceWriterFactory);
servletModule.createConfigureServletsMethod(gwtVersion);
GuiceHandlerModule handlerModule = new GuiceHandlerModule(root, guicePackage.getElementName(),
"ServerModule", sourceWriterFactory);
handlerModule.createConfigureHandlersMethod();
GuiceServletContextListener guiceServletContextListener = new GuiceServletContextListener(root,
guicePackage.getElementName(), "GuiceServletConfig", sourceWriterFactory);
guiceServletContextListener.createInjectorGetterMethod(handlerModule.getType(),
servletModule.getType());
// Shared package
root.createPackageFragment(projectPackage.getElementName() + ".shared", false, monitor);
// Basic sample creation
if (page.isSample()) {
BasicSampleBuilder sampleBuilder = new BasicSampleBuilder(root, projectPackage,
sourceWriterFactory);
sampleBuilder.createSample(ginjector, presenterModule, tokens, defaultPlace, handlerModule);
}
// Commit
presenterModule.commit();
ginjector.commit();
defaultPlace.commit();
placeManager.commit();
tokens.commit();
entryPoint.commit();
servletModule.commit();
handlerModule.commit();
guiceServletContextListener.commit();
// war contents
ProjectHTML projectHTML = new ProjectHTML(project, warPath, project.getName());
projectHTML.createFile();
ProjectCSS projectCSS = new ProjectCSS(project, warPath, project.getName());
projectCSS.createFile();
// war/WEB-INF contents
WebXml webXml = new WebXml(project, webInfPath);
webXml.createFile(projectHTML.getFile(), guiceServletContextListener.getType());
if (page.useGAE()) {
AppengineWebXml appengineWebXml = new AppengineWebXml(project, webInfPath);
appengineWebXml.createFile();
Logging logging = new Logging(project, webInfPath);
logging.createFile();
}
monitor.worked(1);
// Launch Config
monitor.subTask("Launch config creation");
ILaunchConfigurationWorkingCopy launchConfig = WebAppLaunchUtil.createLaunchConfigWorkingCopy(
project.getName(), project, WebAppLaunchUtil.determineStartupURL(project, false), false);
ILaunchGroup[] groups = DebugUITools.getLaunchGroups();
ArrayList groupsNames = new ArrayList();
for (ILaunchGroup group : groups) {
if ((!("org.eclipse.debug.ui.launchGroup.debug".equals(group.getIdentifier())))
&& (!("org.eclipse.debug.ui.launchGroup.run".equals(group.getIdentifier())))) {
continue;
}
groupsNames.add(group.getIdentifier());
}
launchConfig.setAttribute("org.eclipse.debug.ui.favoriteGroups", groupsNames);
launchConfig.doSave();
project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "nametokens"),
tokens.getType().getFullyQualifiedName());
project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "ginjector"),
ginjector.getType().getFullyQualifiedName());
project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "presentermodule"),
presenterModule.getType().getFullyQualifiedName());
project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "handlermodule"),
handlerModule.getType().getFullyQualifiedName());
project.getProject().setPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "action"),
"com.gwtplatform.dispatch.shared.ActionImpl");
// Remove bin folder
IFolder binFolder = project.getFolder(new Path("/bin"));
if (binFolder.exists()) {
binFolder.delete(true, monitor);
}
monitor.worked(1);
} catch (Exception e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"An unexpected error has happened. Close the wizard and retry.", e);
ErrorDialog.openError(getShell(), null, null, status);
return false;
}
monitor.done();
return true;
}
From source file:org.ebayopensource.turmeric.eclipse.buildsystem.utils.BuildSystemUtil.java
License:Open Source License
/** * Updates the SOA Container. Rather than update a better name for this API * would be re-initialize. This basically fetches the associated container * initializer and as the initializer to reinitialize the container, which * in turn calls the container call back methods. * * @param project the project//from w ww .j av a 2 s . c om * @throws CoreException the core exception */ public static void updateSOAClasspathContainer(final IProject project) throws CoreException { final IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); final String containerId = GlobalRepositorySystem.instanceOf().getActiveRepositorySystem() .getClasspathContainerID(); final IPath containerPath = new Path(containerId); final ClasspathContainerInitializer containerInitializer = JavaCore .getClasspathContainerInitializer(containerId); containerInitializer.initialize(containerPath, javaProject); }
From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java
License:Open Source License
/** * Update maven classpath container.//from w w w . ja v a 2 s . c o m * * @param project the project * @param dependentName the dependent name * @param type the type * @throws CoreException the core exception * @throws InterruptedException the interrupted exception */ public static void updateMavenClasspathContainer(final IProject project, final String dependentName, final String type) throws CoreException, InterruptedException { final IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); final IPath containerPath = new Path(SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID); final ClasspathContainerInitializer containerInitializer = JavaCore .getClasspathContainerInitializer(SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID); if (containerInitializer.canUpdateClasspathContainer(containerPath, javaProject)) { final IClasspathContainer mavenContainer = getMaven2ClasspathContainer(javaProject); containerInitializer.requestClasspathContainerUpdate(containerPath, javaProject, mavenContainer); containerInitializer.initialize(containerPath, javaProject); /* * project.build(IncrementalProjectBuilder.FULL_BUILD, * ProgressUtil.getDefaultMonitor(null)); */ // TODO this is a hot fix for the Maven class path issue // it will continuously wait until the newly added service is // available in the classpath String tlGroupId = getMavenOrgProviderInstance().getProjectGroupId(SupportedProjectType.TYPE_LIBRARY); if (IAssetInfo.TYPE_SERVICE_LIBRARY.equals(type)) { waitForClasspathContainerToUpdate( getMavenOrgProviderInstance().getProjectGroupId(SupportedProjectType.INTERFACE), javaProject, dependentName); } else if (tlGroupId.equals(type)) { waitForClasspathContainerToUpdate(tlGroupId, javaProject, dependentName); } } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException { IProgressMonitor monitor = this.batchContainerInitializationsProgress; if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); IClasspathContainer container = null; final ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer(containerPath.segment(0)); if (initializer != null) { if (CP_RESOLVE_VERBOSE) verbose_triggering_container_initialization(project, containerPath, initializer); if (CP_RESOLVE_VERBOSE_ADVANCED) verbose_triggering_container_initialization_invocation_trace(); PerformanceStats stats = null;//from ww w . j a v a 2 s . c o m if (JavaModelManager.PERF_CONTAINER_INITIALIZER) { stats = PerformanceStats.getStats(JavaModelManager.CONTAINER_INITIALIZER_PERF, this); stats.startRun(containerPath + " of " + project.getPath()); //$NON-NLS-1$ } containerPut(project, containerPath, CONTAINER_INITIALIZATION_IN_PROGRESS); // avoid initialization cycles boolean ok = false; try { if (monitor != null) monitor.subTask(Messages.bind(Messages.javamodel_configuring, initializer.getDescription(containerPath, project))); // let OperationCanceledException go through // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59363) initializer.initialize(containerPath, project); if (monitor != null) monitor.subTask(""); //$NON-NLS-1$ // retrieve value (if initialization was successful) container = containerBeingInitializedGet(project, containerPath); if (container == null && containerGet(project, containerPath) == CONTAINER_INITIALIZATION_IN_PROGRESS) { // initializer failed to do its job: redirect to the failure container container = initializer.getFailureContainer(containerPath, project); if (container == null) { if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE) verbose_container_null_failure_container(project, containerPath, initializer); return null; // break cycle } if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE) verbose_container_using_failure_container(project, containerPath, initializer); containerPut(project, containerPath, container); } ok = true; } catch (CoreException e) { if (e instanceof JavaModelException) { throw (JavaModelException) e; } else { throw new JavaModelException(e); } } catch (RuntimeException e) { if (JavaModelManager.CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE) e.printStackTrace(); throw e; } catch (Error e) { if (JavaModelManager.CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE) e.printStackTrace(); throw e; } finally { if (JavaModelManager.PERF_CONTAINER_INITIALIZER) { stats.endRun(); } if (!ok) { // just remove initialization in progress and keep previous session container so as to avoid a full build // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=92588 containerRemoveInitializationInProgress(project, containerPath); if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE) verbose_container_initialization_failed(project, containerPath, container, initializer); } } if (CP_RESOLVE_VERBOSE_ADVANCED) verbose_container_value_after_initialization(project, containerPath, container); } else { // create a dummy initializer and get the default failure container container = (new ClasspathContainerInitializer() { public void initialize(IPath path, IJavaProject javaProject) throws CoreException { // not used } }).getFailureContainer(containerPath, project); if (CP_RESOLVE_VERBOSE_ADVANCED || CP_RESOLVE_VERBOSE_FAILURE) verbose_no_container_initializer_found(project, containerPath); } return container; }