001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Sep 17, 2007
014: * @author Will Gorman
015: */
016: package org.pentaho.plugin.versionchecker;
017:
018: import java.util.List;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.pentaho.messages.Messages;
023: import org.pentaho.plugin.ComponentBase;
024:
025: /**
026: * Version Check Component
027: * This component makes a call to pentaho's server to see if a new version
028: * is a vailable.
029: *
030: * Uses reflection helper so that versioncheck.jar can be deleted without
031: * problems
032: *
033: * input param "ignoreExistingUpdates" - if true, ignore existing updates discovered
034: *
035: * @author Will Gorman
036: *
037: */
038: public class PentahoVersionCheckComponent extends ComponentBase {
039:
040: private static final long serialVersionUID = 8178713714323100555L;
041:
042: private static final String DOCUMENT = "document"; //$NON-NLS-1$
043:
044: public Log getLogger() {
045: return LogFactory.getLog(PentahoVersionCheckComponent.class);
046: }
047:
048: protected boolean validateSystemSettings() {
049: return true;
050: }
051:
052: protected boolean validateAction() {
053: return true;
054: }
055:
056: public void done() {
057:
058: }
059:
060: protected boolean executeAction() {
061:
062: String output = null;
063:
064: boolean ignoreExistingUpdates = getInputBooleanValue(
065: "ignoreExistingUpdates", true); //$NON-NLS-1$
066:
067: // pull out release flags from the releaseFlags string
068: int versionRequestFlags = -1;
069: try {
070: Object releaseFlagsObj = getInputValue("releaseFlags"); //$NON-NLS-1$
071: String releaseFlags = ""; //$NON-NLS-1$
072: if (releaseFlagsObj instanceof String[]) {
073: String[] arr = (String[]) releaseFlagsObj;
074: if (arr.length > 0) {
075: releaseFlags += arr[0];
076: for (int i = 1; i < arr.length; i++) {
077: releaseFlags += "," + arr[i]; //$NON-NLS-1$
078: }
079: }
080: } else {
081: releaseFlags = releaseFlagsObj.toString();
082: }
083:
084: if (releaseFlags != null) {
085: releaseFlags = releaseFlags.toLowerCase();
086: boolean requestMajorReleases = releaseFlags
087: .indexOf("major") >= 0; //$NON-NLS-1$
088: boolean requestMinorReleases = releaseFlags
089: .indexOf("minor") >= 0; //$NON-NLS-1$
090: boolean requestRCReleases = releaseFlags.indexOf("rc") >= 0; //$NON-NLS-1$
091: boolean requestGAReleases = releaseFlags.indexOf("ga") >= 0; //$NON-NLS-1$
092: boolean requestMilestoneReleases = releaseFlags
093: .indexOf("milestone") >= 0; //$NON-NLS-1$
094:
095: versionRequestFlags = (requestMajorReleases ? 4 : 0)
096: + (requestMinorReleases ? 8 : 0)
097: + (requestRCReleases ? 16 : 0)
098: + (requestGAReleases ? 32 : 0)
099: + (requestMilestoneReleases ? 64 : 0);
100: }
101: } catch (Exception e) {
102: // ignore errors
103: }
104:
105: if (PentahoVersionCheckReflectHelper
106: .isVersionCheckerAvailable()) {
107: List results = PentahoVersionCheckReflectHelper
108: .performVersionCheck(ignoreExistingUpdates,
109: versionRequestFlags);
110: output = PentahoVersionCheckReflectHelper.logVersionCheck(
111: results, getLogger());
112: } else {
113: output = "<vercheck><error><[!CDATA[" + Messages.getString("VersionCheck.VERSION_CHECK_DISABLED") + "]]></error></vercheck>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
114: }
115:
116: if (isDefinedOutput(DOCUMENT)) {
117: setOutputValue(DOCUMENT, output);
118: }
119: return true;
120: }
121:
122: public boolean init() {
123: return true;
124: }
125:
126: }
|