|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.internal.p2.artifact.repository.ant; |
| 12 |
|
| 13 |
import java.net.MalformedURLException; |
| 14 |
import java.net.URL; |
| 15 |
import java.util.HashMap; |
| 16 |
import java.util.Map; |
| 17 |
import org.apache.tools.ant.BuildException; |
| 18 |
import org.apache.tools.ant.Task; |
| 19 |
import org.eclipse.equinox.app.IApplicationContext; |
| 20 |
import org.eclipse.equinox.internal.p2.artifact.mirror.MirrorApplication; |
| 21 |
import org.osgi.framework.Bundle; |
| 22 |
|
| 23 |
/** |
| 24 |
* Ant task for running the artifact repository mirroring application. |
| 25 |
*/ |
| 26 |
public class MirrorApplicationTask extends Task { |
| 27 |
|
| 28 |
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ |
| 29 |
private static final String ARG_COMPARATOR = "-comparator"; //$NON-NLS-1$ |
| 30 |
private static final String ARG_COMPARE = "-compare"; //$NON-NLS-1$ |
| 31 |
private static final String ARG_COMPARE_AGAINST = "-compareAgainst"; //$NON-NLS-1$ |
| 32 |
private static final String ARG_DESTINATION = "-destination"; //$NON-NLS-1$ |
| 33 |
private static final String ARG_IGNORE_ERRORS = "-ignoreErrors"; //$NON-NLS-1$ |
| 34 |
private static final String ARG_RAW = "-raw"; //$NON-NLS-1$ |
| 35 |
private static final String ARG_SOURCE = "-source"; //$NON-NLS-1$ |
| 36 |
private static final String ARG_VERBOSE = "-verbose"; //$NON-NLS-1$ |
| 37 |
private static final String ARG_WRITE_MODE = "-writeMode"; //$NON-NLS-1$ |
| 38 |
|
| 39 |
URL source; |
| 40 |
URL destination; |
| 41 |
URL baseline; // location of known good repository for compare against (optional) |
| 42 |
String comparatorID; // specifies a comparator (optional) |
| 43 |
String writeMode; |
| 44 |
boolean compare = false; |
| 45 |
boolean ignoreErrors = false; |
| 46 |
boolean raw = false; // use raw artifact descriptors? |
| 47 |
boolean verbose = false; |
| 48 |
|
| 49 |
/* |
| 50 |
* Runs the mirror application with the given arguments. |
| 51 |
*/ |
| 52 |
private void runMirrorApplication(final String[] args) throws Exception { |
| 53 |
new MirrorApplication().start(new IApplicationContext() { |
| 54 |
|
| 55 |
public void applicationRunning() { |
| 56 |
// nothing to do |
| 57 |
} |
| 58 |
|
| 59 |
public Map getArguments() { |
| 60 |
Map arguments = new HashMap(); |
| 61 |
arguments.put(IApplicationContext.APPLICATION_ARGS, args); |
| 62 |
return arguments; |
| 63 |
} |
| 64 |
|
| 65 |
public String getBrandingApplication() { |
| 66 |
return null; |
| 67 |
} |
| 68 |
|
| 69 |
public Bundle getBrandingBundle() { |
| 70 |
return null; |
| 71 |
} |
| 72 |
|
| 73 |
public String getBrandingDescription() { |
| 74 |
return null; |
| 75 |
} |
| 76 |
|
| 77 |
public String getBrandingId() { |
| 78 |
return null; |
| 79 |
} |
| 80 |
|
| 81 |
public String getBrandingName() { |
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
public String getBrandingProperty(String key) { |
| 86 |
return null; |
| 87 |
} |
| 88 |
}); |
| 89 |
} |
| 90 |
|
| 91 |
/* (non-Javadoc) |
| 92 |
* @see org.apache.tools.ant.Task#execute() |
| 93 |
*/ |
| 94 |
public void execute() { |
| 95 |
// Compare against if baseline specified |
| 96 |
boolean compareAgainst = baseline != null; |
| 97 |
boolean comparator = comparatorID != null; |
| 98 |
|
| 99 |
// create arguments |
| 100 |
String[] args = new String[] { // |
| 101 |
ARG_SOURCE, source.toExternalForm(), // |
| 102 |
ARG_DESTINATION, destination.toExternalForm(), // |
| 103 |
ARG_WRITE_MODE, writeMode == null ? EMPTY_STRING : writeMode, // |
| 104 |
compare ? ARG_COMPARE : EMPTY_STRING, // |
| 105 |
ignoreErrors ? ARG_IGNORE_ERRORS : EMPTY_STRING, // |
| 106 |
raw ? ARG_RAW : EMPTY_STRING, // |
| 107 |
verbose ? ARG_VERBOSE : EMPTY_STRING, // |
| 108 |
compareAgainst ? ARG_COMPARE_AGAINST : EMPTY_STRING, // |
| 109 |
compareAgainst ? baseline.toExternalForm() : EMPTY_STRING, // |
| 110 |
comparator ? ARG_COMPARATOR : EMPTY_STRING, // |
| 111 |
comparator ? comparatorID : EMPTY_STRING}; |
| 112 |
|
| 113 |
try { |
| 114 |
runMirrorApplication(args); |
| 115 |
} catch (Exception e) { |
| 116 |
throw new BuildException("Exception while running mirror application.", e); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
/* |
| 121 |
* Set the location of the source. |
| 122 |
*/ |
| 123 |
public void setSource(String value) throws MalformedURLException { |
| 124 |
source = new URL(value); |
| 125 |
} |
| 126 |
|
| 127 |
/* |
| 128 |
* Set the location of the destination. |
| 129 |
*/ |
| 130 |
public void setDestination(String value) throws MalformedURLException { |
| 131 |
destination = new URL(value); |
| 132 |
} |
| 133 |
|
| 134 |
/* |
| 135 |
* Set the location of the baseline repository. (used in comparison) |
| 136 |
*/ |
| 137 |
public void setBaseline(String value) throws MalformedURLException { |
| 138 |
baseline = new URL(value); |
| 139 |
compare = true; |
| 140 |
} |
| 141 |
|
| 142 |
/* |
| 143 |
* Set the identifier of the comparator to use. |
| 144 |
*/ |
| 145 |
public void setComparatorID(String value) { |
| 146 |
comparatorID = value; |
| 147 |
compare = true; |
| 148 |
} |
| 149 |
|
| 150 |
/* |
| 151 |
* Set the write mode. (e.g. clean or append) |
| 152 |
*/ |
| 153 |
public void setWriteMode(String value) { |
| 154 |
writeMode = value; |
| 155 |
} |
| 156 |
|
| 157 |
/* |
| 158 |
* Set whether or not the application should be calling a comparator when mirroring. |
| 159 |
*/ |
| 160 |
public void setCompare(boolean value) { |
| 161 |
compare = value; |
| 162 |
} |
| 163 |
|
| 164 |
/* |
| 165 |
* Set whether or not we should ignore errors when running the mirror application. |
| 166 |
*/ |
| 167 |
public void setIgnoreErrors(boolean value) { |
| 168 |
ignoreErrors = value; |
| 169 |
} |
| 170 |
|
| 171 |
/* |
| 172 |
* Set whether or not the the artifacts are raw. |
| 173 |
*/ |
| 174 |
public void setRaw(boolean value) { |
| 175 |
raw = value; |
| 176 |
} |
| 177 |
|
| 178 |
/* |
| 179 |
* Set whether or not the mirror application should be run in verbose mode. |
| 180 |
*/ |
| 181 |
public void setVerbose(boolean value) { |
| 182 |
verbose = value; |
| 183 |
} |
| 184 |
} |