Author: akazakov
Date: 2009-11-09 14:11:05 -0500 (Mon, 09 Nov 2009)
New Revision: 18509
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/propertieseditor/bundlemodel/BundleModel.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ELReference.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamRefactorContributionFactory.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/view/SeamComponentsViewTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5179
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -12,35 +12,60 @@
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
-import org.eclipse.core.resources.*;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+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.Path;
import org.eclipse.core.runtime.Plugin;
-import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModelMarker;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
-import org.osgi.framework.Bundle;
-
import org.jboss.tools.common.meta.action.XActionInvoker;
-import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelConstants;
+import org.jboss.tools.common.model.XModelFactory;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelObjectConstants;
import org.jboss.tools.common.model.filesystems.FilePathHelper;
import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
import org.jboss.tools.common.model.filesystems.XFileObject;
-import org.jboss.tools.common.model.filesystems.impl.*;
-import org.jboss.tools.common.model.icons.impl.*;
+import org.jboss.tools.common.model.filesystems.impl.FileSystemImpl;
+import org.jboss.tools.common.model.filesystems.impl.FileSystemsImpl;
+import org.jboss.tools.common.model.filesystems.impl.JarSystemImpl;
+import org.jboss.tools.common.model.icons.impl.XModelObjectIcon;
import org.jboss.tools.common.model.impl.XModelObjectImpl;
import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.project.ModelNature;
import org.jboss.tools.common.model.project.ModelNatureExtension;
+import org.jboss.tools.common.util.FileUtil;
+import org.osgi.framework.Bundle;
public class EclipseResourceUtil {
@@ -962,4 +987,22 @@
return path.endsWith(".jar") || path.endsWith(".zip");
//$NON-NLS-1$ //$NON-NLS-2$
}
-}
+ public static String getFileContent(IFile file) {
+ InputStream is = null;
+ try {
+ is = file.getContents();
+ return FileUtil.readStream(is);
+ } catch (CoreException e) {
+ ModelPlugin.getPluginLog().logError(e);
+ return null;
+ } finally {
+ if(is!=null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/propertieseditor/bundlemodel/BundleModel.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/propertieseditor/bundlemodel/BundleModel.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/propertieseditor/bundlemodel/BundleModel.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -162,8 +162,9 @@
ArrayList<String> keys = new ArrayList<String>();
ArrayList<String> values = new ArrayList<String>();
Properties p = new Properties();
+ InputStream s = null;
try {
- InputStream s = file.getContents();
+ s = file.getContents();
BufferedReader in = new BufferedReader(new InputStreamReader(s, "8859_1"));
//$NON-NLS-1$
while (true) {
String line = in.readLine();
@@ -198,6 +199,14 @@
ModelUIPlugin.getPluginLog().logError(e);
} catch (IOException e) {
ModelUIPlugin.getPluginLog().logError(e);
+ } finally {
+ if(s!=null) {
+ try {
+ s.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}
String[][] r = new String[keys.size()][2];
for (int i = 0; i < r.length; i++) {
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/ELValidator.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -73,7 +73,6 @@
import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.preferences.JSFSeverityPreferences;
import org.jboss.tools.jsf.project.JSFNature;
@@ -269,13 +268,7 @@
removeAllMessagesFromResource(file);
displaySubtask(JSFValidationMessages.VALIDATING_EL_FILE, new
String[]{file.getProject().getName(), file.getName()});
String ext = file.getFileExtension();
- String content = null;
- try {
- content = FileUtil.readStream(file.getContents());
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- return;
- }
+ String content = EclipseResourceUtil.getFileContent(file);
if(ext.equalsIgnoreCase(JAVA_EXT)) {
validateJava(file, content);
} else {
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ELReference.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ELReference.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ELReference.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -28,8 +28,8 @@
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.el.core.parser.SyntaxError;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ITextSourceReference;
-import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
import org.w3c.dom.Element;
@@ -117,29 +117,25 @@
public ELExpression[] getEl() {
if(el==null) {
Set<ELExpression> exps = new HashSet<ELExpression>();
- try {
- String content = FileUtil.readStream(getResource().getContents());
- String elText = content.substring(startPosition, startPosition + length);
- int startEl = elText.indexOf("#{"); //$NON-NLS-1$
- if(startEl>-1) {
- ELParser parser = ELParserUtil.getJbossFactory().createParser();
- ELModel model = parser.parse(elText);
- List<SyntaxError> errors = model.getSyntaxErrors();
- if(!errors.isEmpty()) {
+ String content = EclipseResourceUtil.getFileContent(getResource());
+ String elText = content.substring(startPosition, startPosition + length);
+ int startEl = elText.indexOf("#{"); //$NON-NLS-1$
+ if(startEl>-1) {
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(elText);
+ List<SyntaxError> errors = model.getSyntaxErrors();
+ if(!errors.isEmpty()) {
+ WebKbPlugin.getDefault().logWarning("ELObject hold incorrect information. Maybe
resource " + getResource() + " has been changed.");
+ return null;
+ }
+ List<ELInstance> is = model.getInstances();
+ for (ELInstance i : is) {
+ if(!i.getErrors().isEmpty()) {
WebKbPlugin.getDefault().logWarning("ELObject hold incorrect information.
Maybe resource " + getResource() + " has been changed.");
- return null;
+ continue;
}
- List<ELInstance> is = model.getInstances();
- for (ELInstance i : is) {
- if(!i.getErrors().isEmpty()) {
- WebKbPlugin.getDefault().logWarning("ELObject hold incorrect information.
Maybe resource " + getResource() + " has been changed.");
- continue;
- }
- exps.add(i.getExpression());
- }
+ exps.add(i.getExpression());
}
- } catch (CoreException e) {
- WebKbPlugin.getDefault().logError(e);
}
el = exps.toArray(new ELExpression[0]);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -30,8 +30,8 @@
import org.eclipse.text.edits.TextEdit;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ITextSourceReference;
-import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
@@ -217,15 +217,8 @@
if(!isFileCorrect(file))
return;
-
- String content = null;
- try {
- content = FileUtil.readStream(file.getContents());
- } catch (CoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
-
+
+ String content = EclipseResourceUtil.getFileContent(file);
String text = content.substring(location.getStartPosition(),
location.getStartPosition()+location.getLength());
if(text.startsWith("<")){ //$NON-NLS-1$
int position = text.lastIndexOf("/>"); //$NON-NLS-1$
@@ -245,14 +238,7 @@
if(!isFileCorrect(file))
return;
- String content = null;
- try {
- content = FileUtil.readStream(file.getContents());
- } catch (CoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
-
+ String content = EclipseResourceUtil.getFileContent(file);
String text = content.substring(location.getStartPosition(),
location.getStartPosition()+location.getLength());
int openBracket = text.indexOf("("); //$NON-NLS-1$
int openQuote = text.indexOf("\""); //$NON-NLS-1$
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamRefactorContributionFactory.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamRefactorContributionFactory.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamRefactorContributionFactory.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -169,23 +169,16 @@
}else if(editor instanceof WebCompoundEditor)
sel =
((WebCompoundEditor)editor).getActiveEditor().getSite().getSelectionProvider().getSelection();
}
-
+
if(sel instanceof TextSelection){
TextSelection selection = (TextSelection)sel;
-
+
selectedText = selection.getText();
-
- fileContent = null;
- try {
- fileContent = FileUtil.readStream(editorFile.getContents());
- } catch (CoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- return;
- }
-
+
+ fileContent = EclipseResourceUtil.getFileContent(editorFile);
+
boolean status = false;
-
-
+
if(JAVA_EXT.equalsIgnoreCase(ext)){
// check - whether selected component's name or not
// if(checkNameAnnotation(selection)){
@@ -199,10 +192,10 @@
status = checkContextVariableInDOM(editorFile, fileContent, selection);
else if(PROPERTIES_EXT.equalsIgnoreCase(ext))
status = checkContextVariableInProperties(editorFile, fileContent, selection);
-
+
if(status){
mm.add(new RenameSeamContextVariableAction());
-
+
if(!separatorIsAdded)
additions.addContributionItem(new Separator(), null);
additions.addContributionItem(mm, null);
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -9,6 +9,7 @@
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.MultiTextEdit;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamProject;
@@ -130,8 +131,7 @@
assertNotNull("Can't load component " + newName,
seamProject.getComponent(newName));
for(TestChangeStructure changeStructure : changeList){
IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
- String content = null;
- content = FileUtil.readStream(file.getContents());
+ String content = EclipseResourceUtil.getFileContent(file);
//System.out.println("File - "+file.getName()+" offset -
"+changeStructure.getOffset()+" expected -
["+changeStructure.getText()+"] actual -
["+content.substring(changeStructure.getOffset(),
changeStructure.getOffset()+changeStructure.getLength())+"]");
for(TestTextChange change : changeStructure.getTextChanges()){
assertEquals("There is unexpected change in resource -
"+file.getName(),change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -9,6 +9,7 @@
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.MultiTextEdit;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamProject;
import
org.jboss.tools.seam.internal.core.refactoring.RenameSeamContextVariableProcessor;
@@ -25,8 +26,7 @@
// Test before renaming
for(TestChangeStructure changeStructure : changeList){
IFile file = changeStructure.getProject().getFile(changeStructure.getFileName());
- String content = null;
- content = FileUtil.readStream(file.getContents());
+ String content = EclipseResourceUtil.getFileContent(file);
for(TestTextChange change : changeStructure.getTextChanges()){
assertNotSame(change.getText(), content.substring(change.getOffset(),
change.getOffset()+change.getLength()));
}
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/view/SeamComponentsViewTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/view/SeamComponentsViewTest.java 2009-11-09
19:08:01 UTC (rev 18508)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/view/SeamComponentsViewTest.java 2009-11-09
19:11:05 UTC (rev 18509)
@@ -11,6 +11,8 @@
******************************************************************************/
package org.jboss.tools.seam.ui.test.view;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
import junit.framework.TestCase;
@@ -37,6 +39,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.navigator.CommonNavigator;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamPackage;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -238,10 +241,20 @@
IFile file1 = project.getFile("JavaSource/demo/Person.1");
assertTrue("Cannot find Person.1 in test project", file1 != null &&
file1.exists());
+ InputStream is = null;
try{
- classFile.create(file1.getContents(), false, new NullProgressMonitor());
+ is = file1.getContents();
+ classFile.create(is, false, new NullProgressMonitor());
}catch(Exception ex){
JUnitUtils.fail("Cannot read file JavaSource/demo/Person.1", ex);
+ } finally {
+ if(is!=null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}
refreshProject(project);