Author: xcoulon
Date: 2012-08-01 05:52:33 -0400 (Wed, 01 Aug 2012)
New Revision: 42828
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/domain/package-info.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilderTestCase.java
Log:
More testing on JBIDE-12095
JAX-RS facet in JBoss Tools chokes on package-info.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-08-01
09:51:49 UTC (rev 42827)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2012-08-01
09:52:33 UTC (rev 42828)
@@ -113,7 +113,6 @@
}
switch (deltaKind) {
case ADDED:
- //if(element.exists()) { // needed to prevent exception for edge cases such as
'package-info.java' that holds some shadow 'A' type..
switch (elementType) {
case JAVA_PROJECT:
return processAddition(element, metamodel, progressMonitor);
Added:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/domain/package-info.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/domain/package-info.java
(rev 0)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/domain/package-info.java 2012-08-01
09:52:33 UTC (rev 42828)
@@ -0,0 +1 @@
+package org.jboss.tools.ws.jaxrs.sample.domain;
\ No newline at end of file
Property changes on:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/projects/org.jboss.tools.ws.jaxrs.tests.sampleproject/src/main/java/org/jboss/tools/ws/jaxrs/sample/domain/package-info.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2012-08-01
09:51:49 UTC (rev 42827)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2012-08-01
09:52:33 UTC (rev 42828)
@@ -893,6 +893,7 @@
return folder.findMember(fileName);
}
+
/**
* Replaces the content of the given resource with the given stream.
*
@@ -901,6 +902,37 @@
* @throws CoreException
* @throws IOException
*/
+ public static void replaceContent(IResource resource, InputStream stream) throws
CoreException, IOException {
+ final IProject project = resource.getProject();
+ final IFile file = project.getFile(resource.getProjectRelativePath());
+ if (file.exists()) {
+ file.delete(true, new NullProgressMonitor());
+ }
+ file.create(stream, true, null);
+ LOGGER.debug("Content:");
+ final InputStream contents = file.getContents();
+ final char[] buffer = new char[0x10000];
+ StringBuilder out = new StringBuilder();
+ Reader in = new InputStreamReader(contents, "UTF-8");
+ int read;
+ do {
+ read = in.read(buffer, 0, buffer.length);
+ if (read > 0) {
+ out.append(buffer, 0, read);
+ }
+ } while (read >= 0);
+ LOGGER.debug(out.toString());
+ }
+
+
+ /**
+ * Replaces the content of the given resource with the given stream.
+ *
+ * @param webxmlResource
+ * @param stream
+ * @throws CoreException
+ * @throws IOException
+ */
public static void replaceContent(IResource resource, InputStream stream, boolean
useWorkingCopy) throws CoreException, IOException {
final IProject project = resource.getProject();
final IFile file = project.getFile(resource.getProjectRelativePath());
@@ -908,8 +940,6 @@
IBuffer buffer = ((IOpenable) unit).getBuffer();
buffer.setContents(IOUtils.toString(stream));
saveAndClose(unit);
-
-
}
/**
@@ -936,7 +966,7 @@
InputStream stream = FileLocator.openStream(bundle, new
Path("resources").append(webxmlReplacementName), false);
assertThat(stream, notNullValue());
if (webxmlResource != null) {
- replaceContent(webxmlResource, stream, false);
+ replaceContent(webxmlResource, stream);
return webxmlResource;
} else {
return createFileFromStream(webInfFolder, "web.xml", stream);
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilderTestCase.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilderTestCase.java 2012-08-01
09:51:49 UTC (rev 42827)
+++
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilderTestCase.java 2012-08-01
09:52:33 UTC (rev 42828)
@@ -10,12 +10,17 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
-import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import java.io.IOException;
+
+import org.apache.commons.io.IOUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -156,5 +161,33 @@
assertThat(metamodel.getAllEndpoints().size(), equalTo(16));
}
+ @Test
+ public void shouldDoNothingWhenPackageInfoAdded() throws CoreException, IOException {
+ // pre-conditions
+ IFolder folder =
javaProject.getProject().getFolder("src/main/java/org/jboss/tools/ws/jaxrs/sample/services");
+ // operation
+ WorkbenchUtils.createFileFromStream(folder, "package-info.java",
+ IOUtils.toInputStream("package
org.jboss.tools.ws.jaxrs.sample.services;"));
+ // explicitly trigger the project build
+ javaProject.getProject().build(IncrementalProjectBuilder.AUTO_BUILD, null);
+ // verifications: no exception should have been thrown
+ }
+
+ @Test
+ public void shouldDoNothingWhenPackageInfoChanged() throws CoreException, IOException {
+ // pre-conditions
+ JBossJaxrsCorePlugin.getDefault().registerListeners();
+ IFile pkgInfoFile =
javaProject.getProject().getFile("src/main/java/org/jboss/tools/ws/jaxrs/sample/services/package-info.java");
+ pkgInfoFile.create(IOUtils.toInputStream(""), true, new
NullProgressMonitor());
+ // operation
+ WorkbenchUtils.replaceContent(pkgInfoFile, IOUtils.toInputStream("package
org.jboss.tools.ws.jaxrs.sample;"), true);
+ WorkbenchUtils.replaceContent(pkgInfoFile, IOUtils.toInputStream("package
org.jboss.tools.ws.jaxrs.sample.services;"), true);
+ // explicitly trigger the project build
+ //javaProject.getProject().build(IncrementalProjectBuilder.AUTO_BUILD, null);
+ // verifications: no exception should have been thrown
+
+ }
+
+
}