Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2010-01-05 18:46:08 +0000
committerAndrew Niefer2010-01-05 18:46:08 +0000
commit562b851e35aeb4ec4efd0e399647cebd96694eec (patch)
treed0bfa66befe225495f58d480bf7ecfc1a8986dd0
parent0d5feae3552aaef4b8200481f3165613ae754147 (diff)
downloadrt.equinox.p2-562b851e35aeb4ec4efd0e399647cebd96694eec.tar.gz
rt.equinox.p2-562b851e35aeb4ec4efd0e399647cebd96694eec.tar.xz
rt.equinox.p2-562b851e35aeb4ec4efd0e399647cebd96694eec.zip
bug 294334 - change product build to use in-process director
-rw-r--r--bundles/org.eclipse.equinox.p2.director.app/plugin.xml7
-rw-r--r--bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java46
-rw-r--r--bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/ILog.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties3
-rw-r--r--bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java192
6 files changed, 206 insertions, 59 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director.app/plugin.xml b/bundles/org.eclipse.equinox.p2.director.app/plugin.xml
index d4294922f..6d9af373f 100644
--- a/bundles/org.eclipse.equinox.p2.director.app/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.director.app/plugin.xml
@@ -23,4 +23,11 @@
<extension point="org.eclipse.ant.core.extraClasspathEntries">
<extraClasspathEntry library="ant_tasks/director-ant.jar"/>
</extension>
+ <extension point="org.eclipse.ant.core.antTasks">
+ <antTask
+ library="ant_tasks/director-ant.jar"
+ name="p2.director"
+ class="org.eclipse.equinox.p2.director.app.ant.DirectorTask">
+ </antTask>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java
index b7ba128fd..a90790e7d 100644
--- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java
+++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/DirectorApplication.java
@@ -204,6 +204,7 @@ public class DirectorApplication implements IApplication {
private PackageAdmin packageAdmin;
private ServiceReference packageAdminRef;
private IPlanner planner;
+ private ILog log = null;
private IProvisioningAgent agent;
@@ -351,7 +352,7 @@ public class DirectorApplication implements IApplication {
anyValid = true;
} catch (ProvisionException e) {
//one of the repositories did not load
- LogHelper.log(e.getStatus());
+ logStatus(e.getStatus());
}
}
if (!anyValid)
@@ -379,7 +380,7 @@ public class DirectorApplication implements IApplication {
anyValid = true;
} catch (ProvisionException e) {
//one of the repositories did not load
- LogHelper.log(e.getStatus());
+ logStatus(e.getStatus());
}
}
if (!anyValid)
@@ -443,11 +444,28 @@ public class DirectorApplication implements IApplication {
throw new ProvisionException(Messages.Missing_Engine);
}
- private void logFailure(IStatus status) {
- FrameworkLog log = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName());
+ private void logStatus(IStatus status) {
if (log != null)
- System.err.println("Application failed, log file location: " + log.getFile()); //$NON-NLS-1$
- LogHelper.log(status);
+ log.log(status);
+ else
+ LogHelper.log(status);
+ }
+
+ private void printMessage(String message) {
+ if (log != null)
+ log.log(message);
+ else
+ System.out.println(message);
+ }
+
+ private void logFailure(IStatus status) {
+ if (log == null) {
+ FrameworkLog frameworkLog = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName());
+ if (frameworkLog != null)
+ System.err.println("Application failed, log file location: " + frameworkLog.getFile()); //$NON-NLS-1$
+ }
+
+ logStatus(status);
}
private void markRoots(ProfileChangeRequest request, IInstallableUnit[] roots) {
@@ -525,11 +543,11 @@ public class DirectorApplication implements IApplication {
private void printRequest(ProfileChangeRequest request) {
IInstallableUnit[] toAdd = request.getAddedInstallableUnits();
for (int i = 0; i < toAdd.length; i++) {
- System.out.println(NLS.bind(Messages.Installing, toAdd[i].getId(), toAdd[i].getVersion()));
+ printMessage(NLS.bind(Messages.Installing, toAdd[i].getId(), toAdd[i].getVersion()));
}
IInstallableUnit[] toRemove = request.getRemovedInstallableUnits();
for (int i = 0; i < toRemove.length; i++) {
- System.out.println(NLS.bind(Messages.Uninstalling, toRemove[i].getId(), toRemove[i].getVersion()));
+ printMessage(NLS.bind(Messages.Uninstalling, toRemove[i].getId(), toRemove[i].getVersion()));
}
}
@@ -667,7 +685,7 @@ public class DirectorApplication implements IApplication {
}
if (!printHelpInfo && !printIUList && rootsToInstall.isEmpty() && rootsToUninstall.isEmpty() && revertToPreviousState == -1) {
- System.out.println(Messages.Help_Missing_argument);
+ printMessage(Messages.Help_Missing_argument);
printHelpInfo = true;
}
}
@@ -719,10 +737,11 @@ public class DirectorApplication implements IApplication {
performProvisioningActions();
if (printIUList)
performList();
- System.out.println(NLS.bind(Messages.Operation_complete, new Long(System.currentTimeMillis() - time)));
+ printMessage(NLS.bind(Messages.Operation_complete, new Long(System.currentTimeMillis() - time)));
}
return IApplication.EXIT_OK;
} catch (CoreException e) {
+ printMessage(Messages.Operation_failed);
deeplyPrint(e.getStatus(), System.err, 0);
logFailure(e.getStatus());
//set empty exit data to suppress error dialog from launcher
@@ -906,6 +925,11 @@ public class DirectorApplication implements IApplication {
}
public void stop() {
- // Nothing left to do here
+ if (log != null)
+ log.close();
+ }
+
+ public void setLog(ILog log) {
+ this.log = log;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/ILog.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/ILog.java
new file mode 100644
index 000000000..7d12bf3f2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/ILog.java
@@ -0,0 +1,14 @@
+package org.eclipse.equinox.internal.p2.director.app;
+
+import org.eclipse.core.runtime.IStatus;
+
+public interface ILog {
+
+ // Log a status
+ public void log(IStatus status);
+
+ public void log(String message);
+
+ // Notify that logging is completed & cleanup resources
+ public void close();
+}
diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java
index 53167e5c8..58ff15672 100644
--- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/Messages.java
@@ -68,6 +68,9 @@ public class Messages extends NLS {
public static String Uninstalling;
public static String unknown_option_0;
+ public static String problem_CallingDirector;
+ public static String problem_repoMustBeURI;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties
index 92924850b..cd8a4588b 100644
--- a/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.director.app/src/org/eclipse/equinox/internal/p2/director/app/messages.properties
@@ -58,3 +58,6 @@ unable_to_parse_0_to_uri_1=Unable to parse {0} into an URI: {1}.
unknown_option_0=Unknown option {0}. Use -help for a list of known options.
Help_Missing_argument=The argument specifying what to install or uninstall is missing.
Missing_profile = The profile to revert to could not be found.
+problem_CallingDirector=A problem occured while invoking the director.
+problem_repoMustBeURI = The repository location ({0}) must be a URI.
+
diff --git a/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java b/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java
index e3d1d56ae..d81ec3eba 100644
--- a/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java
+++ b/bundles/org.eclipse.equinox.p2.director.app/src_ant/org/eclipse/equinox/p2/director/app/ant/DirectorTask.java
@@ -13,26 +13,50 @@ package org.eclipse.equinox.p2.director.app.ant;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import org.apache.tools.ant.*;
+import org.apache.tools.ant.util.StringUtils;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.URIUtil;
-import org.eclipse.equinox.internal.p2.director.app.Application;
-import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
+import org.eclipse.equinox.internal.p2.director.app.*;
+import org.eclipse.equinox.internal.provisional.p2.metadata.VersionedId;
+import org.eclipse.osgi.util.NLS;
/**
* An Ant task to call the p2 Director application.
*
* @since 1.0
*/
-public class DirectorTask extends Task {
+public class DirectorTask extends Task implements ILog {
+ private static final String ANT_PREFIX = "${"; //$NON-NLS-1$
- boolean roaming;
- boolean list;
- String profile, flavor, os, ws, nl, arch, installIU, uninstallIU;
- File destination, bundlePool;
- URI metadataRepository, artifactRepository;
- Version version;
+ private boolean roaming;
+ private boolean list;
+ private String profile, flavor, os, ws, nl, arch, uninstallIU;
+ private String extraArguments;
+ private File destination, bundlePool, agentLocation;
+ private URI metadataRepository, artifactRepository;
+ private List ius = new ArrayList();
+ private String outputProperty;
+ private StringBuffer outputBuffer = null;
+
+ public static class IUDescription {
+ private String id = null;
+ private String version = null;
+
+ public VersionedId getVersionedId() {
+ return new VersionedId(id, version);
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setVersion(String version) {
+ if (version.length() > 0 && !version.startsWith(ANT_PREFIX))
+ this.version = version;
+ }
+ }
/*
* (non-Javadoc)
@@ -40,68 +64,96 @@ public class DirectorTask extends Task {
*/
public void execute() throws BuildException {
try {
+ if (outputProperty != null)
+ outputBuffer = new StringBuffer();
+
// collect the arguments and call the application
- new Application().run(getArguments());
+ DirectorApplication application = new DirectorApplication();
+ application.setLog(this);
+ application.run(getArguments());
} catch (Exception e) {
- throw new BuildException("Exception while calling the director task.", e);
+ getProject().log(Messages.problem_CallingDirector, e, Project.MSG_ERR);
+ throw new BuildException(Messages.problem_CallingDirector, e);
+ } finally {
+ if (outputBuffer != null) {
+ getProject().setNewProperty(outputProperty, outputBuffer.toString());
+ }
}
}
+ public void addConfiguredIu(IUDescription iu) {
+ ius.add(iu);
+ }
+
private String[] getArguments() {
List<String> result = new ArrayList<String>();
if (roaming)
- result.add("-roaming");
+ result.add("-roaming"); //$NON-NLS-1$
if (profile != null) {
- result.add("-profile");
+ result.add("-profile"); //$NON-NLS-1$
result.add(profile);
}
+ if (extraArguments != null) {
+ StringTokenizer tokenizer = new StringTokenizer(extraArguments);
+ while (tokenizer.hasMoreTokens()) {
+ result.add(tokenizer.nextToken());
+ }
+ }
if (destination != null) {
- result.add("-destination");
+ result.add("-destination"); //$NON-NLS-1$
result.add(destination.getAbsolutePath());
}
if (bundlePool != null) {
- result.add("-bundlePool");
+ result.add("-bundlePool"); //$NON-NLS-1$
result.add(bundlePool.getAbsolutePath());
}
+ if (agentLocation != null) {
+ result.add("-shared"); //$NON-NLS-1$
+ result.add(agentLocation.getAbsolutePath());
+ }
if (metadataRepository != null) {
- result.add("-metadataRepository");
+ result.add("-metadataRepository"); //$NON-NLS-1$
result.add(metadataRepository.toString());
}
if (artifactRepository != null) {
- result.add("-artifactRepository");
+ result.add("-artifactRepository"); //$NON-NLS-1$
result.add(artifactRepository.toString());
}
if (flavor != null) {
- result.add("-flavor");
+ result.add("-flavor"); //$NON-NLS-1$
result.add(flavor);
}
- if (version != null) {
- result.add("-version");
- result.add(version.toString());
+ if (ius.size() > 0) {
+ result.add("-installIUs"); //$NON-NLS-1$
+ StringBuffer arg = new StringBuffer();
+ for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
+ IUDescription object = (IUDescription) iterator.next();
+ arg.append(object.getVersionedId().toString());
+ if (iterator.hasNext())
+ arg.append(',');
+ }
+ result.add(arg.toString());
}
if (os != null) {
- result.add("-p2.os");
+ result.add("-p2.os"); //$NON-NLS-1$
result.add(os);
}
if (ws != null) {
- result.add("-p2.ws");
+ result.add("-p2.ws"); //$NON-NLS-1$
result.add(ws);
}
if (arch != null) {
- result.add("-p2.arch");
+ result.add("-p2.arch"); //$NON-NLS-1$
result.add(arch);
}
if (nl != null) {
- result.add("-p2.nl");
+ result.add("-p2.nl"); //$NON-NLS-1$
result.add(nl);
}
if (list) {
result.add(Application.COMMAND_NAMES[Application.COMMAND_LIST]);
}
- if (installIU != null) {
- result.add(Application.COMMAND_NAMES[Application.COMMAND_INSTALL]);
- result.add(installIU);
- }
+
if (uninstallIU != null) {
result.add(Application.COMMAND_NAMES[Application.COMMAND_UNINSTALL]);
result.add(uninstallIU);
@@ -117,7 +169,7 @@ public class DirectorTask extends Task {
try {
artifactRepository = URIUtil.fromString(value);
} catch (URISyntaxException e) {
- log("Error setting the artifact repository.", e, Project.MSG_ERR);
+ log(NLS.bind(Messages.problem_repoMustBeURI, value), e, Project.MSG_ERR);
}
}
@@ -130,50 +182,94 @@ public class DirectorTask extends Task {
}
public void setFlavor(String value) {
- flavor = value;
- }
-
- public void setInstallIU(String value) {
- installIU = value;
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ flavor = value;
}
public void setList(String value) {
- list = Boolean.valueOf(value).booleanValue();
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ list = Boolean.valueOf(value).booleanValue();
}
public void setMetadataRepository(String value) {
try {
metadataRepository = URIUtil.fromString(value);
} catch (URISyntaxException e) {
- log("Error setting the metadata repository.", e, Project.MSG_ERR);
+ log(NLS.bind(Messages.problem_repoMustBeURI, value), e, Project.MSG_ERR);
}
}
public void setNl(String value) {
- nl = value;
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ nl = value;
}
public void setOs(String value) {
- os = value;
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ os = value;
}
public void setProfile(String value) {
- profile = value;
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ profile = value;
+ }
+
+ public void setExtraArguments(String value) {
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX)) {
+ extraArguments = value;
+ }
+
}
public void setRoaming(String value) {
- roaming = Boolean.valueOf(value).booleanValue();
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ roaming = Boolean.valueOf(value).booleanValue();
}
public void setUninstallIU(String value) {
- uninstallIU = value;
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ uninstallIU = value;
}
- public void setVersion(String value) {
- version = Version.create(value);
+ public void setWs(String value) {
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ ws = value;
}
- public void setWs(String value) {
- ws = value;
+ public void setAgentLocation(String value) {
+ if (value != null && value.length() > 0 && !value.startsWith(ANT_PREFIX))
+ agentLocation = new File(value);
+ }
+
+ public void log(String msg) {
+ if (outputBuffer != null) {
+ outputBuffer.append(msg);
+ if (!msg.endsWith("\n")) //$NON-NLS-1$
+ outputBuffer.append(StringUtils.LINE_SEP);
+ }
+ super.log(msg, Project.MSG_INFO);
+ }
+
+ public void log(IStatus status) {
+ if (status.isMultiStatus()) {
+ IStatus[] children = status.getChildren();
+ for (int i = 0; i < children.length; i++)
+ log(children[i]);
+ }
+
+ log(status.getMessage(), status.getException(), Project.MSG_ERR);
+ if (outputBuffer != null) {
+ outputBuffer.append(status.getMessage());
+ outputBuffer.append(StringUtils.LINE_SEP);
+ }
+
+ }
+
+ public void setOutputProperty(String property) {
+ this.outputProperty = property;
+ }
+
+ public void close() {
+ // ILog#close(), nothing to do here
}
}

Back to the top