Java Code Examples for org.apache.tools.ant.taskdefs.Expand#setDest()

The following examples show how to use org.apache.tools.ant.taskdefs.Expand#setDest() . 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: AntFile.java    From antiplag with Apache License 2.0 6 votes vote down vote up
public static int unzip(File src,File dest){
	int res = -1;
	try {
		Project prj=new Project(); 
		Expand expand=new Expand(); 
		expand.setProject(prj); 
		expand.setSrc(src); 
		expand.setOverwrite(true); 
		expand.setDest(dest); 
		expand.execute();
		res = 1;
	} catch (BuildException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();			
	} 
	return res;
}
 
Example 2
Source File: JarExpander.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
private Expand createExpand(File jarFile)
{
    String outputDir = expandDir + File.separator + jarFile.getName();

    Project prj = new Project();
    FileSet fileSet = createFileSetForJarFile(jarFile, prj);
    PatternSet patternSet = createPatternSet(prj);
    Expand expand = new Expand();
    expand.setProject(prj);
    expand.setOverwrite(true);
    expand.setDest(new File(outputDir));
    expand.addFileset(fileSet);
    expand.addPatternset(patternSet);
    return expand;
}
 
Example 3
Source File: ImportTest.java    From thym with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void test() throws Exception {
	ReadableByteChannel channel = null;
	try {
		channel = Channels.newChannel(new URL("https://github.com/apache/cordova-app-hello-world/archive/master.zip").openStream()); //$NON-NLS-1$
	} catch (IOException ex) {
		Assume.assumeNoException("This test require ability to connect to Internet", ex); //$NON-NLS-1$
	}
	File outputFile = File.createTempFile("cordova-app-hello-world", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$
	FileOutputStream fos = new FileOutputStream(outputFile);
	fos.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
	channel.close();
	fos.close();
	Expand expand = new Expand();
	expand.setSrc(outputFile);
	File outputDirectory = Files.createTempDirectory("cordova-app-hello-world").toFile(); //$NON-NLS-1$
	expand.setDest(outputDirectory);
	expand.execute();
	outputFile.delete();

	Set<IProject> newProjects = null;
	SmartImportJob job = new SmartImportJob(outputDirectory, Collections.EMPTY_SET, true, true);
	try {
		Map<File, List<ProjectConfigurator>> proposals = job.getImportProposals(new NullProgressMonitor());
		Assert.assertEquals("Expected only 1 project to import", 1, proposals.size()); //$NON-NLS-1$
		boolean thymConfiguratorFound = false;
		for (ProjectConfigurator configurator : proposals.values().iterator().next()) {
			if (configurator instanceof CordovaProjectConfigurator) {
				thymConfiguratorFound = true;
			}
		}
		Assert.assertTrue("Cordova configurator not found while checking directory", thymConfiguratorFound); //$NON-NLS-1$
		
		// accept proposals
		job.setDirectoriesToImport(proposals.keySet());

		IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
		Set<IProject> beforeImport = new HashSet<>(Arrays.asList(wsRoot.getProjects()));
		job.run(new NullProgressMonitor());
		job.join();
		newProjects = new HashSet<>(Arrays.asList(wsRoot.getProjects()));
		newProjects.removeAll(beforeImport);
		Assert.assertEquals("Expected only 1 new project", 1, newProjects.size()); //$NON-NLS-1$
		IProject newProject = newProjects.iterator().next();
		boolean startsWith = newProject.getLocation().toFile().getAbsolutePath().startsWith(outputDirectory.toPath().toRealPath().toAbsolutePath().toString());
		Assert.assertTrue(startsWith);
		HybridProject hybridProject = HybridProject.getHybridProject(newProject);
		Assert.assertNotNull("Project not configured as hybrid", hybridProject); //$NON-NLS-1$
	} finally {
		if (newProjects != null) {
			for (IProject project : newProjects) {
				project.delete(true, true, new NullProgressMonitor());
			}
		}
	}
}
 
Example 4
Source File: BasicSupport.java    From ci.maven with Apache License 2.0 4 votes vote down vote up
protected void installFromFile() throws Exception {
    // Check if there is a different/newer archive or missing marker to trigger assembly install
    File installMarker = new File(installDirectory, ".installed");

    if (!refresh) {
        if (!installMarker.exists()) {
            refresh = true;
        } else if (assemblyArchive.lastModified() > installMarker.lastModified()) {
            log.debug(MessageFormat.format(messages.getString("debug.detect.assembly.archive"), ""));
            refresh = true;
        } else if(!assemblyArchive.getCanonicalPath().equals(FileUtils.fileRead(installMarker))) {
            refresh = true;
        }
    } else {
        log.debug(MessageFormat.format(messages.getString("debug.request.refresh"), ""));
    }

    String userDirectoryPath = userDirectory.getCanonicalPath();
    if (refresh && installDirectory.exists() && installDirectory.isDirectory()) {
        log.info(MessageFormat.format(messages.getString("info.uninstalling.server.home"), installDirectory));
        // Delete everything in the install directory except usr directory
        for(File f : installDirectory.listFiles()) {
            if(!(f.isDirectory() && f.getCanonicalPath().equals(userDirectoryPath))) {
                FileUtils.forceDelete(f);
            }
        }
    }

    // Install the assembly
    if (!installMarker.exists()) {
        log.info("Installing assembly...");

        FileUtils.forceMkdir(installDirectory);

        Expand unzip = (Expand) ant.createTask("unzip");

        unzip.setSrc(assemblyArchive);
        unzip.setDest(assemblyInstallDirectory.getCanonicalFile());
        unzip.execute();

        // Make scripts executable, since Java unzip ignores perms
        Chmod chmod = (Chmod) ant.createTask("chmod");
        chmod.setPerm("ugo+rx");
        chmod.setDir(installDirectory);
        chmod.setIncludes("bin/*");
        chmod.setExcludes("bin/*.bat");
        chmod.execute();

        // delete installMarker first in case it was packaged with the assembly
        installMarker.delete();
        installMarker.createNewFile();
        
        // Write the assembly archive path so we can determine whether to install a different assembly in future invocations
        FileUtils.fileWrite(installMarker, assemblyArchive.getCanonicalPath());
    } else {
        log.info(MessageFormat.format(messages.getString("info.reuse.installed.assembly"), ""));
    }
}