Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'developer-studio-kernel-4.1.0' of https://github.com/ws…
Browse files Browse the repository at this point in the history
…o2/developer-studio into developer-studio-kernel-4.1.0
  • Loading branch information
Jasintha committed May 13, 2016
2 parents db6488e + b47fdf8 commit fc49508
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,125 +15,23 @@
*/
package org.wso2.developerstudio.eclipse.updater.handler;

import java.util.Calendar;

import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.PlatformUI;
import org.wso2.developerstudio.eclipse.logging.core.IDeveloperStudioLog;
import org.wso2.developerstudio.eclipse.logging.core.Logger;
import org.wso2.developerstudio.eclipse.platform.ui.WorkbenchToolkit;
import org.wso2.developerstudio.eclipse.platform.ui.preferences.PreferenceConstants;
import org.wso2.developerstudio.eclipse.platform.ui.preferences.PreferenceInitializer;
import org.wso2.developerstudio.eclipse.platform.ui.preferences.UpdateCheckerPreferencePage;
import org.wso2.developerstudio.eclipse.updater.UpdaterPlugin;
import org.wso2.developerstudio.eclipse.updater.core.UpdateManager;
import org.wso2.developerstudio.eclipse.updater.job.BackgroundUpdateTaskJob;
import org.wso2.developerstudio.eclipse.updater.job.BackgroundUpdaterTaskListener;
import org.wso2.developerstudio.eclipse.updater.job.UpdateMetaFileReaderJob;
import org.wso2.developerstudio.eclipse.updater.job.UpdateMetaFileReaderJobListener;
import org.wso2.developerstudio.eclipse.updater.ui.UpdaterDialog.ActiveTab;

public class StartupUpdateHandler implements IStartup {

private static final int DELAY_ONE_MINUTE = 60000;
protected static final String DAILY = "Daily";
protected static final String WEEKLY = "Weekly";
protected static final String MONTHLY = "Monthly";
protected long repeatDelay = 3600000;
protected long minute = 60000;

protected UpdateManager updateManager = new UpdateManager();


protected static IDeveloperStudioLog log = Logger.getLog(UpdaterPlugin.PLUGIN_ID);

@Override
public void earlyStartup() {
// check if user has set startup updates
// Read updater preferences
// Let updater wait a minute till workspace preferences are initialized
try {
Thread.sleep(DELAY_ONE_MINUTE);
} catch (InterruptedException e) {
log.error("error while running automatic updates", e);
Thread.currentThread().interrupt();
}
IPreferenceStore prefPage = PlatformUI.getPreferenceStore();
UpdateCheckerPreferencePage.setPreferenceDefaults(prefPage);
boolean isAutomaticUpdate = prefPage.getBoolean(PreferenceConstants.ENABLE_AUTOMATIC_UPDATES);
String updateRunConfig = prefPage.getString(PreferenceConstants.UPDATE_RUNNING_CONFIGURATION);
if (updateRunConfig == null || updateRunConfig.isEmpty()) {
updateRunConfig = PreferenceConstants.STARTUP;
}
if (updateRunConfig.equals(PreferenceConstants.SCHEDULE)) {
isAutomaticUpdate = false; // do not run at startup if user has
// scheduled the updater job
BackgroundUpdateTaskJob job = new BackgroundUpdateTaskJob("BackgroundScheduler", minute);
// start at user specified time.
job.schedule(evaluateTimeToUserScheduledTime());
job.addJobChangeListener(new BackgroundUpdaterTaskListener(updateManager));
}
if (!isAutomaticUpdate) {
return;
}
/**
* before running the update checker job, read the updates meta file and
* see if it has updates before iterating through the updater
* repository. UpdateMetaFileReaderJob
*/
runUpdateMetaFileReaderJob();
}

private void runUpdateMetaFileReaderJob() {
Job readMetaFileJob = new UpdateMetaFileReaderJob(updateManager);
readMetaFileJob.schedule();
readMetaFileJob.addJobChangeListener(
new UpdateMetaFileReaderJobListener(updateManager, ActiveTab.UPDATE_FEATURES, true));
}

private long evaluateTimeToUserScheduledTime() {
final IPreferenceStore prefPage = PlatformUI.getPreferenceStore();
String updateIntervalDay = prefPage.getString(PreferenceConstants.UPDATE_DATE_INTERVAL);
if (updateIntervalDay == null || updateIntervalDay.isEmpty()) {
updateIntervalDay = PreferenceConstants.DEFAULT_SUNDAY;
}
int intValOfDay = getIntValOfDay(updateIntervalDay);
String updateIntervalTime = prefPage.getString(PreferenceConstants.UPDATE_TIME_INTERVAL);
if (updateIntervalTime == null || updateIntervalTime.isEmpty()) {
updateIntervalTime = PreferenceConstants.DEFAULT_EIGHT_AM;
}

String[] hourValFromIntervalTime = updateIntervalTime.split(":");
Integer intHourVal = Integer.parseInt(hourValFromIntervalTime[0]);

Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_WEEK, intValOfDay);
c.set(Calendar.HOUR_OF_DAY, intHourVal);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return (c.getTimeInMillis() - System.currentTimeMillis());

}

