protected Archive getResolvedArchive(String mfValue, EARFile ear) { String aUri = ArchiveUtil.deriveEARRelativeURI(mfValue, this); if (aUri == null) return null; try { return (Archive) ear.getFile(aUri); } catch (FileNotFoundException ex) { return null; } catch (ClassCastException ex2) { return null; } }
public static String[] getTokens(String aString) { return getTokens(aString, null); }
protected byte[] getClassBytesFor(String className) { if (className == null) return null; // Change the class name to a jar entry name String jarEntryName = ArchiveUtil.classNameToUri(className); return getData(getFile(jarEntryName)); }
/** * Concatenates the two strings and ensures the correct separator is used in the path */ public static String getOSUri(String directoryname, String filename) { String osDirName = getOSUri(directoryname); String osFileName = getOSUri(filename); return concatUri(osDirName, osFileName, File.separatorChar); }
public static File createTempFile(String baseName) throws IOException { return createTempFile(baseName, getTempDirectory()); }
public LoadStrategy createTempZipFileStrategyIfPossible(String uri, LoadStrategy parent) { if (!ArchiveUtil.shouldUseTempDirectoryForRead()) return null; try { java.io.File tempFile = ArchiveUtil.createTempFile(uri); DeleteOnExitUtility.markForDeletion(tempFile); InputStream in = parent.getInputStream(uri); OutputStream out = new FileOutputStream(tempFile); ArchiveUtil.copy(in, out); return new TempZipFileLoadStrategyImpl(tempFile); } catch (IOException ex) { ArchiveUtil.inform(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.make_temp_file_WARN_, (new Object[]{uri})) + ex.getLocalizedMessage()); // = "Warning: Unable to create temp file for {0}. This will impact performance." } return null; }
if (className == null) continue; String classUri = org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil.classNameToUri(className); String javaUri = org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil.classNameToJavaUri(className); try { result.add(getFile(classUri));
/** * Parse the manifest class path and the extra class path, and instantiate a URL classloader, * with a parent of the archiveClassLoader */ protected ClassLoader getClassPathClassLoader(ClassLoader parentCl) { List classPathComponents = new ArrayList(); if (getManifest() != null) classPathComponents.addAll(Arrays.asList(getManifest().getClassPathTokenized())); String extraCp = getExtraClasspath(); if (extraCp != null) classPathComponents.addAll(Arrays.asList(ArchiveUtil.getTokens(extraCp, ";")));//$NON-NLS-1$ java.net.URL[] urlArray = ArchiveUtil.toLocalURLs(classPathComponents, getRootForRelativeDependentJars()); return new java.net.URLClassLoader(urlArray, parentCl); }
/** * Read all the data from the input stream up until the first end of file character, add this * data to a byte array, and close the input stream; returns the byte array */ public static byte[] inputStreamToBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); }
String uri = ArchiveUtil.deriveEARRelativeURI(cp[i], anArchive); if (uri == null) { invalidClassPathEntryWarning(cp[i], anArchive); Archive archive = (Archive) f; ModuleFile m = (ModuleFile) anArchive; if (!ArchiveUtil.isValidDependency(archive, m)) invalidDepedencyWarning(cp[i], archive, m);
protected boolean isClassWithoutSource(File aFile) { String javaUri = ArchiveUtil.classUriToJavaUri(aFile.getURI()); if (javaUri == null) return false; return !archive.containsFile(javaUri); } }
protected void addFiles(java.io.File aDirectory, List aList) { String[] fileNames = aDirectory.list(); if (fileNames == null) return; for (int i = 0; i < fileNames.length; i++) { String fileName = ArchiveUtil.concatUri(aDirectory.getPath(), fileNames[i], SEPARATOR_CHAR); if (fileNames[i] == null || (IS_AIX && ".backup".equals(fileNames[i]))) //$NON-NLS-1$ continue; java.io.File aFile = new java.io.File(fileName); if (!aFile.exists()) continue; //This could occur on some windows machines, eg C:\pagefile.sys //throw new RuntimeException("Error scanning directory structure"); if (aFile.isDirectory() && !isArchive(getURIFrom(aFile))) { addDirectory(aFile, aList); } else { addFile(aFile, aList); } } }
public static File createTempDirectory(String baseName, File parentDirectory) throws IOException { File tempFile = createTempFile(baseName, parentDirectory); tempFile.delete(); tempFile.mkdir(); return tempFile; }
/** * @see com.ibm.etools.commonarchive.Archive */ public void extractNoReopen(int expansionFlags) throws SaveFailureException { String aUri = getURI(); java.io.File aDir = new java.io.File(aUri); boolean inUse = getLoadStrategy().isUsing(aDir); try { java.io.File destinationDir = inUse ? ArchiveUtil.createTempDirectory(aUri, aDir.getCanonicalFile().getParentFile()) : aDir; SaveStrategy aSaveStrategy = createSaveStrategyForDirectory(destinationDir, expansionFlags); save(aSaveStrategy); aSaveStrategy.close(); close(); if (inUse) { cleanupAfterTempSave(aUri, aDir, destinationDir); } } catch (java.io.IOException ex) { throw new SaveFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.error_saving_EXC_, (new Object[]{uri})), ex); // = "Error saving " } }
/** * @see org.eclipse.wst.validation.internal.operations.IWorkbenchContext#getPortableName(IResource) */ public String getPortableName(IResource resource) { // Return the URI of the object. if (!(resource instanceof IFile)) { return super.getPortableName(resource); } IFile file = (IFile) resource; if ((resource.getFileExtension() != null) && (resource.getFileExtension().equals("java"))) { //$NON-NLS-1$ JavaClass clazz = JemProjectUtilities.getJavaClass(file); if (clazz == null) { return super.getPortableName(resource); } return ArchiveUtil.classNameToJavaUri(clazz.getQualifiedName()); } else if ((resource.getFileExtension() != null) && (resource.getFileExtension().equals("class"))) { //$NON-NLS-1$ JavaClass clazz = JemProjectUtilities.getJavaClass(file); if (clazz == null) { return super.getPortableName(resource); } return ArchiveUtil.classNameToUri(clazz.getQualifiedName()); } else if (resource.getName().equals("ejb-jar.xml")) //$NON-NLS-1$ return J2EEConstants.EJBJAR_DD_URI; return null; }
protected IFile saveFile(File aFile, IProject p) throws IOException { IFile iFile = p.getFile(aFile.getURI()); WorkbenchByteArrayOutputStream out = new WorkbenchByteArrayOutputStream(iFile); ArchiveUtil.copy(aFile.getInputStream(), out); return iFile; }
String convertedClassURI = classURI; if (classURI.endsWith(".class")) //$NON-NLS-1$ convertedClassURI = ArchiveUtil.classUriToJavaUri(aClassFile.getURI()); else return null;
protected File addCopyFileAddingPrefix(File aFile, String uriPrefix) throws DuplicateObjectException { String swizzledUri = aFile.getURI(); if (!swizzledUri.startsWith(uriPrefix)) { swizzledUri = ArchiveUtil.concatUri(uriPrefix, swizzledUri, '/'); } checkAddValid(swizzledUri); File copy = copy(aFile); copy.setURI(swizzledUri); getFiles().add(copy); return copy; }
try { try { java.io.File destinationFile = fileExisted ? ArchiveUtil.createTempFile(aUri, aFile.getCanonicalFile().getParentFile()) : aFile; aSaveStrategy = createSaveStrategyForJar(destinationFile); save(aSaveStrategy);
/** * Leverage the java.io.File apis to resolve things like "./xxx" and "../xxx" into uris of * entries in the ear file * * @param classpathEntry - * a classpath entry from the manifest of * @anArchive * @param anArchive - * the archive to which the dependent jar is relative * * @return a cananonicalized relative uri of an entry in an ear file representing the dependent * jar */ public static String deriveEARRelativeURI(String classpathEntry, Archive anArchive) { return deriveEARRelativeURI(classpathEntry, anArchive.getURI()); }