List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:com.liferay.ide.project.ui.wizard.NewPluginProjectWizard.java
License:Open Source License
private IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) { final String projectName = project.getName(); final IJavaProject javaProject = JavaCore.create(project); final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true); final ClasspathSetup classpathSetup = new ClasspathSetup(); conf.setAdvancedProjectSpecific(false); conf.setClasspathSetup(classpathSetup); conf.setClassthProjectSpecific(false); conf.setConfs(Collections.singletonList("*")); //$NON-NLS-1$ conf.setMappingProjectSpecific(false); conf.setSettingsProjectSpecific(true); SDK sdk = SDKUtil.getSDK(project);//from ww w. j ava2 s . c o m final SettingsSetup settingsSetup = new SettingsSetup(); if (sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE).toFile().exists()) { StringBuilder builder = new StringBuilder(); builder.append("${"); //$NON-NLS-1$ builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR); builder.append(":"); //$NON-NLS-1$ builder.append(projectName); builder.append("}/"); //$NON-NLS-1$ builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE); settingsSetup.setIvySettingsPath(builder.toString()); } StringBuilder builder = new StringBuilder(); builder.append("${"); //$NON-NLS-1$ builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR); builder.append(":"); //$NON-NLS-1$ builder.append(projectName); builder.append("}/.ivy"); //$NON-NLS-1$ settingsSetup.setIvyUserDir(builder.toString()); conf.setIvySettingsSetup(settingsSetup); final IPath path = IvyClasspathContainerConfAdapter.getPath(conf); final IClasspathAttribute[] atts = conf.getAttributes(); final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false); final IVirtualComponent virtualComponent = ComponentCore.createComponent(project); try { IvyClasspathContainer ivycp = new IvyClasspathContainer(javaProject, path, new IClasspathEntry[0], new IClasspathAttribute[0]); JavaCore.setClasspathContainer(path, new IJavaProject[] { javaProject }, new IClasspathContainer[] { ivycp }, monitor); IClasspathEntry[] entries = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(Arrays.asList(entries)); IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry); // add the deployment assembly config to deploy ivy container to /WEB-INF/lib final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath); newEntries.add(cpeTagged); entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor); return ivycp; } catch (JavaModelException e) { ProjectUIPlugin.logError("Unable to add Ivy library container", e); //$NON-NLS-1$ } return null; }
From source file:com.liferay.ide.sdk.ui.SDKProjectRenameParticipant.java
License:Open Source License
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { final String newName = this.getArguments().getNewName(); return new Change() { @Override//from ww w .j a va 2 s . co m public String getName() { return "Update Ivy classpath entry"; //$NON-NLS-1$ } @Override public void initializeValidationData(IProgressMonitor pm) { System.out.println(); } @Override public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException { return new RefactoringStatus(); } @Override public Change perform(IProgressMonitor pm) throws CoreException { final RenameJavaProjectProcessor rjpp = (RenameJavaProjectProcessor) getProcessor(); final IJavaProject newJavaProject = (IJavaProject) rjpp.getNewElement(); final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration( newJavaProject, ISDKConstants.IVY_XML_FILE, true); IClasspathEntry oldEntry = null; for (IClasspathEntry cpEntry : newJavaProject.getRawClasspath()) { if (cpEntry.getPath().segment(0).equals(IvyClasspathContainer.CONTAINER_ID)) { oldEntry = cpEntry; break; } } IvyClasspathContainerConfAdapter.load(conf, oldEntry.getPath(), oldEntry.getExtraAttributes()); final String oldIvySettingsPath = conf.getIvySettingsSetup().getRawIvySettingsPath(); final String oldIvyUserDir = conf.getIvySettingsSetup().getRawIvyUserDir(); conf.setProject(newJavaProject); conf.getIvySettingsSetup().setIvySettingsPath(oldIvySettingsPath.replaceAll(oldName, newName)); conf.getIvySettingsSetup().setIvyUserDir(oldIvyUserDir.replaceAll(oldName, newName)); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry cpEntry : newJavaProject.getRawClasspath()) { if (!cpEntry.getPath().segment(0).equals(IvyClasspathContainer.CONTAINER_ID)) { newEntries.add(cpEntry); } } IPath newIvyPath = IvyClasspathContainerConfAdapter.getPath(conf); newJavaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), pm); IClasspathEntry ivyEntry = JavaCore.newContainerEntry(newIvyPath, null, oldEntry.getExtraAttributes(), false); IvyClasspathContainer ivycp = new IvyClasspathContainer(newJavaProject, newIvyPath, new IClasspathEntry[0], new IClasspathAttribute[0]); JavaCore.setClasspathContainer(newIvyPath, new IJavaProject[] { newJavaProject }, new IClasspathContainer[] { ivycp }, pm); IClasspathEntry[] entries = newJavaProject.getRawClasspath(); newEntries.add(ivyEntry); entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); newJavaProject.setRawClasspath(entries, newJavaProject.getOutputLocation(), pm); JavaCore.getClasspathContainerInitializer(IvyClasspathContainer.CONTAINER_ID) .requestClasspathContainerUpdate(newIvyPath, newJavaProject, ivycp); ivycp.launchResolve(false, pm); return null; } @Override public Object getModifiedElement() { return null; } }; }
From source file:com.liferay.ide.server.remote.ModuleTraverser.java
License:Open Source License
private static IPath getOSPath(IProject project, IJavaProject javaProject, IPath outputPath) throws JavaModelException { if (outputPath == null) outputPath = javaProject.getOutputLocation(); // If we have the root of a project, return project location if (outputPath.segmentCount() == 1) { return ResourcesPlugin.getWorkspace().getRoot().getProject(outputPath.lastSegment()).getLocation(); }/*from ww w . jav a 2 s.co m*/ // Otherwise return project folder location return ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath).getLocation(); }
From source file:com.proxiad.emfcustomizer.stylesheet.dsl.contentassist.StylesheetProposalProvider.java
License:Open Source License
/** * Return true if the folder is valid to search for customizable models * //from w w w.jav a2s . c o m * @param folder * a given IFolder in the IProject * @return if the folder is valid to search for customizable models */ private boolean isValidFolderForFindingCustomizableFiles(IFolder folder) { boolean res = true; List<String> naturesProject = new ArrayList<String>(); IProject project = folder.getProject(); // List the project's natures available try { naturesProject = Arrays.asList(project.getDescription().getNatureIds()); } catch (CoreException e1) { // ignore } // if a project has a javaProject nature if (naturesProject.contains(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); try { IPath location = folder.getFullPath(); IPath outputLocation = javaProject.getOutputLocation(); // Is "location" equal to a "outputLocation of the project" OR // "one // of the outputLocation in a folder" ? res = (outputLocation.equals(location) || (checkOutputLocationForEachFolder(javaProject, folder))); } catch (JavaModelException e) { // ignore } } return !res; }
From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java
License:Open Source License
/** * Sets the configured build path and output location to the given Java project. * If the project already exists, only build paths are updated. * <p>// ww w . ja v a 2s.c om * If the classpath contains an Execution Environment entry, the EE's compiler compliance options * are used as project-specific options (unless the classpath already contained the same Execution Environment) * * @param classPathEntries the new classpath entries (list of {@link CPListElement}) * @param javaOutputLocation the output location * @param javaProject the Java project * @param newProjectCompliance compliance to set for a new project, can be <code>null</code> * @param monitor a progress monitor, or <code>null</code> * @throws CoreException if flushing failed * @throws OperationCanceledException if flushing has been cancelled */ public static void flush(List<CPListElement> classPathEntries, List<CPListElement> resourcePathEntries, IPath javaOutputLocation, IJavaProject javaProject, String newProjectCompliance, IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.setTaskName(NewWizardMessages.BuildPathsBlock_operationdesc_java); monitor.beginTask("", classPathEntries.size() * 4 + 4); //$NON-NLS-1$ try { IProject project = javaProject.getProject(); IPath projPath = project.getFullPath(); IPath oldOutputLocation; try { oldOutputLocation = javaProject.getOutputLocation(); } catch (CoreException e) { oldOutputLocation = projPath.append( PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); } if (oldOutputLocation.equals(projPath) && !javaOutputLocation.equals(projPath)) { if (CeylonBuildPathsBlock.hasClassfiles(project)) { if (CeylonBuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(false, projPath)) { CeylonBuildPathsBlock.removeOldClassfiles(project); } } } else if (!javaOutputLocation.equals(oldOutputLocation)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation); if (folder.exists()) { if (folder.members().length == 0) { CeylonBuildPathsBlock.removeOldClassfiles(folder); } else { if (CeylonBuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(folder.isDerived(), oldOutputLocation)) { CeylonBuildPathsBlock.removeOldClassfiles(folder); } } } } getCeylonModulesOutputFolder(project).delete(true, monitor); monitor.worked(1); IWorkspaceRoot fWorkspaceRoot = JavaPlugin.getWorkspace().getRoot(); //create and set the output path first if (!fWorkspaceRoot.exists(javaOutputLocation)) { CoreUtility.createDerivedFolder(fWorkspaceRoot.getFolder(javaOutputLocation), true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } for (Iterator<CPListElement> iter = resourcePathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); IResource res = entry.getResource(); //1 tick if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) { CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } //3 ticks if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT); if (folderOutput != null && folderOutput.segmentCount() > 1) { IFolder folder = fWorkspaceRoot.getFolder(folderOutput); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } IPath path = entry.getPath(); if (projPath.equals(path)) { monitor.worked(2); continue; } if (projPath.isPrefixOf(path)) { path = path.removeFirstSegments(projPath.segmentCount()); } IFolder folder = project.getFolder(path); IPath orginalPath = entry.getOrginalPath(); if (orginalPath == null) { if (!folder.exists()) { //New source folder needs to be created if (entry.getLinkTarget() == null) { CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2)); } else { folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 2)); } } } else { if (projPath.isPrefixOf(orginalPath)) { orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount()); } IFolder orginalFolder = project.getFolder(orginalPath); if (entry.getLinkTarget() == null) { if (!folder.exists()) { //Source folder was edited, move to new location IPath parentPath = entry.getPath().removeLastSegments(1); if (projPath.isPrefixOf(parentPath)) { parentPath = parentPath.removeFirstSegments(projPath.segmentCount()); } if (parentPath.segmentCount() > 0) { IFolder parentFolder = project.getFolder(parentPath); if (!parentFolder.exists()) { CoreUtility.createFolder(parentFolder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } } else { monitor.worked(1); } orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1)); } } else { if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) { orginalFolder.delete(true, new SubProgressMonitor(monitor, 1)); folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); } } } } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } int nEntries = classPathEntries.size(); IClasspathEntry[] classpath = new IClasspathEntry[nEntries]; int i = 0; for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); classpath[i] = entry.getClasspathEntry(); i++; IResource res = entry.getResource(); //1 tick if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) { CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } //3 ticks if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT); if (folderOutput != null && folderOutput.segmentCount() > 1) { IFolder folder = fWorkspaceRoot.getFolder(folderOutput); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } IPath path = entry.getPath(); if (projPath.equals(path)) { monitor.worked(2); continue; } if (projPath.isPrefixOf(path)) { path = path.removeFirstSegments(projPath.segmentCount()); } IFolder folder = project.getFolder(path); IPath orginalPath = entry.getOrginalPath(); if (orginalPath == null) { if (!folder.exists()) { //New source folder needs to be created if (entry.getLinkTarget() == null) { CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2)); } else { folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 2)); } } } else { if (projPath.isPrefixOf(orginalPath)) { orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount()); } IFolder orginalFolder = project.getFolder(orginalPath); if (entry.getLinkTarget() == null) { if (!folder.exists()) { //Source folder was edited, move to new location IPath parentPath = entry.getPath().removeLastSegments(1); if (projPath.isPrefixOf(parentPath)) { parentPath = parentPath.removeFirstSegments(projPath.segmentCount()); } if (parentPath.segmentCount() > 0) { IFolder parentFolder = project.getFolder(parentPath); if (!parentFolder.exists()) { CoreUtility.createFolder(parentFolder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } } else { monitor.worked(1); } orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1)); } } else { if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) { orginalFolder.delete(true, new SubProgressMonitor(monitor, 1)); folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); } } } } else { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (!path.equals(entry.getOrginalPath())) { String eeID = JavaRuntime.getExecutionEnvironmentId(path); if (eeID != null) { BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance); newProjectCompliance = null; // don't set it again below } } if (newProjectCompliance != null) { setOptionsFromJavaProject(javaProject, newProjectCompliance); } } monitor.worked(3); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } javaProject.setRawClasspath(classpath, javaOutputLocation, new SubProgressMonitor(monitor, 2)); CeylonProjectConfig config = CeylonProjectConfig.get(project); List<String> srcDirs = new ArrayList<String>(); for (CPListElement cpe : classPathEntries) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcDirs.add(configFilePath(project, cpe)); } } config.setProjectSourceDirectories(srcDirs); List<String> rsrcDirs = new ArrayList<String>(); for (CPListElement cpe : resourcePathEntries) { rsrcDirs.add(configFilePath(project, cpe)); } config.setProjectResourceDirectories(rsrcDirs); config.save(); } finally { monitor.done(); } }
From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java
License:Open Source License
/** * Sets the configured build path and output location to the given Java project. * If the project already exists, only build paths are updated. * <p>/* ww w.j a v a2 s . c om*/ * If the classpath contains an Execution Environment entry, the EE's compiler compliance options * are used as project-specific options (unless the classpath already contained the same Execution Environment) * * @param classPathEntries the new classpath entries (list of {@link CPListElement}) * @param javaOutputLocation the output location * @param javaProject the Java project * @param newProjectCompliance compliance to set for a new project, can be <code>null</code> * @param monitor a progress monitor, or <code>null</code> * @throws CoreException if flushing failed * @throws OperationCanceledException if flushing has been cancelled */ public static void flush(List<CPListElement> classPathEntries, IPath javaOutputLocation, IJavaProject javaProject, String newProjectCompliance, IProgressMonitor monitor) throws CoreException, OperationCanceledException { if (monitor == null) { monitor = new NullProgressMonitor(); } monitor.setTaskName(NewWizardMessages.BuildPathsBlock_operationdesc_java); monitor.beginTask("", classPathEntries.size() * 4 + 4); //$NON-NLS-1$ try { IProject project = javaProject.getProject(); IPath projPath = project.getFullPath(); IPath oldOutputLocation; try { oldOutputLocation = javaProject.getOutputLocation(); } catch (CoreException e) { oldOutputLocation = projPath.append( PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)); } if (oldOutputLocation.equals(projPath) && !javaOutputLocation.equals(projPath)) { if (BuildPathsBlock.hasClassfiles(project)) { if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(false, projPath)) { BuildPathsBlock.removeOldClassfiles(project); } } } else if (!javaOutputLocation.equals(oldOutputLocation)) { IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation); if (folder.exists()) { if (folder.members().length == 0) { BuildPathsBlock.removeOldClassfiles(folder); } else { if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()) .doQuery(folder.isDerived(), oldOutputLocation)) { BuildPathsBlock.removeOldClassfiles(folder); } } } } //TODO: more robust clean up the "old" ceylon output location! project.getFolder("modules").delete(true, monitor); monitor.worked(1); IWorkspaceRoot fWorkspaceRoot = JavaPlugin.getWorkspace().getRoot(); //create and set the output path first if (!fWorkspaceRoot.exists(javaOutputLocation)) { CoreUtility.createDerivedFolder(fWorkspaceRoot.getFolder(javaOutputLocation), true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } int nEntries = classPathEntries.size(); IClasspathEntry[] classpath = new IClasspathEntry[nEntries]; int i = 0; for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) { CPListElement entry = iter.next(); classpath[i] = entry.getClasspathEntry(); i++; IResource res = entry.getResource(); //1 tick if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) { CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } //3 ticks if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT); if (folderOutput != null && folderOutput.segmentCount() > 1) { IFolder folder = fWorkspaceRoot.getFolder(folderOutput); CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } IPath path = entry.getPath(); if (projPath.equals(path)) { monitor.worked(2); continue; } if (projPath.isPrefixOf(path)) { path = path.removeFirstSegments(projPath.segmentCount()); } IFolder folder = project.getFolder(path); IPath orginalPath = entry.getOrginalPath(); if (orginalPath == null) { if (!folder.exists()) { //New source folder needs to be created if (entry.getLinkTarget() == null) { CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2)); } else { folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 2)); } } } else { if (projPath.isPrefixOf(orginalPath)) { orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount()); } IFolder orginalFolder = project.getFolder(orginalPath); if (entry.getLinkTarget() == null) { if (!folder.exists()) { //Source folder was edited, move to new location IPath parentPath = entry.getPath().removeLastSegments(1); if (projPath.isPrefixOf(parentPath)) { parentPath = parentPath.removeFirstSegments(projPath.segmentCount()); } if (parentPath.segmentCount() > 0) { IFolder parentFolder = project.getFolder(parentPath); if (!parentFolder.exists()) { CoreUtility.createFolder(parentFolder, true, true, new SubProgressMonitor(monitor, 1)); } else { monitor.worked(1); } } else { monitor.worked(1); } orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1)); } } else { if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) { orginalFolder.delete(true, new SubProgressMonitor(monitor, 1)); folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); } } } } else { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (!path.equals(entry.getOrginalPath())) { String eeID = JavaRuntime.getExecutionEnvironmentId(path); if (eeID != null) { BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance); newProjectCompliance = null; // don't set it again below } } if (newProjectCompliance != null) { Map<String, String> options = javaProject.getOptions(false); JavaModelUtil.setComplianceOptions(options, newProjectCompliance); JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options javaProject.setOptions(options); } } monitor.worked(3); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } } javaProject.setRawClasspath(classpath, javaOutputLocation, new SubProgressMonitor(monitor, 2)); } finally { monitor.done(); } }
From source file:com.siteview.mde.internal.core.builders.SourceEntryErrorReporter.java
License:Open Source License
public void initialize(ArrayList sourceEntries, ArrayList outputEntries, IClasspathEntry[] cpes, IProject project) {//from www .j a va2s . c o m fProject = project; IPath defaultOutputLocation = null; IJavaProject javaProject = JavaCore.create(fProject); try { defaultOutputLocation = javaProject.getOutputLocation(); } catch (JavaModelException e) { } List pluginLibraryNames = new ArrayList(1); IMonitorModelBase pluginModel = MonitorRegistry.findModel(fProject); if (pluginModel != null) { IMonitorLibrary[] pluginLibraries = pluginModel.getMonitorBase().getLibraries(); for (int i = 0; i < pluginLibraries.length; i++) { pluginLibraryNames.add(pluginLibraries[i].getName()); } } if (!pluginLibraryNames.contains(".")) { //$NON-NLS-1$ pluginLibraryNames.add("."); //$NON-NLS-1$) } for (int i = 0; i < cpes.length; i++) { if (cpes[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = getPath(cpes[i]); if (sourcePath == null) continue; IPath outputLocation = cpes[i].getOutputLocation(); if (outputLocation == null) outputLocation = defaultOutputLocation; IPath outputPath = getPath(outputLocation); OutputFolder outputFolder = (OutputFolder) fOutputFolderMap.get(outputPath); if (outputFolder == null) { outputFolder = new OutputFolder(outputPath); } SourceFolder sourceFolder = (SourceFolder) fSourceFolderMap.get(sourcePath); if (sourceFolder == null) { sourceFolder = new SourceFolder(sourcePath, outputFolder); } outputFolder.addSourceFolder(sourceFolder); fOutputFolderMap.put(outputPath, outputFolder); fSourceFolderMap.put(sourcePath, sourceFolder); } else if (cpes[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry entry = cpes[i]; IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); IPath outputPath = null; if (roots.length == 1) { // should only be one entry for a library if (!roots[0].isArchive()) { outputPath = getPath(entry); OutputFolder outputFolder = new OutputFolder(outputPath, true); fOutputFolderMap.put(outputPath, outputFolder); } } } } for (Iterator iterator = sourceEntries.iterator(); iterator.hasNext();) { IBuildEntry sourceEntry = (IBuildEntry) iterator.next(); String libName = sourceEntry.getName().substring(PROPERTY_SOURCE_PREFIX.length()); if (!pluginLibraryNames.contains(libName)) { prepareError(sourceEntry.getName(), null, NLS.bind(MDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName), MDEMarkerFactory.B_REMOVAL, fSrcLibSeverity, MDEMarkerFactory.CAT_OTHER); } String[] tokens = sourceEntry.getTokens(); for (int i = 0; i < tokens.length; i++) { IPath path = new Path(tokens[i]).addTrailingSeparator(); SourceFolder sourceFolder = (SourceFolder) fSourceFolderMap.get(path); if (sourceFolder == null) { sourceFolder = new SourceFolder(path, null); fSourceFolderMap.put(path, sourceFolder); } sourceFolder.setToken(tokens[i]); sourceFolder.addLib(libName); } } for (Iterator iterator = outputEntries.iterator(); iterator.hasNext();) { IBuildEntry outputEntry = (IBuildEntry) iterator.next(); String libName = outputEntry.getName().substring(PROPERTY_OUTPUT_PREFIX.length()); if (!pluginLibraryNames.contains(libName)) { prepareError(outputEntry.getName(), null, NLS.bind(MDECoreMessages.SourceEntryErrorReporter_MissingLibrary, libName), MDEMarkerFactory.B_REMOVAL, fOututLibSeverity, MDEMarkerFactory.CAT_OTHER); } String[] tokens = outputEntry.getTokens(); for (int i = 0; i < tokens.length; i++) { IPath path = new Path(tokens[i]).addTrailingSeparator(); if (path.segmentCount() == 1 && path.segment(0).equals(".")) { //$NON-NLS-1$ // translate "." to root path path = Path.ROOT; } OutputFolder outputFolder = (OutputFolder) fOutputFolderMap.get(path); if (outputFolder == null) { outputFolder = new OutputFolder(path); fOutputFolderMap.put(path, outputFolder); } outputFolder.setToken(tokens[i]); outputFolder.addLib(libName); } } }
From source file:com.siteview.mde.internal.core.ClasspathComputer.java
License:Open Source License
public static IClasspathEntry[] getClasspath(IProject project, IMonitorModelBase model, Map sourceLibraryMap, boolean clear, boolean overrideCompliance) throws CoreException { IJavaProject javaProject = JavaCore.create(project); ArrayList result = new ArrayList(); IBuild build = getBuild(project);/*from w w w . j av a2s . com*/ // add JRE and set compliance options String ee = getExecutionEnvironment(model.getBundleDescription()); result.add(createEntryUsingPreviousEntry(javaProject, ee, MDECore.JRE_CONTAINER_PATH)); setComplianceOptions(JavaCore.create(project), ee, overrideCompliance); // add pde container result.add(createEntryUsingPreviousEntry(javaProject, ee, MDECore.REQUIRED_PLUGINS_CONTAINER_PATH)); // add own libraries/source addSourceAndLibraries(project, model, build, clear, sourceLibraryMap, result); IClasspathEntry[] entries = (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); IJavaModelStatus validation = JavaConventions.validateClasspath(javaProject, entries, javaProject.getOutputLocation()); if (!validation.isOK()) { MDECore.logErrorMessage(validation.getMessage()); throw new CoreException(validation); } return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); }
From source file:com.siteview.mde.internal.core.ClasspathHelper.java
License:Open Source License
private static Map getClasspathMap(IProject project, boolean checkExcluded, boolean onlyJarsIfLinked, boolean absolutePaths) throws JavaModelException { List excluded = getFoldersToExclude(project, checkExcluded); IJavaProject jProject = JavaCore.create(project); HashMap map = new HashMap(); IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { // most of the paths we get will be project relative, so we need to make the paths relative // we will have problems adding an "absolute" path that is workspace relative IPath output = null, source = null; if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { source = entries[i].getPath(); output = entries[i].getOutputLocation(); if (output == null) output = jProject.getOutputLocation(); } else if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { source = entries[i].getPath(); output = entries[i].getPath(); if (source.segmentCount() == 1) source = new Path(DOT); }//from www. jav a 2 s.c o m if (output != null && !excluded.contains(output)) { IResource file = project.findMember(output.removeFirstSegments(1)); // make the path either relative or absolute if (file != null) { boolean isLinked = file.isLinked(IResource.CHECK_ANCESTORS); if (entries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE && !isLinked && onlyJarsIfLinked) continue; output = (isLinked || absolutePaths) ? file.getLocation().makeAbsolute() : output.makeRelative(); } else continue; ArrayList list = (ArrayList) map.get(source); if (list == null) list = new ArrayList(); list.add(output); map.put(source, list); } } return map; }
From source file:com.siteview.mde.internal.core.exports.WorkspaceExportHelper.java
License:Open Source License
private Map getPluginOutputFolders(IBuildModel buildModel, IJavaProject javaProject) throws JavaModelException { Map outputEntries = new HashMap(); IBuildEntry[] buildEntries = buildModel.getBuild().getBuildEntries(); for (int i = 0; i < buildEntries.length; i++) { String name = buildEntries[i].getName(); if (name.startsWith(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX)) { Set outputPaths = new HashSet(); String[] sourceFolders = buildEntries[i].getTokens(); for (int j = 0; j < sourceFolders.length; j++) { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (int k = 0; k < classpathEntries.length; k++) { if (classpathEntries[k].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = classpathEntries[k].getPath().removeFirstSegments(1); // Entries include project as first segment if (sourcePath.equals(new Path(sourceFolders[j]))) { IPath outputPath = classpathEntries[k].getOutputLocation(); if (outputPath == null) { outputPath = javaProject.getOutputLocation(); }/*www .ja v a2 s. co m*/ outputPaths.add(outputPath.removeFirstSegments(1)); // Entries include project as first segment } } } } if (!outputPaths.isEmpty()) { outputEntries.put(name.substring(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX.length()), outputPaths); } } } return outputEntries; }