blob: ee746dc57547746841d03a93694db1a74c43f582 [file] [log] [blame]
/*******************************************************************************
* 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.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.packaging.core.Activator;
import org.eclipse.update.core.ISite;
import org.eclipse.update.core.ISiteFeatureReference;
import org.eclipse.update.core.SiteManager;
import org.eclipse.update.core.VersionedIdentifier;
import org.osgi.framework.Version;
/**
* A configurable IPackagerConfiguration. All data is handed in as String, then
* converted to the proper objects.
*/
public class PackagerConfiguration implements IModifiablePackagerConfiguration {
private static final String PACKAGER_CONFIGURATION_DIRECTORY
= "packagerConfiguration"; //$NON-NLS-1$
private static final String ECLIPSE_PLATTFORM
// TODO change this to platform
= "eclipse-platform-"; //$NON-NLS-1$
// = "eclipse-SDK-"; //$NON-NLS-1$
private final List<URL> updateSites = new ArrayList<URL>();
private final List<Platform> targetPlatforms = new ArrayList<Platform>();
private List<VersionedIdentifier> requiredFeatures = new ArrayList<VersionedIdentifier>();
private File baseFolder;
private File extensionSite;
private String rcpVersion;
private File rootFolder;
private String productName;
private String eclipseProductId;
private String initialPerspectiveId;
public PackagerConfiguration() {
this.baseFolder = org.eclipse.core.runtime.Platform.getLocation().toFile();
}
public URL[] getUpdateSites() {
return this.updateSites.toArray( new URL[ this.updateSites.size() ] );
}
public void addUpdateSite( final String string ) throws MalformedURLException
{
this.updateSites.add( new URL( string ) );
}
public VersionedIdentifier[] getRequiredFeatures() {
return this.requiredFeatures.toArray( new VersionedIdentifier[ this.requiredFeatures.size() ] );
}
public void addRequiredFeature( final String id, final String version ) {
this.requiredFeatures.add( new VersionedIdentifier( id, version ) );
}
public File getTargetFolder() {
return this.baseFolder;
}
public File getPackagerConfigurationFolder() {
File result = new File( this.baseFolder, PACKAGER_CONFIGURATION_DIRECTORY );
if( ! result.isDirectory() ) {
result.mkdir();
}
return result;
}
public void setExtensionSiteRelative( final String relativeFolder ) {
this.extensionSite = new File( this.baseFolder, relativeFolder );
}
public File getExtensionSite() {
return this.extensionSite;
}
public Platform addTargetPlatform( final String os,
final String ws,
final String arch,
final String eclipseIniFileContent,
final String eclipseIniFilePath )
{
Platform platform = new Platform( os, ws, arch, eclipseIniFileContent, eclipseIniFilePath );
this.targetPlatforms.add( platform );
return platform;
}
public IPlatform[] getTargetPlatforms() {
return this.targetPlatforms.toArray( new IPlatform[ this.targetPlatforms.size() ] );
}
public String getRootFileBaseName() {
return ECLIPSE_PLATTFORM + this.rcpVersion + '-';
}
public File getRootFileFolder() {
return this.rootFolder;
}
public void setRcpVersion( final String version ) {
this.rcpVersion = version;
}
public void setRootFileFolder( final String folderName ) {
this.rootFolder = new File( folderName );
}
public void setProductName( final String name ) {
this.productName = name;
}
public String getProductName() {
return this.productName;
}
public void setEclipseProductId( final String eclipseProductId ) {
this.eclipseProductId = eclipseProductId;
}
public String getEclipseProductId() {
return this.eclipseProductId;
}
public void setInitialPerspectiveId( final String initialPerspectiveId ) {
this.initialPerspectiveId = initialPerspectiveId;
}
public String getInitialPerspectiveId() {
return this.initialPerspectiveId;
}
/**
* Creates a list of available feature versions from all given update sites.
* Required features with no version number (0.0.0) are replaced with the
* highest available version number.
*/
public IStatus checkFeatures( final IProgressMonitor monitor )
throws CoreException
{
MultiStatus result = new MultiStatus( Activator.PLUGIN_ID, IStatus.OK, null, null );
FeatureVersionRepository availableFeatures = new FeatureVersionRepository();
List<VersionedIdentifier> newRequiredFeatures = new ArrayList<VersionedIdentifier>();
createFeatureRepository( monitor, availableFeatures );
for( VersionedIdentifier featureIdentifier : this.requiredFeatures ) {
VersionedIdentifier newIdentifier = featureIdentifier;
String featureId = featureIdentifier.getIdentifier();
Version featureVersion = new Version( featureIdentifier.getVersion().toString() );
if( ! availableFeatures.containsIdentifier( featureId ) ) {
String message = "Feature " //$NON-NLS-1$
+ featureId
+ " not available on given update sites."; //$NON-NLS-1$
result.add( new Status( IStatus.WARNING, Activator.PLUGIN_ID, message ) );
} else {
Version highestVersion = availableFeatures.getHighestVersion( featureId );
String newVersion = highestVersion.toString();
if( Version.emptyVersion.equals( featureVersion ) )
{
String message = "Replacing feature version of " //$NON-NLS-1$
+ featureId
+ " with version " //$NON-NLS-1$
+ newVersion;
result.add( new Status( IStatus.INFO, Activator.PLUGIN_ID, message ) );
newIdentifier = new VersionedIdentifier( featureId, newVersion );
} else {
if( highestVersion.compareTo( featureVersion ) > 0 ) {
String message = "Higher version of feature " //$NON-NLS-1$
+ featureId
+ " available: " //$NON-NLS-1$
+ newVersion;
result.add( new Status( IStatus.INFO, Activator.PLUGIN_ID, message ) );
}
if( highestVersion.compareTo( featureVersion ) < 0 ) {
String message = "Only lower version of feature " //$NON-NLS-1$
+ featureId
+ " available: " //$NON-NLS-1$
+ newVersion;
result.add( new Status( IStatus.WARNING, Activator.PLUGIN_ID, message ) );
}
}
}
newRequiredFeatures.add( newIdentifier );
}
this.requiredFeatures = newRequiredFeatures;
return result;
}
// internal methods
///////////////////
private void createFeatureRepository( final IProgressMonitor monitor,
final FeatureVersionRepository availableFeatures )
throws CoreException
{
for( URL url : this.updateSites ) {
ISite site = SiteManager.getSite( url, monitor );
ISiteFeatureReference[] featureReferences = site.getFeatureReferences();
for( ISiteFeatureReference featureReference : featureReferences ) {
VersionedIdentifier versionedIdentifier = featureReference.getVersionedIdentifier();
availableFeatures.addVersionIdentifier( versionedIdentifier );
}
}
}
}