|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 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 |
|
| 12 |
package org.eclipse.equinox.internal.p2.artifact.repository.ant; |
| 13 |
|
| 14 |
import java.net.MalformedURLException; |
| 15 |
import java.net.URL; |
| 16 |
import java.util.HashMap; |
| 17 |
import java.util.Map; |
| 18 |
import org.apache.tools.ant.BuildException; |
| 19 |
import org.apache.tools.ant.Task; |
| 20 |
import org.eclipse.equinox.app.IApplicationContext; |
| 21 |
import org.eclipse.equinox.internal.p2.artifact.mirror.MirrorApplication; |
| 22 |
import org.osgi.framework.Bundle; |
| 23 |
|
| 24 |
public class MirrorApplicationTask extends Task { |
| 25 |
URL source; |
| 26 |
URL destination; |
| 27 |
URL baseline; //location of known good repository for compare against. Not required |
| 28 |
String comparatorID; //specifies a comparator. Not required |
| 29 |
String message = ""; |
| 30 |
boolean clean = false; //don't append? |
| 31 |
boolean compare = false; |
| 32 |
boolean ignoreErrors = false; |
| 33 |
boolean raw = false; //use raw artifact descriptors? |
| 34 |
boolean verbose = false; |
| 35 |
|
| 36 |
/** |
| 37 |
* runs the mirror application with arguments args |
| 38 |
*/ |
| 39 |
private void runMirrorApplication(String msg, final String[] args) throws Exception { |
| 40 |
MirrorApplication application = new MirrorApplication(); |
| 41 |
application.start(new IApplicationContext() { |
| 42 |
|
| 43 |
public void applicationRunning() { |
| 44 |
} |
| 45 |
|
| 46 |
public Map getArguments() { |
| 47 |
Map arguments = new HashMap(); |
| 48 |
|
| 49 |
arguments.put(IApplicationContext.APPLICATION_ARGS, args); |
| 50 |
|
| 51 |
return arguments; |
| 52 |
} |
| 53 |
|
| 54 |
public String getBrandingApplication() { |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
public Bundle getBrandingBundle() { |
| 59 |
return null; |
| 60 |
} |
| 61 |
|
| 62 |
public String getBrandingDescription() { |
| 63 |
return null; |
| 64 |
} |
| 65 |
|
| 66 |
public String getBrandingId() { |
| 67 |
return null; |
| 68 |
} |
| 69 |
|
| 70 |
public String getBrandingName() { |
| 71 |
return null; |
| 72 |
} |
| 73 |
|
| 74 |
public String getBrandingProperty(String key) { |
| 75 |
return null; |
| 76 |
} |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
public void execute() { |
| 81 |
//Compare against if baseline specified |
| 82 |
boolean compareAgainst = baseline != null; |
| 83 |
boolean comparator = comparatorID != null; |
| 84 |
//create arguments |
| 85 |
String[] args = new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), "-writeMode", clean ? "clean" : "", compare ? "-compare" : "", ignoreErrors ? "-ignoreErrors" : "", raw ? "-raw" : "", verbose ? "-verbose" : "", compareAgainst ? "-compareAgainst" : "", compareAgainst ? baseline.toExternalForm() : "", comparator ? "-comparator" : "", comparator ? comparatorID : ""}; |
| 86 |
|
| 87 |
try { |
| 88 |
runMirrorApplication(message, args); |
| 89 |
} catch (Exception e) { |
| 90 |
throw new BuildException("Exception while running mirror application.", e); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
public void setSource(String value) throws MalformedURLException { |
| 95 |
source = new URL(value); |
| 96 |
} |
| 97 |
|
| 98 |
public void setDestination(String value) throws MalformedURLException { |
| 99 |
destination = new URL(value); |
| 100 |
} |
| 101 |
|
| 102 |
public void setBaseline(String value) throws MalformedURLException { |
| 103 |
baseline = new URL(value); |
| 104 |
compare = true; |
| 105 |
} |
| 106 |
|
| 107 |
public void setComparatorID(String value) { |
| 108 |
comparatorID = value; |
| 109 |
compare = true; |
| 110 |
} |
| 111 |
|
| 112 |
public void setMessage(String value) { |
| 113 |
message = value; |
| 114 |
} |
| 115 |
|
| 116 |
public void setClean(boolean value) { |
| 117 |
clean = value; |
| 118 |
} |
| 119 |
|
| 120 |
public void setCompare(boolean value) { |
| 121 |
compare = value; |
| 122 |
} |
| 123 |
|
| 124 |
public void setIgnoreErrors(boolean value) { |
| 125 |
ignoreErrors = value; |
| 126 |
} |
| 127 |
|
| 128 |
public void setRaw(boolean value) { |
| 129 |
raw = value; |
| 130 |
} |
| 131 |
|
| 132 |
public void setVerbose(boolean value) { |
| 133 |
verbose = value; |
| 134 |
} |
| 135 |
} |