Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: af633cf60215b3baf48bbf6be0f39436db52eed1 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
 *  Copyright (c) 2005, 2017 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *      IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.jarprocessor;

import java.io.*;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.internal.p2.jarprocessor.PackStep;
import org.eclipse.equinox.internal.p2.jarprocessor.verifier.Verifier;
import org.eclipse.equinox.internal.p2.jarprocessor.verifier.VerifyStep;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;

public class JarProcessorTests extends AbstractProvisioningTest {

	public void testVerifyStep() throws Exception {
		if (!VerifyStep.canVerify())
			return;

		// run verify on
		File workingDir = getTestFolder("testVerifyStep");

		Verifier verifier = new Verifier() {
			@Override
			public void verify(File workingDirectory, String[] input) {
				options = new Options();
				options.verbose = false;
				options.pack = true; // we are verifying during the pack phase.
				options.outputDir = workingDirectory.toString();
				options.input = workingDirectory;

				JarProcessor processor = new JarProcessor();
				processor.setWorkingDirectory(workingDirectory.getAbsolutePath());

				FileFilter filter = pathname -> {
					String name = pathname.getName();
					if (pathname.isFile() && name.endsWith(".jar"))
						if ((!name.contains("source")) && name.startsWith("org.eclipse.equinox.p2"))
							return true;
					return false;
				};
				for (int i = 0; i < input.length; i++) {
					File inputFile = new File(input[i]);
					if (inputFile.exists()) {
						try {
							process(inputFile, filter, true, processor, null);
						} catch (FileNotFoundException e) {
							e.printStackTrace();
						}
					}
				}
			}
		};

		String install = Platform.getInstallLocation().getURL().getPath();
		File plugins = new File(install, "plugins");

		PrintStream oldOut = System.out;
		try (PrintStream newOut = new PrintStream(new FileOutputStream(workingDir + "/out.out"))) {
			System.setOut(newOut);

			verifier.verify(workingDir, new String[] {plugins.getAbsolutePath()});
		} finally {
			System.setOut(oldOut);
		}

	}

	public void testPackUnpackVerify() throws Exception {
		if (!PackStep.canPack() || !VerifyStep.canVerify())
			return;

		File workingDir = getTestFolder("testPackUnpackVerify");

		File input = new File(workingDir, "in");
		File packed = new File(workingDir, "packed");

		String install = Platform.getInstallLocation().getURL().getPath();
		File plugins = new File(install, "plugins");
		File[] files = plugins.listFiles((FileFilter) pathname -> {
			String name = pathname.getName();
			if (pathname.isFile() && name.endsWith(".jar") && !name.contains(".source")) {
				if (name.startsWith("org.eclipse.core.c") || name.startsWith("org.eclipse.core.r"))
					return true;
			}
			return false;
		});

		input.mkdirs();
		for (int i = 0; i < files.length; i++) {
			copy("Setup input", files[i], new File(input, files[i].getName()));
		}

		Options options = new Options();
		options.pack = true;
		options.outputDir = packed.getAbsolutePath();
		options.input = input;

		PrintStream oldOut = System.out;
		try (PrintStream newOut = new PrintStream(new FileOutputStream(workingDir + "/out.out"))) {
			System.setOut(newOut);

			JarProcessorExecutor executor = new JarProcessorExecutor();
			executor.runJarProcessor(options);

			Verifier.main(new String[] {"-dir", packed.getAbsolutePath(), packed.getAbsolutePath()});
		} finally {
			System.setOut(oldOut);
		}
	}
}

Back to the top