private int getIntValOfDay(String updateIntervalDay) {
switch (updateIntervalDay) {
case (PreferenceConstants.EVERY_MONDAY):
return Calendar.MONDAY;
case (PreferenceConstants.EVERY_TUESDAY):
return Calendar.TUESDAY;
case (PreferenceConstants.EVERY_WEDNESDAY):
return Calendar.WEDNESDAY;
case (PreferenceConstants.EVERY_THURSDAY):
return Calendar.THURSDAY;
case (PreferenceConstants.EVERY_FRIDAY):
return Calendar.FRIDAY;
case (PreferenceConstants.EVERY_SATURDAY):
return Calendar.SATURDAY;
default:
return Calendar.SUNDAY; // case SUNDAY default setting
}

UpdaterRootJob updaterRootJob = new UpdaterRootJob("Running Developer Studio updater Tool");
updaterRootJob.schedule();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package org.wso2.developerstudio.eclipse.updater.handler;

import java.util.Calendar;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.PlatformUI;
import org.wso2.developerstudio.eclipse.logging.core.IDeveloperStudioLog;
import org.wso2.developerstudio.eclipse.logging.core.Logger;
import org.wso2.developerstudio.eclipse.platform.ui.preferences.PreferenceConstants;
import org.wso2.developerstudio.eclipse.platform.ui.preferences.UpdateCheckerPreferencePage;
import org.wso2.developerstudio.eclipse.updater.UpdaterPlugin;
import org.wso2.developerstudio.eclipse.updater.core.UpdateManager;
import org.wso2.developerstudio.eclipse.updater.job.BackgroundUpdateTaskJob;
import org.wso2.developerstudio.eclipse.updater.job.BackgroundUpdaterTaskListener;
import org.wso2.developerstudio.eclipse.updater.job.UpdateMetaFileReaderJob;
import org.wso2.developerstudio.eclipse.updater.job.UpdateMetaFileReaderJobListener;
import org.wso2.developerstudio.eclipse.updater.ui.UpdaterDialog.ActiveTab;

public class UpdaterRootJob extends Job {

private static final int DELAY_ONE_MINUTE = 60000;
protected static final String DAILY = "Daily";
protected static final String WEEKLY = "Weekly";
protected static final String MONTHLY = "Monthly";
protected long repeatDelay = 3600000;
protected long minute = 60000;

protected UpdateManager updateManager = new UpdateManager();

protected static IDeveloperStudioLog log = Logger.getLog(UpdaterPlugin.PLUGIN_ID);

public UpdaterRootJob(String name) {
super(name);
// TODO Auto-generated constructor stub
}

@Override
protected IStatus run(IProgressMonitor arg0) {
// TODO Auto-generated method stub
try {
Thread.sleep(DELAY_ONE_MINUTE);
} catch (InterruptedException e) {
log.error("error while running automatic updates", e);
Thread.currentThread().interrupt();
}
IPreferenceStore prefPage = PlatformUI.getPreferenceStore();
UpdateCheckerPreferencePage.setPreferenceDefaults(prefPage);
boolean isAutomaticUpdate = prefPage.getBoolean(PreferenceConstants.ENABLE_AUTOMATIC_UPDATES);
String updateRunConfig = prefPage.getString(PreferenceConstants.UPDATE_RUNNING_CONFIGURATION);
if (updateRunConfig == null || updateRunConfig.isEmpty()) {
updateRunConfig = PreferenceConstants.STARTUP;
}
if (updateRunConfig.equals(PreferenceConstants.SCHEDULE)) {
isAutomaticUpdate = false; // do not run at startup if user has
// scheduled the updater job
BackgroundUpdateTaskJob job = new BackgroundUpdateTaskJob("BackgroundScheduler", minute);
// start at user specified time.
job.schedule(evaluateTimeToUserScheduledTime());
job.addJobChangeListener(new BackgroundUpdaterTaskListener(updateManager));
}
if (!isAutomaticUpdate) {
return Status.CANCEL_STATUS;
}
/**
* before running the update checker job, read the updates meta file and
* see if it has updates before iterating through the updater
* repository. UpdateMetaFileReaderJob
*/
runUpdateMetaFileReaderJob();
return Status.OK_STATUS;
}

private void runUpdateMetaFileReaderJob() {
Job readMetaFileJob = new UpdateMetaFileReaderJob(updateManager);
readMetaFileJob.schedule();
readMetaFileJob.addJobChangeListener(
new UpdateMetaFileReaderJobListener(updateManager, ActiveTab.UPDATE_FEATURES, true));
}

private long evaluateTimeToUserScheduledTime() {
final IPreferenceStore prefPage = PlatformUI.getPreferenceStore();
String updateIntervalDay = prefPage.getString(PreferenceConstants.UPDATE_DATE_INTERVAL);
if (updateIntervalDay == null || updateIntervalDay.isEmpty()) {
updateIntervalDay = PreferenceConstants.DEFAULT_SUNDAY;
}
int intValOfDay = getIntValOfDay(updateIntervalDay);
String updateIntervalTime = prefPage.getString(PreferenceConstants.UPDATE_TIME_INTERVAL);
if (updateIntervalTime == null || updateIntervalTime.isEmpty()) {
updateIntervalTime = PreferenceConstants.DEFAULT_EIGHT_AM;
}

String[] hourValFromIntervalTime = updateIntervalTime.split(":");
Integer intHourVal = Integer.parseInt(hourValFromIntervalTime[0]);

Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_WEEK, intValOfDay);
c.set(Calendar.HOUR_OF_DAY, intHourVal);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return (c.getTimeInMillis() - System.currentTimeMillis());

}

private int getIntValOfDay(String updateIntervalDay) {
switch (updateIntervalDay) {
case (PreferenceConstants.EVERY_MONDAY):
return Calendar.MONDAY;
case (PreferenceConstants.EVERY_TUESDAY):
return Calendar.TUESDAY;
case (PreferenceConstants.EVERY_WEDNESDAY):
return Calendar.WEDNESDAY;
case (PreferenceConstants.EVERY_THURSDAY):
return Calendar.THURSDAY;
case (PreferenceConstants.EVERY_FRIDAY):
return Calendar.FRIDAY;
case (PreferenceConstants.EVERY_SATURDAY):
return Calendar.SATURDAY;
default:
return Calendar.SUNDAY; // case SUNDAY default setting
}

}
}

0 comments on commit fc49508

Please sign in to comment.