Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2011-03-31 21:28:46 +0000
committerPascal Rapicault2011-03-31 21:28:46 +0000
commitc377674f48d8946bbd6b8229a523f738540fbfb4 (patch)
tree25084152526b5299f69bd96e09a480eae6eea20c /bundles/org.eclipse.equinox.p2.publisher
parentb3382f1399d1d434084b66cdb72e35b050bea8f7 (diff)
downloadrt.equinox.p2-c377674f48d8946bbd6b8229a523f738540fbfb4.tar.gz
rt.equinox.p2-c377674f48d8946bbd6b8229a523f738540fbfb4.tar.xz
rt.equinox.p2-c377674f48d8946bbd6b8229a523f738540fbfb4.zip
Merging changes from work done for https://bugs.eclipse.org/bugs/show_bug.cgi?id=331974
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.publisher')
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/.classpath1
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Metadata Generator Ant Tasks.launch20
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Publisher Ant Tasks.launch20
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/.project10
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF35
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/ant_tasks/.cvsignore1
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/plugin.xml47
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml36
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Activator.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java137
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java54
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/BrandingIron.java544
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java130
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ExecutablesDescriptor.java265
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureManifestParser.java269
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureParser.java98
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java73
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/IProductDescriptor.java136
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ProductFile.java768
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/swt/tools/IconExe.java3339
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java31
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java215
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java85
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java138
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java182
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/TaskMessages.java26
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/messages.properties14
27 files changed, 10 insertions, 6666 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/.classpath b/bundles/org.eclipse.equinox.p2.publisher/.classpath
index 834ea833e..64c5e31b7 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/.classpath
+++ b/bundles/org.eclipse.equinox.p2.publisher/.classpath
@@ -3,6 +3,5 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="src" output="bin_ant" path="src_ant"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Metadata Generator Ant Tasks.launch b/bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Metadata Generator Ant Tasks.launch
deleted file mode 100644
index ec9c3e8df..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Metadata Generator Ant Tasks.launch
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
-<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
-<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
-<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/org.eclipse.equinox.p2.metadata.generator"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="4"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
-<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
-<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.equinox.p2.metadata.generator"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.equinox.p2.metadata.generator/scripts/buildExtraJAR.xml}"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value=""/>
-<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
-</launchConfiguration>
diff --git a/bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Publisher Ant Tasks.launch b/bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Publisher Ant Tasks.launch
deleted file mode 100644
index 3c6003b89..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/.externalToolBuilders/Build Publisher Ant Tasks.launch
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
-<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
-<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
-<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1255396868921_12&quot; label=&quot;working set&quot; name=&quot;working set&quot;&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.equinox.p2.publisher&quot; type=&quot;4&quot;/&gt;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
-<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
-<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.equinox.p2.publisher"/>
-<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml}"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
-<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
-</launchConfiguration>
diff --git a/bundles/org.eclipse.equinox.p2.publisher/.project b/bundles/org.eclipse.equinox.p2.publisher/.project
index 20aa4f425..b096e6556 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/.project
+++ b/bundles/org.eclipse.equinox.p2.publisher/.project
@@ -21,16 +21,6 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
- <triggers>full,incremental,</triggers>
- <arguments>
- <dictionary>
- <key>LaunchConfigHandle</key>
- <value>&lt;project&gt;/.externalToolBuilders/Build Publisher Ant Tasks.launch</value>
- </dictionary>
- </arguments>
- </buildCommand>
- <buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
diff --git a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
index bdba755d5..6fc7d7380 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
@@ -10,33 +10,17 @@ Export-Package: org.eclipse.equinox.internal.p2.publisher;
x-friends:="org.eclipse.equinox.p2.directorywatcher,
org.eclipse.equinox.p2.touchpoint.eclipse,
org.eclipse.equinox.p2.ui.sdk,
- org.eclipse.equinox.p2.updatesite",
- org.eclipse.equinox.internal.p2.publisher.compatibility;x-internal:=true,
- org.eclipse.equinox.internal.p2.publisher.eclipse;
- x-friends:="org.eclipse.equinox.p2.directorywatcher,
- org.eclipse.equinox.p2.extensionlocation,
- org.eclipse.equinox.p2.repository.tools,
- org.eclipse.equinox.p2.updatesite",
- org.eclipse.equinox.internal.p2.swt.tools;x-internal:=true,
- org.eclipse.equinox.p2.publisher;x-friends:="org.eclipse.equinox.p2.directorywatcher,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.updatesite",
- org.eclipse.equinox.p2.publisher.actions;x-friends:="org.eclipse.equinox.p2.updatesite,org.eclipse.equinox.p2.directorywatcher",
- org.eclipse.equinox.p2.publisher.eclipse;
- x-friends:="org.eclipse.equinox.p2.directorywatcher,
- org.eclipse.equinox.p2.extensionlocation,
- org.eclipse.equinox.p2.touchpoint.eclipse,
org.eclipse.equinox.p2.updatesite,
- org.eclipse.equinox.p2.repository.tools",
+ org.eclipse.pde.publishing",
+ org.eclipse.equinox.p2.publisher;x-friends:="org.eclipse.equinox.p2.directorywatcher,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.updatesite,org.eclipse.pde.publishing",
+ org.eclipse.equinox.p2.publisher.actions;x-friends:="org.eclipse.equinox.p2.updatesite,org.eclipse.equinox.p2.directorywatcher,org.eclipse.pde.publishing",
org.eclipse.equinox.spi.p2.publisher;x-friends:="org.eclipse.equinox.p2.updatesite"
Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.5.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: J2SE-1.5,
J2SE-1.4,
CDC-1.1/Foundation-1.1
Bundle-ActivationPolicy: lazy
-Import-Package: javax.xml.parsers,
- org.eclipse.equinox.app;version="1.0.0";resolution:=optional,
- org.eclipse.equinox.frameworkadmin;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.internal.frameworkadmin.equinox,
- org.eclipse.equinox.internal.frameworkadmin.utils,
+Import-Package: org.eclipse.equinox.app;version="1.0.0";resolution:=optional,
org.eclipse.equinox.internal.p2.artifact.repository,
org.eclipse.equinox.internal.p2.artifact.repository.simple,
org.eclipse.equinox.internal.p2.core.helpers,
@@ -44,7 +28,6 @@ Import-Package: javax.xml.parsers,
org.eclipse.equinox.internal.p2.metadata.expression,
org.eclipse.equinox.internal.p2.metadata.index,
org.eclipse.equinox.internal.p2.metadata.repository,
- org.eclipse.equinox.internal.provisional.frameworkadmin,
org.eclipse.equinox.p2.core;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.metadata;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.metadata.expression;version="[2.0.0,3.0.0)",
@@ -54,15 +37,7 @@ Import-Package: javax.xml.parsers,
org.eclipse.equinox.p2.repository.artifact;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.artifact.spi;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.metadata;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.p2.repository.spi,
- org.eclipse.equinox.simpleconfigurator.manipulator;version="[2.0.0,3.0.0)",
- org.eclipse.osgi.service.datalocation;version="1.2.0",
- org.eclipse.osgi.service.environment;version="1.1.0",
- org.eclipse.osgi.service.pluginconversion;version="1.0.0",
org.eclipse.osgi.service.resolver;version="1.2.0",
org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework;version="1.6.0",
- org.osgi.service.application;version="1.1.0",
- org.osgi.service.packageadmin;version="1.2.0",
- org.xml.sax,
- org.xml.sax.helpers
+ org.osgi.service.application;version="1.1.0"
diff --git a/bundles/org.eclipse.equinox.p2.publisher/ant_tasks/.cvsignore b/bundles/org.eclipse.equinox.p2.publisher/ant_tasks/.cvsignore
deleted file mode 100644
index 1d6b46f03..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/ant_tasks/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-publisher-ant.jar
diff --git a/bundles/org.eclipse.equinox.p2.publisher/plugin.xml b/bundles/org.eclipse.equinox.p2.publisher/plugin.xml
deleted file mode 100644
index 210c1d9e8..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/plugin.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.5"?>
-<plugin>
- <extension id="InstallPublisher" point="org.eclipse.core.runtime.applications">
- <application cardinality="1" thread="any" visible="true">
- <run class="org.eclipse.equinox.p2.publisher.eclipse.InstallPublisherApplication" />
- </application>
- </extension>
- <extension id="org.eclipse.equinox.p2.publisher.EclipseGenerator" point="org.eclipse.core.runtime.applications">
- <application cardinality="1" thread="main" visible="true">
- <run class="org.eclipse.equinox.internal.p2.publisher.compatibility.GeneratorApplication" />
- </application>
- </extension>
- <extension id="ProductPublisher" point="org.eclipse.core.runtime.applications">
- <application cardinality="1" thread="any" visible="true">
- <run class="org.eclipse.equinox.p2.publisher.eclipse.ProductPublisherApplication" />
- </application>
- </extension>
- <extension id="FeaturesAndBundlesPublisher" point="org.eclipse.core.runtime.applications">
- <application cardinality="1" thread="any" visible="true">
- <run class="org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherApplication" />
- </application>
- </extension>
-
- <extension point="org.eclipse.ant.core.antTasks">
- <antTask
- library="ant_tasks/publisher-ant.jar"
- name="p2.publisher"
- class="org.eclipse.equinox.internal.p2.publisher.ant.PublisherTask">
- </antTask>
- <antTask
- class="org.eclipse.equinox.internal.p2.publisher.ant.FeaturesAndBundlesPublisherTask"
- library="ant_tasks/publisher-ant.jar"
- name="p2.publish.featuresAndBundles">
- </antTask>
- <antTask
- class="org.eclipse.equinox.internal.p2.publisher.ant.ProductPublisherTask"
- library="ant_tasks/publisher-ant.jar"
- name="p2.publish.product">
- </antTask>
- </extension>
-
- <extension point="org.eclipse.ant.core.extraClasspathEntries">
- <extraClasspathEntry library="ant_tasks/publisher-ant.jar"/>
- </extension>
-
-</plugin>
diff --git a/bundles/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml b/bundles/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml
deleted file mode 100644
index a34be7af7..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="org.eclipse.equinox.p2.metadata.generator" default="default" basedir="..">
-
- <target name="init" depends="properties">
- <property name="plugin" value="org.eclipse.equinox.p2.publisher"/>
- <property name="temp.folder" value="${basedir}/temp.folder"/>
- <property name="plugin.destination" value="${basedir}"/>
- <property name="build.result.folder" value="${basedir}/ant_tasks"/>
- <property name="version.suffix" value="_1.0.0"/>
- </target>
-
- <target name="properties" if="eclipse.running">
- <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
- </target>
-
- <target name="buildScripts" depends="init" description="Build from generated scripts">
- <tstamp/>
- <eclipse.buildScript elements="plugin@${plugin}"
- buildDirectory="${buildDirectory}"
- configInfo="*,*,*"
- baseLocation="${baseLocation}"
- buildingOSGi="true"
- outputUpdateJars="false"
- pluginpath="${basedir}"
- forceContextQualifier="z${DSTAMP}${TSTAMP}"
- />
- <delete file="${basedir}/ant_tasks/publisher-ant.jar" failonerror="false"/>
- <ant antfile="${basedir}/build.xml" target="ant_tasks/publisher-ant.jar"/>
- </target>
-
- <target name="default" description="Jar up the binaries that were compiled by the jdt builder" >
- <mkdir dir="${basedir}/ant_tasks" />
- <delete file="${basedir}/ant_tasks/publisher-ant.jar" failonerror="false"/>
- <jar destfile="${basedir}/ant_tasks/publisher-ant.jar" basedir="bin_ant"/>
- </target>
-</project> \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Activator.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Activator.java
index 80380db60..78d22739e 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Activator.java
@@ -13,7 +13,7 @@ import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
- public static BundleContext context = null;
+ private static BundleContext context = null;
public static String ID = "org.eclipse.equinox.p2.publisher"; //$NON-NLS-1$
public static BundleContext getContext() {
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java
deleted file mode 100644
index f7bed224f..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.p2.publisher.compatibility;
-
-import java.io.File;
-import java.util.*;
-import org.eclipse.core.runtime.URIUtil;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.p2.publisher.Activator;
-import org.osgi.service.application.*;
-
-/**
- * @since 1.1
- */
-public class GeneratorApplication implements IApplication {
- protected static final String APP_ID = "app.id"; //$NON-NLS-1$
-
- public static final String UPDATE_SITE_APPLICATION = "org.eclipse.equinox.p2.publisher.UpdateSitePublisher"; //$NON-NLS-1$
- public static final String INSTALL_APPLICATION = "org.eclipse.equinox.p2.publisher.InstallPublisher"; //$NON-NLS-1$
- public static final String FEATURES_BUNDLES_APPLICATION = "org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher"; //$NON-NLS-1$
-
- public Object start(IApplicationContext context) throws Exception {
- return run((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS));
- }
-
- public void stop() {
- // TODO Auto-generated method stub
- }
-
- public Object run(String[] arguments) {
- Map<String, Object> argumentMap = parseArguments(arguments);
- return launchApplication(argumentMap);
- }
-
- protected Object launchApplication(Map<String, Object> applicationMap) {
- String applicationId = (String) applicationMap.get(APP_ID);
- String filter = "(service.pid=" + applicationId + ")"; //$NON-NLS-1$//$NON-NLS-2$
- ApplicationDescriptor descriptor = (ApplicationDescriptor) ServiceHelper.getService(Activator.getContext(), ApplicationDescriptor.class.getName(), filter);
- try {
- ApplicationHandle handle = descriptor.launch(applicationMap);
- return handle.getExitValue(0);
- } catch (ApplicationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- private Map<String, Object> parseArguments(String[] arguments) {
- Map<String, Object> applicationMap = new HashMap<String, Object>();
- Map<String, String> args = new HashMap<String, String>(arguments.length);
- for (int i = 0; i < arguments.length; i++) {
- if (i == arguments.length - 1 || arguments[i + 1].startsWith(IGeneratorConstants.DASH))
- args.put(arguments[i], null);
- else
- args.put(arguments[i], arguments[++i]);
- }
-
- //adjust the short forms
- if (args.containsKey(IGeneratorConstants.AR))
- args.put(IGeneratorConstants.ARTIFACT_REPO, args.remove(IGeneratorConstants.AR));
- if (args.containsKey(IGeneratorConstants.MR))
- args.put(IGeneratorConstants.METADATA_REPO, args.remove(IGeneratorConstants.MR));
- if (args.containsKey(IGeneratorConstants.PA))
- args.put(IGeneratorConstants.PUBLISH_ARTIFACTS, args.remove(IGeneratorConstants.PA));
- if (args.containsKey(IGeneratorConstants.PAR))
- args.put(IGeneratorConstants.PUBLISH_ATIFACT_REPOSITORY, args.remove(IGeneratorConstants.PAR));
-
- if (args.containsKey(IGeneratorConstants.ROOT)) {
- String rootId = args.remove(IGeneratorConstants.ROOT);
- args.put(IGeneratorConstants.IU, rootId);
- args.put(IGeneratorConstants.ID, rootId);
- }
-
- if (args.containsKey(IGeneratorConstants.ROOT_VERSION))
- args.put(IGeneratorConstants.VERSION, args.remove(IGeneratorConstants.ROOT_VERSION));
-
- String source = null;
- // -inplace and -updateSite become -source, and imply -append
- if (args.containsKey(IGeneratorConstants.UPDATE_SITE))
- source = args.remove(IGeneratorConstants.UPDATE_SITE);
- if (args.containsKey(IGeneratorConstants.INPLACE))
- source = args.remove(IGeneratorConstants.INPLACE);
- if (source != null) {
- args.put(IGeneratorConstants.SOURCE, source);
- args.put(IGeneratorConstants.APPEND, null);
-
- //if not specified, repo locations are based on source
- String repoLocation = URIUtil.toUnencodedString(new File(source).toURI());
- if (!args.containsKey(IGeneratorConstants.ARTIFACT_REPO))
- args.put(IGeneratorConstants.ARTIFACT_REPO, repoLocation);
- if (!args.containsKey(IGeneratorConstants.METADATA_REPO))
- args.put(IGeneratorConstants.METADATA_REPO, repoLocation);
- }
-
- File base = new File(args.get(IGeneratorConstants.SOURCE));
- File configuration = new File(base, "configuration"); //$NON-NLS-1$
- if (configuration.exists()) {
- applicationMap.put(APP_ID, INSTALL_APPLICATION);
- } else if (args.containsKey(IGeneratorConstants.SITE)) {
- applicationMap.put(APP_ID, UPDATE_SITE_APPLICATION);
- } else if (args.containsKey(IGeneratorConstants.CONFIG)) {
- applicationMap.put(APP_ID, INSTALL_APPLICATION);
- } else {
- applicationMap.put(APP_ID, FEATURES_BUNDLES_APPLICATION);
- }
-
- applicationMap.put(IApplicationContext.APPLICATION_ARGS, flattenMap(args));
- return applicationMap;
- }
-
- private String[] flattenMap(Map<String, String> map) {
- ArrayList<String> list = new ArrayList<String>(map.size());
- for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();) {
- String key = iterator.next();
- String value = map.get(key);
- list.add(key);
- if (value != null)
- list.add(value);
- }
- return list.toArray(new String[list.size()]);
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java
deleted file mode 100644
index 30bd49cb9..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.internal.p2.publisher.compatibility;
-
-/**
- * @since 1.1
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IGeneratorConstants {
- public static final String DASH = "-"; //$NON-NLS-1$
-
- //arguments understood by the old metadata generator application
- public static final String PUBLISH_ARTIFACTS = "-publishArtifacts"; //$NON-NLS-1$
- public static final String PA = "-pa"; //$NON-NLS-1$
- public static final String PUBLISH_ATIFACT_REPOSITORY = "-publishArtifactRepository"; //$NON-NLS-1$
- public static final String PAR = "-par"; //$NON-NLS-1$
- public static final String APPEND = "-append"; //$NON-NLS-1$
- public static final String NO_DEFAULT_IUS = "-noDefaultIUs"; //$NON-NLS-1$
- public static final String COMPRESS = "-compress"; //$NON-NLS-1$
- public static final String REUSE_PACK200 = "-reusePack200Files"; //$NON-NLS-1$
- public static final String SOURCE = "-source"; //$NON-NLS-1$
- public static final String INPLACE = "-inplace"; //$NON-NLS-1$
- public static final String CONFIG = "-config"; //$NON-NLS-1$
- public static final String UPDATE_SITE = "-updateSite"; //$NON-NLS-1$
- public static final String EXE = "-exe"; //$NON-NLS-1$
- public static final String LAUNCHER_CONFIG = "-launcherConfig"; //$NON-NLS-1$
- public static final String METADATA_REPO_NAME = "-metadataRepositoryName"; //$NON-NLS-1$
- public static final String METADATA_REPO = "-metadataRepository"; //$NON-NLS-1$
- public static final String MR = "-mr"; //$NON-NLS-1$
- public static final String ARTIFACT_REPO = "-artifactRepository"; //$NON-NLS-1$
- public static final String AR = "-ar"; //$NON-NLS-1$
- public static final String ARTIFACT_REPO_NAME = "-artifactRepositoryName"; //$NON-NLS-1$
- public static final String FLAVOR = "-flavor"; //$NON-NLS-1$
- public static final String PRODUCT_FILE = "-productFile"; //$NON-NLS-1$
- public static final String FEATURES = "-features"; //$NON-NLS-1$
- public static final String BUNDLES = "-bundles"; //$NON-NLS-1$
- public static final String BASE = "-base"; //$NON-NLS-1$
- public static final String ROOT = "-root"; //$NON-NLS-1$
- public static final String ROOT_VERSION = "-rootVersion"; //$NON-NLS-1$
- public static final String P2_OS = "-p2.os"; //$NON-NLS-1$
- public static final String SITE = "-site"; //$NON-NLS-1$
- public static final String IU = "-iu"; //$NON-NLS-1$
- public static final String ID = "-id"; //$NON-NLS-1$
- public static final String VERSION = "-version"; //$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/BrandingIron.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/BrandingIron.java
deleted file mode 100644
index 5878b640c..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/BrandingIron.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2008 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
- * Code 9 - Additional function and fixes
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.*;
-import org.eclipse.equinox.internal.frameworkadmin.utils.Utils;
-import org.eclipse.equinox.internal.p2.swt.tools.IconExe;
-
-/**
- *
- */
-public class BrandingIron {
- private static final String MARKER_NAME = "%EXECUTABLE_NAME%"; //$NON-NLS-1$
- private static final String BUNDLE_NAME = "%BUNDLE_NAME%"; //$NON-NLS-1$
- private static final String ICON_NAME = "%ICON_NAME%"; //$NON-NLS-1$
- private static final String MARKER_KEY = "<key>CFBundleExecutable</key>"; //$NON-NLS-1$
- private static final String BUNDLE_KEY = "<key>CFBundleName</key>"; //$NON-NLS-1$
- private static final String ICON_KEY = "<key>CFBundleIconFile</key>"; //$NON-NLS-1$
- private static final String STRING_START = "<string>"; //$NON-NLS-1$
- private static final String STRING_END = "</string>"; //$NON-NLS-1$
- private static final String XDOC_ICON = "-Xdock:icon=../Resources/Eclipse.icns"; //$NON-NLS-1$
- private static final String XDOC_ICON_PREFIX = "-Xdock:icon=../Resources/"; //$NON-NLS-1$
-
- private String[] icons = null;
- private String root;
- private String name;
- private String os = "win32"; //$NON-NLS-1$
- private boolean brandIcons = true;
-
- public void setName(String value) {
- name = value;
- }
-
- public void setIcons(String[] value) {
- icons = value;
- }
-
- public void setIcons(String value) {
- icons = Utils.getTokens(value, ",");//$NON-NLS-1$
- if (icons[0].startsWith("${")) { //$NON-NLS-1$
- if (icons.length > 1) {
- String[] temp = new String[icons.length - 1];
- System.arraycopy(icons, 1, temp, 0, temp.length);
- icons = temp;
- } else {
- icons = null;
- }
- }
- //trim whitespace
- if (icons != null) {
- for (int i = 0; i < icons.length; i++) {
- icons[i] = icons[i].trim();
- }
- }
- }
-
- public void setRoot(String value) {
- root = value;
- }
-
- public void brand() throws Exception {
- // if the name property is not set it will be ${launcher.name} so just bail.
- if (name.startsWith("${")) //$NON-NLS-1$
- return;
-
- if (icons == null || icons[0].startsWith("${")) //$NON-NLS-1$
- brandIcons = false;
-
- // if the root does not exists (happens in some packaging cases) or
- // there is already a file with target name and we don't need to update its icons, don't do anything
- String testName = os.equals("win32") ? name + ".exe" : name; //$NON-NLS-1$ //$NON-NLS-2$
- if (!new File(root).exists() || (!brandIcons && new File(root, testName).exists()))
- return;
-
- if ("win32".equals(os)) //$NON-NLS-1$
- brandWindows();
- else if ("linux".equals(os)) //$NON-NLS-1$
- brandLinux();
- else if ("solaris".equals(os)) //$NON-NLS-1$
- brandSolaris();
- else if ("macosx".equals(os)) //$NON-NLS-1$
- brandMac();
- else if ("aix".equals(os)) //$NON-NLS-1$
- brandAIX();
- else if ("hpux".equals(os)) //$NON-NLS-1$
- brandHPUX();
- else
- renameLauncher();
- }
-
- private void brandAIX() {
- renameLauncher();
- }
-
- private void brandHPUX() {
- renameLauncher();
- }
-
- private void brandLinux() throws Exception {
- renameLauncher();
- if (brandIcons)
- copy(new File(icons[0]), new File(root, "icon.xpm")); //$NON-NLS-1$
- }
-
- private void brandSolaris() throws Exception {
- renameLauncher();
- if (brandIcons == false)
- return;
-
- for (int i = 0; i < icons.length; i++) {
- String icon = icons[i];
- if (icon.endsWith(".l.pm")) //$NON-NLS-1$
- copy(new File(icon), new File(root, name + ".l.pm")); //$NON-NLS-1$
- if (icon.endsWith(".m.pm")) //$NON-NLS-1$
- copy(new File(icon), new File(root, name + ".m.pm")); //$NON-NLS-1$
- if (icon.endsWith(".s.pm")) //$NON-NLS-1$
- copy(new File(icon), new File(root, name + ".s.pm")); //$NON-NLS-1$
- if (icon.endsWith(".t.pm")) //$NON-NLS-1$
- copy(new File(icon), new File(root, name + ".t.pm")); //$NON-NLS-1$
- }
- }
-
- private void brandMac() throws Exception {
- //Initially the files are in: <root>/Eclipse.app/
- //and they must appear in <root>/MyAppName.app/
- //Because java does not support the rename of a folder, files are copied.
-
- //Initialize the target folders
- String appName = name;
- if (appName.equals("eclipse")) //$NON-NLS-1$
- appName = "Eclipse"; //$NON-NLS-1$
- else if (appName.equals("launcher")) //$NON-NLS-1$
- appName = "Launcher"; //$NON-NLS-1$
-
- String target = root + '/' + appName + ".app/Contents"; //$NON-NLS-1$
- new File(target).mkdirs();
- new File(target + "/MacOS").mkdirs(); //$NON-NLS-1$
- new File(target + "/Resources").mkdirs(); //$NON-NLS-1$
-
- String initialRoot = root + "/Launcher.app/Contents"; //$NON-NLS-1$
- if (!new File(initialRoot).exists())
- initialRoot = root + "/Eclipse.app/Contents"; //$NON-NLS-1$
- copyMacLauncher(initialRoot, target);
- String iconName = ""; //$NON-NLS-1$
- File splashApp = new File(initialRoot, "Resources/Splash.app"); //$NON-NLS-1$
- if (brandIcons) {
- File icon = new File(icons[0]);
- iconName = icon.getName();
- copy(icon, new File(target + "/Resources/" + icon.getName())); //$NON-NLS-1$
- new File(initialRoot + "/Resources/Eclipse.icns").delete(); //$NON-NLS-1$
- if (!splashApp.exists())
- new File(initialRoot + "/Resources/").delete(); //$NON-NLS-1$
- }
- copyMacIni(initialRoot, target, iconName);
- modifyInfoPListFile(initialRoot, target, iconName);
- if (splashApp.exists()) {
- brandMacSplash(initialRoot, target, iconName);
- }
-
- File rootFolder = getCanonicalFile(new File(initialRoot));
- File targetFolder = getCanonicalFile(new File(target));
- if (!rootFolder.equals(targetFolder)) {
- rootFolder.delete();
- if (rootFolder.exists()) {
- //if the rootFolder still exists, its because there were other files that need to be moved over
- moveContents(rootFolder, targetFolder);
- }
- rootFolder.getParentFile().delete();
- }
- }
-
- /**
- * Brand the splash.app Info.plist and link or copy the mac launcher.
- * It is assumed that the mac launcher has been branded already.
- * @param initialRoot
- * @param target
- * @param iconName
- */
- private void brandMacSplash(String initialRoot, String target, String iconName) {
- String splashContents = "/Resources/Splash.app/Contents"; //$NON-NLS-1$
- modifyInfoPListFile(initialRoot + splashContents, target + splashContents, iconName);
-
- //link the MacOS launcher for the splash app
- int result = -1;
- String osName = System.getProperty("os.name"); //$NON-NLS-1$
- if (osName != null && !osName.startsWith("Windows")) { //$NON-NLS-1$
- try {
- String[] command = new String[] {"ln", "-sf", "../../../MacOS/" + name, "MacOS/" + name}; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
- File linkDir = new File(target, splashContents);
- Process proc = Runtime.getRuntime().exec(command, null, linkDir);
- result = proc.waitFor();
- } catch (IOException e) {
- // ignore
- } catch (InterruptedException e) {
- // ignore
- }
- }
-
- if (result != 0) {
- //ln failed, or we are on windows, just copy the executable instead
- File macOSDir = new File(target, "MacOS"); //$NON-NLS-1$
- File splashMacOSDir = new File(target, splashContents + "/MacOS"); //$NON-NLS-1$
- splashMacOSDir.mkdirs();
- try {
- File targetFile = new File(splashMacOSDir, name);
- copy(new File(macOSDir, name), targetFile);
- try {
- Runtime.getRuntime().exec(new String[] {"chmod", "755", targetFile.getAbsolutePath()}); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (IOException e) {
- // ignore
- }
- } catch (IOException e) {
- System.out.println("Could not copy macosx splash launcher"); //$NON-NLS-1$
- }
- }
- }
-
- private void moveContents(File source, File target) {
- if (!source.exists())
- return;
-
- try {
- if (source.getCanonicalFile().equals(target.getCanonicalFile()))
- return;
- } catch (IOException e) {
- System.out.println("Could not copy macosx resources."); //$NON-NLS-1$
- return;
- }
-
- target.getParentFile().mkdirs();
- if (source.isDirectory()) {
- target.mkdirs();
- File[] contents = source.listFiles();
- for (int i = 0; i < contents.length; i++) {
- File dest = new File(target, contents[i].getName());
- if (contents[i].isFile())
- contents[i].renameTo(dest);
- else
- moveContents(contents[i], dest);
- }
- source.delete();
- } else {
- source.renameTo(target);
- }
- }
-
- private void brandWindows() throws Exception {
- File templateLauncher = new File(root, name + ".exe"); //$NON-NLS-1$
- if (!templateLauncher.exists())
- templateLauncher = new File(root, "launcher.exe"); //$NON-NLS-1$
- if (!templateLauncher.exists())
- templateLauncher = new File(root, "eclipse.exe"); //$NON-NLS-1$
- if (brandIcons) {
- if (templateLauncher.exists()) {
- String[] args = new String[icons.length + 1];
- args[0] = templateLauncher.getAbsolutePath();
- System.arraycopy(icons, 0, args, 1, icons.length);
- IconExe.main(args);
- }
- }
- if (templateLauncher.exists() && !templateLauncher.getName().equals(name + ".exe")) //$NON-NLS-1$
- templateLauncher.renameTo(new File(root, name + ".exe")); //$NON-NLS-1$
- }
-
- private void renameLauncher() {
- if (!new File(root, "launcher").renameTo(new File(root, name))) //$NON-NLS-1$
- new File(root, "eclipse").renameTo(new File(root, name)); //$NON-NLS-1$
- }
-
- private void copyMacLauncher(String initialRoot, String target) {
- String targetLauncher = target + "/MacOS/"; //$NON-NLS-1$
- File launcher = getCanonicalFile(new File(initialRoot + "/MacOS/launcher")); //$NON-NLS-1$
- File eclipseLauncher = getCanonicalFile(new File(initialRoot + "/MacOS/eclipse")); //$NON-NLS-1$
- File targetFile = getCanonicalFile(new File(targetLauncher, name));
- if (!launcher.exists()) {
- launcher = eclipseLauncher;
- } else if (eclipseLauncher.exists() && !targetFile.equals(eclipseLauncher)) {
- //we may actually have both if exporting from the mac
- eclipseLauncher.delete();
- }
- try {
- if (targetFile.equals(launcher)) {
- try {
- //Force the executable bit on the exe because it has been lost when copying the file
- Runtime.getRuntime().exec(new String[] {"chmod", "755", targetFile.getAbsolutePath()}); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (IOException e) {
- //ignore
- }
- return;
- }
- copy(launcher, targetFile);
- } catch (IOException e) {
- System.out.println("Could not copy macosx launcher"); //$NON-NLS-1$
- return;
- }
- try {
- //Force the executable bit on the exe because it has been lost when copying the file
- Runtime.getRuntime().exec(new String[] {"chmod", "755", targetFile.getAbsolutePath()}); //$NON-NLS-1$ //$NON-NLS-2$
- } catch (IOException e) {
- //ignore
- }
- launcher.delete();
- launcher.getParentFile().delete();
- }
-
- private File getCanonicalFile(File file) {
- try {
- return file.getCanonicalFile();
- } catch (IOException e) {
- return file;
- }
- }
-
- private void copyMacIni(String initialRoot, String target, String iconName) {
- // 3 possibilities, in order of preference:
- // rcp.app/Contents/MacOS/rcp.ini (targetFile)
- // Eclipse.app/Contents/MacOS/rcp.ini (brandedIni)
- // Eclipse.app/Contents/MacOs/eclipse.ini (ini)
- File targetFile = getCanonicalFile(new File(target, "/MacOS/" + name + ".ini")); //$NON-NLS-1$//$NON-NLS-2$
- File brandedIni = getCanonicalFile(new File(initialRoot, "/MacOS/" + name + ".ini")); //$NON-NLS-1$ //$NON-NLS-2$
- File ini = getCanonicalFile(new File(initialRoot, "/MacOS/eclipse.ini")); //$NON-NLS-1$
-
- if (targetFile.exists()) {
- //an ini already exists at the target, use that
- if (brandedIni.exists() && !brandedIni.equals(targetFile))
- brandedIni.delete();
- if (ini.exists() && !ini.equals(targetFile))
- ini.delete();
- ini = targetFile;
- } else if (brandedIni.exists()) {
- //take the one that is already branded
- if (ini.exists() && !ini.equals(brandedIni))
- ini.delete();
- ini = brandedIni;
- } else if (!ini.exists()) {
- return;
- }
-
- StringBuffer buffer;
- try {
- buffer = readFile(ini);
- } catch (IOException e) {
- System.out.println("Impossible to brand ini file"); //$NON-NLS-1$
- return;
- }
-
- if (iconName.length() > 0) {
- int xdoc = scan(buffer, 0, XDOC_ICON);
- if (xdoc != -1) {
- String icns = XDOC_ICON_PREFIX + iconName;
- buffer.replace(xdoc, xdoc + XDOC_ICON.length(), icns);
- }
- }
-
- try {
- transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(targetFile));
- if (!ini.equals(targetFile))
- ini.delete();
- } catch (FileNotFoundException e) {
- System.out.println("Impossible to brand ini file"); //$NON-NLS-1$
- return;
- } catch (IOException e) {
- System.out.println("Impossible to brand ini file"); //$NON-NLS-1$
- return;
- }
- }
-
- private void modifyInfoPListFile(String initialRoot, String targetRoot, String iconName) {
- File infoPList = new File(initialRoot, "Info.plist"); //$NON-NLS-1$
- StringBuffer buffer;
- try {
- buffer = readFile(infoPList);
- } catch (IOException e) {
- System.out.println("Impossible to brand info.plist file"); //$NON-NLS-1$
- return;
- }
- int exePos = scan(buffer, 0, MARKER_NAME);
- if (exePos != -1)
- buffer.replace(exePos, exePos + MARKER_NAME.length(), name);
- else {
- exePos = scan(buffer, 0, MARKER_KEY);
- if (exePos != -1) {
- int start = scan(buffer, exePos + MARKER_KEY.length(), STRING_START);
- int end = scan(buffer, start + STRING_START.length(), STRING_END);
- if (start > -1 && end > start) {
- buffer.replace(start + STRING_START.length(), end, name);
- }
- }
- }
-
- int bundlePos = scan(buffer, 0, BUNDLE_NAME);
- if (bundlePos != -1)
- buffer.replace(bundlePos, bundlePos + BUNDLE_NAME.length(), name);
- else {
- exePos = scan(buffer, 0, BUNDLE_KEY);
- if (exePos != -1) {
- int start = scan(buffer, exePos + BUNDLE_KEY.length(), STRING_START);
- int end = scan(buffer, start + STRING_START.length(), STRING_END);
- if (start > -1 && end > start) {
- buffer.replace(start + STRING_START.length(), end, name);
- }
- }
- }
-
- int iconPos = scan(buffer, 0, ICON_NAME);
- if (iconPos != -1)
- buffer.replace(iconPos, iconPos + ICON_NAME.length(), iconName);
- else {
- exePos = scan(buffer, 0, ICON_KEY);
- if (exePos != -1) {
- int start = scan(buffer, exePos + ICON_KEY.length(), STRING_START);
- int end = scan(buffer, start + STRING_START.length(), STRING_END);
- if (start > -1 && end > start) {
- buffer.replace(start + STRING_START.length(), end, iconName);
- }
- }
- }
-
- File target = null;
- try {
- target = new File(targetRoot, "Info.plist"); //$NON-NLS-1$
- target.getParentFile().mkdirs();
- transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(target));
- } catch (FileNotFoundException e) {
- System.out.println("Impossible to brand info.plist file"); //$NON-NLS-1$
- return;
- } catch (IOException e) {
- System.out.println("Impossible to brand info.plist file"); //$NON-NLS-1$
- return;
- }
- try {
- if (!infoPList.getCanonicalFile().equals(target.getCanonicalFile()))
- infoPList.delete();
- } catch (IOException e) {
- //ignore
- }
- }
-
- /**
- * Transfers all available bytes from the given input stream to the given output stream.
- * Regardless of failure, this method closes both streams.
- * @throws IOException
- */
- public void copy(File source, File destination) throws IOException {
- InputStream in = null;
- OutputStream out = null;
- try {
- in = new BufferedInputStream(new FileInputStream(source));
- out = new BufferedOutputStream(new FileOutputStream(destination));
- final byte[] buffer = new byte[8192];
- while (true) {
- int bytesRead = -1;
- bytesRead = in.read(buffer);
- if (bytesRead == -1)
- break;
- out.write(buffer, 0, bytesRead);
- }
- } finally {
- try {
- if (in != null)
- in.close();
- } finally {
- if (out != null)
- out.close();
- }
- }
- }
-
- private int scan(StringBuffer buf, int start, String targetName) {
- return scan(buf, start, new String[] {targetName});
- }
-
- private int scan(StringBuffer buf, int start, String[] targets) {
- for (int i = start; i < buf.length(); i++) {
- for (int j = 0; j < targets.length; j++) {
- if (i < buf.length() - targets[j].length()) {
- String match = buf.substring(i, i + targets[j].length());
- if (targets[j].equalsIgnoreCase(match))
- return i;
- }
- }
- }
- return -1;
- }
-
- private StringBuffer readFile(File targetName) throws IOException {
- InputStreamReader reader = new InputStreamReader(new BufferedInputStream(new FileInputStream(targetName)));
- StringBuffer result = new StringBuffer();
- char[] buf = new char[4096];
- int count;
- try {
- count = reader.read(buf, 0, buf.length);
- while (count != -1) {
- result.append(buf, 0, count);
- count = reader.read(buf, 0, buf.length);
- }
- } finally {
- try {
- reader.close();
- } catch (IOException e) {
- // ignore exceptions here
- }
- }
- return result;
- }
-
- private void transferStreams(InputStream source, OutputStream destination) throws IOException {
- source = new BufferedInputStream(source);
- destination = new BufferedOutputStream(destination);
- try {
- byte[] buffer = new byte[8192];
- while (true) {
- int bytesRead = -1;
- if ((bytesRead = source.read(buffer)) == -1)
- break;
- destination.write(buffer, 0, bytesRead);
- }
- } finally {
- try {
- source.close();
- } catch (IOException e) {
- // ignore
- }
- try {
- destination.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
-
- public void setOS(String value) {
- os = value;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java
deleted file mode 100644
index b6244ce8b..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/DataLoader.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Code 9 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:
- * Code 9 - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.*;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxFwConfigFileParser;
-import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxManipulatorImpl;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.p2.publisher.Activator;
-import org.eclipse.equinox.internal.provisional.frameworkadmin.*;
-import org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
-import org.osgi.framework.Constants;
-
-public class DataLoader {
-
- private final static String FILTER_OBJECTCLASS = "(" + Constants.OBJECTCLASS + "=" + FrameworkAdmin.class.getName() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- private final static String filterFwName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_FW_NAME + "=Equinox)"; //$NON-NLS-1$ //$NON-NLS-2$
- //String filterFwVersion = "(" + FrameworkAdmin.SERVICE_PROP_KEY_FW_VERSION + "=" + props.getProperty("equinox.fw.version") + ")";
- private final static String filterLauncherName = "(" + FrameworkAdmin.SERVICE_PROP_KEY_LAUNCHER_NAME + "=Eclipse.exe)"; //$NON-NLS-1$ //$NON-NLS-2$
- //String filterLauncherVersion = "(" + FrameworkAdmin.SERVICE_PROP_KEY_LAUNCHER_VERSION + "=" + props.getProperty("equinox.launcher.version") + ")";
- private final static String frameworkAdminFillter = "(&" + FILTER_OBJECTCLASS + filterFwName + filterLauncherName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final String ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL = "org.eclipse.equinox.simpleconfigurator.configUrl"; //$NON-NLS-1$
-
- private Manipulator manipulator;
- private File configurationLocation;
-
- /**
- *
- * @param configurationLocation configuration file (i.e. config.ini).
- * @param executableLocation executable file (i.e. eclipse.exe).
- */
- public DataLoader(File configurationLocation, File executableLocation) {
- this.configurationLocation = configurationLocation;
- initializeFrameworkManipulator(configurationLocation.getParentFile(), executableLocation);
- }
-
- private void initializeFrameworkManipulator(File config, File executable) {
- getFrameworkManipulator();
-
- LauncherData launcherData = manipulator.getLauncherData();
- launcherData.setFwPersistentDataLocation(config, true);
- launcherData.setLauncher(executable);
- if (executable == null)
- launcherData.setHome(config.getParentFile());
- try {
- manipulator.load();
- } catch (IllegalStateException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- } catch (FrameworkAdminRuntimeException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- } catch (IOException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- }
-
- public ConfigData getConfigData() {
- if (manipulator == null)
- return null;
-
- EquinoxFwConfigFileParser parser = new EquinoxFwConfigFileParser(Activator.getContext());
- try {
- if (configurationLocation != null && configurationLocation.exists())
- parser.readFwConfig(manipulator, configurationLocation);
- } catch (IOException e) {
- LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error loading config.", e)); //$NON-NLS-1$ //TODO: Fix error string
- } catch (URISyntaxException e) {
- LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error loading config.", e)); //$NON-NLS-1$ //TODO: Fix error string
- }
- ConfigData data = manipulator.getConfigData();
- String value = data.getProperty(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL);
- if (value != null) {
- try {
- //config.ini uses simpleconfigurator, read the bundles.info and replace the bundle infos
- SimpleConfiguratorManipulator simpleManipulator = (SimpleConfiguratorManipulator) ServiceHelper.getService(Activator.getContext(), SimpleConfiguratorManipulator.class.getName());
- //input stream will be buffered and closed for us
- BundleInfo[] bundleInfos = simpleManipulator.loadConfiguration(new URL(value).openStream(), null);
- data.setBundles(bundleInfos);
- } catch (MalformedURLException e1) {
- // ignore
- } catch (IOException e1) {
- // ignore
- }
- try {
- data.setProperty(ORG_ECLIPSE_EQUINOX_SIMPLECONFIGURATOR_CONFIGURL, EquinoxManipulatorImpl.makeRelative(value, configurationLocation.toURL()));
- } catch (MalformedURLException e) {
- //ignore
- }
- }
-
- return data;
- }
-
- public LauncherData getLauncherData() {
- return manipulator == null ? null : manipulator.getLauncherData();
- }
-
- /**
- * Obtains the framework manipulator instance. Throws an exception
- * if it could not be created.
- */
- private void getFrameworkManipulator() {
- FrameworkAdmin admin = getFrameworkAdmin();
- if (admin == null)
- throw new RuntimeException("Framework admin service not found"); //$NON-NLS-1$
- manipulator = admin.getManipulator();
- if (manipulator == null)
- throw new RuntimeException("Framework manipulator not found"); //$NON-NLS-1$
- }
-
- private FrameworkAdmin getFrameworkAdmin() {
- return (FrameworkAdmin) ServiceHelper.getService(Activator.getContext(), FrameworkAdmin.class.getName(), frameworkAdminFillter);
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ExecutablesDescriptor.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ExecutablesDescriptor.java
deleted file mode 100644
index e10b6c502..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ExecutablesDescriptor.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 EclipseSource 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:
- * Eclipse Source - initial API and implementation
- * IBM Corporation - ongoing development
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.*;
-import java.util.HashSet;
-import java.util.Set;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.publisher.Activator;
-import org.eclipse.equinox.p2.publisher.AbstractPublisherAction;
-import org.eclipse.osgi.service.environment.Constants;
-
-public class ExecutablesDescriptor {
-
- private File location;
- private Set<File> files;
- private String executableName;
- private boolean temporary = false;
- private String os;
- private File iniFile;
-
- public static File findExecutable(String os, File root, String baseName) {
- // TODO this may need to get more intelligent
- // if MacOS its going to be baseName.app/Contents/MacOS/baseName
- if (Constants.OS_MACOSX.equals(os)) {
- return new File(root, baseName + ".app/Contents/MacOS/" + baseName); //$NON-NLS-1$
- }
- // if it is not Mac and not Windows it must be a UNIX flavor
- if (!Constants.OS_WIN32.equals(os)) {
- return new File(root, baseName);
- }
- // otherwise we are left with windows
- return new File(root, baseName + ".exe"); //$NON-NLS-1$
- }
-
- /**
- * Return the root directory of the executables folder for the given configSpec. The folder
- * is expected to be part of the standard Eclipse executables feature whose structure is
- * embedded here.
- * @param executablesFeatureLocation the location of the executables feature
- * @param configSpec the configuration to lookup
- * @return the root location of the requested executables
- */
- public static ExecutablesDescriptor createExecutablesFromFeature(File executablesFeatureLocation, String configSpec) {
- // TODO consider handling JAR'd features here...
- if (executablesFeatureLocation == null || !executablesFeatureLocation.exists())
- return null;
- String[] config = AbstractPublisherAction.parseConfigSpec(configSpec);
- File result = new File(executablesFeatureLocation, "bin/" + config[0] + "/" + config[1] + "/" + config[2]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (!result.exists())
- return null;
- return new ExecutablesDescriptor(config[1], "launcher", result, new File[] {result}); //$NON-NLS-1$
- }
-
- /**
- * Create an executable descriptor based on the given location, os and name.
- * This method is typically used to identify the executable related files in existing
- * unmanaged configurations.
- * @param os
- * @param location
- * @param executable
- * @return the created descriptor
- */
- public static ExecutablesDescriptor createDescriptor(String os, String executable, File location) {
- if (Constants.OS_MACOSX.equals(os))
- return createMacDescriptor(os, executable, location);
-
- // if it is not Mac and not Windows it must be a UNIX flavor
- if (!Constants.OS_WIN32.equals(os))
- return createUnixDescriptor(os, executable, location);
-
- // Nothing else so it must be Windows
- return createWindowsDescriptor(os, executable, location);
- }
-
- private static ExecutablesDescriptor createWindowsDescriptor(String os, String executable, File location) {
- ExecutablesDescriptor result = new ExecutablesDescriptor(os, executable, location, null);
- File file = new File(location, executable + ".exe"); //$NON-NLS-1$
- if (file.isFile()) {
- result.addFile(file);
- result.iniFile = new File(location, executable + ".ini"); //$NON-NLS-1$
- }
- file = new File(location, "eclipsec.exe"); //$NON-NLS-1$
- if (file.isFile())
- result.addFile(file);
- return result;
- }
-
- private static ExecutablesDescriptor createUnixDescriptor(String os, String executable, File location) {
- ExecutablesDescriptor result = new ExecutablesDescriptor(os, executable, location, null);
- File[] files = location.listFiles();
- for (int i = 0; files != null && i < files.length; i++) {
- String extension = new Path(files[i].getName()).getFileExtension();
- if (files[i].isFile() && (extension == null || extension.equals("so"))) //$NON-NLS-1$
- result.addFile(files[i]);
- }
- result.iniFile = new File(location, executable + ".ini"); //$NON-NLS-1$
- return result;
- }
-
- private static ExecutablesDescriptor createMacDescriptor(String os, String executable, File location) {
- File files[] = location.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- int length = name.length();
- return length > 3 && name.substring(length - 4, length).equalsIgnoreCase(".app"); //$NON-NLS-1$
- }
- });
- ExecutablesDescriptor result = new ExecutablesDescriptor(os, executable, location, files);
- result.iniFile = new File(location, executable + ".ini"); //$NON-NLS-1$
- return result;
- }
-
- public ExecutablesDescriptor(String os, String executable, File location, File[] files) {
- this.os = os;
- this.executableName = executable;
- this.location = location;
- if (files == null)
- this.files = new HashSet<File>(11);
- else {
- this.files = new HashSet<File>(files.length);
- for (int i = 0; i < files.length; i++)
- addAllFiles(files[i]);
- }
- }
-
- public ExecutablesDescriptor(ExecutablesDescriptor descriptor) {
- this.os = descriptor.os;
- this.location = descriptor.location;
- this.executableName = descriptor.executableName;
- this.temporary = descriptor.temporary;
- this.files = new HashSet<File>(descriptor.files);
- }
-
- public void addAllFiles(File file) {
- if (file.isFile())
- files.add(relativize(file));
- else {
- File absolute = file.isAbsolute() ? file : new File(location, file.getPath());
- File[] list = absolute.listFiles();
- for (int i = 0; i < list.length; i++)
- addAllFiles(list[i]);
- }
- }
-
- public void addFile(File file) {
- files.add(relativize(file));
- }
-
- // do a simple relativization by removing all the bits before the location
- private File relativize(File file) {
- if (!file.isAbsolute())
- return file;
- String path = file.getPath();
- if (!path.startsWith(location.getPath()))
- throw new IllegalArgumentException(file.toString() + " must be related to " + location); //$NON-NLS-1$
- path = path.substring(location.getPath().length());
- // trim off any separator. This accomodates people who set the location with a trailing /
- if (path.startsWith("/") || path.startsWith("\\")) //$NON-NLS-1$//$NON-NLS-2$
- path = path.substring(1);
- return new File(path);
- }
-
- public void removeFile(File file) {
- files.remove(relativize(file));
- }
-
- public void replace(File oldFile, File newFile) {
- removeFile(oldFile);
- addFile(newFile);
- }
-
- public File[] getFiles() {
- File[] result = files.toArray(new File[files.size()]);
- for (int i = 0; i < result.length; i++)
- result[i] = new File(location, result[i].getPath());
- return result;
- }
-
- public String getExecutableName() {
- return executableName;
- }
-
- public File getExecutable() {
- return findExecutable(os, location, executableName);
- }
-
- public File getIniLocation() {
- return iniFile;
- }
-
- public File getLocation() {
- return location;
- }
-
- public void setLocation(File value) {
- location = value;
- }
-
- public boolean isTemporary() {
- return temporary;
- }
-
- public void setExecutableName(String value, boolean updateFiles) {
- if (updateFiles)
- updateExecutableName(value);
- executableName = value;
- }
-
- public void makeTemporaryCopy() {
- if (isTemporary())
- return;
- File tempFile = null;
- try {
- tempFile = File.createTempFile("p2.brandingIron", ""); //$NON-NLS-1$ //$NON-NLS-2$
- tempFile.delete();
- for (File file : files)
- FileUtils.copy(location, tempFile, file, true);
- } catch (IOException e) {
- LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error publishing artifacts", e)); //$NON-NLS-1$
- }
- location = tempFile;
- temporary = true;
- }
-
- /**
- * If the executable represented by this descriptor has been branded then a mess
- * of files have been renamed. Here scan the descriptor's file list and update the names
- * taking into account the different layout on different OSes.
- * @param newName the new name of the executable.
- */
- private void updateExecutableName(String newName) {
- if (newName.equalsIgnoreCase(executableName))
- return;
- String targetIni = executableName + ".ini"; //$NON-NLS-1$
- String targetExecutable = executableName;
- String executableExtension = Constants.OS_WIN32.equals(os) ? ".exe" : ""; //$NON-NLS-1$ //$NON-NLS-2$
- targetExecutable = executableName + executableExtension;
- Set<File> filesCopy = new HashSet<File>(files);
- for (File file : filesCopy) {
- String base = file.getParent();
-
- // use String concatenation here because new File("", "foo") is absolute on at least windows...
- base = base == null ? "" : base + "/"; //$NON-NLS-1$ //$NON-NLS-2$
- if (Constants.OS_MACOSX.equals(os) && base.startsWith(executableName + ".app")) //$NON-NLS-1$
- base = newName + ".app" + base.substring(executableName.length() + 4); //$NON-NLS-1$
- if (file.getName().equalsIgnoreCase(targetExecutable))
- replace(file, new File(base + newName + executableExtension));
- else if (file.getName().equalsIgnoreCase(targetIni))
- replace(file, new File(base + newName + ".ini")); //$NON-NLS-1$
- else if (Constants.OS_MACOSX.equals(os))
- replace(file, new File(base + file.getName()));
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureManifestParser.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureManifestParser.java
deleted file mode 100644
index 3e51ed23a..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureManifestParser.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * Cloudsmith Inc - split into FeatureParser and FeatureManifestParser
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.*;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.parsers.*;
-import org.eclipse.equinox.p2.publisher.eclipse.Feature;
-import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;
-import org.eclipse.osgi.util.NLS;
-import org.xml.sax.*;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Parses a feature manifest from a provided stream.
- */
-public class FeatureManifestParser extends DefaultHandler {
-
- private final static SAXParserFactory parserFactory = SAXParserFactory.newInstance();
- private SAXParser parser;
- protected Feature result;
- private URL url;
- private StringBuffer characters = null;
-
- private List<String> messageKeys = new ArrayList<String>();
-
- public FeatureManifestParser() {
- this(true);
- }
-
- public FeatureManifestParser(boolean createParser) {
- super();
- if (!createParser)
- return;
- try {
- parserFactory.setNamespaceAware(true);
- this.parser = parserFactory.newSAXParser();
- } catch (ParserConfigurationException e) {
- System.out.println(e);
- } catch (SAXException e) {
- System.out.println(e);
- }
- }
-
- public void characters(char[] ch, int start, int length) {
- if (characters == null)
- return;
- characters.append(ch, start, length);
- }
-
- protected Feature createFeature(String id, String version) {
- return new Feature(id, version);
- }
-
- public void endElement(String uri, String localName, String qName) {
- if (characters == null)
- return;
- if ("description".equals(localName)) { //$NON-NLS-1$
- result.setDescription(localize(characters.toString().trim()));
- } else if ("license".equals(localName)) { //$NON-NLS-1$
- result.setLicense(localize(characters.toString().trim()));
- } else if ("copyright".equals(localName)) { //$NON-NLS-1$
- result.setCopyright(localize(characters.toString().trim()));
- }
- characters = null;
- }
-
- public Feature getResult() {
- return result;
- }
-
- private String localize(String value) {
- if (value != null && value.startsWith("%")) { //$NON-NLS-1$
- String key = value.substring(1);
- messageKeys.add(key);
- }
- return value;
- }
-
- /**
- * Parse the given input stream and return a feature object
- * or null.
- */
- public Feature parse(InputStream in) {
- result = null;
- try {
- parser.parse(new InputSource(in), this);
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return result;
- }
-
- public List<String> getMessageKeys() {
- return messageKeys;
- }
-
- private void processCopyright(Attributes attributes) {
- result.setCopyrightURL(attributes.getValue("url")); //$NON-NLS-1$
- characters = new StringBuffer();
- }
-
- private void processDescription(Attributes attributes) {
- result.setDescriptionURL(attributes.getValue("url")); //$NON-NLS-1$
- characters = new StringBuffer();
- }
-
- private void processDiscoverySite(Attributes attributes) {
- //ignore discovery sites of type 'web'
- if ("web".equals(attributes.getValue("type"))) //$NON-NLS-1$ //$NON-NLS-2$
- return;
- result.addDiscoverySite(attributes.getValue("label"), attributes.getValue("url")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected void processFeature(Attributes attributes) {
- String id = attributes.getValue("id"); //$NON-NLS-1$
- String ver = attributes.getValue("version"); //$NON-NLS-1$
-
- if (id == null || id.trim().equals("") //$NON-NLS-1$
- || ver == null || ver.trim().equals("")) { //$NON-NLS-1$
- // System.out.println(NLS.bind(Messages.FeatureParser_IdOrVersionInvalid, (new String[] { id, ver})));
- } else {
- result = createFeature(id, ver);
-
- String os = attributes.getValue("os"); //$NON-NLS-1$
- String ws = attributes.getValue("ws"); //$NON-NLS-1$
- String nl = attributes.getValue("nl"); //$NON-NLS-1$
- String arch = attributes.getValue("arch"); //$NON-NLS-1$
- result.setEnvironment(os, ws, arch, nl);
-
- result.setApplication(attributes.getValue("application")); //$NON-NLS-1$
- result.setPlugin(attributes.getValue("plugin")); //$NON-NLS-1$
- result.setExclusive(Boolean.valueOf(attributes.getValue("exclusive")).booleanValue()); //$NON-NLS-1$
- result.setPrimary(Boolean.valueOf(attributes.getValue("primary")).booleanValue()); //$NON-NLS-1$
- result.setColocationAffinity(attributes.getValue("colocation-affinity")); //$NON-NLS-1$
-
- //TODO rootURLs
- if (url != null && "file".equals(url.getProtocol())) { //$NON-NLS-1$
- File f = new File(url.getFile().replace('/', File.separatorChar));
- result.setURL("features" + "/" + f.getParentFile().getName() + "/");// + f.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else {
- // externalized URLs might be in relative form, ensure they are absolute
- // feature.setURL(Utils.makeAbsolute(Utils.getInstallURL(), url).toExternalForm());
- }
-
- result.setProviderName(localize(attributes.getValue("provider-name"))); //$NON-NLS-1$
- result.setLabel(localize(attributes.getValue("label"))); //$NON-NLS-1$
- result.setImage(attributes.getValue("image")); //$NON-NLS-1$
-
- // Utils.debug("End process DefaultFeature tag: id:" +id + " ver:" +ver + " url:" + feature.getURL()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
-
- private void processImport(Attributes attributes) {
- String id = attributes.getValue("feature"); //$NON-NLS-1$
- FeatureEntry entry = null;
- if (id != null) {
- if ("true".equalsIgnoreCase(attributes.getValue("patch"))) { //$NON-NLS-1$ //$NON-NLS-2$
- entry = FeatureEntry.createRequires(id, attributes.getValue("version"), "perfect", attributes.getValue("filter"), false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- entry.setPatch(true);
- } else {
- entry = FeatureEntry.createRequires(id, attributes.getValue("version"), attributes.getValue("match"), attributes.getValue("filter"), false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- } else {
- id = attributes.getValue("plugin"); //$NON-NLS-1$
- entry = FeatureEntry.createRequires(id, attributes.getValue("version"), attributes.getValue("match"), attributes.getValue("filter"), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- result.addEntry(entry);
- }
-
- private void processIncludes(Attributes attributes) {
- FeatureEntry entry = new FeatureEntry(attributes.getValue("id"), attributes.getValue("version"), false); //$NON-NLS-1$ //$NON-NLS-2$
- String flag = attributes.getValue("optional"); //$NON-NLS-1$
- if (flag != null)
- entry.setOptional(Boolean.valueOf(flag).booleanValue());
- setEnvironment(attributes, entry);
- String filter = attributes.getValue("filter"); //$NON-NLS-1$
- if (filter != null)
- entry.setFilter(filter);
- result.addEntry(entry);
- }
-
- private void processInstallHandler(Attributes attributes) {
- result.setInstallHandler(attributes.getValue("handler")); //$NON-NLS-1$
- result.setInstallHandlerLibrary(attributes.getValue("library")); //$NON-NLS-1$
- result.setInstallHandlerURL(attributes.getValue("url")); //$NON-NLS-1$
- }
-
- private void processLicense(Attributes attributes) {
- result.setLicenseURL(attributes.getValue("url")); //$NON-NLS-1$
- characters = new StringBuffer();
- }
-
- private void processPlugin(Attributes attributes) {
- String id = attributes.getValue("id"); //$NON-NLS-1$
- String version = attributes.getValue("version"); //$NON-NLS-1$
-
- if (id == null || id.trim().equals("") || version == null || version.trim().equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println(NLS.bind("FeatureParser#processPlugin, ID {0} or version {1} invalid", (new String[] {id, version}))); //$NON-NLS-1$
- } else {
- FeatureEntry plugin = new FeatureEntry(id, version, true);
- setEnvironment(attributes, plugin);
- String unpack = attributes.getValue("unpack"); //$NON-NLS-1$
- if (unpack != null)
- plugin.setUnpack(Boolean.valueOf(unpack).booleanValue());
- String fragment = attributes.getValue("fragment"); //$NON-NLS-1$
- if (fragment != null)
- plugin.setFragment(Boolean.valueOf(fragment).booleanValue());
- String filter = attributes.getValue("filter"); //$NON-NLS-1$
- if (filter != null)
- plugin.setFilter(filter);
- result.addEntry(plugin);
-
- // Utils.debug("End process DefaultFeature tag: id:" + id + " ver:" + ver + " url:" + feature.getURL()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
-
- private void processUpdateSite(Attributes attributes) {
- result.setUpdateSiteLabel(attributes.getValue("label")); //$NON-NLS-1$
- result.setUpdateSiteURL(attributes.getValue("url")); //$NON-NLS-1$
- }
-
- private void setEnvironment(Attributes attributes, FeatureEntry entry) {
- String os = attributes.getValue("os"); //$NON-NLS-1$
- String ws = attributes.getValue("ws"); //$NON-NLS-1$
- String nl = attributes.getValue("nl"); //$NON-NLS-1$
- String arch = attributes.getValue("arch"); //$NON-NLS-1$
- entry.setEnvironment(os, ws, arch, nl);
- }
-
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- // Utils.debug("Start Element: uri:" + uri + " local Name:" + localName + " qName:" + qName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if ("plugin".equals(localName)) { //$NON-NLS-1$
- processPlugin(attributes);
- } else if ("description".equals(localName)) { //$NON-NLS-1$
- processDescription(attributes);
- } else if ("license".equals(localName)) { //$NON-NLS-1$
- processLicense(attributes);
- } else if ("copyright".equals(localName)) { //$NON-NLS-1$
- processCopyright(attributes);
- } else if ("feature".equals(localName)) { //$NON-NLS-1$
- processFeature(attributes);
- } else if ("import".equals(localName)) { //$NON-NLS-1$
- processImport(attributes);
- } else if ("includes".equals(localName)) { //$NON-NLS-1$
- processIncludes(attributes);
- } else if ("install-handler".equals(localName)) { //$NON-NLS-1$
- processInstallHandler(attributes);
- } else if ("update".equals(localName)) { //$NON-NLS-1$
- processUpdateSite(attributes);
- } else if ("discovery".equals(localName)) { //$NON-NLS-1$
- processDiscoverySite(attributes);
- }
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureParser.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureParser.java
deleted file mode 100644
index 08fd6a805..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/FeatureParser.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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
- * Cloudsmith Inc - split into FeatureParser and FeatureManifestParser
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.*;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.publisher.Activator;
-import org.eclipse.equinox.p2.publisher.eclipse.Feature;
-import org.eclipse.equinox.spi.p2.publisher.LocalizationHelper;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * The publisher feature parser. This class parses a feature either in jar or folder
- * form. Feature localization data (feature.properties) is also processed here.
- */
-public class FeatureParser extends DefaultHandler {
-
- private FeatureManifestParser parser = new FeatureManifestParser();
-
- /**
- * Parses the specified location and constructs a feature. The given location
- * should be either the location of the feature JAR or the directory containing
- * the feature.
- *
- * @param location the location of the feature to parse.
- */
- public Feature parse(File location) {
- if (!location.exists())
- return null;
-
- Feature feature = null;
- if (location.isDirectory()) {
- //skip directories that don't contain a feature.xml file
- File file = new File(location, "feature.xml"); //$NON-NLS-1$
- InputStream input = null;
- try {
- input = new BufferedInputStream(new FileInputStream(file));
- feature = parser.parse(input);
- if (feature != null) {
- List<String> messageKeys = parser.getMessageKeys();
- String[] keyStrings = messageKeys.toArray(new String[messageKeys.size()]);
- feature.setLocalizations(LocalizationHelper.getDirPropertyLocalizations(location, "feature", null, keyStrings)); //$NON-NLS-1$
- }
- } catch (FileNotFoundException e) {
- return null;
- } finally {
- if (input != null)
- try {
- input.close();
- } catch (IOException e) {
- //
- }
- }
- } else if (location.getName().endsWith(".jar")) { //$NON-NLS-1$
- JarFile jar = null;
- try {
- jar = new JarFile(location);
- JarEntry entry = jar.getJarEntry("feature.xml"); //$NON-NLS-1$
- if (entry == null)
- return null;
-
- InputStream input = new BufferedInputStream(jar.getInputStream(entry));
- feature = parser.parse(input);
- if (feature != null) {
- List<String> messageKeys = parser.getMessageKeys();
- String[] keyStrings = messageKeys.toArray(new String[messageKeys.size()]);
- feature.setLocalizations(LocalizationHelper.getJarPropertyLocalizations(location, "feature", null, keyStrings)); //$NON-NLS-1$
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- LogHelper.log(new Status(IStatus.WARNING, Activator.ID, "Exception parsing feature: " + location.getAbsolutePath(), e)); //$NON-NLS-1$
- } finally {
- try {
- if (jar != null)
- jar.close();
- } catch (IOException e) {
- //
- }
- }
- }
- return feature;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java
deleted file mode 100644
index 4c55a27f0..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/GeneratorBundleInfo.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 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.internal.p2.publisher.eclipse;
-
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-
-public class GeneratorBundleInfo extends BundleInfo {
- private IInstallableUnit iu = null;
- private String specialConfigCommands;
- private String specialUnconfigCommands;
-
- public GeneratorBundleInfo(BundleInfo bInfo) {
- super.setBundleId(bInfo.getBundleId());
- super.setLocation(bInfo.getLocation());
- super.setManifest(bInfo.getManifest());
- super.setMarkedAsStarted(bInfo.isMarkedAsStarted());
- super.setResolved(bInfo.isResolved());
- super.setStartLevel(bInfo.getStartLevel());
- super.setSymbolicName(bInfo.getSymbolicName());
- super.setVersion(bInfo.getVersion());
- }
-
- public GeneratorBundleInfo() {
- super();
- }
-
- public String getSpecialConfigCommands() {
- return specialConfigCommands;
- }
-
- public void setSpecialConfigCommands(String specialConfigCommands) {
- this.specialConfigCommands = specialConfigCommands;
- }
-
- public void setIU(IInstallableUnit iu) {
- this.iu = iu;
- }
-
- public IInstallableUnit getIU() {
- return iu;
- }
-
- public String getSpecialUnconfigCommands() {
- return specialUnconfigCommands;
- }
-
- public void setSpecialUnconfigCommands(String specialUnconfigCommands) {
- this.specialUnconfigCommands = specialUnconfigCommands;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- String superSt = super.toString();
- if (superSt.length() > 0)
- buffer.append(superSt.substring(0, superSt.length() - 1));
- buffer.append(", this.specialConfigCommands="); //$NON-NLS-1$
- buffer.append(this.specialConfigCommands);
- buffer.append(')');
- return buffer.toString();
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/IProductDescriptor.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/IProductDescriptor.java
deleted file mode 100644
index d37be68f6..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/IProductDescriptor.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Code 9 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:
- * Code 9 - initial API and implementation
- * EclipseSource - ongoing development
- ******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-import org.eclipse.equinox.p2.metadata.IVersionedId;
-
-/**
- * Represents a product file.
- *
- * If getLocation returns null, then config.ini and p2 advice files cannot
- * be used (since these are both relative to the product location).
- *
- */
-public interface IProductDescriptor {
-
- /**
- * Gets the name of the launcher.
- */
- public String getLauncherName();
-
- /**
- * Returns the list of all bundles in this product.
- * @param includeFragments whether or not to include the fragments in the return value
- * @return the list of bundles in this product
- */
- public List<IVersionedId> getBundles(boolean includeFragments);
-
- /**
- * Returns a list<VersionedName> of fragments that constitute this product.
- */
- public List<IVersionedId> getFragments();
-
- /**
- * Returns a List<VersionedName> of features that constitute this product.
- */
- public List<IVersionedId> getFeatures();
-
- /**
- * Returns the path to the config.ini file as specified in the .product file.
- */
- public String getConfigIniPath(String os);
-
- /**
- * Returns the ID for this product.
- */
- public String getId();
-
- /**
- * Returns the Product extension point ID
- */
- public String getProductId();
-
- /**
- * Returns the Applicaiton extension point ID
- */
- public String getApplication();
-
- /**
- * Returns the ID of the bundle in which the splash screen resides.
- */
- public String getSplashLocation();
-
- /**
- * Returns the name of the product
- */
- public String getProductName();
-
- /**
- * Specifies whether this product was built using features or not.
- */
- public boolean useFeatures();
-
- /**
- * Returns the version of the product.
- */
- public String getVersion();
-
- /**
- * Returns the VM arguments for this product for a given OS.
- */
- public String getVMArguments(String os);
-
- /**
- * Returns the program arguments for this product for a given OS.
- */
- public String getProgramArguments(String os);
-
- /**
- * Returns the properties for a product file.
- */
- public Map<String, String> getConfigurationProperties();
-
- /**
- * Returns a list of icons for this product for a given OS.
- */
- public String[] getIcons(String os);
-
- /**
- * Returns a List<BundleInfo> for each bundle that has custom configuration data.
- * @return A List<BundleInfo>
- */
- public List<BundleInfo> getBundleInfos();
-
- /**
- * This is needed for config.ini files and p2 advice
- */
- public File getLocation();
-
- /**
- * Determines if the launchers should be included in the published product
- */
- public boolean includeLaunchers();
-
- /**
- * Returns the license URL for this product
- */
- public String getLicenseURL();
-
- /**
- * Returns the license text for this product
- */
- public String getLicenseText();
-
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ProductFile.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ProductFile.java
deleted file mode 100644
index a0b6498df..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/eclipse/ProductFile.java
+++ /dev/null
@@ -1,768 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 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
- * Code 9 - Additional function and fixes
- * EclipseSource - ongoing development
- *******************************************************************************/
-
-package org.eclipse.equinox.internal.p2.publisher.eclipse;
-
-import java.io.*;
-import java.util.*;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.equinox.frameworkadmin.BundleInfo;
-import org.eclipse.equinox.internal.p2.core.helpers.*;
-import org.eclipse.equinox.internal.p2.publisher.Activator;
-import org.eclipse.equinox.p2.metadata.IVersionedId;
-import org.eclipse.equinox.p2.metadata.VersionedId;
-import org.eclipse.osgi.service.datalocation.Location;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Used to parse a .product file.
- */
-public class ProductFile extends DefaultHandler implements IProductDescriptor {
- private static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
- private static final String ATTRIBUTE_ICON = "icon"; //$NON-NLS-1$
- protected static final String ATTRIBUTE_FRAGMENT = "fragment"; //$NON-NLS-1$
- private static final String ATTRIBUTE_APPLICATION = "application"; //$NON-NLS-1$
- private static final String ATTRIBUTE_INCLUDE_LAUNCHERS = "includeLaunchers"; //$NON-NLS-1$
- private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
- private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
- private static final String ATTRIBUTE_LOCATION = "location"; //$NON-NLS-1$
- private static final String ATTRIBUTE_AUTO_START = "autoStart"; //$NON-NLS-1$
- private static final String ATTRIBUTE_START_LEVEL = "startLevel"; //$NON-NLS-1$
- protected static final String ATTRIBUTE_VERSION = "version"; //$NON-NLS-1$
- protected static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
- private static final String ATTRIBUTE_UID = "uid"; //$NON-NLS-1$
-
- private static final String PROPERTY_ECLIPSE_APPLICATION = "eclipse.application"; //$NON-NLS-1$
- private static final String PROPERTY_ECLIPSE_PRODUCT = "eclipse.product"; //$NON-NLS-1$
-
- private final static SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-
- private static final String PROGRAM_ARGS = "programArgs"; //$NON-NLS-1$
- private static final String PROGRAM_ARGS_LINUX = "programArgsLin"; //$NON-NLS-1$
- private static final String PROGRAM_ARGS_MAC = "programArgsMac"; //$NON-NLS-1$
- private static final String PROGRAM_ARGS_SOLARIS = "programArgsSol"; //$NON-NLS-1$
- private static final String PROGRAM_ARGS_WIN = "programArgsWin"; //$NON-NLS-1$
- private static final String VM_ARGS = "vmArgs"; //$NON-NLS-1$
- private static final String VM_ARGS_LINUX = "vmArgsLin"; //$NON-NLS-1$
- private static final String VM_ARGS_MAC = "vmArgsMac"; //$NON-NLS-1$
- private static final String VM_ARGS_SOLARIS = "vmArgsSol"; //$NON-NLS-1$
- private static final String VM_ARGS_WIN = "vmArgsWin"; //$NON-NLS-1$
-
- private static final String SOLARIS_LARGE = "solarisLarge"; //$NON-NLS-1$
- private static final String SOLARIS_MEDIUM = "solarisMedium"; //$NON-NLS-1$
- private static final String SOLARIS_SMALL = "solarisSmall"; //$NON-NLS-1$
- private static final String SOLARIS_TINY = "solarisTiny"; //$NON-NLS-1$
- private static final String WIN32_16_LOW = "winSmallLow"; //$NON-NLS-1$
- private static final String WIN32_16_HIGH = "winSmallHigh"; //$NON-NLS-1$
- private static final String WIN32_24_LOW = "win24Low"; //$NON-NLS-1$
- private static final String WIN32_32_LOW = "winMediumLow"; //$NON-NLS-1$
- private static final String WIN32_32_HIGH = "winMediumHigh"; //$NON-NLS-1$
- private static final String WIN32_48_LOW = "winLargeLow"; //$NON-NLS-1$
- private static final String WIN32_48_HIGH = "winLargeHigh"; //$NON-NLS-1$
-
- private static final String OS_WIN32 = "win32";//$NON-NLS-1$
- private static final String OS_LINUX = "linux";//$NON-NLS-1$
- private static final String OS_SOLARIS = "solaris";//$NON-NLS-1$
- private static final String OS_MACOSX = "macosx";//$NON-NLS-1$
-
- //element names
- private static final String EL_FEATURES = "features"; //$NON-NLS-1$
- private static final String EL_FEATURE = "feature"; //$NON-NLS-1$
- private static final String EL_PLUGINS = "plugins"; //$NON-NLS-1$
- private static final String EL_PLUGIN = "plugin"; //$NON-NLS-1$
- private static final String EL_PRODUCT = "product"; //$NON-NLS-1$
- private static final String EL_PROPERTY = "property"; //$NON-NLS-1$
- private static final String EL_CONFIG_INI = "configIni"; //$NON-NLS-1$
- private static final String EL_LAUNCHER = "launcher"; //$NON-NLS-1$
- private static final String EL_LAUNCHER_ARGS = "launcherArgs"; //$NON-NLS-1$
- private static final String EL_SPLASH = "splash"; //$NON-NLS-1$
- private static final String EL_CONFIGURATIONS = "configurations"; //$NON-NLS-1$
- private static final String EL_LICENSE = "license"; //$NON-NLS-1$
- private static final String EL_URL = "url"; //$NON-NLS-1$
- private static final String EL_TEXT = "text"; //$NON-NLS-1$
-
- //These constants form a small state machine to parse the .product file
- private static final int STATE_START = 0;
- private static final int STATE_PRODUCT = 1;
- private static final int STATE_LAUNCHER = 2;
- private static final int STATE_LAUNCHER_ARGS = 3;
- private static final int STATE_PLUGINS = 4;
- private static final int STATE_FEATURES = 5;
- private static final int STATE_PROGRAM_ARGS = 6;
- private static final int STATE_PROGRAM_ARGS_LINUX = 7;
- private static final int STATE_PROGRAM_ARGS_MAC = 8;
- private static final int STATE_PROGRAM_ARGS_SOLARIS = 9;
- private static final int STATE_PROGRAM_ARGS_WIN = 10;
- private static final int STATE_VM_ARGS = 11;
- private static final int STATE_VM_ARGS_LINUX = 12;
- private static final int STATE_VM_ARGS_MAC = 13;
- private static final int STATE_VM_ARGS_SOLARIS = 14;
- private static final int STATE_VM_ARGS_WIN = 15;
- private static final int STATE_CONFIG_INI = 16;
- private static final int STATE_CONFIGURATIONS = 17;
- private static final int STATE_LICENSE = 18;
- private static final int STATE_LICENSE_URL = 19;
- private static final int STATE_LICENSE_TEXT = 20;
-
- private int state = STATE_START;
-
- private SAXParser parser;
- private String launcherName = null;
- // private boolean useIco = false;
- private Map<String, Collection<String>> icons = new HashMap<String, Collection<String>>(6);
- private String configPath = null;
- private final Map<String, String> platformSpecificConfigPaths = new HashMap<String, String>();
- private String configPlatform = null;
- private String platformConfigPath = null;
- private String id = null;
- private String uid = null;
- private boolean useFeatures = false;
- protected List<IVersionedId> plugins = null;
- protected List<IVersionedId> fragments = null;
- private List<IVersionedId> features = null;
- private String splashLocation = null;
- private String productName = null;
- private String application = null;
- private String version = null;
- private Properties launcherArgs = new Properties();
- private File location;
- private List<BundleInfo> bundleInfos;
- private Map<String, String> properties;
- private boolean includeLaunchers = true;
- private String licenseURL;
- private String licenseText = null;
-
- private static String normalize(String text) {
- if (text == null || text.trim().length() == 0)
- return ""; //$NON-NLS-1$
-
- StringBuffer result = new StringBuffer(text.length());
- boolean haveSpace = false;
- for (int i = 0; i < text.length(); i++) {
- char c = text.charAt(i);
- if (Character.isWhitespace(c)) {
- if (haveSpace)
- continue;
- haveSpace = true;
- result.append(" "); //$NON-NLS-1$
- } else {
- haveSpace = false;
- result.append(c);
- }
- }
- return result.toString();
- }
-
- /**
- * Constructs a product file parser.
- */
- public ProductFile(String location) throws Exception {
- super();
- this.location = new File(location);
-
- parserFactory.setNamespaceAware(true);
- parser = parserFactory.newSAXParser();
- InputStream in = new BufferedInputStream(new FileInputStream(location));
- try {
- parser.parse(new InputSource(in), this);
- } finally {
- if (in != null)
- in.close();
- }
- parser = null;
- }
-
- /**
- * Gets the name of the launcher specified in the .product file.
- */
- public String getLauncherName() {
- return launcherName;
- }
-
- /**
- * Gets the location of the .product file.
- */
- public File getLocation() {
- return location;
- }
-
- /**
- * Returns the properties found in .product file. Properties
- * are located in the <configurations> block of the file
- */
- public Map<String, String> getConfigurationProperties() {
- Map<String, String> result = properties != null ? properties : new HashMap<String, String>();
- if (application != null && !result.containsKey(PROPERTY_ECLIPSE_APPLICATION))
- result.put(PROPERTY_ECLIPSE_APPLICATION, application);
- if (id != null && !result.containsKey(PROPERTY_ECLIPSE_PRODUCT))
- result.put(PROPERTY_ECLIPSE_PRODUCT, id);
-
- return result;
- }
-
- /**
- * Returns a List<VersionedName> for each bundle that makes up this product.
- * @param includeFragments Indicates whether or not fragments should
- * be included in the list
- */
- public List<IVersionedId> getBundles(boolean includeFragments) {
- List<IVersionedId> p = plugins != null ? plugins : CollectionUtils.<IVersionedId> emptyList();
- if (!includeFragments)
- return p;
-
- List<IVersionedId> f = fragments != null ? fragments : CollectionUtils.<IVersionedId> emptyList();
- int size = p.size() + f.size();
- if (size == 0)
- return CollectionUtils.emptyList();
-
- List<IVersionedId> both = new ArrayList<IVersionedId>(size);
- both.addAll(p);
- both.addAll(f);
- return both;
- }
-
- /**
- * Returns a List<BundleInfo> for each bundle that has custom configuration data
- * in the product file.
- * @return A List<BundleInfo>
- */
- public List<BundleInfo> getBundleInfos() {
- return bundleInfos != null ? bundleInfos : CollectionUtils.<BundleInfo> emptyList();
- }
-
- /**
- * Returns a list<VersionedName> of fragments that constitute this product.
- */
- public List<IVersionedId> getFragments() {
- return fragments != null ? fragments : CollectionUtils.<IVersionedId> emptyList();
- }
-
- /**
- * Returns a List<VersionedName> of features that constitute this product.
- */
- public List<IVersionedId> getFeatures() {
- return features != null ? features : CollectionUtils.<IVersionedId> emptyList();
- }
-
- public String[] getIcons(String os) {
- Collection<String> result = icons.get(os);
- if (result == null)
- return null;
- return result.toArray(new String[result.size()]);
- }
-
- public String getConfigIniPath(String os) {
- String specific = platformSpecificConfigPaths.get(os);
- return specific == null ? configPath : specific;
- }
-
- public String getConfigIniPath() {
- return configPath;
- }
-
- /**
- * Returns the ID for this product.
- */
- public String getId() {
- if (uid != null)
- return uid;
- return id;
- }
-
- public String getProductId() {
- return id;
- }
-
- /**
- * Returns the location (the bundle) that defines the splash screen
- */
- public String getSplashLocation() {
- return splashLocation;
- }
-
- /**
- * Returns the product name.
- */
- public String getProductName() {
- return productName;
- }
-
- /**
- * Returns the application identifier for this product.
- */
- public String getApplication() {
- return application;
- }
-
- /**
- * Returns true if this product is built using feature,
- * false otherwise.
- */
- public boolean useFeatures() {
- return useFeatures;
- }
-
- /**
- * Returns the version of the product
- */
- public String getVersion() {
- return (version == null || version.length() == 0) ? "0.0.0" : version; //$NON-NLS-1$
- }
-
- public boolean includeLaunchers() {
- return includeLaunchers;
- }
-
- /**
- * Returns the VM arguments for a specific platform.
- * If the empty string is used for the OS, this returns
- * the default VM arguments
- */
- public String getVMArguments(String os) {
- os = os == null ? "" : os; //$NON-NLS-1$
- String key = null;
- if (os.equals(OS_WIN32)) {
- key = VM_ARGS_WIN;
- } else if (os.equals(OS_LINUX)) {
- key = VM_ARGS_LINUX;
- } else if (os.equals(OS_MACOSX)) {
- key = VM_ARGS_MAC;
- } else if (os.equals(OS_SOLARIS)) {
- key = VM_ARGS_SOLARIS;
- }
-
- String prefix = launcherArgs.getProperty(VM_ARGS);
- String platform = null, args = null;
- if (key != null)
- platform = launcherArgs.getProperty(key);
- if (prefix != null)
- args = platform != null ? prefix + " " + platform : prefix; //$NON-NLS-1$
- else
- args = platform != null ? platform : ""; //$NON-NLS-1$
- return normalize(args);
- }
-
- /**
- * Returns the program arguments for a specific platform.
- * If the empty string is used for the OS, this returns
- * the default program arguments
- */
- public String getProgramArguments(String os) {
- os = os == null ? "" : os; //$NON-NLS-1$
- String key = null;
- if (os.equals(OS_WIN32)) {
- key = PROGRAM_ARGS_WIN;
- } else if (os.equals(OS_LINUX)) {
- key = PROGRAM_ARGS_LINUX;
- } else if (os.equals(OS_MACOSX)) {
- key = PROGRAM_ARGS_MAC;
- } else if (os.equals(OS_SOLARIS)) {
- key = PROGRAM_ARGS_SOLARIS;
- }
-
- String prefix = launcherArgs.getProperty(PROGRAM_ARGS);
- String platform = null, args = null;
- if (key != null)
- platform = launcherArgs.getProperty(key);
- if (prefix != null)
- args = platform != null ? prefix + " " + platform : prefix; //$NON-NLS-1$
- else
- args = platform != null ? platform : ""; //$NON-NLS-1$
- return normalize(args);
- }
-
- public String getLicenseText() {
- return licenseText;
- }
-
- public String getLicenseURL() {
- return licenseURL;
- }
-
- public void startElement(String uri, String localName, String qName, Attributes attributes) {
- switch (state) {
- case STATE_START :
- if (EL_PRODUCT.equals(localName)) {
- processProduct(attributes);
- state = STATE_PRODUCT;
- }
- break;
-
- case STATE_PRODUCT :
- if (EL_CONFIG_INI.equals(localName)) {
- processConfigIni(attributes);
- state = STATE_CONFIG_INI;
- } else if (EL_LAUNCHER.equals(localName)) {
- processLauncher(attributes);
- state = STATE_LAUNCHER;
- } else if (EL_PLUGINS.equals(localName)) {
- state = STATE_PLUGINS;
- } else if (EL_FEATURES.equals(localName)) {
- state = STATE_FEATURES;
- } else if (EL_LAUNCHER_ARGS.equals(localName)) {
- state = STATE_LAUNCHER_ARGS;
- } else if (EL_SPLASH.equals(localName)) {
- splashLocation = attributes.getValue(ATTRIBUTE_LOCATION);
- } else if (EL_CONFIGURATIONS.equals(localName)) {
- state = STATE_CONFIGURATIONS;
- } else if (EL_LICENSE.equals(localName)) {
- state = STATE_LICENSE;
- }
- break;
-
- case STATE_CONFIG_INI :
- processConfigIniPlatform(localName, true);
- break;
-
- case STATE_LAUNCHER :
- if (OS_SOLARIS.equals(localName)) {
- processSolaris(attributes);
- } else if ("win".equals(localName)) { //$NON-NLS-1$
- processWin(attributes);
- } else if (OS_LINUX.equals(localName)) {
- processLinux(attributes);
- } else if (OS_MACOSX.equals(localName)) {
- processMac(attributes);
- }
- if ("ico".equals(localName)) { //$NON-NLS-1$
- processIco(attributes);
- } else if ("bmp".equals(localName)) { //$NON-NLS-1$
- processBmp(attributes);
- }
- break;
-
- case STATE_LAUNCHER_ARGS :
- if (PROGRAM_ARGS.equals(localName)) {
- state = STATE_PROGRAM_ARGS;
- } else if (PROGRAM_ARGS_LINUX.equals(localName)) {
- state = STATE_PROGRAM_ARGS_LINUX;
- } else if (PROGRAM_ARGS_MAC.equals(localName)) {
- state = STATE_PROGRAM_ARGS_MAC;
- } else if (PROGRAM_ARGS_SOLARIS.equals(localName)) {
- state = STATE_PROGRAM_ARGS_SOLARIS;
- } else if (PROGRAM_ARGS_WIN.equals(localName)) {
- state = STATE_PROGRAM_ARGS_WIN;
- } else if (VM_ARGS.equals(localName)) {
- state = STATE_VM_ARGS;
- } else if (VM_ARGS_LINUX.equals(localName)) {
- state = STATE_VM_ARGS_LINUX;
- } else if (VM_ARGS_MAC.equals(localName)) {
- state = STATE_VM_ARGS_MAC;
- } else if (VM_ARGS_SOLARIS.equals(localName)) {
- state = STATE_VM_ARGS_SOLARIS;
- } else if (VM_ARGS_WIN.equals(localName)) {
- state = STATE_VM_ARGS_WIN;
- }
- break;
-
- case STATE_PLUGINS :
- if (EL_PLUGIN.equals(localName)) {
- processPlugin(attributes);
- }
- break;
-
- case STATE_LICENSE :
- if (EL_URL.equals(localName)) {
- state = STATE_LICENSE_URL;
- } else if (EL_TEXT.equals(localName)) {
- licenseText = ""; //$NON-NLS-1$
- state = STATE_LICENSE_TEXT;
- }
- break;
-
- case STATE_FEATURES :
- if (EL_FEATURE.equals(localName)) {
- processFeature(attributes);
- }
- break;
- case STATE_CONFIGURATIONS :
- if (EL_PLUGIN.equals(localName)) {
- processPluginConfiguration(attributes);
- } else if (EL_PROPERTY.equals(localName)) {
- processPropertyConfiguration(attributes);
- }
- break;
- }
- }
-
- /**
- * Processes the property tag in the .product file. These tags contain
- * a Name and Value pair. For each tag (with a non-null name), a property
- * is created.
- */
- private void processPropertyConfiguration(Attributes attributes) {
- String name = attributes.getValue(ATTRIBUTE_NAME);
- String value = attributes.getValue(ATTRIBUTE_VALUE);
- if (name == null)
- return;
- if (value == null)
- value = ""; //$NON-NLS-1$
- if (properties == null)
- properties = new HashMap<String, String>();
- properties.put(name, value);
- }
-
- private void processPluginConfiguration(Attributes attributes) {
- BundleInfo info = new BundleInfo();
- info.setSymbolicName(attributes.getValue(ATTRIBUTE_ID));
- info.setVersion(attributes.getValue(ATTRIBUTE_VERSION));
- String value = attributes.getValue(ATTRIBUTE_START_LEVEL);
- if (value != null) {
- int startLevel = Integer.parseInt(value);
- if (startLevel > 0)
- info.setStartLevel(startLevel);
- }
- value = attributes.getValue(ATTRIBUTE_AUTO_START);
- if (value != null)
- info.setMarkedAsStarted(Boolean.valueOf(value).booleanValue());
- if (bundleInfos == null)
- bundleInfos = new ArrayList<BundleInfo>();
- bundleInfos.add(info);
- }
-
- public void endElement(String uri, String localName, String qName) {
- switch (state) {
- case STATE_PLUGINS :
- if (EL_PLUGINS.equals(localName))
- state = STATE_PRODUCT;
- break;
- case STATE_FEATURES :
- if (EL_FEATURES.equals(localName))
- state = STATE_PRODUCT;
- break;
- case STATE_LAUNCHER_ARGS :
- if (EL_LAUNCHER_ARGS.equals(localName))
- state = STATE_PRODUCT;
- break;
- case STATE_LAUNCHER :
- if (EL_LAUNCHER.equals(localName))
- state = STATE_PRODUCT;
- break;
- case STATE_CONFIGURATIONS :
- if (EL_CONFIGURATIONS.equals(localName))
- state = STATE_PRODUCT;
- break;
- case STATE_LICENSE :
- if (EL_LICENSE.equals(localName))
- state = STATE_PRODUCT;
- break;
-
- case STATE_PROGRAM_ARGS :
- case STATE_PROGRAM_ARGS_LINUX :
- case STATE_PROGRAM_ARGS_MAC :
- case STATE_PROGRAM_ARGS_SOLARIS :
- case STATE_PROGRAM_ARGS_WIN :
- case STATE_VM_ARGS :
- case STATE_VM_ARGS_LINUX :
- case STATE_VM_ARGS_MAC :
- case STATE_VM_ARGS_SOLARIS :
- case STATE_VM_ARGS_WIN :
- state = STATE_LAUNCHER_ARGS;
- break;
- case STATE_LICENSE_URL :
- case STATE_LICENSE_TEXT :
- state = STATE_LICENSE;
- break;
-
- case STATE_CONFIG_INI :
- if (EL_CONFIG_INI.equals(localName))
- state = STATE_PRODUCT;
- else
- processConfigIniPlatform(localName, false);
- break;
- }
- }
-
- public void characters(char[] ch, int start, int length) {
- switch (state) {
- case STATE_PROGRAM_ARGS :
- addLaunchArgumentToMap(PROGRAM_ARGS, String.valueOf(ch, start, length));
- break;
- case STATE_PROGRAM_ARGS_LINUX :
- addLaunchArgumentToMap(PROGRAM_ARGS_LINUX, String.valueOf(ch, start, length));
- break;
- case STATE_PROGRAM_ARGS_MAC :
- addLaunchArgumentToMap(PROGRAM_ARGS_MAC, String.valueOf(ch, start, length));
- break;
- case STATE_PROGRAM_ARGS_SOLARIS :
- addLaunchArgumentToMap(PROGRAM_ARGS_SOLARIS, String.valueOf(ch, start, length));
- break;
- case STATE_PROGRAM_ARGS_WIN :
- addLaunchArgumentToMap(PROGRAM_ARGS_WIN, String.valueOf(ch, start, length));
- break;
- case STATE_VM_ARGS :
- addLaunchArgumentToMap(VM_ARGS, String.valueOf(ch, start, length));
- break;
- case STATE_VM_ARGS_LINUX :
- addLaunchArgumentToMap(VM_ARGS_LINUX, String.valueOf(ch, start, length));
- break;
- case STATE_VM_ARGS_MAC :
- addLaunchArgumentToMap(VM_ARGS_MAC, String.valueOf(ch, start, length));
- break;
- case STATE_VM_ARGS_SOLARIS :
- addLaunchArgumentToMap(VM_ARGS_SOLARIS, String.valueOf(ch, start, length));
- break;
- case STATE_VM_ARGS_WIN :
- addLaunchArgumentToMap(VM_ARGS_WIN, String.valueOf(ch, start, length));
- break;
- case STATE_CONFIG_INI :
- if (platformConfigPath != null)
- platformConfigPath += String.valueOf(ch, start, length);
- break;
- case STATE_LICENSE_URL :
- licenseURL = String.valueOf(ch, start, length);
- break;
- case STATE_LICENSE_TEXT :
- if (licenseText != null)
- licenseText += String.valueOf(ch, start, length);
- break;
-
- }
- }
-
- private void addLaunchArgumentToMap(String key, String value) {
- if (launcherArgs == null)
- launcherArgs = new Properties();
-
- String oldValue = launcherArgs.getProperty(key);
- if (oldValue != null)
- launcherArgs.setProperty(key, oldValue + value);
- else
- launcherArgs.setProperty(key, value);
- }
-
- protected void processPlugin(Attributes attributes) {
- String fragment = attributes.getValue(ATTRIBUTE_FRAGMENT);
- IVersionedId name = new VersionedId(attributes.getValue(ATTRIBUTE_ID), attributes.getValue(ATTRIBUTE_VERSION));
- if (fragment != null && new Boolean(fragment).booleanValue()) {
- if (fragments == null)
- fragments = new ArrayList<IVersionedId>();
- fragments.add(name);
- } else {
- if (plugins == null)
- plugins = new ArrayList<IVersionedId>();
- plugins.add(name);
- }
- }
-
- private void processFeature(Attributes attributes) {
- IVersionedId name = new VersionedId(attributes.getValue(ATTRIBUTE_ID), attributes.getValue(ATTRIBUTE_VERSION));
- if (features == null)
- features = new ArrayList<IVersionedId>();
- features.add(name);
- }
-
- private void processProduct(Attributes attributes) {
- id = attributes.getValue(ATTRIBUTE_ID);
- uid = attributes.getValue(ATTRIBUTE_UID);
- productName = attributes.getValue(ATTRIBUTE_NAME);
- application = attributes.getValue(ATTRIBUTE_APPLICATION);
- if (attributes.getIndex(ATTRIBUTE_INCLUDE_LAUNCHERS) >= 0)
- includeLaunchers = Boolean.valueOf(attributes.getValue(ATTRIBUTE_INCLUDE_LAUNCHERS));
- String use = attributes.getValue("useFeatures"); //$NON-NLS-1$
- if (use != null)
- useFeatures = Boolean.valueOf(use).booleanValue();
- version = attributes.getValue(ATTRIBUTE_VERSION);
- }
-
- private void processConfigIni(Attributes attributes) {
- String path = null;
- if ("custom".equals(attributes.getValue("use"))) { //$NON-NLS-1$//$NON-NLS-2$
- path = attributes.getValue(ATTRIBUTE_PATH);
- }
- String os = attributes.getValue("os"); //$NON-NLS-1$
- if (os != null && os.length() > 0) {
- // TODO should we allow a platform-specific default to over-ride a custom generic path?
- if (path != null)
- platformSpecificConfigPaths.put(os, path);
- } else if (path != null) {
- configPath = path;
- }
- }
-
- private void processConfigIniPlatform(String key, boolean begin) {
- if (begin) {
- configPlatform = key;
- platformConfigPath = ""; //$NON-NLS-1$
- } else if (configPlatform.equals(key) && platformConfigPath.length() > 0) {
- platformSpecificConfigPaths.put(key, platformConfigPath);
- platformConfigPath = null;
- }
- }
-
- private void processLauncher(Attributes attributes) {
- launcherName = attributes.getValue(ATTRIBUTE_NAME);
- }
-
- private void addIcon(String os, String value) {
- if (value == null)
- return;
-
- File iconFile = new File(value);
- if (!iconFile.isFile()) {
- //workspace
- Location instanceLocation = (Location) ServiceHelper.getService(Activator.getContext(), Location.class.getName(), Location.INSTANCE_FILTER);
- if (instanceLocation != null && instanceLocation.getURL() != null) {
- File workspace = URLUtil.toFile(instanceLocation.getURL());
- if (workspace != null)
- iconFile = new File(workspace, value);
- }
- }
- if (!iconFile.isFile())
- iconFile = new File(location.getParentFile(), value);
-
- Collection<String> list = icons.get(os);
- if (list == null) {
- list = new ArrayList<String>(6);
- icons.put(os, list);
- }
- list.add(iconFile.getAbsolutePath());
- }
-
- private void processSolaris(Attributes attributes) {
- addIcon(OS_SOLARIS, attributes.getValue(SOLARIS_LARGE));
- addIcon(OS_SOLARIS, attributes.getValue(SOLARIS_MEDIUM));
- addIcon(OS_SOLARIS, attributes.getValue(SOLARIS_SMALL));
- addIcon(OS_SOLARIS, attributes.getValue(SOLARIS_TINY));
- }
-
- private void processWin(Attributes attributes) {
- // useIco = Boolean.valueOf(attributes.getValue(P_USE_ICO)).booleanValue();
- }
-
- private void processIco(Attributes attributes) {
- addIcon(OS_WIN32, attributes.getValue(ATTRIBUTE_PATH));
- }
-
- private void processBmp(Attributes attributes) {
- addIcon(OS_WIN32, attributes.getValue(WIN32_16_HIGH));
- addIcon(OS_WIN32, attributes.getValue(WIN32_16_LOW));
- addIcon(OS_WIN32, attributes.getValue(WIN32_24_LOW));
- addIcon(OS_WIN32, attributes.getValue(WIN32_32_HIGH));
- addIcon(OS_WIN32, attributes.getValue(WIN32_32_LOW));
- addIcon(OS_WIN32, attributes.getValue(WIN32_48_HIGH));
- addIcon(OS_WIN32, attributes.getValue(WIN32_48_LOW));
- }
-
- private void processLinux(Attributes attributes) {
- addIcon(OS_LINUX, attributes.getValue(ATTRIBUTE_ICON));
- }
-
- private void processMac(Attributes attributes) {
- addIcon(OS_MACOSX, attributes.getValue(ATTRIBUTE_ICON));
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/swt/tools/IconExe.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/swt/tools/IconExe.java
deleted file mode 100644
index 6367a40b9..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/swt/tools/IconExe.java
+++ /dev/null
@@ -1,3339 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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.internal.p2.swt.tools;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * Customize the icon of a Windows exe
- *
- * WARNING! This class is not part of SWT API. It is NOT API. It is an internal
- * tool that may be changed or removed at anytime.
- *
- * Based on MSDN "An In-Depth Look into the Win32 Portable Executable File Format".
- *
- * Win x64 support (Bug #238001) based on MSDN "x64 Primer: Everything You Need To
- * Know To Start Programming 64-Bit Windows Systems".
- */
-public class IconExe {
-
- /**
- * Replace the Desktop icons provided in the Windows executable program
- * with matching icons provided by the user.
- *
- * Takes 2 arguments
- * argument 0: the Windows executable e.g c:/eclipse/eclipse.exe
- * argument 1: The .ico file to write to the given executable e.g. c:/myApp.ico
- *
- * Note 1. Write access to the executable program is required. As a result, that
- * program must not be currently running or edited elsewhere.
- *
- * Note 2. The Eclipse 3.4 launcher requires an .ico file with the following 7 images (in any order).
- * 1. 48x48, 32 bit (RGB / Alpha Channel)
- * 2. 32x32, 32 bit (RGB / Alpha Channel)
- * 3. 16x16, 32 bit (RGB / Alpha Channel)
- * 4. 48x48, 8 bit (256 colors)
- * 5. 32x32, 8 bit (256 colors)
- * 6. 24x24, 8 bit (256 colors)
- * 7. 16x16, 8 bit (256 colors)
- * A user icon matching exactly the width/height/depth of an executable icon will be written
- * to the executable and will replace that executable icon. If an executable icon
- * does not match a user icon, it is silently left as is.
- *
- * Note 3. This function modifies the content of the executable program and may cause
- * its corruption.
- */
- public static void main(String[] args) throws Exception {
- if (args.length < 2) {
- System.err.println("Usage: IconExe <windows executable> <ico file>"); //$NON-NLS-1$
- return;
- }
- ImageLoader loader = new ImageLoader();
-
- List<ImageData> images = new ArrayList<ImageData>();
- for (int i = 1; i < args.length; i++) {
- try {
- //An ICO should contain 7 images, a BMP will contain 1
- ImageData[] current = loader.load(args[i]);
- for (int j = 0; j < current.length; j++) {
- images.add(current[j]);
- }
- } catch (RuntimeException e) {
- //ignore so that we process the other images
- }
- }
- ImageData[] data = new ImageData[images.size()];
- data = images.toArray(data);
-
- int nMissing = unloadIcons(args[0], data);
- if (nMissing != 0)
- System.err.println("Error - " + nMissing + " icon(s) not replaced in " + args[0] + " using " + args[1]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /* Implementation */
-
- /**
- * Retrieve the Desktop icons provided in the Windows executable program.
- * These icons are typically shown in various places of the Windows desktop.
- *
- * Note. The Eclipse 3.4 launcher returns the following 7 images (in any order).
- * 1. 48x48, 32 bit (RGB / Alpha Channel)
- * 2. 32x32, 32 bit (RGB / Alpha Channel)
- * 3. 16x16, 32 bit (RGB / Alpha Channel)
- * 4. 48x48, 8 bit (256 colors)
- * 5. 32x32, 8 bit (256 colors)
- * 6. 24x24, 8 bit (256 colors)
- * 7. 16x16, 8 bit (256 colors)
- *
- * @param program the Windows executable e.g c:/eclipse/eclipse.exe
- */
- static ImageData[] loadIcons(String program) throws FileNotFoundException, IOException {
- RandomAccessFile raf = new RandomAccessFile(program, "r"); //$NON-NLS-1$
- IconExe iconExe = new IconExe();
- IconResInfo[] iconInfo = iconExe.getIcons(raf);
- ImageData[] data = new ImageData[iconInfo.length];
- for (int i = 0; i < data.length; i++)
- data[i] = iconInfo[i].data;
- raf.close();
- return data;
- }
-
- /**
- * Replace the Desktop icons provided in the Windows executable program
- * with icons provided by the user.
- *
- * Note 1. Write access to the executable program is required. As a result, that
- * program must not be currently running or edited elsewhere.
- *
- * Note 2. Use loadIcons to determine which set of icons (width, height, depth)
- * is required to replace the icons in the executable program. A user icon
- * matching exactly the width/height/depth of an executable icon will be written
- * to the executable and will replace that executable icon. If an executable icon
- * does not match a user icon, it is left as is. Verify the return value matches
- * the number of icons to write. Finally, use loadIcons after this operation
- * to verify the icons have changed as expected.
- *
- * Note 3. The Eclipse 3.4 launcher requires the following 7 images (in any order).
- * 1. 48x48, 32 bit (RGB / Alpha Channel)
- * 2. 32x32, 32 bit (RGB / Alpha Channel)
- * 3. 16x16, 32 bit (RGB / Alpha Channel)
- * 4. 48x48, 8 bit (256 colors)
- * 5. 32x32, 8 bit (256 colors)
- * 6. 24x24, 8 bit (256 colors)
- * 7. 16x16, 8 bit (256 colors)
- *
- * Note 4. This function modifies the content of the executable program and may cause
- * its corruption.
- *
- * @param program the Windows executable e.g c:/eclipse/eclipse.exe
- * @param icons to write to the given executable
- * @return the number of icons from the original program that were not successfully replaced (0 if success)
- */
- static int unloadIcons(String program, ImageData[] icons) throws FileNotFoundException, IOException {
- RandomAccessFile raf = new RandomAccessFile(program, "rw"); //$NON-NLS-1$
- IconExe iconExe = new IconExe();
- IconResInfo[] iconInfo = iconExe.getIcons(raf);
- // Display an error if no icons found in target executable.
- if (iconInfo.length == 0) {
- System.err.println("Warning - no icons detected in \"" + program + "\"."); //$NON-NLS-1$ //$NON-NLS-2$
- raf.close();
- return 0;
- }
- int cnt = 0;
- for (int i = 0; i < iconInfo.length; i++) {
- for (int j = 0; j < icons.length; j++) {
- if (icons[j] == null)
- continue;
- if (iconInfo[i].data.width == icons[j].width && iconInfo[i].data.height == icons[j].height && iconInfo[i].data.depth == icons[j].depth) {
- raf.seek(iconInfo[i].offset);
- unloadIcon(raf, icons[j]);
- cnt++;
- break;
- }
- }
- }
- raf.close();
- return iconInfo.length - cnt;
- }
-
- public static final String VERSION = "20050124"; //$NON-NLS-1$
-
- static final boolean DEBUG = false;
-
- public static class IconResInfo {
- ImageData data;
- int offset;
- int size;
- }
-
- IconResInfo[] iconInfo = null;
- int iconCnt;
-
- IconResInfo[] getIcons(RandomAccessFile raf) throws IOException {
- iconInfo = new IconResInfo[4];
- iconCnt = 0;
- IMAGE_DOS_HEADER imageDosHeader = new IMAGE_DOS_HEADER();
- read(raf, imageDosHeader);
- if (imageDosHeader.e_magic != IMAGE_DOS_SIGNATURE)
- return new IconResInfo[0];
- int imageNtHeadersOffset = imageDosHeader.e_lfanew;
- raf.seek(imageNtHeadersOffset);
- IMAGE_NT_HEADERS imageNtHeaders = new IMAGE_NT_HEADERS();
- read(raf, imageNtHeaders);
- if (imageNtHeaders.Signature != IMAGE_NT_SIGNATURE)
- return new IconResInfo[0];
- // DumpResources
- int resourcesRVA = imageNtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
- if (resourcesRVA == 0)
- return new IconResInfo[0];
- if (DEBUG)
- System.out.println("* Resources (RVA= " + resourcesRVA + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- IMAGE_SECTION_HEADER imageSectionHeader = new IMAGE_SECTION_HEADER();
- int firstSectionOffset = imageNtHeadersOffset + IMAGE_NT_HEADERS.FIELD_OFFSET_OptionalHeader + imageNtHeaders.FileHeader.SizeOfOptionalHeader;
- raf.seek(firstSectionOffset);
- boolean found = false;
- for (int i = 0; i < imageNtHeaders.FileHeader.NumberOfSections; i++) {
- read(raf, imageSectionHeader);
- if (resourcesRVA >= imageSectionHeader.VirtualAddress && resourcesRVA < imageSectionHeader.VirtualAddress + imageSectionHeader.Misc_VirtualSize) {
- // could check the imageSectionHeader name is .rsrc
- found = true;
- break;
- }
- }
- if (!found)
- return new IconResInfo[0];
- int delta = imageSectionHeader.VirtualAddress - imageSectionHeader.PointerToRawData;
- int imageResourceDirectoryOffset = resourcesRVA - delta;
- dumpResourceDirectory(raf, imageResourceDirectoryOffset, imageResourceDirectoryOffset, delta, 0, 0, false);
- if (iconCnt < iconInfo.length) {
- IconResInfo[] newArray = new IconResInfo[iconCnt];
- System.arraycopy(iconInfo, 0, newArray, 0, iconCnt);
- iconInfo = newArray;
- }
- return iconInfo;
- }
-
- void dumpResourceDirectory(RandomAccessFile raf, int imageResourceDirectoryOffset, int resourceBase, int delta, int type, int level, boolean rt_icon_root) throws IOException {
- if (DEBUG)
- System.out.println("** LEVEL " + level); //$NON-NLS-1$
-
- IMAGE_RESOURCE_DIRECTORY imageResourceDirectory = new IMAGE_RESOURCE_DIRECTORY();
- raf.seek(imageResourceDirectoryOffset);
- read(raf, imageResourceDirectory);
-
- if (DEBUG) {
- String sType = "" + type; //$NON-NLS-1$
- // level 1 resources are resource types
- if (level == 1) {
- System.out.println("___________________________"); //$NON-NLS-1$
- if (type == RT_ICON)
- sType = "RT_ICON"; //$NON-NLS-1$
- if (type == RT_GROUP_ICON)
- sType = "RT_GROUP_ICON"; //$NON-NLS-1$
- }
- System.out.println("Resource Directory [" + sType + "]" + " (Named " + imageResourceDirectory.NumberOfNamedEntries + ", ID " + imageResourceDirectory.NumberOfIdEntries + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
-
- IMAGE_RESOURCE_DIRECTORY_ENTRY[] imageResourceDirectoryEntries = new IMAGE_RESOURCE_DIRECTORY_ENTRY[imageResourceDirectory.NumberOfIdEntries];
- for (int i = 0; i < imageResourceDirectoryEntries.length; i++) {
- imageResourceDirectoryEntries[i] = new IMAGE_RESOURCE_DIRECTORY_ENTRY();
- read(raf, imageResourceDirectoryEntries[i]);
- }
- for (int i = 0; i < imageResourceDirectoryEntries.length; i++) {
- if (imageResourceDirectoryEntries[i].DataIsDirectory) {
- dumpResourceDirectory(raf, imageResourceDirectoryEntries[i].OffsetToDirectory + resourceBase, resourceBase, delta, imageResourceDirectoryEntries[i].Id, level + 1, rt_icon_root ? true : type == RT_ICON);
- } else {
- // Resource found
- /// pResDirEntry->Name
- IMAGE_RESOURCE_DIRECTORY_ENTRY irde = imageResourceDirectoryEntries[i];
- IMAGE_RESOURCE_DATA_ENTRY data = new IMAGE_RESOURCE_DATA_ENTRY();
- raf.seek(imageResourceDirectoryEntries[i].OffsetToData + resourceBase);
- read(raf, data);
- if (DEBUG)
- System.out.println("Resource Id " + irde.Id + " Data Offset RVA " + data.OffsetToData + ", Size " + data.Size); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (rt_icon_root) {
- if (DEBUG)
- System.out.println("iconcnt " + iconCnt + " |" + iconInfo.length); //$NON-NLS-1$ //$NON-NLS-2$
- iconInfo[iconCnt] = new IconResInfo();
- iconInfo[iconCnt].data = parseIcon(raf, data.OffsetToData - delta, data.Size);
- iconInfo[iconCnt].offset = data.OffsetToData - delta;
- iconInfo[iconCnt].size = data.Size;
- iconCnt++;
- if (iconCnt == iconInfo.length) {
- IconResInfo[] newArray = new IconResInfo[iconInfo.length + 4];
- System.arraycopy(iconInfo, 0, newArray, 0, iconInfo.length);
- iconInfo = newArray;
- }
- }
- }
- }
- }
-
- static ImageData parseIcon(RandomAccessFile raf, int offset, int size) throws IOException {
- raf.seek(offset);
- BITMAPINFO bitmapInfo = new BITMAPINFO();
- read(raf, bitmapInfo);
- bitmapInfo.bmiHeader.biHeight /= 2;
- int width = bitmapInfo.bmiHeader.biWidth;
- int height = bitmapInfo.bmiHeader.biHeight;
- int depth = bitmapInfo.bmiHeader.biBitCount;
-
- PaletteData palette = loadPalette(bitmapInfo.bmiHeader, raf);
- byte[] shapeData = loadData(bitmapInfo.bmiHeader, raf);
- bitmapInfo.bmiHeader.biBitCount = 1;
- byte[] maskData = loadData(bitmapInfo.bmiHeader, raf);
- maskData = convertPad(maskData, width, height, 1, 4, 2);
- bitInvertData(maskData, 0, maskData.length);
- return ImageData.internal_new(width, height, depth, palette, 4, shapeData, 2, maskData, null, -1, -1, SWT.IMAGE_ICO, 0, 0, 0, 0);
- }
-
- static byte[] bitInvertData(byte[] data, int startIndex, int endIndex) {
- // Destructively bit invert data in the given byte array.
- for (int i = startIndex; i < endIndex; i++) {
- data[i] = (byte) (255 - data[i - startIndex]);
- }
- return data;
- }
-
- static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) {
- if (pad == newPad)
- return data;
- int stride = (width * depth + 7) / 8;
- int bpl = (stride + (pad - 1)) / pad * pad;
- int newBpl = (stride + (newPad - 1)) / newPad * newPad;
- byte[] newData = new byte[height * newBpl];
- int srcIndex = 0, destIndex = 0;
- for (int y = 0; y < height; y++) {
- System.arraycopy(data, srcIndex, newData, destIndex, newBpl);
- srcIndex += bpl;
- destIndex += newBpl;
- }
- return newData;
- }
-
- static PaletteData loadPalette(BITMAPINFOHEADER bih, RandomAccessFile raf) throws IOException {
- int depth = bih.biBitCount;
- if (depth <= 8) {
- int numColors = bih.biClrUsed;
- if (numColors == 0) {
- numColors = 1 << depth;
- } else {
- if (numColors > 256)
- numColors = 256;
- }
- byte[] buf = new byte[numColors * 4];
- raf.read(buf);
- return paletteFromBytes(buf, numColors);
- }
- if (depth == 16)
- return new PaletteData(0x7C00, 0x3E0, 0x1F);
- if (depth == 24)
- return new PaletteData(0xFF, 0xFF00, 0xFF0000);
- return new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
- }
-
- static PaletteData paletteFromBytes(byte[] bytes, int numColors) {
- int bytesOffset = 0;
- RGB[] colors = new RGB[numColors];
- for (int i = 0; i < numColors; i++) {
- colors[i] = new RGB(bytes[bytesOffset + 2] & 0xFF, bytes[bytesOffset + 1] & 0xFF, bytes[bytesOffset] & 0xFF);
- bytesOffset += 4;
- }
- return new PaletteData(colors);
- }
-
- static byte[] loadData(BITMAPINFOHEADER bih, RandomAccessFile raf) throws IOException {
- int stride = (bih.biWidth * bih.biBitCount + 7) / 8;
- stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple
- byte[] data = loadData(bih, raf, stride);
- flipScanLines(data, stride, bih.biHeight);
- return data;
- }
-
- static void flipScanLines(byte[] data, int stride, int height) {
- int i1 = 0;
- int i2 = (height - 1) * stride;
- for (int i = 0; i < height / 2; i++) {
- for (int index = 0; index < stride; index++) {
- byte b = data[index + i1];
- data[index + i1] = data[index + i2];
- data[index + i2] = b;
- }
- i1 += stride;
- i2 -= stride;
- }
- }
-
- static byte[] loadData(BITMAPINFOHEADER bih, RandomAccessFile raf, int stride) throws IOException {
- int dataSize = bih.biHeight * stride;
- byte[] data = new byte[dataSize];
- int cmp = bih.biCompression;
- if (cmp == 0) { // BMP_NO_COMPRESSION
- raf.read(data);
- } else {
- if (DEBUG)
- System.out.println("ICO cannot be compressed?"); //$NON-NLS-1$
- }
- return data;
- }
-
- static void unloadIcon(RandomAccessFile raf, ImageData icon) throws IOException {
- int sizeImage = (((icon.width * icon.depth + 31) / 32 * 4) + ((icon.width + 31) / 32 * 4)) * icon.height;
- write4(raf, BMPHeaderFixedSize);
- write4(raf, icon.width);
- write4(raf, icon.height * 2);
- writeU2(raf, 1);
- writeU2(raf, icon.depth);
- write4(raf, 0);
- write4(raf, sizeImage);
- write4(raf, 0);
- write4(raf, 0);
- write4(raf, icon.palette.colors != null ? icon.palette.colors.length : 0);
- write4(raf, 0);
-
- byte[] rgbs = paletteToBytes(icon.palette);
- raf.write(rgbs);
- unloadShapeData(raf, icon);
- unloadMaskData(raf, icon);
- }
-
- static byte[] paletteToBytes(PaletteData pal) {
- int n = pal.colors == null ? 0 : (pal.colors.length < 256 ? pal.colors.length : 256);
- byte[] bytes = new byte[n * 4];
- int offset = 0;
- for (int i = 0; i < n; i++) {
- RGB col = pal.colors[i];
- bytes[offset] = (byte) col.blue;
- bytes[offset + 1] = (byte) col.green;
- bytes[offset + 2] = (byte) col.red;
- offset += 4;
- }
- return bytes;
- }
-
- static void unloadMaskData(RandomAccessFile raf, ImageData icon) {
- ImageData mask = icon.getTransparencyMask();
- int bpl = (icon.width + 7) / 8;
- int pad = mask.scanlinePad;
- int srcBpl = (bpl + pad - 1) / pad * pad;
- int destBpl = (bpl + 3) / 4 * 4;
- byte[] buf = new byte[destBpl];
- int offset = (icon.height - 1) * srcBpl;
- byte[] data = mask.data;
- try {
- for (int i = 0; i < icon.height; i++) {
- System.arraycopy(data, offset, buf, 0, bpl);
- bitInvertData(buf, 0, bpl);
- raf.write(buf, 0, destBpl);
- offset -= srcBpl;
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- static void unloadShapeData(RandomAccessFile raf, ImageData icon) {
- int bpl = (icon.width * icon.depth + 7) / 8;
- int pad = icon.scanlinePad;
- int srcBpl = (bpl + pad - 1) / pad * pad;
- int destBpl = (bpl + 3) / 4 * 4;
- byte[] buf = new byte[destBpl];
- int offset = (icon.height - 1) * srcBpl;
- byte[] data = icon.data;
- try {
- for (int i = 0; i < icon.height; i++) {
- System.arraycopy(data, offset, buf, 0, bpl);
- raf.write(buf, 0, destBpl);
- offset -= srcBpl;
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
-
- static boolean readIconGroup(RandomAccessFile raf, int offset, int size) throws IOException {
- raf.seek(offset);
- NEWHEADER newHeader = new NEWHEADER();
- read(raf, newHeader);
- if (newHeader.ResType != RES_ICON)
- return false;
- RESDIR[] resDir = new RESDIR[newHeader.ResCount];
- for (int i = 0; i < newHeader.ResCount; i++) {
- resDir[i] = new RESDIR();
- read(raf, resDir[i]);
- }
- return true;
- }
-
- static void copyFile(String src, String dst) throws FileNotFoundException, IOException {
- File srcFile = new File(src);
- File dstFile = new File(dst);
- InputStream in = new BufferedInputStream(new FileInputStream(srcFile));
- OutputStream out = new BufferedOutputStream(new FileOutputStream(dstFile));
- int c;
- while ((c = in.read()) != -1)
- out.write(c);
- in.close();
- out.close();
- }
-
- /* IO utilities to parse Windows executable */
- static final int IMAGE_DOS_SIGNATURE = 0x5a4d;
- static final int IMAGE_NT_SIGNATURE = 0x00004550;
- static final int IMAGE_DIRECTORY_ENTRY_RESOURCE = 2;
- static final int RES_ICON = 1;
- static final int RT_ICON = 3;
- static final int RT_GROUP_ICON = 14;
- static final int BMPHeaderFixedSize = 40;
- static final int IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b;
- static final int IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b;
-
- public static class IMAGE_DOS_HEADER {
- int e_magic; // WORD
- int e_cblp; // WORD
- int e_cp; // WORD
- int e_crlc; // WORD
- int e_cparhdr; // WORD
- int e_minalloc; // WORD
- int e_maxalloc; // WORD
- int e_ss; // WORD
- int e_sp; // WORD
- int e_csum; // WORD
- int e_ip; // WORD
- int e_cs; // WORD
- int e_lfarlc; // WORD
- int e_ovno; // WORD
- int[] e_res = new int[4]; // WORD[4]
- int e_oemid; // WORD
- int e_oeminfo; // WORD
- int[] e_res2 = new int[10]; // WORD[10]
- int e_lfanew; // LONG
- }
-
- public static class IMAGE_FILE_HEADER {
- int Machine; // WORD
- int NumberOfSections; // WORD
- int TimeDateStamp; // DWORD
- int PointerToSymbolTable; // DWORD
- int NumberOfSymbols; // DWORD
- int SizeOfOptionalHeader; // WORD
- int Characteristics; // WORD
- }
-
- public static class IMAGE_DATA_DIRECTORY {
- int VirtualAddress; // DWORD
- int Size; // DWORD
- }
-
- public static class IMAGE_OPTIONAL_HEADER {
- // Allocate enough storage for the 64 bit version of the header.
- int Magic; // WORD
- int MajorLinkerVersion; // BYTE
- int MinorLinkerVersion; // BYTE
- int SizeOfCode; // DWORD
- int SizeOfInitializedData; // DWORD
- int SizeOfUninitializedData; // DWORD
- int AddressOfEntryPoint; // DWORD
- int BaseOfCode; // DWORD
- int BaseOfData; // DWORD
- long ImageBase; // ULONGLONG
- int SectionAlignment; // DWORD
- int FileAlignment; // DWORD
- int MajorOperatingSystemVersion; // WORD
- int MinorOperatingSystemVersion; // WORD
- int MajorImageVersion; // WORD
- int MinorImageVersion; // WORD
- int MajorSubsystemVersion; // WORD
- int MinorSubsystemVersion; // WORD
- int Win32VersionValue; // DWORD
- int SizeOfImage; // DWORD
- int SizeOfHeaders; // DWORD
- int CheckSum; // DWORD
- int Subsystem; // WORD
- int DllCharacteristics; // WORD
- long SizeOfStackReserve; // ULONGLONG
- long SizeOfStackCommit; // ULONGLONG
- long SizeOfHeapReserve; // ULONGLONG
- long SizeOfHeapCommit; // ULONGLONG
- int LoaderFlags; // DWORD
- int NumberOfRvaAndSizes; // DWORD
- IMAGE_DATA_DIRECTORY[] DataDirectory = new IMAGE_DATA_DIRECTORY[16];
- }
-
- public static class IMAGE_NT_HEADERS {
- int Signature; // DWORD
- IMAGE_FILE_HEADER FileHeader = new IMAGE_FILE_HEADER();
- IMAGE_OPTIONAL_HEADER OptionalHeader = new IMAGE_OPTIONAL_HEADER();
- final static int FIELD_OFFSET_OptionalHeader = 24;
- }
-
- public static class IMAGE_SECTION_HEADER {
- int[] Name = new int[8]; // BYTE[8]
- int Misc_VirtualSize; // DWORD (union Misc { DWORD PhysicalAddress; DWORD VirtualSize }
- int VirtualAddress; // DWORD
- int SizeOfRawData; // DWORD
- int PointerToRawData; // DWORD
- int PointerToRelocations; // DWORD
- int PointerToLinenumbers; // DWORD
- int NumberOfRelocations; // WORD
- int NumberOfLinenumbers; // WORD
- int Characteristics; // DWORD
- }
-
- public static class IMAGE_RESOURCE_DIRECTORY {
- int Characteristics; // DWORD
- int TimeDateStamp; // DWORD
- int MajorVersion; // WORD
- int MinorVersion; // WORD
- int NumberOfNamedEntries; // WORD - used
- int NumberOfIdEntries; // WORD - used
- final static int SIZEOF = 16;
- }
-
- public static class IMAGE_RESOURCE_DIRECTORY_ENTRY {
- // union
- int NameOffset; // DWORD 31 bits
- boolean NameIsString; // DWORD 1 bit
- int Name; // DWORD
- int Id; // WORD
- // union
- int OffsetToData; // DWORD
- int OffsetToDirectory; // DWORD 31 bits
- boolean DataIsDirectory; // DWORD 1 bit
- }
-
- public static class IMAGE_RESOURCE_DATA_ENTRY {
- int OffsetToData; // DWORD
- int Size; // DWORD
- int CodePage; // DWORD
- int Reserved; // DWORD
- }
-
- public static class NEWHEADER {
- int Reserved; // WORD
- int ResType; // WORD
- int ResCount; // WORD
- }
-
- public static class ICONRESDIR {
- int Width; // BYTE
- int Height; // BYTE
- int ColorCount; // BYTE
- int reserved; // BYTE
- }
-
- public static class CURSORDIR {
- int Width; // WORD
- int Height; // WORD
- }
-
- public static class RESDIR {
- // union
- ICONRESDIR Icon = new ICONRESDIR();
- CURSORDIR Cursor = new CURSORDIR();
- int Planes; // WORD
- int BitCount; // WORD
- int BytesInRes; // DWORD
- int IconCursorId; // WORD
- }
-
- public static class BITMAPINFOHEADER {
- int biSize; // DWORD
- int biWidth; // LONG
- int biHeight; // LONG
- int biPlanes; // WORD
- int biBitCount; // WORD
- int biCompression; // DWORD
- int biSizeImage; // DWORD
- int biXPelsPerMeter; // LONG
- int biYPelsPerMeter; // LONG
- int biClrUsed; // DWORD
- int biClrImportant; // DWORD
- }
-
- static class RGBQUAD {
- int rgBlue; // BYTE
- int rgbGreen; // BYTE
- int rgbRed; // BYTE
- int rgbReserved; // BYTE
- }
-
- static class BITMAPINFO {
- BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
- RGBQUAD[] bmiColors = null;
- }
-
- static void read(RandomAccessFile raf, BITMAPINFOHEADER bih) throws IOException {
- bih.biSize = read4(raf);
- bih.biWidth = read4(raf);
- bih.biHeight = read4(raf);
- bih.biPlanes = readU2(raf);
- bih.biBitCount = readU2(raf);
- bih.biCompression = read4(raf);
- bih.biSizeImage = read4(raf);
- bih.biXPelsPerMeter = read4(raf);
- bih.biYPelsPerMeter = read4(raf);
- bih.biClrUsed = read4(raf);
- bih.biClrImportant = read4(raf);
- }
-
- static void read(RandomAccessFile raf, BITMAPINFO bi) throws IOException {
- read(raf, bi.bmiHeader);
- }
-
- /* Little Endian helpers */
- static int readU2(RandomAccessFile raf) throws IOException {
- int b0 = raf.readByte() & 0xFF;
- int b1 = raf.readByte() & 0xFF;
- return (b1 << 8 | b0);
- }
-
- static int read4(RandomAccessFile raf) throws IOException {
- int b0 = raf.readByte() & 0xFF;
- int b1 = raf.readByte() & 0xFF;
- int b2 = raf.readByte() & 0xFF;
- int b3 = raf.readByte() & 0xFF;
- return b3 << 24 | b2 << 16 | b1 << 8 | b0;
- }
-
- static long read8(RandomAccessFile raf) throws IOException {
- int b0 = raf.readByte() & 0xFF;
- int b1 = raf.readByte() & 0xFF;
- int b2 = raf.readByte() & 0xFF;
- int b3 = raf.readByte() & 0xFF;
- int b4 = raf.readByte() & 0xFF;
- int b5 = raf.readByte() & 0xFF;
- int b6 = raf.readByte() & 0xFF;
- int b7 = raf.readByte() & 0xFF;
- return b7 << 56 | b6 << 48 | b5 << 40 | b4 << 32 | b3 << 24 | b2 << 16 | b1 << 8 | b0;
- }
-
- static void write4(RandomAccessFile raf, int value) throws IOException {
- raf.write(value & 0xFF);
- raf.write((value >> 8) & 0xFF);
- raf.write((value >> 16) & 0xFF);
- raf.write((value >> 24) & 0xFF);
- }
-
- static void writeU2(RandomAccessFile raf, int value) throws IOException {
- raf.write(value & 0xFF);
- raf.write((value >> 8) & 0xFF);
- }
-
- static void read(RandomAccessFile raf, IMAGE_DOS_HEADER idh) throws IOException {
- idh.e_magic = readU2(raf);
- idh.e_cblp = readU2(raf);
- idh.e_cp = readU2(raf);
- idh.e_crlc = readU2(raf);
- idh.e_cparhdr = readU2(raf);
- idh.e_minalloc = readU2(raf);
- idh.e_maxalloc = readU2(raf);
- idh.e_ss = readU2(raf);
- idh.e_sp = readU2(raf);
- idh.e_csum = readU2(raf);
- idh.e_ip = readU2(raf);
- idh.e_cs = readU2(raf);
- idh.e_lfarlc = readU2(raf);
- idh.e_ovno = readU2(raf);
- for (int i = 0; i < idh.e_res.length; i++)
- idh.e_res[i] = readU2(raf);
- idh.e_oemid = readU2(raf);
- idh.e_oeminfo = readU2(raf);
- for (int i = 0; i < idh.e_res2.length; i++)
- idh.e_res2[i] = readU2(raf);
- idh.e_lfanew = read4(raf);
- }
-
- static void read(RandomAccessFile raf, IMAGE_FILE_HEADER ifh) throws IOException {
- ifh.Machine = readU2(raf);
- ifh.NumberOfSections = readU2(raf);
- ifh.TimeDateStamp = read4(raf);
- ifh.PointerToSymbolTable = read4(raf);
- ifh.NumberOfSymbols = read4(raf);
- ifh.SizeOfOptionalHeader = readU2(raf);
- ifh.Characteristics = readU2(raf);
- }
-
- static void read(RandomAccessFile raf, IMAGE_DATA_DIRECTORY idd) throws IOException {
- idd.VirtualAddress = read4(raf);
- idd.Size = read4(raf);
- }
-
- static void read(RandomAccessFile raf, IMAGE_OPTIONAL_HEADER ioh) throws IOException {
- ioh.Magic = readU2(raf);
-
- // Assume file is 32bit executable unless x64 magic is present
- boolean is32 = !(ioh.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC);
-
- ioh.MajorLinkerVersion = raf.read();
- ioh.MinorLinkerVersion = raf.read();
- ioh.SizeOfCode = read4(raf);
- ioh.SizeOfInitializedData = read4(raf);
- ioh.SizeOfUninitializedData = read4(raf);
- ioh.AddressOfEntryPoint = read4(raf);
- ioh.BaseOfCode = read4(raf);
-
- if (is32) {
- ioh.BaseOfData = read4(raf);
- ioh.ImageBase = read4(raf);
- } else {
- // BaseOfData deleted in the 64 bit version PE32+
- ioh.ImageBase = read8(raf);
- }
-
- ioh.SectionAlignment = read4(raf);
- ioh.FileAlignment = read4(raf);
- ioh.MajorOperatingSystemVersion = readU2(raf);
- ioh.MinorOperatingSystemVersion = readU2(raf);
- ioh.MajorImageVersion = readU2(raf);
- ioh.MinorImageVersion = readU2(raf);
- ioh.MajorSubsystemVersion = readU2(raf);
- ioh.MinorSubsystemVersion = readU2(raf);
- ioh.Win32VersionValue = read4(raf);
- ioh.SizeOfImage = read4(raf);
- ioh.SizeOfHeaders = read4(raf);
- ioh.CheckSum = read4(raf);
- ioh.Subsystem = readU2(raf);
- ioh.DllCharacteristics = readU2(raf);
-
- if (is32) {
- ioh.SizeOfStackReserve = read4(raf);
- ioh.SizeOfStackCommit = read4(raf);
- ioh.SizeOfHeapReserve = read4(raf);
- ioh.SizeOfHeapCommit = read4(raf);
- } else {
- ioh.SizeOfStackReserve = read8(raf);
- ioh.SizeOfStackCommit = read8(raf);
- ioh.SizeOfHeapReserve = read8(raf);
- ioh.SizeOfHeapCommit = read8(raf);
- }
-
- ioh.LoaderFlags = read4(raf);
- ioh.NumberOfRvaAndSizes = read4(raf);
- for (int i = 0; i < ioh.DataDirectory.length; i++) {
- ioh.DataDirectory[i] = new IMAGE_DATA_DIRECTORY();
- read(raf, ioh.DataDirectory[i]);
- }
- }
-
- static void read(RandomAccessFile raf, IMAGE_NT_HEADERS inh) throws IOException {
- inh.Signature = read4(raf);
- read(raf, inh.FileHeader);
- read(raf, inh.OptionalHeader);
- }
-
- static void read(RandomAccessFile raf, IMAGE_SECTION_HEADER ish) throws IOException {
- for (int i = 0; i < ish.Name.length; i++)
- ish.Name[i] = raf.read();
- ish.Misc_VirtualSize = read4(raf);
- ish.VirtualAddress = read4(raf);
- ish.SizeOfRawData = read4(raf);
- ish.PointerToRawData = read4(raf);
- ish.PointerToRelocations = read4(raf);
- ish.PointerToLinenumbers = read4(raf);
- ish.NumberOfRelocations = readU2(raf);
- ish.NumberOfLinenumbers = readU2(raf);
- ish.Characteristics = read4(raf);
- }
-
- static void read(RandomAccessFile raf, IMAGE_RESOURCE_DIRECTORY ird) throws IOException {
- ird.Characteristics = read4(raf);
- ird.TimeDateStamp = read4(raf);
- ird.MajorVersion = readU2(raf);
- ird.MinorVersion = readU2(raf);
- ird.NumberOfNamedEntries = readU2(raf);
- ird.NumberOfIdEntries = readU2(raf);
- }
-
- static void read(RandomAccessFile raf, IMAGE_RESOURCE_DIRECTORY_ENTRY irde) throws IOException {
- irde.Name = read4(raf);
- irde.OffsetToData = read4(raf);
- // construct other union members
- irde.NameOffset = irde.Name & ~(1 << 31);
- irde.NameIsString = (irde.Name & (1 << 31)) != 0;
- irde.Id = irde.Name & 0xFFFF;
- irde.OffsetToDirectory = irde.OffsetToData & ~(1 << 31);
- irde.DataIsDirectory = (irde.OffsetToData & (1 << 31)) != 0;
- }
-
- static void read(RandomAccessFile raf, IMAGE_RESOURCE_DATA_ENTRY irde) throws IOException {
- irde.OffsetToData = read4(raf);
- irde.Size = read4(raf);
- irde.CodePage = read4(raf);
- irde.Reserved = read4(raf);
- }
-
- static void read(RandomAccessFile raf, NEWHEADER nh) throws IOException {
- nh.Reserved = readU2(raf);
- nh.ResType = readU2(raf);
- nh.ResCount = readU2(raf);
- }
-
- static void read(RandomAccessFile raf, ICONRESDIR i) throws IOException {
- i.Width = raf.read();
- i.Height = raf.read();
- i.ColorCount = raf.read();
- i.reserved = raf.read();
- }
-
- static void read(RandomAccessFile raf, CURSORDIR c) throws IOException {
- c.Width = readU2(raf);
- c.Height = readU2(raf);
- }
-
- static void read(RandomAccessFile raf, RESDIR rs) throws IOException {
- long start = raf.getFilePointer();
- read(raf, rs.Icon);
- raf.seek(start);
- read(raf, rs.Cursor);
- rs.Planes = readU2(raf);
- rs.BitCount = readU2(raf);
- rs.BytesInRes = read4(raf);
- rs.IconCursorId = readU2(raf);
- }
-
- /* ImageData and Image Decoder inlining to avoid dependency on SWT
- * The following section can be entirely removed if SWT can be used.
- */
-
- static class RGB {
-
- /**
- * the red component of the RGB
- */
- public int red;
-
- /**
- * the green component of the RGB
- */
- public int green;
-
- /**
- * the blue component of the RGB
- */
- public int blue;
-
- static final long serialVersionUID = 3258415023461249074L;
-
- /**
- * Constructs an instance of this class with the given
- * red, green and blue values.
- *
- * @param red the red component of the new instance
- * @param green the green component of the new instance
- * @param blue the blue component of the new instance
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li>
- * </ul>
- */
- public RGB(int red, int green, int blue) {
- if ((red > 255) || (red < 0) || (green > 255) || (green < 0) || (blue > 255) || (blue < 0))
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.red = red;
- this.green = green;
- this.blue = blue;
- }
-
- /**
- * Compares the argument to the receiver, and returns true
- * if they represent the <em>same</em> object using a class
- * specific comparison.
- *
- * @param object the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
- *
- * @see #hashCode()
- */
- public boolean equals(Object object) {
- if (object == this)
- return true;
- if (!(object instanceof RGB))
- return false;
- RGB rgb = (RGB) object;
- return (rgb.red == this.red) && (rgb.green == this.green) && (rgb.blue == this.blue);
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two
- * objects which return <code>true</code> when passed to
- * <code>equals</code> must return the same value for this
- * method.
- *
- * @return the receiver's hash
- *
- * @see #equals(Object)
- */
- public int hashCode() {
- return (blue << 16) | (green << 8) | red;
- }
-
- /**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the <code>RGB</code>
- */
- public String toString() {
- return "RGB {" + red + ", " + green + ", " + blue + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
- //$NON-NLS-4$
- }
-
- }
-
- static class PaletteData {
-
- /**
- * true if the receiver is a direct palette,
- * and false otherwise
- */
- public boolean isDirect;
-
- /**
- * the RGB values for an indexed palette, where the
- * indices of the array correspond to pixel values
- */
- public RGB[] colors;
-
- /**
- * the red mask for a direct palette
- */
- public int redMask;
-
- /**
- * the green mask for a direct palette
- */
- public int greenMask;
-
- /**
- * the blue mask for a direct palette
- */
- public int blueMask;
-
- /**
- * the red shift for a direct palette
- */
- public int redShift;
-
- /**
- * the green shift for a direct palette
- */
- public int greenShift;
-
- /**
- * the blue shift for a direct palette
- */
- public int blueShift;
-
- /**
- * Constructs a new indexed palette given an array of RGB values.
- *
- * @param colors the array of <code>RGB</code>s for the palette
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- */
- public PaletteData(RGB[] colors) {
- if (colors == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.colors = colors;
- this.isDirect = false;
- }
-
- /**
- * Constructs a new direct palette given the red, green and blue masks.
- *
- * @param redMask the red mask
- * @param greenMask the green mask
- * @param blueMask the blue mask
- */
- public PaletteData(int redMask, int greenMask, int blueMask) {
- this.redMask = redMask;
- this.greenMask = greenMask;
- this.blueMask = blueMask;
- this.isDirect = true;
- this.redShift = shiftForMask(redMask);
- this.greenShift = shiftForMask(greenMask);
- this.blueShift = shiftForMask(blueMask);
- }
-
- /**
- * Returns the pixel value corresponding to the given <code>RBG</code>.
- *
- * @param rgb the RGB to get the pixel value for
- * @return the pixel value for the given RGB
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the RGB is not found in the palette</li>
- * </ul>
- */
- public int getPixel(RGB rgb) {
- if (rgb == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (isDirect) {
- int pixel = 0;
- pixel |= (redShift < 0 ? rgb.red << -redShift : rgb.red >>> redShift) & redMask;
- pixel |= (greenShift < 0 ? rgb.green << -greenShift : rgb.green >>> greenShift) & greenMask;
- pixel |= (blueShift < 0 ? rgb.blue << -blueShift : rgb.blue >>> blueShift) & blueMask;
- return pixel;
- }
-
- for (int i = 0; i < colors.length; i++) {
- if (colors[i].equals(rgb))
- return i;
- }
- /* The RGB did not exist in the palette */
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return 0;
- }
-
- /**
- * Returns an <code>RGB</code> corresponding to the given pixel value.
- *
- * @param pixel the pixel to get the RGB value for
- * @return the RGB value for the given pixel
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the pixel does not exist in the palette</li>
- * </ul>
- */
- public RGB getRGB(int pixel) {
- if (isDirect) {
- int r = pixel & redMask;
- r = (redShift < 0) ? r >>> -redShift : r << redShift;
- int g = pixel & greenMask;
- g = (greenShift < 0) ? g >>> -greenShift : g << greenShift;
- int b = pixel & blueMask;
- b = (blueShift < 0) ? b >>> -blueShift : b << blueShift;
- return new RGB(r, g, b);
- }
- if (pixel < 0 || pixel >= colors.length) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- return colors[pixel];
- }
-
- /**
- * Returns all the RGB values in the receiver if it is an
- * indexed palette, or null if it is a direct palette.
- *
- * @return the <code>RGB</code>s for the receiver or null
- */
- public RGB[] getRGBs() {
- return colors;
- }
-
- /**
- * Computes the shift value for a given mask.
- *
- * @param mask the mask to compute the shift for
- * @return the shift amount
- *
- * @see IconExe.PaletteData
- */
- int shiftForMask(int mask) {
- for (int i = 31; i >= 0; i--) {
- if (((mask >> i) & 0x1) != 0)
- return 7 - i;
- }
- return 32;
- }
-
- }
-
- static class ImageLoader {
-
- /**
- * the array of ImageData objects in this ImageLoader.
- * This array is read in when the load method is called,
- * and it is written out when the save method is called
- */
- public ImageData[] data;
-
- /**
- * the width of the logical screen on which the images
- * reside, in pixels (this corresponds to the GIF89a
- * Logical Screen Width value)
- */
- public int logicalScreenWidth;
-
- /**
- * the height of the logical screen on which the images
- * reside, in pixels (this corresponds to the GIF89a
- * Logical Screen Height value)
- */
- public int logicalScreenHeight;
-
- /**
- * the background pixel for the logical screen (this
- * corresponds to the GIF89a Background Color Index value).
- * The default is -1 which means 'unspecified background'
- *
- */
- public int backgroundPixel;
-
- /**
- * the number of times to repeat the display of a sequence
- * of animated images (this corresponds to the commonly-used
- * GIF application extension for "NETSCAPE 2.0 01")
- */
- public int repeatCount;
-
- /*
- * the set of ImageLoader event listeners, created on demand
- */
- Vector<?> imageLoaderListeners;
-
- /**
- * Construct a new empty ImageLoader.
- */
- public ImageLoader() {
- reset();
- }
-
- /**
- * Resets the fields of the ImageLoader, except for the
- * <code>imageLoaderListeners</code> field.
- */
- void reset() {
- data = null;
- logicalScreenWidth = 0;
- logicalScreenHeight = 0;
- backgroundPixel = -1;
- repeatCount = 1;
- }
-
- /**
- * Loads an array of <code>ImageData</code> objects from the
- * specified input stream. Throws an error if either an error
- * occurs while loading the images, or if the images are not
- * of a supported type. Returns the loaded image data array.
- *
- * @param stream the input stream to load the images from
- * @return an array of <code>ImageData</code> objects loaded from the specified input stream
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO - if an input/output error occurs while reading data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- */
- public ImageData[] load(InputStream stream) {
- if (stream == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- reset();
- data = FileFormat.load(stream, this);
- return data;
- }
-
- /**
- * Loads an array of <code>ImageData</code> objects from the
- * file with the specified name. Throws an error if either
- * an error occurs while loading the images, or if the images are
- * not of a supported type. Returns the loaded image data array.
- *
- * @param filename the name of the file to load the images from
- * @return an array of <code>ImageData</code> objects loaded from the specified file
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO - if an IO error occurs while reading data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- */
- public ImageData[] load(String filename) {
- if (filename == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- InputStream stream = null;
- try {
- stream = new BufferedInputStream(new FileInputStream(filename));
- return load(stream);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException e) {
- // Ignore error
- }
- }
- return null;
- }
- }
-
- static class ImageData {
-
- /**
- * The width of the image, in pixels.
- */
- public int width;
-
- /**
- * The height of the image, in pixels.
- */
- public int height;
-
- /**
- * The color depth of the image, in bits per pixel.
- * <p>
- * Note that a depth of 8 or less does not necessarily
- * mean that the image is palette indexed, or
- * conversely that a depth greater than 8 means that
- * the image is direct color. Check the associated
- * PaletteData's isDirect field for such determinations.
- */
- public int depth;
-
- /**
- * The scanline padding.
- * <p>
- * If one scanline of the image is not a multiple of
- * this number, it will be padded with zeros until it is.
- * </p>
- */
- public int scanlinePad;
-
- /**
- * The number of bytes per scanline.
- * <p>
- * This is a multiple of the scanline padding.
- * </p>
- */
- public int bytesPerLine;
-
- /**
- * The pixel data of the image.
- * <p>
- * Note that for 16 bit depth images the pixel data is stored
- * in least significant byte order; however, for 24bit and
- * 32bit depth images the pixel data is stored in most
- * significant byte order.
- * </p>
- */
- public byte[] data;
-
- /**
- * The color table for the image.
- */
- public PaletteData palette;
-
- /**
- * The transparent pixel.
- * <p>
- * Pixels with this value are transparent.
- * </p><p>
- * The default is -1 which means 'no transparent pixel'.
- * </p>
- */
- public int transparentPixel;
-
- /**
- * An icon-specific field containing the data from the icon mask.
- * <p>
- * This is a 1 bit bitmap stored with the most significant
- * bit first. The number of bytes per scanline is
- * '((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad'.
- * </p><p>
- * The default is null which means 'no transparency mask'.
- * </p>
- */
- public byte[] maskData;
-
- /**
- * An icon-specific field containing the scanline pad of the mask.
- * <p>
- * If one scanline of the transparency mask is not a
- * multiple of this number, it will be padded with zeros until
- * it is.
- * </p>
- */
- public int maskPad;
-
- /**
- * The alpha data of the image.
- * <p>
- * Every pixel can have an <em>alpha blending</em> value that
- * varies from 0, meaning fully transparent, to 255 meaning
- * fully opaque. The number of bytes per scanline is
- * 'width'.
- * </p>
- */
- public byte[] alphaData;
-
- /**
- * The global alpha value to be used for every pixel.
- * <p>
- * If this value is set, the <code>alphaData</code> field
- * is ignored and when the image is rendered each pixel
- * will be blended with the background an amount
- * proportional to this value.
- * </p><p>
- * The default is -1 which means 'no global alpha value'
- * </p>
- */
- public int alpha;
-
- /**
- * The type of file from which the image was read.
- *
- * It is expressed as one of the following values:
- * <dl>
- * <dt><code>IMAGE_BMP</code></dt>
- * <dd>Windows BMP file format, no compression</dd>
- * <dt><code>IMAGE_BMP_RLE</code></dt>
- * <dd>Windows BMP file format, RLE compression if appropriate</dd>
- * <dt><code>IMAGE_GIF</code></dt>
- * <dd>GIF file format</dd>
- * <dt><code>IMAGE_ICO</code></dt>
- * <dd>Windows ICO file format</dd>
- * <dt><code>IMAGE_JPEG</code></dt>
- * <dd>JPEG file format</dd>
- * <dt><code>IMAGE_PNG</code></dt>
- * <dd>PNG file format</dd>
- * </dl>
- */
- public int type;
-
- /**
- * The x coordinate of the top left corner of the image
- * within the logical screen (this field corresponds to
- * the GIF89a Image Left Position value).
- */
- public int x;
-
- /**
- * The y coordinate of the top left corner of the image
- * within the logical screen (this field corresponds to
- * the GIF89a Image Top Position value).
- */
- public int y;
-
- /**
- * A description of how to dispose of the current image
- * before displaying the next.
- *
- * It is expressed as one of the following values:
- * <dl>
- * <dt><code>DM_UNSPECIFIED</code></dt>
- * <dd>disposal method not specified</dd>
- * <dt><code>DM_FILL_NONE</code></dt>
- * <dd>do nothing - leave the image in place</dd>
- * <dt><code>DM_FILL_BACKGROUND</code></dt>
- * <dd>fill with the background color</dd>
- * <dt><code>DM_FILL_PREVIOUS</code></dt>
- * <dd>restore the previous picture</dd>
- * </dl>
- * (this field corresponds to the GIF89a Disposal Method value)
- */
- public int disposalMethod;
-
- /**
- * The time to delay before displaying the next image
- * in an animation (this field corresponds to the GIF89a
- * Delay Time value).
- */
- public int delayTime;
-
- /**
- * Arbitrary channel width data to 8-bit conversion table.
- */
- static final byte[][] ANY_TO_EIGHT = new byte[9][];
- static {
- for (int b = 0; b < 9; ++b) {
- byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b];
- if (b == 0)
- continue;
- int inc = 0;
- for (int bit = 0x10000; (bit >>= b) != 0;)
- inc |= bit;
- for (int v = 0, p = 0; v < 0x10000; v += inc)
- data[p++] = (byte) (v >> 8);
- }
- }
- static final byte[] ONE_TO_ONE_MAPPING = ANY_TO_EIGHT[8];
-
- /**
- * Scaled 8x8 Bayer dither matrix.
- */
- static final int[][] DITHER_MATRIX = { {0xfc0000, 0x7c0000, 0xdc0000, 0x5c0000, 0xf40000, 0x740000, 0xd40000, 0x540000}, {0x3c0000, 0xbc0000, 0x1c0000, 0x9c0000, 0x340000, 0xb40000, 0x140000, 0x940000}, {0xcc0000, 0x4c0000, 0xec0000, 0x6c0000, 0xc40000, 0x440000, 0xe40000, 0x640000}, {0x0c0000, 0x8c0000, 0x2c0000, 0xac0000, 0x040000, 0x840000, 0x240000, 0xa40000}, {0xf00000, 0x700000, 0xd00000, 0x500000, 0xf80000, 0x780000, 0xd80000, 0x580000}, {0x300000, 0xb00000, 0x100000, 0x900000, 0x380000, 0xb80000, 0x180000, 0x980000}, {0xc00000, 0x400000, 0xe00000, 0x600000, 0xc80000, 0x480000, 0xe80000, 0x680000}, {0x000000, 0x800000, 0x200000, 0xa00000, 0x080000, 0x880000, 0x280000, 0xa80000}};
-
- /**
- * Constructs a new, empty ImageData with the given width, height,
- * depth and palette. The data will be initialized to an (all zero)
- * array of the appropriate size.
- *
- * @param width the width of the image
- * @param height the height of the image
- * @param depth the depth of the image
- * @param palette the palette of the image (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width or height is negative, or if the depth is not
- * one of 1, 2, 4, 8, 16, 24 or 32</li>
- * <li>ERROR_NULL_ARGUMENT - if the palette is null</li>
- * </ul>
- */
- public ImageData(int width, int height, int depth, PaletteData palette) {
- this(width, height, depth, palette, 4, null, 0, null, null, -1, -1, SWT.IMAGE_UNDEFINED, 0, 0, 0, 0);
- }
-
- /**
- * Constructs a new, empty ImageData with the given width, height,
- * depth, palette, scanlinePad and data.
- *
- * @param width the width of the image
- * @param height the height of the image
- * @param depth the depth of the image
- * @param palette the palette of the image
- * @param scanlinePad the padding of each line, in bytes
- * @param data the data of the image
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the width or height is negative, or if the depth is not
- * one of 1, 2, 4, 8, 16, 24 or 32</li>
- * <li>ERROR_NULL_ARGUMENT - if the palette or data is null</li>
- * <li>ERROR_CANNOT_BE_ZERO - if the scanlinePad is zero</li>
- * </ul>
- */
- public ImageData(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data) {
- this(width, height, depth, palette, scanlinePad, checkData(data), 0, null, null, -1, -1, SWT.IMAGE_UNDEFINED, 0, 0, 0, 0);
- }
-
- /**
- * Constructs an <code>ImageData</code> loaded from a file with the
- * specified name. Throws an error if an error occurs loading the
- * image, or if the image has an unsupported type.
- * <p>
- * This constructor is provided for convenience when loading a single
- * image only. If the file contains multiple images, only the first
- * one will be loaded. To load multiple images, use
- * <code>ImageLoader.load()</code>.
- * </p>
- *
- * @param filename the name of the file to load the image from (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the file name is null</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li>
- * <li>ERROR_IO if an IO error occurs while reading data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li>
- * </ul>
- */
- public ImageData(String filename) {
- ImageData[] data = new ImageLoader().load(filename);
- if (data.length < 1)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- ImageData i = data[0];
- setAllFields(i.width, i.height, i.depth, i.scanlinePad, i.bytesPerLine, i.data, i.palette, i.transparentPixel, i.maskData, i.maskPad, i.alphaData, i.alpha, i.type, i.x, i.y, i.disposalMethod, i.delayTime);
- }
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- ImageData() {
- //empty constructor
- }
-
- /**
- * Constructs an image data by giving values for all non-computable fields.
- * <p>
- * This method is for internal use, and is not described further.
- * </p>
- */
- ImageData(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data, int maskPad, byte[] maskData, byte[] alphaData, int alpha, int transparentPixel, int type, int x, int y, int disposalMethod, int delayTime) {
-
- if (palette == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (!(depth == 1 || depth == 2 || depth == 4 || depth == 8 || depth == 16 || depth == 24 || depth == 32)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (width <= 0 || height <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (scanlinePad == 0)
- SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
-
- int bytesPerLine = (((width * depth + 7) / 8) + (scanlinePad - 1)) / scanlinePad * scanlinePad;
- setAllFields(width, height, depth, scanlinePad, bytesPerLine, data != null ? data : new byte[bytesPerLine * height], palette, transparentPixel, maskData, maskPad, alphaData, alpha, type, x, y, disposalMethod, delayTime);
- }
-
- /**
- * Initializes all fields in the receiver. This method must be called
- * by all public constructors to ensure that all fields are initialized
- * for a new ImageData object. If a new field is added to the class,
- * then it must be added to this method.
- * <p>
- * This method is for internal use, and is not described further.
- * </p>
- */
- void setAllFields(int width, int height, int depth, int scanlinePad, int bytesPerLine, byte[] data, PaletteData palette, int transparentPixel, byte[] maskData, int maskPad, byte[] alphaData, int alpha, int type, int x, int y, int disposalMethod, int delayTime) {
-
- this.width = width;
- this.height = height;
- this.depth = depth;
- this.scanlinePad = scanlinePad;
- this.bytesPerLine = bytesPerLine;
- this.data = data;
- this.palette = palette;
- this.transparentPixel = transparentPixel;
- this.maskData = maskData;
- this.maskPad = maskPad;
- this.alphaData = alphaData;
- this.alpha = alpha;
- this.type = type;
- this.x = x;
- this.y = y;
- this.disposalMethod = disposalMethod;
- this.delayTime = delayTime;
- }
-
- /**
- * Invokes internal SWT functionality to create a new instance of
- * this class.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>ImageData</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is subject
- * to change without notice, and should never be called from
- * application code.
- * </p>
- * <p>
- * This method is for internal use, and is not described further.
- * </p>
- */
- public static ImageData internal_new(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data, int maskPad, byte[] maskData, byte[] alphaData, int alpha, int transparentPixel, int type, int x, int y, int disposalMethod, int delayTime) {
- return new ImageData(width, height, depth, palette, scanlinePad, data, maskPad, maskData, alphaData, alpha, transparentPixel, type, x, y, disposalMethod, delayTime);
- }
-
- ImageData colorMaskImage(int pixel) {
- ImageData mask = new ImageData(width, height, 1, bwPalette(), 2, null, 0, null, null, -1, -1, SWT.IMAGE_UNDEFINED, 0, 0, 0, 0);
- int[] row = new int[width];
- for (int y = 0; y < height; y++) {
- getPixels(0, y, width, row, 0);
- for (int i = 0; i < width; i++) {
- if (pixel != -1 && row[i] == pixel) {
- row[i] = 0;
- } else {
- row[i] = 1;
- }
- }
- mask.setPixels(0, y, width, row, 0);
- }
- return mask;
- }
-
- static byte[] checkData(byte[] data) {
- if (data == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return data;
- }
-
- /**
- * Returns <code>getWidth</code> pixel values starting at offset
- * <code>x</code> in scanline <code>y</code> in the receiver's
- * data starting at <code>startIndex</code>.
- *
- * @param x the x position of the first pixel to get
- * @param y the y position of the first pixel to get
- * @param getWidth the width of the data to get
- * @param pixels the buffer in which to put the pixels
- * @param startIndex the offset into the byte array to begin storing pixels
- *
- * @exception IndexOutOfBoundsException if getWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4 or 8
- * (For higher depths, use the int[] version of this method.)</li>
- * </ul>
- */
- public void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex) {
- if (pixels == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0)
- SWT.error
-
- (SWT.ERROR_INVALID_ARGUMENT);
- if (getWidth == 0)
- return;
- int index;
- int theByte;
- int mask = 0;
- int n = getWidth;
- int i = startIndex;
- int srcX = x, srcY = y;
- if (depth == 1) {
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((theByte & mask) == 0) {
- pixels[i] = 0;
- } else {
- pixels[i] = 1;
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0)
- theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- if (n > 0)
- theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- }
- if (depth == 2) {
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index] & 0xFF;
- int offset;
- while (n > 0) {
- offset = 3 - (srcX % 4);
- mask = 3 << (offset * 2);
- pixels[i] = (byte) ((theByte & mask) >> (offset * 2));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0)
- theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- }
- if (depth == 4) {
- index = (y * bytesPerLine) + (x >> 1);
- if ((x & 0x1) == 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = (byte) (theByte & 0x0F);
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- while (n > 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = (byte) (theByte >> 4);
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- pixels[i] = (byte) (theByte & 0x0F);
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- }
- if (n > 0) {
- theByte = data[index] & 0xFF;
- pixels[i] = (byte) (theByte >> 4);
- }
- return;
- }
- if (depth == 8) {
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = data[index];
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- /**
- * Returns <code>getWidth</code> pixel values starting at offset
- * <code>x</code> in scanline <code>y</code> in the receiver's
- * data starting at <code>startIndex</code>.
- *
- * @param x the x position of the first pixel to get
- * @param y the y position of the first pixel to get
- * @param getWidth the width of the data to get
- * @param pixels the buffer in which to put the pixels
- * @param startIndex the offset into the buffer to begin storing pixels
- *
- * @exception IndexOutOfBoundsException if getWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if getWidth is negative</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li>
- * </ul>
- */
- public void getPixels(int x, int y, int getWidth, int[] pixels, int startIndex) {
- if (pixels == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getWidth < 0 || x >= width || y >= height || x < 0 || y < 0)
- SWT.error
-
- (SWT.ERROR_INVALID_ARGUMENT);
- if (getWidth == 0)
- return;
- int index;
- int theByte;
- int mask;
- int n = getWidth;
- int i = startIndex;
- int srcX = x, srcY = y;
- if (depth == 1) {
- index = (y * bytesPerLine) + (x >> 3);
- theByte = data[index] & 0xFF;
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((theByte & mask) == 0) {
- pixels[i] = 0;
- } else {
- pixels[i] = 1;
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0)
- theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- if (n > 0)
- theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- }
- if (depth == 2) {
- index = (y * bytesPerLine) + (x >> 2);
- theByte = data[index] & 0xFF;
- int offset;
- while (n > 0) {
- offset = 3 - (srcX % 4);
- mask = 3 << (offset * 2);
- pixels[i] = (byte) ((theByte & mask) >> (offset * 2));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- if (n > 0)
- theByte = data[index] & 0xFF;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- theByte = data[index] & 0xFF;
- }
- }
- }
- return;
- }
- if (depth == 4) {
- index = (y * bytesPerLine) + (x >> 1);
- if ((x & 0x1) == 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = theByte & 0x0F;
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- while (n > 1) {
- theByte = data[index] & 0xFF;
- pixels[i] = theByte >> 4;
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- pixels[i] = theByte & 0x0F;
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- }
- if (n > 0) {
- theByte = data[index] & 0xFF;
- pixels[i] = theByte >> 4;
- }
- return;
- }
- if (depth == 8) {
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = data[index] & 0xFF;
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- }
- if (depth == 16) {
- index = (y * bytesPerLine) + (x * 2);
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = ((data[index + 1] & 0xFF) << 8) + (data[index] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 2;
- }
- }
- return;
- }
- if (depth == 24) {
- index = (y * bytesPerLine) + (x * 3);
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = ((data[index] & 0xFF) << 16) | ((data[index + 1] & 0xFF) << 8) | (data[index + 2] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 3;
- }
- }
- return;
- }
- if (depth == 32) {
- index = (y * bytesPerLine) + (x * 4);
- i = startIndex;
- for (int j = 0; j < getWidth; j++) {
- pixels[i] = ((data[index] & 0xFF) << 24) | ((data[index + 1] & 0xFF) << 16) | ((data[index + 2] & 0xFF) << 8) | (data[index + 3] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 4;
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- /**
- * Returns an array of <code>RGB</code>s which comprise the
- * indexed color table of the receiver, or null if the receiver
- * has a direct color model.
- *
- * @return the RGB values for the image or null if direct color
- *
- * @see IconExe.PaletteData#getRGBs()
- */
- public RGB[] getRGBs() {
- return palette.getRGBs();
- }
-
- /**
- * Returns an <code>ImageData</code> which specifies the
- * transparency mask information for the receiver, or null if the
- * receiver has no transparency and is not an icon.
- *
- * @return the transparency mask or null if none exists
- */
- public ImageData getTransparencyMask() {
- if (getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- return new ImageData(width, height, 1, bwPalette(), maskPad, maskData);
- }
- return colorMaskImage(transparentPixel);
- }
-
- /**
- * Returns the image transparency type.
- *
- * @return the receiver's transparency type
- */
- public int getTransparencyType() {
- if (maskData != null)
- return SWT.TRANSPARENCY_MASK;
- if (transparentPixel != -1)
- return SWT.TRANSPARENCY_PIXEL;
- if (alphaData != null)
- return SWT.TRANSPARENCY_ALPHA;
- return SWT.TRANSPARENCY_NONE;
- }
-
- /**
- * Returns the byte order of the receiver.
- *
- * @return MSB_FIRST or LSB_FIRST
- */
- int getByteOrder() {
- return depth != 16 ? MSB_FIRST : LSB_FIRST;
- }
-
- /**
- * Sets the pixel values starting at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's data to the
- * values from the array <code>pixels</code> starting at
- * <code>startIndex</code>.
- *
- * @param x the x position of the pixel to set
- * @param y the y position of the pixel to set
- * @param putWidth the width of the pixels to set
- * @param pixels the pixels to set
- * @param startIndex the index at which to begin setting
- *
- * @exception IndexOutOfBoundsException if putWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8
- * (For higher depths, use the int[] version of this method.)</li>
- * </ul>
- */
- public void setPixels(int x, int y, int putWidth, byte[] pixels, int startIndex) {
- if (pixels == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0)
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (putWidth == 0)
- return;
- int index;
- int theByte;
- int mask;
- int n = putWidth;
- int i = startIndex;
- int srcX = x, srcY = y;
- if (depth == 1) {
- index = (y * bytesPerLine) + (x >> 3);
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((pixels[i] & 0x1) == 1) {
- data[index] = (byte) ((data[index] & 0xFF) | mask);
- } else {
- data[index] = (byte) ((data[index] & 0xFF) & (mask ^ -1));
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- }
- }
- }
- return;
- }
- if (depth == 2) {
- byte[] masks = {(byte) 0xFC, (byte) 0xF3, (byte) 0xCF, (byte) 0x3F};
- index = (y * bytesPerLine) + (x >> 2);
- int offset = 3 - (x % 4);
- while (n > 0) {
- theByte = pixels[i] & 0x3;
- data[index] = (byte) ((data[index] & masks[offset]) | (theByte << (offset * 2)));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- offset = 0;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- offset = 3;
- } else {
- offset--;
- }
- }
- }
- return;
- }
- if (depth == 4) {
- index = (y * bytesPerLine) + (x >> 1);
- boolean high = (x & 0x1) == 0;
- while (n > 0) {
- theByte = pixels[i] & 0x0F;
- if (high) {
- data[index] = (byte) ((data[index] & 0x0F) | (theByte << 4));
- } else {
- data[index] = (byte) ((data[index] & 0xF0) | theByte);
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- high = true;
- srcX = 0;
- } else {
- if (!high)
- index++;
- high = !high;
- }
- }
- return;
- }
- if (depth == 8) {
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < putWidth; j++) {
- data[index] = (byte) (pixels[i] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- /**
- * Sets the pixel values starting at offset <code>x</code> in
- * scanline <code>y</code> in the receiver's data to the
- * values from the array <code>pixels</code> starting at
- * <code>startIndex</code>.
- *
- * @param x the x position of the pixel to set
- * @param y the y position of the pixel to set
- * @param putWidth the width of the pixels to set
- * @param pixels the pixels to set
- * @param startIndex the index at which to begin setting
- *
- * @exception IndexOutOfBoundsException if putWidth is too large
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if pixels is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if x or y is out of bounds</li>
- * <li>ERROR_INVALID_ARGUMENT - if putWidth is negative</li>
- * </ul>
- * @exception RuntimeException <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH if the depth is not one of 1, 2, 4, 8, 16, 24 or 32</li>
- * </ul>
- */
- public void setPixels(int x, int y, int putWidth, int[] pixels, int startIndex) {
- if (pixels == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (putWidth < 0 || x >= width || y >= height || x < 0 || y < 0)
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (putWidth == 0)
- return;
- int index;
- int theByte;
- int mask;
- int n = putWidth;
- int i = startIndex;
- int pixel;
- int srcX = x, srcY = y;
- if (depth == 1) {
- index = (y * bytesPerLine) + (x >> 3);
- while (n > 0) {
- mask = 1 << (7 - (srcX & 0x7));
- if ((pixels[i] & 0x1) == 1) {
- data[index] = (byte) ((data[index] & 0xFF) | mask);
- } else {
- data[index] = (byte) ((data[index] & 0xFF) & (mask ^ -1));
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- if (mask == 1) {
- index++;
- }
- }
- }
- return;
- }
- if (depth == 2) {
- byte[] masks = {(byte) 0xFC, (byte) 0xF3, (byte) 0xCF, (byte) 0x3F};
- index = (y * bytesPerLine) + (x >> 2);
- int offset = 3 - (x % 4);
- while (n > 0) {
- theByte = pixels[i] & 0x3;
- data[index] = (byte) ((data[index] & masks[offset]) | (theByte << (offset * 2)));
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- offset = 3;
- srcX = 0;
- } else {
- if (offset == 0) {
- index++;
- offset = 3;
- } else {
- offset--;
- }
- }
- }
- return;
- }
- if (depth == 4) {
- index = (y * bytesPerLine) + (x >> 1);
- boolean high = (x & 0x1) == 0;
- while (n > 0) {
- theByte = pixels[i] & 0x0F;
- if (high) {
- data[index] = (byte) ((data[index] & 0x0F) | (theByte << 4));
- } else {
- data[index] = (byte) ((data[index] & 0xF0) | theByte);
- }
- i++;
- n--;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- high = true;
- srcX = 0;
- } else {
- if (!high)
- index++;
- high = !high;
- }
- }
- return;
- }
- if (depth == 8) {
- index = (y * bytesPerLine) + x;
- for (int j = 0; j < putWidth; j++) {
- data[index] = (byte) (pixels[i] & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index++;
- }
- }
- return;
-
- }
- if (depth == 16) {
- index = (y * bytesPerLine) + (x * 2);
- for (int j = 0; j < putWidth; j++) {
- pixel = pixels[i];
- data[index] = (byte) (pixel & 0xFF);
- data[index + 1] = (byte) ((pixel >> 8) & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 2;
- }
- }
- return;
- }
- if (depth == 24) {
- index = (y * bytesPerLine) + (x * 3);
- for (int j = 0; j < putWidth; j++) {
- pixel = pixels[i];
- data[index] = (byte) ((pixel >> 16) & 0xFF);
- data[index + 1] = (byte) ((pixel >> 8) & 0xFF);
- data[index + 2] = (byte) (pixel & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 3;
- }
- }
- return;
- }
- if (depth == 32) {
- index = (y * bytesPerLine) + (x * 4);
- for (int j = 0; j < putWidth; j++) {
- pixel = pixels[i];
- data[index] = (byte) ((pixel >> 24) & 0xFF);
- data[index + 1] = (byte) ((pixel >> 16) & 0xFF);
- data[index + 2] = (byte) ((pixel >> 8) & 0xFF);
- data[index + 3] = (byte) (pixel & 0xFF);
- i++;
- srcX++;
- if (srcX >= width) {
- srcY++;
- index = srcY * bytesPerLine;
- srcX = 0;
- } else {
- index += 4;
- }
- }
- return;
- }
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- /**
- * Returns a palette with 2 colors: black & white.
- */
- static PaletteData bwPalette() {
- return new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255, 255, 255)});
- }
-
- /**
- * Gets the offset of the most significant bit for
- * the given mask.
- */
- static int getMSBOffset(int mask) {
- for (int i = 31; i >= 0; i--) {
- if (((mask >> i) & 0x1) != 0)
- return i + 1;
- }
- return 0;
- }
-
- /**
- * Finds the closest match.
- */
- static int closestMatch(int depth, byte red, byte green, byte blue, int redMask, int greenMask, int blueMask, byte[] reds, byte[] greens, byte[] blues) {
- if (depth > 8) {
- int rshift = 32 - getMSBOffset(redMask);
- int gshift = 32 - getMSBOffset(greenMask);
- int bshift = 32 - getMSBOffset(blueMask);
- return (((red << 24) >>> rshift) & redMask) | (((green << 24) >>> gshift) & greenMask) | (((blue << 24) >>> bshift) & blueMask);
- }
- int r, g, b;
- int minDistance = 0x7fffffff;
- int nearestPixel = 0;
- int n = reds.length;
- for (int j = 0; j < n; j++) {
- r = (reds[j] & 0xFF) - (red & 0xFF);
- g = (greens[j] & 0xFF) - (green & 0xFF);
- b = (blues[j] & 0xFF) - (blue & 0xFF);
- int distance = r * r + g * g + b * b;
- if (distance < minDistance) {
- nearestPixel = j;
- if (distance == 0)
- break;
- minDistance = distance;
- }
- }
- return nearestPixel;
- }
-
- static final ImageData convertMask(ImageData mask) {
- if (mask.depth == 1)
- return mask;
- PaletteData palette = new PaletteData(new RGB[] {new RGB(0, 0, 0), new RGB(255, 255, 255)});
- ImageData newMask = new ImageData(mask.width, mask.height, 1, palette);
- /* Find index of black in mask palette */
- int blackIndex = 0;
- RGB[] rgbs = mask.getRGBs();
- if (rgbs != null) {
- while (blackIndex < rgbs.length) {
- if (rgbs[blackIndex].equals(palette.colors[0]))
- break;
- blackIndex++;
- }
- }
- int[] pixels = new int[mask.width];
- for (int y = 0; y < mask.height; y++) {
- mask.getPixels(0, y, mask.width, pixels, 0);
- for (int i = 0; i < pixels.length; i++) {
- if (pixels[i] == blackIndex) {
- pixels[i] = 0;
- } else {
- pixels[i] = 1;
- }
- }
- newMask.setPixels(0, y, mask.width, pixels, 0);
- }
- return newMask;
- }
-
- static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) {
- if (pad == newPad)
- return data;
- int stride = (width * depth + 7) / 8;
- int bpl = (stride + (pad - 1)) / pad * pad;
- int newBpl = (stride + (newPad - 1)) / newPad * newPad;
- byte[] newData = new byte[height * newBpl];
- int srcIndex = 0, destIndex = 0;
- for (int y = 0; y < height; y++) {
- System.arraycopy(data, srcIndex, newData, destIndex, stride);
- srcIndex += bpl;
- destIndex += newBpl;
- }
- return newData;
- }
-
- /**
- * Blit operation bits to be OR'ed together to specify the desired operation.
- */
- static final int BLIT_SRC = 1, // copy source directly, else applies logic operations
- BLIT_ALPHA = 2, // enable alpha blending
- BLIT_DITHER = 4; // enable dithering in low color modes
-
- /**
- * Alpha mode, values 0 - 255 specify global alpha level
- */
- static final int ALPHA_OPAQUE = 255, // Fully opaque (ignores any alpha data)
- ALPHA_TRANSPARENT = 0, // Fully transparent (ignores any alpha data)
- ALPHA_CHANNEL_SEPARATE = -1, // Use alpha channel from separate alphaData
- ALPHA_CHANNEL_SOURCE = -2, // Use alpha channel embedded in sourceData
- ALPHA_MASK_UNPACKED = -3, // Use transparency mask formed by bytes in alphaData (non-zero is opaque)
- ALPHA_MASK_PACKED = -4, // Use transparency mask formed by packed bits in alphaData
- ALPHA_MASK_INDEX = -5, // Consider source palette indices transparent if in alphaData array
- ALPHA_MASK_RGB = -6; // Consider source RGBs transparent if in RGB888 format alphaData array
-
- /**
- * Byte and bit order constants.
- */
- static final int LSB_FIRST = 0;
- static final int MSB_FIRST = 1;
-
- /**
- * Data types (internal)
- */
- /*
- private static final int
- // direct / true color formats with arbitrary masks & shifts
- TYPE_GENERIC_8 = 0,
- TYPE_GENERIC_16_MSB = 1,
- TYPE_GENERIC_16_LSB = 2,
- TYPE_GENERIC_24 = 3,
- TYPE_GENERIC_32_MSB = 4,
- TYPE_GENERIC_32_LSB = 5,
- // palette indexed color formats
- TYPE_INDEX_8 = 6,
- TYPE_INDEX_4 = 7,
- TYPE_INDEX_2 = 8,
- TYPE_INDEX_1_MSB = 9,
- TYPE_INDEX_1_LSB = 10;
- */
- /**
- * Computes the required channel shift from a mask.
- */
- static int getChannelShift(int mask) {
- if (mask == 0)
- return 0;
- int i;
- for (i = 0; ((mask & 1) == 0) && (i < 32); ++i) {
- mask >>>= 1;
- }
- return i;
- }
-
- /**
- * Computes the required channel width (depth) from a mask.
- */
- static int getChannelWidth(int mask, int shift) {
- if (mask == 0)
- return 0;
- int i;
- mask >>>= shift;
- for (i = shift; ((mask & 1) != 0) && (i < 32); ++i) {
- mask >>>= 1;
- }
- return i - shift;
- }
-
- /**
- * Extracts a field from packed RGB data given a mask for that field.
- */
- static byte getChannelField(int data, int mask) {
- final int shift = getChannelShift(mask);
- return ANY_TO_EIGHT[getChannelWidth(mask, shift)][(data & mask) >>> shift];
- }
-
- /*
- * Fill in dithered gradated values for a color channel
- */
- static final void buildDitheredGradientChannel(int from, int to, int steps, int bandWidth, int bandHeight, boolean vertical, byte[] bitmapData, int dp, int bytesPerLine, int bits) {
- final int mask = 0xff00 >>> bits;
- int val = from << 16;
- final int inc = ((to << 16) - val) / steps + 1;
- if (vertical) {
- for (int dy = 0; dy < bandHeight; ++dy, dp += bytesPerLine) {
- for (int dx = 0, dptr = dp; dx < bandWidth; ++dx, dptr += 4) {
- final int thresh = DITHER_MATRIX[dy & 7][dx] >>> bits;
- int temp = val + thresh;
- if (temp > 0xffffff)
- bitmapData[dptr] = -1;
- else
- bitmapData[dptr] = (byte) ((temp >>> 16) & mask);
- }
- val += inc;
- }
- } else {
- for (int dx = 0; dx < bandWidth; ++dx, dp += 4) {
- for (int dy = 0, dptr = dp; dy < bandHeight; ++dy, dptr += bytesPerLine) {
- final int thresh = DITHER_MATRIX[dy][dx & 7] >>> bits;
- int temp = val + thresh;
- if (temp > 0xffffff)
- bitmapData[dptr] = -1;
- else
- bitmapData[dptr] = (byte) ((temp >>> 16) & mask);
- }
- val += inc;
- }
- }
- }
- }
-
- static class LEDataInputStream extends InputStream {
- int position;
- InputStream in;
-
- /**
- * The byte array containing the bytes to read.
- */
- protected byte[] buf;
-
- /**
- * The current position within the byte array <code>buf</code>. A value
- * equal to buf.length indicates no bytes available. A value of
- * 0 indicates the buffer is full.
- */
- protected int pos;
-
- public LEDataInputStream(InputStream input) {
- this(input, 512);
- }
-
- public LEDataInputStream(InputStream input, int bufferSize) {
- this.in = input;
- if (bufferSize > 0) {
- buf = new byte[bufferSize];
- pos = bufferSize;
- } else
- throw new IllegalArgumentException();
- }
-
- public void close() throws IOException {
- buf = null;
- if (in != null) {
- in.close();
- in = null;
- }
- }
-
- /**
- * Answer how many bytes were read.
- */
- public int getPosition() {
- return position;
- }
-
- /**
- * Answers how many bytes are available for reading without blocking
- */
- public int available() throws IOException {
- if (buf == null)
- throw new IOException();
- return (buf.length - pos) + in.available();
- }
-
- /**
- * Answer the next byte of the input stream.
- */
- public int read() throws IOException {
- if (buf == null)
- throw new IOException();
- position++;
- if (pos < buf.length)
- return (buf[pos++] & 0xFF);
- return in.read();
- }
-
- /**
- * Don't imitate the JDK behaviour of reading a random number
- * of bytes when you can actually read them all.
- */
- public int read(byte b[], int off, int len) throws IOException {
- int result;
- int left = len;
- result = readData(b, off, len);
- while (true) {
- if (result == -1)
- return -1;
- position += result;
- if (result == left)
- return len;
- left -= result;
- off += result;
- result = readData(b, off, left);
- }
- }
-
- /**
- * Reads at most <code>length</code> bytes from this LEDataInputStream and
- * stores them in byte array <code>buffer</code> starting at <code>offset</code>.
- * <p>
- * Answer the number of bytes actually read or -1 if no bytes were read and
- * end of stream was encountered. This implementation reads bytes from
- * the pushback buffer first, then the target stream if more bytes are required
- * to satisfy <code>count</code>.
- * </p>
- * @param buffer the byte array in which to store the read bytes.
- * @param offset the offset in <code>buffer</code> to store the read bytes.
- * @param length the maximum number of bytes to store in <code>buffer</code>.
- *
- * @return int the number of bytes actually read or -1 if end of stream.
- *
- * @exception java.io.IOException if an IOException occurs.
- */
- private int readData(byte[] buffer, int offset, int length) throws IOException {
- if (buf == null)
- throw new IOException();
- if (offset < 0 || offset > buffer.length || length < 0 || (length > buffer.length - offset)) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- int cacheCopied = 0;
- int newOffset = offset;
-
- // Are there pushback bytes available?
- int available = buf.length - pos;
- if (available > 0) {
- cacheCopied = (available >= length) ? length : available;
- System.arraycopy(buf, pos, buffer, newOffset, cacheCopied);
- newOffset += cacheCopied;
- pos += cacheCopied;
- }
-
- // Have we copied enough?
- if (cacheCopied == length)
- return length;
-
- int inCopied = in.read(buffer, newOffset, length - cacheCopied);
-
- if (inCopied > 0)
- return inCopied + cacheCopied;
- if (cacheCopied == 0)
- return inCopied;
- return cacheCopied;
- }
-
- /**
- * Answer an integer comprised of the next
- * four bytes of the input stream.
- */
- public int readInt() throws IOException {
- byte[] buf = new byte[4];
- read(buf);
- return ((((((buf[3] & 0xFF) << 8) | (buf[2] & 0xFF)) << 8) | (buf[1] & 0xFF)) << 8) | (buf[0] & 0xFF);
- }
-
- /**
- * Answer a short comprised of the next
- * two bytes of the input stream.
- */
- public short readShort() throws IOException {
- byte[] buf = new byte[2];
- read(buf);
- return (short) (((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF));
- }
-
- /**
- * Push back the entire content of the given buffer <code>b</code>.
- * <p>
- * The bytes are pushed so that they would be read back b[0], b[1], etc.
- * If the push back buffer cannot handle the bytes copied from <code>b</code>,
- * an IOException will be thrown and no byte will be pushed back.
- * </p>
- *
- * @param b the byte array containing bytes to push back into the stream
- *
- * @exception java.io.IOException if the pushback buffer is too small
- */
- public void unread(byte[] b) throws IOException {
- int length = b.length;
- if (length > pos)
- throw new IOException();
- position -= length;
- pos -= length;
- System.arraycopy(b, 0, buf, pos, length);
- }
- }
-
- public static abstract class FileFormat {
- LEDataInputStream inputStream;
- ImageLoader loader;
- int compression;
-
- byte[] bitInvertData(byte[] data, int startIndex, int endIndex) {
- // Destructively bit invert data in the given byte array.
- for (int i = startIndex; i < endIndex; i++) {
- data[i] = (byte) (255 - data[i - startIndex]);
- }
- return data;
- }
-
- /**
- * Return whether or not the specified input stream
- * represents a supported file format.
- */
- abstract boolean isFileFormat(LEDataInputStream stream);
-
- abstract ImageData[] loadFromByteStream();
-
- public ImageData[] loadFromStream(LEDataInputStream stream) {
- try {
- inputStream = stream;
- return loadFromByteStream();
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
-
- public static ImageData[] load(InputStream is, ImageLoader loader) {
- LEDataInputStream stream = new LEDataInputStream(is);
- boolean isSupported = false;
- FileFormat fileFormat = new WinICOFileFormat();
- if (fileFormat.isFileFormat(stream))
- isSupported = true;
- else {
- fileFormat = new WinBMPFileFormat();
- if (fileFormat.isFileFormat(stream))
- isSupported = true;
- }
- if (!isSupported)
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- fileFormat.loader = loader;
- return fileFormat.loadFromStream(stream);
- }
- }
-
- static class WinBMPFileFormat extends FileFormat {
- static final int BMPFileHeaderSize = 14;
- static final int BMPHeaderFixedSize = 40;
- int importantColors;
-
- void decompressData(byte[] src, byte[] dest, int stride, int cmp) {
- if (cmp == 1) { // BMP_RLE8_COMPRESSION
- if (decompressRLE8Data(src, src.length, stride, dest, dest.length) <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return;
- }
- if (cmp == 2) { // BMP_RLE4_COMPRESSION
- if (decompressRLE4Data(src, src.length, stride, dest, dest.length) <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return;
- }
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
-
- int decompressRLE4Data(byte[] src, int numBytes, int stride, byte[] dest, int destSize) {
- int sp = 0;
- int se = numBytes;
- int dp = 0;
- int de = destSize;
- int x = 0, y = 0;
- while (sp < se) {
- int len = src[sp] & 0xFF;
- sp++;
- if (len == 0) {
- len = src[sp] & 0xFF;
- sp++;
- switch (len) {
- case 0 : /* end of line */
- y++;
- x = 0;
- dp = y * stride;
- if (dp >= de)
- return -1;
- break;
- case 1 : /* end of bitmap */
- return 1;
- case 2 : /* delta */
- x += src[sp] & 0xFF;
- sp++;
- y += src[sp] & 0xFF;
- sp++;
- dp = y * stride + x / 2;
- if (dp >= de)
- return -1;
- break;
- default : /* absolute mode run */
- if ((len & 1) != 0) /* odd run lengths not currently supported */
- return -1;
- x += len;
- len = len / 2;
- if (len > (se - sp))
- return -1;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = src[sp];
- dp++;
- sp++;
- }
- if ((sp & 1) != 0)
- sp++; /* word align sp? */
- break;
- }
- } else {
- if ((len & 1) != 0)
- return -1;
- x += len;
- len = len / 2;
- byte theByte = src[sp];
- sp++;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = theByte;
- dp++;
- }
- }
- }
- return 1;
- }
-
- int decompressRLE8Data(byte[] src, int numBytes, int stride, byte[] dest, int destSize) {
- int sp = 0;
- int se = numBytes;
- int dp = 0;
- int de = destSize;
- int x = 0, y = 0;
- while (sp < se) {
- int len = src[sp] & 0xFF;
- sp++;
- if (len == 0) {
- len = src[sp] & 0xFF;
- sp++;
- switch (len) {
- case 0 : /* end of line */
- y++;
- x = 0;
- dp = y * stride;
- if (dp >= de)
- return -1;
- break;
- case 1 : /* end of bitmap */
- return 1;
- case 2 : /* delta */
- x += src[sp] & 0xFF;
- sp++;
- y += src[sp] & 0xFF;
- sp++;
- dp = y * stride + x;
- if (dp >= de)
- return -1;
- break;
- default : /* absolute mode run */
- if (len > (se - sp))
- return -1;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = src[sp];
- dp++;
- sp++;
- }
- if ((sp & 1) != 0)
- sp++; /* word align sp? */
- x += len;
- break;
- }
- } else {
- byte theByte = src[sp];
- sp++;
- if (len > (de - dp))
- return -1;
- for (int i = 0; i < len; i++) {
- dest[dp] = theByte;
- dp++;
- }
- x += len;
- }
- }
- return 1;
- }
-
- boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] header = new byte[18];
- stream.read(header);
- stream.unread(header);
- int infoHeaderSize = (header[14] & 0xFF) | ((header[15] & 0xFF) << 8) | ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24);
- return header[0] == 0x42 && header[1] == 0x4D && infoHeaderSize >= BMPHeaderFixedSize;
- } catch (Exception e) {
- return false;
- }
- }
-
- byte[] loadData(byte[] infoHeader) {
- int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- int stride = (width * bitCount + 7) / 8;
- stride = (stride + 3) / 4 * 4; // Round up to 4 byte multiple
- byte[] data = loadData(infoHeader, stride);
- flipScanLines(data, stride, height);
- return data;
- }
-
- byte[] loadData(byte[] infoHeader, int stride) {
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int dataSize = height * stride;
- byte[] data = new byte[dataSize];
- int cmp = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24);
- if (cmp == 0) { // BMP_NO_COMPRESSION
- try {
- if (inputStream.read(data) != dataSize)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- } else {
- int compressedSize = (infoHeader[20] & 0xFF) | ((infoHeader[21] & 0xFF) << 8) | ((infoHeader[22] & 0xFF) << 16) | ((infoHeader[23] & 0xFF) << 24);
- byte[] compressed = new byte[compressedSize];
- try {
- if (inputStream.read(compressed) != compressedSize)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- decompressData(compressed, data, stride, cmp);
- }
- return data;
- }
-
- int[] loadFileHeader() {
- int[] header = new int[5];
- try {
- header[0] = inputStream.readShort();
- header[1] = inputStream.readInt();
- header[2] = inputStream.readShort();
- header[3] = inputStream.readShort();
- header[4] = inputStream.readInt();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if (header[0] != 0x4D42)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return header;
- }
-
- ImageData[] loadFromByteStream() {
- int[] fileHeader = loadFileHeader();
- byte[] infoHeader = new byte[BMPHeaderFixedSize];
- try {
- inputStream.read(infoHeader);
- } catch (Exception e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- PaletteData palette = loadPalette(infoHeader);
- if (inputStream.getPosition() < fileHeader[4]) {
- // Seek to the specified offset
- try {
- inputStream.skip(fileHeader[4] - inputStream.getPosition());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- }
- byte[] data = loadData(infoHeader);
- this.compression = (infoHeader[16] & 0xFF) | ((infoHeader[17] & 0xFF) << 8) | ((infoHeader[18] & 0xFF) << 16) | ((infoHeader[19] & 0xFF) << 24);
- this.importantColors = (infoHeader[36] & 0xFF) | ((infoHeader[37] & 0xFF) << 8) | ((infoHeader[38] & 0xFF) << 16) | ((infoHeader[39] & 0xFF) << 24);
- // int xPelsPerMeter = (infoHeader[24] & 0xFF) | ((infoHeader[25] & 0xFF) << 8) | ((infoHeader[26] & 0xFF) << 16) | ((infoHeader[27] & 0xFF) << 24);
- // int yPelsPerMeter = (infoHeader[28] & 0xFF) | ((infoHeader[29] & 0xFF) << 8) | ((infoHeader[30] & 0xFF) << 16) | ((infoHeader[31] & 0xFF) << 24);
- int type = (this.compression == 1 /*BMP_RLE8_COMPRESSION*/) || (this.compression == 2 /*BMP_RLE4_COMPRESSION*/) ? SWT.IMAGE_BMP_RLE : SWT.IMAGE_BMP;
- return new ImageData[] {ImageData.internal_new(width, height, bitCount, palette, 4, data, 0, null, null, -1, -1, type, 0, 0, 0, 0)};
- }
-
- PaletteData loadPalette(byte[] infoHeader) {
- int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- if (depth <= 8) {
- int numColors = (infoHeader[32] & 0xFF) | ((infoHeader[33] & 0xFF) << 8) | ((infoHeader[34] & 0xFF) << 16) | ((infoHeader[35] & 0xFF) << 24);
- if (numColors == 0) {
- numColors = 1 << depth;
- } else {
- if (numColors > 256)
- numColors = 256;
- }
- byte[] buf = new byte[numColors * 4];
- try {
- if (inputStream.read(buf) != buf.length)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return paletteFromBytes(buf, numColors);
- }
- if (depth == 16)
- return new PaletteData(0x7C00, 0x3E0, 0x1F);
- if (depth == 24)
- return new PaletteData(0xFF, 0xFF00, 0xFF0000);
- return new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
- }
-
- PaletteData paletteFromBytes(byte[] bytes, int numColors) {
- int bytesOffset = 0;
- RGB[] colors = new RGB[numColors];
- for (int i = 0; i < numColors; i++) {
- colors[i] = new RGB(bytes[bytesOffset + 2] & 0xFF, bytes[bytesOffset + 1] & 0xFF, bytes[bytesOffset] & 0xFF);
- bytesOffset += 4;
- }
- return new PaletteData(colors);
- }
-
- /**
- * Answer a byte array containing the BMP representation of
- * the given device independent palette.
- */
- static byte[] paletteToBytes(PaletteData pal) {
- int n = pal.colors == null ? 0 : (pal.colors.length < 256 ? pal.colors.length : 256);
- byte[] bytes = new byte[n * 4];
- int offset = 0;
- for (int i = 0; i < n; i++) {
- RGB col = pal.colors[i];
- bytes[offset] = (byte) col.blue;
- bytes[offset + 1] = (byte) col.green;
- bytes[offset + 2] = (byte) col.red;
- offset += 4;
- }
- return bytes;
- }
-
- void flipScanLines(byte[] data, int stride, int height) {
- int i1 = 0;
- int i2 = (height - 1) * stride;
- for (int i = 0; i < height / 2; i++) {
- for (int index = 0; index < stride; index++) {
- byte b = data[index + i1];
- data[index + i1] = data[index + i2];
- data[index + i2] = b;
- }
- i1 += stride;
- i2 -= stride;
- }
- }
-
- }
-
- static class WinICOFileFormat extends FileFormat {
-
- static final byte[] convertPad(byte[] data, int width, int height, int depth, int pad, int newPad) {
- if (pad == newPad)
- return data;
- int stride = (width * depth + 7) / 8;
- int bpl = (stride + (pad - 1)) / pad * pad;
- int newBpl = (stride + (newPad - 1)) / newPad * newPad;
- byte[] newData = new byte[height * newBpl];
- int srcIndex = 0, destIndex = 0;
- for (int y = 0; y < height; y++) {
- System.arraycopy(data, srcIndex, newData, destIndex, newBpl);
- srcIndex += bpl;
- destIndex += newBpl;
- }
- return newData;
- }
-
- /**
- * Answer the size in bytes of the file representation of the given
- * icon
- */
- int iconSize(ImageData i) {
- int shapeDataStride = (i.width * i.depth + 31) / 32 * 4;
- int maskDataStride = (i.width + 31) / 32 * 4;
- int dataSize = (shapeDataStride + maskDataStride) * i.height;
- int paletteSize = i.palette.colors != null ? i.palette.colors.length * 4 : 0;
- return WinBMPFileFormat.BMPHeaderFixedSize + paletteSize + dataSize;
- }
-
- boolean isFileFormat(LEDataInputStream stream) {
- try {
- byte[] header = new byte[4];
- stream.read(header);
- stream.unread(header);
- return header[0] == 0 && header[1] == 0 && header[2] == 1 && header[3] == 0;
- } catch (Exception e) {
- return false;
- }
- }
-
- boolean isValidIcon(ImageData i) {
- switch (i.depth) {
- case 1 :
- case 4 :
- case 8 :
- if (i.palette.isDirect)
- return false;
- int size = i.palette.colors.length;
- return size == 2 || size == 16 || size == 32 || size == 256;
- case 24 :
- case 32 :
- return i.palette.isDirect;
- }
- return false;
- }
-
- int loadFileHeader(LEDataInputStream byteStream) {
- int[] fileHeader = new int[3];
- try {
- fileHeader[0] = byteStream.readShort();
- fileHeader[1] = byteStream.readShort();
- fileHeader[2] = byteStream.readShort();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if ((fileHeader[0] != 0) || (fileHeader[1] != 1))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- int numIcons = fileHeader[2];
- if (numIcons <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return numIcons;
- }
-
- int loadFileHeader(LEDataInputStream byteStream, boolean hasHeader) {
- int[] fileHeader = new int[3];
- try {
- if (hasHeader) {
- fileHeader[0] = byteStream.readShort();
- fileHeader[1] = byteStream.readShort();
- } else {
- fileHeader[0] = 0;
- fileHeader[1] = 1;
- }
- fileHeader[2] = byteStream.readShort();
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if ((fileHeader[0] != 0) || (fileHeader[1] != 1))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- int numIcons = fileHeader[2];
- if (numIcons <= 0)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- return numIcons;
- }
-
- ImageData[] loadFromByteStream() {
- int numIcons = loadFileHeader(inputStream);
- int[][] headers = loadIconHeaders(numIcons);
- ImageData[] icons = new ImageData[headers.length];
- for (int i = 0; i < icons.length; i++) {
- icons[i] = loadIcon(headers[i]);
- }
- return icons;
- }
-
- /**
- * Load one icon from the byte stream.
- */
- ImageData loadIcon(int[] iconHeader) {
- byte[] infoHeader = loadInfoHeader(iconHeader);
- WinBMPFileFormat bmpFormat = new WinBMPFileFormat();
- bmpFormat.inputStream = inputStream;
- PaletteData palette = bmpFormat.loadPalette(infoHeader);
- byte[] shapeData = bmpFormat.loadData(infoHeader);
- int width = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int height = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int depth = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- infoHeader[14] = 1;
- infoHeader[15] = 0;
- byte[] maskData = bmpFormat.loadData(infoHeader);
- maskData = convertPad(maskData, width, height, 1, 4, 2);
- bitInvertData(maskData, 0, maskData.length);
- return ImageData.internal_new(width, height, depth, palette, 4, shapeData, 2, maskData, null, -1, -1, SWT.IMAGE_ICO, 0, 0, 0, 0);
- }
-
- int[][] loadIconHeaders(int numIcons) {
- int[][] headers = new int[numIcons][7];
- try {
- for (int i = 0; i < numIcons; i++) {
- headers[i][0] = inputStream.read();
- headers[i][1] = inputStream.read();
- headers[i][2] = inputStream.readShort();
- headers[i][3] = inputStream.readShort();
- headers[i][4] = inputStream.readShort();
- headers[i][5] = inputStream.readInt();
- headers[i][6] = inputStream.readInt();
- }
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- return headers;
- }
-
- byte[] loadInfoHeader(int[] iconHeader) {
- int width = iconHeader[0];
- int height = iconHeader[1];
- int numColors = iconHeader[2]; // the number of colors is in the low byte, but the high byte must be 0
- if (numColors == 0)
- numColors = 256; // this is specified: '00' represents '256' (0x100) colors
- if ((numColors != 2) && (numColors != 8) && (numColors != 16) && (numColors != 32) && (numColors != 256))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (inputStream.getPosition() < iconHeader[6]) {
- // Seek to the specified offset
- try {
- inputStream.skip(iconHeader[6] - inputStream.getPosition());
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- return null;
- }
- }
- byte[] infoHeader = new byte[WinBMPFileFormat.BMPHeaderFixedSize];
- try {
- inputStream.read(infoHeader);
- } catch (IOException e) {
- SWT.error(SWT.ERROR_IO, e);
- }
- if (((infoHeader[12] & 0xFF) | ((infoHeader[13] & 0xFF) << 8)) != 1)
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- int infoWidth = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
- int infoHeight = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
- int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
- if (height == infoHeight && bitCount == 1)
- height /= 2;
- if (!((width == infoWidth) && (height * 2 == infoHeight) && (bitCount == 1 || bitCount == 4 || bitCount == 8 || bitCount == 24 || bitCount == 32)))
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- infoHeader[8] = (byte) (height & 0xFF);
- infoHeader[9] = (byte) ((height >> 8) & 0xFF);
- infoHeader[10] = (byte) ((height >> 16) & 0xFF);
- infoHeader[11] = (byte) ((height >> 24) & 0xFF);
- return infoHeader;
- }
- }
-
- static class SWT {
- public static final int IMAGE_ICO = 3;
- public static final int ERROR_IO = 39;
- public static final int ERROR_INVALID_IMAGE = 40;
- public static final int ERROR_NULL_ARGUMENT = 4;
- public static final int ERROR_INVALID_ARGUMENT = 5;
- public static final int ERROR_CANNOT_BE_ZERO = 7;
- public static final int IMAGE_UNDEFINED = -1;
- public static final int ERROR_UNSUPPORTED_DEPTH = 38;
- public static final int TRANSPARENCY_MASK = 1 << 1;
- public static final int ERROR_UNSUPPORTED_FORMAT = 42;
- public static final int TRANSPARENCY_ALPHA = 1 << 0;
- public static final int TRANSPARENCY_NONE = 0x0;
- public static final int TRANSPARENCY_PIXEL = 1 << 2;
- public static final int IMAGE_BMP = 0;
- public static final int IMAGE_BMP_RLE = 1;
-
- public static void error(int code) {
- throw new RuntimeException("Error " + code); //$NON-NLS-1$
- }
-
- public static void error(int code, Throwable t) {
- throw new RuntimeException(t);
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java
index 907c1d791..67abd747f 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/spi/p2/publisher/PublisherHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2011 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
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Genuitec, LLC - added license support
* Code 9 - Ongoing development
+# SAP AG - consolidation of publishers for PDE formats
*******************************************************************************/
package org.eclipse.equinox.spi.p2.publisher;
@@ -16,18 +17,15 @@ import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
-import java.util.Map.Entry;
-import org.eclipse.equinox.internal.p2.metadata.*;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.p2.metadata.BasicVersion;
import org.eclipse.equinox.p2.metadata.*;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitFragmentDescription;
import org.eclipse.equinox.p2.publisher.IPublisherInfo;
-import org.eclipse.equinox.p2.publisher.PublisherInfo;
-import org.eclipse.equinox.p2.publisher.eclipse.*;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
-import org.eclipse.osgi.service.resolver.BundleDescription;
import org.osgi.framework.Constants;
/**
@@ -210,27 +208,6 @@ public class PublisherHelper {
return MetadataFactory.createInstallableUnit(cu);
}
- private static void addExtraProperties(IInstallableUnit iiu, Map<String, String> extraProperties) {
- if (iiu instanceof InstallableUnit) {
- InstallableUnit iu = (InstallableUnit) iiu;
-
- for (Entry<String, String> entry : extraProperties.entrySet()) {
- iu.setProperty(entry.getKey(), entry.getValue());
- }
- }
- }
-
- public static IInstallableUnit[] createEclipseIU(BundleDescription bd, boolean isFolderPlugin, IArtifactKey key, Map<String, String> extraProperties) {
- ArrayList<IInstallableUnit> iusCreated = new ArrayList<IInstallableUnit>(1);
- IPublisherInfo info = new PublisherInfo();
- String shape = isFolderPlugin ? IBundleShapeAdvice.DIR : IBundleShapeAdvice.JAR;
- info.addAdvice(new BundleShapeAdvice(bd.getSymbolicName(), fromOSGiVersion(bd.getVersion()), shape));
- IInstallableUnit iu = BundlesAction.createBundleIU(bd, key, info);
- addExtraProperties(iu, extraProperties);
- iusCreated.add(iu);
- return (iusCreated.toArray(new IInstallableUnit[iusCreated.size()]));
- }
-
public static ArtifactKey createBinaryArtifactKey(String id, Version version) {
return new ArtifactKey(BINARY_ARTIFACT_CLASSIFIER, id, version);
}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java
deleted file mode 100644
index 04f18ebd7..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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 - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.ant;
-
-import org.eclipse.equinox.p2.query.QueryUtil;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.tools.ant.Task;
-import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
-import org.eclipse.equinox.internal.p2.publisher.Activator;
-import org.eclipse.equinox.internal.p2.publisher.Messages;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.IArtifactKey;
-import org.eclipse.equinox.p2.publisher.*;
-import org.eclipse.equinox.p2.query.IQueryResult;
-import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
-import org.eclipse.osgi.util.NLS;
-
-public abstract class AbstractPublishTask extends Task {
- protected static final String ANT_PROPERTY_PREFIX = "${"; //$NON-NLS-1$
-
- /**
- * Support nested repository elements that looking something like
- * <repo location="file:/foo" metadata="true" artifact="true" />
- * Both metadata and artifact are optional:
- * 1) if neither are set, the repo is used for both metadata and artifacts
- * 2) if only one is true, the repo is that type and not the other
- */
- static public class RepoEntry {
- private URI repoLocation;
- private Boolean metadata = null;
- private Boolean artifact = null;
-
- /**
- * If not set, default is true if we aren't set as an artifact repo
- */
- public boolean isMetadataRepository() {
- if (metadata != null)
- return metadata.booleanValue();
- return !Boolean.TRUE.equals(artifact);
- }
-
- /**
- * If not set, default is true if we aren't set as an metadata repo
- */
- public boolean isArtifactRepository() {
- if (artifact != null)
- return artifact.booleanValue();
- return !Boolean.TRUE.equals(metadata);
- }
-
- public URI getRepositoryLocation() {
- return repoLocation;
- }
-
- public void setLocation(String location) {
- try {
- repoLocation = URIUtil.fromString(location);
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("Repository location (" + location + ") must be a URL."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public void setMetadata(boolean metadata) {
- this.metadata = Boolean.valueOf(metadata);
- }
-
- public void setArtifact(boolean artifact) {
- this.artifact = Boolean.valueOf(artifact);
- }
- }
-
- protected boolean compress = false;
- protected boolean reusePackedFiles = false;
- protected boolean append = true;
- protected boolean publish = true;
- protected String source = null;
- protected URI metadataLocation;
- protected String metadataRepoName;
- protected URI artifactLocation;
- protected String artifactRepoName;
- protected PublisherInfo provider = null;
- protected List<RepoEntry> contextRepositories = new ArrayList<RepoEntry>();
-
- protected IProvisioningAgent getProvisioningAgent() {
- return (IProvisioningAgent) ServiceHelper.getService(Activator.context, IProvisioningAgent.SERVICE_NAME);
- }
-
- protected IStatus createConfigurationEror(String message) {
- return new Status(IStatus.ERROR, "org.eclipse.equinox.p2.publisher", message); //$NON-NLS-1$
- }
-
- private boolean isEmpty(IArtifactRepository repo) {
- IQueryResult<IArtifactKey> result = repo.query(QueryUtil.createLimitQuery(ArtifactKeyQuery.ALL_KEYS, 1), null);
- return result.isEmpty();
- }
-
- protected void initializeRepositories(PublisherInfo info) throws ProvisionException {
- if (artifactLocation != null) {
- IArtifactRepository repo = Publisher.createArtifactRepository(getProvisioningAgent(), artifactLocation, artifactRepoName, compress, reusePackedFiles);
- if (!append && !isEmpty(repo)) {
- File repoLocation = URIUtil.toFile(artifactLocation);
- if (repoLocation != null && source != null) {
- if (repoLocation.isFile())
- repoLocation = repoLocation.getParentFile();
- if (repoLocation.equals(new File(source)))
- throw new IllegalArgumentException(NLS.bind(Messages.exception_artifactRepoNoAppendDestroysInput, URIUtil.toUnencodedString(artifactLocation)));
- }
- repo.removeAll();
- }
- info.setArtifactRepository(repo);
- } else if ((info.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
- throw new ProvisionException(createConfigurationEror(Messages.exception_noArtifactRepo));
- if (metadataLocation == null)
- throw new ProvisionException(createConfigurationEror(Messages.exception_noMetadataRepo));
- info.setMetadataRepository(Publisher.createMetadataRepository(getProvisioningAgent(), metadataLocation, metadataRepoName, append, compress));
-
- if (contextRepositories.size() > 0) {
- CompositeMetadataRepository contextMetadata = CompositeMetadataRepository.createMemoryComposite(getProvisioningAgent());
- CompositeArtifactRepository contextArtifact = CompositeArtifactRepository.createMemoryComposite(getProvisioningAgent());
-
- for (RepoEntry entry : contextRepositories) {
- if (contextMetadata != null && entry.isMetadataRepository())
- contextMetadata.addChild(entry.getRepositoryLocation());
- if (contextArtifact != null && entry.isArtifactRepository())
- contextArtifact.addChild(entry.getRepositoryLocation());
- }
-
- if (contextMetadata != null && contextMetadata.getChildren().size() > 0)
- info.setContextMetadataRepository(contextMetadata);
-
- if (contextArtifact != null && contextArtifact.getChildren().size() > 0)
- info.setContextArtifactRepository(contextArtifact);
- }
- }
-
- protected PublisherInfo getInfo() {
- if (provider == null)
- provider = new PublisherInfo();
-
- if (publish)
- provider.setArtifactOptions(provider.getArtifactOptions() | IPublisherInfo.A_PUBLISH);
- return provider;
- }
-
- public void setCompress(String value) {
- compress = Boolean.valueOf(value).booleanValue();
- }
-
- public void setReusePackedFiles(String value) {
- reusePackedFiles = Boolean.valueOf(value).booleanValue();
- }
-
- public void setAppend(String value) {
- append = Boolean.valueOf(value).booleanValue();
- }
-
- public void setPublishArtifacts(String value) {
- publish = Boolean.valueOf(value).booleanValue();
- }
-
- public void setArtifactRepository(String location) {
- try {
- artifactLocation = URIUtil.fromString(location);
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("Artifact repository location (" + location + ") must be a URL."); //$NON-NLS-1$//$NON-NLS-2$
- }
- }
-
- public void setArtifactRepositoryName(String value) {
- artifactRepoName = value;
- }
-
- public void setMetadataRepository(String location) {
- try {
- metadataLocation = URIUtil.fromString(location);
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("Metadata repository location (" + location + ") must be a URL."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public void setMetadataRepositoryName(String value) {
- metadataRepoName = value;
- }
-
- public void setRepository(String location) {
- setArtifactRepository(location);
- setMetadataRepository(location);
- }
-
- public void setRepositoryName(String name) {
- setArtifactRepositoryName(name);
- setMetadataRepositoryName(name);
- }
-
- // nested <contextRepository/> elements
- public void addConfiguredContextRepository(RepoEntry repo) {
- contextRepositories.add(repo);
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java
deleted file mode 100644
index 0c8bcab19..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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 - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.ant;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.types.FileSet;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.publisher.IPublisherAction;
-import org.eclipse.equinox.p2.publisher.Publisher;
-import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
-import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
-
-public class FeaturesAndBundlesPublisherTask extends AbstractPublishTask {
- private ArrayList<Object> features = new ArrayList<Object>();
- private ArrayList<Object> bundles = new ArrayList<Object>();
-
- public void execute() throws BuildException {
- try {
- initializeRepositories(getInfo());
- } catch (ProvisionException e) {
- throw new BuildException("Unable to configure repositories", e); //$NON-NLS-1$
- }
-
- File[] f = getLocations(features);
- File[] b = getLocations(bundles);
-
- ArrayList<IPublisherAction> actions = new ArrayList<IPublisherAction>();
- if (f.length > 0)
- actions.add(new FeaturesAction(f));
- if (b.length > 0)
- actions.add(new BundlesAction(b));
-
- if (actions.size() > 0)
- new Publisher(getInfo()).publish(actions.toArray(new IPublisherAction[actions.size()]), new NullProgressMonitor());
- }
-
- private File[] getLocations(List<Object> collection) {
- ArrayList<Object> results = new ArrayList<Object>();
- for (Object obj : collection) {
- if (obj instanceof FileSet) {
- FileSet set = (FileSet) obj;
-
- DirectoryScanner scanner = set.getDirectoryScanner(getProject());
- String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < elements[i].length; j++) {
- results.add(new File(set.getDir(), elements[i][j]));
- }
- }
- } else if (obj instanceof File) {
- results.add(obj);
- }
- }
- return results.toArray(new File[results.size()]);
- }
-
- public FileSet createFeatures() {
- FileSet set = new FileSet();
- features.add(set);
- return set;
- }
-
- public FileSet createBundles() {
- FileSet set = new FileSet();
- bundles.add(set);
- return set;
- }
-
- public void setSource(String source) {
- super.source = source;
- features.add(new File(source, "features")); //$NON-NLS-1$
- bundles.add(new File(source, "plugins")); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java
deleted file mode 100644
index 2a4af026b..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 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 - Initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.internal.p2.publisher.ant;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.tools.ant.BuildException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor;
-import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.publisher.*;
-import org.eclipse.equinox.p2.publisher.actions.VersionAdvice;
-import org.eclipse.equinox.p2.publisher.eclipse.ProductAction;
-
-public class ProductPublisherTask extends AbstractPublishTask {
-
- public static class ConfigElement {
- public String os;
- public String ws;
- public String arch;
-
- public void setOs(String os) {
- this.os = os;
- }
-
- public void setWs(String ws) {
- this.ws = ws;
- }
-
- public void setArch(String arch) {
- this.arch = arch;
- }
-
- public String toString() {
- return ws + '.' + os + '.' + arch;
- }
- }
-
- public static class AdviceElement {
- public String kind;
- public String file;
-
- public void setKind(String kind) {
- this.kind = kind;
- }
-
- public void setFile(String file) {
- this.file = file;
- }
- }
-
- private String flavor;
- private String productFile;
- private String executables;
- private List<ConfigElement> configurations = new ArrayList<ConfigElement>(3);
- private List<AdviceElement> advice = new ArrayList<AdviceElement>(3);
-
- public void execute() throws BuildException {
- try {
- initializeRepositories(getInfo());
- } catch (ProvisionException e) {
- throw new BuildException("Unable to configure repositories", e); //$NON-NLS-1$
- }
-
- IProductDescriptor productDescriptor = null;
- try {
- productDescriptor = new ProductFile(productFile);
- } catch (Exception e) {
- if (productFile == null)
- throw new IllegalArgumentException("unable to load product file"); //$NON-NLS-1$
- }
-
- if (flavor == null || flavor.startsWith(ANT_PROPERTY_PREFIX))
- flavor = "tooling"; //$NON-NLS-1$
-
- IPublisherAction action = new ProductAction(source, productDescriptor, flavor, executables != null ? new File(executables) : null);
- new Publisher(getInfo()).publish(new IPublisherAction[] {action}, new NullProgressMonitor());
- }
-
- protected PublisherInfo getInfo() {
- String[] configStrings = new String[configurations.size()];
- for (int i = 0; i < configurations.size(); i++) {
- configStrings[i] = configurations.get(i).toString();
- }
-
- PublisherInfo info = super.getInfo();
- info.setConfigurations(configStrings);
- processAdvice(info);
- return info;
- }
-
- protected void processAdvice(PublisherInfo info) {
- for (AdviceElement element : advice) {
- if (element.kind == null || element.file == null)
- continue;
-
- if (element.kind.equals("featureVersions") || element.kind.equals("pluginVersions")) { //$NON-NLS-1$ //$NON-NLS-2$
- VersionAdvice versionAdvice = new VersionAdvice();
- versionAdvice.load(IInstallableUnit.NAMESPACE_IU_ID, element.file, element.kind.startsWith("features") ? ".feature.group" : null); //$NON-NLS-1$ //$NON-NLS-2$
- info.addAdvice(versionAdvice);
- }
- }
- }
-
- public void setFlavor(String flavor) {
- this.flavor = flavor;
- }
-
- public void setProductFile(String productFile) {
- this.productFile = productFile;
- }
-
- public void setExecutables(String executables) {
- this.executables = executables;
- }
-
- public void setSource(String source) {
- super.source = source;
- }
-
- public void addConfiguredConfig(ConfigElement config) {
- this.configurations.add(config);
- }
-
- public void addConfiguredAdvice(AdviceElement element) {
- this.advice.add(element);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java
deleted file mode 100644
index d25b04174..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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.internal.p2.publisher.ant;
-
-import java.io.File;
-import org.apache.tools.ant.BuildException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.IVersionedId;
-import org.eclipse.equinox.p2.metadata.Version;
-import org.eclipse.equinox.p2.publisher.*;
-import org.eclipse.equinox.p2.publisher.eclipse.EclipseInstallAction;
-
-/**
- * An Ant task to call the p2 publisher application.
- *
- * @since 1.0
- */
-public class PublisherTask extends AbstractPublishTask {
-
- protected boolean inplace = false;
- protected String[] configurations;
- protected String mode;
- private String flavor;
- private String operation;
- private String operationValue;
- private String root;
- private String rootVersion;
- private String versionAdvice;
- private String rootName;
- private String executableName;
- private IVersionedId[] topLevel;
- private boolean start;
- private String[] nonRootFiles;
-
- /* (non-Javadoc)
- * @see org.apache.tools.ant.Task#execute()
- */
- public void execute() throws BuildException {
- try {
- initialize(getInfo());
- } catch (ProvisionException e) {
- throw new BuildException("Unable to configure repositories", e); //$NON-NLS-1$
- }
- createVersionAdvice();
- IPublisherAction[] actions = createActions();
- //TODO Do something with publisher result
- new Publisher(getInfo()).publish(actions, new NullProgressMonitor());
- }
-
- private IPublisherAction[] createActions() {
- if (operation == null)
- // TODO what to do in this case?
- return new IPublisherAction[] {};
- if (operation.equals("-update")) //$NON-NLS-1$
- // TODO fix this up. watch for circularities
- // return new IPublishingAction[] {new LocalUpdateSiteAction(operationValue)};
- return new IPublisherAction[] {};
- if (operation.equals("-source")) //$NON-NLS-1$
- // TODO what to do in this case?
- return new IPublisherAction[] {new EclipseInstallAction(operationValue, root, Version.parseVersion(rootVersion), rootName, executableName, flavor, topLevel, nonRootFiles, start)};
- // TODO what to do in this case?
- return new IPublisherAction[] {};
- }
-
- private void createVersionAdvice() {
- if (versionAdvice == null)
- return;
- // TODO read the version advice and add the IVersionAdvice
- }
-
- protected void initialize(PublisherInfo info) throws ProvisionException {
- if (inplace) {
- File sourceLocation = new File(source);
- if (metadataLocation == null)
- metadataLocation = sourceLocation.toURI();
- if (artifactLocation == null)
- artifactLocation = sourceLocation.toURI();
- info.setArtifactOptions(info.getArtifactOptions() | IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH);
- } else
- info.setArtifactOptions(info.getArtifactOptions() | IPublisherInfo.A_INDEX | IPublisherInfo.A_PUBLISH | IPublisherInfo.A_OVERWRITE);
- initializeRepositories(info);
- }
-
- public void setBase(String value) {
- source = value;
- }
-
- public void setBundles(String value) {
- //TODO Remove - currently exists for compatibility with generator task
- }
-
- public void setConfig(String value) {
- operation = "-config"; //$NON-NLS-1$
- operationValue = value;
- }
-
- public void setInplace(String value) {
- operation = "-inplace"; //$NON-NLS-1$
- operationValue = value;
- }
-
- public void setSource(String location) {
- super.source = location;
- operation = "-source"; //$NON-NLS-1$
- operationValue = location;
- }
-
- public void setUpdateSite(String value) {
- operation = "-update"; //$NON-NLS-1$
- operationValue = value;
- }
-
- /**
- * @deprecated
- */
- public void setExe(String value) {
- executableName = value;
- }
-
- public void setFeatures(String value) {
- //TODO Remove - currently exists for compatibility with generator task
- }
-
- public void setFlavor(String value) {
- flavor = value;
- }
-
- /**
- * @deprecated
- */
- public void setLauncherConfig(String value) {
- //TODO Remove - currently exists for compatibility with generator task
- }
-
- public void setNoDefaultIUs(String value) {
- //TODO Remove - currently exists for compatibility with generator task
- }
-
- /**
- * @deprecated
- */
- public void setP2OS(String value) {
- //TODO Remove - currently exists for compatibility with generator task
- }
-
- public void setProductFile(String file) {
- //TODO Remove - currently exists for compatibility with generator task
- }
-
- public void setPublishArtifactRepository(String value) {
- getInfo().setArtifactOptions(getInfo().getArtifactOptions() | IPublisherInfo.A_INDEX);
- }
-
- public void setPublishArtifacts(String value) {
- getInfo().setArtifactOptions(getInfo().getArtifactOptions() | IPublisherInfo.A_PUBLISH);
- }
-
- public void setRoot(String value) {
- root = value;
- }
-
- public void setRootVersion(String value) {
- rootVersion = value;
- }
-
- public void setMode(String value) {
- mode = value;
- }
-
- public void setVersionAdvice(String value) {
- versionAdvice = value;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/TaskMessages.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/TaskMessages.java
deleted file mode 100644
index 5edd9feea..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/TaskMessages.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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.internal.p2.publisher.ant;
-
-import org.eclipse.osgi.util.NLS;
-
-public class TaskMessages extends NLS {
- private static final String BUNDLE_NAME = "org.eclipse.equinox.internal.p2.publisher.ant.messages";//$NON-NLS-1$
-
- public static String exception_errorOccurredCallingGenerator;
- public static String exception_errorArtifactRepo;
- public static String exception_errorMetadataRepo;
-
- static {
- // load message values from bundle file
- NLS.initializeMessages(BUNDLE_NAME, TaskMessages.class);
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/messages.properties b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/messages.properties
deleted file mode 100644
index 2c2eb1c97..000000000
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/messages.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-###############################################################################
-# Copyright (c) 2008 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
-###############################################################################
-
-exception_errorOccurredCallingGenerator = An error occurred when calling generator.
-exception_errorArtifactRepo = Error setting artifact repository {0}.
-exception_errorMetadataRepo = Error setting metadata repository {0}.

Back to the top