Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3fd6fec9b8bba2cfbe675eaa9152d24baca84372 (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
/*******************************************************************************
 * Copyright (c) 2008, 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.net.URI;
import java.net.URISyntaxException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;

/**
 * Ant task for running the metadata mirror application.
 */
public class MirrorMetadataTask extends Task {
	URI source;
	URI destination;
	String destinationName;
	String writeMode;

	/* (non-Javadoc)
	 * @see org.apache.tools.ant.Task#execute()
	 */
	public void execute() {
		RepositoryDescriptor destinationRepo = new RepositoryDescriptor();
		destinationRepo.setName(destinationName);
		destinationRepo.setLocation(destination);
		destinationRepo.setKind(RepositoryDescriptor.KIND_METADATA);
		destinationRepo.setFormat(source);
		if (writeMode != null && writeMode.equals("clean")) //$NON-NLS-1$
			destinationRepo.setAppend(false);

		RepositoryDescriptor sourceRepo = new RepositoryDescriptor();
		sourceRepo.setLocation(source);
		sourceRepo.setKind(RepositoryDescriptor.KIND_METADATA);

		MirrorApplication app = new MirrorApplication();
		app.addDestination(destinationRepo);
		app.addSource(sourceRepo);
		try {
			IStatus result = app.run(null);
			if (result.getSeverity() != IStatus.OK)
				log(result.getMessage());
		} catch (ProvisionException e) {
			throw new BuildException(e);
		}
	}

	/*
	 * Set the source location.
	 */
	public void setSource(String value) {
		try {
			source = URIUtil.fromString(value);
		} catch (URISyntaxException e) {
			throw new BuildException(e);
		}
	}

	/*
	 * Set the destination location.
	 */
	public void setDestination(String value) {
		try {
			destination = URIUtil.fromString(value);
		} catch (URISyntaxException e) {
			throw new BuildException(e);
		}
	}

	/*
	 * Set the destination name.
	 */
	public void setDestinationName(String value) {
		destinationName = value;
	}

	/*
	 * Set the write mode for the application. (e.g. clean or append)
	 */
	public void setWriteMode(String value) {
		writeMode = value;
	}
}

Back to the top