Compare commits
1 Commits
patch/7.3.
...
feat/maste
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cebfe678b1 |
@@ -12,10 +12,13 @@
|
||||
// ============================================================================
|
||||
package org.talend.core.service;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.talend.core.IService;
|
||||
|
||||
public interface IUpdateService extends IService {
|
||||
|
||||
boolean checkComponentNexusUpdate();
|
||||
|
||||
boolean checkStudioUpdate(IProgressMonitor monitor);
|
||||
|
||||
}
|
||||
|
||||
@@ -198,6 +198,7 @@ public class M2eUserSettingForTalendLoginTask extends AbstractLoginTask {
|
||||
// add one marker to check to sync or not.
|
||||
File repoFolder = new File(maven.getLocalRepositoryPath());
|
||||
File markerFile = new File(repoFolder, ".syncMarker"); //$NON-NLS-1$
|
||||
System.setProperty("m2.syncmarker.path", markerFile.getAbsolutePath()); //$NON-NLS-1$
|
||||
Properties prop = new Properties();
|
||||
FileInputStream inStream = null;
|
||||
FileOutputStream outputStream = null;
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.talend.core.model.migration.IMigrationToolService;
|
||||
import org.talend.core.model.utils.TalendPropertiesUtil;
|
||||
import org.talend.core.repository.CoreRepositoryPlugin;
|
||||
import org.talend.core.runtime.services.IMavenUIService;
|
||||
import org.talend.core.service.IUpdateService;
|
||||
import org.talend.core.services.ICoreTisService;
|
||||
import org.talend.core.ui.branding.IBrandingService;
|
||||
import org.talend.core.ui.workspace.ChooseWorkspaceData;
|
||||
@@ -156,8 +157,15 @@ public class Application implements IApplication {
|
||||
(IMigrationToolService) GlobalServiceRegister.getDefault().getService(IMigrationToolService.class);
|
||||
service.executeWorspaceTasks();
|
||||
// saveConnectionBean(email);
|
||||
|
||||
boolean needRelaunch = false;
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(IUpdateService.class)) {
|
||||
IUpdateService updateService = GlobalServiceRegister.getDefault().getService(IUpdateService.class);
|
||||
needRelaunch = updateService.checkStudioUpdate(new NullProgressMonitor());
|
||||
}
|
||||
if (needRelaunch) {
|
||||
setRelaunchData();
|
||||
return IApplication.EXIT_RELAUNCH;
|
||||
}
|
||||
final PatchComponent patchComponent = PatchComponentHelper.getPatchComponent();
|
||||
if (patchComponent != null) {
|
||||
final boolean installed = patchComponent.install();
|
||||
|
||||
@@ -182,4 +182,12 @@ FeaturesManager.Type.p2.studioPatch=Studio Patch
|
||||
FeaturesManager.Type.plainZip=Plain ZIP
|
||||
FeaturesManager.Category.all=All Categories
|
||||
|
||||
P2UpdateManager.update.product=Updating talend product...
|
||||
P2UpdateManager.p2.uri.null=P2 repository URI is null.
|
||||
P2UpdateManager.p2.feature.null=Feature list is empty.
|
||||
P2UpdateManager.no.iu.available=Could not find any available IU in current profile.
|
||||
P2UpdateManager.user.cancel=User canceled the upgrade of product.
|
||||
P2UpdateManager.update.error=error updating product : {0}
|
||||
P2UpdateManager.update.sucess=Update talend product successfully.
|
||||
|
||||
UIUtils.exception.interrupt=User cancelled.
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.updates.runtime;
|
||||
|
||||
public interface P2UpdateConstants {
|
||||
|
||||
public static final String STUDIO_CORE_FEATURE_ID = "org.talend.tup.feature.feature.group"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_UPDATESITE_PATH = "updatesite.path"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_FEATURES_TO_INSTALL = "features.to.install"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_FEATURES_TO_UPDATE = "features.to.update"; //$NON-NLS-1$
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@
|
||||
// ============================================================================
|
||||
package org.talend.updates.runtime;
|
||||
|
||||
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
|
||||
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
@@ -25,10 +27,14 @@ public class UpdatesRuntimePlugin extends AbstractUIPlugin {
|
||||
|
||||
private static UpdatesRuntimePlugin plugin;
|
||||
|
||||
private IProvisioningAgent agent;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
agent = ServiceHelper.getService(context, IProvisioningAgent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,4 +46,9 @@ public class UpdatesRuntimePlugin extends AbstractUIPlugin {
|
||||
public static UpdatesRuntimePlugin getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public IProvisioningAgent getProvisioningAgent() {
|
||||
return agent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,13 +32,11 @@ import org.eclipse.equinox.p2.query.QueryUtil;
|
||||
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
|
||||
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
|
||||
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.ui.runtime.update.PreferenceKeys;
|
||||
import org.talend.commons.utils.VersionUtils;
|
||||
import org.talend.commons.utils.io.FilesUtils;
|
||||
import org.talend.updates.runtime.i18n.Messages;
|
||||
@@ -60,8 +58,6 @@ public class P2Manager {
|
||||
|
||||
private final Object p2ProfileLock = new Object();
|
||||
|
||||
private final Object clearOsgiLock = new Object();
|
||||
|
||||
private P2Manager() {
|
||||
reset();
|
||||
}
|
||||
@@ -243,9 +239,4 @@ public class P2Manager {
|
||||
}
|
||||
}
|
||||
|
||||
public void clearOsgiCache() {
|
||||
synchronized (clearOsgiLock) {
|
||||
PlatformUI.getPreferenceStore().setValue(PreferenceKeys.NEED_OSGI_CLEAN, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.updates.runtime.engine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
||||
import org.eclipse.equinox.p2.core.ProvisionException;
|
||||
import org.eclipse.equinox.p2.engine.IPhaseSet;
|
||||
import org.eclipse.equinox.p2.engine.IProfile;
|
||||
import org.eclipse.equinox.p2.engine.IProfileRegistry;
|
||||
import org.eclipse.equinox.p2.engine.PhaseSetFactory;
|
||||
import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery;
|
||||
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
|
||||
import org.eclipse.equinox.p2.operations.InstallOperation;
|
||||
import org.eclipse.equinox.p2.operations.ProfileModificationJob;
|
||||
import org.eclipse.equinox.p2.operations.ProvisioningSession;
|
||||
import org.eclipse.equinox.p2.operations.UpdateOperation;
|
||||
import org.eclipse.equinox.p2.query.QueryUtil;
|
||||
import org.eclipse.equinox.p2.repository.IRepositoryManager;
|
||||
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
|
||||
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.updates.runtime.P2UpdateConstants;
|
||||
import org.talend.updates.runtime.UpdatesRuntimePlugin;
|
||||
import org.talend.updates.runtime.i18n.Messages;
|
||||
import org.talend.updates.runtime.model.ExtraFeatureException;
|
||||
import org.talend.updates.runtime.model.P2ExtraFeatureException;
|
||||
import org.talend.updates.runtime.utils.P2UpdateHelper;
|
||||
|
||||
public class P2UpdateManager {
|
||||
|
||||
private Logger logger = Logger.getLogger(P2UpdateManager.class);
|
||||
|
||||
private static P2UpdateManager instance;
|
||||
|
||||
private IProvisioningAgent agent;
|
||||
|
||||
private ProvisioningSession session;
|
||||
|
||||
private IPhaseSet talendPhaseSet;
|
||||
|
||||
private P2UpdateManager() {
|
||||
agent = UpdatesRuntimePlugin.getDefault().getProvisioningAgent();
|
||||
agent.registerService(IProvisioningAgent.INSTALLER_AGENT, agent);
|
||||
// DirectorApplication.PROP_P2_PROFILE
|
||||
agent.registerService("eclipse.p2.profile", IProfileRegistry.SELF);//$NON-NLS-1$
|
||||
talendPhaseSet = PhaseSetFactory.createDefaultPhaseSetExcluding(new String[] { PhaseSetFactory.PHASE_CHECK_TRUST });
|
||||
}
|
||||
|
||||
public static P2UpdateManager getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (P2UpdateManager.class) {
|
||||
if (instance == null) {
|
||||
instance = new P2UpdateManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public IStatus execute(final IProgressMonitor monitor) throws ExtraFeatureException { // check p2 repository url
|
||||
if (P2UpdateHelper.getP2RepositoryURI() == null) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.p2.uri.null"); //$NON-NLS-1$
|
||||
}
|
||||
// check features to install/update or TODO filter available features in license
|
||||
List<String> featuresToInstall = P2UpdateHelper.getConfigFeatures(P2UpdateConstants.KEY_FEATURES_TO_INSTALL);
|
||||
List<String> featuresToUpdate = P2UpdateHelper.getConfigFeatures(P2UpdateConstants.KEY_FEATURES_TO_UPDATE);
|
||||
if (featuresToInstall.isEmpty() && featuresToUpdate.isEmpty()) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.p2.feature.null"); //$NON-NLS-1$
|
||||
}
|
||||
IStatus result = null;
|
||||
File configIniBackupFile = null;
|
||||
try {
|
||||
// backup the config.ini
|
||||
configIniBackupFile = P2UpdateHelper.backupConfigFile();
|
||||
if (!featuresToInstall.isEmpty()) {
|
||||
result = doInstall(monitor, featuresToInstall);
|
||||
return result;
|
||||
}
|
||||
result = doUpdate(monitor, featuresToUpdate);
|
||||
} catch (IOException e) {
|
||||
throw new ExtraFeatureException(
|
||||
new ProvisionException(Messages.createErrorStatus(e, "ExtraFeaturesFactory.restore.config.error"))); //$NON-NLS-1$
|
||||
} finally {
|
||||
boolean success = false;
|
||||
if (result != null) {
|
||||
switch (result.getSeverity()) {
|
||||
case IStatus.OK:
|
||||
case IStatus.INFO:
|
||||
case IStatus.WARNING:
|
||||
success = true;
|
||||
break;
|
||||
default:
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
P2UpdateHelper.clearOsgiCache();
|
||||
if (success) {
|
||||
// restore the config.ini
|
||||
if (configIniBackupFile != null) {
|
||||
try {
|
||||
P2UpdateHelper.restoreConfigFile(configIniBackupFile);
|
||||
} catch (IOException e) {
|
||||
throw new P2ExtraFeatureException(
|
||||
new ProvisionException(Messages.createErrorStatus(e, "ExtraFeaturesFactory.back.config.error"))); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if (!featuresToInstall.isEmpty()) {
|
||||
P2UpdateHelper.clearConfigFeatures(P2UpdateConstants.KEY_FEATURES_TO_INSTALL);
|
||||
} else if (!featuresToUpdate.isEmpty()) {
|
||||
P2UpdateHelper.clearConfigFeatures(P2UpdateConstants.KEY_FEATURES_TO_UPDATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private IStatus doInstall(IProgressMonitor monitor, List<String> featuresToInstall) throws P2ExtraFeatureException {
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, 4);
|
||||
subMonitor.setTaskName(Messages.getString("P2UpdateManager.update.product")); //$NON-NLS-1$
|
||||
// reset isInstalled to make is compute the next time is it used
|
||||
List<URI> allRepoUris = new ArrayList<>();
|
||||
allRepoUris.add(P2UpdateHelper.getP2RepositoryURI());
|
||||
subMonitor.setTaskName(Messages.getString("ExtraFeature.searching.talend.features.label")); //$NON-NLS-1$
|
||||
Set<IInstallableUnit> availableIUs = queryFromP2Repository(subMonitor.newChild(1), allRepoUris);
|
||||
// show the installation unit
|
||||
List<IInstallableUnit> toInstall = availableIUs.stream().filter(iu -> featuresToInstall.contains(iu.getId()))
|
||||
.collect(Collectors.toList());
|
||||
logger.debug("IUs to install:" + toInstall); //$NON-NLS-1$
|
||||
if (toInstall.isEmpty()) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.no.iu.available");
|
||||
}
|
||||
if (subMonitor.isCanceled()) {
|
||||
return Messages.createCancelStatus("P2UpdateManager.user.cancel"); //$NON-NLS-1$
|
||||
}
|
||||
InstallOperation installOperation = new InstallOperation(getProvisioningSession(), toInstall);
|
||||
IStatus installResolvedStatus = installOperation.resolveModal(subMonitor.newChild(1));
|
||||
if (installResolvedStatus.getSeverity() == IStatus.ERROR) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.update.error", //$NON-NLS-1$
|
||||
installOperation.getResolutionDetails());
|
||||
}
|
||||
ProfileModificationJob provisioningJob = (ProfileModificationJob) installOperation
|
||||
.getProvisioningJob(subMonitor.newChild(1));
|
||||
if (subMonitor.isCanceled()) {
|
||||
return Messages.createCancelStatus("P2UpdateManager.user.cancel"); //$NON-NLS-1$
|
||||
}
|
||||
provisioningJob.setPhaseSet(talendPhaseSet);
|
||||
IStatus status = provisioningJob.run(subMonitor.newChild(1));
|
||||
logger.debug("installed features with status :" + status); //$NON-NLS-1$
|
||||
return Messages.createOkStatus("P2UpdateManager.update.sucess"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private IStatus doUpdate(IProgressMonitor monitor, List<String> featuresToUpdate) throws P2ExtraFeatureException {
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, 5);
|
||||
subMonitor.setTaskName(Messages.getString("P2UpdateManager.update.product")); //$NON-NLS-1$
|
||||
// reset isInstalled to make is compute the next time is it used
|
||||
IProfile p2Profile = getProfile(IProfileRegistry.SELF);
|
||||
List<URI> allRepoUris = new ArrayList<>();
|
||||
allRepoUris.add(P2UpdateHelper.getP2RepositoryURI());
|
||||
Set<IInstallableUnit> currentIUs = p2Profile.query(new UserVisibleRootQuery(), subMonitor.newChild(1))
|
||||
.toUnmodifiableSet();
|
||||
// show the installation unit
|
||||
List<IInstallableUnit> iusToUpdate = currentIUs.stream().filter(iu -> featuresToUpdate.contains(iu.getId()))
|
||||
.collect(Collectors.toList());
|
||||
logger.debug("IUs to update:" + iusToUpdate); //$NON-NLS-1$
|
||||
if (iusToUpdate.isEmpty()) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.no.iu.available"); //$NON-NLS-1$
|
||||
}
|
||||
// update
|
||||
UpdateOperation updateOperation = new UpdateOperation(getProvisioningSession(), iusToUpdate);
|
||||
updateOperation.getProvisioningContext().setArtifactRepositories(allRepoUris.toArray(new URI[allRepoUris.size()]));
|
||||
updateOperation.getProvisioningContext().setMetadataRepositories(allRepoUris.toArray(new URI[allRepoUris.size()]));
|
||||
updateOperation.setProfileId(IProfileRegistry.SELF);
|
||||
IStatus result = updateOperation.resolveModal(subMonitor.newChild(1));
|
||||
if (subMonitor.isCanceled()) {
|
||||
return Messages.createCancelStatus("P2UpdateManager.user.cancel"); //$NON-NLS-1$
|
||||
}
|
||||
if (result.getSeverity() == IStatus.ERROR) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.update.error", //$NON-NLS-1$
|
||||
updateOperation.getResolutionDetails());
|
||||
}
|
||||
ProfileModificationJob provisioningJob = (ProfileModificationJob) updateOperation
|
||||
.getProvisioningJob(subMonitor.newChild(1));
|
||||
if (subMonitor.isCanceled()) {
|
||||
return Messages.createCancelStatus("P2UpdateManager.user.cancel"); //$NON-NLS-1$
|
||||
}
|
||||
if (provisioningJob == null) {
|
||||
return Messages.createErrorStatus(null, "P2UpdateManager.update.error", //$NON-NLS-1$
|
||||
updateOperation.getResolutionDetails());
|
||||
}
|
||||
provisioningJob.setPhaseSet(talendPhaseSet);
|
||||
IStatus status = provisioningJob.run(subMonitor.newChild(1));
|
||||
if (subMonitor.isCanceled()) {
|
||||
return Messages.createCancelStatus("P2UpdateManager.user.cancel"); //$NON-NLS-1$
|
||||
}
|
||||
logger.debug("Updated product with status: " + status); //$NON-NLS-1$
|
||||
if (featuresToUpdate.contains(P2UpdateConstants.STUDIO_CORE_FEATURE_ID)) {
|
||||
// TODO change to the new studio.core feature.
|
||||
try {
|
||||
P2UpdateHelper.updateProductVersion(subMonitor.newChild(1), getProfile(IProfileRegistry.SELF));
|
||||
// remove .syncMarker to force to sync maven repository
|
||||
String filePath = System.getProperty("m2.syncmarker.path"); //$NON-NLS-1$
|
||||
if (filePath != null) {
|
||||
File markerFile = new File(filePath);
|
||||
if (markerFile.exists()) {
|
||||
markerFile.delete();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
return Messages.createOkStatus("P2UpdateManager.update.sucess"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public Set<IInstallableUnit> queryFromP2Repository(IProgressMonitor monitor, List<URI> allRepoUris) {
|
||||
// get the repository managers and add our repository
|
||||
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) agent
|
||||
.getService(IMetadataRepositoryManager.SERVICE_NAME);
|
||||
IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent
|
||||
.getService(IArtifactRepositoryManager.SERVICE_NAME);
|
||||
// remove existing repositories
|
||||
for (URI existingRepUri : metadataManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)) {
|
||||
metadataManager.removeRepository(existingRepUri);
|
||||
}
|
||||
for (URI existingRepUri : artifactManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)) {
|
||||
metadataManager.removeRepository(existingRepUri);
|
||||
}
|
||||
for (URI repoUri : allRepoUris) {
|
||||
metadataManager.addRepository(repoUri);
|
||||
artifactManager.addRepository(repoUri);
|
||||
}
|
||||
return metadataManager.query(QueryUtil.createLatestQuery(QueryUtil.createIUGroupQuery()), monitor).toUnmodifiableSet();
|
||||
}
|
||||
|
||||
public ProvisioningSession getProvisioningSession() {
|
||||
if (session == null) {
|
||||
session = new ProvisioningSession(agent);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
public IProfileRegistry getProfileRegistry() {
|
||||
return (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
|
||||
}
|
||||
|
||||
public IProfile getProfile(String profilId) {
|
||||
return getProfileRegistry().getProfile(profilId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,6 @@
|
||||
package org.talend.updates.runtime.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -62,9 +61,6 @@ import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.runtime.utils.io.IOUtils;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.services.ICoreTisService;
|
||||
import org.talend.updates.runtime.engine.P2Manager;
|
||||
import org.talend.updates.runtime.feature.model.Category;
|
||||
import org.talend.updates.runtime.feature.model.Type;
|
||||
@@ -77,6 +73,7 @@ import org.talend.updates.runtime.service.ITaCoKitUpdateService;
|
||||
import org.talend.updates.runtime.service.ITaCoKitUpdateService.ICarInstallationResult;
|
||||
import org.talend.updates.runtime.storage.AbstractFeatureStorage;
|
||||
import org.talend.updates.runtime.storage.IFeatureStorage;
|
||||
import org.talend.updates.runtime.utils.P2UpdateHelper;
|
||||
import org.talend.updates.runtime.utils.PathUtils;
|
||||
import org.talend.updates.runtime.utils.TaCoKitCarUtils;
|
||||
import org.talend.utils.files.FileUtils;
|
||||
@@ -284,7 +281,7 @@ public class P2ExtraFeature extends AbstractExtraFeature implements IP2Feature {
|
||||
try {
|
||||
if (!isUseLegacyP2Install()) {
|
||||
// backup the config.ini
|
||||
configIniBackupFile = backupConfigFile();
|
||||
configIniBackupFile = P2UpdateHelper.backupConfigFile();
|
||||
} // else legacy p2 install will update the config.ini
|
||||
doInstallStatus = installP2(progress, allRepoUris);
|
||||
if (doInstallStatus == null || !doInstallStatus.isOK()) {
|
||||
@@ -334,9 +331,9 @@ public class P2ExtraFeature extends AbstractExtraFeature implements IP2Feature {
|
||||
}
|
||||
}
|
||||
// restore the config.ini
|
||||
if (configIniBackupFile != null) { // must existed backup file.
|
||||
if (isInstalled && configIniBackupFile != null) { // must existed backup file.
|
||||
try {
|
||||
restoreConfigFile(configIniBackupFile, isInstalled);
|
||||
P2UpdateHelper.restoreConfigFile(configIniBackupFile);
|
||||
} catch (IOException e) {
|
||||
throw new P2ExtraFeatureException(
|
||||
new ProvisionException(Messages.createErrorStatus(e, "ExtraFeaturesFactory.back.config.error"))); //$NON-NLS-1$
|
||||
@@ -359,7 +356,7 @@ public class P2ExtraFeature extends AbstractExtraFeature implements IP2Feature {
|
||||
}
|
||||
|
||||
protected void afterInstallP2(IProgressMonitor progress, Map<File, File> unzippedPatchMap) throws P2ExtraFeatureException {
|
||||
P2Manager.getInstance().clearOsgiCache();
|
||||
P2UpdateHelper.clearOsgiCache();
|
||||
}
|
||||
|
||||
protected void afterRestoreConfigFile(IProgressMonitor progress, Map<File, File> unzippedPatchMap)
|
||||
@@ -546,6 +543,7 @@ public class P2ExtraFeature extends AbstractExtraFeature implements IP2Feature {
|
||||
protected void updateRoamingProp(IProvisioningAgent agent, IProvisioningAgentProvider agentProvider)
|
||||
throws ProvisionException {
|
||||
agent.registerService(IProvisioningAgent.INSTALLER_AGENT, agentProvider.createAgent(null));
|
||||
// DirectorApplication.PROP_P2_PROFILE
|
||||
agent.registerService("eclipse.p2.profile", getP2ProfileId());//$NON-NLS-1$
|
||||
}
|
||||
|
||||
@@ -659,39 +657,6 @@ public class P2ExtraFeature extends AbstractExtraFeature implements IP2Feature {
|
||||
}
|
||||
}
|
||||
|
||||
protected File backupConfigFile() throws IOException {
|
||||
try {
|
||||
File configurationFile = PathUtils.getStudioConfigFile();
|
||||
File tempFile = File.createTempFile("config.ini", null); //$NON-NLS-1$
|
||||
FilesUtils.copyFile(new FileInputStream(configurationFile), tempFile);
|
||||
return tempFile;
|
||||
} catch (Exception e) {
|
||||
if (e instanceof IOException) {
|
||||
throw (IOException) e;
|
||||
}
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreConfigFile(File toResore, boolean isInstalled) throws IOException {
|
||||
try {
|
||||
File configurationFile = PathUtils.getStudioConfigFile();
|
||||
if (isInstalled && !IOUtils.contentEquals(new FileInputStream(configurationFile), new FileInputStream(toResore))) {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreTisService.class)) {
|
||||
ICoreTisService coreTisService = (ICoreTisService) GlobalServiceRegister.getDefault()
|
||||
.getService(ICoreTisService.class);
|
||||
coreTisService.updateConfiguratorBundles(configurationFile, toResore);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
if (toResore != null && toResore.exists()) {
|
||||
toResore.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtraFeature getInstalledFeature(IProgressMonitor progress) throws ExtraFeatureException {
|
||||
ExtraFeature extraFeature = null;
|
||||
|
||||
@@ -19,14 +19,18 @@ import java.util.Set;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.talend.commons.CommonsPlugin;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.core.nexus.ArtifactRepositoryBean;
|
||||
import org.talend.core.service.IUpdateService;
|
||||
import org.talend.updates.runtime.engine.P2UpdateManager;
|
||||
import org.talend.updates.runtime.engine.component.InstallComponentMessages;
|
||||
import org.talend.updates.runtime.engine.factory.ComponentsNexusInstallFactory;
|
||||
import org.talend.updates.runtime.model.ExtraFeature;
|
||||
import org.talend.updates.runtime.model.ExtraFeatureException;
|
||||
import org.talend.updates.runtime.model.FeatureCategory;
|
||||
import org.talend.updates.runtime.nexus.component.NexusServerManager;
|
||||
|
||||
@@ -100,4 +104,30 @@ public class UpdateService implements IUpdateService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkStudioUpdate(IProgressMonitor monitor) {
|
||||
if (Platform.inDevelopmentMode()) {
|
||||
return false;
|
||||
}
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
try {
|
||||
IStatus status = P2UpdateManager.getInstance().execute(monitor);
|
||||
if (status != null) {
|
||||
switch (status.getSeverity()) {
|
||||
case IStatus.OK:
|
||||
case IStatus.INFO:
|
||||
case IStatus.WARNING:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (ExtraFeatureException e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.updates.runtime.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.equinox.p2.engine.IProfile;
|
||||
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
|
||||
import org.eclipse.equinox.p2.query.QueryUtil;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.runtime.utils.io.IOUtils;
|
||||
import org.talend.commons.ui.runtime.update.PreferenceKeys;
|
||||
import org.talend.commons.utils.resource.UpdatesHelper;
|
||||
import org.talend.core.GlobalServiceRegister;
|
||||
import org.talend.core.runtime.maven.MavenConstants;
|
||||
import org.talend.core.services.ICoreTisService;
|
||||
import org.talend.updates.runtime.P2UpdateConstants;
|
||||
import org.talend.utils.io.FilesUtils;
|
||||
|
||||
public class P2UpdateHelper {
|
||||
|
||||
private static Object clearOsgiLock = new Object();
|
||||
|
||||
public static File backupConfigFile() throws IOException {
|
||||
try {
|
||||
File configurationFile = PathUtils.getStudioConfigFile();
|
||||
File tempFile = File.createTempFile(UpdatesHelper.FILE_CONFIG_INI, null);
|
||||
FilesUtils.copyFile(new FileInputStream(configurationFile), tempFile);
|
||||
return tempFile;
|
||||
} catch (Exception e) {
|
||||
if (e instanceof IOException) {
|
||||
throw (IOException) e;
|
||||
}
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreConfigFile(File toResore) throws IOException {
|
||||
try {
|
||||
File configurationFile = PathUtils.getStudioConfigFile();
|
||||
if (!IOUtils.contentEquals(new FileInputStream(configurationFile), new FileInputStream(toResore))) {
|
||||
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreTisService.class)) {
|
||||
ICoreTisService coreTisService = (ICoreTisService) GlobalServiceRegister.getDefault()
|
||||
.getService(ICoreTisService.class);
|
||||
coreTisService.updateConfiguratorBundles(configurationFile, toResore);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
if (toResore != null && toResore.exists()) {
|
||||
toResore.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static URI getP2RepositoryURI() {
|
||||
String updatesite = null;
|
||||
try (InputStream fis = new FileInputStream(PathUtils.getStudioConfigFile())) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(fis);
|
||||
updatesite = properties.getProperty(P2UpdateConstants.KEY_UPDATESITE_PATH);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
if (updatesite == null) {
|
||||
return null;
|
||||
}
|
||||
File file = new File(updatesite);
|
||||
if (file.isFile() || file.isDirectory()) {
|
||||
return file.toURI();
|
||||
}
|
||||
return URI.create(updatesite);
|
||||
}
|
||||
|
||||
public static List<String> getConfigFeatures(String type) {
|
||||
String targetFeatures = null;
|
||||
try (InputStream fis = new FileInputStream(PathUtils.getStudioConfigFile())) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(fis);
|
||||
targetFeatures = properties.getProperty(type);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
if (StringUtils.isBlank(targetFeatures)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(targetFeatures.trim().split(",")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static void clearConfigFeatures(String type) {
|
||||
Properties properties = new Properties();
|
||||
try (InputStream fis = new FileInputStream(PathUtils.getStudioConfigFile())) {
|
||||
properties.load(fis);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
try (OutputStream fos = new FileOutputStream(PathUtils.getStudioConfigFile())) {
|
||||
properties.setProperty(type, StringUtils.EMPTY);
|
||||
properties.store(fos, "Configuration File"); //$NON-NLS-1$
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateProductVersion(IProgressMonitor monitor, IProfile profile) throws IOException {
|
||||
Properties properties = new Properties();
|
||||
File eclipseProductFile = new File(
|
||||
Platform.getInstallLocation().getDataArea(UpdatesHelper.FILE_ECLIPSE_PRODUCT).getPath());
|
||||
try (InputStream in = new FileInputStream(eclipseProductFile)) {
|
||||
properties.load(in);
|
||||
}
|
||||
String oldVersion = properties.getProperty("version"); //$NON-NLS-1$
|
||||
Set<IInstallableUnit> queryResult = profile.query(QueryUtil.createIUQuery(P2UpdateConstants.STUDIO_CORE_FEATURE_ID), monitor)
|
||||
.toUnmodifiableSet();
|
||||
IInstallableUnit newCoreFeature = queryResult.stream().findFirst().get();
|
||||
String newVersion = newCoreFeature.getVersion().toString();
|
||||
if (oldVersion.endsWith(MavenConstants.SNAPSHOT)) {
|
||||
// for nightly build only.
|
||||
newVersion += MavenConstants.SNAPSHOT;
|
||||
}
|
||||
properties.setProperty("version", newVersion); //$NON-NLS-1$
|
||||
try (OutputStream out = new FileOutputStream(eclipseProductFile)) {
|
||||
properties.store(out, "Configuration File"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearOsgiCache() {
|
||||
synchronized (clearOsgiLock) {
|
||||
PlatformUI.getPreferenceStore().setValue(PreferenceKeys.NEED_OSGI_CLEAN, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user