de.schlichtherle.truezip.file.TFile Java Examples
The following examples show how to use
de.schlichtherle.truezip.file.TFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void checkCompatibleVersion(TFile war, ModuleDetails installingModuleDetails) { //Version check TFile propsFile = new TFile(war+VERSION_PROPERTIES); if (propsFile != null && propsFile.exists()) { log.info("INFO: Checking the war version using "+VERSION_PROPERTIES); Properties warVers = loadProperties(propsFile); VersionNumber warVersion = new VersionNumber(warVers.getProperty("version.major")+"."+warVers.getProperty("version.minor")+"."+warVers.getProperty("version.revision")); checkVersions(warVersion, installingModuleDetails); } else { log.info("INFO: Checking the war version using the manifest."); checkCompatibleVersionUsingManifest(war,installingModuleDetails); } }
Example #2
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testListModules() throws Exception { TFile theWar = getFile(".war", "module/test.war"); List<ModuleDetails> details = this.listModules(theWar); assertNotNull(details); assertEquals(details.size(), 0); theWar = getFile(".war", "module/share-4.2.a.war"); details = this.listModules(theWar); assertNotNull(details); assertEquals(details.size(), 1); ModuleDetails aModule = details.get(0); assertEquals("alfresco-mm-share", aModule.getId()); assertEquals("0.1.5.6", aModule.getModuleVersionNumber().toString()); assertEquals(ModuleInstallState.INSTALLED, aModule.getInstallState()); }
Example #3
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Checks to see if the module that is being installed is compatible with the war, (using the entry in the manifest). * This is more accurate and works for both alfresco.war and share.war, however * valid manifest entries weren't added until 3.4.11, 4.1.1 and Community 4.2 * @param war TFile * @param installingModuleDetails ModuleDetails */ public void checkCompatibleEditionUsingManifest(TFile war, ModuleDetails installingModuleDetails) { List<String> installableEditions = installingModuleDetails.getEditions(); if (installableEditions != null && installableEditions.size() > 0) { String warEdition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); if (warEdition != null && warEdition.length() > 0) { warEdition = warEdition.toLowerCase(); for (String edition : installableEditions) { if (warEdition.endsWith(edition.toLowerCase())) { return; //successful match. } } throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() +") can only be installed in one of the following editions"+installableEditions); } else { log.info("WARNING: No edition information detected in war, edition validation is disabled, continuing anyway. Is this war prior to 3.4.11, 4.1.1 and Community 4.2 ?"); } } }
Example #4
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void checkModuleDependencies(TFile war, ModuleDetails installingModuleDetails) { // Check that the target war has the necessary dependencies for this install List<ModuleDependency> installingModuleDependencies = installingModuleDetails.getDependencies(); List<ModuleDependency> missingDependencies = new ArrayList<ModuleDependency>(0); for (ModuleDependency dependency : installingModuleDependencies) { String dependencyId = dependency.getDependencyId(); ModuleDetails dependencyModuleDetails = getModuleDetails(war, dependencyId); // Check the dependency. The API specifies that a null returns false, so no null check is required if (!dependency.isValidDependency(dependencyModuleDetails)) { missingDependencies.add(dependency); continue; } } if (missingDependencies.size() > 0) { throw new ModuleManagementToolException("The following modules must first be installed: " + missingDependencies); } }
Example #5
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ModuleDetails getModuleDetailsOrAlias(TFile war, ModuleDetails installingModuleDetails) { ModuleDetails installedModuleDetails = getModuleDetails(war, installingModuleDetails.getId()); if (installedModuleDetails == null) { // It might be there as one of the aliases List<String> installingAliases = installingModuleDetails.getAliases(); for (String installingAlias : installingAliases) { ModuleDetails installedAliasModuleDetails = getModuleDetails(war, installingAlias); if (installedAliasModuleDetails == null) { // There is nothing by that alias continue; } // We found an alias and will treat it as the same module installedModuleDetails = installedAliasModuleDetails; //outputMessage("Module '" + installingAlias + "' is installed and is an alias of '" + installingModuleDetails + "'", false); break; } } return installedModuleDetails; }
Example #6
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testfindManifest() throws Exception { //Now check the compatible versions using the manifest TFile theWar = getFile(".war", "module/share-3.4.11.war"); Manifest manifest = this.findManifest(theWar); assertNotNull(manifest); assertEquals("Alfresco Share Enterprise", manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_TITLE)); assertEquals("3.4.11", manifest.getMainAttributes().getValue(MANIFEST_SPECIFICATION_VERSION)); theWar = getFile(".war", "module/alfresco-4.2.a.war"); manifest = this.findManifest(theWar); assertNotNull(manifest); assertEquals("Alfresco Repository Community", manifest.getMainAttributes().getValue(MANIFEST_IMPLEMENTATION_TITLE)); assertEquals("4.2.a", manifest.getMainAttributes().getValue(MANIFEST_SPECIFICATION_VERSION)); }
Example #7
Source File: ModuleManagementToolTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private void checkContentsOfFile(String location, String expectedContents) throws IOException { File file = new TFile(location); assertTrue(file.exists()); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new TFileInputStream(file))); String line = reader.readLine(); assertNotNull(line); assertEquals(expectedContents, line.trim()); } finally { if (reader != null) { try { reader.close(); } catch (Throwable e ) {} } } }
Example #8
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private TFile getFile(String extension, String location) { File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension); InputStream is = this.getClass().getClassLoader().getResourceAsStream(location); assertNotNull(is); OutputStream os; try { os = new FileOutputStream(file); FileCopyUtils.copy(is, os); } catch (IOException error) { error.printStackTrace(); } return new TFile(file); }
Example #9
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Tests to see if the war is a share war. */ @Test public void testIsShareWar() { TFile theWar = getFile(".war", "module/test.war"); //Version 4.1.0 assertFalse(this.isShareWar(theWar)); theWar = getFile(".war", "module/empty.war"); assertFalse(this.isShareWar(theWar)); theWar = getFile(".war", "module/alfresco-4.2.a.war"); assertFalse(this.isShareWar(theWar)); theWar = getFile(".war", "module/share-4.2.a.war"); assertTrue(this.isShareWar(theWar)); }
Example #10
Source File: ModuleManagementToolTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
private String extractToDir(String extension, String location) { File tmpDir = TempFileProvider.getTempDir(); try { TFile zipFile = new TFile(this.getClass().getClassLoader().getResource(location).getPath()); TFile outDir = new TFile(tmpDir.getAbsolutePath()+"/moduleManagementToolTestDir"+System.currentTimeMillis()); outDir.mkdir(); zipFile.cp_rp(outDir); TVFS.umount(zipFile); return outDir.getPath(); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #11
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testCheckCompatibleEdition() { Properties props = dummyModuleProperties(); ModuleDetails installingModuleDetails = new ModuleDetailsImpl(props); TFile theWar = getFile(".war", "module/test.war"); //Community Edition //Test for no edition specified this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception //Test for invalid edition props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT"); installingModuleDetails = new ModuleDetailsImpl(props); try { this.checkCompatibleEdition(theWar, installingModuleDetails); fail(); //should never get here } catch (ModuleManagementToolException exception) { assertTrue(exception.getMessage().endsWith("can only be installed in one of the following editions[CommuniT]")); } props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity")); //should ignore case installingModuleDetails = new ModuleDetailsImpl(props); this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,community,bob")); //should ignore case installingModuleDetails = new ModuleDetailsImpl(props); this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,Community")); //should ignore case installingModuleDetails = new ModuleDetailsImpl(props); this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception }
Example #12
Source File: ShortcutDialog.java From setupmaker with Apache License 2.0 | 5 votes |
private void search(TFile entry, Stack<File> files) throws IOException { if (entry.isDirectory()) { files.push(entry); for (TFile member : entry.listFiles()) search(member, files); } else if (entry.isFile()) { files.push(entry); } // else is special file or non-existent }
Example #13
Source File: TrueZipCastFactory.java From setupmaker with Apache License 2.0 | 5 votes |
/** * convert rar archive to zip * @param rar_file * @return * @throws IOException */ /*public static File rarToZip(File rar_file) throws IOException { TFile zip_file = new TFile(rar_file.getAbsolutePath().replace(".rar", ".zip")); new TFile(rar_file).cp_rp(zip_file); archives.add(zip_file); return zip_file; }*/ public static void clearArchives() { for(TFile f:archives) { f.deleteOnExit(); } }
Example #14
Source File: ModuleManagementToolTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void checkForFileExistance(String warLocation, List<String> files) { for (String file : files) { File file0 = new TFile(warLocation + file); assertTrue("The file/dir " + file + " does not exist in the WAR.", file0.exists()); } }
Example #15
Source File: ModuleManagementToolTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private void checkForFileNonExistance(String warLocation, List<String> files) { for (String file : files) { File file0 = new TFile(warLocation + file); assertFalse("The file/dir " + file + " does exist in the WAR.", file0.exists()); } }
Example #16
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks if the module is compatible using the entry in the manifest. This is more accurate and works for both alfresco.war and share.war, however * valid manifest entries weren't added until 3.4.11, 4.1.1 and Community 4.2 * @param war TFile * @param installingModuleDetails ModuleDetails */ protected void checkCompatibleVersionUsingManifest(TFile war, ModuleDetails installingModuleDetails) { String version = findManifestArtibute(war, MANIFEST_SPECIFICATION_VERSION); if (version != null && version.length() > 0) { if (version.matches(REGEX_NUMBER_OR_DOT)) { VersionNumber warVersion = new VersionNumber(version); checkVersions(warVersion, installingModuleDetails); } else { //A non-numeric version number. Currently our VersionNumber class doesn't support Strings in the version String edition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); if (edition.endsWith(MANIFEST_COMMUNITY)) { //If it's a community version, so don't worry about it log.info("WARNING: Community edition war detected, the version number is non-numeric so we will not validate it."); } else { throw new ModuleManagementToolException("Invalid version number specified: "+ version); } } } else { log.info("WARNING: No version information detected in war, therefore version validation is disabled, continuing anyway. Is this war prior to 3.4.11, 4.1.1 and Community 4.2 ?"); } }
Example #17
Source File: WarHelperImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testNoVersionProperties() { TFile theWar = getFile(".war", "module/empty.war"); ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module"); installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1")); this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception }
Example #18
Source File: FileUtils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
static TFile getLocalZipArchive(URL contextURL, String localArchivePath) throws IOException { // apply the contextURL URL url = FileUtils.getFileURL(contextURL, localArchivePath); String absolutePath = FileUtils.getUrlFile(url); registerTrueZipVSFEntry(newTFile(localArchivePath)); return new TFile(absolutePath); }
Example #19
Source File: FileUtils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
/** * This method should be used instead of the {@link TFile} constructor * to avoid CLO-5569. * * @param path * @return new {@link TFile} */ private static TFile newTFile(String path) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { // CLO-5569: use the same classloader that loaded the TrueZip kernel ClassLoader cl = TFile.class.getClassLoader(); Thread.currentThread().setContextClassLoader(cl); return new TFile(path); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } }
Example #20
Source File: TrueZipVFSEntries.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
public void addVFSEntry(TFile entry) { TFile rootArchive = null; for (TFile enclosingArchive = entry.getEnclArchive(); enclosingArchive != null; enclosingArchive = enclosingArchive.getEnclArchive()) { rootArchive = enclosingArchive; } if (rootArchive != null) { rootArchives.add(rootArchive); } else { throw new IllegalArgumentException(entry + " is not in an archive"); } }
Example #21
Source File: TrueZipVFSEntries.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
public void freeAll() { for (TFile entry : rootArchives) { try { TFile.umount(entry, false, false, false, false); } catch (FsSyncException e) { logger.warn("Cannot unmount zip archive " + entry.getAbsolutePath()); } } }
Example #22
Source File: ModuleDetailsHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Saves the module details to the war in the correct location based on the module id * * @param warLocation the war location * @param moduleDetails the module id */ public static void saveModuleDetails(String warLocation, ModuleDetails moduleDetails) { // Ensure that it is a valid set of properties String moduleId = moduleDetails.getId(); try { String modulePropertiesFileLocation = getModulePropertiesFileLocation(warLocation, moduleId); TFile file = new TFile(modulePropertiesFileLocation); if (file.exists() == false) { file.createNewFile(); } // Get all the module properties Properties moduleProperties = moduleDetails.getProperties(); OutputStream os = new TFileOutputStream(file); try { moduleProperties.store(os, null); } finally { os.close(); } } catch (IOException exception) { throw new ModuleManagementToolException( "Unable to save module details into WAR file: \n" + " Module: " + moduleDetails.getId() + "\n" + " Properties: " + moduleDetails.getProperties(), exception); } }
Example #23
Source File: ModuleDetailsHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * @param warLocation the location of the WAR file * @param moduleId the module ID within the WAR * @return Returns a file handle to the module properties file within the given WAR. * The file may or may not exist. */ public static TFile getModuleDetailsFileFromWarAndId(String warLocation, String moduleId) { String location = ModuleDetailsHelper.getModulePropertiesFileLocation(warLocation, moduleId); TFile file = new TFile(location); return file; }
Example #24
Source File: ArchiveExtractor.java From phantomjs-maven-plugin with MIT License | 5 votes |
public void extract(File archive, String member, File extractTo) throws ExtractionException { try { TFile tfile = new TFile(archive, member); LOGGER.info(EXTRACTING, tfile.getAbsolutePath(), extractTo.getAbsolutePath()); if (extractTo.getParentFile().exists() || extractTo.getParentFile().mkdirs()) { tfile.cp(extractTo); } } catch (IOException e) { throw new ExtractionException(String.format(UNABLE_TO_EXTRACT, archive), e); } finally { unmountArchive(); } }
Example #25
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the module details for the specified module from the war. * @param war a valid war file or exploded directory from a war * @param moduleId String * @return ModuleDetails */ protected ModuleDetails getModuleDetails(TFile war, String moduleId) { ModuleDetails moduleDets = null; TFile theFile = getModuleDetailsFile(war, moduleId); if (theFile != null && theFile.exists()) { moduleDets = new ModuleDetailsImpl(loadProperties(theFile)); } return moduleDets; }
Example #26
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean isShareWar(TFile warFile) { if (!warFile.exists()) { throw new ModuleManagementToolException("The war file '" + warFile + "' does not exist."); } String title = findManifestArtibute(warFile, MANIFEST_SPECIFICATION_TITLE); if (MANIFEST_SHARE.equals(title)) return true; //It is share return false; //default }
Example #27
Source File: WarHelperImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void checkCompatibleEdition(TFile war, ModuleDetails installingModuleDetails) { List<String> installableEditions = installingModuleDetails.getEditions(); if (installableEditions != null && installableEditions.size() > 0) { TFile propsFile = new TFile(war+VERSION_PROPERTIES); if (propsFile != null && propsFile.exists()) { Properties warVers = loadProperties(propsFile); String warEdition = warVers.getProperty("version.edition"); for (String edition : installableEditions) { if (warEdition.equalsIgnoreCase(edition)) { return; //successful match. } } throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() +") can only be installed in one of the following editions"+installableEditions); } else { checkCompatibleEditionUsingManifest(war,installingModuleDetails); } } }
Example #28
Source File: FileUtils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
private static void registerTrueZipVSFEntry(TFile entry) { TransformationGraph graph = ContextProvider.getGraph(); if (graph != null) { graph.getVfsEntries().addVFSEntry(entry); } }
Example #29
Source File: GetLatestVersionTest.java From chipster with MIT License | 4 votes |
@Test public void testGetLatestVersionDirFromTar() { File f = Files.getLatestVersion(new TFile("/Users/hupponen/git/chipster/chipster-tools-3.6.3.tar.gz"), "chipster-tools", null); System.out.println(f.getName()); }
Example #30
Source File: ModuleManagementToolTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void testListAndInstall() throws Exception { String warLocation = getFileLocation(".war", "module/test.war"); String ampLocation = getFileLocation(".amp", "module/test_v1.amp"); String ampV2Location = getFileLocation(".amp", "module/test_v2.amp"); TFile war = new TFile(warLocation); List<ModuleDetails> details = this.manager.warHelper.listModules(war); assertNotNull(details); assertEquals(details.size(), 0); this.manager.installModule(ampLocation, warLocation); details = this.manager.warHelper.listModules(war); assertNotNull(details); assertEquals(details.size(), 1); ModuleDetails aModule = details.get(0); assertEquals("test", aModule.getId()); assertEquals("1.0", aModule.getModuleVersionNumber().toString()); this.manager.installModule(ampV2Location, warLocation); details = this.manager.warHelper.listModules(war); assertNotNull(details); assertEquals(details.size(), 1); aModule = details.get(0); assertEquals("test", aModule.getId()); assertEquals("2.0", aModule.getModuleVersionNumber().toString()); String testAmpDepV2Location = getFileLocation(".amp", "module/dependent_on_test_v2.amp"); String testAmp7 = getFileLocation(".amp", "module/test_v7.amp"); this.manager.installModule(testAmpDepV2Location, warLocation, false, true, false); this.manager.installModule(testAmp7, warLocation, false, true, false); details = this.manager.warHelper.listModules(war); assertNotNull(details); assertEquals(details.size(), 3); //Sort them by installation date Collections.sort(details, new Comparator<ModuleDetails>() { @Override public int compare(ModuleDetails a, ModuleDetails b) { return a.getInstallDate().compareTo(b.getInstallDate()); } }); ModuleDetails installedModule = details.get(0); assertEquals("test", installedModule.getId()); assertEquals("2.0", installedModule.getModuleVersionNumber().toString()); installedModule = details.get(1); assertEquals("org.alfresco.module.test.dependent", installedModule.getId()); assertEquals("2.0", installedModule.getModuleVersionNumber().toString()); installedModule = details.get(2); assertEquals("forcedtest", installedModule.getId()); assertEquals("1.0", installedModule.getModuleVersionNumber().toString()); }