Author: rob.stryker(a)jboss.com
Date: 2012-02-23 02:53:30 -0500 (Thu, 23 Feb 2012)
New Revision: 39032
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java
Log:
JBIDE-11010 - error handling
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java 2012-02-23
07:51:17 UTC (rev 39031)
+++
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java 2012-02-23
07:53:30 UTC (rev 39032)
@@ -16,11 +16,14 @@
import org.eclipse.core.internal.variables.StringVariableManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
public class Fileset implements Cloneable {
@@ -33,14 +36,12 @@
public Fileset() {
}
public Fileset(String string) {
- try {
- name = folder = includesPattern =excludesPattern = ""; //$NON-NLS-1$
- String[] parts = string.split(SEP);
- name = parts[0];
- folder = parts[1];
- includesPattern = parts[2];
- excludesPattern = parts[3];
- } catch( ArrayIndexOutOfBoundsException aioobe) {}
+ name = folder = includesPattern =excludesPattern = ""; //$NON-NLS-1$
+ String[] parts = string.split(SEP);
+ name = parts.length <= 0 ? null : parts[0];
+ folder = parts.length <= 1 ? null : parts[1];
+ includesPattern = parts.length <= 2 ? null : parts[2];
+ excludesPattern = parts.length <= 3 ? null : parts[3];
}
public Fileset(String name, String folder, String inc, String exc) {
@@ -72,6 +73,10 @@
}
public static String getFolder(String folder, IRuntime runtime) {
+ return getFolder(folder, runtime, true);
+ }
+ public static String getFolder(String folder, IRuntime runtime, boolean ignoreError) {
+
String tmp = folder == null ? "" : folder; //$NON-NLS-1$
if( runtime != null ) {
tmp = tmp.replace(JBOSS_CONFIG_DIR_ARG, getConfigDirSubstitute(runtime));
@@ -81,7 +86,12 @@
StringSubstitutionEngine engine = new StringSubstitutionEngine();
tmp = engine.performStringSubstitution(tmp, true,
true, StringVariableManager.getDefault());
- } catch( CoreException ce ) {}
+ } catch( CoreException ce ) {
+ if( !ignoreError ) {
+ IntegrationPlugin.getDefault().getLog().log(
+ new Status(IStatus.WARNING, IntegrationPlugin.PLUGIN_ID, ce.getMessage(), ce));
+ }
+ }
IPath p = new Path(tmp);
if( !p.isAbsolute() && runtime != null ) {
@@ -158,10 +168,10 @@
}
public Object clone() {
- try {
- return super.clone();
- } catch( Exception e ) {}
- return null;
+ Fileset fs = new Fileset(name, folder, includesPattern, excludesPattern);
+ fs.setServer(server);
+ fs.setRuntime(runtime);
+ return fs;
}
public boolean equals(Object other) {
@@ -181,8 +191,18 @@
String excludes = getExcludesPattern();
return findPaths(dir, includes, excludes);
}
+
+ /**
+ * This method intentionally will not log any exceptions. It will only
+ * return an empty array if the scanner is incapable of scanning
+ * with the given parameters.
+ *
+ * @param dir
+ * @param includes
+ * @param excludes
+ * @return
+ */
public static IPath[] findPaths(String dir, String includes, String excludes) {
- IPath[] paths = new IPath[0];
try {
if (dir != null && new File(dir).exists()) {
DirectoryScanner scanner = DirectoryScannerFactory
@@ -190,15 +210,17 @@
null, false, 1, true);
if (scanner != null) {
String[] files = scanner.getIncludedFiles();
- paths = new IPath[files.length];
+ IPath[] paths = new IPath[files.length];
for (int i = 0; i < files.length; i++) {
paths[i] = new Path(files[i]);
}
+ return paths;
}
}
} catch (IllegalStateException ise) {
+ return new IPath[0];
}
- return paths;
+ return new IPath[0];
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java 2012-02-23
07:51:17 UTC (rev 39031)
+++
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java 2012-02-23
07:53:30 UTC (rev 39032)
@@ -13,7 +13,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
import org.apache.tools.ant.BuildException;
import org.eclipse.core.runtime.IPath;
@@ -21,7 +20,6 @@
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
public class FilesetContentProvider implements ITreeContentProvider {
private static final String FILESET_KEY =
"org.jboss.ide.eclipse.as.ui.views.server.providers.FilesetViewProvider.PropertyKey";
//$NON-NLS-1$
@@ -84,19 +82,18 @@
private void addPath(ArrayList<PathWrapper> children,
HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
- try {
- FolderWrapper fw = null;
- if (!folders.containsKey(path.segment(0))) {
- fw = new FolderWrapper(path.removeLastSegments(path
- .segmentCount() - 1), folder);
- folders.put(path.segment(0), fw);
+ FolderWrapper fw = null;
+ if (path.segmentCount() > 0) {
+ String seg1 = path.segment(0);
+ if( !folders.containsKey(seg1)) {
+ fw = new FolderWrapper(path.removeLastSegments(
+ path.segmentCount() - 1), folder);
+ folders.put(seg1, fw);
children.add(fw);
} else {
- fw = folders.get(path.segment(0));
+ fw = folders.get(seg1);
}
fw.addChild(path.removeFirstSegments(1));
- } catch (Exception e) {
- e.printStackTrace();
}
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java 2012-02-23
07:51:17 UTC (rev 39031)
+++
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java 2012-02-23
07:53:30 UTC (rev 39032)
@@ -18,7 +18,10 @@
import java.io.InputStream;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.tools.jmx.core.IMemento;
import org.jboss.tools.jmx.core.util.XMLMemento;
@@ -38,12 +41,13 @@
* @return
*/
public static Fileset[] loadFilesets(File file, IServer server) {
- if( file != null && file.exists()) {
- try {
- return loadFilesets(new FileInputStream(file), server);
- } catch( FileNotFoundException fnfe) {}
+ if( file == null || !file.exists())
+ return new Fileset[0];
+ try {
+ return loadFilesets(new FileInputStream(file), server);
+ } catch( FileNotFoundException fnfe) {
+ return new Fileset[0];
}
- return new Fileset[]{};
}
/**
@@ -101,7 +105,9 @@
try {
memento.save(new FileOutputStream(file));
} catch( IOException ioe) {
- // TODO LOG
+ IntegrationPlugin.getDefault().getLog().log(
+ new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID, ioe.getMessage(), ioe)
+ );
}
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java 2012-02-23
07:51:17 UTC (rev 39031)
+++
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java 2012-02-23
07:53:30 UTC (rev 39032)
@@ -8,13 +8,13 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerType;
import org.eclipse.wst.server.core.ServerCore;
import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.UnitedServerListener;
public class NewServerFilesetHandler extends UnitedServerListener {
@@ -28,20 +28,23 @@
protected NewServerFilesetHandler() {
IServerType[] types = ServerCore.getServerTypes();
for( int i = 0; i < types.length; i++ ) {
- try {
- IPath fileToWrite = FilesetUtil.DEFAULT_FS_ROOT.append(types[i].getId());
- if( !fileToWrite.toFile().exists()) {
- IPath p = new Path("filesetdata").append(types[i].getId()); //$NON-NLS-1$
- URL url = FileLocator.find(IntegrationPlugin.getDefault().getBundle(), p, null);
- if( url != null ) {
+ IPath fileToWrite = FilesetUtil.DEFAULT_FS_ROOT.append(types[i].getId());
+ if( !fileToWrite.toFile().exists()) {
+ IPath p = new Path("filesetdata").append(types[i].getId()); //$NON-NLS-1$
+ URL url = FileLocator.find(IntegrationPlugin.getDefault().getBundle(), p, null);
+ if( url != null ) {
+ try {
InputStream fis = url.openStream();
Fileset[] sets = FilesetUtil.loadFilesets(fis, null);
if( sets != null && sets.length != 0 ) {
FilesetUtil.saveFilesets(fileToWrite.toFile(), sets);
}
+ } catch(IOException ioe) {
+ IntegrationPlugin.getDefault().getLog().log(
+ new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID, ioe.getMessage(), ioe));
}
}
- } catch(IOException ioe) {}
+ }
}
}