Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2f04c6deabfb994f896ea13cfdbbf90c8f59d6a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2006, 2017 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 - Initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.jarprocessor;

import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * @author aniefer@ca.ibm.com
 *
 */
public class PackUnpackStep extends PackStep {
	private Set<String> exclusions = null;

	public PackUnpackStep(Properties options) {
		super(options);
		exclusions = Utils.getPackExclusions(options);
	}

	public PackUnpackStep(Properties options, boolean verbose) {
		super(options, verbose);
		exclusions = Utils.getPackExclusions(options);
	}

	@Override
	public String recursionEffect(String entryName) {
		if (canPack() && entryName.endsWith(".jar") && !exclusions.contains(entryName)) { //$NON-NLS-1$
			return entryName;
		}
		return null;
	}

	@Override
	public File postProcess(File input, File workingDirectory, List<Properties> containers) {
		if (canPack() && packCommand != null && input != null) {
			Properties inf = Utils.getEclipseInf(input, verbose);
			if (!shouldPack(input, containers, inf))
				return null;
			File tempFile = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
			try {
				String[] tmp = getCommand(input, tempFile, inf, containers);
				String[] cmd = new String[tmp.length + 1];
				cmd[0] = tmp[0];
				cmd[1] = "-r"; //$NON-NLS-1$
				System.arraycopy(tmp, 1, cmd, 2, tmp.length - 1);

				int result = execute(cmd, verbose);
				if (result == 0 && tempFile.exists()) {
					File finalFile = new File(workingDirectory, input.getName());
					if (finalFile.exists())
						finalFile.delete();
					tempFile.renameTo(finalFile);
					return finalFile;
				} else if (verbose) {
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
				}
			} catch (IOException e) {
				if (verbose)
					e.printStackTrace();
				return null;
			}
		}
		return null;
	}

	@Override
	public File preProcess(File input, File workingDirectory, List<Properties> containers) {
		return null;
	}

	@Override
	public String getStepName() {
		return "Repack"; //$NON-NLS-1$
	}
}

Back to the top