private void buildMetaInf(IPath outputLocation, IProgressMonitor monitor) throws CoreException, JavaModelException { IProject project = getProject(); IFolder metaInf = project.getFolder(META_INF); if (!metaInf.exists()) { error("META-INF folder not found for project: " + getProject().getName()); // $NON-NLS-1$ return; } IFolder binFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation); if (!binFolder.exists()) { binFolder.create(true, true, null); } else { binFolder.refreshLocal(IResource.DEPTH_ONE, null); } IFolder binaryMetaInf = binFolder.getFolder(META_INF); if (!binaryMetaInf.exists()) { binaryMetaInf.create(true, true, null); } else { binaryMetaInf.refreshLocal(IResource.DEPTH_ONE, null); } SubProgressMonitor sub = new SubProgressMonitor(monitor, 1); IResource[] children = metaInf.members(); sub.beginTask(Messages.Builder_CopyMetaInfContent, children.length); for (IResource iResource : children) { if (!iResource.isTeamPrivateMember() && !iResource.isDerived()) { IPath target = binaryMetaInf.getFullPath().append(iResource.getName()); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(target); if (res != null && res.exists()) { if (DEBUG) { debug(res.getFullPath().toString() + " exists, deleting"); // $NON-NLS-1$ } res.refreshLocal(IResource.DEPTH_INFINITE, null); res.delete(true, null); if (DEBUG) { debug(res.getFullPath().toString() + " deleted"); // $NON-NLS-1$ } } iResource.copy(target, true, null); if (DEBUG) { debug( "Copied " + iResource.getFullPath().toString() + " to " + target.toString()); // $NON-NLS-1$ //$NON-NLS-2$ } } sub.worked(1); } monitor.done(); }
/** Convenience method to copy resources. */ protected void copyResources(IResource[] resources, IPath container) throws DartModelException { IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); try { for (int i = 0, length = resources.length; i < length; i++) { IResource resource = resources[i]; IPath destination = container.append(resource.getName()); if (root.findMember(destination) == null) { resource.copy(destination, false, subProgressMonitor); } } setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); } catch (CoreException e) { throw new DartModelException(e); } }