JBoss Tools SVN: r43239 - branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server.
by jbosstools-commits@lists.jboss.org
Author: ljelinko
Date: 2012-08-27 03:01:39 -0400 (Mon, 27 Aug 2012)
New Revision: 43239
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java
Log:
Added wait for dialog to disappear
Modified: branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java
===================================================================
--- branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java 2012-08-27 06:59:53 UTC (rev 43238)
+++ branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java 2012-08-27 07:01:39 UTC (rev 43239)
@@ -58,7 +58,7 @@
}
log.info("Waiting for confirmation shell to disappear");
- SWTBotFactory.getBot().waitUntil(shellIsActive("Really mark these resources as deployable?"));
+ SWTBotFactory.getBot().waitWhile(shellIsActive("Really mark these resources as deployable?"));
}
private boolean isWindowsOS(){
12 years, 4 months
JBoss Tools SVN: r43238 - branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server.
by jbosstools-commits@lists.jboss.org
Author: ljelinko
Date: 2012-08-27 02:59:53 -0400 (Mon, 27 Aug 2012)
New Revision: 43238
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java
Log:
Added logging
Modified: branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java
===================================================================
--- branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java 2012-08-27 06:37:18 UTC (rev 43237)
+++ branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java 2012-08-27 06:59:53 UTC (rev 43238)
@@ -6,6 +6,7 @@
import java.awt.Robot;
import java.awt.event.KeyEvent;
+import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.jboss.tools.portlet.ui.bot.entity.WorkspaceFile;
@@ -21,6 +22,8 @@
*/
public class MarkFileAsDeployableTask extends AbstractSWTTask {
+ private static final Logger log = Logger.getLogger(MarkFileAsDeployableTask.class);
+
private WorkspaceFile workspaceFile;
public MarkFileAsDeployableTask(WorkspaceFile file) {
@@ -29,16 +32,20 @@
@Override
public void perform() {
+ log.info("Marking " + workspaceFile.getFileName() + " as deployable");
performInnerTask(new FileContextMenuSelectingTask(workspaceFile, "Mark as Deployable"));
+ log.info("Waiting for confirmation shell to appear");
SWTBotFactory.getBot().waitUntil(shellIsActive("Really mark these resources as deployable?"));
// for the confirmation dialog select OK (the dialog is native and normal swtbot functions do now work)
try {
Robot robot = new Robot();
if (!isWindowsOS()){
+ log.info("Non Windows OS");
KeyboardFactory.getAWTKeyboard().pressShortcut(Keystrokes.RIGHT, Keystrokes.CR, Keystrokes.LF);
} else {
+ log.info("Windows OS");
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_LEFT);
@@ -49,6 +56,9 @@
} catch (AWTException e) {
throw new IllegalStateException("Cannot create instance of " + Robot.class + " in order to close native dialog", e);
}
+
+ log.info("Waiting for confirmation shell to disappear");
+ SWTBotFactory.getBot().waitUntil(shellIsActive("Really mark these resources as deployable?"));
}
private boolean isWindowsOS(){
12 years, 4 months
JBoss Tools SVN: r43237 - branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server.
by jbosstools-commits@lists.jboss.org
Author: ljelinko
Date: 2012-08-27 02:37:18 -0400 (Mon, 27 Aug 2012)
New Revision: 43237
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java
Log:
Changed handling of non Windows system back to SWTBot
Modified: branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java
===================================================================
--- branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java 2012-08-27 06:36:34 UTC (rev 43236)
+++ branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/task/server/MarkFileAsDeployableTask.java 2012-08-27 06:37:18 UTC (rev 43237)
@@ -6,6 +6,8 @@
import java.awt.Robot;
import java.awt.event.KeyEvent;
+import org.eclipse.swtbot.swt.finder.keyboard.KeyboardFactory;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
import org.jboss.tools.portlet.ui.bot.entity.WorkspaceFile;
import org.jboss.tools.portlet.ui.bot.task.AbstractSWTTask;
import org.jboss.tools.portlet.ui.bot.task.workspace.FileContextMenuSelectingTask;
@@ -35,16 +37,15 @@
try {
Robot robot = new Robot();
if (!isWindowsOS()){
- robot.keyPress(KeyEvent.VK_RIGHT);
- robot.keyRelease(KeyEvent.VK_RIGHT);
+ KeyboardFactory.getAWTKeyboard().pressShortcut(Keystrokes.RIGHT, Keystrokes.CR, Keystrokes.LF);
} else {
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_LEFT);
robot.keyRelease(KeyEvent.VK_LEFT);
+ robot.keyPress(KeyEvent.VK_ENTER);
+ robot.keyRelease(KeyEvent.VK_ENTER);
}
- robot.keyPress(KeyEvent.VK_ENTER);
- robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
throw new IllegalStateException("Cannot create instance of " + Robot.class + " in order to close native dialog", e);
}
12 years, 4 months
JBoss Tools SVN: r43236 - trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test.
by jbosstools-commits@lists.jboss.org
Author: jjankovi
Date: 2012-08-27 02:36:34 -0400 (Mon, 27 Aug 2012)
New Revision: 43236
Modified:
trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/ArchivesTestBase.java
trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/VariousProjectsArchiving.java
Log:
enhancing of archive bot tests
Modified: trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/ArchivesTestBase.java
===================================================================
--- trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/ArchivesTestBase.java 2012-08-27 06:35:38 UTC (rev 43235)
+++ trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/ArchivesTestBase.java 2012-08-27 06:36:34 UTC (rev 43236)
@@ -106,9 +106,10 @@
return serversView;
}
- public void assertClearErrorLog() {
- assertTrue("Error log contains some records",
- new ErrorLogView().getRecordCount() == 0);
+ public void assertClearArchivesErrorLog() {
+
+ assertTrue("Error log contains archive errors",
+ countOfArchivesErrors() == 0);
}
public static void showErrorView() {
@@ -144,4 +145,15 @@
ImportHelper.importProject(projectLocation, dir, Activator.PLUGIN_ID);
}
+ private int countOfArchivesErrors() {
+ ErrorLogView errorLog = new ErrorLogView();
+ int archivesErrorsCount = 0;
+ for (SWTBotTreeItem ti : errorLog.getMessages()) {
+ if (ti.getText().contains("org.jboss.ide.eclipse.archives")) {
+ archivesErrorsCount++;
+ }
+ }
+ return archivesErrorsCount;
+ }
+
}
Modified: trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/VariousProjectsArchiving.java
===================================================================
--- trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/VariousProjectsArchiving.java 2012-08-27 06:35:38 UTC (rev 43235)
+++ trunk/archives/tests/org.jboss.tools.archives.ui.bot.test/src/org/jboss/tools/archives/ui/bot/test/VariousProjectsArchiving.java 2012-08-27 06:36:34 UTC (rev 43236)
@@ -35,7 +35,7 @@
@After
public void checkErrorLog() {
- assertClearErrorLog();
+ assertClearArchivesErrorLog();
}
@Test
@@ -54,9 +54,6 @@
/* create archive */
view.createNewJarArchive(project).finish();
- /* workaround JBIDE-11878 */
- view = viewForProject(project);
-
/* test if archive was created and no error was thrown*/
assertItemExistsInView(view,
project, project + ".jar [/" + project + "]");
@@ -78,9 +75,6 @@
/* create archive */
view.createNewJarArchive(project).finish();
- /* workaround JBIDE-11878 */
- view = viewForProject(project);
-
/* test if archive was created and no error was thrown*/
assertItemExistsInView(view,
project, project + ".jar [/" + project + "]");
12 years, 4 months
JBoss Tools SVN: r43235 - trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view.
by jbosstools-commits@lists.jboss.org
Author: jjankovi
Date: 2012-08-27 02:35:38 -0400 (Mon, 27 Aug 2012)
New Revision: 43235
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ErrorLogView.java
Log:
added method for obtaining errors tree items from error log
Modified: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ErrorLogView.java
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ErrorLogView.java 2012-08-25 09:35:49 UTC (rev 43234)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/view/ErrorLogView.java 2012-08-27 06:35:38 UTC (rev 43235)
@@ -29,6 +29,10 @@
for (SWTBotTreeItem i : items)
passTree(i);
}
+
+ public SWTBotTreeItem[] getMessages() {
+ return getView().bot().tree().getAllItems();
+ }
private void passTree(SWTBotTreeItem item) {
int i = 0;
12 years, 4 months
JBoss Tools SVN: r43234 - in trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common: core/classpath and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2012-08-25 05:35:49 -0400 (Sat, 25 Aug 2012)
New Revision: 43234
Added:
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainer.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainerInitializer.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorations.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorationsManager.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/IMemento.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLMemento.java
Modified:
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties
Log:
JBIDE-12481 add some classes from jmx / as.classpath to common
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java 2012-08-25 06:14:56 UTC (rev 43233)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -20,6 +20,9 @@
public static String SAXValidator_UnableToInstantiateMessage;
public static String XMLUtilities_IOExceptionMessage;
public static String XMLUtilities_SAXExceptionMessage;
+ public static String AbstractClasspathContainer_error_loading_container;
+ public static String ClasspathDecorationsManager_unexpected_exception;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainer.java (from rev 43203, trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/jee/AbstractClasspathContainer.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainer.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainer.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.core.classpath;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+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.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.jboss.tools.common.core.CommonCorePlugin;
+import org.jboss.tools.common.core.Messages;
+
+/**
+ *
+ * @author Rob Stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public abstract class AbstractClasspathContainer implements IClasspathContainer {
+
+ public static final String LIB_FOLDER = "lib"; //$NON-NLS-1$
+ public static final String LIB_SOURCE_FOLDER = "libsrc"; //$NON-NLS-1$
+ public final static String CLASSPATH_CONTAINER_PREFIX = "org.jboss.ide.eclipse.as.classpath.core"; //$NON-NLS-1$
+
+ protected IClasspathEntry[] entries;
+ protected IPath path;
+ protected String description;
+ protected String libFolder;
+ protected IJavaProject javaProject;
+
+ protected static ClasspathDecorationsManager decorations;
+ static {
+
+ decorations = new ClasspathDecorationsManager();
+ }
+
+ public AbstractClasspathContainer(IPath path, String description,
+ String libFolder, IJavaProject project) {
+ this.path = path;
+ this.description = description;
+ this.libFolder = libFolder;
+ this.javaProject = project;
+ }
+
+ public IClasspathEntry[] getClasspathEntries() {
+ if (entries == null) {
+ entries = computeEntries();
+ }
+ return entries;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public int getKind() {
+ return IClasspathContainer.K_APPLICATION;
+ }
+
+ public IPath getPath() {
+ return this.path;
+ }
+
+ protected IClasspathEntry[] computeEntries() {
+ ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
+
+ String baseDir = getBaseDir();
+ if (baseDir == null)
+ return new IClasspathEntry[0];
+
+ File libDir = new File(baseDir
+ + "/" + LIB_FOLDER + "/" + getLibFolder());//$NON-NLS-1$ //$NON-NLS-2$
+ File libSrcDir = new File(baseDir
+ + "/" + LIB_SOURCE_FOLDER + "/" + getLibFolder());//$NON-NLS-1$ //$NON-NLS-2$
+
+ // Lists every modules in the lib dir
+ File[] jars = libDir.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return (file.toString().endsWith(".jar"));//$NON-NLS-1$
+ }
+ });
+
+ if (jars != null) {
+ for (int i = 0; i < jars.length; i++) {
+ File jarFile = jars[i];
+ String jarFileName = jarFile.getName();
+ File jarSrcFile = new File(libSrcDir, jarFileName);
+
+ IPath entryPath = new Path(jarFile.toString());
+
+ IPath sourceAttachementPath = null;
+ IPath sourceAttachementRootPath = null;
+
+ final ClasspathDecorations dec
+ = decorations.getDecorations( getDecorationManagerKey(getPath().toString()), entryPath.toString() );
+
+
+ IClasspathAttribute[] attrs = {};
+ if( dec != null ) {
+ sourceAttachementPath = dec.getSourceAttachmentPath();
+ sourceAttachementRootPath = dec.getSourceAttachmentRootPath();
+ attrs = dec.getExtraAttributes();
+ } else if (jarSrcFile.exists()) {
+ sourceAttachementPath = new Path(jarSrcFile.toString());
+ sourceAttachementRootPath = new Path("/");//$NON-NLS-1$
+ }
+
+ IAccessRule[] access = {};
+ IClasspathEntry entry = JavaCore.newLibraryEntry( entryPath, sourceAttachementPath,
+ sourceAttachementRootPath, access, attrs, false );
+ entries.add(entry);
+ }
+ }
+
+ return entries.toArray(new IClasspathEntry[entries.size()]);
+ }
+
+ protected String getLibFolder() {
+ return this.libFolder;
+ }
+
+ protected String getBaseDir() {
+ try {
+ URL installURL = FileLocator.toFileURL(CommonCorePlugin
+ .getDefault().getBundle().getEntry("/")); //$NON-NLS-1$
+ return installURL.getFile().toString();
+ } catch (IOException ioe) {
+ // LOG THE ERROR (one day)
+ IStatus status = new Status(IStatus.ERROR, CommonCorePlugin.PLUGIN_ID,
+ Messages.AbstractClasspathContainer_error_loading_container, ioe);
+ CommonCorePlugin.getDefault().getLog().log(status);
+ }
+ return null;
+ }
+
+ public static String getDecorationManagerKey( String container){
+ return container;
+ }
+
+ protected static ClasspathDecorationsManager getDecorationsManager() {
+ return decorations;
+ }
+
+ public void install() {
+ entries = computeEntries();
+ IJavaProject[] javaProjects = new IJavaProject[] {javaProject};
+ final IClasspathContainer[] conts = new IClasspathContainer[] { this };
+ try {
+ JavaCore.setClasspathContainer(path, javaProjects, conts, null);
+ } catch (CoreException e) {
+ CommonCorePlugin.getDefault().logError(e);
+ }
+ }
+
+ public abstract void refresh();
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainerInitializer.java (from rev 43203, trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/jee/AbstractClasspathContainerInitializer.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainerInitializer.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/AbstractClasspathContainerInitializer.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.core.classpath;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ClasspathContainerInitializer;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ *
+ * @author Rob Stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public abstract class AbstractClasspathContainerInitializer extends
+ ClasspathContainerInitializer {
+
+ protected IJavaProject javaProject;
+ public AbstractClasspathContainerInitializer() {
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param containerPath
+ * Description of the Parameter
+ * @param project
+ * Description of the Parameter
+ * @exception CoreException
+ * Description of the Exception
+ */
+ public void initialize(IPath containerPath, IJavaProject project)
+ throws CoreException {
+ this.javaProject = project;
+ int size = containerPath.segmentCount();
+ if (size > 0) {
+ AbstractClasspathContainer container = createClasspathContainer(containerPath);
+ JavaCore.setClasspathContainer(containerPath,
+ new IJavaProject[] { project },
+ new IClasspathContainer[] { container }, null);
+ }
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param path
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected abstract AbstractClasspathContainer createClasspathContainer(
+ IPath path);
+
+ /**
+ * Gets the classpathContainerID attribute of the
+ * AbstractClasspathContainerInitializer object
+ *
+ * @return The classpathContainerID value
+ */
+ protected abstract String getClasspathContainerID();
+
+ public boolean canUpdateClasspathContainer(IPath containerPath,
+ IJavaProject project) {
+ return true;
+ }
+
+ public void requestClasspathContainerUpdate(final IPath containerPath,
+ final IJavaProject project, final IClasspathContainer sg)
+
+ throws CoreException
+
+ {
+ String key = AbstractClasspathContainer
+ .getDecorationManagerKey(containerPath.toString());
+
+ IClasspathEntry[] entries = sg.getClasspathEntries();
+ ClasspathDecorationsManager decorations = AbstractClasspathContainer
+ .getDecorationsManager();
+ decorations.clearAllDecorations(key);
+
+ for (int i = 0; i < entries.length; i++) {
+ final IClasspathEntry entry = entries[i];
+
+ final IPath srcpath = entry.getSourceAttachmentPath();
+ final IPath srcrootpath = entry.getSourceAttachmentRootPath();
+ final IClasspathAttribute[] attrs = entry.getExtraAttributes();
+ final String eid = entry.getPath().toString();
+ final ClasspathDecorations dec = new ClasspathDecorations();
+
+ dec.setSourceAttachmentPath(srcpath);
+ dec.setSourceAttachmentRootPath(srcrootpath);
+ dec.setExtraAttributes(attrs);
+
+ decorations.setDecorations(key, eid, dec);
+ }
+ decorations.save();
+ final IClasspathContainer container = JavaCore.getClasspathContainer(
+ containerPath, project);
+ ((AbstractClasspathContainer) container).refresh();
+ }
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorations.java (from rev 43203, trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/xpl/ClasspathDecorations.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorations.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorations.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -0,0 +1,65 @@
+/******************************************************************************
+ * Copyright (c) 2005 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Konstantin Komissarchik - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.core.classpath;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
+ */
+
+public final class ClasspathDecorations {
+ private IPath sourceAttachmentPath;
+ private IPath sourceAttachmentRootPath;
+ private ArrayList extraAttributes = new ArrayList();
+
+ public IPath getSourceAttachmentPath() {
+ return this.sourceAttachmentPath;
+ }
+
+ public void setSourceAttachmentPath(final IPath sourceAttachmentPath) {
+ this.sourceAttachmentPath = sourceAttachmentPath;
+ }
+
+ public IPath getSourceAttachmentRootPath() {
+ return this.sourceAttachmentRootPath;
+ }
+
+ public void setSourceAttachmentRootPath(final IPath sourceAttachmentRootPath) {
+ this.sourceAttachmentRootPath = sourceAttachmentRootPath;
+ }
+
+ public IClasspathAttribute[] getExtraAttributes() {
+ final IClasspathAttribute[] array = new IClasspathAttribute[this.extraAttributes
+ .size()];
+
+ return (IClasspathAttribute[]) this.extraAttributes.toArray(array);
+ }
+
+ public void setExtraAttributes(final IClasspathAttribute[] attrs) {
+ for (int i = 0; i < attrs.length; i++) {
+ this.extraAttributes.add(attrs[i]);
+ }
+ }
+
+ public void addExtraAttribute(final String name, final String value) {
+ final IClasspathAttribute attr = JavaCore.newClasspathAttribute(name,
+ value);
+
+ this.extraAttributes.add(attr);
+ }
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorationsManager.java (from rev 43203, trunk/as/plugins/org.jboss.ide.eclipse.as.classpath.core/src/org/jboss/ide/eclipse/as/classpath/core/xpl/ClasspathDecorationsManager.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorationsManager.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/classpath/ClasspathDecorationsManager.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -0,0 +1,316 @@
+/******************************************************************************
+ * Copyright (c) 2005 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Konstantin Komissarchik - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.core.classpath;
+
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.jboss.tools.common.core.CommonCorePlugin;
+import org.jboss.tools.common.core.Messages;
+import org.osgi.service.prefs.BackingStoreException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
+ */
+
+public final class ClasspathDecorationsManager {
+ private static final String CLASSPATH_PREFERENCES = "classpathPreferences"; //$NON-NLS-1$
+ private static final String SEPARATOR = System
+ .getProperty("line.separator"); //$NON-NLS-1$
+ private final HashMap decorations;
+
+ public ClasspathDecorationsManager() {
+ this.decorations = read();
+ }
+
+ private IEclipsePreferences getEclipsePreferences() {
+ IEclipsePreferences node = (IEclipsePreferences) Platform
+ .getPreferencesService().getRootNode()
+ .node(InstanceScope.SCOPE).node(CommonCorePlugin.PLUGIN_ID);
+ return node;
+ }
+
+ private String getPreferences() {
+ return getEclipsePreferences().get(CLASSPATH_PREFERENCES, null);
+ }
+
+ public ClasspathDecorations getDecorations(final String key,
+ final String entry) {
+ final HashMap submap = (HashMap) this.decorations.get(key);
+
+ if (submap == null) {
+ return null;
+ }
+
+ return (ClasspathDecorations) submap.get(entry);
+ }
+
+ public void setDecorations(final String key, final String entry,
+ final ClasspathDecorations dec) {
+ HashMap submap = (HashMap) this.decorations.get(key);
+
+ if (submap == null) {
+ submap = new HashMap();
+ this.decorations.put(key, submap);
+ }
+
+ submap.put(entry, dec);
+ }
+
+ public void clearAllDecorations(final String key) {
+ this.decorations.remove(key);
+ }
+
+ public void save() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<classpath>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+ for (Iterator itr1 = decorations.entrySet().iterator(); itr1.hasNext();) {
+ final Map.Entry entry1 = (Map.Entry) itr1.next();
+ final Map submap = (Map) entry1.getValue();
+
+ buffer.append(" <container id=\""); //$NON-NLS-1$
+ buffer.append((String) entry1.getKey());
+ buffer.append("\">"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+
+ for (Iterator itr2 = submap.entrySet().iterator(); itr2.hasNext();) {
+ final Map.Entry entry2 = (Map.Entry) itr2.next();
+
+ final ClasspathDecorations dec = (ClasspathDecorations) entry2
+ .getValue();
+
+ buffer.append(" <entry id=\""); //$NON-NLS-1$
+ buffer.append((String) entry2.getKey());
+ buffer.append("\">"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+
+ String src = ""; //$NON-NLS-1$
+ if (dec.getSourceAttachmentPath() != null) {
+ src = dec.getSourceAttachmentPath().toString();
+ }
+ buffer.append(" <source-attachment-path>"); //$NON-NLS-1$
+ buffer.append(src);
+ buffer.append("</source-attachment-path>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+
+ if (dec.getSourceAttachmentRootPath() != null) {
+ buffer.append(" <source-attachment-root-path>"); //$NON-NLS-1$
+ buffer.append(dec.getSourceAttachmentRootPath().toString());
+ buffer.append("</source-attachment-root-path>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+ }
+
+ final IClasspathAttribute[] attrs = dec.getExtraAttributes();
+
+ for (int i = 0; i < attrs.length; i++) {
+ final IClasspathAttribute attr = attrs[i];
+
+ buffer.append(" <attribute name=\""); //$NON-NLS-1$
+ buffer.append(attr.getName());
+ buffer.append("\">"); //$NON-NLS-1$
+ buffer.append(attr.getValue());
+ buffer.append("</attribute>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+ }
+
+ buffer.append(" </entry>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+ }
+
+ buffer.append(" </container>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+ }
+
+ buffer.append("</classpath>"); //$NON-NLS-1$
+ buffer.append(SEPARATOR);
+ IEclipsePreferences ep = getEclipsePreferences();
+ ep.put(CLASSPATH_PREFERENCES, buffer.toString());
+ try {
+ ep.flush();
+ } catch (BackingStoreException e) {
+ String msg = Messages.ClasspathDecorationsManager_unexpected_exception;
+ CommonCorePlugin.getDefault().logError(msg, e);
+ }
+ }
+
+ private HashMap read() {
+ final HashMap map = new HashMap();
+ String prefs = getPreferences();
+ if (prefs == null || prefs.length() <= 0)
+ return map;
+
+ Element root = null;
+ try {
+ final DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+
+ final DocumentBuilder docbuilder = factory.newDocumentBuilder();
+
+ StringReader reader = new StringReader(prefs);
+ InputSource source = new InputSource(reader);
+ root = docbuilder.parse(source).getDocumentElement();
+ } catch (Exception e) {
+ String msg = Messages.ClasspathDecorationsManager_unexpected_exception;
+ CommonCorePlugin.getDefault().logError(msg, e);
+ return map;
+ }
+
+ for (Iterator itr1 = elements(root, "container"); itr1.hasNext();) //$NON-NLS-1$
+ {
+ final Element e1 = (Element) itr1.next();
+ final String cid = e1.getAttribute("id"); //$NON-NLS-1$
+
+ final HashMap submap = new HashMap();
+ map.put(cid, submap);
+
+ for (Iterator itr2 = elements(e1, "entry"); itr2.hasNext();) //$NON-NLS-1$
+ {
+ final Element e2 = (Element) itr2.next();
+ final String eid = e2.getAttribute("id"); //$NON-NLS-1$
+ final ClasspathDecorations dec = new ClasspathDecorations();
+
+ submap.put(eid, dec);
+
+ for (Iterator itr3 = elements(e2); itr3.hasNext();) {
+ final Element e3 = (Element) itr3.next();
+ final String n = e3.getNodeName();
+ String text = text(e3);
+ if (text != null) {
+ if (n.equals("source-attachment-path")) //$NON-NLS-1$
+ {
+ dec.setSourceAttachmentPath(new Path(text(e3)));
+ } else if (n.equals("source-attachment-root-path")) //$NON-NLS-1$
+ {
+ dec.setSourceAttachmentRootPath(new Path(text(e3)));
+ }
+ }
+ if (n.equals("attribute")) //$NON-NLS-1$
+ {
+ final String name = e3.getAttribute("name"); //$NON-NLS-1$
+ dec.addExtraAttribute(name, text(e3));
+ }
+
+ }
+ }
+ }
+
+ return map;
+ }
+
+ private static String text(final Element el) {
+ final NodeList nodes = el.getChildNodes();
+
+ String str = null;
+ StringBuffer buf = null;
+
+ for (int i = 0, n = nodes.getLength(); i < n; i++) {
+ final Node node = nodes.item(i);
+
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ final String val = node.getNodeValue();
+
+ if (buf != null) {
+ buf.append(val);
+ } else if (str != null) {
+ buf = new StringBuffer();
+ buf.append(str);
+ buf.append(val);
+
+ str = null;
+ } else {
+ str = val;
+ }
+ }
+ }
+
+ if (buf != null) {
+ return buf.toString();
+ }
+ return str;
+ }
+
+ private static Iterator elements(final Element el, final String name) {
+ return new ElementsIterator(el, name);
+ }
+
+ private static Iterator elements(final Element el) {
+ return new ElementsIterator(el, null);
+ }
+
+ private static final class ElementsIterator implements Iterator {
+ private final NodeList nodes;
+ private final int length;
+ private final String name;
+ private int position;
+ private Element element;
+
+ public ElementsIterator(final Element parent, final String name) {
+ this.nodes = parent.getChildNodes();
+ this.length = nodes.getLength();
+ this.position = -1;
+ this.name = name;
+
+ advance();
+ }
+
+ private void advance() {
+ this.element = null;
+ this.position++;
+
+ for (; this.position < this.length && this.element == null; this.position++) {
+ final Node node = this.nodes.item(this.position);
+
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && (this.name == null || node.getNodeName().equals(
+ this.name))) {
+ this.element = (Element) node;
+ }
+ }
+ }
+
+ public boolean hasNext() {
+ return (this.element != null);
+ }
+
+ public Object next() {
+ final Element el = this.element;
+
+ if (el == null) {
+ throw new NoSuchElementException();
+ }
+
+ advance();
+
+ return el;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties 2012-08-25 06:14:56 UTC (rev 43233)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties 2012-08-25 09:35:49 UTC (rev 43234)
@@ -3,3 +3,5 @@
SAXValidator_UnableToInstantiateMessage=error: Unable to instantiate parser ({0})
XMLUtilities_IOExceptionMessage=Unexpected parser error
XMLUtilities_SAXExceptionMessage=Unexpected parser error
+AbstractClasspathContainer_error_loading_container=Error loading classpath container
+ClasspathDecorationsManager_unexpected_exception=Encountered an unexpected exception.
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/IMemento.java (from rev 43203, trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/IMemento.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/IMemento.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/IMemento.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2006
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.jboss.tools.common.xml;
+
+import java.util.List;
+
+/**
+ * Stolen from webtools wst.server.core,
+ * represents a savable memento to be
+ * translated into xml
+ *
+ */
+public interface IMemento {
+ /**
+ * Creates a new child of this memento with the given type.
+ * <p>
+ * The <code>getChild</code> and <code>getChildren</code> methods
+ * are used to retrieve children of a given type.
+ * </p>
+ *
+ * @param type the type
+ * @return a new child memento
+ * @see #getChild
+ * @see #getChildren
+ */
+ public IMemento createChild(String type);
+
+ /**
+ * Returns the first child with the given type id.
+ *
+ * @param type the type id
+ * @return the first child with the given type
+ */
+ public IMemento getChild(String type);
+
+ /**
+ * Returns all children with the given type id.
+ *
+ * @param type the type id
+ * @return the list of children with the given type
+ */
+ public IMemento[] getChildren(String type);
+
+ /**
+ * Returns the floating point value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was found
+ * but was not a floating point number
+ */
+ public Float getFloat(String key);
+
+ /**
+ * Returns the integer value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was found
+ * but was not an integer
+ */
+ public Integer getInteger(String key);
+
+ /**
+ * Returns the string value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was found
+ * but was not an integer
+ */
+ public String getString(String key);
+
+ /**
+ * Returns the boolean value of the given key.
+ *
+ * @param key the key
+ * @return the value, or <code>null</code> if the key was not found or was found
+ * but was not a boolean
+ */
+ public Boolean getBoolean(String key);
+
+ public List<String> getNames();
+
+ /**
+ * Sets the value of the given key to the given integer.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putInteger(String key, int value);
+
+ /**
+ * Sets the value of the given key to the given boolean value.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putBoolean(String key, boolean value);
+
+ /**
+ * Sets the value of the given key to the given string.
+ *
+ * @param key the key
+ * @param value the value
+ */
+ public void putString(String key, String value);
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLMemento.java (from rev 43203, trunk/jmx/plugins/org.jboss.tools.jmx.core/src/org/jboss/tools/jmx/core/util/XMLMemento.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLMemento.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLMemento.java 2012-08-25 09:35:49 UTC (rev 43234)
@@ -0,0 +1,430 @@
+/*******************************************************************************
+ * Copyright (c) 2006
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.jboss.tools.common.xml;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+
+/**
+ * Stolen from webtools wst.server.core
+ *
+ */
+public final class XMLMemento implements IMemento {
+ private Document factory;
+ private Element element;
+
+ /**
+ * Answer a memento for the document and element. For simplicity
+ * you should use createReadRoot and createWriteRoot to create the initial
+ * mementos on a document.
+ */
+ public XMLMemento(Document doc, Element el) {
+ factory = doc;
+ element = el;
+ }
+
+ /*
+ * @see IMemento
+ */
+ public IMemento createChild(String type) {
+ Element child = factory.createElement(type);
+ element.appendChild(child);
+ return new XMLMemento(factory, child);
+ }
+
+ public void removeChild(XMLMemento child) {
+ element.removeChild(child.element);
+ }
+
+ /**
+ * Create a Document from a Reader and answer a root memento for reading
+ * a document.
+ */
+ public static XMLMemento createReadRoot(InputStream in) {
+ Document document = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ document = parser.parse(new InputSource(in));
+ Node node = document.getFirstChild();
+ if (node instanceof Element)
+ return new XMLMemento(document, (Element) node);
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ try {
+ in.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Answer a root memento for writing a document.
+ *
+ * @param type a type
+ * @return a memento
+ */
+ public static XMLMemento createWriteRoot(String type) {
+ Document document;
+ try {
+ document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ Element element = document.createElement(type);
+ document.appendChild(element);
+ return new XMLMemento(document, element);
+ } catch (ParserConfigurationException e) {
+ throw new Error(e);
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public IMemento getChild(String type) {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return null;
+
+ // Find the first node which is a child of this node.
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (element2.getNodeName().equals(type))
+ return new XMLMemento(factory, element2);
+ }
+ }
+
+ // A child was not found.
+ return null;
+ }
+
+ /*
+ * @see IMemento
+ */
+ public IMemento [] getChildren(String type) {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return new IMemento[0];
+
+ // Extract each node with given type.
+ List<Element> list = new ArrayList<Element>(size);
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (element2.getNodeName().equals(type))
+ list.add(element2);
+ }
+ }
+
+ // Create a memento for each node.
+ size = list.size();
+ IMemento [] results = new IMemento[size];
+ for (int x = 0; x < size; x ++) {
+ results[x] = new XMLMemento(factory, list.get(x));
+ }
+ return results;
+ }
+
+ public String[] getChildNames() {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0)
+ return new String[0];
+
+ // Extract each node with given type.
+ List<String> list = new ArrayList<String>();
+ for (int nX = 0; nX < size; nX ++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Element) {
+ Element element2 = (Element)node;
+ if (!list.contains(element2.getNodeName()))
+ list.add(element2.getNodeName());
+ }
+ }
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Return the contents of this memento as a byte array.
+ *
+ * @return byte[]
+ * @throws IOException if anything goes wrong
+ */
+ public byte[] getContents() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return out.toByteArray();
+ }
+
+ /**
+ * Returns an input stream for writing to the disk with a local locale.
+ *
+ * @return java.io.InputStream
+ * @throws IOException if anything goes wrong
+ */
+ public InputStream getInputStream() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return new ByteArrayInputStream(out.toByteArray());
+ }
+
+ /*
+ * @see IMemento
+ */
+ public Float getFloat(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ try {
+ return new Float(strValue);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public Integer getInteger(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ try {
+ return new Integer(strValue);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public String getString(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ return attr.getValue();
+ }
+
+ public List<String> getNames() {
+ NamedNodeMap map = element.getAttributes();
+ int size = map.getLength();
+ List<String> list = new ArrayList<String>();
+ for (int i = 0; i < size; i++) {
+ Node node = map.item(i);
+ String name = node.getNodeName();
+ list.add(name);
+ }
+ return list;
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param in java.io.InputStream
+ * @return org.eclipse.ui.IMemento
+ */
+ public static IMemento loadMemento(InputStream in) {
+ return createReadRoot(in);
+ }
+
+ /**
+ * Loads a memento from the given filename.
+ *
+ * @param filename java.lang.String
+ * @return org.eclipse.ui.IMemento
+ * @exception java.io.IOException
+ */
+ public static IMemento loadMemento(String filename) throws IOException {
+ InputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(filename));
+ return XMLMemento.createReadRoot(in);
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ /*
+ * @see IMemento
+ */
+ public void putInteger(String key, int n) {
+ element.setAttribute(key, String.valueOf(n));
+ }
+
+ /*
+ * @see IMemento
+ */
+ public void putString(String key, String value) {
+ if (value == null)
+ return;
+ element.setAttribute(key, value);
+ }
+
+ /**
+ * Save this Memento to a Writer.
+ *
+ * @throws IOException if there is a problem saving
+ */
+ public void save(OutputStream os) throws IOException {
+ Result result = new StreamResult(os);
+ Source source = new DOMSource(factory);
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+ transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ transformer.transform(source, result);
+ } catch (Exception e) {
+ throw (IOException) (new IOException().initCause(e));
+ }
+ }
+
+ /**
+ * Saves the memento to the given file.
+ *
+ * @param filename java.lang.String
+ * @exception java.io.IOException
+ */
+ public void saveToFile(String filename) throws IOException {
+ BufferedOutputStream w = null;
+ try {
+ w = new BufferedOutputStream(new FileOutputStream(filename));
+ save(w);
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException(e.getLocalizedMessage());
+ } finally {
+ if (w != null) {
+ try {
+ w.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public String saveToString() throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ save(out);
+ return out.toString("UTF-8"); //$NON-NLS-1$
+ }
+
+ /*
+ * @see IMemento#getBoolean(String)
+ */
+ public Boolean getBoolean(String key) {
+ Attr attr = element.getAttributeNode(key);
+ if (attr == null)
+ return null;
+ String strValue = attr.getValue();
+ if ("true".equalsIgnoreCase(strValue)) //$NON-NLS-1$
+ return new Boolean(true);
+ return new Boolean(false);
+ }
+
+ /*
+ * @see IMemento#putBoolean(String, boolean)
+ */
+ public void putBoolean(String key, boolean value) {
+ element.setAttribute(key, new Boolean(value).toString());
+ }
+
+ /**
+ * Returns the Text node of the memento. Each memento is allowed only
+ * one Text node.
+ *
+ * @return the Text node of the memento, or <code>null</code> if
+ * the memento has no Text node.
+ */
+ public Text getTextNode() {
+ // Get the nodes.
+ NodeList nodes = element.getChildNodes();
+ int size = nodes.getLength();
+ if (size == 0) {
+ return null;
+ }
+ for (int nX = 0; nX < size; nX++) {
+ Node node = nodes.item(nX);
+ if (node instanceof Text) {
+ return (Text) node;
+ }
+ }
+ // a Text node was not found
+ return null;
+ }
+
+ /* (non-Javadoc)
+ */
+ public void putTextData(String data) {
+ Text textNode = getTextNode();
+ if (textNode == null) {
+ textNode = factory.createTextNode(data);
+ // Always add the text node as the first child (fixes bug 93718)
+ element.insertBefore(textNode, element.getFirstChild());
+ } else {
+ textNode.setData(data);
+ }
+ }
+
+ public String getTextData() {
+ Text textNode = getTextNode();
+ if (textNode != null) {
+ return textNode.getData();
+ }
+ return ""; //$NON-NLS-1$
+ }
+}
\ No newline at end of file
12 years, 4 months
JBoss Tools SVN: r43233 - trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2012-08-25 02:14:56 -0400 (Sat, 25 Aug 2012)
New Revision: 43233
Added:
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties
Log:
JBIDE-12469 split of o.j.t.common and creation of o.j.t.common.core (missed messages files)
Added: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/Messages.java 2012-08-25 06:14:56 UTC (rev 43233)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2009 - 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.core;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.jboss.tools.common.core.messages"; //$NON-NLS-1$
+ public static String SAXValidator_IOExceptionMessage;
+ public static String SAXValidator_SAXExceptionMessage;
+ public static String SAXValidator_UnableToInstantiateMessage;
+ public static String XMLUtilities_IOExceptionMessage;
+ public static String XMLUtilities_SAXExceptionMessage;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Added: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/messages.properties 2012-08-25 06:14:56 UTC (rev 43233)
@@ -0,0 +1,5 @@
+SAXValidator_IOExceptionMessage=Unidentified parser error
+SAXValidator_SAXExceptionMessage=Unidentified parser error
+SAXValidator_UnableToInstantiateMessage=error: Unable to instantiate parser ({0})
+XMLUtilities_IOExceptionMessage=Unexpected parser error
+XMLUtilities_SAXExceptionMessage=Unexpected parser error
12 years, 4 months
JBoss Tools SVN: r43232 - in trunk/common: plugins and 20 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2012-08-25 02:08:31 -0400 (Sat, 25 Aug 2012)
New Revision: 43232
Added:
trunk/common/plugins/org.jboss.tools.common.core/
trunk/common/plugins/org.jboss.tools.common.core/.classpath
trunk/common/plugins/org.jboss.tools.common.core/.project
trunk/common/plugins/org.jboss.tools.common.core/META-INF/
trunk/common/plugins/org.jboss.tools.common.core/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.core/about.html
trunk/common/plugins/org.jboss.tools.common.core/build.properties
trunk/common/plugins/org.jboss.tools.common.core/plugin.properties
trunk/common/plugins/org.jboss.tools.common.core/plugin.xml
trunk/common/plugins/org.jboss.tools.common.core/pom.xml
trunk/common/plugins/org.jboss.tools.common.core/src/
trunk/common/plugins/org.jboss.tools.common.core/src/org/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/CommonCorePlugin.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/databinding/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/jobs/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/BasePlugin.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/ILoggingAdapter.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/IPluginLog.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/LogHelper.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/PluginLogger.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/StatusFactory.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/preferences/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/text/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/BeanUtil.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/FileUtils.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/HttpUtil.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/web/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/zip/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
Removed:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/databinding/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/jobs/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/BasePlugin.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/ILoggingAdapter.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/IPluginLog.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/LogHelper.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/PluginLogger.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/StatusFactory.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/preferences/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseJavaUtil.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/HttpUtil.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/web/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/zip/
Modified:
trunk/common/features/org.jboss.tools.common.core.feature/feature.xml
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/ParametedType.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/ParametedTypeFactory.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/preferences/SeverityPreferences.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/ProblemBuffer.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/Submit.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/web/WebUtils.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/DtdResolver.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/SAXValidator.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLEntityResolver.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLEntityResolverImpl.java
trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLUtilities.java
trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/Messages.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/messages.properties
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java
trunk/common/plugins/pom.xml
Log:
JBIDE-12469 split of o.j.t.common and creation of o.j.t.common.core
Modified: trunk/common/features/org.jboss.tools.common.core.feature/feature.xml
===================================================================
--- trunk/common/features/org.jboss.tools.common.core.feature/feature.xml 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/features/org.jboss.tools.common.core.feature/feature.xml 2012-08-25 06:08:31 UTC (rev 43232)
@@ -16,6 +16,12 @@
<license>
%license
</license>
+ <plugin
+ id="org.jboss.tools.common.core"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
<plugin
id="org.jboss.tools.common"
Modified: trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/META-INF/MANIFEST.MF 2012-08-25 06:08:31 UTC (rev 43232)
@@ -6,20 +6,10 @@
Bundle-SymbolicName: org.jboss.tools.common;singleton:=true
Bundle-Localization: plugin
Export-Package: org.jboss.tools.common,
- org.jboss.tools.common.databinding,
- org.jboss.tools.common.java,
- org.jboss.tools.common.java.impl,
- org.jboss.tools.common.jobs,
org.jboss.tools.common.log,
- org.jboss.tools.common.preferences,
org.jboss.tools.common.quickfix,
org.jboss.tools.common.refactoring,
- org.jboss.tools.common.reporting,
- org.jboss.tools.common.text,
- org.jboss.tools.common.util,
- org.jboss.tools.common.web,
- org.jboss.tools.common.xml,
- org.jboss.tools.common.zip
+ org.jboss.tools.common.util
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.wst.xml.core;bundle-version="1.1.600";visibility:=reexport,
org.eclipse.wst.common.modulecore;bundle-version="1.2.100",
@@ -43,7 +33,8 @@
org.eclipse.jpt.common.core;bundle-version="1.0.0",
org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
org.eclipse.wst.sse.ui;bundle-version="1.3.100",
- org.eclipse.jdt.core.manipulation;bundle-version="1.5.0"
+ org.eclipse.jdt.core.manipulation;bundle-version="1.5.0",
+ org.jboss.tools.common.core;bundle-version="3.4.0";visibility:=reexport
Bundle-Version: 3.4.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/Messages.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/Messages.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/Messages.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -16,11 +16,6 @@
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.jboss.tools.common.messages"; //$NON-NLS-1$
public static String BaseUIPlugin_ErrorDialogTitle;
- public static String SAXValidator_IOExceptionMessage;
- public static String SAXValidator_SAXExceptionMessage;
- public static String SAXValidator_UnableToInstantiateMessage;
- public static String XMLUtilities_IOExceptionMessage;
- public static String XMLUtilities_SAXExceptionMessage;
public static String MethodNotImplementedException_MethodIsNotImplementedYet;
static {
// initialize resource bundle
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/BasePlugin.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/BasePlugin.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/BasePlugin.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.log;
-
-import org.eclipse.core.runtime.Plugin;
-
-/**
- * Provides an easy way to log status of events.
- *
- * NOTE: It is useful to make the static method getPluginLog()
- * which provides the interface IPluginLog for using it in your code
- * in future
- *
- * @author Sergey Vasilyev
- *
- */
-
-public class BasePlugin extends Plugin implements IPluginLog {
- public void logError(String message, Throwable t) {
- LogHelper.logError(this, message, t);
- }
-
- public void logError(String message) {
- LogHelper.logError(this, message);
- }
-
- public void logError(Throwable t) {
- LogHelper.logError(this, t);
- }
-
- public void logWarning(String message, Throwable t) {
- LogHelper.logWarning(this, message, t);
- }
-
- public void logWarning(String message) {
- LogHelper.logWarning(this, message);
- }
-
- public void logWarning(Throwable t) {
- LogHelper.logWarning(this, t);
- }
-
- public void logInfo(String message, Throwable t) {
- LogHelper.logInfo(this, message, t);
- }
-
- public void logInfo(String message) {
- LogHelper.logInfo(this, message);
- }
-}
\ No newline at end of file
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/ILoggingAdapter.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/ILoggingAdapter.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/ILoggingAdapter.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.log;
-
-/**
- * @author Andre Dietisheim
- */
-public interface ILoggingAdapter {
-
- public void error(String errorMessage);
-
- public void debug(String message);
-
-}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/IPluginLog.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/IPluginLog.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/IPluginLog.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.log;
-
-public interface IPluginLog {
- public void logError(String message, Throwable t);
- public void logError(String message);
- public void logError(Throwable t);
-
- public void logWarning(String message, Throwable t);
- public void logWarning(String message);
- public void logWarning(Throwable t);
-
- public void logInfo(String message, Throwable t);
- public void logInfo(String message);
-}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/LogHelper.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/LogHelper.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/LogHelper.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.log;
-
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
-import org.osgi.framework.Bundle;
-
-public class LogHelper {
- public static void logError(Plugin plugin, Throwable t) {
- logError(plugin, null, t);
- }
-
- public static void logError(Plugin plugin, String message) {
- logError(plugin, message, null);
- }
-
- public static void logError(Plugin plugin, String message, Throwable t) {
- IStatus status = StatusFactory.getInstance(IStatus.ERROR,
- plugin.getBundle().getSymbolicName(), message, t);
- logStatus(plugin, status);
- }
-
- public static void logError(String pluginId, Throwable t) {
- logError(pluginId, null, t);
- }
-
- public static void logError(String pluginId, String message) {
- logError(pluginId, message, null);
- }
-
- public static void logError(String pluginId, String message, Throwable t) {
- IStatus status = StatusFactory.getInstance(IStatus.ERROR, pluginId,
- message, t);
- logStatus(pluginId, status);
- }
-
- public static void logWarning(Plugin plugin, Throwable t) {
- logWarning(plugin, null, t);
- }
-
- public static void logWarning(Plugin plugin, String message) {
- logWarning(plugin, message, null);
- }
-
-
- public static void logWarning(Plugin plugin, String message, Throwable t) {
- IStatus status = StatusFactory.getInstance(IStatus.WARNING,
- plugin.getBundle().getSymbolicName(), message, t);
- logStatus(plugin, status);
- }
-
- public static void logWarning(String pluginId, Throwable t) {
- logWarning(pluginId, null, t);
- }
-
- public static void logWarning(String pluginId, String message) {
- logWarning(pluginId, message, null);
- }
-
-
- public static void logWarning(String pluginId, String message,
- Throwable t) {
- IStatus status = StatusFactory.getInstance(IStatus.WARNING, pluginId,
- message, t);
- logStatus(pluginId, status);
- }
-
- public static void logInfo(Plugin plugin, String message,
- Throwable t) {
- IStatus status = StatusFactory.getInstance(IStatus.INFO,
- plugin.getBundle().getSymbolicName(), message, t);
- logStatus(plugin, status);
- }
-
-
- public static void logInfo(Plugin plugin, String message) {
- IStatus status = StatusFactory.getInstance(IStatus.INFO,
- plugin.getBundle().getSymbolicName(), message);
- logStatus(plugin, status);
- }
-
- public static void logInfo(String pluginId, String message,
- Throwable t) {
- IStatus status = StatusFactory.getInstance(IStatus.INFO, pluginId,
- message, t);
- logStatus(pluginId, status);
- }
-
- public static void logInfo(String pluginId, String message) {
- IStatus status = StatusFactory.getInstance(IStatus.INFO, pluginId,
- message);
- logStatus(pluginId, status);
- }
-
- public static void log(int severity, String pluginId, int code,
- String message, Throwable t) {
- IStatus status = StatusFactory.getInstance(severity, pluginId, code,
- message, t);
- logStatus(pluginId, status);
- }
-
- public static void logStatus(Plugin plugin, IStatus status) {
- plugin.getLog().log(status);
- }
-
- public static void logStatus(String pluginId, IStatus status) {
- Bundle bundle = Platform.getBundle(pluginId);
- logStatus(bundle, status);
- }
-
- public static void logStatus(Bundle bundle, IStatus status) {
- ILog log = Platform.getLog(bundle);
- log.log(status);
- }
-}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/PluginLogger.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/PluginLogger.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/PluginLogger.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.log;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.core.runtime.Status;
-
-/**
- * A logging adapter that logs to a given plugin.
- *
- * @author Andre Dietisheim
- */
-public class PluginLogger implements ILoggingAdapter {
-
- private Plugin plugin;
-
- public PluginLogger(Plugin plugin) {
- this.plugin = plugin;
- }
-
- public void error(String message) {
- log(IStatus.ERROR, message);
- }
-
- public void debug(String message) {
- log(IStatus.INFO, message);
- }
-
- private void log(int severity, String message) {
- if (!isTracingEnabled()) {
- return;
- }
-
- if (plugin != null) {
- IStatus status = new Status(severity, plugin.getBundle().getSymbolicName(), message);
- plugin.getLog().log(status);
- }
- }
-
- protected Plugin getPlugin() {
- return plugin;
- }
-
- protected boolean isTracingEnabled() {
- // defaults to always log
- return true;
- }
-}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/StatusFactory.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/StatusFactory.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/StatusFactory.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.log;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
-
-public class StatusFactory {
- public final static int UNDEFINED_ERROR = 0;
- public final static String UNSPECIFIED_MESSAGE = null;
- public final static String EMPTY_MESSAGE = ""; //$NON-NLS-1$
-
- public static IStatus getInstance(int severity, String pluginId,
- int code, String message, Throwable t) {
- return new Status(severity, pluginId, code, checkMessage(message, t), t);
- }
-
- public static IStatus getInstance(int severity, String pluginId,
- String message, Throwable t) {
- return getInstance(severity, pluginId, UNDEFINED_ERROR, message, t);
- }
-
- public static IStatus getInstance(int severity, String pluginId,
- String message) {
- return getInstance(severity, pluginId, UNDEFINED_ERROR, message, null);
- }
-
- public static IStatus getInstance(int severity, String pluginId,
- Throwable t) {
- return getInstance(severity, pluginId, UNDEFINED_ERROR, EMPTY_MESSAGE, t);
- }
-
- public static IStatus getInstance(int severity, String pluginId,
- int code, Throwable t) {
- return getInstance(severity, pluginId, code, EMPTY_MESSAGE, t);
- }
-
- public static IStatus getInstance(int severity, String pluginId,
- int code, String message) {
- return getInstance(severity, pluginId, code, message, null);
- }
-
- /**
- * Returns a multi status with the given severity, plugin id, error code,
- * message, cause and child status instances.
- *
- * @param severity
- * @param pluginId
- * @param message
- * @param t
- * @param status
- * @return a multi status
- */
- public static IStatus getInstance(int severity, String pluginId, String message, Throwable t, IStatus... status) {
- return new MultiStatus(pluginId, UNDEFINED_ERROR, status, message, t);
- }
-
- private static String checkMessage(String message, Throwable t) {
- if (message == UNSPECIFIED_MESSAGE) {
- if (t != null && t.getMessage() != null) {
- return t.getMessage();
- }
- return EMPTY_MESSAGE;
- }
- return message;
- }
-}
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/messages.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/messages.properties 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/messages.properties 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,7 +1,2 @@
BaseUIPlugin_ErrorDialogTitle=Hibernate Console
-SAXValidator_IOExceptionMessage=Unidentified parser error
-SAXValidator_SAXExceptionMessage=Unidentified parser error
-SAXValidator_UnableToInstantiateMessage=error: Unable to instantiate parser ({0})
-XMLUtilities_IOExceptionMessage=Unexpected parser error
-XMLUtilities_SAXExceptionMessage=Unexpected parser error
MethodNotImplementedException_MethodIsNotImplementedYet=Method is not implemented yet
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.util;
-
-import org.eclipse.jdt.core.IMethod;
-
-/**
- *
- * @author V. Kabanovich
- *
- */
-public class BeanUtil {
- public static final String GET = "get"; //$NON-NLS-1$
- public static final String SET = "set"; //$NON-NLS-1$
- public static final String IS = "is"; //$NON-NLS-1$
-
- public static boolean isGetter(String methodName, int numberOfParameters) {
- return (((methodName.startsWith(GET) && !methodName.equals(GET))
- || (methodName.startsWith(IS) && !methodName.equals(IS)))
- && numberOfParameters == 0);
- }
-
- public static boolean isSetter(String methodName, int numberOfParameters) {
- return (((methodName.startsWith(SET) && !methodName.equals(SET)))
- && numberOfParameters == 1);
- }
-
- public static boolean isGetter(IMethod method) {
- return method != null && isGetter(method.getElementName(), method.getNumberOfParameters())
- && checkPropertyReturnType(method);
- }
-
-
- public static boolean checkPropertyReturnType(String typeName, String methodName) {
- if(typeName == null || typeName.equals("void")) { //$NON-NLS-1$
- return false;
- }
- if(methodName.startsWith(BeanUtil.IS)) {
- if(!"boolean".equals(typeName) && !"java.lang.Boolean".equals(typeName)) { //$NON-NLS-1$ //$NON-NLS-2$
- return false;
- }
- }
- return true;
- }
-
- private static boolean checkPropertyReturnType(IMethod method) {
- return method != null && checkPropertyReturnType(EclipseJavaUtil.getMemberTypeAsString(method), method.getElementName());
- }
-
- public static boolean isSetter(IMethod method) {
- return method != null && isSetter(method.getElementName(), method.getNumberOfParameters());
- }
-
- public static String getPropertyName(String methodName) {
- if(isGetter(methodName, 0) || isSetter(methodName, 1)) {
- StringBuffer name = new StringBuffer(methodName);
- if(methodName.startsWith(IS)) {
- name.delete(0, 2);
- } else {
- name.delete(0, 3);
- }
- if(name.length() < 2 || !Character.isUpperCase(name.charAt(1))) {
- name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
- }
- return name.toString();
- }
- return null;
- }
-
-}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseJavaUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseJavaUtil.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseJavaUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,247 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.util;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.IAnnotatable;
-import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeHierarchy;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.Signature;
-import org.jboss.tools.common.CommonPlugin;
-
-public class EclipseJavaUtil {
-
- public static String getMemberTypeAsString(IMember member) {
- if(member instanceof IField) return getMemberTypeAsString((IField)member);
- if(member instanceof IMethod) return getMemberTypeAsString((IMethod)member);
- return null;
- }
-
- public static String getMemberTypeAsString(IField f) {
- if(f == null) return null;
- try {
- String typeName = new String(Signature.toCharArray(f.getTypeSignature().toCharArray()));
- return resolveType(f.getDeclaringType(), typeName);
- } catch (JavaModelException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- return null;
- }
-
- public static String getMemberTypeAsString(IMethod m) {
- if(m == null) return null;
- try {
- return resolveTypeAsString(m.getDeclaringType(), m.getReturnType());
- } catch (JavaModelException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- return null;
- }
-
- public static String resolveTypeAsString(IType type, String typeName) {
- if(type == null || typeName == null) return null;
- typeName = new String(Signature.toCharArray(typeName.toCharArray()));
- int i = typeName.indexOf(Signature.C_GENERIC_START);
- if(i > 0) typeName = typeName.substring(0, i);
- return resolveType(type, typeName);
- }
-
- public static String resolveType(IType type, String typeName) {
- return TypeResolutionCache.getInstance().resolveType(type, typeName);
- }
-
- public static IType findType(IJavaProject javaProject, String qualifiedName) throws JavaModelException {
- if(qualifiedName == null || qualifiedName.length() == 0) return null;
- IType type = javaProject.findType(qualifiedName);
- if(type != null) return type;
- int dot = qualifiedName.lastIndexOf('.');
- String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot); //$NON-NLS-1$
- String shortName = qualifiedName.substring(dot + 1);
- IPackageFragmentRoot[] rs = javaProject.getPackageFragmentRoots();
- for (int i = 0; i < rs.length; i++) {
- IPackageFragment f = rs[i].getPackageFragment(packageName);
- if(f == null || !f.exists()) continue;
- ICompilationUnit[] us = f.getCompilationUnits();
- for (int j = 0; j < us.length; j++) {
- IType t = us[j].getType(shortName);
- if(t != null && t.exists()) return t;
- }
- }
- return null;
- }
-
- public static List<IType> getSupperTypes(IType type) throws JavaModelException {
- ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
- IType[] superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
- if(superTypes == null) {
- return Collections.emptyList();
- }
- List<IType> suppers = new ArrayList<IType>();
- for (int i = 0; i < superTypes.length; i++) {
- suppers.add(superTypes[i]);
- }
- return suppers;
- }
-
- public static IAnnotation findAnnotation(IType sourceType, IAnnotatable member, String qulifiedAnnotationName) throws JavaModelException{
- IAnnotation[] annotations = member.getAnnotations();
- String simpleAnnotationTypeName = qulifiedAnnotationName;
- int lastDot = qulifiedAnnotationName.lastIndexOf('.');
- if(lastDot>-1) {
- simpleAnnotationTypeName = simpleAnnotationTypeName.substring(lastDot + 1);
- }
- for (IAnnotation annotation : annotations) {
- if(qulifiedAnnotationName.equals(annotation.getElementName())) {
- return annotation;
- }
- if(simpleAnnotationTypeName.equals(annotation.getElementName())) {
- String fullAnnotationclassName = EclipseJavaUtil.resolveType(sourceType, simpleAnnotationTypeName);
- if(fullAnnotationclassName!=null) {
- IType annotationType = sourceType.getJavaProject().findType(fullAnnotationclassName);
- if(annotationType!=null && annotationType.getFullyQualifiedName().equals(qulifiedAnnotationName)) {
- return annotation;
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Finds field declared in the given type or its super types.
- *
- * @param type
- * @param name
- * @return
- * @throws CoreException
- */
- public static IField findField(IType type, String name) throws CoreException {
- return findField(type, name, new HashSet<IType>());
- }
- private static IField findField(IType type, String name, Set<IType> processed) throws CoreException {
- if(!type.exists() || processed.contains(type)) {
- return null;
- }
- processed.add(type);
- if(type.getField(name).exists()) {
- return type.getField(name);
- }
- IField f = findField(type, type.getSuperclassName(), name, processed);
- String[] is = type.getSuperInterfaceNames();
- for (int i = 0; f == null && i < is.length; i++) {
- f = findField(type, is[i], name, processed);
- }
- if(f == null) {
- IType d = type.getDeclaringType();
- if(d != null && d != type && d.exists()) {
- f = findField(d, name);
- }
- }
-
- return f;
- }
- private static IField findField(IType context, String typeName, String fieldName, Set<IType> processed) throws CoreException {
- typeName = resolveType(context, typeName);
- if(typeName != null) {
- IType s = findType(context.getJavaProject(), typeName);
- return (s != null) ? findField(s, fieldName, processed) : null;
- }
- return null;
- }
-
- /**
- * Returns true if the given annotation has the given full name
- * @param annotation
- * @param fullName
- * @return
- * @throws JavaModelException
- */
- public static boolean checkAnnotationByFulltName(IAnnotation annotation, String fullName) throws JavaModelException {
- if(annotation.getElementName().equals(fullName)) {
- return true;
- }
- boolean result = true;
- IType sourceType = null;
- IJavaElement parent = annotation.getParent();
- if(parent instanceof IMember) {
- if(parent instanceof IType) {
- sourceType = (IType)parent;
- } else {
- sourceType = ((IMember)parent).getDeclaringType();
- }
- String fullAnnotationName = EclipseJavaUtil.resolveType(sourceType, annotation.getElementName());
- if(fullAnnotationName!=null) {
- IType annotationType = sourceType.getJavaProject().findType(fullAnnotationName);
- result = annotationType!=null && annotationType.getFullyQualifiedName().equals(fullName);
- } else {
- result = false;
- }
- }
- return result;
- }
-
- /**
- * Returns annotation by the short name declared for the given java member and its parents.
- * Returns null if no annotation found.
- * @param member
- * @param name
- * @param checkParents
- * @return
- * @throws JavaModelException
- */
- public static Set<IAnnotation> findAnnotationsByShortName(IJavaElement element, String name, boolean checkParents) throws JavaModelException {
- return findAnnotationsByShortName(null, element, name, checkParents);
- }
-
- private static Set<IAnnotation> findAnnotationsByShortName(Set<IAnnotation> result, IJavaElement element, String name, boolean checkParents) throws JavaModelException {
- if(element instanceof IAnnotatable) {
- IAnnotation[] annotations = ((IAnnotatable)element).getAnnotations();
- for (IAnnotation annotation : annotations) {
- String aName = annotation.getElementName();
- int i = aName.lastIndexOf('.');
- if(i>-1) {
- aName = aName.substring(i+1);
- }
- if(aName.equals(name)) {
- if(result==null) {
- result = new HashSet<IAnnotation>();
- }
- result.add(annotation);
- break;
- }
- }
- }
- if(checkParents) {
- IJavaElement parent = element.getParent();
- if(parent instanceof IAnnotatable) {
- return findAnnotationsByShortName(result, parent, name, true);
- }
- }
- return result;
- }
-}
\ No newline at end of file
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -10,42 +10,12 @@
******************************************************************************/
package org.jboss.tools.common.util;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.IFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
@@ -53,686 +23,10 @@
import org.eclipse.ui.texteditor.ITextEditor;
import org.jboss.tools.common.CommonPlugin;
-public final class FileUtil {
+public final class FileUtil extends FileUtils {
public FileUtil() {}
- public static String getEncoding(IFile f) {
- String encoding = null;
- if(f != null && f.exists() && f.isSynchronized(0)) try {
- encoding = f.getCharset();
- } catch (CoreException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- return encoding != null ? encoding : "8859_1"; //$NON-NLS-1$
- }
-
- public static String readFile(File f) {
- if(!f.isFile()) return ""; //$NON-NLS-1$
- ReadBytes bs = readBytes(f);
- if(bs == null) return ""; //$NON-NLS-1$
- String encoding = getEncoding(bs.bs);
- if(encoding == null) return new String(bs.bs, 0, bs.length);
- try {
- return new String(bs.bs, 0, bs.length, encoding);
- } catch (UnsupportedEncodingException e) {
- return new String(bs.bs, 0, bs.length);
- }
- }
-
- public static String readFileWithEncodingCheck(File f, String defaultEncoding) {
- if(!f.isFile()) return ""; //$NON-NLS-1$
- ReadBytes bs = readBytes(f);
- if(bs == null) return ""; //$NON-NLS-1$
- String encoding = getEncoding(bs.bs);
- if(encoding == null) encoding = validateEncoding(defaultEncoding, null);
- if(encoding == null) return new String(bs.bs, 0, bs.length);
- try {
- return new String(bs.bs, 0, bs.length, encoding);
- } catch (UnsupportedEncodingException e) {
- return new String(bs.bs, 0, bs.length);
- }
- }
-
- public static ReadBytes readBytes(File f) {
- if(!f.isFile()) return null;
- BufferedInputStream br = null;
- try {
- FileInputStream fr = new FileInputStream(f);
- br = new BufferedInputStream(fr);
- int l = (int)f.length();
- byte[] bs = new byte[l];
- l = br.read(bs, 0, l);
- br.close();
- fr.close();
- return new ReadBytes(bs, l);
- } catch (IOException e) {
- return null;
- } finally {
- if(br!=null) {
- try {
- br.close();
- } catch (IOException e) {
- //ignore
- }
- }
- }
- }
-
- static class ReadBytes {
- byte[] bs;
- int length;
-
- ReadBytes(byte[] bs, int l) {
- this.bs = bs;
- length = l;
- }
- }
-
- public static String readFile(File f, String encoding) {
- ReadBytes bs = readBytes(f);
- if(bs == null) return null;
- try {
- return new String(bs.bs, 0, bs.length, encoding);
- } catch (UnsupportedEncodingException e) {
- return null;
- }
- }
-
- public static boolean isTextFile(File f, int length) {
- if(!f.isFile()) return false;
- BufferedReader br = null;
- try {
- FileReader fr = new FileReader(f);
- br = new BufferedReader(fr);
- int l = (int)f.length();
- if(l > length) l = length;
- char[] cs = new char[l];
- br.read(cs, 0, l);
- br.close();
- fr.close();
- return isText(new String(cs));
- } catch (IOException e) {
- return false;
- } finally {
- if(br!=null) {
- try {
- br.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
-
- public static boolean isText(String body) {
- if(body == null) return false;
- int l = body.length();
- for (int i = 0; i < l; i++) {
- char c = body.charAt(i);
- if(((int)c) < 32 && c != '\n' && c != '\r' && c != 't') return false;
- }
- return true;
- }
-
- // FIXME Size of string buffer should be set to size of file by default
- // to avoid StringBuffer extension on each append
- public static String readStream(InputStream is) {
- StringBuffer sb = new StringBuffer(""); //$NON-NLS-1$
- try {
- byte[] b = new byte[4096];
- while(true) {
- int l = is.read(b, 0, b.length);
- if(l < 0) break;
- sb.append(new String(b, 0, l));
- }
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- // Ignore
- }
- }
- return sb.toString();
- }
-
- public static String readStream(IFile file) throws CoreException {
- String content = null;
- InputStream in = null;
- try {
- String charset = file.getCharset();
- if(charset != null) {
- charset = validateEncoding(charset, null);
- }
- in = file.getContents();
- content = (charset == null) ? readStream(in) : readStream(in, charset);
- } finally {
- if(in!=null) {
- try {
- in.close();
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- }
- }
- return content;
- }
-
- public static String readStream(InputStream is, String charset) {
- StringBuffer sb = new StringBuffer(""); //$NON-NLS-1$
- try {
- byte[] b = new byte[4096];
- while(true) {
- int l = is.read(b, 0, b.length);
- if(l < 0) break;
- sb.append(new String(b, 0, l, charset));
- }
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- // Ignore
- }
- }
-
- return sb.toString();
- }
-
- public static void copyContent(IFile from, IFile to, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
- InputStream is = null;
- try {
- is = from.getContents();
- to.setContents(is, force, keepHistory, monitor);
- } finally {
- if(is!=null) {
- try {
- is.close();
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- }
- }
- }
-
- public static boolean writeFile(File f, String value) {
- return writeFileWithEncodingCheck(f, value, null);
- }
-
- public static boolean writeFileWithEncodingCheck(File f, String value, String defaultEncoding) {
- if(value == null) return false;
- String encoding = getEncoding(value);
- if(encoding == null) encoding = validateEncoding(defaultEncoding, null);
- if(value.startsWith("<?xml")) { //$NON-NLS-1$
- String s = validateEncoding(encoding, "UTF-8"); //$NON-NLS-1$
- if(encoding == null) {
- encoding = s;
- } else if(s == null || !s.equals(encoding)) {
- return false;
- }
- }
- if(encoding == null) return writeFileDefault(f, value);
- return writeFile(f, value, encoding);
- }
-
- public static boolean writeFileDefault(File f, String value) {
- try {
- try {
- if(f.isFile() && !isSameFile(f)) f.delete();
- if(!f.exists()) f.createNewFile();
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError("Problem writing to file " + f, e); //$NON-NLS-1$
- } catch (SecurityException e) {
- CommonPlugin.getPluginLog().logError("Problem writing to file " + f, e); //$NON-NLS-1$
- }
- PrintWriter pw = new PrintWriter(new FileWriter(f));
- pw.print(value);
- pw.flush();
- pw.close();
- return true;
- } catch (IOException e) {
- return false;
- }
- }
-
-
- public static boolean copyFile(File source, File dest, boolean mkdirs) {
- return copyFile(source, dest, mkdirs, true);
- }
-
- public static boolean copyFile(File source, File dest) {
- return copyFile(source, dest, false, true);
- }
-
- public static boolean copyFile(File source, File dest, boolean mkdirs, boolean overwrite) {
- if (mkdirs) dest.getParentFile().mkdirs();
- if(!source.isFile()) return false;
- if(dest.isFile() && !isSameFile(dest)) dest.delete();
- if(dest.isFile() && !overwrite) return false;
- if(!dest.exists())
- try {
- dest.createNewFile();
- } catch (IOException e1) {
- CommonPlugin.getPluginLog().logError(e1);
- }
- InputStream is = null;
- OutputStream os = null;
- try {
- is = new BufferedInputStream(new FileInputStream(source), 16 * 1024);
- os = new BufferedOutputStream(new FileOutputStream(dest), 16 * 1024);
- copyStream(is, os);
- return true;
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- return false;
- } finally {
- try {
- if (is != null) is.close();
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- try {
- if (os != null) os.close();
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- }
- }
-
- public static boolean updateFile(File source, File dest, boolean mkdirs) {
- if(!source.isFile()) return false;
- if(dest.isFile() && (dest.lastModified()<source.lastModified())) {
- dest.delete();
- }
- return copyFile(source, dest, mkdirs);
- }
-
- public static void copyStream(InputStream is, OutputStream os) throws IOException {
- byte[] buffer = new byte[1<<14];
- while (true) {
- int r = is.read(buffer);
- if (r > 0) {
- os.write(buffer, 0, r);
- } else if (r == -1) break;
- }
- os.flush();
- }
-
- public static void clear(File f) {
- if (f.isDirectory()) {
- File[] fs = f.listFiles();
- for (int i = 0; i < fs.length; i++) {
- remove(fs[i]);
- }
- }
- }
-
- public static void remove(File f) {
- if (f.isFile()) {
- f.delete();
- } else if (f.isDirectory()) {
- File[] fs = f.listFiles();
- for (int i = 0; i < fs.length; i++) {
- remove(fs[i]);
- }
- f.delete();
- }
- }
-
- public static boolean isSameFile(File f) {
- if(!f.exists()) return false;
- String fn = f.getName();
- try {
- String cn = f.getCanonicalFile().getName();
- return fn.equals(cn);
- } catch (IOException e) {
- return false;
- }
- }
-
- public static void copyDir(File from, File to) {
- copyDir(from, to, false);
- }
-
- public static void copyDir(File from, File to, boolean mkdirs) {
- copyDir(from, to, mkdirs, true);
- }
-
- public static void copyDir(File from, File to, boolean mkdirs, boolean includeSubdirs) {
- copyDir(from, to, includeSubdirs, mkdirs, false);
- }
-
- public static void copyDir(File from, boolean includeSubdirs, File to) {
- copyDir(from, to, includeSubdirs, false, false);
- }
-
- public static void copyDir(File from, File to, boolean includeSubdirs, boolean mkdirs, boolean overwriteOnlyOlderFiles) {
- copyDir(from, to, includeSubdirs, mkdirs, overwriteOnlyOlderFiles, null);
- }
-
- public static void copyDir(File from, File to, boolean includeSubdirs, boolean mkdirs, boolean overwriteOnlyOlderFiles, FileFilter filter) {
- if(filter != null && !filter.accept(from)) return;
- if (mkdirs) to.mkdirs();
- if(from == null || !from.isDirectory() || !to.isDirectory()) return;
- File[] fs = from.listFiles();
- if(fs == null) return;
- for (int i = 0; i < fs.length; i++) {
- String n = fs[i].getName();
- File c = new File(to, n);
- if (fs[i].isDirectory() && !includeSubdirs) continue;
- if(filter != null && !filter.accept(new File(from, n))) continue;
-
- if(fs[i].isDirectory()) {
- c.mkdirs();
- copyDir(fs[i], c, includeSubdirs, mkdirs, overwriteOnlyOlderFiles, filter);
- } else if (overwriteOnlyOlderFiles && fs[i].isFile() && c.isFile()) {
- copyFile(fs[i], c, false, c.lastModified() < fs[i].lastModified());
- } else {
- copyFile(fs[i], c);
- }
- }
- }
-
- public static void unjar(File dest, String jar) throws IOException {
- dest.mkdirs();
- JarFile jf = new JarFile(jar);
- try {
- Enumeration es = jf.entries();
- while(es.hasMoreElements()) {
- JarEntry je = (JarEntry)es.nextElement();
- String n = je.getName();
- File f = new File(dest, n);
- if (je.isDirectory()) {
- f.mkdirs();
- } else {
- if (f.exists()) {
- f.delete();
- } else {
- f.getParentFile().mkdirs();
- }
- InputStream is = jf.getInputStream(je);
- FileOutputStream os = new FileOutputStream(f);
- try {
- copyStream(is, os);
- } finally {
- os.close();
- }
- }
- long time = je.getTime();
- if (time != -1) f.setLastModified(time);
- }
- } finally {
- jf.close();
- }
- }
-
- public static void unjar(File dest, InputStream is) throws IOException {
- dest.mkdirs();
- JarInputStream jis = new JarInputStream(is);
- try {
- while(true) {
- JarEntry je = jis.getNextJarEntry();
- if (je == null) break;
- String n = je.getName();
- File f = new File(dest, n);
- if (je.isDirectory()) {
- f.mkdirs();
- } else {
- if (f.exists()) {
- f.delete();
- } else {
- f.getParentFile().mkdirs();
- }
- FileOutputStream os = new FileOutputStream(f);
- try {
- copyStream(jis, os);
- } finally {
- os.close();
- }
- }
- long time = je.getTime();
- if (time != -1) f.setLastModified(time);
- }
- } finally {
- jis.close();
- }
- }
-
- public static void jar(File[] fs, String path) throws IOException {
- jar(fs, path, null);
- }
-
- public static void jar(File[] fs, String path, Manifest mf) throws IOException {
- File f = new File(path);
- FileOutputStream fos = new FileOutputStream(f);
- JarOutputStream jos = mf == null ? new JarOutputStream(fos) : new JarOutputStream(fos, mf);
- try {
- for (int i = 0; i < fs.length; i++) add(fs[i].getParentFile(), fs[i], jos);
- } finally {
- jos.close();
- fos.close();
- }
- }
-
- public static void add(File root, File f, JarOutputStream jos) throws IOException {
- int l = root.getAbsolutePath().length();
- String en = f.getAbsolutePath().substring(l + 1).replace('\\', '/');
- add(f, en, jos);
- }
-
- public static void add(File f, String name, JarOutputStream jos) throws IOException {
- String en = name;
- if(f.isDirectory()) en += "/"; //$NON-NLS-1$
- JarEntry entry = (en.endsWith("/")) ? null : new JarEntry(en); //$NON-NLS-1$
- if(f.isDirectory()) {
- if("/".equals(en)) en = ""; //$NON-NLS-1$ //$NON-NLS-2$
- File[] fs = f.listFiles();
- if(fs != null) for (int i = 0; i < fs.length; i++)
- add(fs[i], en + fs[i].getName(), jos);
- } else {
- try {
- jos.putNextEntry(entry);
- } catch (IOException e) {
- return;
- }
- FileInputStream is = new FileInputStream(f);
- byte[] b = new byte[1024];
- int q = 0;
- while((q = is.available()) > 0) {
- if(q > 1024) q = 1024;
- q = is.read(b, 0, q);
- jos.write(b, 0, q);
- }
- is.close();
- }
- if(entry != null) jos.closeEntry();
- }
-
- public static void copy(InputStream f, OutputStream t) throws IOException {
- try {
- byte[] b = new byte[1024];
- int q = 0;
- while((q = f.read(b, 0, b.length)) > 0) t.write(b, 0, q);
- } finally {
- f.close();
- t.close();
- }
- }
-
- public static void unzip(File dest, String jar) throws IOException {
- dest.mkdirs();
- ZipFile zf = new ZipFile(jar);
- try {
- Enumeration es = zf.entries();
- while(es.hasMoreElements()) {
- ZipEntry je = (ZipEntry)es.nextElement();
- String n = je.getName();
- File f = new File(dest, n);
- if (je.isDirectory()) {
- f.mkdirs();
- } else {
- if (f.exists()) {
- f.delete();
- } else {
- f.getParentFile().mkdirs();
- }
- InputStream is = zf.getInputStream(je);
- FileOutputStream os = new FileOutputStream(f);
- try {
- copyStream(is, os);
- } finally {
- os.close();
- }
- }
- long time = je.getTime();
- if (time != -1) f.setLastModified(time);
- }
- } finally {
- zf.close();
- }
- }
-
- public static String fileURLToFilePath(String url) {
- if(url == null) return null;
- String resultUrl = url.replace('\\', '/');
-/// if(!url.startsWith("file:/")) return url;
- if(!resultUrl.startsWith("file:")) return resultUrl; //$NON-NLS-1$
- int iLast = resultUrl.lastIndexOf(':'), iFirst = resultUrl.indexOf(':');
- return (iLast == iFirst) ? resultUrl.substring(5) : resultUrl.substring(iLast - 1);
- }
-
- //// Relative path
-
- public static String getRelativePath(String rootpath, String path) {
- String[] r = tokenizePath(rootpath);
- String[] p = tokenizePath(path);
- if(r.length == 0 || p.length == 0 || !r[0].equalsIgnoreCase(p[0])) return null;
- int i = 0;
- while(i < r.length && i < p.length && r[i].equalsIgnoreCase(p[i])) ++i;
- StringBuffer sb = new StringBuffer();
- for (int k = i; k < r.length; k++) sb.append("/.."); //$NON-NLS-1$
- for (int k = i; k < p.length; k++) sb.append("/").append(p[k]); //$NON-NLS-1$
- return sb.toString();
- }
-
- private static String[] tokenizePath(String path) {
- String tokenizedPath = path.replace('\\', '/');
- StringTokenizer st = new StringTokenizer(tokenizedPath, "/"); //$NON-NLS-1$
- ArrayList l = new ArrayList();
- while(st.hasMoreTokens()) {
- String t = st.nextToken();
- if(t.isEmpty() || ".".equals(t)) continue; //$NON-NLS-1$
- if("..".equals(t)) { //$NON-NLS-1$
- if(!l.isEmpty()) l.remove(l.size() - 1);
- continue;
- }
- l.add(t);
- }
- return (String[])l.toArray(new String[l.size()]);
- }
-
- public static boolean writeFile(File f, String value, String encoding) {
- try {
- try {
- if(f.isFile() && !isSameFile(f)) f.delete();
- if(!f.exists()) {
- f.getParentFile().mkdirs();
- f.createNewFile();
- }
- } catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- FileOutputStream fs = new FileOutputStream(f);
- OutputStreamWriter osw = new OutputStreamWriter(fs, encoding);
- PrintWriter pw = new PrintWriter(osw);
- pw.print(value);
- pw.flush();
- pw.close();
- return true;
- } catch (FileNotFoundException e) {
- //ignore
- return writeFileDefault(f, value);
- } catch (UnsupportedEncodingException e) {
- //ignore
- return writeFileDefault(f, value);
- }
- }
-
-
- public static String getEncoding(String s) {
- if(s == null) return null;
- if(s.startsWith("<?xml")) { //$NON-NLS-1$
- int i = s.indexOf("encoding="); //$NON-NLS-1$
- if(i < 0) return null;
- i += "encoding=".length() + 1; //$NON-NLS-1$
- int j = s.indexOf('\"', i);
- if(j < 0) return null;
- return s.substring(i, j);
- }
- return null;
- }
-
- static Set validEncodings = new HashSet();
- static Set invalidEncodings = new HashSet();
-
- public static String validateEncoding(String encoding, String defaultEncoding) {
- if(encoding == null || encoding.equals(defaultEncoding)) return defaultEncoding;
- if(validEncodings.contains(encoding)) return encoding;
- if(invalidEncodings.contains(encoding)) return defaultEncoding;
- try {
- if(defaultEncoding != null && defaultEncoding.equals("UTF-16")) { //$NON-NLS-1$
- new String(XML_16, 0, XML_16.length, encoding);
- } else {
- new String(XML_8, 0, XML_8.length, encoding);
- }
- validEncodings.add(encoding);
- return encoding;
- } catch (UnsupportedEncodingException e) {
- invalidEncodings.add(encoding);
- return defaultEncoding;
- }
- }
-
- static byte[] XML_8 = {(byte)'<',(byte)'?',(byte)'x',(byte)'m',(byte)'l'};
- static byte[] XML_16 = {(byte)-2,(byte)-1,(byte)0,(byte)60,(byte)0,(byte)63,(byte)0,(byte)120,(byte)0,(byte)109,(byte)0,(byte)108};
-
- public static String getEncoding(byte[] bs) {
- if(bs.length < 20) return null;
- if(startsWith(bs, XML_8)) {
- int i = getIndex(bs, (byte)'?', 5);
- if(i < 0) return "UTF-8"; //$NON-NLS-1$
- String encoding = getEncoding(new String(bs, 0, i));
- return validateEncoding(encoding, "UTF-8"); //$NON-NLS-1$
- } else if(startsWith(bs, XML_16)) {
- int i = getIndex(bs, (byte)'?', XML_16.length);
- if(i < 0) return "UTF-16"; //$NON-NLS-1$
- try {
- String encoding = getEncoding(new String(bs, 0, i, "UTF-16")); //$NON-NLS-1$
- return validateEncoding(encoding, "UTF-16"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e) {
- return null;
- }
- }
- return null;
- }
-
- static boolean startsWith(byte[] bs, byte[] prefix) {
- for (int i = 0; i < prefix.length; i++) {
- if(bs[i] != prefix[i]) return false;
- }
- return true;
- }
-
- static int getIndex(byte[] bs, byte b, int offset) {
- for (int i = offset; i < bs.length; i++) {
- if(bs[i] == b) return i;
- }
- return -1;
- }
-
/**
* Returns the content of the file. If this file is open in an active editor
* then the content of the editor will be returned.
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/HttpUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/HttpUtil.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/HttpUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,202 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
-import org.jboss.tools.common.CommonPlugin;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-/**
- * HTTP Utilities
- * @author Alexey Kazakov
- */
-public class HttpUtil {
-
- private static IProxyService proxyService;
-
- /**
- * @param url
- * @return InputStream of responce to http GET request. Use proxy settings from preferences.
- * @throws Exception
- */
- public static InputStream getInputStreamFromUrlByGetMethod(String url) throws IOException {
- InputStream is = executeGetMethod(url).getResponseBodyAsStream();
- return is;
- }
-
- /**
- * @param url
- * @return InputStream of responce to http GET request. Use proxy settings from preferences.
- * @throws Exception
- */
- public static InputStream getInputStreamFromUrlByGetMethod(String url, IProxyService proxyService) throws IOException {
- InputStream is = executeGetMethod(url, proxyService).getResponseBodyAsStream();
- return is;
- }
-
- /**
- * @param url
- * @param proxyService
- * @return Status code of responce to http GET request. Use given proxy settings.
- * @throws Exception
- */
- public static int getStatusCodeFromUrlByGetMethod(String url, IProxyService proxyService) throws IOException {
- int code = executeGetMethod(url, proxyService).getStatusCode();
- return code;
- }
-
- /**
- * @param url
- * @return Status code of responce to http GET request. Use proxy settings from preferences.
- * @throws Exception
- */
- public static int getStatusCodeFromUrlByGetMethod(String url) throws IOException {
- int code = executeGetMethod(url).getStatusCode();
- return code;
- }
-
- /**
- * @param url
- * @return InputStream of responce to http POST request. Use proxy settings from preferences.
- * @throws Exception
- */
- public static InputStream getInputStreamFromUrlByPostMethod(String url) throws IOException {
- InputStream is = executePostMethod(url).getResponseBodyAsStream();
- return is;
- }
-
- /**
- * @param url
- * @param proxyService
- * @return Status code of responce to http POST request. Use given proxy settings.
- * @throws Exception
- */
- public static int getStatusCodeFromUrlByPostMethod(String url, IProxyService proxyService) throws IOException {
- int code = executePostMethod(url, proxyService).getStatusCode();
- return code;
- }
-
- /**
- * @param url
- * @return Status code of responce to http POST request. Use proxy settings from preferences.
- * @throws Exception
- */
- public static int getStatusCodeFromUrlByPostMethod(String url) throws IOException {
- int code = executePostMethod(url).getStatusCode();
- return code;
- }
-
- private static GetMethod executeGetMethod(String url) throws IOException {
- IProxyService proxyService = getProxyService();
- return executeGetMethod(url, proxyService);
- }
-
- private static PostMethod executePostMethod(String url) throws IOException {
- IProxyService proxyService = getProxyService();
- return executePostMethod(url, proxyService);
- }
-
- /**
- * @param url
- * @param proxyService
- * @return
- * @throws Exception
- */
- public static GetMethod executeGetMethod(String url, IProxyService proxyService) throws IOException {
- GetMethod httpGet = new GetMethod(url);
- HttpClient httpClient = createHttpClient(url, proxyService);
- httpClient.executeMethod(httpGet);
- return httpGet;
- }
-
- private static PostMethod executePostMethod(String url, IProxyService proxyService) throws IOException {
- PostMethod httpPost = new PostMethod(url);
- HttpClient httpClient = createHttpClient(url, proxyService);
- httpClient.executeMethod(httpPost);
- return httpPost;
- }
-
- /**
- * @param url
- * @return HttpClient with internet proxy settings;
- * @throws Exception
- */
- public static HttpClient createHttpClient(String url) throws IOException {
- return createHttpClient(url, getProxyService());
- }
-
- private static HttpClient createHttpClient(String url, IProxyService proxyService) throws IOException {
- HttpClient httpClient = new HttpClient();
-
- if(proxyService.isProxiesEnabled()) {
- IProxyData[] proxyData = proxyService.getProxyData();
- URL netUrl = new URL(url);
- String hostName = netUrl.getHost();
- String[] nonProxiedHosts = proxyService.getNonProxiedHosts();
- boolean nonProxiedHost = false;
- for (int i = 0; i < nonProxiedHosts.length; i++) {
- String nonProxiedHostName = nonProxiedHosts[i];
- if(nonProxiedHostName.equalsIgnoreCase(hostName)) {
- nonProxiedHost = true;
- break;
- }
- }
- if(!nonProxiedHost) {
- for (int i = 0; i < proxyData.length; i++) {
- IProxyData proxy = proxyData[i];
- if(IProxyData.HTTP_PROXY_TYPE.equals(proxy.getType())) {
- String proxyHostName = proxy.getHost();
- if(proxyHostName==null) {
- break;
- }
- int portNumber = proxy.getPort();
- if(portNumber==-1) {
- portNumber = 80;
- }
- httpClient.getHostConfiguration().setProxy(proxyHostName, portNumber);
- if(proxy.isRequiresAuthentication()) {
- String userName = proxy.getUserId();
- if(userName!=null) {
- String password = proxy.getPassword();
- httpClient.getState().setProxyCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(userName, password));
- }
- }
- break; // Use HTTP proxy only.
- }
- }
- }
- }
-
- httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
-
- return httpClient;
- }
-
- private static IProxyService getProxyService() {
- if(proxyService==null) {
- BundleContext bundleContext = CommonPlugin.getInstance().getBundle().getBundleContext();
- ServiceReference serviceReference = bundleContext.getServiceReference(IProxyService.class.getName());
- proxyService = (IProxyService)bundleContext.getService(serviceReference);
- }
- return proxyService;
- }
-}
\ No newline at end of file
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Arrays;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.ui.dialogs.IOverwriteQuery;
-import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
-import org.eclipse.ui.wizards.datatransfer.ImportOperation;
-import org.osgi.framework.Bundle;
-
-/**
- * @author eskimo
- *
- */
-public class ResourcesUtils {
-
- public static IProject importProject(Bundle bundle, String templLocation,
- IProgressMonitor monitor) throws IOException, CoreException,
- InvocationTargetException, InterruptedException {
-
- String tplPrjLcStr;
- tplPrjLcStr = FileLocator.resolve(bundle.getEntry(templLocation))
- .getFile();
-
- return importProject(tplPrjLcStr, monitor);
- }
-
- public static IProject importProject(String location,
- IProgressMonitor monitor) throws CoreException, IOException,
- InvocationTargetException, InterruptedException {
- IProject importedPrj = createEclipseProjectDromDescriptor(location,
- monitor);
- ImportOperation op = new ImportOperation(importedPrj.getFullPath(),
- new File(location), FileSystemStructureProvider.INSTANCE,
- new IOverwriteQuery() {
- public String queryOverwrite(String pathString) {
- return IOverwriteQuery.ALL;
- }
- }, Arrays.asList(new File(location).listFiles()));
-
- op.setCreateContainerStructure(false);
- op.run(monitor);
- return importedPrj;
- }
-
- public static IProject importExistingProject(IProject project, String location, String name) throws CoreException {
- return importExistingProject(project, location, name, new NullProgressMonitor(), true);
- }
-
- public static IProject importExistingProject(IProject project, String location, String name, IProgressMonitor monitor, boolean refreshWorkspace) throws CoreException {
- IPath path = new Path(location).append(".project"); //$NON-NLS-1$
- IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(path);
- description.setName(name);
- project.create(description, monitor);
- project.open(IResource.NONE, monitor);
- if(refreshWorkspace) {
- ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
- }
- return project;
- }
-
- public static IProject createEclipseProject(String projectName,
- IProgressMonitor monitor) throws CoreException {
-
- IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(projectName);
-
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- final IProjectDescription description = workspace
- .newProjectDescription(projectName);
- newProjectHandle.create(description, new NullProgressMonitor());
- newProjectHandle.open(monitor);
- return newProjectHandle;
- }
-
- public static IProject createEclipseProjectDromDescriptor(
- String templateLocation, IProgressMonitor monitor)
- throws CoreException, IOException {
-
- IPath tplPrjDescr = new Path(templateLocation)
- .append(IProjectDescription.DESCRIPTION_FILE_NAME);
- IProjectDescription descr = ResourcesPlugin.getWorkspace()
- .loadProjectDescription(tplPrjDescr);
- descr.setLocation(null);
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
- descr.getName());
- project.create(descr, monitor);
- project.open(IResource.BACKGROUND_REFRESH, monitor);
-
- return project;
- }
-}
Copied: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author eskimo
+ *
+ */
+public class ResourcesUtils {
+
+ public static IProject importProject(Bundle bundle, String templLocation,
+ IProgressMonitor monitor) throws IOException, CoreException,
+ InvocationTargetException, InterruptedException {
+
+ String tplPrjLcStr;
+ tplPrjLcStr = FileLocator.resolve(bundle.getEntry(templLocation))
+ .getFile();
+
+ return importProject(tplPrjLcStr, monitor);
+ }
+
+ public static IProject importProject(String location,
+ IProgressMonitor monitor) throws CoreException, IOException,
+ InvocationTargetException, InterruptedException {
+ IProject importedPrj = createEclipseProjectDromDescriptor(location,
+ monitor);
+ ImportOperation op = new ImportOperation(importedPrj.getFullPath(),
+ new File(location), FileSystemStructureProvider.INSTANCE,
+ new IOverwriteQuery() {
+ public String queryOverwrite(String pathString) {
+ return IOverwriteQuery.ALL;
+ }
+ }, Arrays.asList(new File(location).listFiles()));
+
+ op.setCreateContainerStructure(false);
+ op.run(monitor);
+ return importedPrj;
+ }
+
+ public static IProject importExistingProject(IProject project, String location, String name) throws CoreException {
+ return importExistingProject(project, location, name, new NullProgressMonitor(), true);
+ }
+
+ public static IProject importExistingProject(IProject project, String location, String name, IProgressMonitor monitor, boolean refreshWorkspace) throws CoreException {
+ IPath path = new Path(location).append(".project"); //$NON-NLS-1$
+ IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(path);
+ description.setName(name);
+ project.create(description, monitor);
+ project.open(IResource.NONE, monitor);
+ if(refreshWorkspace) {
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ }
+ return project;
+ }
+
+ public static IProject createEclipseProject(String projectName,
+ IProgressMonitor monitor) throws CoreException {
+
+ IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IProjectDescription description = workspace
+ .newProjectDescription(projectName);
+ newProjectHandle.create(description, new NullProgressMonitor());
+ newProjectHandle.open(monitor);
+ return newProjectHandle;
+ }
+
+ public static IProject createEclipseProjectDromDescriptor(
+ String templateLocation, IProgressMonitor monitor)
+ throws CoreException, IOException {
+
+ IPath tplPrjDescr = new Path(templateLocation)
+ .append(IProjectDescription.DESCRIPTION_FILE_NAME);
+ IProjectDescription descr = ResourcesPlugin.getWorkspace()
+ .loadProjectDescription(tplPrjDescr);
+ descr.setLocation(null);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ descr.getName());
+ project.create(descr, monitor);
+ project.open(IResource.BACKGROUND_REFRESH, monitor);
+
+ return project;
+ }
+}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.common.util;
-
-/**
- * Miscellaneous String utility functions
- *
- * @author Victor V. Rubezhny
- */
-public class StringUtil {
-/**
- * Cuts of the starting and ending quotes from a given text value
- *
- * @param Quoted text value
- * @return Non-quoted text value
- */
- public static String trimQuotes(String value) {
- if(value == null)
- return null;
-
- if(value.startsWith("'") || value.startsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(1);
- }
-
- if(value.endsWith("'") || value.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(0, value.length() - 1);
- }
- return value;
- }
-
-}
Deleted: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -1,227 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 - 2012 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.common.util;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IImportDeclaration;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.jboss.tools.common.CommonPlugin;
-
-public class TypeResolutionCache {
- private static TypeResolutionCache instance = new TypeResolutionCache();
-
- public static TypeResolutionCache getInstance() {
- return instance;
- }
-
- static class Resolved {
- IType type;
- Map<String, String> types = new Hashtable<String, String>();
- List<String> classImports = new ArrayList<String>();
- List<String> packageImports = new ArrayList<String>();
- Resolved(IType type) {
- this.type = type;
- readImports();
- }
-
- void setType(IType type) {
- this.type = type;
- types.clear();
-
- readImports();
- }
-
- void readImports() {
- ICompilationUnit unit = type.getCompilationUnit();
- if(unit == null) return;
- IImportDeclaration[] ds = null;
- try {
- ds = unit.getImports();
- } catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
- ds = new IImportDeclaration[0];
- }
- IResource r = unit.getResource();
-
- if(r instanceof IFile && r.exists()) {
- List<String> newClassImports = new ArrayList<String>();
- List<String> newPackageImports = new ArrayList<String>();
- //add local package
- newPackageImports.add(type.getPackageFragment().getElementName() + "."); //$NON-NLS-1$
- for (IImportDeclaration d: ds) {
- String q = d.getElementName();
- if(q.endsWith(".*")) { //$NON-NLS-1$
- newPackageImports.add( q = q.substring(0, q.length() - 1));
- } else {
- newClassImports.add(q);
- }
- }
- classImports = newClassImports;
- packageImports = newPackageImports;
- }
- }
-
- public String resolveInImports(String typeName) {
- if(typeName.indexOf(".") >= 0) { //$NON-NLS-1$
- try {
- IType q = EclipseJavaUtil.findType(type.getJavaProject(), typeName);
- if(q != null) {
- types.put(typeName, typeName);
- return typeName;
- }
- } catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
- }
- //too difficult
- return null;
- }
- for (String imp: classImports) {
- if(imp.endsWith("." + typeName)) { //$NON-NLS-1$
- types.put(typeName, imp);
- return imp;
- }
- }
- for (String imp: packageImports) {
- String result = imp + typeName;
- try {
- IType q = EclipseJavaUtil.findType(type.getJavaProject(), result);
- if(q != null) {
- types.put(typeName, result);
- return result;
- }
- } catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
- }
- }
- String pr = "java.lang." + typeName; //$NON-NLS-1$
- if(primitive.contains(pr)) {
- types.put(typeName, pr);
- return pr;
- }
-
- if(type.getTypeParameter(typeName).exists()) {
- types.put(typeName, typeName);
- return typeName;
- }
- return null;
- }
- }
-
- static Set<String> primitive = new HashSet<String>();
- static {
- primitive.add("void"); //$NON-NLS-1$
- primitive.add("int"); //$NON-NLS-1$
- primitive.add("char"); //$NON-NLS-1$
- primitive.add("boolean"); //$NON-NLS-1$
- primitive.add("long"); //$NON-NLS-1$
- primitive.add("short"); //$NON-NLS-1$
- primitive.add("double"); //$NON-NLS-1$
- primitive.add("float"); //$NON-NLS-1$
- primitive.add("java.lang.Object"); //$NON-NLS-1$
- primitive.add("java.lang.Number"); //$NON-NLS-1$
- primitive.add("java.lang.Integer"); //$NON-NLS-1$
- primitive.add("java.lang.Character"); //$NON-NLS-1$
- primitive.add("java.lang.Boolean"); //$NON-NLS-1$
- primitive.add("java.lang.Long"); //$NON-NLS-1$
- primitive.add("java.lang.Short"); //$NON-NLS-1$
- primitive.add("java.lang.Double"); //$NON-NLS-1$
- primitive.add("java.lang.Float"); //$NON-NLS-1$
- primitive.add("java.lang.String"); //$NON-NLS-1$
- primitive.add("java.lang.StringBuffer"); //$NON-NLS-1$
- primitive.add("java.lang.Class"); //$NON-NLS-1$
- primitive.add("java.lang.Deprecated"); //$NON-NLS-1$
- primitive.add("java.lang.SuppressWarnings"); //$NON-NLS-1$
- primitive.add("java.lang.Throwable"); //$NON-NLS-1$
- primitive.add("java.lang.Exception"); //$NON-NLS-1$
- primitive.add("java.lang.RuntimeException"); //$NON-NLS-1$
- primitive.add("java.lang.Override"); //$NON-NLS-1$
- }
- static String NULL = ";;;"; //$NON-NLS-1$
- Map<String,Resolved> resolved = new Hashtable<String, Resolved>();
-
- private TypeResolutionCache() {}
-
- public String resolveType(IType type, String typeName) {
- if(type == null) return null;
- if(type.isBinary() || typeName == null || primitive.contains(typeName)) return typeName;
-
- String n = getKey(type);
- Resolved r = resolved.get(n);
- if(r == null) {
- r = new Resolved(type);
- resolved.put(n, r);
- } else if(r.type != type) {
- r.setType(type);
- }
-
- String result = r.types.get(typeName);
- if(result != null) {
- return (result == NULL) ? null : result;
- }
-
- result = r.resolveInImports(typeName);
- if(result != null) {
- return result;
- }
-
- result = __resolveType(type, typeName);
-
-// System.out.println(typeName + "---" + result);
-
- r.types.put(typeName, result == null ? NULL : result);
- return result;
-
- }
-
- public void clean() {
- resolved = new Hashtable<String, Resolved>();
- }
-
- private String __resolveType(IType type, String typeName) {
- try {
- String resolvedArray[][] = type.resolveType(typeName);
-// resolvedArray == null for primitive types
- if(resolvedArray == null) return typeName;
- typeName = ""; //$NON-NLS-1$
- for (int i = 0; i < resolvedArray[0].length; i++)
- typeName += (!"".equals(typeName) ? "." : "") + resolvedArray[0][i]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return typeName;
- } catch (JavaModelException e) {
- CommonPlugin.getPluginLog().logError(e);
- } catch (IllegalArgumentException e) {
- CommonPlugin.getPluginLog().logError(e);
- }
- return null;
- }
-
- private String getKey(IType type) {
- String n = type.getFullyQualifiedName();
- IJavaProject jp = type.getJavaProject();
- if(jp == null) return n;
- IProject p = jp.getProject();
- if(p == null || !p.isAccessible()) return n;
- return p.getName() + ":" + n; //$NON-NLS-1$
- }
-
-}
Added: trunk/common/plugins/org.jboss.tools.common.core/.classpath
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/.classpath (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/.classpath 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Property changes on: trunk/common/plugins/org.jboss.tools.common.core/.classpath
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/common/plugins/org.jboss.tools.common.core/.project
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/.project (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/.project 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.common.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
Property changes on: trunk/common/plugins/org.jboss.tools.common.core/.project
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/common/plugins/org.jboss.tools.common.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/META-INF/MANIFEST.MF (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/META-INF/MANIFEST.MF 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,43 @@
+Manifest-Version: 1.0
+Bundle-Name: %Bundle-Name.0
+Bundle-ClassPath: .
+Bundle-Activator: org.jboss.tools.common.core.CommonCorePlugin
+Bundle-Vendor: %providerName
+Bundle-SymbolicName: org.jboss.tools.common.core;singleton:=true
+Bundle-Localization: plugin
+Export-Package: org.jboss.tools.common.core,
+ org.jboss.tools.common.databinding,
+ org.jboss.tools.common.java,
+ org.jboss.tools.common.java.impl,
+ org.jboss.tools.common.jobs,
+ org.jboss.tools.common.log,
+ org.jboss.tools.common.preferences,
+ org.jboss.tools.common.reporting,
+ org.jboss.tools.common.text,
+ org.jboss.tools.common.util,
+ org.jboss.tools.common.web,
+ org.jboss.tools.common.xml,
+ org.jboss.tools.common.zip
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.wst.xml.core;bundle-version="1.1.600";visibility:=reexport,
+ org.eclipse.wst.common.modulecore;bundle-version="1.2.100",
+ org.eclipse.jst.j2ee;bundle-version="1.1.500",
+ org.eclipse.jst.j2ee.core;bundle-version="1.2.100",
+ org.eclipse.wst.common.project.facet.core;bundle-version="1.4.200",
+ org.eclipse.jem.util;bundle-version="2.1.2",
+ org.eclipse.wst.common.emfworkbench.integration;bundle-version="1.2.100",
+ org.eclipse.jface;bundle-version="3.7.0",
+ org.eclipse.core.resources;bundle-version="3.7.100",
+ org.eclipse.wst.common.uriresolver;bundle-version="1.1.401";visibility:=reexport,
+ org.eclipse.core.net;bundle-version="1.2.100",
+ org.eclipse.jdt.core;bundle-version="3.7.0",
+ org.eclipse.jface.text;bundle-version="3.7.0",
+ org.apache.commons.httpclient;bundle-version="3.1.0",
+ org.eclipse.jpt.common.core;bundle-version="1.0.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
+ org.eclipse.jdt.core.manipulation;bundle-version="1.5.0",
+ org.eclipse.core.filebuffers;bundle-version="3.5.200"
+Bundle-Version: 3.4.0.qualifier
+Bundle-ActivationPolicy: lazy
+Bundle-ManifestVersion: 2
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Added: trunk/common/plugins/org.jboss.tools.common.core/about.html
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/about.html (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/about.html 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>©2007 - 2012 Red Hat, Inc. All rights reserved</P>
+
+<H3>License</H3>
+
+<P>Red Hat Inc., through its JBoss division, makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from Red Hat Inc., the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributor's license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+ <A href="http://www.jboss.org/tools">http://www.jboss.org/tools</A>.</P>
+
+</BODY>
+</HTML>
\ No newline at end of file
Added: trunk/common/plugins/org.jboss.tools.common.core/build.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/build.properties (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/build.properties 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,7 @@
+source.. = src
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ plugin.properties,\
+ about.html
+source.. = src
Added: trunk/common/plugins/org.jboss.tools.common.core/plugin.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/plugin.properties (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/plugin.properties 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,7 @@
+providerName=JBoss by Red Hat
+
+reportParameterName=reportDescription
+reportingUrl=http://box.exadel.com/goto/bugreport.jsp
+reportingJobName=Bug reporting
+errorReportingMessage=Can't submit report
+Bundle-Name.0 = JBoss Tools Common Core
Added: trunk/common/plugins/org.jboss.tools.common.core/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/plugin.xml (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/plugin.xml 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+</plugin>
\ No newline at end of file
Property changes on: trunk/common/plugins/org.jboss.tools.common.core/plugin.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/common/plugins/org.jboss.tools.common.core/pom.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/pom.xml (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/pom.xml 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.tools.common</groupId>
+ <artifactId>plugins</artifactId>
+ <version>3.4.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.jboss.tools.common.plugins</groupId>
+ <artifactId>org.jboss.tools.common.core</artifactId>
+
+ <packaging>eclipse-plugin</packaging>
+</project>
Property changes on: trunk/common/plugins/org.jboss.tools.common.core/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/CommonCorePlugin.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/CommonCorePlugin.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/core/CommonCorePlugin.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,117 @@
+package org.jboss.tools.common.core;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.log.BasePlugin;
+import org.jboss.tools.common.log.IPluginLog;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+public class CommonCorePlugin extends BasePlugin {
+ public static final String PLUGIN_ID = "org.jboss.tools.common"; //$NON-NLS-1$
+ protected static CommonCorePlugin instance;
+ private static String environment;
+
+ public CommonCorePlugin() {
+ super();
+ instance = this;
+ }
+
+ public static CommonCorePlugin getInstance() {
+ return instance;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+ /**
+ * Gets message from plugin.properties
+ * @param key
+ * @return
+ */
+ public static String getMessage(String key) {
+ return Platform.getResourceString(instance.getBundle(), key);
+ }
+
+ /**
+ * @return Studio environment.
+ */
+ public static String getEnvironment() {
+ if(environment == null) {
+ String osName = System.getProperty("os.name"); //$NON-NLS-1$
+ String javaVersion = System.getProperty("java.version"); //$NON-NLS-1$
+ String studioName = "unknown"; //$NON-NLS-1$
+ String studioVersion = "unknown"; //$NON-NLS-1$
+ String eclipseVersion = "unknown"; //$NON-NLS-1$
+ String eclipseBuildId = "unknown"; //$NON-NLS-1$
+
+ Bundle studio = Platform.getBundle("org.jboss.tools.common"); //$NON-NLS-1$
+ if(studio!=null) {
+ Dictionary studioDic = studio.getHeaders();
+ studioName = (String)studioDic.get("Bundle-Name"); //$NON-NLS-1$
+ studioVersion = (String)studioDic.get("Bundle-Version"); //$NON-NLS-1$
+ }
+
+ Bundle eclipse = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$
+ if(eclipse!=null) {
+ Dictionary eclipseDic = eclipse.getHeaders();
+ eclipseVersion = (String)eclipseDic.get("Bundle-Version"); //$NON-NLS-1$
+ FileInputStream fis = null;
+ try {
+ String path = FileLocator.resolve(eclipse.getEntry("/")).getPath(); //$NON-NLS-1$
+ if(path!=null) {
+ File aboutMappings = new File(path, "about.mappings"); //$NON-NLS-1$
+ if(aboutMappings.exists()) {
+ Properties properties = new Properties();
+ fis = new FileInputStream(aboutMappings);
+ properties.load(fis);
+ String buildId = properties.getProperty("0"); //$NON-NLS-1$
+ if(buildId!=null && buildId.length()>0) {
+ eclipseBuildId = buildId;
+ }
+ }
+ }
+ } catch (IOException e) {
+ getPluginLog().logError("Error in getting environment info: " + e.getMessage()); //$NON-NLS-1$
+ } finally {
+ if(fis!=null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ StringBuffer result = new StringBuffer(studioName).append(" ").append(studioVersion). //$NON-NLS-1$
+ append(", Eclipse ").append(eclipseVersion).append(" "). //$NON-NLS-1$ //$NON-NLS-2$
+ append(eclipseBuildId).append(", Java ").append(javaVersion). //$NON-NLS-1$
+ append(", ").append(osName); //$NON-NLS-1$
+ environment = result.toString();
+ }
+ return environment;
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static CommonCorePlugin getDefault() {
+ return instance;
+ }
+
+ /**
+ * @return IPluginLog object
+ */
+ public static IPluginLog getPluginLog() {
+ return getDefault();
+ }
+
+}
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/ParametedType.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedType.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/ParametedType.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -23,7 +23,7 @@
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
/**
*
@@ -224,7 +224,7 @@
}
}
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
this.inheritedTypes = inheritedTypes;
inheritanceIsBuilt = true;
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/ParametedTypeFactory.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/ParametedTypeFactory.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/ParametedTypeFactory.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -21,7 +21,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.jboss.tools.common.util.EclipseJavaUtil;
public class ParametedTypeFactory {
@@ -48,7 +48,7 @@
try {
r = type.getNameRange();
} catch (CoreException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
if(r != null) {
parametedType = new TypeDeclaration(parametedType, type.getResource(), r.getOffset(), r.getLength());
@@ -61,7 +61,7 @@
try {
ps = type.getTypeParameterSignatures();
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
if(ps != null && ps.length > 0) {
for (int i = 0; i < ps.length; i++) {
@@ -69,7 +69,7 @@
ParametedType p = getParametedTypeForParameter(type, ps[i], null);
if(p != null) parametedType.addParameter(p);
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
}
}
@@ -137,7 +137,7 @@
ParametedType st = getParametedTypeForParameter(context, ps[i], result);
if(st != null) {
if(st.getSignature().indexOf(Signature.C_COLON) >= 0) {
- CommonPlugin.getDefault().logWarning("Wrong signature=" + st.getSignature());
+ CommonCorePlugin.getDefault().logWarning("Wrong signature=" + st.getSignature());
}
return st;
}
@@ -163,7 +163,7 @@
try {
paramSignatures = Signature.getTypeArguments(typeSignature);
} catch (IllegalArgumentException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
if(paramSignatures != null) for (String paramSignature: paramSignatures) {
ParametedType param = getParametedType(context, basetype, paramSignature);
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/AnnotationDeclaration.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -24,7 +24,7 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.IType;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.jboss.tools.common.java.IAnnotationDeclaration;
import org.jboss.tools.common.java.IAnnotationType;
import org.jboss.tools.common.java.IJavaAnnotation;
@@ -159,7 +159,7 @@
}
} catch (CoreException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
}
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/java/impl/JavaAnnotation.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/java/impl/JavaAnnotation.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -18,7 +18,7 @@
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.jboss.tools.common.java.IJavaAnnotation;
import org.jboss.tools.common.util.EclipseJavaUtil;
@@ -35,7 +35,7 @@
annotationTypeName = EclipseJavaUtil.resolveType(declaringType, name);
type = EclipseJavaUtil.findType(annotation.getJavaProject(), annotationTypeName);
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
}
@@ -58,7 +58,7 @@
return range.getLength();
}
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
return 0;
}
@@ -70,7 +70,7 @@
return range.getOffset();
}
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
return 0;
}
@@ -94,7 +94,7 @@
try {
return annotation.getMemberValuePairs();
} catch (JavaModelException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
return new IMemberValuePair[0];
}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/BasePlugin.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/BasePlugin.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/BasePlugin.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/BasePlugin.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.log;
+
+import org.eclipse.core.runtime.Plugin;
+
+/**
+ * Provides an easy way to log status of events.
+ *
+ * NOTE: It is useful to make the static method getPluginLog()
+ * which provides the interface IPluginLog for using it in your code
+ * in future
+ *
+ * @author Sergey Vasilyev
+ *
+ */
+
+public class BasePlugin extends Plugin implements IPluginLog {
+ public void logError(String message, Throwable t) {
+ LogHelper.logError(this, message, t);
+ }
+
+ public void logError(String message) {
+ LogHelper.logError(this, message);
+ }
+
+ public void logError(Throwable t) {
+ LogHelper.logError(this, t);
+ }
+
+ public void logWarning(String message, Throwable t) {
+ LogHelper.logWarning(this, message, t);
+ }
+
+ public void logWarning(String message) {
+ LogHelper.logWarning(this, message);
+ }
+
+ public void logWarning(Throwable t) {
+ LogHelper.logWarning(this, t);
+ }
+
+ public void logInfo(String message, Throwable t) {
+ LogHelper.logInfo(this, message, t);
+ }
+
+ public void logInfo(String message) {
+ LogHelper.logInfo(this, message);
+ }
+}
\ No newline at end of file
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/ILoggingAdapter.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/ILoggingAdapter.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/ILoggingAdapter.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/ILoggingAdapter.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.log;
+
+/**
+ * @author Andre Dietisheim
+ */
+public interface ILoggingAdapter {
+
+ public void error(String errorMessage);
+
+ public void debug(String message);
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/IPluginLog.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/IPluginLog.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/IPluginLog.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/IPluginLog.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.log;
+
+public interface IPluginLog {
+ public void logError(String message, Throwable t);
+ public void logError(String message);
+ public void logError(Throwable t);
+
+ public void logWarning(String message, Throwable t);
+ public void logWarning(String message);
+ public void logWarning(Throwable t);
+
+ public void logInfo(String message, Throwable t);
+ public void logInfo(String message);
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/LogHelper.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/LogHelper.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/LogHelper.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/LogHelper.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.log;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.Bundle;
+
+public class LogHelper {
+ public static void logError(Plugin plugin, Throwable t) {
+ logError(plugin, null, t);
+ }
+
+ public static void logError(Plugin plugin, String message) {
+ logError(plugin, message, null);
+ }
+
+ public static void logError(Plugin plugin, String message, Throwable t) {
+ IStatus status = StatusFactory.getInstance(IStatus.ERROR,
+ plugin.getBundle().getSymbolicName(), message, t);
+ logStatus(plugin, status);
+ }
+
+ public static void logError(String pluginId, Throwable t) {
+ logError(pluginId, null, t);
+ }
+
+ public static void logError(String pluginId, String message) {
+ logError(pluginId, message, null);
+ }
+
+ public static void logError(String pluginId, String message, Throwable t) {
+ IStatus status = StatusFactory.getInstance(IStatus.ERROR, pluginId,
+ message, t);
+ logStatus(pluginId, status);
+ }
+
+ public static void logWarning(Plugin plugin, Throwable t) {
+ logWarning(plugin, null, t);
+ }
+
+ public static void logWarning(Plugin plugin, String message) {
+ logWarning(plugin, message, null);
+ }
+
+
+ public static void logWarning(Plugin plugin, String message, Throwable t) {
+ IStatus status = StatusFactory.getInstance(IStatus.WARNING,
+ plugin.getBundle().getSymbolicName(), message, t);
+ logStatus(plugin, status);
+ }
+
+ public static void logWarning(String pluginId, Throwable t) {
+ logWarning(pluginId, null, t);
+ }
+
+ public static void logWarning(String pluginId, String message) {
+ logWarning(pluginId, message, null);
+ }
+
+
+ public static void logWarning(String pluginId, String message,
+ Throwable t) {
+ IStatus status = StatusFactory.getInstance(IStatus.WARNING, pluginId,
+ message, t);
+ logStatus(pluginId, status);
+ }
+
+ public static void logInfo(Plugin plugin, String message,
+ Throwable t) {
+ IStatus status = StatusFactory.getInstance(IStatus.INFO,
+ plugin.getBundle().getSymbolicName(), message, t);
+ logStatus(plugin, status);
+ }
+
+
+ public static void logInfo(Plugin plugin, String message) {
+ IStatus status = StatusFactory.getInstance(IStatus.INFO,
+ plugin.getBundle().getSymbolicName(), message);
+ logStatus(plugin, status);
+ }
+
+ public static void logInfo(String pluginId, String message,
+ Throwable t) {
+ IStatus status = StatusFactory.getInstance(IStatus.INFO, pluginId,
+ message, t);
+ logStatus(pluginId, status);
+ }
+
+ public static void logInfo(String pluginId, String message) {
+ IStatus status = StatusFactory.getInstance(IStatus.INFO, pluginId,
+ message);
+ logStatus(pluginId, status);
+ }
+
+ public static void log(int severity, String pluginId, int code,
+ String message, Throwable t) {
+ IStatus status = StatusFactory.getInstance(severity, pluginId, code,
+ message, t);
+ logStatus(pluginId, status);
+ }
+
+ public static void logStatus(Plugin plugin, IStatus status) {
+ plugin.getLog().log(status);
+ }
+
+ public static void logStatus(String pluginId, IStatus status) {
+ Bundle bundle = Platform.getBundle(pluginId);
+ logStatus(bundle, status);
+ }
+
+ public static void logStatus(Bundle bundle, IStatus status) {
+ ILog log = Platform.getLog(bundle);
+ log.log(status);
+ }
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/PluginLogger.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/PluginLogger.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/PluginLogger.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/PluginLogger.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.log;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * A logging adapter that logs to a given plugin.
+ *
+ * @author Andre Dietisheim
+ */
+public class PluginLogger implements ILoggingAdapter {
+
+ private Plugin plugin;
+
+ public PluginLogger(Plugin plugin) {
+ this.plugin = plugin;
+ }
+
+ public void error(String message) {
+ log(IStatus.ERROR, message);
+ }
+
+ public void debug(String message) {
+ log(IStatus.INFO, message);
+ }
+
+ private void log(int severity, String message) {
+ if (!isTracingEnabled()) {
+ return;
+ }
+
+ if (plugin != null) {
+ IStatus status = new Status(severity, plugin.getBundle().getSymbolicName(), message);
+ plugin.getLog().log(status);
+ }
+ }
+
+ protected Plugin getPlugin() {
+ return plugin;
+ }
+
+ protected boolean isTracingEnabled() {
+ // defaults to always log
+ return true;
+ }
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/StatusFactory.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/log/StatusFactory.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/StatusFactory.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/log/StatusFactory.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.log;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+
+public class StatusFactory {
+ public final static int UNDEFINED_ERROR = 0;
+ public final static String UNSPECIFIED_MESSAGE = null;
+ public final static String EMPTY_MESSAGE = ""; //$NON-NLS-1$
+
+ public static IStatus getInstance(int severity, String pluginId,
+ int code, String message, Throwable t) {
+ return new Status(severity, pluginId, code, checkMessage(message, t), t);
+ }
+
+ public static IStatus getInstance(int severity, String pluginId,
+ String message, Throwable t) {
+ return getInstance(severity, pluginId, UNDEFINED_ERROR, message, t);
+ }
+
+ public static IStatus getInstance(int severity, String pluginId,
+ String message) {
+ return getInstance(severity, pluginId, UNDEFINED_ERROR, message, null);
+ }
+
+ public static IStatus getInstance(int severity, String pluginId,
+ Throwable t) {
+ return getInstance(severity, pluginId, UNDEFINED_ERROR, EMPTY_MESSAGE, t);
+ }
+
+ public static IStatus getInstance(int severity, String pluginId,
+ int code, Throwable t) {
+ return getInstance(severity, pluginId, code, EMPTY_MESSAGE, t);
+ }
+
+ public static IStatus getInstance(int severity, String pluginId,
+ int code, String message) {
+ return getInstance(severity, pluginId, code, message, null);
+ }
+
+ /**
+ * Returns a multi status with the given severity, plugin id, error code,
+ * message, cause and child status instances.
+ *
+ * @param severity
+ * @param pluginId
+ * @param message
+ * @param t
+ * @param status
+ * @return a multi status
+ */
+ public static IStatus getInstance(int severity, String pluginId, String message, Throwable t, IStatus... status) {
+ return new MultiStatus(pluginId, UNDEFINED_ERROR, status, message, t);
+ }
+
+ private static String checkMessage(String message, Throwable t) {
+ if (message == UNSPECIFIED_MESSAGE) {
+ if (t != null && t.getMessage() != null) {
+ return t.getMessage();
+ }
+ return EMPTY_MESSAGE;
+ }
+ return message;
+ }
+}
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/preferences/SeverityPreferences.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/preferences/SeverityPreferences.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/preferences/SeverityPreferences.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -18,7 +18,7 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.JavaCore;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
/**
* Constants for names of seam preferences.
@@ -46,9 +46,9 @@
public abstract class SeverityPreferences {
public static final String ENABLE_BLOCK_PREFERENCE_NAME = "enableBlock"; //$NON-NLS-1$
- public static final String MAX_NUMBER_OF_MARKERS_PREFERENCE_NAME = CommonPlugin.PLUGIN_ID + ".validator.problem.markersBlock"; //$NON-NLS-1$
+ public static final String MAX_NUMBER_OF_MARKERS_PREFERENCE_NAME = CommonCorePlugin.PLUGIN_ID + ".validator.problem.markersBlock"; //$NON-NLS-1$
public static final int DEFAULT_MAX_NUMBER_OF_MARKERS_PER_FILE = 20;
- public static final String WRONG_BUILDER_ORDER_PREFERENCE_NAME = CommonPlugin.PLUGIN_ID + ".validator.problem.wrongBuilderOrder"; //$NON-NLS-1$
+ public static final String WRONG_BUILDER_ORDER_PREFERENCE_NAME = CommonCorePlugin.PLUGIN_ID + ".validator.problem.wrongBuilderOrder"; //$NON-NLS-1$
public static final String ERROR = "error"; //$NON-NLS-1$
public static final String WARNING = "warning"; //$NON-NLS-1$
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/ProblemBuffer.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemBuffer.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/ProblemBuffer.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -12,14 +12,14 @@
import java.io.File;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.tools.common.util.FileUtils;
+import org.osgi.framework.Bundle;
//import org.eclipse.core.internal.runtime.PlatformLogWriter;
//import org.eclipse.core.runtime.ILogListener;
//import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
//import org.eclipse.core.runtime.adaptor.EclipseLog;
//import org.eclipse.osgi.framework.log.FrameworkLog;
-import org.jboss.tools.common.util.FileUtil;
-import org.osgi.framework.Bundle;
/**
* This class is intended only to be called by Report Problem Framework.
@@ -68,12 +68,12 @@
*/
public String getContent() {
File f = getLogFile();
- return (!f.isFile()) ? "" : FileUtil.readFile(f); //$NON-NLS-1$
+ return (!f.isFile()) ? "" : FileUtils.readFile(f); //$NON-NLS-1$
}
public String getEclipseLogContent() {
File f = Platform.getLogFileLocation().toFile();
- return (f.isFile()) ? FileUtil.readFile(f) : ""; //$NON-NLS-1$
+ return (f.isFile()) ? FileUtils.readFile(f) : ""; //$NON-NLS-1$
}
public void clean() {
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/Submit.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/Submit.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/reporting/Submit.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -18,7 +18,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.jboss.tools.common.util.HttpUtil;
/**
@@ -27,11 +27,11 @@
*/
public class Submit {
- public static String REPORT_DESRIPTION_PARAMETER_NAME = CommonPlugin.getMessage("%reportParameterName"); //$NON-NLS-1$
+ public static String REPORT_DESRIPTION_PARAMETER_NAME = CommonCorePlugin.getMessage("%reportParameterName"); //$NON-NLS-1$
- private static String URL = CommonPlugin.getMessage("%reportingUrl"); //$NON-NLS-1$
- private static String JOB_NAME = CommonPlugin.getMessage("%reportingJobName"); //$NON-NLS-1$
- private static String ERROR_MESSAGE = CommonPlugin.getMessage("%errorReportingMessage"); //$NON-NLS-1$
+ private static String URL = CommonCorePlugin.getMessage("%reportingUrl"); //$NON-NLS-1$
+ private static String JOB_NAME = CommonCorePlugin.getMessage("%reportingJobName"); //$NON-NLS-1$
+ private static String ERROR_MESSAGE = CommonCorePlugin.getMessage("%errorReportingMessage"); //$NON-NLS-1$
private static Submit INSTANCE = new Submit();
@@ -63,7 +63,7 @@
if(exceptionMessage!=null && exceptionMessage.trim().length()>0) {
message = message + ".\r\n" + e.getClass().getName() + ": " + exceptionMessage; //$NON-NLS-1$ //$NON-NLS-2$
}
- Status status = new Status(IStatus.WARNING, CommonPlugin.PLUGIN_ID, IStatus.WARNING, message, e);
+ Status status = new Status(IStatus.WARNING, CommonCorePlugin.PLUGIN_ID, IStatus.WARNING, message, e);
return status;
}
if(cleanBuffer) {
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/BeanUtil.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/BeanUtil.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/BeanUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/BeanUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import org.eclipse.jdt.core.IMethod;
+
+/**
+ *
+ * @author V. Kabanovich
+ *
+ */
+public class BeanUtil {
+ public static final String GET = "get"; //$NON-NLS-1$
+ public static final String SET = "set"; //$NON-NLS-1$
+ public static final String IS = "is"; //$NON-NLS-1$
+
+ public static boolean isGetter(String methodName, int numberOfParameters) {
+ return (((methodName.startsWith(GET) && !methodName.equals(GET))
+ || (methodName.startsWith(IS) && !methodName.equals(IS)))
+ && numberOfParameters == 0);
+ }
+
+ public static boolean isSetter(String methodName, int numberOfParameters) {
+ return (((methodName.startsWith(SET) && !methodName.equals(SET)))
+ && numberOfParameters == 1);
+ }
+
+ public static boolean isGetter(IMethod method) {
+ return method != null && isGetter(method.getElementName(), method.getNumberOfParameters())
+ && checkPropertyReturnType(method);
+ }
+
+
+ public static boolean checkPropertyReturnType(String typeName, String methodName) {
+ if(typeName == null || typeName.equals("void")) { //$NON-NLS-1$
+ return false;
+ }
+ if(methodName.startsWith(BeanUtil.IS)) {
+ if(!"boolean".equals(typeName) && !"java.lang.Boolean".equals(typeName)) { //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean checkPropertyReturnType(IMethod method) {
+ return method != null && checkPropertyReturnType(EclipseJavaUtil.getMemberTypeAsString(method), method.getElementName());
+ }
+
+ public static boolean isSetter(IMethod method) {
+ return method != null && isSetter(method.getElementName(), method.getNumberOfParameters());
+ }
+
+ public static String getPropertyName(String methodName) {
+ if(isGetter(methodName, 0) || isSetter(methodName, 1)) {
+ StringBuffer name = new StringBuffer(methodName);
+ if(methodName.startsWith(IS)) {
+ name.delete(0, 2);
+ } else {
+ name.delete(0, 3);
+ }
+ if(name.length() < 2 || !Character.isUpperCase(name.charAt(1))) {
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ }
+ return name.toString();
+ }
+ return null;
+ }
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseJavaUtil.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/EclipseJavaUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,247 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.jboss.tools.common.core.CommonCorePlugin;
+
+public class EclipseJavaUtil {
+
+ public static String getMemberTypeAsString(IMember member) {
+ if(member instanceof IField) return getMemberTypeAsString((IField)member);
+ if(member instanceof IMethod) return getMemberTypeAsString((IMethod)member);
+ return null;
+ }
+
+ public static String getMemberTypeAsString(IField f) {
+ if(f == null) return null;
+ try {
+ String typeName = new String(Signature.toCharArray(f.getTypeSignature().toCharArray()));
+ return resolveType(f.getDeclaringType(), typeName);
+ } catch (JavaModelException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ return null;
+ }
+
+ public static String getMemberTypeAsString(IMethod m) {
+ if(m == null) return null;
+ try {
+ return resolveTypeAsString(m.getDeclaringType(), m.getReturnType());
+ } catch (JavaModelException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ return null;
+ }
+
+ public static String resolveTypeAsString(IType type, String typeName) {
+ if(type == null || typeName == null) return null;
+ typeName = new String(Signature.toCharArray(typeName.toCharArray()));
+ int i = typeName.indexOf(Signature.C_GENERIC_START);
+ if(i > 0) typeName = typeName.substring(0, i);
+ return resolveType(type, typeName);
+ }
+
+ public static String resolveType(IType type, String typeName) {
+ return TypeResolutionCache.getInstance().resolveType(type, typeName);
+ }
+
+ public static IType findType(IJavaProject javaProject, String qualifiedName) throws JavaModelException {
+ if(qualifiedName == null || qualifiedName.length() == 0) return null;
+ IType type = javaProject.findType(qualifiedName);
+ if(type != null) return type;
+ int dot = qualifiedName.lastIndexOf('.');
+ String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot); //$NON-NLS-1$
+ String shortName = qualifiedName.substring(dot + 1);
+ IPackageFragmentRoot[] rs = javaProject.getPackageFragmentRoots();
+ for (int i = 0; i < rs.length; i++) {
+ IPackageFragment f = rs[i].getPackageFragment(packageName);
+ if(f == null || !f.exists()) continue;
+ ICompilationUnit[] us = f.getCompilationUnits();
+ for (int j = 0; j < us.length; j++) {
+ IType t = us[j].getType(shortName);
+ if(t != null && t.exists()) return t;
+ }
+ }
+ return null;
+ }
+
+ public static List<IType> getSupperTypes(IType type) throws JavaModelException {
+ ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
+ IType[] superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
+ if(superTypes == null) {
+ return Collections.emptyList();
+ }
+ List<IType> suppers = new ArrayList<IType>();
+ for (int i = 0; i < superTypes.length; i++) {
+ suppers.add(superTypes[i]);
+ }
+ return suppers;
+ }
+
+ public static IAnnotation findAnnotation(IType sourceType, IAnnotatable member, String qulifiedAnnotationName) throws JavaModelException{
+ IAnnotation[] annotations = member.getAnnotations();
+ String simpleAnnotationTypeName = qulifiedAnnotationName;
+ int lastDot = qulifiedAnnotationName.lastIndexOf('.');
+ if(lastDot>-1) {
+ simpleAnnotationTypeName = simpleAnnotationTypeName.substring(lastDot + 1);
+ }
+ for (IAnnotation annotation : annotations) {
+ if(qulifiedAnnotationName.equals(annotation.getElementName())) {
+ return annotation;
+ }
+ if(simpleAnnotationTypeName.equals(annotation.getElementName())) {
+ String fullAnnotationclassName = EclipseJavaUtil.resolveType(sourceType, simpleAnnotationTypeName);
+ if(fullAnnotationclassName!=null) {
+ IType annotationType = sourceType.getJavaProject().findType(fullAnnotationclassName);
+ if(annotationType!=null && annotationType.getFullyQualifiedName().equals(qulifiedAnnotationName)) {
+ return annotation;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds field declared in the given type or its super types.
+ *
+ * @param type
+ * @param name
+ * @return
+ * @throws CoreException
+ */
+ public static IField findField(IType type, String name) throws CoreException {
+ return findField(type, name, new HashSet<IType>());
+ }
+ private static IField findField(IType type, String name, Set<IType> processed) throws CoreException {
+ if(!type.exists() || processed.contains(type)) {
+ return null;
+ }
+ processed.add(type);
+ if(type.getField(name).exists()) {
+ return type.getField(name);
+ }
+ IField f = findField(type, type.getSuperclassName(), name, processed);
+ String[] is = type.getSuperInterfaceNames();
+ for (int i = 0; f == null && i < is.length; i++) {
+ f = findField(type, is[i], name, processed);
+ }
+ if(f == null) {
+ IType d = type.getDeclaringType();
+ if(d != null && d != type && d.exists()) {
+ f = findField(d, name);
+ }
+ }
+
+ return f;
+ }
+ private static IField findField(IType context, String typeName, String fieldName, Set<IType> processed) throws CoreException {
+ typeName = resolveType(context, typeName);
+ if(typeName != null) {
+ IType s = findType(context.getJavaProject(), typeName);
+ return (s != null) ? findField(s, fieldName, processed) : null;
+ }
+ return null;
+ }
+
+ /**
+ * Returns true if the given annotation has the given full name
+ * @param annotation
+ * @param fullName
+ * @return
+ * @throws JavaModelException
+ */
+ public static boolean checkAnnotationByFulltName(IAnnotation annotation, String fullName) throws JavaModelException {
+ if(annotation.getElementName().equals(fullName)) {
+ return true;
+ }
+ boolean result = true;
+ IType sourceType = null;
+ IJavaElement parent = annotation.getParent();
+ if(parent instanceof IMember) {
+ if(parent instanceof IType) {
+ sourceType = (IType)parent;
+ } else {
+ sourceType = ((IMember)parent).getDeclaringType();
+ }
+ String fullAnnotationName = EclipseJavaUtil.resolveType(sourceType, annotation.getElementName());
+ if(fullAnnotationName!=null) {
+ IType annotationType = sourceType.getJavaProject().findType(fullAnnotationName);
+ result = annotationType!=null && annotationType.getFullyQualifiedName().equals(fullName);
+ } else {
+ result = false;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns annotation by the short name declared for the given java member and its parents.
+ * Returns null if no annotation found.
+ * @param member
+ * @param name
+ * @param checkParents
+ * @return
+ * @throws JavaModelException
+ */
+ public static Set<IAnnotation> findAnnotationsByShortName(IJavaElement element, String name, boolean checkParents) throws JavaModelException {
+ return findAnnotationsByShortName(null, element, name, checkParents);
+ }
+
+ private static Set<IAnnotation> findAnnotationsByShortName(Set<IAnnotation> result, IJavaElement element, String name, boolean checkParents) throws JavaModelException {
+ if(element instanceof IAnnotatable) {
+ IAnnotation[] annotations = ((IAnnotatable)element).getAnnotations();
+ for (IAnnotation annotation : annotations) {
+ String aName = annotation.getElementName();
+ int i = aName.lastIndexOf('.');
+ if(i>-1) {
+ aName = aName.substring(i+1);
+ }
+ if(aName.equals(name)) {
+ if(result==null) {
+ result = new HashSet<IAnnotation>();
+ }
+ result.add(annotation);
+ break;
+ }
+ }
+ }
+ if(checkParents) {
+ IJavaElement parent = element.getParent();
+ if(parent instanceof IAnnotatable) {
+ return findAnnotationsByShortName(result, parent, name, true);
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/FileUtils.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/FileUtil.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/FileUtils.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/FileUtils.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,726 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.common.core.CommonCorePlugin;
+
+public class FileUtils {
+
+ public FileUtils() {}
+
+ public static String getEncoding(IFile f) {
+ String encoding = null;
+ if(f != null && f.exists() && f.isSynchronized(0)) try {
+ encoding = f.getCharset();
+ } catch (CoreException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ return encoding != null ? encoding : "8859_1"; //$NON-NLS-1$
+ }
+
+ public static String readFile(File f) {
+ if(!f.isFile()) return ""; //$NON-NLS-1$
+ ReadBytes bs = readBytes(f);
+ if(bs == null) return ""; //$NON-NLS-1$
+ String encoding = getEncoding(bs.bs);
+ if(encoding == null) return new String(bs.bs, 0, bs.length);
+ try {
+ return new String(bs.bs, 0, bs.length, encoding);
+ } catch (UnsupportedEncodingException e) {
+ return new String(bs.bs, 0, bs.length);
+ }
+ }
+
+ public static String readFileWithEncodingCheck(File f, String defaultEncoding) {
+ if(!f.isFile()) return ""; //$NON-NLS-1$
+ ReadBytes bs = readBytes(f);
+ if(bs == null) return ""; //$NON-NLS-1$
+ String encoding = getEncoding(bs.bs);
+ if(encoding == null) encoding = validateEncoding(defaultEncoding, null);
+ if(encoding == null) return new String(bs.bs, 0, bs.length);
+ try {
+ return new String(bs.bs, 0, bs.length, encoding);
+ } catch (UnsupportedEncodingException e) {
+ return new String(bs.bs, 0, bs.length);
+ }
+ }
+
+ public static ReadBytes readBytes(File f) {
+ if(!f.isFile()) return null;
+ BufferedInputStream br = null;
+ try {
+ FileInputStream fr = new FileInputStream(f);
+ br = new BufferedInputStream(fr);
+ int l = (int)f.length();
+ byte[] bs = new byte[l];
+ l = br.read(bs, 0, l);
+ br.close();
+ fr.close();
+ return new ReadBytes(bs, l);
+ } catch (IOException e) {
+ return null;
+ } finally {
+ if(br!=null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+ }
+ }
+
+ static class ReadBytes {
+ byte[] bs;
+ int length;
+
+ ReadBytes(byte[] bs, int l) {
+ this.bs = bs;
+ length = l;
+ }
+ }
+
+ public static String readFile(File f, String encoding) {
+ ReadBytes bs = readBytes(f);
+ if(bs == null) return null;
+ try {
+ return new String(bs.bs, 0, bs.length, encoding);
+ } catch (UnsupportedEncodingException e) {
+ return null;
+ }
+ }
+
+ public static boolean isTextFile(File f, int length) {
+ if(!f.isFile()) return false;
+ BufferedReader br = null;
+ try {
+ FileReader fr = new FileReader(f);
+ br = new BufferedReader(fr);
+ int l = (int)f.length();
+ if(l > length) l = length;
+ char[] cs = new char[l];
+ br.read(cs, 0, l);
+ br.close();
+ fr.close();
+ return isText(new String(cs));
+ } catch (IOException e) {
+ return false;
+ } finally {
+ if(br!=null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public static boolean isText(String body) {
+ if(body == null) return false;
+ int l = body.length();
+ for (int i = 0; i < l; i++) {
+ char c = body.charAt(i);
+ if(((int)c) < 32 && c != '\n' && c != '\r' && c != 't') return false;
+ }
+ return true;
+ }
+
+ // FIXME Size of string buffer should be set to size of file by default
+ // to avoid StringBuffer extension on each append
+ public static String readStream(InputStream is) {
+ StringBuffer sb = new StringBuffer(""); //$NON-NLS-1$
+ try {
+ byte[] b = new byte[4096];
+ while(true) {
+ int l = is.read(b, 0, b.length);
+ if(l < 0) break;
+ sb.append(new String(b, 0, l));
+ }
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ return sb.toString();
+ }
+
+ public static String readStream(IFile file) throws CoreException {
+ String content = null;
+ InputStream in = null;
+ try {
+ String charset = file.getCharset();
+ if(charset != null) {
+ charset = validateEncoding(charset, null);
+ }
+ in = file.getContents();
+ content = (charset == null) ? readStream(in) : readStream(in, charset);
+ } finally {
+ if(in!=null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+ return content;
+ }
+
+ public static String readStream(InputStream is, String charset) {
+ StringBuffer sb = new StringBuffer(""); //$NON-NLS-1$
+ try {
+ byte[] b = new byte[4096];
+ while(true) {
+ int l = is.read(b, 0, b.length);
+ if(l < 0) break;
+ sb.append(new String(b, 0, l, charset));
+ }
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+
+ return sb.toString();
+ }
+
+ public static void copyContent(IFile from, IFile to, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ InputStream is = null;
+ try {
+ is = from.getContents();
+ to.setContents(is, force, keepHistory, monitor);
+ } finally {
+ if(is!=null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+ }
+
+ public static boolean writeFile(File f, String value) {
+ return writeFileWithEncodingCheck(f, value, null);
+ }
+
+ public static boolean writeFileWithEncodingCheck(File f, String value, String defaultEncoding) {
+ if(value == null) return false;
+ String encoding = getEncoding(value);
+ if(encoding == null) encoding = validateEncoding(defaultEncoding, null);
+ if(value.startsWith("<?xml")) { //$NON-NLS-1$
+ String s = validateEncoding(encoding, "UTF-8"); //$NON-NLS-1$
+ if(encoding == null) {
+ encoding = s;
+ } else if(s == null || !s.equals(encoding)) {
+ return false;
+ }
+ }
+ if(encoding == null) return writeFileDefault(f, value);
+ return writeFile(f, value, encoding);
+ }
+
+ public static boolean writeFileDefault(File f, String value) {
+ try {
+ try {
+ if(f.isFile() && !isSameFile(f)) f.delete();
+ if(!f.exists()) f.createNewFile();
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError("Problem writing to file " + f, e); //$NON-NLS-1$
+ } catch (SecurityException e) {
+ CommonCorePlugin.getPluginLog().logError("Problem writing to file " + f, e); //$NON-NLS-1$
+ }
+ PrintWriter pw = new PrintWriter(new FileWriter(f));
+ pw.print(value);
+ pw.flush();
+ pw.close();
+ return true;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+
+ public static boolean copyFile(File source, File dest, boolean mkdirs) {
+ return copyFile(source, dest, mkdirs, true);
+ }
+
+ public static boolean copyFile(File source, File dest) {
+ return copyFile(source, dest, false, true);
+ }
+
+ public static boolean copyFile(File source, File dest, boolean mkdirs, boolean overwrite) {
+ if (mkdirs) dest.getParentFile().mkdirs();
+ if(!source.isFile()) return false;
+ if(dest.isFile() && !isSameFile(dest)) dest.delete();
+ if(dest.isFile() && !overwrite) return false;
+ if(!dest.exists())
+ try {
+ dest.createNewFile();
+ } catch (IOException e1) {
+ CommonCorePlugin.getPluginLog().logError(e1);
+ }
+ InputStream is = null;
+ OutputStream os = null;
+ try {
+ is = new BufferedInputStream(new FileInputStream(source), 16 * 1024);
+ os = new BufferedOutputStream(new FileOutputStream(dest), 16 * 1024);
+ copyStream(is, os);
+ return true;
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ return false;
+ } finally {
+ try {
+ if (is != null) is.close();
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ try {
+ if (os != null) os.close();
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+
+ public static boolean updateFile(File source, File dest, boolean mkdirs) {
+ if(!source.isFile()) return false;
+ if(dest.isFile() && (dest.lastModified()<source.lastModified())) {
+ dest.delete();
+ }
+ return copyFile(source, dest, mkdirs);
+ }
+
+ public static void copyStream(InputStream is, OutputStream os) throws IOException {
+ byte[] buffer = new byte[1<<14];
+ while (true) {
+ int r = is.read(buffer);
+ if (r > 0) {
+ os.write(buffer, 0, r);
+ } else if (r == -1) break;
+ }
+ os.flush();
+ }
+
+ public static void clear(File f) {
+ if (f.isDirectory()) {
+ File[] fs = f.listFiles();
+ for (int i = 0; i < fs.length; i++) {
+ remove(fs[i]);
+ }
+ }
+ }
+
+ public static void remove(File f) {
+ if (f.isFile()) {
+ f.delete();
+ } else if (f.isDirectory()) {
+ File[] fs = f.listFiles();
+ for (int i = 0; i < fs.length; i++) {
+ remove(fs[i]);
+ }
+ f.delete();
+ }
+ }
+
+ public static boolean isSameFile(File f) {
+ if(!f.exists()) return false;
+ String fn = f.getName();
+ try {
+ String cn = f.getCanonicalFile().getName();
+ return fn.equals(cn);
+ } catch (IOException e) {
+ return false;
+ }
+ }
+
+ public static void copyDir(File from, File to) {
+ copyDir(from, to, false);
+ }
+
+ public static void copyDir(File from, File to, boolean mkdirs) {
+ copyDir(from, to, mkdirs, true);
+ }
+
+ public static void copyDir(File from, File to, boolean mkdirs, boolean includeSubdirs) {
+ copyDir(from, to, includeSubdirs, mkdirs, false);
+ }
+
+ public static void copyDir(File from, boolean includeSubdirs, File to) {
+ copyDir(from, to, includeSubdirs, false, false);
+ }
+
+ public static void copyDir(File from, File to, boolean includeSubdirs, boolean mkdirs, boolean overwriteOnlyOlderFiles) {
+ copyDir(from, to, includeSubdirs, mkdirs, overwriteOnlyOlderFiles, null);
+ }
+
+ public static void copyDir(File from, File to, boolean includeSubdirs, boolean mkdirs, boolean overwriteOnlyOlderFiles, FileFilter filter) {
+ if(filter != null && !filter.accept(from)) return;
+ if (mkdirs) to.mkdirs();
+ if(from == null || !from.isDirectory() || !to.isDirectory()) return;
+ File[] fs = from.listFiles();
+ if(fs == null) return;
+ for (int i = 0; i < fs.length; i++) {
+ String n = fs[i].getName();
+ File c = new File(to, n);
+ if (fs[i].isDirectory() && !includeSubdirs) continue;
+ if(filter != null && !filter.accept(new File(from, n))) continue;
+
+ if(fs[i].isDirectory()) {
+ c.mkdirs();
+ copyDir(fs[i], c, includeSubdirs, mkdirs, overwriteOnlyOlderFiles, filter);
+ } else if (overwriteOnlyOlderFiles && fs[i].isFile() && c.isFile()) {
+ copyFile(fs[i], c, false, c.lastModified() < fs[i].lastModified());
+ } else {
+ copyFile(fs[i], c);
+ }
+ }
+ }
+
+ public static void unjar(File dest, String jar) throws IOException {
+ dest.mkdirs();
+ JarFile jf = new JarFile(jar);
+ try {
+ Enumeration es = jf.entries();
+ while(es.hasMoreElements()) {
+ JarEntry je = (JarEntry)es.nextElement();
+ String n = je.getName();
+ File f = new File(dest, n);
+ if (je.isDirectory()) {
+ f.mkdirs();
+ } else {
+ if (f.exists()) {
+ f.delete();
+ } else {
+ f.getParentFile().mkdirs();
+ }
+ InputStream is = jf.getInputStream(je);
+ FileOutputStream os = new FileOutputStream(f);
+ try {
+ copyStream(is, os);
+ } finally {
+ os.close();
+ }
+ }
+ long time = je.getTime();
+ if (time != -1) f.setLastModified(time);
+ }
+ } finally {
+ jf.close();
+ }
+ }
+
+ public static void unjar(File dest, InputStream is) throws IOException {
+ dest.mkdirs();
+ JarInputStream jis = new JarInputStream(is);
+ try {
+ while(true) {
+ JarEntry je = jis.getNextJarEntry();
+ if (je == null) break;
+ String n = je.getName();
+ File f = new File(dest, n);
+ if (je.isDirectory()) {
+ f.mkdirs();
+ } else {
+ if (f.exists()) {
+ f.delete();
+ } else {
+ f.getParentFile().mkdirs();
+ }
+ FileOutputStream os = new FileOutputStream(f);
+ try {
+ copyStream(jis, os);
+ } finally {
+ os.close();
+ }
+ }
+ long time = je.getTime();
+ if (time != -1) f.setLastModified(time);
+ }
+ } finally {
+ jis.close();
+ }
+ }
+
+ public static void jar(File[] fs, String path) throws IOException {
+ jar(fs, path, null);
+ }
+
+ public static void jar(File[] fs, String path, Manifest mf) throws IOException {
+ File f = new File(path);
+ FileOutputStream fos = new FileOutputStream(f);
+ JarOutputStream jos = mf == null ? new JarOutputStream(fos) : new JarOutputStream(fos, mf);
+ try {
+ for (int i = 0; i < fs.length; i++) add(fs[i].getParentFile(), fs[i], jos);
+ } finally {
+ jos.close();
+ fos.close();
+ }
+ }
+
+ public static void add(File root, File f, JarOutputStream jos) throws IOException {
+ int l = root.getAbsolutePath().length();
+ String en = f.getAbsolutePath().substring(l + 1).replace('\\', '/');
+ add(f, en, jos);
+ }
+
+ public static void add(File f, String name, JarOutputStream jos) throws IOException {
+ String en = name;
+ if(f.isDirectory()) en += "/"; //$NON-NLS-1$
+ JarEntry entry = (en.endsWith("/")) ? null : new JarEntry(en); //$NON-NLS-1$
+ if(f.isDirectory()) {
+ if("/".equals(en)) en = ""; //$NON-NLS-1$ //$NON-NLS-2$
+ File[] fs = f.listFiles();
+ if(fs != null) for (int i = 0; i < fs.length; i++)
+ add(fs[i], en + fs[i].getName(), jos);
+ } else {
+ try {
+ jos.putNextEntry(entry);
+ } catch (IOException e) {
+ return;
+ }
+ FileInputStream is = new FileInputStream(f);
+ byte[] b = new byte[1024];
+ int q = 0;
+ while((q = is.available()) > 0) {
+ if(q > 1024) q = 1024;
+ q = is.read(b, 0, q);
+ jos.write(b, 0, q);
+ }
+ is.close();
+ }
+ if(entry != null) jos.closeEntry();
+ }
+
+ public static void copy(InputStream f, OutputStream t) throws IOException {
+ try {
+ byte[] b = new byte[1024];
+ int q = 0;
+ while((q = f.read(b, 0, b.length)) > 0) t.write(b, 0, q);
+ } finally {
+ f.close();
+ t.close();
+ }
+ }
+
+ public static void unzip(File dest, String jar) throws IOException {
+ dest.mkdirs();
+ ZipFile zf = new ZipFile(jar);
+ try {
+ Enumeration es = zf.entries();
+ while(es.hasMoreElements()) {
+ ZipEntry je = (ZipEntry)es.nextElement();
+ String n = je.getName();
+ File f = new File(dest, n);
+ if (je.isDirectory()) {
+ f.mkdirs();
+ } else {
+ if (f.exists()) {
+ f.delete();
+ } else {
+ f.getParentFile().mkdirs();
+ }
+ InputStream is = zf.getInputStream(je);
+ FileOutputStream os = new FileOutputStream(f);
+ try {
+ copyStream(is, os);
+ } finally {
+ os.close();
+ }
+ }
+ long time = je.getTime();
+ if (time != -1) f.setLastModified(time);
+ }
+ } finally {
+ zf.close();
+ }
+ }
+
+ public static String fileURLToFilePath(String url) {
+ if(url == null) return null;
+ String resultUrl = url.replace('\\', '/');
+/// if(!url.startsWith("file:/")) return url;
+ if(!resultUrl.startsWith("file:")) return resultUrl; //$NON-NLS-1$
+ int iLast = resultUrl.lastIndexOf(':'), iFirst = resultUrl.indexOf(':');
+ return (iLast == iFirst) ? resultUrl.substring(5) : resultUrl.substring(iLast - 1);
+ }
+
+ //// Relative path
+
+ public static String getRelativePath(String rootpath, String path) {
+ String[] r = tokenizePath(rootpath);
+ String[] p = tokenizePath(path);
+ if(r.length == 0 || p.length == 0 || !r[0].equalsIgnoreCase(p[0])) return null;
+ int i = 0;
+ while(i < r.length && i < p.length && r[i].equalsIgnoreCase(p[i])) ++i;
+ StringBuffer sb = new StringBuffer();
+ for (int k = i; k < r.length; k++) sb.append("/.."); //$NON-NLS-1$
+ for (int k = i; k < p.length; k++) sb.append("/").append(p[k]); //$NON-NLS-1$
+ return sb.toString();
+ }
+
+ private static String[] tokenizePath(String path) {
+ String tokenizedPath = path.replace('\\', '/');
+ StringTokenizer st = new StringTokenizer(tokenizedPath, "/"); //$NON-NLS-1$
+ ArrayList l = new ArrayList();
+ while(st.hasMoreTokens()) {
+ String t = st.nextToken();
+ if(t.isEmpty() || ".".equals(t)) continue; //$NON-NLS-1$
+ if("..".equals(t)) { //$NON-NLS-1$
+ if(!l.isEmpty()) l.remove(l.size() - 1);
+ continue;
+ }
+ l.add(t);
+ }
+ return (String[])l.toArray(new String[l.size()]);
+ }
+
+ public static boolean writeFile(File f, String value, String encoding) {
+ try {
+ try {
+ if(f.isFile() && !isSameFile(f)) f.delete();
+ if(!f.exists()) {
+ f.getParentFile().mkdirs();
+ f.createNewFile();
+ }
+ } catch (IOException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ FileOutputStream fs = new FileOutputStream(f);
+ OutputStreamWriter osw = new OutputStreamWriter(fs, encoding);
+ PrintWriter pw = new PrintWriter(osw);
+ pw.print(value);
+ pw.flush();
+ pw.close();
+ return true;
+ } catch (FileNotFoundException e) {
+ //ignore
+ return writeFileDefault(f, value);
+ } catch (UnsupportedEncodingException e) {
+ //ignore
+ return writeFileDefault(f, value);
+ }
+ }
+
+
+ public static String getEncoding(String s) {
+ if(s == null) return null;
+ if(s.startsWith("<?xml")) { //$NON-NLS-1$
+ int i = s.indexOf("encoding="); //$NON-NLS-1$
+ if(i < 0) return null;
+ i += "encoding=".length() + 1; //$NON-NLS-1$
+ int j = s.indexOf('\"', i);
+ if(j < 0) return null;
+ return s.substring(i, j);
+ }
+ return null;
+ }
+
+ static Set validEncodings = new HashSet();
+ static Set invalidEncodings = new HashSet();
+
+ public static String validateEncoding(String encoding, String defaultEncoding) {
+ if(encoding == null || encoding.equals(defaultEncoding)) return defaultEncoding;
+ if(validEncodings.contains(encoding)) return encoding;
+ if(invalidEncodings.contains(encoding)) return defaultEncoding;
+ try {
+ if(defaultEncoding != null && defaultEncoding.equals("UTF-16")) { //$NON-NLS-1$
+ new String(XML_16, 0, XML_16.length, encoding);
+ } else {
+ new String(XML_8, 0, XML_8.length, encoding);
+ }
+ validEncodings.add(encoding);
+ return encoding;
+ } catch (UnsupportedEncodingException e) {
+ invalidEncodings.add(encoding);
+ return defaultEncoding;
+ }
+ }
+
+ static byte[] XML_8 = {(byte)'<',(byte)'?',(byte)'x',(byte)'m',(byte)'l'};
+ static byte[] XML_16 = {(byte)-2,(byte)-1,(byte)0,(byte)60,(byte)0,(byte)63,(byte)0,(byte)120,(byte)0,(byte)109,(byte)0,(byte)108};
+
+ public static String getEncoding(byte[] bs) {
+ if(bs.length < 20) return null;
+ if(startsWith(bs, XML_8)) {
+ int i = getIndex(bs, (byte)'?', 5);
+ if(i < 0) return "UTF-8"; //$NON-NLS-1$
+ String encoding = getEncoding(new String(bs, 0, i));
+ return validateEncoding(encoding, "UTF-8"); //$NON-NLS-1$
+ } else if(startsWith(bs, XML_16)) {
+ int i = getIndex(bs, (byte)'?', XML_16.length);
+ if(i < 0) return "UTF-16"; //$NON-NLS-1$
+ try {
+ String encoding = getEncoding(new String(bs, 0, i, "UTF-16")); //$NON-NLS-1$
+ return validateEncoding(encoding, "UTF-16"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ static boolean startsWith(byte[] bs, byte[] prefix) {
+ for (int i = 0; i < prefix.length; i++) {
+ if(bs[i] != prefix[i]) return false;
+ }
+ return true;
+ }
+
+ static int getIndex(byte[] bs, byte b, int offset) {
+ for (int i = offset; i < bs.length; i++) {
+ if(bs[i] == b) return i;
+ }
+ return -1;
+ }
+}
\ No newline at end of file
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/HttpUtil.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/HttpUtil.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/HttpUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/HttpUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.net.proxy.IProxyService;
+import org.jboss.tools.common.core.CommonCorePlugin;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * HTTP Utilities
+ * @author Alexey Kazakov
+ */
+public class HttpUtil {
+
+ private static IProxyService proxyService;
+
+ /**
+ * @param url
+ * @return InputStream of responce to http GET request. Use proxy settings from preferences.
+ * @throws Exception
+ */
+ public static InputStream getInputStreamFromUrlByGetMethod(String url) throws IOException {
+ InputStream is = executeGetMethod(url).getResponseBodyAsStream();
+ return is;
+ }
+
+ /**
+ * @param url
+ * @return InputStream of responce to http GET request. Use proxy settings from preferences.
+ * @throws Exception
+ */
+ public static InputStream getInputStreamFromUrlByGetMethod(String url, IProxyService proxyService) throws IOException {
+ InputStream is = executeGetMethod(url, proxyService).getResponseBodyAsStream();
+ return is;
+ }
+
+ /**
+ * @param url
+ * @param proxyService
+ * @return Status code of responce to http GET request. Use given proxy settings.
+ * @throws Exception
+ */
+ public static int getStatusCodeFromUrlByGetMethod(String url, IProxyService proxyService) throws IOException {
+ int code = executeGetMethod(url, proxyService).getStatusCode();
+ return code;
+ }
+
+ /**
+ * @param url
+ * @return Status code of responce to http GET request. Use proxy settings from preferences.
+ * @throws Exception
+ */
+ public static int getStatusCodeFromUrlByGetMethod(String url) throws IOException {
+ int code = executeGetMethod(url).getStatusCode();
+ return code;
+ }
+
+ /**
+ * @param url
+ * @return InputStream of responce to http POST request. Use proxy settings from preferences.
+ * @throws Exception
+ */
+ public static InputStream getInputStreamFromUrlByPostMethod(String url) throws IOException {
+ InputStream is = executePostMethod(url).getResponseBodyAsStream();
+ return is;
+ }
+
+ /**
+ * @param url
+ * @param proxyService
+ * @return Status code of responce to http POST request. Use given proxy settings.
+ * @throws Exception
+ */
+ public static int getStatusCodeFromUrlByPostMethod(String url, IProxyService proxyService) throws IOException {
+ int code = executePostMethod(url, proxyService).getStatusCode();
+ return code;
+ }
+
+ /**
+ * @param url
+ * @return Status code of responce to http POST request. Use proxy settings from preferences.
+ * @throws Exception
+ */
+ public static int getStatusCodeFromUrlByPostMethod(String url) throws IOException {
+ int code = executePostMethod(url).getStatusCode();
+ return code;
+ }
+
+ private static GetMethod executeGetMethod(String url) throws IOException {
+ IProxyService proxyService = getProxyService();
+ return executeGetMethod(url, proxyService);
+ }
+
+ private static PostMethod executePostMethod(String url) throws IOException {
+ IProxyService proxyService = getProxyService();
+ return executePostMethod(url, proxyService);
+ }
+
+ /**
+ * @param url
+ * @param proxyService
+ * @return
+ * @throws Exception
+ */
+ public static GetMethod executeGetMethod(String url, IProxyService proxyService) throws IOException {
+ GetMethod httpGet = new GetMethod(url);
+ HttpClient httpClient = createHttpClient(url, proxyService);
+ httpClient.executeMethod(httpGet);
+ return httpGet;
+ }
+
+ private static PostMethod executePostMethod(String url, IProxyService proxyService) throws IOException {
+ PostMethod httpPost = new PostMethod(url);
+ HttpClient httpClient = createHttpClient(url, proxyService);
+ httpClient.executeMethod(httpPost);
+ return httpPost;
+ }
+
+ /**
+ * @param url
+ * @return HttpClient with internet proxy settings;
+ * @throws Exception
+ */
+ public static HttpClient createHttpClient(String url) throws IOException {
+ return createHttpClient(url, getProxyService());
+ }
+
+ private static HttpClient createHttpClient(String url, IProxyService proxyService) throws IOException {
+ HttpClient httpClient = new HttpClient();
+
+ if(proxyService.isProxiesEnabled()) {
+ IProxyData[] proxyData = proxyService.getProxyData();
+ URL netUrl = new URL(url);
+ String hostName = netUrl.getHost();
+ String[] nonProxiedHosts = proxyService.getNonProxiedHosts();
+ boolean nonProxiedHost = false;
+ for (int i = 0; i < nonProxiedHosts.length; i++) {
+ String nonProxiedHostName = nonProxiedHosts[i];
+ if(nonProxiedHostName.equalsIgnoreCase(hostName)) {
+ nonProxiedHost = true;
+ break;
+ }
+ }
+ if(!nonProxiedHost) {
+ for (int i = 0; i < proxyData.length; i++) {
+ IProxyData proxy = proxyData[i];
+ if(IProxyData.HTTP_PROXY_TYPE.equals(proxy.getType())) {
+ String proxyHostName = proxy.getHost();
+ if(proxyHostName==null) {
+ break;
+ }
+ int portNumber = proxy.getPort();
+ if(portNumber==-1) {
+ portNumber = 80;
+ }
+ httpClient.getHostConfiguration().setProxy(proxyHostName, portNumber);
+ if(proxy.isRequiresAuthentication()) {
+ String userName = proxy.getUserId();
+ if(userName!=null) {
+ String password = proxy.getPassword();
+ httpClient.getState().setProxyCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(userName, password));
+ }
+ }
+ break; // Use HTTP proxy only.
+ }
+ }
+ }
+ }
+
+ httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
+
+ return httpClient;
+ }
+
+ private static IProxyService getProxyService() {
+ if(proxyService==null) {
+ BundleContext bundleContext = CommonCorePlugin.getInstance().getBundle().getBundleContext();
+ ServiceReference serviceReference = bundleContext.getServiceReference(IProxyService.class.getName());
+ proxyService = (IProxyService)bundleContext.getService(serviceReference);
+ }
+ return proxyService;
+ }
+}
\ No newline at end of file
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/StringUtil.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.util;
+
+/**
+ * Miscellaneous String utility functions
+ *
+ * @author Victor V. Rubezhny
+ */
+public class StringUtil {
+/**
+ * Cuts of the starting and ending quotes from a given text value
+ *
+ * @param Quoted text value
+ * @return Non-quoted text value
+ */
+ public static String trimQuotes(String value) {
+ if(value == null)
+ return null;
+
+ if(value.startsWith("'") || value.startsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(1);
+ }
+
+ if(value.endsWith("'") || value.endsWith("\"")) { //$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(0, value.length() - 1);
+ }
+ return value;
+ }
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java (from rev 43123, trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/util/TypeResolutionCache.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * Copyright (c) 2011 - 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IImportDeclaration;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.common.core.CommonCorePlugin;
+
+public class TypeResolutionCache {
+ private static TypeResolutionCache instance = new TypeResolutionCache();
+
+ public static TypeResolutionCache getInstance() {
+ return instance;
+ }
+
+ static class Resolved {
+ IType type;
+ Map<String, String> types = new Hashtable<String, String>();
+ List<String> classImports = new ArrayList<String>();
+ List<String> packageImports = new ArrayList<String>();
+ Resolved(IType type) {
+ this.type = type;
+ readImports();
+ }
+
+ void setType(IType type) {
+ this.type = type;
+ types.clear();
+
+ readImports();
+ }
+
+ void readImports() {
+ ICompilationUnit unit = type.getCompilationUnit();
+ if(unit == null) return;
+ IImportDeclaration[] ds = null;
+ try {
+ ds = unit.getImports();
+ } catch (JavaModelException e) {
+ CommonCorePlugin.getDefault().logError(e);
+ ds = new IImportDeclaration[0];
+ }
+ IResource r = unit.getResource();
+
+ if(r instanceof IFile && r.exists()) {
+ List<String> newClassImports = new ArrayList<String>();
+ List<String> newPackageImports = new ArrayList<String>();
+ //add local package
+ newPackageImports.add(type.getPackageFragment().getElementName() + "."); //$NON-NLS-1$
+ for (IImportDeclaration d: ds) {
+ String q = d.getElementName();
+ if(q.endsWith(".*")) { //$NON-NLS-1$
+ newPackageImports.add( q = q.substring(0, q.length() - 1));
+ } else {
+ newClassImports.add(q);
+ }
+ }
+ classImports = newClassImports;
+ packageImports = newPackageImports;
+ }
+ }
+
+ public String resolveInImports(String typeName) {
+ if(typeName.indexOf(".") >= 0) { //$NON-NLS-1$
+ try {
+ IType q = EclipseJavaUtil.findType(type.getJavaProject(), typeName);
+ if(q != null) {
+ types.put(typeName, typeName);
+ return typeName;
+ }
+ } catch (JavaModelException e) {
+ CommonCorePlugin.getDefault().logError(e);
+ }
+ //too difficult
+ return null;
+ }
+ for (String imp: classImports) {
+ if(imp.endsWith("." + typeName)) { //$NON-NLS-1$
+ types.put(typeName, imp);
+ return imp;
+ }
+ }
+ for (String imp: packageImports) {
+ String result = imp + typeName;
+ try {
+ IType q = EclipseJavaUtil.findType(type.getJavaProject(), result);
+ if(q != null) {
+ types.put(typeName, result);
+ return result;
+ }
+ } catch (JavaModelException e) {
+ CommonCorePlugin.getDefault().logError(e);
+ }
+ }
+ String pr = "java.lang." + typeName; //$NON-NLS-1$
+ if(primitive.contains(pr)) {
+ types.put(typeName, pr);
+ return pr;
+ }
+
+ if(type.getTypeParameter(typeName).exists()) {
+ types.put(typeName, typeName);
+ return typeName;
+ }
+ return null;
+ }
+ }
+
+ static Set<String> primitive = new HashSet<String>();
+ static {
+ primitive.add("void"); //$NON-NLS-1$
+ primitive.add("int"); //$NON-NLS-1$
+ primitive.add("char"); //$NON-NLS-1$
+ primitive.add("boolean"); //$NON-NLS-1$
+ primitive.add("long"); //$NON-NLS-1$
+ primitive.add("short"); //$NON-NLS-1$
+ primitive.add("double"); //$NON-NLS-1$
+ primitive.add("float"); //$NON-NLS-1$
+ primitive.add("java.lang.Object"); //$NON-NLS-1$
+ primitive.add("java.lang.Number"); //$NON-NLS-1$
+ primitive.add("java.lang.Integer"); //$NON-NLS-1$
+ primitive.add("java.lang.Character"); //$NON-NLS-1$
+ primitive.add("java.lang.Boolean"); //$NON-NLS-1$
+ primitive.add("java.lang.Long"); //$NON-NLS-1$
+ primitive.add("java.lang.Short"); //$NON-NLS-1$
+ primitive.add("java.lang.Double"); //$NON-NLS-1$
+ primitive.add("java.lang.Float"); //$NON-NLS-1$
+ primitive.add("java.lang.String"); //$NON-NLS-1$
+ primitive.add("java.lang.StringBuffer"); //$NON-NLS-1$
+ primitive.add("java.lang.Class"); //$NON-NLS-1$
+ primitive.add("java.lang.Deprecated"); //$NON-NLS-1$
+ primitive.add("java.lang.SuppressWarnings"); //$NON-NLS-1$
+ primitive.add("java.lang.Throwable"); //$NON-NLS-1$
+ primitive.add("java.lang.Exception"); //$NON-NLS-1$
+ primitive.add("java.lang.RuntimeException"); //$NON-NLS-1$
+ primitive.add("java.lang.Override"); //$NON-NLS-1$
+ }
+ static String NULL = ";;;"; //$NON-NLS-1$
+ Map<String,Resolved> resolved = new Hashtable<String, Resolved>();
+
+ private TypeResolutionCache() {}
+
+ public String resolveType(IType type, String typeName) {
+ if(type == null) return null;
+ if(type.isBinary() || typeName == null || primitive.contains(typeName)) return typeName;
+
+ String n = getKey(type);
+ Resolved r = resolved.get(n);
+ if(r == null) {
+ r = new Resolved(type);
+ resolved.put(n, r);
+ } else if(r.type != type) {
+ r.setType(type);
+ }
+
+ String result = r.types.get(typeName);
+ if(result != null) {
+ return (result == NULL) ? null : result;
+ }
+
+ result = r.resolveInImports(typeName);
+ if(result != null) {
+ return result;
+ }
+
+ result = __resolveType(type, typeName);
+
+// System.out.println(typeName + "---" + result);
+
+ r.types.put(typeName, result == null ? NULL : result);
+ return result;
+
+ }
+
+ public void clean() {
+ resolved = new Hashtable<String, Resolved>();
+ }
+
+ private String __resolveType(IType type, String typeName) {
+ try {
+ String resolvedArray[][] = type.resolveType(typeName);
+// resolvedArray == null for primitive types
+ if(resolvedArray == null) return typeName;
+ typeName = ""; //$NON-NLS-1$
+ for (int i = 0; i < resolvedArray[0].length; i++)
+ typeName += (!"".equals(typeName) ? "." : "") + resolvedArray[0][i]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return typeName;
+ } catch (JavaModelException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ } catch (IllegalArgumentException e) {
+ CommonCorePlugin.getPluginLog().logError(e);
+ }
+ return null;
+ }
+
+ private String getKey(IType type) {
+ String n = type.getFullyQualifiedName();
+ IJavaProject jp = type.getJavaProject();
+ if(jp == null) return n;
+ IProject p = jp.getProject();
+ if(p == null || !p.isAccessible()) return n;
+ return p.getName() + ":" + n; //$NON-NLS-1$
+ }
+
+}
\ No newline at end of file
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/web/WebUtils.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/web/WebUtils.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/web/WebUtils.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -30,7 +30,7 @@
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
public class WebUtils {
@@ -87,7 +87,7 @@
try {
facetedProject = ProjectFacetsManager.create(project);
} catch (CoreException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
}
if(facetedProject!=null && facetedProject.getProjectFacetVersion(IJ2EEFacetConstants.DYNAMIC_WEB_FACET)!=null) {
IVirtualComponent component = ComponentCore.createComponent(project);
@@ -137,9 +137,9 @@
// Not available in this WTP version, let's ignore it
WTP_3_3_0 = true;
} catch (IllegalArgumentException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
} catch (IllegalAccessException e) {
- CommonPlugin.getDefault().logError(e);
+ CommonCorePlugin.getDefault().logError(e);
} catch (InvocationTargetException e) {
// Not available in this WTP version, let's ignore it
WTP_3_3_0 = true;
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/DtdResolver.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/DtdResolver.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/DtdResolver.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -23,7 +23,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.jboss.tools.common.util.HttpUtil;
import org.osgi.framework.Bundle;
import org.xml.sax.EntityResolver;
@@ -72,7 +72,7 @@
if(location == null) {
if(systemId != null && !unfound.contains(systemId)) {
unfound.add(systemId);
-// CommonPlugin.getPluginLog().logInfo("Cannot find locally: " //$NON-NLS-1$
+// CommonCorePlugin.getPluginLog().logInfo("Cannot find locally: " //$NON-NLS-1$
// + "Public ID " + publicId //$NON-NLS-1$
// + " System ID " + systemId); //$NON-NLS-1$
}
@@ -87,7 +87,7 @@
return url.openStream();
}
} catch(FileNotFoundException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
}
}
@@ -109,9 +109,9 @@
is = HttpUtil.getInputStreamFromUrlByGetMethod(systemId);
}
} catch (MalformedURLException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
} catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
}
}
return is;
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/SAXValidator.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SAXValidator.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/SAXValidator.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -22,16 +22,15 @@
import org.apache.xerces.util.XMLCatalogResolver;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.eclipse.core.runtime.Platform;
-import org.jboss.tools.common.CommonPlugin;
-import org.jboss.tools.common.Messages;
-import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.common.core.CommonCorePlugin;
+import org.jboss.tools.common.core.Messages;
+import org.jboss.tools.common.util.FileUtils;
import org.osgi.framework.Bundle;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author eskimo(dgolovin(a)exadel.com)
@@ -73,9 +72,9 @@
try {
parserInstance.setProperty(ENTITY_RESOLVER_PROPERTY_ID, new XMLEntityResolverImpl());
} catch (SAXNotRecognizedException e1) {
- CommonPlugin.getPluginLog().logError( e1.getMessage()+"", e1); //$NON-NLS-1$
+ CommonCorePlugin.getPluginLog().logError( e1.getMessage()+"", e1); //$NON-NLS-1$
} catch (SAXNotSupportedException e1) {
- CommonPlugin.getPluginLog().logError( e1.getMessage()+"", e1); //$NON-NLS-1$
+ CommonCorePlugin.getPluginLog().logError( e1.getMessage()+"", e1); //$NON-NLS-1$
}
parserInstance.setContentHandler(handler);
@@ -94,7 +93,7 @@
parser.setFeature(name, value);
} catch (SAXException e) {
// TODO - Move to NLS bundle
- CommonPlugin.getPluginLog().logError("warning: Parser does not support feature ("+name+")", e); //$NON-NLS-1$ //$NON-NLS-2$
+ CommonCorePlugin.getPluginLog().logError("warning: Parser does not support feature ("+name+")", e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -108,7 +107,7 @@
try {
parser.setProperty(name, value);
} catch (SAXException e) {
- CommonPlugin.getPluginLog().logError("warning: Parser does not support feature ("+name+")", e); //$NON-NLS-1$ //$NON-NLS-2$
+ CommonCorePlugin.getPluginLog().logError("warning: Parser does not support feature ("+name+")", e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -159,7 +158,7 @@
*/
String getCatalog() {
- Bundle b = Platform.getBundle(CommonPlugin.PLUGIN_ID);
+ Bundle b = Platform.getBundle(CommonCorePlugin.PLUGIN_ID);
String location = Platform.getStateLocation(b).toString().replace('\\', '/');
if(!location.endsWith("/")) { //$NON-NLS-1$
location += "/"; //$NON-NLS-1$
@@ -174,20 +173,20 @@
}
urlString += "schemas"; //$NON-NLS-1$
} catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
}
File f1 = new File(url.getFile() + "/schemas/catalog.xml"); //$NON-NLS-1$
File f2 = new File(location + "schemas/catalog.xml"); //$NON-NLS-1$
if(f2.exists()) {
return "file:///" + location + "schemas/catalog.xml"; //$NON-NLS-1$ //$NON-NLS-2$
}
- FileUtil.copyDir(f1.getParentFile(), f2.getParentFile(), true);
- String text = FileUtil.readFile(f2);
+ FileUtils.copyDir(f1.getParentFile(), f2.getParentFile(), true);
+ String text = FileUtils.readFile(f2);
while(text.indexOf("%install%") >= 0) { //$NON-NLS-1$
int i = text.indexOf("%install%"); //$NON-NLS-1$
text = text.substring(0, i) + urlString + text.substring(i + 9);
}
- FileUtil.writeFile(f2, text);
+ FileUtils.writeFile(f2, text);
return "file:///" + location + "schemas/catalog.xml"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLEntityResolver.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLEntityResolver.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLEntityResolver.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -10,7 +10,7 @@
import java.util.Properties;
import org.eclipse.core.runtime.FileLocator;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -104,7 +104,7 @@
source = new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes())); //$NON-NLS-1$
}
if(source == null) {
- CommonPlugin.getDefault().logError("WARNING: Cannot resolve entity " + systemId); //$NON-NLS-1$
+ CommonCorePlugin.getDefault().logError("WARNING: Cannot resolve entity " + systemId); //$NON-NLS-1$
}
// TODO study if we can always return non-null value.
return source;
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLEntityResolverImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLEntityResolverImpl.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLEntityResolverImpl.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -19,7 +19,7 @@
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLInputSource;
-import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.core.CommonCorePlugin;
import org.xml.sax.SAXException;
@@ -52,7 +52,7 @@
result = new XMLInputSource(rid.getPublicId(), systemId, rid.getBaseSystemId(), is, null);
}
} catch (SAXException e) {
- CommonPlugin.getPluginLog().logError( "Exception publicId=" + publicId + " systemId=" + systemId + " exception=" + e.getClass().getName() + ":" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CommonCorePlugin.getPluginLog().logError( "Exception publicId=" + publicId + " systemId=" + systemId + " exception=" + e.getClass().getName() + ":" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
return result;
Modified: trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLUtilities.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLUtilities.java 2012-08-21 09:59:44 UTC (rev 43123)
+++ trunk/common/plugins/org.jboss.tools.common.core/src/org/jboss/tools/common/xml/XMLUtilities.java 2012-08-25 06:08:31 UTC (rev 43232)
@@ -30,8 +30,8 @@
import org.apache.xml.serialize.Method;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
-import org.jboss.tools.common.CommonPlugin;
-import org.jboss.tools.common.Messages;
+import org.jboss.tools.common.core.CommonCorePlugin;
+import org.jboss.tools.common.core.Messages;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
@@ -136,7 +136,7 @@
d.setErrorHandler(new ErrorHandlerImpl());
return d;
} catch (ParserConfigurationException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
}
return null;
}
@@ -196,18 +196,18 @@
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(fr);
return getElement(inSource, resolver);
} catch (FileNotFoundException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
} catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
} catch (SAXException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
} finally {
try {
if (fr != null) {
fr.close();
}
} catch (IOException e) {
- CommonPlugin.getPluginLog().logError(e);
+ CommonCorePlugin.getPluginLog().logError(e);
}
}
return null;
Modified: trunk/common/plugins/pom.xml
===================================================================
--- trunk/common/plugins/pom.xml 2012-08-25 00:27:50 UTC (rev 43231)
+++ trunk/common/plugins/pom.xml 2012-08-25 06:08:31 UTC (rev 43232)
@@ -12,6 +12,7 @@
</parent>
<packaging>pom</packaging>
<modules>
+ <module>org.jboss.tools.common.core</module>
<module>org.jboss.tools.common</module>
<module>org.jboss.tools.common.el.core</module>
<module>org.jboss.tools.common.el.ui</module>
12 years, 4 months
JBoss Tools SVN: r43231 - trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2012-08-24 20:27:50 -0400 (Fri, 24 Aug 2012)
New Revision: 43231
Modified:
trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/CommonValidationPlugin.java
Log:
https://issues.jboss.org/browse/JBIDE-12480 "startup class must implement org.eclipse.ui.IStartup" message in ErrorLog for org.jboss.tools.common.validation plugin
Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/CommonValidationPlugin.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/CommonValidationPlugin.java 2012-08-25 00:25:47 UTC (rev 43230)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/CommonValidationPlugin.java 2012-08-25 00:27:50 UTC (rev 43231)
@@ -15,7 +15,10 @@
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IStartup;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.log.BaseUIPlugin;
import org.jboss.tools.common.validation.java.JavaEditorTracker;
import org.osgi.framework.BundleContext;
@@ -23,7 +26,7 @@
/**
* @author Alexey Kazakov
*/
-public class CommonValidationPlugin extends BaseUIPlugin {
+public class CommonValidationPlugin extends BaseUIPlugin implements IStartup {
public static final String PLUGIN_ID = "org.jboss.tools.common.validation"; //$NON-NLS-1$
protected static CommonValidationPlugin plugin;
@@ -73,10 +76,18 @@
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- JavaEditorTracker.getInstance();
- }
- });
}
+
+ @Override
+ public void earlyStartup() {
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ workbench.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window != null) {
+ JavaEditorTracker.getInstance();
+ }
+ }
+ });
+ }
}
\ No newline at end of file
12 years, 4 months
JBoss Tools SVN: r43230 - trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2012-08-24 20:25:47 -0400 (Fri, 24 Aug 2012)
New Revision: 43230
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java
Log:
removed System.out.println()
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java 2012-08-24 21:51:12 UTC (rev 43229)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/TypeResolutionCache.java 2012-08-25 00:25:47 UTC (rev 43230)
@@ -187,7 +187,7 @@
result = __resolveType(type, typeName);
- System.out.println(typeName + "---" + result);
+// System.out.println(typeName + "---" + result);
r.types.put(typeName, result == null ? NULL : result);
return result;
12 years, 4 months