<commit_before>/**
 * ***************************************************************
 * Agent.GUI is a framework to develop Multi-agent based simulation 
 * applications based on the JADE - Framework in compliance with the 
 * FIPA specifications. 
 * Copyright (C) 2010 <NAME> and DAWIS
 * http://www.dawis.wiwi.uni-due.de
 * http://sourceforge.net/projects/agentgui/
 * http://www.agentgui.org 
 *
 * GNU Lesser General Public License
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation,
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * **************************************************************
 */
package agentgui.core.update;

import javax.swing.JOptionPane;

import org.agentgui.gui.AwbProgressMonitor;
import org.agentgui.gui.UiBridge;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.operations.UpdateOperation;

import agentgui.core.application.Application;
import agentgui.core.application.Language;
import agentgui.core.config.GlobalInfo;
import agentgui.core.config.GlobalInfo.ExecutionEnvironment;
import agentgui.core.config.GlobalInfo.ExecutionMode;
import agentgui.core.gui.options.UpdateOptions;
import de.enflexit.common.p2.P2OperationsHandler;

/**
 * The Class AWBUpdater provides a thread that can be used to update
 * Agent.Workbench and its features.
 * 
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 */
public class AWBUpdater extends Thread {

	public static final long UPDATE_CHECK_PERIOD = 1000 * 60 * 60 * 24; // - once a day -

	// --- For the debugging of this class set true -------------
	private boolean debuggingInIDE = false;
	private boolean debug = false;
	private boolean updateDone = false;

	private GlobalInfo globalInfo;
	private ExecutionMode executionMode;

	private Integer updateAutoConfiguration;
	private long updateDateLastChecked = 0;

	private boolean manualyExecutedByUser = false;
	private boolean doUpdateProcedure = true;
	private boolean askBeforeDownload = false;
	
	private Object synchronizationObject;
	private AwbProgressMonitor progressMonitor;
	

	
	/**
	 * Instantiates a new Agent.GUI updater process.
	 */
	public AWBUpdater() {
		this(false);
	}
	/**
	 * Instantiates a new Agent.GUI updater process.
	 * @param userExecuted indicates that execution was manually chosen by user
	 */
	public AWBUpdater(boolean userExecuted) {
		this.manualyExecutedByUser = userExecuted;
		this.initialize();
	}
	/**
	 * Initialize and set needed local variables.
	 */
	private void initialize() {
		
		this.synchronizationObject = new Object();

		this.setName(Application.getGlobalInfo().getApplicationTitle() + "-Updater");

		this.globalInfo = Application.getGlobalInfo();
		this.executionMode = this.globalInfo.getExecutionMode();
		this.updateAutoConfiguration = this.globalInfo.getUpdateAutoConfiguration();
		this.updateDateLastChecked = this.globalInfo.getUpdateDateLastChecked();

		this.setUpdateConfiguration();
	}

	/**
	 * Sets the update configuration.
	 */
	private void setUpdateConfiguration() {

		if (this.manualyExecutedByUser==false) {
			long timeNow = System.currentTimeMillis();
			long time4NextCheck = this.updateDateLastChecked + AWBUpdater.UPDATE_CHECK_PERIOD;
			if (timeNow < time4NextCheck) {
				doUpdateProcedure = false;
			} else {<commit_msg>Made the P2 update enforcable<commit_after>/**
 * ***************************************************************
 * Agent.GUI is a framework to develop Multi-agent based simulation 
 * applications based on the JADE - Framework in compliance with the 
 * FIPA specifications. 
 * Copyright (C) 2010 <NAME> and DAWIS
 * http://www.dawis.wiwi.uni-due.de
 * http://sourceforge.net/projects/agentgui/
 * http://www.agentgui.org 
 *
 * GNU Lesser General Public License
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation,
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * **************************************************************
 */
package agentgui.core.update;

import javax.swing.JOptionPane;

import org.agentgui.gui.AwbProgressMonitor;
import org.agentgui.gui.UiBridge;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.operations.UpdateOperation;

import agentgui.core.application.Application;
import agentgui.core.application.Language;
import agentgui.core.config.GlobalInfo;
import agentgui.core.config.GlobalInfo.ExecutionEnvironment;
import agentgui.core.config.GlobalInfo.ExecutionMode;
import agentgui.core.gui.options.UpdateOptions;
import de.enflexit.common.p2.P2OperationsHandler;

/**
 * The Class AWBUpdater provides a thread that can be used to update
 * Agent.Workbench and its features.
 * 
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 */
public class AWBUpdater extends Thread {

	public static final long UPDATE_CHECK_PERIOD = 1000 * 60 * 60 * 24; // - once a day -

	// --- For the debugging of this class set true -------------
	private boolean debuggingInIDE = false;
	private boolean debug = false;
	private boolean updateDone = false;

	private GlobalInfo globalInfo;
	private ExecutionMode executionMode;

	private Integer updateAutoConfiguration;
	private long updateDateLastChecked = 0;

	private boolean manualyExecutedByUser = false;
	private boolean enforceUpdate = false;
	private boolean doUpdateProcedure = true;
	private boolean askBeforeDownload = false;
	
	private Object synchronizationObject;
	private AwbProgressMonitor progressMonitor;
	

	
	/**
	 * Instantiates a new Agent.Workbench updater process.
	 */
	public AWBUpdater() {
		this(false);
	}
	/**
	 * Instantiates a new Agent.Workbench updater process.
	 * @param userExecuted indicates that execution was manually chosen by user
	 */
	public AWBUpdater(boolean userExecuted) {
		this(userExecuted, false);
	}
	/**
	 * Instantiates a new Agent.Workbench updater process.
	 * @param userExecuted indicates that execution was manually chosen by user
	 * @param enforceUpdate the enforce update
	 */
	public AWBUpdater(boolean userExecuted, boolean enforceUpdate) {
		this.manualyExecutedByUser = userExecuted;
		this.enforceUpdate = enforceUpdate;
		this.initialize();
	}
	
	/**
	 * Initialize and set needed local variables.
	 */
	private void initialize() {
		
		this.synchronizationObject = new Object();

		this.setName(Application.getGlobalInfo().getApplicationTitle() + "-Updater");

		this.globalInfo = Application.getGlobalInfo();
		this.executionMode = this.globalInfo.getExecutionMode();
		this.updateAutoConfiguration = this.globalInfo.getUpdateAutoConfiguration();
		this.updateDateLastChecked = this.globalInfo.getUpdateDateLastChecked();

		this.setUpdateConfiguration();
	}

	/**
	 * Sets the update configuration.
	 */
	private void setUpdateConfiguration() {

		if (this.manualyExecutedByUser==false) {
			long timeNow = System.currentTimeMillis();
			long time4NextCheck = this.updateDateLastChecked + AWBUpdater.UPDATE_CHECK_PERIOD;
			if (this.enforceUpdate==false && timeNow < time4NextCheck) {
				this.doUpdateProcedure = false;
			} else {
{'fraction_non_alphanumeric': 0.11650018052713924, 'fraction_numerical': 0.008785654110001203, 'mean_word_length': 4.364751452550032, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1699904', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2241, 'n_words': 731}