diff options
author | Markus Knauer | 2007-03-27 15:55:35 +0000 |
---|---|---|
committer | Markus Knauer | 2007-03-27 15:55:35 +0000 |
commit | ff7bedcf7f28a6352f2f4b207b2c63346f146a89 (patch) | |
tree | cf74ea1a01a2c3159e0c9d3b31ea197a19c06179 /plugins/org.eclipse.epp.packaging.core | |
download | org.eclipse.epp.packages-ff7bedcf7f28a6352f2f4b207b2c63346f146a89.tar.gz org.eclipse.epp.packages-ff7bedcf7f28a6352f2f4b207b2c63346f146a89.tar.xz org.eclipse.epp.packages-ff7bedcf7f28a6352f2f4b207b2c63346f146a89.zip |
initial commit
Diffstat (limited to 'plugins/org.eclipse.epp.packaging.core')
48 files changed, 2796 insertions, 0 deletions
diff --git a/plugins/org.eclipse.epp.packaging.core/.classpath b/plugins/org.eclipse.epp.packaging.core/.classpath new file mode 100644 index 00000000..304e8618 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <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="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.epp.packaging.core/.project b/plugins/org.eclipse.epp.packaging.core/.project new file mode 100644 index 00000000..b5688ecf --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.epp.packaging.core</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.epp.packaging.core/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.epp.packaging.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..19f7f8ff --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Tue Mar 27 17:07:43 CEST 2007 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/plugins/org.eclipse.epp.packaging.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.epp.packaging.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000..2b53d4ef --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.epp.packaging.core;singleton:=true +Bundle-Version: 0.5.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.ant.core, + org.eclipse.update.core +Export-Package: org.eclipse.epp.packaging.core, + org.eclipse.epp.packaging.core.assembly, + org.eclipse.epp.packaging.core.configuration, + org.eclipse.epp.packaging.core.configuration.xml, + org.eclipse.epp.packaging.core.download, + org.eclipse.epp.packaging.core.io, + org.eclipse.epp.packaging.core.logging + diff --git a/plugins/org.eclipse.epp.packaging.core/about.html b/plugins/org.eclipse.epp.packaging.core/about.html new file mode 100644 index 00000000..94df2f61 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/about.html @@ -0,0 +1,17 @@ +<h3>About This Content</h3> + +<p>June 5, 2006</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). +Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor’s license +that was provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/build.properties b/plugins/org.eclipse.epp.packaging.core/build.properties new file mode 100644 index 00000000..bc3b0f2b --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html diff --git a/plugins/org.eclipse.epp.packaging.core/plugin.properties b/plugins/org.eclipse.epp.packaging.core/plugin.properties new file mode 100644 index 00000000..abf9d3ae --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/plugin.properties @@ -0,0 +1,16 @@ +############################################################################### +# Copyright (c) 2007 Innoopract Informationssysteme GmbH +# 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: +# Innoopract - initial API and implementation +############################################################################### + +# properties file for org.eclipse.epp.packaging.core +Bundle-Vendor = Eclipse.org +Bundle-Name = EPP Packaging Core + +product.name = EPP
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/plugin.xml b/plugins/org.eclipse.epp.packaging.core/plugin.xml new file mode 100644 index 00000000..8467070b --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/plugin.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + + <extension + id="application" + point="org.eclipse.core.runtime.applications"> + <application> + <run + class="org.eclipse.epp.packaging.core.Application"> + </run> + </application> + </extension> + <extension + id="EPP" + point="org.eclipse.core.runtime.products"> + <product + application="org.eclipse.packaging.application" + name="%product.name"> + <property + name="appName" + value="EPP"> + </property> + </product> + </extension> + +</plugin> diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/Application.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/Application.java new file mode 100644 index 00000000..99451a06 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/Application.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core; + +import org.eclipse.core.runtime.IPlatformRunnable; +import org.eclipse.epp.packaging.core.configuration.ArgumentParser; +import org.eclipse.epp.packaging.core.configuration.ICommands; +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.xml.ConfigurationParser; + +/** + * Main entry point for the EPP packager. + */ +public class Application implements IPlatformRunnable { + + /** + * Runs the Eclipse Packager. args is expected to be a conventional String + * array. The first entry must hold the location of the configuration + * properties file. + */ + public Object run( final Object args ) throws Exception { + ICommands commands = ArgumentParser.parse( args ); + IPackagerConfiguration configuration = new ConfigurationParser().parseConfiguration( commands.getConfigurationFile() ); + new EclipsePackagingExecutor( commands, configuration ).execute(); + return EXIT_OK; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/EclipsePackagingExecutor.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/EclipsePackagingExecutor.java new file mode 100644 index 00000000..a3e8402a --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/EclipsePackagingExecutor.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core; + +import java.io.IOException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.epp.packaging.core.assembly.EclipsePackager; +import org.eclipse.epp.packaging.core.assembly.InstallerPackager; +import org.eclipse.epp.packaging.core.assembly.PackageMover; +import org.eclipse.epp.packaging.core.configuration.ICommands; +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.Task; +import org.eclipse.epp.packaging.core.download.ExtensionSiteManager; +import org.eclipse.epp.packaging.core.download.IUpdateSiteManager; +import org.eclipse.epp.packaging.core.download.UpdateSiteManager; +import org.eclipse.epp.packaging.core.logging.MessageLogger; + +/**The main class, independent from the creation of the configuration and less dependent on the application/platformrunnable*/ +public class EclipsePackagingExecutor { + + private final ICommands commands; + private final IPackagerConfiguration configuration; + + public EclipsePackagingExecutor( final ICommands commands, + final IPackagerConfiguration configuration ) + { + this.commands = commands; + this.configuration = configuration; + } + + /**Run the packaging process*/ + public void execute() throws CoreException, IOException { + MessageLogger.getInstance() + .log( "Application.FeatureCount", //$NON-NLS-1$ + configuration.getRequiredFeatures().length ); + boolean doCheckOrInstall = commands.mustDo( Task.CHECK ) + || commands.mustDo( Task.INSTALL ); + if( doCheckOrInstall ) { + IUpdateSiteManager manager = new UpdateSiteManager( configuration ); + boolean areFeaturesPresent = manager.areFeaturesPresent( configuration.getRequiredFeatures() ); + if( areFeaturesPresent ) { + if( commands.mustDo( Task.INSTALL ) ) { + install( manager ); + } + build(); + } + } else { + build(); + } + } + + private void build() throws IOException, CoreException { + if( commands.mustDo( Task.BUILD ) ) { + MessageLogger.getInstance().logBeginProcess( "Application.Building" ); //$NON-NLS-1$ + new EclipsePackager( configuration ).packApplication(); + new PackageMover( configuration ).moveFiles(); + new InstallerPackager( configuration ).packApplication(); + MessageLogger.getInstance().logEndProcess(); + } + } + + /** + * Installs all requested features from the update sites to an extension + * location. + */ + private void install( final IUpdateSiteManager manager ) + throws IOException, CoreException + { + MessageLogger.getInstance().logBeginProcess( "Application.Installing" ); //$NON-NLS-1$ + new ExtensionSiteManager( configuration ).installFeatures( manager ); + MessageLogger.getInstance().logEndProcess(); + } +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/CustomTargetsWriter.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/CustomTargetsWriter.java new file mode 100644 index 00000000..4aa70fc8 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/CustomTargetsWriter.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.IPlatform; +import org.eclipse.epp.packaging.core.io.FileUtils; + +/** + * Completes the custom targets stub to form a customtargets.xml ant file. + * The targets added define the output files for each platform. + */ +public class CustomTargetsWriter { + + private final PrintWriter writer; + private final IPackagerConfiguration configuration; + + /** + * TODO mknauer missing doc + * @param configuration + * @param baseFile + * @throws IOException + */ + public CustomTargetsWriter( final IPackagerConfiguration configuration, + final String baseFile ) throws IOException + { + this.configuration = configuration; + File stubFile = new File( configuration.getPackagerConfigurationFolder(), + baseFile ); + File customTargetsFile = new File( configuration.getPackagerConfigurationFolder(), + "customTargets.xml" ); //$NON-NLS-1$ + FileUtils.copy( stubFile, customTargetsFile ); + FileOutputStream stream = new FileOutputStream( customTargetsFile, true ); + this.writer = new PrintWriter( stream ); + } + + /** + * TODO mknauer missing doc + * @param platform + */ + public void addTargetFileForPlatform( final IPlatform platform ) { + this.writer.append( "<target name=\"assemble." //$NON-NLS-1$ + + platform.toString( '.' ) + + ".xml\" depends=\"init\">\n" ); //$NON-NLS-1$ + this.writer.append( "<ant antfile=\"${assembleScriptName}\" >\n" ); //$NON-NLS-1$ + this.writer.append( "<property name=\"archiveName\" value=\"" //$NON-NLS-1$ + + platform.getTargetFileName( this.configuration ) + + platform.getArchiveFormat().getExtension() + + "\"/>\n" ); //$NON-NLS-1$ + this.writer.append( "</ant>\n" ); //$NON-NLS-1$ + this.writer.append( "</target>\n" ); //$NON-NLS-1$ + } + + /** + * TODO mknauer missing doc + */ + public void close() { + this.writer.append( "</project>\n" ); //$NON-NLS-1$ + this.writer.close(); + } +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/EclipsePackager.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/EclipsePackager.java new file mode 100644 index 00000000..577f0353 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/EclipsePackager.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.File; +import java.io.IOException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.IPlatform; +import org.eclipse.epp.packaging.core.io.FileUtils; +import org.eclipse.epp.packaging.core.io.Zip; +import org.eclipse.epp.packaging.core.logging.MessageLogger; +import org.eclipse.update.core.VersionedIdentifier; + +/** + * An IPackager using the main configuration as its argument. + */ +public class EclipsePackager implements IPackager { + + private static final String CONFIGURED_FEATURES_ZIP = "ConfiguredFeatures.zip"; //$NON-NLS-1$ + private static final String CONFIG_INI_ZIP = "ConfigIni.zip"; //$NON-NLS-1$ + private final PackagerRunner runner; + + /** + * TODO mknauer missing doc + * @param configuration + * @throws IOException + */ + public EclipsePackager( final IPackagerConfiguration configuration ) + throws IOException + { + this.runner = new PackagerRunner(); + setFolders( configuration ); + setFeatures( configuration ); + configurePlatforms( configuration ); + prepareWorkingArea( configuration ); + } + + /** Creates the map file in the workspace and clears the existing workarea. */ + private void prepareWorkingArea( final IPackagerConfiguration configuration ) + throws IOException + { + FileUtils.deleteFile( new File( configuration.getTargetFolder(), + "workingPlace" ) ); //$NON-NLS-1$ + MapFileWriter mapWriter = new MapFileWriter( configuration ); + PackagingPropertiesWriter propertiesWriter + = new PackagingPropertiesWriter( configuration, "packagingStub.properties" ); //$NON-NLS-1$ + CustomTargetsWriter customTargetsWriter + = new CustomTargetsWriter( configuration, "customTargetsStub.xml" ); //$NON-NLS-1$ + + for( IPlatform platform : configuration.getTargetPlatforms() ) { + mapWriter.addRootFileForPlatform( platform ); + propertiesWriter.addFileToOrder( platform.getRootFileName( configuration ) ); + customTargetsWriter.addTargetFileForPlatform( platform ); + } + + File sourceFolder = new File( configuration.getTargetFolder(), "src" ); //$NON-NLS-1$ + sourceFolder.mkdir(); + zipFeatures( sourceFolder, configuration ); + writeDataForCustomFile( CONFIGURED_FEATURES_ZIP, + mapWriter, + propertiesWriter ); + zipConfig( sourceFolder, configuration ); + writeDataForCustomFile( CONFIG_INI_ZIP, mapWriter, propertiesWriter ); + mapWriter.close(); + propertiesWriter.close(); + customTargetsWriter.close(); + } + + private void writeDataForCustomFile( final String filename, + final MapFileWriter mapWriter, + final PackagingPropertiesWriter propertiesWriter ) + { + mapWriter.addCustomFileForAllPlatforms( filename ); + propertiesWriter.addFileToOrder( filename ); + } + + private void zipConfig( final File parentFolder, + final IPackagerConfiguration configuration ) + throws IOException + { + String canonicalPath = configuration.getConfigIni().getCanonicalPath(); + MessageLogger.getInstance().log( "EclipsePackager.InjectIni", //$NON-NLS-1$ + canonicalPath ); + Zip zip = new Zip( parentFolder, CONFIG_INI_ZIP ); + zip.addFileAs( configuration.getConfigIni(), + "eclipse/configuration/config.ini" ); //$NON-NLS-1$ + zip.close(); + } + + /** + * Zips the requested features from the extension location into a single file. + */ + private void zipFeatures( final File parentFolder, + final IPackagerConfiguration configuration ) + throws IOException + { + MessageLogger.getInstance().logBeginProcess( "Application.Packing" ); //$NON-NLS-1$ + Zip zip = new Zip( parentFolder, CONFIGURED_FEATURES_ZIP ); + zip.addFolder( configuration.getExtensionSite() ); + zip.close(); + MessageLogger.getInstance().logEndProcess(); + } + + /** Sets the required folder info. */ + private void setFolders( final IPackagerConfiguration configuration ) + throws IOException + { + String packagerConfiguration + = configuration.getPackagerConfigurationFolder().getCanonicalPath(); + MessageLogger logger = MessageLogger.getInstance(); + + logger.log( "EclipsePackager.ConfigurationFolder", packagerConfiguration ); //$NON-NLS-1$ + this.runner.setConfigurationFolder( packagerConfiguration ); + + String targetFolder = configuration.getTargetFolder().getCanonicalPath(); + logger.log( "EclipsePackager.TargetFolder", targetFolder ); //$NON-NLS-1$ + this.runner.setBaseDirectory( targetFolder ); + } + + /** Sets the features to be included. */ + private void setFeatures( final IPackagerConfiguration configuration ) { + for( VersionedIdentifier identifier : configuration.getRequiredFeatures() ) + { + this.runner.addFeature( identifier.getIdentifier() ); + } + } + + /** Configures the runner with platform information from configuration. */ + private void configurePlatforms( final IPackagerConfiguration configuration ) + { + for( IPlatform platform : configuration.getTargetPlatforms() ) { + String platformString = platform.toString(); + this.runner.addPlatform( platformString ); + String archiveFormatName = platform.getArchiveFormat().name(); + this.runner.setArchiveFormat( platformString, archiveFormatName ); + } + } + + public void packApplication() throws CoreException, IOException { + MessageLogger.getInstance().logBeginProcess( "EclipsePackager.Running" ); //$NON-NLS-1$ + this.runner.packApplication(); + MessageLogger.getInstance().logEndProcess(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/IPackager.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/IPackager.java new file mode 100644 index 00000000..8a982d62 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/IPackager.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.IOException; + +import org.eclipse.core.runtime.CoreException; + +/** + * Implementors know how to package an RCP Application. + */ +public interface IPackager { + + /** + * Begins the packing process. + * TODO mknauer missing doc + * @throws CoreException + * @throws IOException + */ + public void packApplication() throws CoreException, IOException; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/InstallerPackager.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/InstallerPackager.java new file mode 100644 index 00000000..d365fc3c --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/InstallerPackager.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.IOException; + +import org.eclipse.ant.core.AntRunner; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.IPlatform; + +/** + * An IPackager to interface with the Instantiations-contributed installer + * framework. + */ +public class InstallerPackager implements IPackager { + + private static final String INSTALLER_PLUGIN_ID = "com.instantiations.installer"; //$NON-NLS-1$ + private final IPackagerConfiguration configuration; + + /** + * TODO mknauer missing doc + * @param configuration + */ + public InstallerPackager( final IPackagerConfiguration configuration ) { + this.configuration = configuration; + } + + /** + * Creates the installers. Requires the packager-generated archives to be + * present as input source. + */ + public void packApplication() throws IOException, CoreException { + for( IPlatform platform : this.configuration.getTargetPlatforms() ) { + AntRunner runner = new AntRunner(); + runner.setBuildFileLocation( getBuildScript( platform ) ); + System.setProperty( "build.root", //$NON-NLS-1$ + this.configuration.getTargetFolder().getAbsolutePath() ); + System.setProperty( "product.name", //$NON-NLS-1$ + "Install-" //$NON-NLS-1$ + + platform.getTargetFileName( this.configuration ) ); + System.setProperty( "install.tools", //$NON-NLS-1$ + PluginUtils.getPluginPath( INSTALLER_PLUGIN_ID ) + + "/" ); //$NON-NLS-1$ + System.setProperty( "install.image", //$NON-NLS-1$ + this.configuration.getTargetFolder() + "/" //$NON-NLS-1$ + + platform.getTargetFileName( this.configuration ) + + platform.getArchiveFormat().getExtension() ); + runner.setExecutionTargets( new String[]{ + getAntTarget( platform ) + } ); + runner.run(); + } + } + + private String getAntTarget( final IPlatform platform ) { + String target = null; + switch( platform.getArchiveFormat() ) { + case antZip: { + target = "build_installer_from_zip"; //$NON-NLS-1$ + break; + } + case tar: { + target = "build_installer_from_tar"; //$NON-NLS-1$ + break; + } + } + return target; + } + + private String getBuildScript( final IPlatform platform ) { + String folder = this.configuration.getInstallerConfigurationFolder() + "/"; //$NON-NLS-1$ + return folder + platform.getInstallScriptName(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/MapFileWriter.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/MapFileWriter.java new file mode 100644 index 00000000..fa7f5022 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/MapFileWriter.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; + +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.IPlatform; + +/** + * Creates a packager map file in the workspace. + */ +public class MapFileWriter { + + private final static String MAP_FILE_LINE_END = " | | sdk | eclipse\n"; //$NON-NLS-1$ + private final IPackagerConfiguration configuration; + private final PrintWriter writer; + + /** + * TODO mknauer missing doc + * @param configuration + * @throws IOException + */ + public MapFileWriter( final IPackagerConfiguration configuration ) + throws IOException + { + this.configuration = configuration; + File parent = new File( configuration.getTargetFolder(), "toPackage" ); //$NON-NLS-1$ + parent.mkdir(); + this.writer = new PrintWriter( new File( parent, "PackagerMap.map" ) ); //$NON-NLS-1$ + } + + /** + * TODO mknauer missing doc + * @param platform + */ + public void addRootFileForPlatform( final IPlatform platform ) { + String rootFileFolder = this.configuration.getRootFileFolder().toURI().toString(); + String rootFileName = platform.getRootFileName( this.configuration ); + this.writer.append( rootFileName + "=" //$NON-NLS-1$ + + rootFileFolder + + " | " //$NON-NLS-1$ + + platform.toString() + + MAP_FILE_LINE_END ); + } + + /** + * Adds the given file name to the map. The file is expected to reside in the + * 'src' folder in the workspace. It is designated as valid for all configured + * platforms. + * + * TODO mknauer missing doc + * + * @param filename + */ + public void addCustomFileForAllPlatforms( final String filename ) { + File targetFolder = this.configuration.getTargetFolder(); + String sourceFolder = new File( targetFolder, "src" ).toURI().toString(); //$NON-NLS-1$ + this.writer.append( filename + + "=" //$NON-NLS-1$ + + sourceFolder + + " | " //$NON-NLS-1$ + + getAllPlatformsString() + + MAP_FILE_LINE_END ); + } + + /** + * TODO mknauer missing doc + */ + public void close() { + this.writer.close(); + } + + private String getAllPlatformsString() { + StringBuilder builder = new StringBuilder(); + IPlatform[] platforms = this.configuration.getTargetPlatforms(); + for( int index = 0; index < platforms.length; index++ ) { + builder.append( platforms[ index ].toString() ); + if( index < platforms.length - 1 ) { + builder.append( '&' ); + } + } + return builder.toString(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackageMover.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackageMover.java new file mode 100644 index 00000000..f6678517 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackageMover.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; + +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.IPlatform; +import org.eclipse.epp.packaging.core.io.FileUtils; +import org.eclipse.epp.packaging.core.logging.MessageLogger; + +/** + * Moves the created packages from the packager's work directory to the main + * folder specified in the configuration. + */ +public class PackageMover { + + private final IPackagerConfiguration configuration; + + /** + * TODO mknauer missing doc + * @param configuration + */ + public PackageMover( final IPackagerConfiguration configuration ) { + this.configuration = configuration; + } + + /** + * TODO mknauer missing doc + * Moves the created packages to their final location. + * @throws IOException + */ + public void moveFiles() throws IOException { + MessageLogger.getInstance().logBeginProcess( "PackageMover.MovingFiles" ); //$NON-NLS-1$ + File packageLocation = new File( this.configuration.getTargetFolder(), + "workingPlace/I.EclipsePackagerBuild" ); //$NON-NLS-1$ + for( IPlatform platform : this.configuration.getTargetPlatforms() ) { + File applicationFile = findPlatformFile( packageLocation, platform ); + FileUtils.copy( applicationFile, + new File( this.configuration.getTargetFolder(), + applicationFile.getName() ) ); + } + MessageLogger.getInstance().logEndProcess(); + } + + /** Returns the created package for the given platform. */ + private File findPlatformFile( final File packageLocation, + final IPlatform platform ) + { + final String name = platform.getTargetFileName( this.configuration ) + + platform.getArchiveFormat().getExtension(); + File[] files = packageLocation.listFiles( new FileFilter() { + + public boolean accept( final File file ) { + return file.getName().equals( name ); + } + } ); + if( files.length != 1 ) { + throw new IllegalStateException( files.length + + " packages found for " //$NON-NLS-1$ + + platform + + ". There should be one, and only one." //$NON-NLS-1$ + ); + } + return files[ 0 ]; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackagerRunner.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackagerRunner.java new file mode 100644 index 00000000..8976e658 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackagerRunner.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.ant.core.AntRunner; +import org.eclipse.core.runtime.CoreException; + +/** + * An IPackager based on the PDE Build packager. Locates, configures and + * executes the package.xml ant script + */ +public class PackagerRunner implements IPackager { + + private static final String ARGUMENT_ARCHIVE_FORMATS = "archivesFormat"; //$NON-NLS-1$ + private static final String ARGUMENT_BASE_DIRECTORY = "baseDirectory";//$NON-NLS-1$ + private static final String ARGUMENT_CONFIGURATION_FOLDER = "packagingInfo";//$NON-NLS-1$ + private static final String ARGUMENT_FEATURE_LIST = "featureList";//$NON-NLS-1$ + private static final String ARGUMENT_PLATFORM_LIST = "config";//$NON-NLS-1$ + private static final String PDE_BUILD_PLUGIN_ID = "org.eclipse.pde.build";//$NON-NLS-1$ + private final List<String> features = new ArrayList<String>(); + private final List<String> platforms = new ArrayList<String>(); + private final List<String> formats = new ArrayList<String>(); + + public void packApplication() throws CoreException, IOException { + AntRunner runner = new AntRunner(); + String scriptLocation = PluginUtils.getPluginPath( PDE_BUILD_PLUGIN_ID ) + + "/scripts/package.xml";//$NON-NLS-1$ + runner.setBuildFileLocation( scriptLocation ); + addFeatureListToArguments(); + addPlatformListToArguments(); + addFormatListToArguments(); + runner.run(); + } + + /** + * Prior to running the packager, convert the list of archive formats to an + * argument string and add it to the list of arguments. + */ + private void addFormatListToArguments() { + addListToArguments( this.formats, '&', ARGUMENT_ARCHIVE_FORMATS ); + } + + /** + * Prior to running the packager, convert the list of platforms to an argument + * string and add it to the list of arguments. + */ + private void addPlatformListToArguments() { + addListToArguments( this.platforms, '&', ARGUMENT_PLATFORM_LIST ); + } + + /** + * Prior to running the packager, convert the list of features to an argument + * string and add it to the list of arguments. + */ + private void addFeatureListToArguments() { + addListToArguments( this.features, ',', ARGUMENT_FEATURE_LIST ); + } + + /** + * Converts the source list to a string with the entries separated by + * separator, then sets the result as a value for the argument. + */ + private void addListToArguments( final List<String> sourceList, + final char separator, + final String argumentName ) + { + StringBuilder builder = new StringBuilder(); + for( String feature : sourceList ) { + builder.append( feature ); + builder.append( separator ); + } + setArgument( argumentName, builder.toString() ); + } + + /** + * Sets the configuration folder for the PDE packager. The folder must contain + * packager.properties, packaging.properties and customTargets.xml. + * + * @param folder directory name + */ + public void setConfigurationFolder( final String folder ) { + setArgument( ARGUMENT_CONFIGURATION_FOLDER, folder ); + } + + /** Sets the working directory for the PDE packager. + * @param folder directory name of the base directory + */ + public void setBaseDirectory( final String folder ) { + setArgument( ARGUMENT_BASE_DIRECTORY, folder ); + } + + /** + * Adds a feature to the configured application. + * + * @param identifier The feature id. + */ + public void addFeature( final String identifier ) { + this.features.add( identifier ); + } + + /** Sets an argument for the AntRunner to use. */ + private void setArgument( final String key, final String value ) { + System.setProperty( key, value ); + } + + /** + * Adds a new target platform to the configuration. + * + * @param platform A comma-separated platform description (os,ws,arch). + */ + public void addPlatform( final String platform ) { + this.platforms.add( platform ); + } + + /** + * Sets a platform's archive format. + * + * @param platform A comma-separated platform description - os,ws,arch. + * @param format An archive format. Supported values are antZip, antTar, tar. + */ + public void setArchiveFormat( final String platform, final String format ) { + this.formats.add( platform + '-' + format ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackagingPropertiesWriter.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackagingPropertiesWriter.java new file mode 100644 index 00000000..e55bf7c8 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PackagingPropertiesWriter.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.io.FileUtils; + +/** + * Completes the packaging.properties file by adding the unzipOrder property. + */ +public class PackagingPropertiesWriter { + + private static final String UNZIP_ORDER_PROPERTY = "unzipOrder"; //$NON-NLS-1$ + private static final String PACKAGING_PROPERTIES_FILENAME = "packaging.properties"; //$NON-NLS-1$ + private final PrintWriter writer; + private boolean firstName = true; + + /** + * TODO mknauer missing doc + * @param configuration + * @param baseFile + * @throws IOException + */ + public PackagingPropertiesWriter( final IPackagerConfiguration configuration, + final String baseFile ) throws IOException + { + File stubFile = new File( configuration.getPackagerConfigurationFolder(), + baseFile ); + File packagingFile = new File( configuration.getPackagerConfigurationFolder(), + PACKAGING_PROPERTIES_FILENAME ); + FileUtils.copy( stubFile, packagingFile ); + FileOutputStream stream = new FileOutputStream( packagingFile, true ); + this.writer = new PrintWriter( stream ); + this.writer.append( UNZIP_ORDER_PROPERTY + '=' ); + } + + /** + * TODO mknauer missing doc + * @param fileName + */ + public void addFileToOrder( final String fileName ) { + if( !this.firstName ) { + this.writer.append( ',' ); + } else { + this.firstName = false; + } + this.writer.append( fileName ); + } + + /** + * TODO mknauer missing doc + */ + public void close() { + this.writer.close(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PluginUtils.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PluginUtils.java new file mode 100644 index 00000000..39448ace --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/assembly/PluginUtils.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.assembly; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.service.datalocation.Location; + +/** + * Utility class for Plugin-related tasks. + */ +public class PluginUtils { + + /** Locates the given plugin in the install location. + * + * TODO mknauer missing doc + * @param pluginId + * @return plugin path + * @throws IOException + */ + // This could be done via SiteManager and featurereferences, if the + // application was feature-based, not plugin-based. + public static String getPluginPath( final String pluginId ) throws IOException { + Location installLocation = Platform.getInstallLocation(); + String locationFile = installLocation.getURL().getFile(); + File file = new File( locationFile, "plugins" ); //$NON-NLS-1$ + String result = null; + for( File pluginFile : file.listFiles() ) { + if( pluginFile.getName().startsWith( pluginId ) ) { + result = pluginFile.getCanonicalPath(); + } + } + if( result == null ) { + throw new IllegalStateException( "Required plug-in " //$NON-NLS-1$ + + pluginId + + " not found in folder " //$NON-NLS-1$ + + locationFile + + "plugins." ); //$NON-NLS-1$ + } + return result; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ArchiveFormat.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ArchiveFormat.java new file mode 100644 index 00000000..072b796c --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ArchiveFormat.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +/** + * Enumerates the archive formats. "antTar" will not be available until + * http://issues.apache.org/bugzilla/show_bug.cgi?id=39617 and + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=142792 are fixed. + */ +public enum ArchiveFormat { + tar { + + @Override + public String getExtension() + { + return ".tar.gz"; //$NON-NLS-1$ + } + }, + + antZip { + + @Override + public String getExtension() + { + return ".zip"; //$NON-NLS-1$ + } + }; + + public abstract String getExtension(); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ArgumentParser.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ArgumentParser.java new file mode 100644 index 00000000..ce8bc251 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ArgumentParser.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +/** + * Parses the arguments given to the main application. + */ +public class ArgumentParser { + + /** + * @throws IllegalArgumentException if arguments is no array of strings. + */ + public static ICommands parse( final Object arguments ) { + String[] strings; + try { + strings = ( String[] )arguments; + } catch( ClassCastException exception ) { + throw new IllegalArgumentException( "Arguments must be an array of String.", exception ); //$NON-NLS-1$ + } + Commands command = new Commands(); + command.setConfigurationFile( strings[ 0 ] ); + if( strings.length > 1 ) { + String[] tasks = new String[ strings.length - 1 ]; + System.arraycopy( strings, 1, tasks, 0, tasks.length ); + command.setTasks( tasks ); + } + return command; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Commands.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Commands.java new file mode 100644 index 00000000..58811396 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Commands.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Configurable default implementation of ICommands. + */ +public class Commands implements ICommands { + + private File file; + private Task[] tasks = Task.values(); + + public File getConfigurationFile() { + return file; + } + + public void setConfigurationFile( final String fileName ) { + this.file = new File( fileName ); + } + + public boolean mustDo( final Task task ) { + boolean result = false; + for( Task configuredTask : tasks ) { + result |= configuredTask.equals( task ); + } + return result; + } + + public void setTasks( final String[] tasks ) { + List<Task> taskList = new ArrayList<Task>(); + for( String task : tasks ) { + taskList.add( Task.valueOf( task.toUpperCase() ) ); + } + this.tasks = taskList.toArray( new Task[ taskList.size() ] ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ICommands.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ICommands.java new file mode 100644 index 00000000..4917c701 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/ICommands.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +import java.io.File; + +/** + * Object representation of arguments given to the program. + */ +public interface ICommands { + + public File getConfigurationFile(); + + public boolean mustDo( Task task ); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IModifiablePackagerConfiguration.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IModifiablePackagerConfiguration.java new file mode 100644 index 00000000..c4b94ed4 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IModifiablePackagerConfiguration.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +import java.net.MalformedURLException; + +/** + * A packager configuration that allows to modify its settings. + */ +public interface IModifiablePackagerConfiguration + extends IPackagerConfiguration +{ + + /**Adds an update site to the configuration. + * + * @param string A string containing the URL of the site. + * @throws MalformedURLException if the URL is invalid. + */ + public void addUpdateSite( final String string ) throws MalformedURLException; + + /**Adds the feature [id] with the given version to the list of required features.*/ + public void addRequiredFeature( final String id, final String version ); + + /**Sets the designated folder containing the PDE packager config files.*/ + public void setPackagerConfigurationFolder( final String folder ); + + /**Sets the extension site's name in the target folder.*/ + public void setExtensionSiteRelative( final String relativeFolder ); + + /**Adds a new target platform.*/ + public Platform addTargetPlatform( final String os, + final String ws, + final String arch ); + + /**Sets the RCP version to use.*/ + public void setRcpVersion( final String version ); + + /**Sets the folder containing the RCP root files.*/ + public void setRootFileFolder( final String folderName ); + + /**Sets the config.ini file to use.*/ + public void setConfigIni( final String fileName ); + + /**Sets the product name to use for the final result.*/ + public void setProductName( final String name ); + + /**Sets the folder containing the configuration files for the installer.*/ + public void setInstallerConfigurationFolder( final String folder ); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IPackagerConfiguration.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IPackagerConfiguration.java new file mode 100644 index 00000000..ae6be3a2 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IPackagerConfiguration.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +import java.io.File; +import java.net.URL; +import org.eclipse.update.core.VersionedIdentifier; + +/** + * Provides all data the Eclipse Packager requires to run. + */ +public interface IPackagerConfiguration { + + public URL[] getUpdateSites(); + + public VersionedIdentifier[] getRequiredFeatures(); + + public File getPackagerConfigurationFolder(); + + public String getInstallerConfigurationFolder(); + + public File getTargetFolder(); + + public File getExtensionSite(); + + public IPlatform[] getTargetPlatforms(); + + public String getRootFileBaseName(); + + public File getRootFileFolder(); + + public File getConfigIni(); + + public String getProductName(); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IPlatform.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IPlatform.java new file mode 100644 index 00000000..42c405bd --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/IPlatform.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +/** + * Represents a platform configuration, consisting of operating system (os), + * window system (ws) and system architecture (arch). + */ +public interface IPlatform { + + public ArchiveFormat getArchiveFormat(); + + /** + * Returns the platform components separated by the separator. Example: + * toString(".") for linux,gtk,x86 return "linux.gtk.x86". + * + * @param separator A separator character + * @return The platform description formatted as + * [OS][separator][WS][separator][Arch] + */ + public String toString( char separator ); + + /** + * Builds the file name of the platform files for this platform, using the + * base name provided in configuration. + */ + public String getRootFileName( IPackagerConfiguration configuration ); + + /** Configures the SiteManager to use platform as its current one. */ + public void configureSite(); + + /** + * Builds and returns the filename of the target archive for this platform, + * using the base name provided in configuration. + */ + public String getTargetFileName( IPackagerConfiguration configuration ); + + /** Returns the name installer-creating script most suitable for this platform. */ + public String getInstallScriptName(); +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/PackagerConfiguration.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/PackagerConfiguration.java new file mode 100644 index 00000000..c5624586 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/PackagerConfiguration.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.update.core.VersionedIdentifier; + +/** + * A configurable IPackagerConfiguration. All data is handed in as String, then + * converted to the proper objects. + */ +public class PackagerConfiguration implements IModifiablePackagerConfiguration { + + private final List<URL> updateSites = new ArrayList<URL>(); + private final List<VersionedIdentifier> requiredFeatures = new ArrayList<VersionedIdentifier>(); + private final List<Platform> targetPlatforms = new ArrayList<Platform>(); + private File packagerConfigurationFolder; + private File baseFolder; + private File extensionSite; + private String rcpVersion; + private File rootFolder; + private File configIni; + private String productName; + private String installerConfigurationFolder; + + public PackagerConfiguration() { + this.baseFolder = org.eclipse.core.runtime.Platform.getLocation().toFile(); + } + + public URL[] getUpdateSites() { + return updateSites.toArray( new URL[ updateSites.size() ] ); + } + + public void addUpdateSite( final String string ) throws MalformedURLException + { + updateSites.add( new URL( string ) ); + } + + public VersionedIdentifier[] getRequiredFeatures() { + return requiredFeatures.toArray( new VersionedIdentifier[ requiredFeatures.size() ] ); + } + + public void addRequiredFeature( final String id, final String version ) { + requiredFeatures.add( new VersionedIdentifier( id, version ) ); + } + + public File getPackagerConfigurationFolder() { + return packagerConfigurationFolder; + } + + public void setPackagerConfigurationFolder( final String folder ) { + this.packagerConfigurationFolder = new File( folder ); + } + + public File getTargetFolder() { + return baseFolder; + } + + public void setExtensionSiteRelative( final String relativeFolder ) { + this.extensionSite = new File( baseFolder, relativeFolder ); + } + + public File getExtensionSite() { + return extensionSite; + } + + public Platform addTargetPlatform( final String os, + final String ws, + final String arch ) + { + Platform platform = new Platform( os, ws, arch ); + targetPlatforms.add( platform ); + return platform; + } + + public IPlatform[] getTargetPlatforms() { + return targetPlatforms.toArray( new IPlatform[ targetPlatforms.size() ] ); + } + + public String getRootFileBaseName() { + return "eclipse-RCP-" + rcpVersion + '-'; //$NON-NLS-1$ + } + + public File getRootFileFolder() { + return rootFolder; + } + + public void setRcpVersion( final String version ) { + this.rcpVersion = version; + } + + public void setRootFileFolder( final String folderName ) { + this.rootFolder = new File( folderName ); + } + + public File getConfigIni() { + return configIni; + } + + public void setConfigIni( final String fileName ) { + this.configIni = new File( fileName ); + } + + public void setProductName( final String name ) { + this.productName = name; + } + + public String getProductName() { + return productName; + } + + public String getInstallerConfigurationFolder() { + return installerConfigurationFolder; + } + + public void setInstallerConfigurationFolder( final String folder ) { + this.installerConfigurationFolder = folder; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Platform.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Platform.java new file mode 100644 index 00000000..9f31cdfa --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Platform.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +import static org.eclipse.core.runtime.Platform.ARCH_X86; +import static org.eclipse.core.runtime.Platform.ARCH_X86_64; +import static org.eclipse.core.runtime.Platform.OS_LINUX; +import static org.eclipse.core.runtime.Platform.OS_WIN32; +import static org.eclipse.core.runtime.Platform.WS_GTK; +import org.eclipse.update.core.SiteManager; + +/** + * Represents a platform configuration, consisting of operating system (os), + * windowing system (ws) and system architecture (arch). Default implementation + * of IPlatform. + */ +public class Platform implements IPlatform { + + private final String os; + private final String ws; + private final String arch; + private ArchiveFormat archiveFormat = ArchiveFormat.antZip; + + public Platform( final String os, final String ws, final String arch ) { + this.os = os; + this.ws = ws; + this.arch = arch; + } + + @Override + public boolean equals( final Object obj ) { + boolean result = false; + if( obj instanceof Platform ) { + Platform other = ( Platform )obj; + result = os.equals( other.os ) + && ws.equals( other.ws ) + && arch.equals( other.arch ); + } + return result; + } + + public String toString( final char separator ) { + return os + separator + ws + separator + arch; + } + + /** Identical with toString(',) */ + @Override + public String toString() { + return toString( ',' ); + } + + public ArchiveFormat getArchiveFormat() { + return archiveFormat; + } + + public void setArchiveFormat( final String format ) { + this.archiveFormat = ArchiveFormat.valueOf( format ); + } + + public void configureSite() { + SiteManager.setOS( os ); + SiteManager.setWS( ws ); + SiteManager.setOSArch( arch ); + } + + // Requires PDE Build with up-to-date unzippergenerator. + public String getRootFileName( final IPackagerConfiguration configuration ) { + StringBuilder builder = new StringBuilder( configuration.getRootFileBaseName() ); + builder.append( os ); + boolean isWin32 = isWin32(); + if( !isWin32 ) { + builder.append( '-' ); + builder.append( ws ); + } + boolean isLinuxGtk = isLinux() && WS_GTK.endsWith( ws ); + if( ( isWin32 || isLinuxGtk ) && !isX86() ) { + builder.append( '-' ); + builder.append( arch ); + } + builder.append( archiveFormat.getExtension() ); + return builder.toString(); + } + + private boolean isLinux() { + return OS_LINUX.equals( os ); + } + + private boolean isX86() { + return ARCH_X86.equals( arch ); + } + + private boolean isWin32() { + return OS_WIN32.equals( os ); + } + + public String getTargetFileName( final IPackagerConfiguration configuration ) + { + return configuration.getProductName() + "-" //$NON-NLS-1$ + + toString( '.' ); + } + + public String getInstallScriptName() { + String buildFile; + boolean isWin32x86 = isWin32() && isX86(); + boolean isLinuxX86 = isLinux() && ( isX86() || ARCH_X86_64.equals( arch ) ); + if( ( isWin32x86 || isLinuxX86 ) ) { + buildFile = "build-installer-" + os + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$ + } else { + buildFile = "build-installer-default.xml"; //$NON-NLS-1$ + } + return buildFile; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Task.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Task.java new file mode 100644 index 00000000..4a863132 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/Task.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration; + +/** + * Enumerates the three tasks known to the Eclipse Packager. + */ +public enum Task { + /** Verifies requested features against the installation sites. */ + CHECK, + /** Installs the requested features to the local extension site. */ + INSTALL, + /** Builds the application from the requested features and the root files. */ + BUILD +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/ConfigurationParser.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/ConfigurationParser.java new file mode 100644 index 00000000..b013a1cc --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/ConfigurationParser.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration.xml; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; + +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.PackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.Platform; +import org.xml.sax.SAXException; + +/** + * Parses an Eclipse Packager configuration in XML format. + */ +public class ConfigurationParser { + + private static final String ATTRIB_ARCH = "arch"; //$NON-NLS-1$ + private static final String ATTRIB_FOLDER = "folder"; //$NON-NLS-1$ + private static final String ATTRIB_FORMAT = "format"; //$NON-NLS-1$ + private static final String ATTRIB_ID = "id"; //$NON-NLS-1$ + private static final String ATTRIB_OS = "os"; //$NON-NLS-1$ + private static final String ATTRIB_RELATIVE_FOLDER = "relativeFolder"; //$NON-NLS-1$ + private static final String ATTRIB_URL = "url"; //$NON-NLS-1$ + private static final String ATTRIB_VERSION = "version"; //$NON-NLS-1$ + private static final String ATTRIB_WS = "ws"; //$NON-NLS-1$ + private static final String TAG_ARCHIVE_FORMAT = "archiveFormat"; //$NON-NLS-1$ + private static final String TAG_EXTENSION_SITE = "extensionSite"; //$NON-NLS-1$ + private static final String TAG_FEATURE = "feature"; //$NON-NLS-1$ + private static final String TAG_PACKAGER_CONFIGURATION_FOLDER = "packagerConfigurationFolder"; //$NON-NLS-1$ + private static final String TAG_INSTALLER_CONFIGURATION_FOLDER = "installerConfigurationFolder"; //$NON-NLS-1$ + private static final String TAG_PLATFORM = "platform"; //$NON-NLS-1$ + private static final String TAG_RCP = "rcp"; //$NON-NLS-1$ + private static final String TAG_REQUIRED_FEATURES = "requiredFeatures"; //$NON-NLS-1$ + private static final String TAG_ROOT_FILE_FOLDER = "rootFileFolder"; //$NON-NLS-1$ + private static final String TAG_TARGET_PLATFORMS = "targetPlatforms"; //$NON-NLS-1$ + private static final String TAG_UPDATE_SITE = "updateSite"; //$NON-NLS-1$ + private static final String TAG_UPDATE_SITES = "updateSites"; //$NON-NLS-1$ + private static final String TAG_PRODUCT = "product"; //$NON-NLS-1$ + private static final String ATTRIB_CONFIG_INI = "configIni"; //$NON-NLS-1$ + private static final String ATTRIB_NAME = "name"; //$NON-NLS-1$ + + /** + * Parses the configuration contained in xmlFile. + */ + public IPackagerConfiguration parseConfiguration( final File xmlFile ) + throws SAXException, IOException, ParserConfigurationException + { + return parseConfiguration( new XMLDocument( xmlFile ).getRootElement() ); + } + + /** + * Parses the configuration-string xml. Used in tests only. + */ + public IPackagerConfiguration parseConfiguration( final String xml ) + throws MalformedURLException, SAXException, IOException, + ParserConfigurationException + { + return parseConfiguration( new XMLDocument( xml ).getRootElement() ); + } + + /** + * Reads the various elements of the configuration from the root element. + * + * @throws MalformedURLException + */ + private IPackagerConfiguration parseConfiguration( final IXmlElement root ) + throws MalformedURLException + { + PackagerConfiguration configuration = new PackagerConfiguration(); + parseRcp( configuration, root ); + parseProduct( configuration, root ); + parseUpdateSites( configuration, root ); + parseRequiredFeatures( configuration, root ); + parsePackagerConfigurationFolder( configuration, root ); + parseInstallerConfigurationFolder( configuration, root ); + parseRootFolder( configuration, root ); + parseExtensionSite( configuration, root ); + parsePlatforms( configuration, root ); + return configuration; + } + + private void parseRcp( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + String rcpVersion = parent.getElement( TAG_RCP ) + .getAttributeValue( ATTRIB_VERSION ); + configuration.setRcpVersion( rcpVersion ); + } + + private void parseProduct( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement productElement = parent.getElement( TAG_PRODUCT ); + configuration.setProductName( productElement.getAttributeValue( ATTRIB_NAME ) ); + String configIni = productElement.getAttributeValue( ATTRIB_CONFIG_INI ); + configuration.setConfigIni( configIni ); + } + + /** Loads and sets the target platforms. */ + private void parsePlatforms( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement element = parent.getElement( TAG_TARGET_PLATFORMS ); + for( IXmlElement platformElement : getElements( element, TAG_PLATFORM ) ) { + String os = platformElement.getAttributeValue( ATTRIB_OS ); + String ws = platformElement.getAttributeValue( ATTRIB_WS ); + String arch = platformElement.getAttributeValue( ATTRIB_ARCH ); + Platform platform = configuration.addTargetPlatform( os, ws, arch ); + IXmlElement archiveFormat = platformElement.getElement( TAG_ARCHIVE_FORMAT ); + if( archiveFormat != null ) { + platform.setArchiveFormat( archiveFormat.getAttributeValue( ATTRIB_FORMAT ) ); + } + } + } + + /** Loads and sets the required features. */ + private void parseRequiredFeatures( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement element = parent.getElement( TAG_REQUIRED_FEATURES ); + for( IXmlElement featureElement : getElements( element, TAG_FEATURE ) ) { + configuration.addRequiredFeature( featureElement.getAttributeValue( ATTRIB_ID ), + featureElement.getAttributeValue( ATTRIB_VERSION ) ); + } + } + + /** + * Loads and sets the available update sites. + * + * @throws MalformedURLException + */ + private void parseUpdateSites( final PackagerConfiguration configuration, + final IXmlElement parent ) + throws MalformedURLException + { + IXmlElement element = parent.getElement( TAG_UPDATE_SITES ); + for( IXmlElement siteElement : getElements( element, TAG_UPDATE_SITE ) ) { + configuration.addUpdateSite( siteElement.getAttributeValue( ATTRIB_URL ) ); + } + } + + /** Loads and sets the extension site to use. */ + private void parseExtensionSite( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement element = parent.getElement( TAG_EXTENSION_SITE ); + configuration.setExtensionSiteRelative( element.getAttributeValue( ATTRIB_RELATIVE_FOLDER ) ); + } + + /** Loads and sets the packager configuration folder to use. */ + private void parsePackagerConfigurationFolder( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement element = parent.getElement( TAG_PACKAGER_CONFIGURATION_FOLDER ); + configuration.setPackagerConfigurationFolder( getFolderName( element ) ); + } + + /** Loads and sets the installer configuration folder to use. */ + private void parseInstallerConfigurationFolder( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement element = parent.getElement( TAG_INSTALLER_CONFIGURATION_FOLDER ); + configuration.setInstallerConfigurationFolder( getFolderName( element ) ); + } + + /** Loads and sets the folder containing the root files. */ + private void parseRootFolder( final PackagerConfiguration configuration, + final IXmlElement parent ) + { + IXmlElement element = parent.getElement( TAG_ROOT_FILE_FOLDER ); + configuration.setRootFileFolder( getFolderName( element ) ); + } + + private String getFolderName( final IXmlElement element ) { + return element.getAttributeValue( ATTRIB_FOLDER ); + } + + private IXmlElement[] getElements( final IXmlElement element, + final String name ) + { + return element.getElements( name ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/IXmlElement.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/IXmlElement.java new file mode 100644 index 00000000..afff8db1 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/IXmlElement.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration.xml; + +/** An XML Element with sub elements and attributes. */ +public interface IXmlElement { + + /** + * Returns all descendant elements of this element whose name equals the given + * name. + */ + public IXmlElement[] getElements( String tagName ); + + /** + * Returns the value of the given attribute. + */ + public String getAttributeValue( String attributeName ); + + /** + * Returns the first descendant element of the given name or <code>null</code>, + * if none exist. + */ + public IXmlElement getElement( String tagName ); +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/XMLDocument.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/XMLDocument.java new file mode 100644 index 00000000..974f9fee --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/XMLDocument.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration.xml; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** An XML document based on W3C DOM */ +public class XMLDocument { + + private final Document document; + + public XMLDocument( final File xmlFile ) + throws SAXException, IOException, ParserConfigurationException + { + this.document = DocumentBuilderFactory.newInstance() + .newDocumentBuilder() + .parse( xmlFile ); + } + + /** @param A string with XML data */ + public XMLDocument( final String xmlString ) + throws SAXException, IOException, ParserConfigurationException + { + this.document = DocumentBuilderFactory.newInstance() + .newDocumentBuilder() + .parse( new ByteArrayInputStream( xmlString.getBytes() ) ); + } + + /** Returns the root element of this document. */ + public IXmlElement getRootElement() { + return new XmlElement( ( Element )document.getFirstChild() ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/XmlElement.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/XmlElement.java new file mode 100644 index 00000000..34cf4614 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/configuration/xml/XmlElement.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.configuration.xml; + +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** XML Element implementation using an underlying W3C DOM Element. */ +public class XmlElement implements IXmlElement { + + private final Element node; + + public XmlElement( final Element node ) { + this.node = node; + } + + public String getAttributeValue( final String attributeName ) { + return node.getAttribute( attributeName ); + } + + public IXmlElement getElement( final String tagName ) { + NodeList elementsByTagName = node.getElementsByTagName( tagName ); + IXmlElement result; + if( elementsByTagName.getLength() == 0 ) { + result = null; + } else { + result = new XmlElement( ( Element )elementsByTagName.item( 0 ) ); + } + return result; + } + + public IXmlElement[] getElements( final String tagName ) { + NodeList elementsByTagName = node.getElementsByTagName( tagName ); + List<IXmlElement> result = new ArrayList<IXmlElement>(); + for( int index = 0; index < elementsByTagName.getLength(); index++ ) { + result.add( new XmlElement( ( Element )elementsByTagName.item( index ) ) ); + } + return result.toArray( new IXmlElement[ result.size() ] ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/ExtensionSiteManager.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/ExtensionSiteManager.java new file mode 100644 index 00000000..62f536f6 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/ExtensionSiteManager.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.configuration.IPlatform; +import org.eclipse.epp.packaging.core.logging.MessageLogger; +import org.eclipse.update.configuration.IConfiguredSite; +import org.eclipse.update.core.IFeature; + +/** + * Responsible for creating the extension site and installing the features + * provided by an UpdateSiteManager + */ +public class ExtensionSiteManager { + + private final IPackagerConfiguration configuration; + + public ExtensionSiteManager( final IPackagerConfiguration configuration ) { + this.configuration = configuration; + } + + public void installFeatures( final IUpdateSiteManager manager ) + throws IOException, CoreException + { + File localSiteFolder = configuration.getExtensionSite(); + MessageLogger.getInstance() + .log( "ExtensionSiteManager.SiteCreated", localSiteFolder ); //$NON-NLS-1$ + IConfiguredSite site = SiteCreator.createInstallationSite( localSiteFolder ); + for( IPlatform platform : configuration.getTargetPlatforms() ) { + MessageLogger.getInstance() + .logBeginProcess( "ExtensionSiteManager.InstallPlatform", //$NON-NLS-1$ + platform ); + platform.configureSite(); + for( IFeature feature : manager.getFeatures() ) { + MessageLogger.getInstance() + .logBeginProcess( "ExtensionSiteManager.Installing", feature.getVersionedIdentifier().getIdentifier() ); //$NON-NLS-1$ + site.install( feature, null, new NullProgressMonitor() ); + MessageLogger.getInstance().logEndProcess(); + } + MessageLogger.getInstance().logEndProcess(); + } + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureRetrievingSearchCollector.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureRetrievingSearchCollector.java new file mode 100644 index 00000000..19331916 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureRetrievingSearchCollector.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.update.core.IFeature; +import org.eclipse.update.core.VersionedIdentifier; +import org.eclipse.update.search.IUpdateSearchResultCollector; + +/** An UpdateSearchResultCollector returning a feature.*/ +public class FeatureRetrievingSearchCollector + implements IUpdateSearchResultCollector +{ + + private final List<IFeature> result = new ArrayList<IFeature>(); + private final List<VersionedIdentifier> identifiers = new ArrayList<VersionedIdentifier>(); + + public void accept( final IFeature match ) { + if( !identifiers.contains( match.getVersionedIdentifier() ) ) { + result.add( match ); + identifiers.add( match.getVersionedIdentifier() ); + } + } + + public IFeature[] getFeatures() { + return result.toArray( new IFeature[ result.size() ] ); + } +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureSearcher.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureSearcher.java new file mode 100644 index 00000000..a9be780a --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureSearcher.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.net.URL; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.update.core.VersionedIdentifier; +import org.eclipse.update.search.IUpdateSearchResultCollector; +import org.eclipse.update.search.UpdateSearchRequest; +import org.eclipse.update.search.UpdateSearchScope; + +/**Handles and executes the search for a set of features over a number of update sites.*/ +public class FeatureSearcher { + + private final UpdateSearchScope scope = new UpdateSearchScope(); + private final PackagerSearchCategory category = new PackagerSearchCategory(); + + public FeatureSearcher( final VersionedIdentifier[] listedFeatures, + final URL[] listedSites ) + { + for( VersionedIdentifier identifier : listedFeatures ) { + category.addFeatureToSearch( identifier ); + } + for( URL siteUrl : listedSites ) { + scope.addSearchSite( "", siteUrl, null ); //$NON-NLS-1$ + } + } + + /**Run the search. + * @param collector the collector storing the search results.*/ + public void run( final IUpdateSearchResultCollector collector ) + throws OperationCanceledException, CoreException + { + UpdateSearchRequest searchRequest = new UpdateSearchRequest( category, + scope ); + searchRequest.performSearch( collector, new NullProgressMonitor() ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureVerifyingSearchCollector.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureVerifyingSearchCollector.java new file mode 100644 index 00000000..24283378 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/FeatureVerifyingSearchCollector.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.update.core.IFeature; +import org.eclipse.update.core.VersionedIdentifier; +import org.eclipse.update.search.IUpdateSearchResultCollector; + +/**UpdateSearchResultCollector comparing features found with a base set of features to find.*/ +public class FeatureVerifyingSearchCollector + implements IUpdateSearchResultCollector +{ + + private final List<VersionedIdentifier> featuresToFind = new ArrayList<VersionedIdentifier>(); + + public FeatureVerifyingSearchCollector( final VersionedIdentifier[] listedFeatures ) + { + Collections.addAll( featuresToFind, listedFeatures ); + } + + public void accept( final IFeature feature ) { + featuresToFind.remove( feature.getVersionedIdentifier() ); + } + + /**@return true if all the configured features are found, false otherwise.*/ + public boolean allFeaturesFound() { + return featuresToFind.isEmpty(); + } + + /**Returns the list of missing features*/ + public VersionedIdentifier[] getMissingFeatures() { + return featuresToFind.toArray( new VersionedIdentifier[ featuresToFind.size() ] ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/IUpdateSiteManager.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/IUpdateSiteManager.java new file mode 100644 index 00000000..90fa68aa --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/IUpdateSiteManager.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.update.core.IFeature; +import org.eclipse.update.core.VersionedIdentifier; + +/** + * Responsible for managing the declared update sites. + */ +public interface IUpdateSiteManager { + + /** + * Checks whether all of the features given by identifiers are present on the + * managed update sites. + * + * @return true, if all identified features can be found, false otherwise. + */ + public boolean areFeaturesPresent( VersionedIdentifier[] identifiers ) + throws CoreException; + + /** Returns the IFeatures for the configured feature references + */ + public IFeature[] getFeatures() throws CoreException; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/PackagerSearchCategory.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/PackagerSearchCategory.java new file mode 100644 index 00000000..b874fd27 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/PackagerSearchCategory.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import org.eclipse.update.core.VersionedIdentifier; +import org.eclipse.update.search.IUpdateSearchCategory; +import org.eclipse.update.search.IUpdateSearchQuery; + +/**An UpdateSearchCategory looking for feature identifiers*/ +public class PackagerSearchCategory implements IUpdateSearchCategory { + + private final PackagerSearchQuery query = new PackagerSearchQuery(); + private String id; + + public String getId() { + return id; + } + + /**Adds a feature to search for.*/ + public void addFeatureToSearch( final VersionedIdentifier identifier ) { + query.addFeatureIdentifier( identifier ); + } + + public IUpdateSearchQuery[] getQueries() { + return new IUpdateSearchQuery[]{ + query + }; + } + + public void setId( final String id ) { + this.id = id; + } +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/PackagerSearchQuery.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/PackagerSearchQuery.java new file mode 100644 index 00000000..e369c144 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/PackagerSearchQuery.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.update.core.ISite; +import org.eclipse.update.core.ISiteFeatureReference; +import org.eclipse.update.core.VersionedIdentifier; +import org.eclipse.update.search.IQueryUpdateSiteAdapter; +import org.eclipse.update.search.IUpdateSearchFilter; +import org.eclipse.update.search.IUpdateSearchQuery; +import org.eclipse.update.search.IUpdateSearchResultCollector; + +/**Search query looking for occurences of configured features.*/ +public class PackagerSearchQuery implements IUpdateSearchQuery { + + private final List<VersionedIdentifier> identifiers = new ArrayList<VersionedIdentifier>(); + + public IQueryUpdateSiteAdapter getQuerySearchSite() { + return null; + } + + public void run( final ISite site, + final String[] categoriesToSkip, + final IUpdateSearchFilter filter, + final IUpdateSearchResultCollector collector, + final IProgressMonitor monitor ) + { + ISiteFeatureReference[] featureReferences = site.getFeatureReferences(); + for( ISiteFeatureReference reference : featureReferences ) { + try { + if( identifiers.contains( reference.getVersionedIdentifier() ) ) { + collector.accept( reference.getFeature( new NullProgressMonitor() ) ); + } + } catch( CoreException e ) { + // The search is over, and there is nothing we could do about it. + } + } + } + + /**Add a feature to look for.*/ + public void addFeatureIdentifier( final VersionedIdentifier identifier ) { + identifiers.add( identifier ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/SiteCreator.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/SiteCreator.java new file mode 100644 index 00000000..2e76310d --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/SiteCreator.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.epp.packaging.core.io.FileUtils; +import org.eclipse.update.configuration.IConfiguredSite; +import org.eclipse.update.configuration.IInstallConfiguration; +import org.eclipse.update.core.SiteManager; + +/** + * Responsible for creating and deleting extension sites. + */ +public class SiteCreator { + + /** Adds a new extension site to the system and configures it to be updatable. */ + public static IConfiguredSite createInstallationSite( final File folder ) + throws IOException, CoreException + { + if( !folder.exists() ) { + folder.mkdir(); + } + IInstallConfiguration config = SiteManager.getLocalSite() + .getCurrentConfiguration(); + IConfiguredSite site = config.createConfiguredSite( folder ); + site.verifyUpdatableStatus(); + config.addConfiguredSite( site ); + return site; + } + + /** Removes an extension site from the system, deleting its content. */ + public static void removeInstallationSite( final String siteString ) + throws CoreException, MalformedURLException + { + IInstallConfiguration configuration = SiteManager.getLocalSite() + .getCurrentConfiguration(); + IConfiguredSite[] sites = configuration.getConfiguredSites(); + File file = new File( siteString ); + String fileUrl = file.toURL().toExternalForm() + "eclipse/";//$NON-NLS-1$ + for( IConfiguredSite site : sites ) { + if( site.getSite().getURL().toExternalForm().equals( fileUrl ) ) { + configuration.removeConfiguredSite( site ); + FileUtils.deleteFile( file ); + } + } + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/UpdateSiteManager.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/UpdateSiteManager.java new file mode 100644 index 00000000..0433e409 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/download/UpdateSiteManager.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.download; + +import java.net.URL; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.epp.packaging.core.configuration.IPackagerConfiguration; +import org.eclipse.epp.packaging.core.logging.MessageLogger; +import org.eclipse.update.core.IFeature; +import org.eclipse.update.core.VersionedIdentifier; +import org.eclipse.update.search.IUpdateSearchResultCollector; + +/** + * Holds references to a list of update sites and provides the methods required + * for interaction. + */ +public class UpdateSiteManager implements IUpdateSiteManager { + + private final URL[] listedSites; + private final VersionedIdentifier[] listedFeatures; + + public UpdateSiteManager( final IPackagerConfiguration configuration ) { + this.listedSites = configuration.getUpdateSites(); + this.listedFeatures = configuration.getRequiredFeatures(); + MessageLogger.getInstance() + .log( "UpdateSiteManager.ListedSitesCount", listedSites.length ); //$NON-NLS-1$ + } + + public boolean areFeaturesPresent( final VersionedIdentifier[] identifiers ) + throws CoreException + { + MessageLogger.getInstance() + .logBeginProcess( "UpdateSiteManager.FeatureLookup" ); //$NON-NLS-1$ + FeatureVerifyingSearchCollector collector = new FeatureVerifyingSearchCollector( listedFeatures ); + search( collector ); + boolean result = collector.allFeaturesFound(); + if( result ) { + MessageLogger.getInstance() + .logEndProcess( "UpdateSiteManager.FeaturesPresent" ); //$NON-NLS-1$ + } else { + MessageLogger.getInstance() + .logEndProcess( "UpdateSiteManager.FeaturesMissing" ); //$NON-NLS-1$ + for( VersionedIdentifier feature : collector.getMissingFeatures() ) { + MessageLogger.getInstance().log( feature.toString() ); + } + } + return result; + } + + public IFeature[] getFeatures() throws CoreException { + FeatureRetrievingSearchCollector collector = new FeatureRetrievingSearchCollector(); + search( collector ); + return collector.getFeatures(); + } + + private void search( final IUpdateSearchResultCollector collector ) + throws CoreException + { + new FeatureSearcher( listedFeatures, listedSites ).run( collector ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/io/FileUtils.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/io/FileUtils.java new file mode 100644 index 00000000..201a1923 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/io/FileUtils.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; + +/** + * Utility class for file operation. + */ +public class FileUtils { + + /** + * Copies source to destination. + * + * @param source The source file. + * @param destination The destination file. + */ + public static void copy( final File source, final File destination ) + throws IOException + { + if( !source.exists() ) { + return; + } + createDestinationFolder( destination ); + FileChannel inputChannel = null; + FileChannel outputChannel = null; + try { + inputChannel = new FileInputStream( source ).getChannel(); + outputChannel = new FileOutputStream( destination ).getChannel(); + inputChannel.transferTo( 0, inputChannel.size(), outputChannel ); + } finally { + if( inputChannel != null ) { + inputChannel.close(); + } + if( outputChannel != null ) { + outputChannel.close(); + } + } + } + + /** + * Copies source to destination. + * + * @param source Path to the source file. + * @param destination Path to the destination file. + */ + public static void copy( final String source, final String destination ) + throws IOException + { + File sourceFile = new File( source ); + copy( sourceFile, new File( destination ) ); + } + + /** Creates parent folders, if not existing. */ + private static void createDestinationFolder( final File destinationFile ) { + File destinationParent = destinationFile.getParentFile(); + if( !destinationParent.exists() ) { + destinationParent.mkdirs(); + } + } + + /** Recursively deletes a file or folder. */ + public static void deleteFile( final File file ) { + if( file.isDirectory() ) { + for( File subFile : file.listFiles() ) { + deleteFile( subFile ); + } + } + file.delete(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/io/Zip.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/io/Zip.java new file mode 100644 index 00000000..0f0ecd03 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/io/Zip.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * Capsules creation of archives in ZIP format. Begin with constructor, add + * content, finally end creation with close(). + */ +public class Zip { + + private final ZipOutputStream zipOutputStream; + + /** + * Opens a new zip archive in the location denoted by file and readies it for + * writing. + */ + public Zip( final File file ) throws FileNotFoundException { + this.zipOutputStream = new ZipOutputStream( new FileOutputStream( file ) ); + } + + public Zip( final File sourceFolder, final String fileName ) + throws FileNotFoundException + { + this( new File( sourceFolder, fileName ) ); + } + + /** + * Adds a file to the zip archive. + * + * @param relativePath The relative path to the file to add. + */ + public void addFile( final String relativePath ) throws IOException { + File file = new File( relativePath ); + addFileAs( file, relativePath ); + } + + /** + * Adds the contents of a folder to the zip archive. + * + * @param folder The folder to add. If the file is not a folder, nothing + * happens. + */ + public void addFolder( final File folder ) throws IOException { + if( folder.isDirectory() ) { + addDirectoryContents( folder, folder ); + } + } + + /** + * Adds a file or folder to the archive. * + * + * @param file The file or folder to add. + * @param rootContainer The parent directory. All files' paths are made + * relative to this folder. + */ + private void addFile( final File file, final File rootContainer ) + throws IOException + { + if( file.isDirectory() ) { + addDirectoryContents( file, rootContainer ); + } else { + String entryName = file.getCanonicalPath() + .replace( rootContainer.getCanonicalPath(), "." );//$NON-NLS-1$ + addFileAs( file, entryName ); + } + } + + /** + * Adds the given file to the archive. + * + * @param file The file to add. + * @param entryName The path under which to store the file. + */ + public void addFileAs( final File file, final String entryName ) + throws IOException, FileNotFoundException + { + String name = entryName; + if( entryName.startsWith( "./" ) ) {//$NON-NLS-1$ + name = name.replaceFirst( "./", "" );//$NON-NLS-1$//$NON-NLS-2$ + } + if( entryName.startsWith( ".\\" ) ) {//$NON-NLS-1$ + name = name.replaceFirst( ".\\\\", "" );//$NON-NLS-1$//$NON-NLS-2$ + } + zipOutputStream.putNextEntry( new ZipEntry( name ) ); + writeFileToZip( new FileInputStream( file ) ); + zipOutputStream.closeEntry(); + } + + /** + * Adds all subfiles of the given directory to the archive. Paths are made + * relative to rootContainer. + * + * @param file The directory to add. + * @param rootContainer The parent directory. All files' paths are made + * relative to this folder. + */ + private void addDirectoryContents( final File file, final File rootContainer ) + throws IOException + { + for( File subFile : file.listFiles() ) { + addFile( subFile, rootContainer ); + } + } + + /** + * Writes the given InputStream to the ZipOutputStream + */ + private void writeFileToZip( final InputStream inStream ) throws IOException { + byte[] buffer = new byte[ 512 ]; + int lengthRead = 0; + while( ( lengthRead = inStream.read( buffer ) ) != -1 ) { + zipOutputStream.write( buffer, 0, lengthRead ); + } + inStream.close(); + } + + /** Closes the zip file. No further additions are possible. */ + public void close() throws IOException { + zipOutputStream.close(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java new file mode 100644 index 00000000..32eb4d8c --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Logger.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.logging; + +import java.util.HashMap; +import java.util.Map; + +/** + * A logger with basic process handling facilities. + */ +public class Logger { + + private int processCount = 0; + private Map<Integer, Boolean> subProcesses = new HashMap<Integer, Boolean>(); + private boolean justEndedProcess = false; + + /** Log a single event */ + public void log( final String message ) { + createNewEntry( message ); + justEndedProcess = true; + } + + /** Log the beginning of an ongoing process. */ + public void logBeginProcess( final String message ) { + createNewEntry( message ); + System.out.print( "..." );//$NON-NLS-1$ + processCount++; + memorizeProcess( Boolean.FALSE ); + justEndedProcess = false; + } + + private void createNewEntry( final String message ) { + memorizeProcess( Boolean.TRUE ); + System.out.println(); + indent(); + System.out.print( message ); + } + + private void memorizeProcess( final Boolean value ) { + subProcesses.put( getProcessCount(), value ); + } + + /** Indent to indicate sub-processes. */ + private void indent() { + for( int index = 0; index < processCount; index++ ) { + System.out.print( " " ); //$NON-NLS-1$ + } + } + + public void logEndProcess( final String message ) { + if( processCount > 0 ) { + if( justEndedProcess ) { + System.out.println(); + } + boolean booleanValue = subProcesses.get( getProcessCount() ) + .booleanValue(); + processCount--; + if( booleanValue ) { + indent(); + } + System.out.print( message ); + justEndedProcess = true; + } + } + + private Integer getProcessCount() { + return Integer.valueOf( processCount ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/MessageLogger.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/MessageLogger.java new file mode 100644 index 00000000..83f09475 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/MessageLogger.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.logging; + +/** + * Combines logging and i18n into a single class. + */ +public class MessageLogger { + + private final static MessageLogger instance = new MessageLogger(); + private final Logger logger = new Logger(); + + public static MessageLogger getInstance() { + return instance; + } + + public void log( final String messageKey ) { + logger.log( getI18nedMessage( messageKey ) ); + } + + public void log( final String messageKey, final Object argument ) { + logger.log( getI18nedMessage( messageKey, argument ) ); + } + + public void logBeginProcess( final String messageKey ) { + logger.logBeginProcess( getI18nedMessage( messageKey ) ); + } + + public void logBeginProcess( final String messageKey, final Object argument ) + { + logger.logBeginProcess( getI18nedMessage( messageKey, argument ) ); + } + + + private String getI18nedMessage( final String message ) { + return Messages.getString( message ); + } + + private String getI18nedMessage( final String messageKey, + final Object argument ) + { + return Messages.getString( messageKey, argument ); + } + + public void logEndProcess() { + logger.logEndProcess(Messages.getString( "Logger.Done" )); //$NON-NLS-1$ + } + + public void logEndProcess( final String messageKey ) { + logger.logEndProcess( getI18nedMessage( messageKey ) ); + } + + public void logEndProcess( final String messageKey, final Object argument ) { + logger.logEndProcess( getI18nedMessage( messageKey, argument ) ); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Messages.java b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Messages.java new file mode 100644 index 00000000..1ac1b3b6 --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/Messages.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007 Innoopract Informationssysteme GmbH + * 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: + * Innoopract - initial API and implementation + *******************************************************************************/ +package org.eclipse.epp.packaging.core.logging; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** Utility class providing basic internationalization facilities. */ +public class Messages { + + private static final String BUNDLE_NAME = "org.eclipse.epp.packaging.core.logging.messages"; //$NON-NLS-1$ + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); + + private Messages() { + } + + /** + * Returns the value associated with the given key, or a placeholder if the + * key does not exist. + */ + public static String getString( final String key ) { + String result; + try { + result = RESOURCE_BUNDLE.getString( key ); + } catch( MissingResourceException e ) { + result = '!' + key + '!'; + } + return result; + } + + /** + * Returns the value associated with the given key, using it as a message. + * + * @param key An internationalization key defined in a resource file. Should + * denote a message. + * @param argument The argument to insert into the message. + */ + public static String getString( final String key, final Object argument ) { + Object[] messageArgument = { + argument + }; + MessageFormat formatter = new MessageFormat( "" ); //$NON-NLS-1$ + formatter.applyPattern( getString( key ) ); + String output = formatter.format( messageArgument ); + return output; + } +} diff --git a/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/messages.properties b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/messages.properties new file mode 100644 index 00000000..984fe43b --- /dev/null +++ b/plugins/org.eclipse.epp.packaging.core/src/org/eclipse/epp/packaging/core/logging/messages.properties @@ -0,0 +1,17 @@ +Application.FeatureCount={0} features listed. +UpdateSiteManager.ListedSitesCount={0} sites listed. +UpdateSiteManager.FeatureLookup=Looking up features +UpdateSiteManager.FeaturesPresent=All features accounted for. +UpdateSiteManager.FeaturesMissing=Could not locate all of the requested features. A list of missing features follows: +Application.Installing=Installing features +ExtensionSiteManager.SiteCreated=Created installation site at {0}. +ExtensionSiteManager.InstallPlatform=Installing features for platform {0} +ExtensionSiteManager.Installing=Installing feature {0} +Application.Building=Building configured application +Application.Packing=Packing installation site. +EclipsePackager.ConfigurationFolder=Configuration files taken from {0}. +EclipsePackager.TargetFolder=The application will be built in {0}. +EclipsePackager.InjectIni=Injecting config.ini from {0}. +EclipsePackager.Running=Building +PackageMover.MovingFiles=Moving Files +Logger.Done=Done.
\ No newline at end of file |