Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2cc28cb636cacecde52fe4aff5064e0f040e0acf (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2009, 2010 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 Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.equinox.p2.internal.repository.tools.tasks;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.jarprocessor.ant.JarProcessorTask;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.tools.*;
import org.eclipse.osgi.util.NLS;

public class ProcessRepoTask extends Task {

	public static class SigningOptions {
		public String alias;
		public String keystore;
		public String storepass;
		public String keypass;
		public boolean unsign;

		public void setAlias(String alias) {
			this.alias = alias;
		}

		public void setKeystore(String keystore) {
			this.keystore = keystore;
		}

		public void setKeypass(String keypass) {
			this.keypass = keypass;
		}

		public void setStorepass(String storepass) {
			this.storepass = storepass;
		}

		public void setUnsign(String unsign) {
			this.unsign = Boolean.valueOf(unsign).booleanValue();
		}
	}

	private URI repository = null;

	private boolean pack = false;
	private boolean repack = false;
	private SigningOptions signing = null;
	private JarProcessorTask jarProcessor = null;

	public void execute() throws BuildException {
		File file = URIUtil.toFile(repository);
		if (file == null || !file.exists()) {
			throw new BuildException(NLS.bind(
					Messages.ProcessRepo_must_be_local, repository.toString()));
		}
		if (pack | repack | signing != null) {
			if (jarProcessor == null)
				jarProcessor = new JarProcessorTask();
			if (signing != null) {
				jarProcessor.setAlias(signing.alias);
				jarProcessor.setKeypass(signing.keypass);
				jarProcessor.setKeystore(signing.keystore);
				jarProcessor.setStorepass(signing.storepass);
				jarProcessor.setUnsign(signing.unsign);

				if (signing.alias != null && signing.alias.length() > 0
						&& !signing.alias.startsWith("${")) //$NON-NLS-1$
					jarProcessor.setSign(true);
			}
			jarProcessor.setPack(pack);
			jarProcessor.setNormalize(repack);
			jarProcessor.setInputFolder(new File(repository));
			jarProcessor.setProject(getProject());
			jarProcessor.execute();
		}

		recreateRepository();
	}

	private void recreateRepository() {
		RepositoryDescriptor descriptor = new RepositoryDescriptor();
		descriptor.setAppend(true);
		descriptor.setFormat(null);
		descriptor.setKind("artifact"); //$NON-NLS-1$
		descriptor.setLocation(repository);

		RecreateRepositoryApplication application = new RecreateRepositoryApplication();
		application.setArtifactRepository(descriptor);
		try {
			application.run(new NullProgressMonitor());
		} catch (ProvisionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void setRepositoryPath(String repository) {
		try {
			this.repository = URIUtil.fromString(repository);
		} catch (URISyntaxException e) {
			throw new IllegalArgumentException(NLS.bind(
					Messages.ProcessRepo_location_not_url, repository));
		}
	}

	public void setPack(boolean pack) {
		this.pack = pack;
	}

	public void setNormalize(boolean normalize) {
		this.repack = normalize;
	}

	public void addConfiguredSign(SigningOptions options) {
		this.signing = options;
	}

	public void addConfiguredPlugin(IUDescription iu) {
		if (jarProcessor == null)
			jarProcessor = new JarProcessorTask();

		String path = "plugins/" + iu.getId() + '_' + iu.getVersion(); //$NON-NLS-1$
		File repo = new File(repository);
		File plugin = new File(repo, path);
		if (!plugin.exists())
			plugin = new File(repo, path + ".jar"); //$NON-NLS-1$

		if (plugin.exists()) {
			jarProcessor.addInputFile(plugin);
		}
	}

	public void addConfiguredFeature(IUDescription iu) {
		if (jarProcessor == null)
			jarProcessor = new JarProcessorTask();

		String path = "features/" + iu.getId() + '_' + iu.getVersion(); //$NON-NLS-1$
		File repo = new File(repository);
		File feature = new File(repo, path);
		if (!feature.exists())
			feature = new File(repo, path + ".jar"); //$NON-NLS-1$

		if (feature.exists()) {
			jarProcessor.addInputFile(feature);
		}
	}
}

Back to the top