public static int getArchiveType(Archive anArchive) { int type = ImportUtil.UNKNOWN; try { try { if (anArchive.isEJBJarFile()) type = ImportUtil.EJBJARFILE; else if (anArchive.isWARFile()) type = ImportUtil.WARFILE; else if (anArchive.isApplicationClientFile()) type = ImportUtil.CLIENTJARFILE; else if (anArchive.isRARFile()) type = ImportUtil.RARFILE; else if (anArchive.isEARFile()) type = ImportUtil.EARFILE; } catch (Exception e) { //Ignore } } finally { if (anArchive != null) anArchive.close(); } return type; }
protected File getFileFromArchive(String name) { try { return getArchive().getFile(name); } catch (FileNotFoundException e) { } return null; }
/** * @see com.ibm.etools.archive.ArchiveTypeDiscriminator */ public Archive convert(Archive anArchive) throws OpenFailureException { Archive destination = createConvertedArchive(); //turn of notifications destination.eSetDeliver(false); destination.eSetDeliver(false); //Copy the relevant attributes destination.setURI(anArchive.getURI()); destination.setOriginalURI(anArchive.getURI()); destination.setSize(anArchive.getSize()); destination.setLastModified(anArchive.getLastModified()); destination.setLoadStrategy(anArchive.getLoadStrategy()); destination.setOptions(anArchive.getOptions()); destination.setExtraClasspath(anArchive.getExtraClasspath()); if (destination.isModuleFile()) { ImportStrategy importStrategy = createImportStrategy(anArchive, destination); ((ModuleFile) destination).setImportStrategy(importStrategy); } //turn notifications back on destination.eSetDeliver(true); destination.eSetDeliver(true); return destination; }
/** * Is it within the spec for the JAR or module file to reference the archive via the Manifest * Class-Path? */ public static boolean isValidDependency(Archive referencedJAR, Archive referencingJAR) { //No other modules should reference wars if (referencedJAR.isWARFile()) return false; if (referencedJAR == referencingJAR) return false; //Clients can reference all but the WARs, which we've already covered // above; WARs and EJB JARs //can reference all but WARs, above, or ApplicationClients return referencingJAR.isApplicationClientFile() || !referencedJAR.isApplicationClientFile(); }
public static int getArchiveType(Archive anArchive) { int type = UNKNOWN; try { if (anArchive.isEJBJarFile()) type = EJBJARFILE; else if (anArchive.isWARFile()) type = WARFILE; else if (anArchive.isApplicationClientFile()) type = CLIENTJARFILE; else if (anArchive.isRARFile()) type = RARFILE; else if (anArchive.isEARFile()) type = EARFILE; } catch (Exception e) { //Ignore } return type; }
protected void finishCopy(Archive source, Archive copy, CopyGroup group) { copy.setLoadStrategy(getCommonarchiveFactory().createEmptyLoadStrategy()); copy.setExtraClasspath(source.getExtraClasspath()); copy.setXmlEncoding(source.getXmlEncoding()); if (source.isManifestSet()) { copy.setManifest(copy(source.getManifest())); } else { try { File manifestToCopy = source.getFile(J2EEConstants.MANIFEST_URI); if (manifestToCopy != null) { File copiedManifest = (File) getCopy(manifestToCopy); copiedManifest.setLoadingContainer(manifestToCopy.getLoadingContainer()); copy.addCopy(copiedManifest); if (source.isModuleFile()) copyImportStrategyIfNecessary((ModuleFile) source, (ModuleFile) copy); List files = source.getFiles(); for (int i = 0; i < files.size(); i++) { File aFile = (File) files.get(i); copy.rebuildFileIndex();
public String getText() { return archive.getURI(); }
public void validateManifestCase(Archive anArchive) { String mfuri = J2EEConstants.MANIFEST_URI; //Indicates a manifest file with the valid name exists, //nothing left to do if (anArchive.containsFile(mfuri)) return; //Otherwise iterate the list of files //Ensure the archive is read-only first anArchive.getOptions().setIsReadOnly(true); List files = anArchive.getFiles(); String uri = null; for (int i = 0; i < files.size(); i++) { File aFile = (File) files.get(i); uri = aFile.getURI(); if (mfuri.equalsIgnoreCase(uri) && !mfuri.equals(uri)) { String[] params = {uri, anArchive.getURI()}; IResource target = earHelper.getProject().getFile(J2EEConstants.MANIFEST_URI); String msg = NLS.bind(EARValidationMessageResourceHandler.INVALID_CASE_FOR_MANIFEST_ERROR_, params); addLocalizedError(msg, target); } } }
/** * @see CommonarchiveFactory */ public Archive openNestedArchive(String uri, Archive parent) throws OpenFailureException { try { LoadStrategy childStrategy = createChildLoadStrategy(uri, parent.getLoadStrategy()); ArchiveOptions options = parent.getOptions().cloneWith(childStrategy, uri); if (options.shouldDiscriminateNestedArchives()) return openArchive(options, uri); return primOpenArchive(options, uri); } catch (IOException ex) { throw new OpenFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.open_nested_EXC_, (new Object[]{uri, parent.getURI()})), ex); // = "Could not open the nested archive "{0}" in "{1}"" } }
public void closeOpenArchives() { if (getOpenArchives().isEmpty()) return; List opened = new ArrayList(getOpenArchives().size()); Iterator it = getOpenArchives().keySet().iterator(); while (it.hasNext()) { opened.add(it.next()); } for (int i = 0; i < opened.size(); i++) { Archive anArchive = (Archive) opened.get(i); anArchive.close(); } }
public void validateManifestClasspath(Archive anArchive) throws ValidationException { ArchiveManifest manifest = null; try{ manifest = anArchive.getManifest(); }catch( ManifestException mf){ String[] args = new String[]{anArchive.getURI()}; String tmp = NLS.bind(EARValidationMessageResourceHandler.ERROR_READING_MANIFEST_ERROR_, args); continue; if (f != null && f.isArchive() && anArchive.isModuleFile()) { Archive archive = (Archive) f; ModuleFile m = (ModuleFile) anArchive;
/** * @see com.ibm.etools.commonarchive.CommonarchiveFactory */ public java.lang.String[] getManifestClassPathValues(java.lang.String uri) throws org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException { Archive anArchive = primOpenArchive(uri); String[] result = anArchive.getManifest().getClassPathTokenized(); anArchive.close(); return result; }
if (openedArchive == anArchive) continue; if (!openedArchive.isIndexed()) List files = openedArchive.getFiles(); for (int i = 0; i < files.size(); i++) { File aFile = (File) files.get(i); if (aFile.getLoadingContainer() == anArchive) { Archive outermost = openedArchive; Container c = openedArchive.getContainer(); while (c != null && c.isArchive()) { outermost = (Archive) c; List nestedArchives = anArchive.getArchiveFiles(); for (int i = 0; i < nestedArchives.size(); i++) { dependents.addAll(getOpenArchivesDependingOn((Archive) nestedArchives.get(i)));
protected Object getResourceInDependentJarInEAR(String name, Set visitedArchives, int type) { String[] classpath = archive.getManifest().getClassPathTokenized(); for (int i = 0; i < classpath.length; i++) { try { String uri = ArchiveUtil.deriveEARRelativeURI(classpath[i], archive); if (uri == null) continue; File jarFile = getEARFile().getFile(uri); if (jarFile.isArchive()) { Archive dep = (Archive) jarFile; switch (type) { case CLASS_TYPE : try { return ((ArchiveFileDynamicClassLoader) dep.getArchiveClassLoader()).loadClass(name, visitedArchives); } catch (ClassNotFoundException noDice) { continue; } case FILE_TYPE : try { return dep.getFile(name); } catch (FileNotFoundException noDice) { continue; } } } } catch (java.io.FileNotFoundException depJarNotInEAR) { } } return null; }
public Archive openNestedArchive(LooseArchive loose, Archive parent) throws OpenFailureException { String uri = loose.getUri(); try { if(loose.getBinariesPath() == null){ throw new OpenFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.open_nested_EXC_, (new Object[] {uri,parent.getURI()})), null); // = "Could not open the nested archive "{0}" in "{1}"" } LoadStrategy childStrategy = createLoadStrategy(loose.getBinariesPath()); childStrategy.setLooseArchive(loose); ArchiveOptions options = parent.getOptions().cloneWith(childStrategy, loose.getUri()); return primOpenArchive(options, uri); } catch (IOException ex) { throw new OpenFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.open_nested_EXC_, (new Object[]{uri, parent.getURI()})), ex); // = "Could not open the nested archive "{0}" in "{1}"" } }
public boolean canImport(Archive anArchive) { return anArchive.containsFile(J2EEConstants.EJBJAR_DD_URI); }
cachedWebContextRoot[0] = ((WebModule) ((EARFile) commonArchive.getContainer()).getModule(commonArchive.getURI(), null)).getContextRoot(); return cachedWebContextRoot[0];
/** * Take the primitive archive and run it through the list of discriminators to convert it to the * correct specialized type; after after conversion, tell the archive to initalize itself if * necessary. */ protected Archive openSpecificArchive(Archive anArchive, ArchiveTypeDiscriminator disc) throws OpenFailureException { if (!disc.canImport(anArchive)) { anArchive.close(); throw new OpenFailureException(disc.getUnableToOpenMessage()); } Archive specificArchive = disc.openArchive(anArchive); specificArchive.initializeAfterOpen(); return specificArchive; }