/******************************************************************************* * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262768 [jar exporter] Jardesc for normal Jar contains elements= new ArrayList(); jarPackage.generated_5408645661129745875(element, elements); } } public void xmlReadManifest(JarPackageData jarPackage, Element element) throws java.io.IOException { if (element.getNodeName().equals("manifest")) { //$NON-NLS-1$ jarPackage.setManifestVersion(element.getAttribute("manifestVersion")); //$NON-NLS-1$ jarPackage.setUsesManifest(getBooleanAttribute(element, "usesManifest")); //$NON-NLS-1$ jarPackage.setReuseManifest(getBooleanAttribute(element, "reuseManifest")); //$NON-NLS-1$ jarPackage.setSaveManifest(getBooleanAttribute(element,"saveManifest")); //$NON-NLS-1$ jarPackage.setGenerateManifest(getBooleanAttribute(element, "generateManifest")); //$NON-NLS-1$ jarPackage.generated_8451327371774409245(this, element); } } public void xmlReadSealingInfo(JarPackageData jarPackage, Element element) throws java.io.IOException { /* * Try to find sealing info. Could ask for single child node * but this would stop others from adding more child nodes to * the manifest node. */ NodeList sealingElementContainer= element.getChildNodes(); for (int j= 0; j < sealingElementContainer.getLength(); j++) { Node sealingNode= sealingElementContainer.item(j); if (sealingNode.getNodeType() == Node.ELEMENT_NODE && sealingNode.getNodeName().equals("sealing")) { //$NON-NLS-1$ // Sealing Element sealingElement= (Element)sealingNode; jarPackage.setSealJar(getBooleanAttribute(sealingElement, "sealJar")); //$NON-NLS-1$ jarPackage.generated_7733423015187036103(this, sealingElement); //$NON-NLS-1$ } } } public void xmlReadSelectedElements(JarPackageData jarPackage, Element element) throws java.io.IOException { if (element.getNodeName().equals("selectedElements")) { //$NON-NLS-1$ jarPackage.setExportClassFiles(getBooleanAttribute(element, "exportClassFiles")); //$NON-NLS-1$ jarPackage.setExportOutputFolders(getBooleanAttribute(element, "exportOutputFolder", false)); //$NON-NLS-1$ jarPackage.setExportJavaFiles(getBooleanAttribute(element, "exportJavaFiles")); //$NON-NLS-1$ NodeList selectedElements= element.getChildNodes(); Set elementsToExport= new HashSet(selectedElements.getLength()); for (int j= 0; j < selectedElements.getLength(); j++) { Node selectedNode= selectedElements.item(j); if (selectedNode.getNodeType() != Node.ELEMENT_NODE) continue; Element selectedElement= (Element)selectedNode; if (selectedElement.getNodeName().equals("file")) //$NON-NLS-1$ addFile(elementsToExport, selectedElement); else if (selectedElement.getNodeName().equals("folder")) //$NON-NLS-1$ addFolder(elementsToExport,selectedElement); else if (selectedElement.getNodeName().equals("project")) //$NON-NLS-1$ addProject(elementsToExport ,selectedElement); else if (selectedElement.getNodeName().equals("javaElement")) //$NON-NLS-1$ addJavaElement(elementsToExport, selectedElement); // Note: Other file types are not handled by this writer } jarPackage.setElements(elementsToExport.toArray()); } } public void xmlReadSelectedProjects(JarPackageData jarPackage, Element element) throws java.io.IOException { if (element.getNodeName().equals("selectedProjects")) { //$NON-NLS-1$ NodeList selectedElements= element.getChildNodes(); Set selectedProjects= new HashSet(selectedElements.getLength()); for (int index= 0; index < selectedElements.getLength(); index++) { Node node= selectedElements.item(index); if (node.getNodeType() != Node.ELEMENT_NODE) continue; Element selectedElement= (Element)node; if (selectedElement.getNodeName().equals("project")) //$NON-NLS-1$ addProject(selectedProjects ,selectedElement); } jarPackage.setRefactoringProjects(selectedProjects.toArray(new IProject[selectedProjects.size()])); } } protected boolean getBooleanAttribute(Element element, String name, boolean defaultValue) throws IOException { if (element.hasAttribute(name)) return getBooleanAttribute(element, name); else return defaultValue; } protected boolean getBooleanAttribute(Element element, String name) throws IOException { String value= element.getAttribute(name); if (value != null && value.equalsIgnoreCase("true")) //$NON-NLS-1$ return true; if (value != null && value.equalsIgnoreCase("false")) //$NON-NLS-1$ return false; throw new IOException(JarPackagerMessages.JarPackageReader_error_illegalValueForBooleanAttribute); } private void addFile(Set selectedElements, Element element) throws IOException { IPath path= getPath(element); if (path != null) { IFile file= JavaPlugin.getWorkspace().getRoot().getFile(path); if (file != null) selectedElements.add(file); } } private void addFolder(Set selectedElements, Element element) throws IOException { IPath path= getPath(element); if (path != null) { IFolder folder= JavaPlugin.getWorkspace().getRoot().getFolder(path); if (folder != null) selectedElements.add(folder); } } private void addProject(Set selectedElements, Element element) throws IOException { String name= element.getAttribute("name"); //$NON-NLS-1$ if (name.length() == 0) throw new IOException(JarPackagerMessages.JarPackageReader_error_tagNameNotFound); IProject project= JavaPlugin.getWorkspace().getRoot().getProject(name); if (project != null) selectedElements.add(project); } private IPath getPath(Element element) throws IOException { String pathString= element.getAttribute("path"); //$NON-NLS-1$ if (pathString.length() == 0) throw new IOException(JarPackagerMessages.JarPackageReader_error_tagPathNotFound); return Path.fromPortableString(element.getAttribute("path")); //$NON-NLS-1$ } private void addJavaElement(Set selectedElements, Element element) throws IOException { String handleId= element.getAttribute("handleIdentifier"); //$NON-NLS-1$ if (handleId.length() == 0) throw new IOException(JarPackagerMessages.JarPackageReader_error_tagHandleIdentifierNotFoundOrEmpty); IJavaElement je= JavaCore.create(handleId); if (je == null) addWarning(JarPackagerMessages.JarPackageReader_warning_javaElementDoesNotExist, null); else selectedElements.add(je); } public IPackageFragment[] getPackages(NodeList list) throws IOException { if (list.getLength() > 1) throw new IOException(Messages.format(JarPackagerMessages.JarPackageReader_error_duplicateTag, list.item(0).getNodeName())); if (list.getLength() == 0) return null; // optional entry is not present NodeList packageNodes= list.item(0).getChildNodes(); List packages= new ArrayList(packageNodes.getLength()); for (int i= 0; i < packageNodes.getLength(); i++) { Node packageNode= packageNodes.item(i); if (packageNode.getNodeType() == Node.ELEMENT_NODE && packageNode.getNodeName().equals("package")) { //$NON-NLS-1$ String handleId= ((Element)packageNode).getAttribute("handleIdentifier"); //$NON-NLS-1$ if (handleId.equals("")) //$NON-NLS-1$ throw new IOException(JarPackagerMessages.JarPackageReader_error_tagHandleIdentifierNotFoundOrEmpty); IJavaElement je= JavaCore.create(handleId); if (je != null && je.getElementType() == IJavaElement.PACKAGE_FRAGMENT) packages.add(je); else addWarning(JarPackagerMessages.JarPackageReader_warning_javaElementDoesNotExist, null); } } return packages.toArray(new IPackageFragment[packages.size()]); } public IType getMainClass(Element element) { String handleId= element.getAttribute("mainClassHandleIdentifier"); //$NON-NLS-1$ if (handleId.equals("")) //$NON-NLS-1$ return null; // Main-Class entry is optional or can be empty IJavaElement je= JavaCore.create(handleId); if (je != null && je.getElementType() == IJavaElement.TYPE) return (IType)je; addWarning(JarPackagerMessages.JarPackageReader_warning_mainClassDoesNotExist, null); return null; } /** * Returns the status of the reader. * If there were any errors, the result is a status object containing * individual status objects for each error. * If there were no errors, the result is a status object with error code OK. * * @return the status of this operation */ public IStatus getStatus() { if (fWarnings.getChildren().length == 0) return Status.OK_STATUS; else return fWarnings; } /** * Adds a new warning to the list with the passed information. * Normally the export operation continues after a warning. * @param message the message * @param error the throwable that caused the warning, or null */ protected void addWarning(String message, Throwable error) { fWarnings.add(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, message, error)); } }