JBoss Tools SVN: r36550 - in branches/hibernatetools-multiversion2/plugins: org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-11-22 19:05:33 -0500 (Tue, 22 Nov 2011)
New Revision: 36550
Modified:
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
Log:
Remove strategy usage
Modified: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2011-11-23 00:01:08 UTC (rev 36549)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2011-11-23 00:05:33 UTC (rev 36550)
@@ -14,7 +14,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ext.HibernateExtension;
import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
@@ -33,7 +32,6 @@
ILaunch launch, IProgressMonitor monitor) throws CoreException;
public ConsoleDatabaseCollector readDatabaseSchema(IProgressMonitor monitor,
- ConsoleConfiguration consoleConfiguration,
- ReverseEngineeringStrategy strategy);
+ ConsoleConfiguration consoleConfiguration);
}
Modified: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2011-11-23 00:01:08 UTC (rev 36549)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2011-11-23 00:05:33 UTC (rev 36550)
@@ -33,20 +33,14 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osgi.util.NLS;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.JDBCReaderFactory;
-import org.hibernate.cfg.Settings;
-import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
-import org.hibernate.cfg.reveng.JDBCReader;
-import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
-import org.hibernate.connection.ConnectionProvider;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ImageConstants;
-import org.hibernate.console.execution.ExecutionContext;
+import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
+import org.hibernate.console.ext.api.ITable;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.ext.ConsoleExtensionManager;
import org.hibernate.eclipse.console.utils.EclipseImages;
-import org.hibernate.mapping.Table;
public class LazyDatabaseSchemaWorkbenchAdapter extends BasicWorkbenchAdapter {
@@ -62,13 +56,13 @@
ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration();
Object[] res;
try {
- DefaultDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy());
+ ConsoleDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration);
List<TableContainer> result = new ArrayList<TableContainer>();
- Iterator<Map.Entry<String, List<Table>>> qualifierEntries = db.getQualifierEntries();
+ Iterator<Map.Entry<String, List<ITable>>> qualifierEntries = db.getQualifierEntries();
while (qualifierEntries.hasNext()) {
- Map.Entry<String, List<Table>> entry = qualifierEntries.next();
+ Map.Entry<String, List<ITable>> entry = qualifierEntries.next();
result.add(new TableContainer(entry.getKey(), entry.getValue()));
}
res = toArray(result.iterator(), TableContainer.class, new Comparator<TableContainer>() {
@@ -110,8 +104,10 @@
return getLazyDatabaseSchema(o).getConsoleConfiguration();
}
- protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
- final Configuration configuration = consoleConfiguration.buildWith(null, false);
+ protected ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration/*, final ReverseEngineeringStrategy strategy*/) {
+ return ConsoleExtensionManager.getConsoleExtension(consoleConfiguration)
+ .readDatabaseSchema(monitor, consoleConfiguration);
+ /*final Configuration configuration = consoleConfiguration.buildWith(null, false);
return (DefaultDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {
public Object execute() {
@@ -136,7 +132,7 @@
}
return db;
}
- });
+ });*/
}
}
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-23 00:01:08 UTC (rev 36549)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-23 00:05:33 UTC (rev 36550)
@@ -31,7 +31,6 @@
import org.hibernate.cfg.JDBCMetaDataConfiguration;
import org.hibernate.cfg.JDBCReaderFactory;
import org.hibernate.cfg.Settings;
-import org.hibernate.cfg.reveng.DatabaseCollector;
import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.JDBCReader;
@@ -308,9 +307,8 @@
}
@Override
- public ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration cc,
- final ReverseEngineeringStrategy strategy) {
- return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, strategy));
+ public ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration cc) {
+ return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, new DefaultReverseEngineeringStrategy()));
}
protected DefaultDatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-23 00:01:08 UTC (rev 36549)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-23 00:05:33 UTC (rev 36550)
@@ -32,7 +32,6 @@
import org.hibernate.cfg.JDBCMetaDataConfiguration;
import org.hibernate.cfg.JDBCReaderFactory;
import org.hibernate.cfg.Settings;
-import org.hibernate.cfg.reveng.DatabaseCollector;
import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.JDBCReader;
@@ -58,7 +57,6 @@
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.spi.ServiceRegistryImplementor;
-import org.hibernate.service.spi.Stoppable;
import org.hibernate.tool.hbm2x.ArtifactCollector;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.ide.completion.HQLCodeAssist;
@@ -312,9 +310,8 @@
}
@Override
- public ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration cc,
- final ReverseEngineeringStrategy strategy) {
- return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, strategy));
+ public ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration cc) {
+ return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, new DefaultReverseEngineeringStrategy()));
}
protected DefaultDatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
13 years, 1 month
JBoss Tools SVN: r36549 - in branches/hibernatetools-multiversion2/plugins: org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0 and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-11-22 19:01:08 -0500 (Tue, 22 Nov 2011)
New Revision: 36549
Added:
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/mapping/
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/mapping/TableImpl.java
Removed:
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java
Modified:
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
Log:
Move database reading to console extension
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-22 23:59:26 UTC (rev 36548)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-23 00:01:08 UTC (rev 36549)
@@ -313,7 +313,7 @@
return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, strategy));
}
- protected DatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
+ protected DefaultDatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
final Configuration configuration = consoleConfiguration.buildWith(null, false);
return (DefaultDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {
Deleted: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java 2011-11-22 23:59:26 UTC (rev 36548)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java 2011-11-23 00:01:08 UTC (rev 36549)
@@ -1,28 +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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.hibernate4_0.console;
-
-import org.hibernate.cfg.reveng.DatabaseCollector;
-import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
-
-/**
- * @author Dmitry Geraskov {geraskov(a)gmail.com}
- *
- */
-public class ConsoleDatabaseCollectorImpl extends ConsoleDatabaseCollector {
-
- private DatabaseCollector collector;
-
- public ConsoleDatabaseCollectorImpl(DatabaseCollector databaseCollector){
- this.collector = databaseCollector;
- }
-
-}
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-22 23:59:26 UTC (rev 36548)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-23 00:01:08 UTC (rev 36549)
@@ -317,7 +317,7 @@
return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, strategy));
}
- protected DatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
+ protected DefaultDatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
final Configuration configuration = consoleConfiguration.buildWith(null, false);
return (DefaultDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {
Added: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/mapping/TableImpl.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/mapping/TableImpl.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/mapping/TableImpl.java 2011-11-23 00:01:08 UTC (rev 36549)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate4_0.mapping;
+
+import org.hibernate.console.ext.api.ITable;
+import org.hibernate.mapping.Table;
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public class TableImpl implements ITable {
+
+ private Table table;
+
+ public TableImpl(Table table){
+ this.table = table;
+ }
+
+ @Override
+ public String getName() {
+ return table.getName();
+ }
+
+ @Override
+ public String getSchema() {
+ return table.getSchema();
+ }
+
+ @Override
+ public String getCatalog() {
+ return table.getCatalog();
+ }
+
+}
13 years, 1 month
JBoss Tools SVN: r36548 - in branches/hibernatetools-multiversion2/plugins: org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5 and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-11-22 18:59:26 -0500 (Tue, 22 Nov 2011)
New Revision: 36548
Added:
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/mapping/
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/mapping/TableImpl.java
Modified:
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java
Log:
Move database reading to console extension
Modified: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java 2011-11-22 23:41:59 UTC (rev 36547)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java 2011-11-22 23:59:26 UTC (rev 36548)
@@ -19,14 +19,11 @@
* @author Dmitry Geraskov {geraskov(a)gmail.com}
*
*/
-public class ConsoleDatabaseCollector {
+public interface ConsoleDatabaseCollector {
/**
* @return
*/
- public Iterator<Entry<String, List<ITable>>> getQualifierEntries() {
- // TODO Auto-generated method stub
- return null;
- }
+ public Iterator<Entry<String, List<ITable>>> getQualifierEntries();
}
Modified: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java 2011-11-22 23:41:59 UTC (rev 36547)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java 2011-11-22 23:59:26 UTC (rev 36548)
@@ -25,7 +25,7 @@
public String getCatalog();
- public IPrimaryKey getPrimaryKey();
+ //public IPrimaryKey getPrimaryKey();
- public Iterator<IColumn> getColumnIterator();
+ //public Iterator<IColumn> getColumnIterator();
}
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java 2011-11-22 23:41:59 UTC (rev 36547)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java 2011-11-22 23:59:26 UTC (rev 36548)
@@ -10,19 +10,50 @@
******************************************************************************/
package org.jboss.tools.hibernate3_5.console;
-import org.hibernate.cfg.reveng.DatabaseCollector;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
+import org.hibernate.console.ext.api.ITable;
+import org.hibernate.mapping.Table;
+import org.jboss.tools.hibernate3_5.mapping.TableImpl;
/**
* @author Dmitry Geraskov {geraskov(a)gmail.com}
*
*/
-public class ConsoleDatabaseCollectorImpl extends ConsoleDatabaseCollector {
+public class ConsoleDatabaseCollectorImpl implements ConsoleDatabaseCollector {
- private DatabaseCollector collector;
+ private DefaultDatabaseCollector collector;
- public ConsoleDatabaseCollectorImpl(DatabaseCollector databaseCollector){
+ private Map<String, List<ITable>> qualifiers = new HashMap<String, List<ITable>>();
+
+ public ConsoleDatabaseCollectorImpl(DefaultDatabaseCollector databaseCollector){
this.collector = databaseCollector;
+ this.initializeTableMap();
}
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ protected void initializeTableMap(){
+ Iterator qualifierEntries = collector.getQualifierEntries();
+ while (qualifierEntries.hasNext()) {
+ Entry<String, List<Table>> entry = (Entry<String, List<Table>>) qualifierEntries.next();
+ List<ITable> list = new LinkedList<ITable>();
+ for (Table table : entry.getValue()) {
+ list.add(new TableImpl(table));
+ }
+ qualifiers.put(entry.getKey(), list);
+ }
+ }
+ @Override
+ public Iterator<Entry<String, List<ITable>>> getQualifierEntries() {
+ return qualifiers.entrySet().iterator();
+ }
+
}
Added: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/mapping/TableImpl.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/mapping/TableImpl.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/mapping/TableImpl.java 2011-11-22 23:59:26 UTC (rev 36548)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_5.mapping;
+
+import org.hibernate.console.ext.api.ITable;
+import org.hibernate.mapping.Table;
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public class TableImpl implements ITable {
+
+ private Table table;
+
+ public TableImpl(Table table){
+ this.table = table;
+ }
+
+ @Override
+ public String getName() {
+ return table.getName();
+ }
+
+ @Override
+ public String getSchema() {
+ return table.getSchema();
+ }
+
+ @Override
+ public String getCatalog() {
+ return table.getCatalog();
+ }
+
+}
13 years, 1 month
JBoss Tools SVN: r36547 - branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-11-22 18:41:59 -0500 (Tue, 22 Nov 2011)
New Revision: 36547
Added:
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IColumn.java
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IPrimaryKey.java
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java
Log:
Move database reading to console extension
Added: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IColumn.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IColumn.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IColumn.java 2011-11-22 23:41:59 UTC (rev 36547)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.console.ext.api;
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public interface IColumn {
+
+ public String getName();
+
+ public Integer getSqlTypeCode();
+
+}
Added: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IPrimaryKey.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IPrimaryKey.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/IPrimaryKey.java 2011-11-22 23:41:59 UTC (rev 36547)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.console.ext.api;
+
+import java.util.List;
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public interface IPrimaryKey {
+
+ boolean containsColumn(IColumn col);
+
+ int getColumnSpan();
+
+ IColumn getColumn(int i);
+
+ List<IColumn> getColumns();
+
+ ITable getTable();
+
+}
Added: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ITable.java 2011-11-22 23:41:59 UTC (rev 36547)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.console.ext.api;
+
+import java.util.Iterator;
+
+/**
+ *
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public interface ITable {
+
+ public String getName();
+
+ public String getSchema();
+
+ public String getCatalog();
+
+ public IPrimaryKey getPrimaryKey();
+
+ public Iterator<IColumn> getColumnIterator();
+}
13 years, 1 month
JBoss Tools SVN: r36546 - in branches/hibernatetools-multiversion2/plugins: org.hibernate.eclipse/src/org/hibernate/console/ext/api and 3 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2011-11-22 18:41:06 -0500 (Tue, 22 Nov 2011)
New Revision: 36546
Added:
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java
Modified:
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionManager.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
Log:
Move database reading to console extension
Added: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/api/ConsoleDatabaseCollector.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.console.ext.api;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public class ConsoleDatabaseCollector {
+
+ /**
+ * @return
+ */
+ public Iterator<Entry<String, List<ITable>>> getQualifierEntries() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2011-11-22 23:13:50 UTC (rev 36545)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtension.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -14,7 +14,10 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
/**
* @author Dmitry Geraskov
@@ -28,5 +31,9 @@
public void launchExporters(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException;
+
+ public ConsoleDatabaseCollector readDatabaseSchema(IProgressMonitor monitor,
+ ConsoleConfiguration consoleConfiguration,
+ ReverseEngineeringStrategy strategy);
}
Modified: branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionManager.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionManager.java 2011-11-22 23:13:50 UTC (rev 36545)
+++ branches/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/ext/ConsoleExtensionManager.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -21,6 +21,7 @@
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
+import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.ext.HibernateExtension;
/**
@@ -94,5 +95,12 @@
}
return null;
}
+
+ public static ConsoleExtension getConsoleExtension(ConsoleConfiguration consoleConfiguration){
+ if (consoleConfiguration != null){
+ return getConsoleExtension(consoleConfiguration.getHibernateExtension());
+ }
+ return null;
+ }
}
Added: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleDatabaseCollectorImpl.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate3_5.console;
+
+import org.hibernate.cfg.reveng.DatabaseCollector;
+import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public class ConsoleDatabaseCollectorImpl extends ConsoleDatabaseCollector {
+
+ private DatabaseCollector collector;
+
+ public ConsoleDatabaseCollectorImpl(DatabaseCollector databaseCollector){
+ this.collector = databaseCollector;
+ }
+
+}
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-22 23:13:50 UTC (rev 36545)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -29,10 +29,16 @@
import org.eclipse.osgi.util.NLS;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.JDBCReaderFactory;
+import org.hibernate.cfg.Settings;
+import org.hibernate.cfg.reveng.DatabaseCollector;
+import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.JDBCReader;
import org.hibernate.cfg.reveng.OverrideRepository;
import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+import org.hibernate.connection.ConnectionProvider;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.HibernateConsoleRuntimeException;
import org.hibernate.console.KnownConfigurations;
@@ -40,10 +46,12 @@
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.ext.HibernateException;
import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
import org.hibernate.eclipse.console.ext.ConsoleExtension;
+import org.hibernate.eclipse.console.workbench.ProgressListenerMonitor;
import org.hibernate.eclipse.launch.CodeGenerationStrings;
import org.hibernate.eclipse.launch.CodeGenerationUtils;
import org.hibernate.eclipse.launch.PathHelper;
@@ -299,4 +307,39 @@
}
}
+ @Override
+ public ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration cc,
+ final ReverseEngineeringStrategy strategy) {
+ return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, strategy));
+ }
+
+ protected DatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
+ final Configuration configuration = consoleConfiguration.buildWith(null, false);
+ return (DefaultDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {
+
+ public Object execute() {
+ DefaultDatabaseCollector db = null;
+ Settings settings = consoleConfiguration.getSettings(configuration);
+ ConnectionProvider connectionProvider = null;
+ try {
+ connectionProvider = settings.getConnectionProvider();
+
+ JDBCReader reader = JDBCReaderFactory.newJDBCReader(configuration.getProperties(), settings, strategy);
+ db = new DefaultDatabaseCollector(reader.getMetaDataDialect());
+ reader.readDatabaseSchema(db, settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), new ProgressListenerMonitor(monitor));
+ } catch (HibernateException he) {
+ throw he;
+ } catch (UnsupportedOperationException he) {
+ throw new HibernateException(he);
+ }
+ finally {
+ if (connectionProvider != null) {
+ connectionProvider.close();
+ }
+ }
+ return db;
+ }
+ });
+ }
+
}
Added: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java (rev 0)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleDatabaseCollectorImpl.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate4_0.console;
+
+import org.hibernate.cfg.reveng.DatabaseCollector;
+import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
+
+/**
+ * @author Dmitry Geraskov {geraskov(a)gmail.com}
+ *
+ */
+public class ConsoleDatabaseCollectorImpl extends ConsoleDatabaseCollector {
+
+ private DatabaseCollector collector;
+
+ public ConsoleDatabaseCollectorImpl(DatabaseCollector databaseCollector){
+ this.collector = databaseCollector;
+ }
+
+}
Modified: branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
===================================================================
--- branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-22 23:13:50 UTC (rev 36545)
+++ branches/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-22 23:41:06 UTC (rev 36546)
@@ -30,7 +30,12 @@
import org.hibernate.annotations.common.util.ReflectHelper;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.JDBCReaderFactory;
+import org.hibernate.cfg.Settings;
+import org.hibernate.cfg.reveng.DatabaseCollector;
+import org.hibernate.cfg.reveng.DefaultDatabaseCollector;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.JDBCReader;
import org.hibernate.cfg.reveng.OverrideRepository;
import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
@@ -41,13 +46,19 @@
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.ext.HibernateException;
import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.console.ext.api.ConsoleDatabaseCollector;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
import org.hibernate.eclipse.console.ext.ConsoleExtension;
+import org.hibernate.eclipse.console.workbench.ProgressListenerMonitor;
import org.hibernate.eclipse.launch.CodeGenerationStrings;
import org.hibernate.eclipse.launch.CodeGenerationUtils;
import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.service.ServiceRegistry;
+import org.hibernate.service.ServiceRegistryBuilder;
+import org.hibernate.service.spi.ServiceRegistryImplementor;
+import org.hibernate.service.spi.Stoppable;
import org.hibernate.tool.hbm2x.ArtifactCollector;
import org.hibernate.tool.hbm2x.Exporter;
import org.hibernate.tool.ide.completion.HQLCodeAssist;
@@ -299,5 +310,40 @@
throw new HibernateConsoleRuntimeException(out, e);
}
}
+
+ @Override
+ public ConsoleDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration cc,
+ final ReverseEngineeringStrategy strategy) {
+ return new ConsoleDatabaseCollectorImpl(readDatabaseSchemaInternal(monitor, cc, strategy));
+ }
+
+ protected DatabaseCollector readDatabaseSchemaInternal(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
+ final Configuration configuration = consoleConfiguration.buildWith(null, false);
+ return (DefaultDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {
+ public Object execute() {
+ ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
+ .applySettings(configuration.getProperties())
+ .buildServiceRegistry();
+ DefaultDatabaseCollector db = null;
+ Settings settings = consoleConfiguration.getSettings(configuration);
+ try {
+ JDBCReader reader = JDBCReaderFactory.newJDBCReader(configuration.getProperties(), settings, strategy, serviceRegistry);
+ db = new DefaultDatabaseCollector(reader.getMetaDataDialect());
+ reader.readDatabaseSchema(db, settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), new ProgressListenerMonitor(monitor));
+ } catch (HibernateException he) {
+ throw he;
+ } catch (UnsupportedOperationException he) {
+ throw new HibernateException(he);
+ }
+ finally {
+ if (serviceRegistry instanceof ServiceRegistryImplementor) {
+ ((ServiceRegistryImplementor)serviceRegistry).destroy();
+ }
+ }
+ return db;
+ }
+ });
+ }
+
}
13 years, 1 month
JBoss Tools SVN: r36545 - in trunk/central/plugins/org.jboss.tools.central: src/org/jboss/tools/central/actions and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: snjeza
Date: 2011-11-22 18:13:50 -0500 (Tue, 22 Nov 2011)
New Revision: 36545
Added:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java
Modified:
trunk/central/plugins/org.jboss.tools.central/plugin.xml
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java
Log:
JBIDE-9850 feeds should be cached so it doesnt show blank when opening up the second time
Modified: trunk/central/plugins/org.jboss.tools.central/plugin.xml
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/plugin.xml 2011-11-22 23:13:41 UTC (rev 36544)
+++ trunk/central/plugins/org.jboss.tools.central/plugin.xml 2011-11-22 23:13:50 UTC (rev 36545)
@@ -132,6 +132,14 @@
name="WTP Runtime Preferences"
id="org.jboss.tools.wtp.runtime.preferences">
</command>
+ <command
+ name="Warning"
+ id="org.jboss.tools.central.newsWarning">
+ </command>
+ <command
+ name="Warning"
+ id="org.jboss.tools.central.blogsWarning">
+ </command>
</extension>
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java 2011-11-22 23:13:41 UTC (rev 36544)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossBlogsHandler.java 2011-11-22 23:13:50 UTC (rev 36545)
@@ -14,6 +14,8 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.jobs.RefreshBlogsJob;
@@ -27,7 +29,39 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (RefreshBlogsJob.INSTANCE.getState() == Job.NONE) {
- RefreshBlogsJob.INSTANCE.schedule();
+ final RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
+ job.setForcedDownload(true);
+ job.setException(null);
+ job.setNeedsRefresh(true);
+ job.addJobChangeListener(new IJobChangeListener() {
+
+ @Override
+ public void sleeping(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void scheduled(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void running(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ job.setForcedDownload(false);
+ job.removeJobChangeListener(this);
+ }
+
+ @Override
+ public void awake(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ }
+ });
+ job.schedule();
}
return null;
}
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java 2011-11-22 23:13:41 UTC (rev 36544)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java 2011-11-22 23:13:50 UTC (rev 36545)
@@ -14,6 +14,8 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.jobs.RefreshNewsJob;
@@ -27,7 +29,39 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (RefreshNewsJob.INSTANCE.getState() == Job.NONE) {
- RefreshNewsJob.INSTANCE.schedule();
+ final RefreshNewsJob job = RefreshNewsJob.INSTANCE;
+ job.setForcedDownload(true);
+ job.setNeedsRefresh(true);
+ job.setException(null);
+ job.addJobChangeListener(new IJobChangeListener() {
+
+ @Override
+ public void sleeping(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void scheduled(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void running(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ job.setForcedDownload(false);
+ job.removeJobChangeListener(this);
+ }
+
+ @Override
+ public void awake(IJobChangeEvent event) {
+ }
+
+ @Override
+ public void aboutToRun(IJobChangeEvent event) {
+ }
+ });
+ job.schedule();
}
return null;
}
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-11-22 23:13:41 UTC (rev 36544)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-11-22 23:13:50 UTC (rev 36545)
@@ -34,6 +34,8 @@
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
@@ -65,9 +67,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbenchWindow;
@@ -97,6 +96,7 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.dialogs.ProjectExamplesDialog;
+import org.jboss.tools.central.jobs.AbstractRefreshJob;
import org.jboss.tools.central.jobs.RefreshBlogsJob;
import org.jboss.tools.central.jobs.RefreshNewsJob;
import org.jboss.tools.central.jobs.RefreshTutorialsJob;
@@ -115,6 +115,9 @@
*/
public class GettingStartedPage extends AbstractJBossCentralPage {
+ private static final String NEWS_WARNING_ID = "org.jboss.tools.central.newsWarning";
+ private static final String BLOGS_WARNING_ID = "org.jboss.tools.central.blogsWarning";
+
private static final String CLASS_ATTRIBUTE = "class";
public static final String ID = ID_PREFIX + "GettingStartedPage";
@@ -156,6 +159,10 @@
private Composite settingsComposite;
private Point oldSize;
private Font categoryFont;
+ private Action newsWarning;
+ private ToolBarManager newsToolBarManager;
+ private ToolBarManager blogsToolBarManager;
+ private Action blogsWarning;
public GettingStartedPage(FormEditor editor) {
super(editor, ID, "Getting Started");
@@ -250,10 +257,16 @@
});
showLoading(blogsPageBook, blogsLoadingComposite, blogsScrollComposite);
blogsPageBook.pack(true);
- RefreshBlogsJob refreshBlogsJob = RefreshBlogsJob.INSTANCE;
+ RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
+ job.setException(null);
+ if (job.getEntries().size() > 0) {
+ job.setNeedsRefresh(true);
+ refreshBlogs();
+ job.setNeedsRefresh(false);
+ }
refreshBlogsJobChangeListener = new RefreshBlogsJobChangeListener();
- refreshBlogsJob.addJobChangeListener(refreshBlogsJobChangeListener);
- refreshBlogsJob.schedule();
+ job.addJobChangeListener(refreshBlogsJobChangeListener);
+ job.schedule();
}
private void createNewsSection(FormToolkit toolkit, Composite parent) {
@@ -297,10 +310,16 @@
});
showLoading(newsPageBook, newsLoadingComposite, newsScrollComposite);
newsPageBook.pack(true);
- RefreshNewsJob refreshNewsJob = RefreshNewsJob.INSTANCE;
+ AbstractRefreshJob job = RefreshNewsJob.INSTANCE;
+ job.setException(null);
+ if (job.getEntries().size() > 0) {
+ job.setNeedsRefresh(true);
+ refreshNews();
+ job.setNeedsRefresh(false);
+ }
refreshNewsJobChangeListener = new RefreshNewsJobChangeListener();
- refreshNewsJob.addJobChangeListener(refreshNewsJobChangeListener);
- refreshNewsJob.schedule();
+ job.addJobChangeListener(refreshNewsJobChangeListener);
+ job.schedule();
}
@@ -349,16 +368,27 @@
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
- toolBarManager.createControl(headerComposite);
+
+ blogsToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
+ blogsToolBarManager.createControl(headerComposite);
+ blogsWarning = new Action("Warning", JBossCentralActivator.getImageDescriptor("/icons/nwarning.gif")) {
+
+ };
+ blogsWarning.setId(BLOGS_WARNING_ID);
+ blogsWarning.setActionDefinitionId(BLOGS_WARNING_ID);
+ //blogsWarning.setEnabled(false);
+ blogsToolBarManager.add(blogsWarning);
+
+ setItemVisible(blogsToolBarManager, BLOGS_WARNING_ID, false);
+
CommandContributionItem item = JBossCentralActivator.createContributionItem(getSite(), "org.jboss.tools.central.openJBossBlogs");
- toolBarManager.add(item);
+ blogsToolBarManager.add(item);
item = JBossCentralActivator.createContributionItem(getSite(), "org.jboss.tools.central.refreshJBossBlogs");
- toolBarManager.add(item);
+ blogsToolBarManager.add(item);
- toolBarManager.update(true);
+ blogsToolBarManager.update(true);
section.setTextClient(headerComposite);
}
@@ -371,23 +401,42 @@
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
- toolBarManager.createControl(headerComposite);
+ newsToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
+ newsToolBarManager.createControl(headerComposite);
+ newsWarning = new Action("Warning", JBossCentralActivator.getImageDescriptor("/icons/nwarning.gif")) {
+
+ };
+ newsWarning.setId(NEWS_WARNING_ID);
+ newsWarning.setActionDefinitionId(NEWS_WARNING_ID);
+ //newsWarning.setEnabled(false);
+ newsToolBarManager.add(newsWarning);
+
+ setItemVisible(newsToolBarManager, NEWS_WARNING_ID, false);
+
CommandContributionItem item = JBossCentralActivator.createContributionItem(getSite(), "org.jboss.tools.central.openJBossNews");
- toolBarManager.add(item);
+ newsToolBarManager.add(item);
item = JBossCentralActivator.createContributionItem(getSite(), "org.jboss.tools.central.openJBossToolsTwitter");
- toolBarManager.add(item);
+ newsToolBarManager.add(item);
item = JBossCentralActivator.createContributionItem(getSite(), "org.jboss.tools.central.refreshJBossNews");
- toolBarManager.add(item);
+ newsToolBarManager.add(item);
- toolBarManager.update(true);
+ newsToolBarManager.update(true);
section.setTextClient(headerComposite);
}
+ protected void setItemVisible(ToolBarManager toolBarManager, String id, boolean value) {
+ IContributionItem[] items = toolBarManager.getItems();
+ for (IContributionItem item:items) {
+ if (id.equals(item.getId())) {
+ item.setVisible(value);
+ }
+ }
+ }
+
private void createTutorialsSection(FormToolkit toolkit, Composite parent) {
tutorialsSection = createSection(toolkit, parent, "Project Examples", ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
@@ -773,7 +822,7 @@
});
}
- private void showException(PageBook pageBook, FormText exceptionText, Exception e) {
+ private void showException(PageBook pageBook, FormText exceptionText, Throwable e) {
JBossCentralActivator.log(e);
String message = StringEscapeUtils.escapeXml(e.getMessage());
String text = JBossCentralActivator.FORM_START_TAG +
@@ -790,33 +839,41 @@
RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
if (job.getState() == Job.NONE) {
if (job.getException() != null) {
- showException(blogsPageBook, blogsExceptionText,
- job.getException());
- return;
+ if (job.getEntries().size() <= 0) {
+ showException(blogsPageBook, blogsExceptionText,
+ job.getException());
+ return;
+ }
}
List<FeedsEntry> entries = job.getEntries();
if (entries == null || entries.size() == 0) {
showNote(blogsPageBook, blogsNoteText, blogsScrollComposite);
return;
}
- showEntries(entries, blogsComposite, blogsPageBook, blogsScrollComposite);
+ if (job.needsRefresh()) {
+ showEntries(entries, blogsComposite, blogsPageBook, blogsScrollComposite);
+ }
}
}
public void refreshNews() {
- RefreshNewsJob job = RefreshNewsJob.INSTANCE;
+ AbstractRefreshJob job = RefreshNewsJob.INSTANCE;
if (job.getState() == Job.NONE) {
if (job.getException() != null) {
- showException(newsPageBook, newsExceptionText,
+ if (job.getEntries().size() <= 0) {
+ showException(newsPageBook, newsExceptionText,
job.getException());
- return;
+ return;
+ }
}
List<FeedsEntry> entries = job.getEntries();
- if (entries == null || entries.size() == 0) {
+ if (entries.size() == 0) {
showNote(newsPageBook, newsNoteText, newsScrollComposite);
return;
}
- showEntries(entries, newsComposite, newsPageBook, newsScrollComposite);
+ if (job.needsRefresh()) {
+ showEntries(entries, newsComposite, newsPageBook, newsScrollComposite);
+ }
}
}
@@ -1053,6 +1110,9 @@
}
protected void resize(boolean force) {
+ if (blogsSection == null) {
+ return;
+ }
Point size;
//if (Platform.OS_MACOSX.equals(Platform.getOS())) {
size = form.getSize();
@@ -1161,6 +1221,15 @@
public void run() {
setBusyIndicator(blogsLoadingComposite, false);
refreshBlogs();
+ setItemVisible(blogsToolBarManager, BLOGS_WARNING_ID, false);
+ RefreshBlogsJob job = RefreshBlogsJob.INSTANCE;
+ if (job.getEntries().size() > 0 && job.getException() != null) {
+ String tooltip = job.getException().getClass().getName() + ": " + job.getException().getLocalizedMessage();
+ blogsWarning.setToolTipText(tooltip);
+ setItemVisible(blogsToolBarManager, BLOGS_WARNING_ID, true);
+ }
+ blogsToolBarManager.update(true);
+ blogsSection.layout(true, true);
}
});
@@ -1173,8 +1242,9 @@
@Override
public void scheduled(IJobChangeEvent event) {
- RefreshBlogsJob.INSTANCE.setException(null);
- showLoading(blogsPageBook, blogsLoadingComposite, blogsScrollComposite);
+ if (RefreshBlogsJob.INSTANCE.getEntries().size() <= 0) {
+ showLoading(blogsPageBook, blogsLoadingComposite, blogsScrollComposite);
+ }
}
@Override
@@ -1247,6 +1317,15 @@
public void run() {
setBusyIndicator(newsLoadingComposite, false);
refreshNews();
+ setItemVisible(newsToolBarManager, NEWS_WARNING_ID, false);
+ RefreshNewsJob job = RefreshNewsJob.INSTANCE;
+ if (job.getEntries().size() > 0 && job.getException() != null) {
+ String tooltip = job.getException().getClass().getName() + ": " + job.getException().getLocalizedMessage();
+ newsWarning.setToolTipText(tooltip);
+ setItemVisible(newsToolBarManager, NEWS_WARNING_ID, true);
+ }
+ newsToolBarManager.update(true);
+ newsSection.layout(true, true);
}
});
@@ -1259,8 +1338,9 @@
@Override
public void scheduled(IJobChangeEvent event) {
- RefreshNewsJob.INSTANCE.setException(null);
- showLoading(newsPageBook, newsLoadingComposite, newsScrollComposite);
+ if (RefreshNewsJob.INSTANCE.getEntries().size() <= 0) {
+ showLoading(newsPageBook, newsLoadingComposite, newsScrollComposite);
+ }
}
@Override
Added: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java (rev 0)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/AbstractRefreshJob.java 2011-11-22 23:13:50 UTC (rev 36545)
@@ -0,0 +1,275 @@
+package org.jboss.tools.central.jobs;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.tools.central.JBossCentralActivator;
+import org.jboss.tools.central.model.FeedsEntry;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.filetransfer.ECFExamplesTransport;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.XmlReader;
+
+public abstract class AbstractRefreshJob extends Job {
+
+ protected List<FeedsEntry> entries = new ArrayList<FeedsEntry>();
+ protected Throwable exception;
+ protected long cacheModified;
+ private String urlString;
+ private File cacheFile;
+ private boolean forcedDownload = false;
+ private boolean needsRefresh = true;
+
+ public AbstractRefreshJob(String name, String urlString) {
+ super(name);
+ this.urlString = urlString;
+ setPriority(LONG);
+ cacheFile = getCacheFile();
+ if (cacheFile.exists()) {
+ cacheModified = cacheFile.lastModified();
+ try {
+ getEntries(cacheFile);
+ } catch (FileNotFoundException e) {
+ JBossCentralActivator.log(e);
+ } catch (IllegalArgumentException e) {
+ JBossCentralActivator.log(e);
+ } catch (FeedException e) {
+ JBossCentralActivator.log(e);
+ } catch (IOException e) {
+ JBossCentralActivator.log(e);
+ }
+ }
+ }
+
+ public abstract File getCacheFile();
+
+ protected void getEntries(File file) throws IOException,
+ IllegalArgumentException, FeedException {
+ entries.clear();
+ needsRefresh = true;
+ InputStream in = new FileInputStream(file);
+ SyndFeedInput input = new SyndFeedInput();
+ SyndFeed syndFeed = input.build(new XmlReader(in));
+ List<SyndEntry> feeds = syndFeed.getEntries();
+ if (feeds == null || feeds.size() == 0) {
+ return;
+ }
+ int i = 0;
+
+ for (SyndEntry feed : feeds) {
+ FeedsEntry entry = adaptEntry(feed);
+ if (entry == null) {
+ continue;
+ }
+ if (i++ > JBossCentralActivator.MAX_FEEDS) {
+ break;
+ }
+ entries.add(entry);
+ }
+ }
+
+ private FeedsEntry adaptEntry(SyndEntry entry) {
+ if (entry == null) {
+ return null;
+ }
+ String title = null;
+ if (entry.getTitle() != null) {
+ title = entry.getTitle();
+ } else {
+ SyndContent titleEx = entry.getTitleEx();
+ if (titleEx != null && !titleEx.getValue().isEmpty()) {
+ title = titleEx.getValue();
+ }
+ }
+ if (title == null) {
+ return null;
+ }
+ title = StringEscapeUtils.escapeHtml(title);
+ String link;
+ if (entry.getLink() != null) {
+ link = entry.getLink();
+ } else {
+ link = entry.getUri();
+ }
+ String description = null;
+ if (entry.getDescription() != null) {
+ SyndContent desc = entry.getDescription();
+ if (desc != null && !desc.getValue().isEmpty()) {
+ description = desc.getValue();
+ }
+ }
+ if (description == null) {
+ List<SyndContent> contents = entry.getContents();
+ if (contents != null && contents.size() > 0) {
+ SyndContent desc = contents.get(0);
+ if (desc != null && !desc.getValue().isEmpty()) {
+ description = desc.getValue();
+ }
+ }
+ }
+
+ Date date;
+ if (entry.getUpdatedDate() != null) {
+ date = entry.getUpdatedDate();
+ } else {
+ date = entry.getPublishedDate();
+ }
+ String author = entry.getAuthor();
+ if (author != null) {
+ author = StringEscapeUtils.escapeHtml(author);
+ }
+
+ // description = " " + description;
+ return new FeedsEntry(title, link, description, entry.getAuthor(), date);
+ }
+
+ public Throwable getException() {
+ return exception;
+ }
+
+ public void setException(Throwable exception) {
+ this.exception = exception;
+ }
+
+ public List<FeedsEntry> getEntries() {
+ return entries;
+ }
+
+ public String getUrlString() {
+ return urlString;
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ exception = null;
+ long urlModified = -1;
+ if (!forcedDownload) {
+ urlModified = getUrlModified();
+ if (exception != null) {
+ return Status.CANCEL_STATUS;
+ }
+ }
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ if (forcedDownload || urlModified != cacheModified) {
+ try {
+ File tempFile = File.createTempFile("news", ".xml");
+ tempFile.deleteOnExit();
+ OutputStream destination = new FileOutputStream(tempFile);
+ IStatus status = ECFExamplesTransport.getInstance().download(
+ cacheFile.getName(), urlString, destination, monitor);
+ URL url = getURL();
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ if (status.isOK() && url != null) {
+ cacheModified = ECFExamplesTransport.getInstance()
+ .getLastModified(url);
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = new FileInputStream(tempFile);
+ out = new FileOutputStream(cacheFile);
+ ProjectExamplesActivator.copy(in, out);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ if (out != null) {
+ try {
+ out.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ tempFile.delete();
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ cacheFile.setLastModified(cacheModified);
+ getEntries(cacheFile);
+ } else {
+ setException(status.getException());
+ }
+ } catch (Exception e) {
+ exception = e;
+ return Status.CANCEL_STATUS;
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ private long getUrlModified() {
+ URL url = getURL();
+ if (exception != null) {
+ return -1;
+ }
+ long urlModified;
+ try {
+ urlModified = ECFExamplesTransport.getInstance().getLastModified(
+ url);
+ } catch (CoreException e) {
+ exception = e;
+ urlModified = -1;
+ }
+ return urlModified;
+ }
+
+ private URL getURL() {
+ URL url;
+ try {
+ url = new URL(urlString);
+ return url;
+ } catch (MalformedURLException e) {
+ exception = e;
+ return null;
+ }
+ }
+
+ public boolean isForcedDownload() {
+ return forcedDownload;
+ }
+
+ public void setForcedDownload(boolean forced) {
+ this.forcedDownload = forced;
+ }
+
+ public boolean needsRefresh() {
+ return needsRefresh;
+ }
+
+ public void setNeedsRefresh(boolean needRefresh) {
+ this.needsRefresh = needRefresh;
+ }
+
+}
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java 2011-11-22 23:13:41 UTC (rev 36544)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshBlogsJob.java 2011-11-22 23:13:50 UTC (rev 36545)
@@ -10,150 +10,29 @@
************************************************************************************/
package org.jboss.tools.central.jobs;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.io.File;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.IPath;
import org.jboss.tools.central.JBossCentralActivator;
-import org.jboss.tools.central.model.FeedsEntry;
-import com.sun.syndication.feed.synd.SyndContent;
-import com.sun.syndication.feed.synd.SyndEntry;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.io.SyndFeedInput;
-import com.sun.syndication.io.XmlReader;
-
/**
*
* @author snjeza
*
*/
-public class RefreshBlogsJob extends Job {
+public class RefreshBlogsJob extends AbstractRefreshJob {
- private List<FeedsEntry> entries = new ArrayList<FeedsEntry>();
- private Exception exception;
- public static RefreshBlogsJob INSTANCE = new RefreshBlogsJob(JBossCentralActivator.BLOGS_URL);
+ private static final String CACHE_FILE = "blogs.xml";
+ public static RefreshBlogsJob INSTANCE = new RefreshBlogsJob();
- private String blogsurl;
-
- private RefreshBlogsJob(String blogsurl) {
- super("Refreshing JBoss Blogs...");
- setPriority(LONG);
- this.blogsurl=blogsurl;
+ private RefreshBlogsJob() {
+ super("Refreshing JBoss Blogs...", JBossCentralActivator.BLOGS_URL);
}
@Override
- public IStatus run(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- entries.clear();
- SyndFeedInput input = new SyndFeedInput();
- URL url;
- try {
- url = new URL(blogsurl);
- } catch (MalformedURLException e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- try {
- SyndFeed syndFeed = input.build(new XmlReader(url));
- List<SyndEntry> feeds = syndFeed.getEntries();
- if (feeds == null || feeds.size() == 0) {
- return Status.OK_STATUS;
- }
- int i = 0;
-
- for (SyndEntry feed:feeds) {
- FeedsEntry entry = adaptEntry(feed);
- if (entry == null) {
- continue;
- }
- if (i++ > JBossCentralActivator.MAX_FEEDS) {
- break;
- }
- entries.add(entry);
- }
- } catch (Exception e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
+ public File getCacheFile() {
+ IPath location = JBossCentralActivator.getDefault().getStateLocation();
+ File file = new File(location.toFile(), CACHE_FILE);
+ return file;
}
-
-
- private FeedsEntry adaptEntry(SyndEntry entry) {
- if (entry == null) {
- return null;
- }
- String title = null;
- if (entry.getTitle() != null) {
- title = entry.getTitle();
- } else {
- SyndContent titleEx = entry.getTitleEx();
- if (titleEx != null && !titleEx.getValue().isEmpty()) {
- title = titleEx.getValue();
- }
- }
- if (title == null) {
- return null;
- }
- title = StringEscapeUtils.escapeHtml(title);
- String link;
- if (entry.getLink() != null) {
- link = entry.getLink();
- } else {
- link = entry.getUri();
- }
- String description = null;
- if (entry.getDescription() != null) {
- SyndContent desc = entry.getDescription();
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- if (description == null) {
- List<SyndContent> contents = entry.getContents();
- if (contents != null && contents.size() > 0) {
- SyndContent desc = contents.get(0);
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- }
-
-
- Date date;
- if (entry.getUpdatedDate() != null) {
- date = entry.getUpdatedDate();
- } else {
- date = entry.getPublishedDate();
- }
- String author = entry.getAuthor();
- if (author != null) {
- author = StringEscapeUtils.escapeHtml(author);
- }
-
- //description = " " + description;
- return new FeedsEntry(title, link, description, entry.getAuthor(), date);
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public List<FeedsEntry> getEntries() {
- return entries;
- }
}
Modified: trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java 2011-11-22 23:13:41 UTC (rev 36544)
+++ trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshNewsJob.java 2011-11-22 23:13:50 UTC (rev 36545)
@@ -10,150 +10,30 @@
************************************************************************************/
package org.jboss.tools.central.jobs;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.io.File;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.IPath;
import org.jboss.tools.central.JBossCentralActivator;
-import org.jboss.tools.central.model.FeedsEntry;
-import com.sun.syndication.feed.synd.SyndContent;
-import com.sun.syndication.feed.synd.SyndEntry;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.io.SyndFeedInput;
-import com.sun.syndication.io.XmlReader;
-
/**
*
* @author snjeza
*
*/
-public class RefreshNewsJob extends Job {
+public class RefreshNewsJob extends AbstractRefreshJob {
- private List<FeedsEntry> entries = new ArrayList<FeedsEntry>();
- private Exception exception;
- public static RefreshNewsJob INSTANCE = new RefreshNewsJob(JBossCentralActivator.NEWS_URL);
+ private static final String CACHE_FILE = "news.xml";
+ public static RefreshNewsJob INSTANCE = new RefreshNewsJob();
+
- private String newsurl;
-
- private RefreshNewsJob(String newsurl) {
- super("Refreshing JBoss Blogs...");
- setPriority(LONG);
- this.newsurl=newsurl;
+ private RefreshNewsJob() {
+ super("Refreshing JBoss News...", JBossCentralActivator.NEWS_URL);
}
@Override
- public IStatus run(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- entries.clear();
- SyndFeedInput input = new SyndFeedInput();
- URL url;
- try {
- url = new URL(newsurl);
- } catch (MalformedURLException e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- try {
- SyndFeed syndFeed = input.build(new XmlReader(url));
- List<SyndEntry> feeds = syndFeed.getEntries();
- if (feeds == null || feeds.size() == 0) {
- return Status.OK_STATUS;
- }
- int i = 0;
-
- for (SyndEntry feed:feeds) {
- FeedsEntry entry = adaptEntry(feed);
- if (entry == null) {
- continue;
- }
- if (i++ > JBossCentralActivator.MAX_FEEDS) {
- break;
- }
- entries.add(entry);
- }
- } catch (Exception e) {
- exception = e;
- return Status.CANCEL_STATUS;
- }
- return Status.OK_STATUS;
+ public File getCacheFile() {
+ IPath location = JBossCentralActivator.getDefault().getStateLocation();
+ File file = new File(location.toFile(), CACHE_FILE);
+ return file;
}
-
-
- private FeedsEntry adaptEntry(SyndEntry entry) {
- if (entry == null) {
- return null;
- }
- String title = null;
- if (entry.getTitle() != null) {
- title = entry.getTitle();
- } else {
- SyndContent titleEx = entry.getTitleEx();
- if (titleEx != null && !titleEx.getValue().isEmpty()) {
- title = titleEx.getValue();
- }
- }
- if (title == null) {
- return null;
- }
- title = StringEscapeUtils.escapeHtml(title);
- String link;
- if (entry.getLink() != null) {
- link = entry.getLink();
- } else {
- link = entry.getUri();
- }
- String description = null;
- if (entry.getDescription() != null) {
- SyndContent desc = entry.getDescription();
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- if (description == null) {
- List<SyndContent> contents = entry.getContents();
- if (contents != null && contents.size() > 0) {
- SyndContent desc = contents.get(0);
- if (desc != null && !desc.getValue().isEmpty()) {
- description = desc.getValue();
- }
- }
- }
-
-
- Date date;
- if (entry.getUpdatedDate() != null) {
- date = entry.getUpdatedDate();
- } else {
- date = entry.getPublishedDate();
- }
- String author = entry.getAuthor();
- if (author != null) {
- author = StringEscapeUtils.escapeHtml(author);
- }
-
- //description = " " + description;
- return new FeedsEntry(title, link, description, entry.getAuthor(), date);
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public List<FeedsEntry> getEntries() {
- return entries;
- }
}
13 years, 1 month
JBoss Tools SVN: r36544 - in trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples: model and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: snjeza
Date: 2011-11-22 18:13:41 -0500 (Tue, 22 Nov 2011)
New Revision: 36544
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
Log:
JBIDE-9850 feeds should be cached so it doesnt show blank when opening up the second time
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java 2011-11-22 21:08:43 UTC (rev 36543)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/filetransfer/ECFExamplesTransport.java 2011-11-22 23:13:41 UTC (rev 36544)
@@ -197,12 +197,13 @@
* destination stream will be closed by this method whether it succeeds
* to download or not.
*/
- public IStatus download(String name,String url, OutputStream destination, IProgressMonitor monitor) {
+ public IStatus download(String name, String url, OutputStream destination, IProgressMonitor monitor) {
+ IStatus status = null;
try {
IConnectContext context = getConnectionContext(url, false);
for (int i = 0; i < LOGIN_RETRIES; i++) {
try {
- IStatus status = performDownload(name,url, destination, context, monitor);
+ status = performDownload(name,url, destination, context, monitor);
if (status.isOK()) {
return status;
} else {
@@ -231,6 +232,9 @@
}
}
//reached maximum number of retries without success
+ if (status != null) {
+ return status;
+ }
return new Status(IStatus.ERROR, ProjectExamplesActivator.PLUGIN_ID, Messages.ECFExamplesTransport_IO_error, null);
}
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2011-11-22 21:08:43 UTC (rev 36543)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2011-11-22 23:13:41 UTC (rev 36544)
@@ -38,10 +38,12 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
@@ -504,8 +506,24 @@
if (monitor.isCanceled()) {
return null;
}
- file = File.createTempFile(prefix, suffix);
- file.deleteOnExit();
+ long urlModified = -1;
+ file = getFile(url);
+ try {
+ urlModified = ECFExamplesTransport.getInstance().getLastModified(url);
+ } catch (CoreException e) {
+ if (file.exists()) {
+ return file;
+ }
+ }
+ if (file.exists()) {
+ long modified = file.lastModified();
+ if (urlModified == modified) {
+ return file;
+ }
+ }
+ //file = File.createTempFile(prefix, suffix);
+ //file.deleteOnExit();
+ file.getParentFile().mkdirs();
if (monitor.isCanceled()) {
return null;
}
@@ -519,18 +537,27 @@
if (!result.isOK()) {
ProjectExamplesActivator.getDefault().getLog().log(result);
return null;
+ } else {
+ if (file.exists()) {
+ file.setLastModified(urlModified);
+ }
}
} catch (FileNotFoundException e) {
ProjectExamplesActivator.log(e);
return null;
- } catch (IOException e) {
- ProjectExamplesActivator.log(e);
- return null;
- }
+ }
}
return file;
}
+ private static File getFile(java.net.URL url2) {
+ IPath location = ProjectExamplesActivator.getDefault().getStateLocation();
+ File root = location.toFile();
+ String urlFile = url2.getFile();
+ File file = new File(root, urlFile);
+ return file;
+ }
+
private static ECFExamplesTransport getTransport() {
return ECFExamplesTransport.getInstance();
}
13 years, 1 month
JBoss Tools SVN: r36543 - in trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core: internal/utils and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-11-22 16:08:43 -0500 (Tue, 22 Nov 2011)
New Revision: 36543
Removed:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
Log:
Removing obsolete testcase
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2011-11-22 21:07:06 UTC (rev 36542)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2011-11-22 21:08:43 UTC (rev 36543)
@@ -11,7 +11,6 @@
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodelTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidatorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtilsTestCase;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.PathParamValidationTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepositoryTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.pubsub.PubSubServiceTestCase;
@@ -25,7 +24,7 @@
JavaElementChangedEventFilterTestCase.class, JavaElementChangedProcessorTestCase.class,
JaxrsElementChangedProcessorTestCase.class, JaxrsMetamodelBuildJobTestCase.class,
JaxrsElementFactoryTestCase.class, JaxrsMetamodelTestCase.class, CollectionUtilsTestCase.class,
- PathParamValidationTestCase.class, PubSubServiceTestCase.class, JaxrsMetamodelValidatorTestCase.class })
+ PubSubServiceTestCase.class, JaxrsMetamodelValidatorTestCase.class })
public class AllTests {
}
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java 2011-11-22 21:07:06 UTC (rev 36542)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java 2011-11-22 21:08:43 UTC (rev 36543)
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.utils;
-
-import java.util.List;
-
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.JavaModelException;
-import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
-import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-@Ignore("Requires core code refactoring first")
-public class PathParamValidationTestCase extends AbstractMetamodelBuilderTestCase {
-
- @Test
- public void shouldReportValidationErrorsWhenPathParamDoesNotMatchPath() throws CoreException {
- // pre-conditions : add a standard class : no new root resource (yet)
- ICompilationUnit fooCompilationUnit = WorkbenchUtils.createCompilationUnit(javaProject, "FooResource.txt",
- "org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java", bundle);
- IMarker[] markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
- IResource.DEPTH_INFINITE);
- Assert.assertEquals("No marker expected", 0, markers.length);
- // operation : replace @PathParam("id") with @PathParam("ide")
- WorkbenchUtils.replaceAllOccurrencesOfCode(fooCompilationUnit, "@PathParam(\"id\")", "@PathParam(\"ide\")",
- true);
- // post-conditions: expect a validation error
- markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
- IResource.DEPTH_INFINITE);
- Assert.assertEquals("Wrong number of markers", 1, markers.length);
-
- }
-
- @Test
- public void shouldNotReportValidationErrorsWhenPathParamDoesMatchPath() throws JavaModelException, CoreException {
- // pre-conditions : add a standard class : no new root resource (yet)
- ICompilationUnit fooCompilationUnit = WorkbenchUtils.createCompilationUnit(javaProject, "FooResource.txt",
- "org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java", bundle);
- List<IJaxrsResource> resources = metamodel.getAllResources();
- Assert.assertEquals(6, resources.size());
- IMarker[] markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
- IResource.DEPTH_INFINITE);
- Assert.assertEquals("No marker expected", 0, markers.length);
- // operation : change both @Path and @PathParam values
- WorkbenchUtils
- .replaceAllOccurrencesOfCode(fooCompilationUnit, "@Path(\"{id}\")", "@PathParam(\"{ide}\")", true);
- WorkbenchUtils.replaceAllOccurrencesOfCode(fooCompilationUnit, "@PathParam(\"id\")", "@PathParam(\"ide\")",
- true);
- // post-conditions: expect no validation error
- markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
- IResource.DEPTH_INFINITE);
- Assert.assertEquals("No marker expected", 0, markers.length);
-
- }
-
-}
13 years, 1 month
JBoss Tools SVN: r36542 - in trunk/ws: plugins/org.jboss.tools.ws.jaxrs.core/META-INF and 12 other directories.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-11-22 16:07:06 -0500 (Tue, 22 Nov 2011)
New Revision: 36542
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java
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/JaxrsMetamodelBuildJob.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.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/utils/PathParamValidationTestCase.java
Log:
Fixing https://issues.jboss.org/browse/JBIDE-9829 (at least in the scope of a resource)
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/META-INF/MANIFEST.MF 2011-11-22 21:07:06 UTC (rev 36542)
@@ -19,7 +19,8 @@
org.eclipse.ui.editors;bundle-version="3.7.0",
org.eclipse.core.commands;bundle-version="3.6.0",
org.eclipse.ui;bundle-version="3.7.0",
- org.eclipse.ltk.core.refactoring;bundle-version="3.5.200"
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
+ org.eclipse.wst.validation;bundle-version="1.2.302";visibility:=reexport
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: javax.ws.rs,
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/plugin.xml 2011-11-22 21:07:06 UTC (rev 36542)
@@ -10,7 +10,7 @@
hasNature="false"
isConfigurable="false">
<run
- class="org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuilder">
+ class="org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder">
</run>
</builder>
</extension>
@@ -86,26 +86,24 @@
type="org.eclipse.core.resources.problemmarker">
</super>
</extension>
+ <extension
+ id="org.jboss.tools.ws.jaxrs.JaxrsMetamodelValidator"
+ name="JAX-RS Metamodel Validator"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="true"
+ class="org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidator"
+ manual="true"
+ markerId="org.jboss.tools.ws.jaxrs.metamodelMarker">
+ <include>
+ <rules>
+ <projectNature
+ id="org.jboss.tools.ws.jaxrs.nature">
+ </projectNature>
+ </rules>
+ </include>
+ </validator>
+ </extension>
-
- <!--extension
- point="org.eclipse.ui.propertyPages">
- <page
- adaptable="true"
- class="org.jboss.tools.ws.jaxrs.ui.Tapestry5SettingsPropertyPage"
- id="org.jboss.tools.ws.jaxrs.propertyPage"
- name="Tapestry5 Settings "
- objectClass="org.eclipse.core.resources.IProject">
- <enabledWhen>
- <adapt type="org.eclipse.core.resources.IProject">
- <test
- forcePluginActivation="true"
- property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="org.jboss.tools.ws.jaxrs.projectFacet">
- </test>
- </adapt>
- </enabledWhen>
- </page>
- </extension-->
-
+
</plugin>
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/JBossJaxrsCorePlugin.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -36,20 +36,6 @@
public JBossJaxrsCorePlugin() {
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- registerListeners();
- }
-
/**
*
*/
@@ -72,6 +58,20 @@
super.stop(context);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ registerListeners();
+ }
+
/**
*
*/
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedListener.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -8,6 +8,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
/** Listens to all change events (Java elements and resources) and triggers a new
* job for each change.<br>
@@ -37,7 +38,6 @@
Job job = new JaxrsMetamodelBuildJob(event);
job.schedule();
}
-
}
}
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 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JavaElementChangedProcessor.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -129,7 +129,8 @@
return Collections.emptyList();
}
- /** Process the addition of a Java Element (can be a JavaProject or a Java
+ /**
+ * Process the addition of a Java Element (can be a JavaProject or a Java
* Package Fragment root).
*
* @param scope
@@ -140,7 +141,8 @@
* the progress monitor
* @return a list of impacts (ie, JAX-RS elements that where created)
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
private List<JaxrsElementChangedEvent> processAddition(final IJavaElement scope, final JaxrsMetamodel metamodel,
final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -176,9 +178,11 @@
return impacts;
}
- /** @param type
+ /**
+ * @param type
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processAddition(final IType javaType, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -210,9 +214,11 @@
return impacts;
}
- /** @param type
+ /**
+ * @param type
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processAddition(final IMethod javaMethod, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -223,9 +229,11 @@
return impacts;
}
- /** @param javaAnnotation
+ /**
+ * @param javaAnnotation
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processAddition(final IAnnotation javaAnnotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -247,27 +255,31 @@
return impacts;
}
- /** @param javaAnnotation
+ /**
+ * @param javaAnnotation
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
// FIXME : same code as method processAddition(annotation, etc..) ?!?
private List<JaxrsElementChangedEvent> processChange(final IAnnotation javaAnnotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
Annotation annotation = JdtUtils.resolveAnnotation(javaAnnotation, ast);
- final IJaxrsElement<?> jaxrsElement = metamodel.getElement(annotation);
- if (jaxrsElement == null) {
- final List<IJaxrsElement<?>> elements = factory.createElement(javaAnnotation, ast, metamodel);
- for (IJaxrsElement<?> element : elements) {
- if (element != null) {
- impacts.add(new JaxrsElementChangedEvent(element, ADDED));
+ if (annotation != null) {
+ final IJaxrsElement<?> jaxrsElement = metamodel.getElement(annotation);
+ if (jaxrsElement == null) {
+ final List<IJaxrsElement<?>> elements = factory.createElement(javaAnnotation, ast, metamodel);
+ for (IJaxrsElement<?> element : elements) {
+ if (element != null) {
+ impacts.add(new JaxrsElementChangedEvent(element, ADDED));
+ }
}
+ } else {
+ final int flags = jaxrsElement.addOrUpdateAnnotation(annotation);
+ if (flags > 0) {
+ impacts.add(new JaxrsElementChangedEvent(jaxrsElement, CHANGED, flags));
+ }
}
- } else {
- final int flags = jaxrsElement.addOrUpdateAnnotation(annotation);
- if (flags > 0) {
- impacts.add(new JaxrsElementChangedEvent(jaxrsElement, CHANGED, flags));
- }
}
return impacts;
}
@@ -286,10 +298,12 @@
return impacts;
}
- /** @param element
+ /**
+ * @param element
* @param progressMonitor
* @return
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(IPackageFragmentRoot packageFragmentRoot,
final JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -301,11 +315,13 @@
return impacts;
}
- /** @param element
+ /**
+ * @param element
* @param ast
* @param progressMonitor
* @return
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(ICompilationUnit compilationUnit, CompilationUnit ast,
final JaxrsMetamodel metamodel, IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -317,9 +333,11 @@
return impacts;
}
- /** @param javaType
+ /**
+ * @param javaType
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(final IType javaType, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
@@ -332,9 +350,11 @@
return impacts;
}
- /** @param javaAnnotation
+ /**
+ * @param javaAnnotation
* @param progressMonitor
- * @throws CoreException */
+ * @throws CoreException
+ */
private List<JaxrsElementChangedEvent> processRemoval(final IAnnotation javaAnnotation, final CompilationUnit ast,
final JaxrsMetamodel metamodel, final IProgressMonitor progressMonitor) throws CoreException {
final List<JaxrsElementChangedEvent> impacts = new ArrayList<JaxrsElementChangedEvent>();
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJob.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -7,7 +7,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -34,21 +33,18 @@
private final IJavaProject javaProject;
- private final int kind;
-
private final Object event;
- public JaxrsMetamodelBuildJob(final IProject project) throws CoreException {
- super("Full JAX-RS Metamodel build for " + project.getName() + "...");
+ public JaxrsMetamodelBuildJob(final IProject project, final boolean requiresReset) throws CoreException {
+ super("JAX-RS Metamodel build for " + project.getName() + "...");
this.javaProject = JavaCore.create(project);
JavaElementDelta delta = new JavaElementDelta(javaProject);
delta.added();
this.event = new ElementChangedEvent(delta, ElementChangedEvent.POST_RECONCILE);
- this.kind = IncrementalProjectBuilder.FULL_BUILD;
final JaxrsMetamodel metamodel = JaxrsMetamodel.get(javaProject);
if (metamodel == null) {
JaxrsMetamodel.create(javaProject);
- } else {
+ } else if(requiresReset) {
metamodel.reset();
}
}
@@ -57,14 +53,12 @@
super("Incremental JAX-RS Metamodel build..."); //$NON-NLS-1$
this.event = event;
this.javaProject = JavaCore.create(event.getDelta().getResource().getProject());
- this.kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
}
public JaxrsMetamodelBuildJob(final ElementChangedEvent event) {
super("Incremental JAX-RS Metamodel build..."); //$NON-NLS-1$
this.javaProject = event.getDelta().getElement().getJavaProject();
this.event = event;
- this.kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
}
@Override
Copied: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java (from rev 36520, trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java)
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuilder.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
+
+import java.lang.reflect.Field;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
+import org.jboss.tools.ws.jaxrs.core.configuration.ProjectNatureUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+
+/** The JAX-RS Metamodel builder. Invoked when a full build or an incremental
+ * build is triggered on a project on which the JAX-RS nature is installed.
+ *
+ * This builder is responsible of the creation and update of the JAX-RS
+ * Metamodel which is kept in the project's session properties.
+ *
+ * @author xcoulon */
+public class JaxrsMetamodelBuilder extends IncrementalProjectBuilder {
+
+ /** The number of steps to fully build the JAX-RS Metamodel. */
+ private static final int FULL_BUILD_STEPS = 100;
+
+ /** The standard 'Java type' marker type. */
+ public static final String JAVA_PROBLEM = "org.eclipse.jdt.core.problem";
+
+ /** The custom 'JAX-RS Problem' marker type. */
+ public static final String JAXRS_PROBLEM = "org.jboss.tools.ws.jaxrs.metamodelMarker";
+
+ /** The Java element change listener name. */
+ public static final QualifiedName JAXRS_ELEMENT_CHANGE_LISTENER_NAME = new QualifiedName(
+ JBossJaxrsCorePlugin.PLUGIN_ID, "jaxrsPostReconcileListener");
+
+ // TODO : add support for cancellation
+ // TODO : report build failed
+ /** {@inheritDoc} */
+ @Override
+ protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes") final Map args,
+ final IProgressMonitor monitor) throws CoreException {
+ IProject project = getProject();
+ if (!ProjectNatureUtils.isProjectNatureInstalled(project, ProjectNatureUtils.JAXRS_NATURE_ID)) {
+ Logger.warn("Project '" + project.getName() + "' is not a JAX-RS project.");
+ return null;
+ }
+ logBuild(kind, args, project);
+ switch (kind) {
+ case CLEAN_BUILD:
+ case FULL_BUILD:
+ build(project, true, monitor);
+ break;
+ case AUTO_BUILD:
+ case INCREMENTAL_BUILD:
+ //if (JaxrsMetamodel.get(getProject()) == null) {
+ build(getProject(), false, monitor);
+ //}
+ break;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ /** Checks if the running operation was cancelled by the user, as reported by
+ * the progress monitor.
+ *
+ * @param monitor
+ * the progress monitor. */
+ // @see http://www.eclipse.org/articles/Article-Builders/builders.html
+ protected final void checkCancel(final IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ forgetLastBuiltState(); // not always necessary
+ throw new OperationCanceledException();
+ }
+ }
+
+
+
+ /** Performs a full build of the project's JAX-RS Metamodel. This method has
+ * a public visibility so that it can be called from other components
+ *
+ * @param project
+ * the project
+ * @param monitor
+ * the progress monitor */
+ private void build(final IProject project, final boolean requiresReset, final IProgressMonitor monitor) {
+ long startTime = new Date().getTime();
+ try {
+ monitor.beginTask("Building JAX-RS metamodel...", FULL_BUILD_STEPS);
+ JaxrsMetamodelBuildJob buildJob = new JaxrsMetamodelBuildJob(project, requiresReset);
+ buildJob.schedule();
+ // wait until the job is finished
+ buildJob.join();
+ } catch (InterruptedException e) {
+ Logger.error("Error while building the JAX-RS Metamodel for project " + project.getName(), e);
+ } catch (CoreException e) {
+ Logger.error("Error while building the JAX-RS Metamodel for project " + project.getName(), e);
+ } finally {
+ long endTime = new Date().getTime();
+ Logger.debug("JAX-RS Metamodel for project '" + project.getName() + "' fully built in "
+ + (endTime - startTime) + "ms.");
+ monitor.done();
+ }
+ }
+
+ /** Trace the kind of build in the log.
+ *
+ * @param kind
+ * the build kind
+ * @param args
+ * @param project
+ * the project being built */
+ private void logBuild(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProject project) {
+ StringBuilder sb = new StringBuilder("'");
+ for (Field field : IncrementalProjectBuilder.class.getDeclaredFields()) {
+ String name = field.getName();
+ int value;
+ try {
+ value = field.getInt(this);
+ if (value == kind) {
+ sb.append(name.toLowerCase().replace('_', ' '));
+ }
+ } catch (IllegalArgumentException e) {
+ sb.append("*Unknow build*");
+ } catch (IllegalAccessException e) {
+ sb.append("*Unknow build*");
+ }
+ }
+ sb.append("' on project ").append(project.getName());
+ if (args != null && !args.isEmpty()) {
+ sb.append(" (");
+ for (Iterator<?> iterator = args.keySet().iterator(); iterator.hasNext();) {
+ Object key = iterator.next();
+ sb.append(key).append("=").append(args.get(key));
+ if (iterator.hasNext()) {
+ sb.append(", ");
+ }
+ }
+ sb.append(")");
+ }
+ Logger.debug(sb.toString());
+ }
+
+}
Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuilder.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -1,206 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
-
-import java.lang.reflect.Field;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.QualifiedName;
-import org.jboss.tools.ws.jaxrs.core.JBossJaxrsCorePlugin;
-import org.jboss.tools.ws.jaxrs.core.configuration.ProjectNatureUtils;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
-
-/** The JAX-RS Metamodel builder. Invoked when a full build or an incremental
- * build is triggered on a project on which the JAX-RS nature is installed.
- *
- * This builder is responsible of the creation and update of the JAX-RS
- * Metamodel which is kept in the project's session properties.
- *
- * @author xcoulon */
-public class JaxrsMetamodelFullBuilder extends IncrementalProjectBuilder {
-
- /** The number of steps to fully build the JAX-RS Metamodel. */
- private static final int FULL_BUILD_STEPS = 100;
-
- /** The standard 'Java type' marker type. */
- public static final String JAVA_PROBLEM = "org.eclipse.jdt.core.problem";
-
- /** The custom 'JAX-RS Problem' marker type. */
- public static final String JAXRS_PROBLEM = "org.jboss.tools.ws.jaxrs.metamodelMarker";
-
- /** The Java element change listener name. */
- public static final QualifiedName JAXRS_ELEMENT_CHANGE_LISTENER_NAME = new QualifiedName(
- JBossJaxrsCorePlugin.PLUGIN_ID, "jaxrsPostReconcileListener");
-
- // TODO : add support for cancellation
- // TODO : report build failed
- /** {@inheritDoc} */
- @Override
- protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes") final Map args,
- final IProgressMonitor monitor) throws CoreException {
- IProject project = getProject();
- if (!ProjectNatureUtils.isProjectNatureInstalled(project, ProjectNatureUtils.JAXRS_NATURE_ID)) {
- Logger.warn("Project '" + project.getName() + "' is not a JAX-RS project.");
- return null;
- }
- logBuild(kind, args, project);
- switch (kind) {
- case CLEAN_BUILD:
- case FULL_BUILD:
- fullBuild(project, monitor);
- break;
- case AUTO_BUILD:
- case INCREMENTAL_BUILD:
- if (JaxrsMetamodel.get(getProject()) == null) {
- fullBuild(getProject(), monitor);
- }
-
- /*
- * else { IResourceDelta delta = getDelta(project);
- * incrementalBuild(project, delta, monitor); }
- */
- break;
- default:
- break;
- }
- return null;
- }
-
- /** Checks if the running operation was cancelled by the user, as reported by
- * the progress monitor.
- *
- * @param monitor
- * the progress monitor. */
- // @see http://www.eclipse.org/articles/Article-Builders/builders.html
- protected final void checkCancel(final IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- forgetLastBuiltState(); // not always necessary
- throw new OperationCanceledException();
- }
- }
-
- /** Performs and incremental build on the given project, using the given
- * delta.
- *
- * @param project
- * the project
- * @param delta
- * the resource delta
- * @param monitor
- * the progress monitor (optional)
- * @throws CoreException
- * in case of underlying exception */
- @SuppressWarnings("unused")
- private void incrementalBuild(final IProject project, final IResourceDelta delta, final IProgressMonitor monitor)
- throws CoreException {
- if (delta == null) {
- return;
- }
- // delta.accept(this);
- }
-
- // @Override
- // public final boolean visit(final IResourceDelta delta) throws
- // CoreException {
- // IResource resource = delta.getResource();
- // if (resource.getType() == IResource.FILE &&
- // getProject().getFullPath().isPrefixOf(resource.getFullPath())
- // && resource.getFullPath().getFileExtension().equals("java")) {
- // JaxrsMetamodel jaxrsMetamodel =
- // JaxrsMetamodel.get(resource.getProject());
- // if (jaxrsMetamodel == null) {
- // Logger.warn("No Metamodel found for project " +
- // resource.getProject().getName());
- // return false;
- // }
- // logDelta(delta);
- // jaxrsMetamodel.applyDelta(delta, new NullProgressMonitor());
- // jaxrsMetamodel.validate(new NullProgressMonitor());
- // }
- // return true;
- // }
-
- /** Performs a full build of the project's JAX-RS Metamodel. This method has
- * a public visibility so that it can be called from other components
- *
- * @param project
- * the project
- * @param monitor
- * the progress monitor */
- private void fullBuild(final IProject project, final IProgressMonitor monitor) {
- long startTime = new Date().getTime();
- try {
- monitor.beginTask("Building JAX-RS metamodel...", FULL_BUILD_STEPS);
- JaxrsMetamodelBuildJob fullBuildJob = new JaxrsMetamodelBuildJob(project);
- fullBuildJob.schedule();
- // wait until the job is finished
- fullBuildJob.join();
- } catch (InterruptedException e) {
- Logger.error("Error while building the JAX-RS Metamodel for project " + project.getName(), e);
- } catch (CoreException e) {
- Logger.error("Error while building the JAX-RS Metamodel for project " + project.getName(), e);
- } finally {
- long endTime = new Date().getTime();
- Logger.debug("JAX-RS Metamodel for project '" + project.getName() + "' fully built in "
- + (endTime - startTime) + "ms.");
- monitor.done();
- }
- }
-
- /** Trace the kind of build in the log.
- *
- * @param kind
- * the build kind
- * @param args
- * @param project
- * the project being built */
- private void logBuild(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProject project) {
- StringBuilder sb = new StringBuilder("'");
- for (Field field : IncrementalProjectBuilder.class.getDeclaredFields()) {
- String name = field.getName();
- int value;
- try {
- value = field.getInt(this);
- if (value == kind) {
- sb.append(name.toLowerCase().replace('_', ' '));
- }
- } catch (IllegalArgumentException e) {
- sb.append("*Unknow build*");
- } catch (IllegalAccessException e) {
- sb.append("*Unknow build*");
- }
- }
- sb.append("' on project ").append(project.getName());
- if (args != null && !args.isEmpty()) {
- sb.append(" (");
- for (Iterator<?> iterator = args.keySet().iterator(); iterator.hasNext();) {
- Object key = iterator.next();
- sb.append(key).append("=").append(args.get(key));
- if (iterator.hasNext()) {
- sb.append(", ");
- }
- }
- sb.append(")");
- }
- Logger.debug(sb.toString());
- }
-
-}
Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/IMergeable.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
-
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
-
-public interface IMergeable<T> {
-
- /**
- * Merge of the current JAX-RS element with the java element given in
- * parameter.
- *
- * @param element
- * the java element that changed
- * @param progressMonitor
- * the progress monitor
- * @return a list of changes
- * @throws InvalidModelElementException
- * in case of underlying exception
- * @throws CoreException
- * in case of underlying exception
- */
- abstract Set<EnumElementChange> merge(T element, IProgressMonitor progressMonitor)
- throws InvalidModelElementException, CoreException;
-
-}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsApplication.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -10,14 +10,17 @@
******************************************************************************/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsApplication;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** The optional '@Application' annotation, used to designate the base context
* URI of the root resources.
@@ -83,14 +86,14 @@
*/
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
- // TODO Auto-generated method stub
-
+ public EnumKind getKind() {
+ return EnumKind.APPLICATION;
}
@Override
- public EnumKind getKind() {
- return EnumKind.APPLICATION;
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsElement.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -38,6 +38,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.JavaModelException;
@@ -47,7 +48,6 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** Base class for all elements in the JAX-RS Metamodel.
*
@@ -55,7 +55,7 @@
*
* @param <T>
* the underlying Java type managed by the JAX-RS ElementKind. */
-public abstract class JaxrsElement<T extends IMember> implements IJaxrsElement<T>, IValidable {
+public abstract class JaxrsElement<T extends IMember> implements IJaxrsElement<T> {
/** The associated metamodel. */
private final JaxrsMetamodel metamodel;
@@ -146,6 +146,10 @@
public List<Annotation> getAnnotations() {
return Collections.unmodifiableList(new ArrayList<Annotation>(annotations.values()));
}
+
+ IResource getResource() {
+ return this.javaElement.getResource();
+ }
@Override
public int addOrUpdateAnnotation(final Annotation annotation) {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsHttpMethod.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -11,27 +11,36 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.ws.rs.HttpMethod;
-import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
-/** A request method designator is a runtime annotation that is annotated with
+/**
+ * A request method designator is a runtime annotation that is annotated with
* the @HttpMethod annotation. JAX-RS defines a set of request method
* designators for the common HTTP resourceMethods: @GET, @POST, @PUT, @DELETE,
*
* @HEAD. Users may define their own custom request method designators including
* alternate designators for the common HTTP resourceMethods.
*
- * @author xcoulon */
+ * @author xcoulon
+ */
public class JaxrsHttpMethod extends JaxrsElement<IType> implements IJaxrsHttpMethod {
- /** A Simple sorter for HTTP Verbs: the preferred order is
- * GET/POST/PUT/DELETE/HEAD/OPTION. Other/custom Verbs come after. */
+ /**
+ * A Simple sorter for HTTP Verbs: the preferred order is
+ * GET/POST/PUT/DELETE/HEAD/OPTION. Other/custom Verbs come after.
+ */
private enum HttpVerbSortEnum {
/** GET Verb. */
GET(0),
@@ -51,10 +60,12 @@
/** the order rank. */
private int rank = 0;
- /** The constructor.
+ /**
+ * The constructor.
*
* @param r
- * the rank */
+ * the rank
+ */
HttpVerbSortEnum(final int r) {
this.rank = r;
}
@@ -64,12 +75,14 @@
return rank;
}
- /** Converter from literal to enum value. If no direct match, 'OTHER' is
+ /**
+ * Converter from literal to enum value. If no direct match, 'OTHER' is
* returned.
*
* @param verb
* the HTTP verb
- * @return the corresponding value in the enum. */
+ * @return the corresponding value in the enum.
+ */
static HttpVerbSortEnum from(final String verb) {
for (HttpVerbSortEnum e : HttpVerbSortEnum.values()) {
if (verb.equals(e.toString())) {
@@ -89,12 +102,28 @@
return EnumElementKind.HTTP_METHOD;
}
- /** {@inheritDoc} */
@Override
- public void validate(IProgressMonitor progressMonitor) {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ final Annotation annotation = getHttpMethodAnnotation();
+ if(annotation == null) {
+
+ } else {
+ final String httpValue = annotation.getValue("value");
+ if(httpValue == null || httpValue.isEmpty()) {
+ final ValidatorMessage message = ValidatorMessage.create("HTTP Verb should not be empty", getResource());
+ message.setAttribute(IMarker.MARKER, JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ message.setAttribute(IMarker.CHAR_START, annotation.getRegion().getOffset());
+ message.setAttribute(IMarker.CHAR_END, annotation.getRegion().getOffset() + annotation.getRegion().getLength());
+ messages.add(message);
+ }
+ }
+ return messages;
}
+
+
/*
* (non-Javadoc)
*
@@ -111,9 +140,11 @@
return null;
}
- /** @param httpVerb
+ /**
+ * @param httpVerb
* the httpVerb to set
- * @return */
+ * @return
+ */
public boolean setHttpMethodAnnotation(final Annotation httpVerbAnnotation) {
return getHttpMethodAnnotation().update(httpVerbAnnotation);
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsMetamodel.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -24,6 +24,7 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
@@ -47,14 +48,18 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
-/** Manages all the JAX-RS domain classes of the JAX-RS Metamodel. Not only a
+/**
+ * Manages all the JAX-RS domain classes of the JAX-RS Metamodel. Not only a
* POJO, but also provides business services.
*
- * @author xcoulon */
+ * @author xcoulon
+ */
public class JaxrsMetamodel implements IJaxrsMetamodel {
- /** The qualified name of the metamodel when stored in the project session
- * properties. */
+ /**
+ * The qualified name of the metamodel when stored in the project session
+ * properties.
+ */
public static final QualifiedName METAMODEL_QUALIFIED_NAME = new QualifiedName(JBossJaxrsCorePlugin.PLUGIN_ID,
"metamodel");
@@ -64,17 +69,23 @@
/** The Service URI. Default is "/" */
private String serviceUri = "/";
- /** All the subclasses of <code>javax.ws.rs.core.Application</code>, although
- * there should be only one. */
+ /**
+ * All the subclasses of <code>javax.ws.rs.core.Application</code>, although
+ * there should be only one.
+ */
private final List<IJaxrsApplication> applications = new ArrayList<IJaxrsApplication>();
- /** All the resources (both rootresources and subresources) available in the
- * service , indexed by their associated java type fully qualified name. */
+ /**
+ * All the resources (both rootresources and subresources) available in the
+ * service , indexed by their associated java type fully qualified name.
+ */
private final List<IJaxrsResource> resources = new ArrayList<IJaxrsResource>();
- /** The available providers (classes which implement MessageBodyWriter<T>,
+ /**
+ * The available providers (classes which implement MessageBodyWriter<T>,
* MessageBodyReader<T> or ExceptionMapper<T>), , indexed by their
- * associated java type fully qualified name. */
+ * associated java type fully qualified name.
+ */
private final List<IJaxrsProvider> providers = new ArrayList<IJaxrsProvider>();
/** The HTTP ResourceMethod elements container. */
@@ -86,12 +97,14 @@
/** the endpoints, built from the resource methods. */
private final List<IJaxrsEndpoint> endpoints = new ArrayList<IJaxrsEndpoint>();
- /** Full constructor.
+ /**
+ * Full constructor.
*
* @param javaProject
* the enclosing java project
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
private JaxrsMetamodel(final IJavaProject javaProject) throws CoreException {
this.javaProject = javaProject;
}
@@ -107,13 +120,15 @@
return javaProject;
}
- /** Accessor to the metamodel from the given project's session properties.
+ /**
+ * Accessor to the metamodel from the given project's session properties.
*
* @param javaProject
* the java project
* @return the metamodel or null if none was found
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public static JaxrsMetamodel create(final IJavaProject javaProject) throws CoreException {
if (javaProject == null || javaProject.getProject() == null) {
return null;
@@ -124,13 +139,15 @@
return metamodel;
}
- /** Accessor to the metamodel from the given project's session properties.
+ /**
+ * Accessor to the metamodel from the given project's session properties.
*
* @param javaProject
* the java project
* @return the metamodel or null if none was found
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public static JaxrsMetamodel get(final IJavaProject javaProject) throws CoreException {
if (javaProject == null || javaProject.getProject() == null) {
return null;
@@ -141,19 +158,23 @@
return metamodel;
}
- /** Accessor to the metamodel from the given project's session properties.
+ /**
+ * Accessor to the metamodel from the given project's session properties.
*
* @param project
* the project
* @return the metamodel or null if none was found
* @throws CoreException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public static JaxrsMetamodel get(final IProject project) throws CoreException {
return get(JavaCore.create(project));
}
- /** @throws CoreException
- * in case of underlying exception */
+ /**
+ * @throws CoreException
+ * in case of underlying exception
+ */
public final void remove() throws CoreException {
Logger.debug("JAX-RS Metamodel removed for project " + javaProject.getElementName());
javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, null);
@@ -173,20 +194,13 @@
this.resources.add((IJaxrsResource) element);
break;
/*
- * case RESOURCE_FIELD:
- * final JaxrsResource fieldParent = findResource((IType)
- * element.getJavaElement().getParent());
- * if (fieldParent != null) {
- * fieldParent.addField((JaxrsParamField) element);
- * }
- * break;
- * case RESOURCE_METHOD:
- * final JaxrsResource methodParent = findResource((IType)
- * element.getJavaElement().getParent());
- * if (methodParent != null) {
- * methodParent.addMethod((IJaxrsResourceMethod) element);
- * }
- * break;
+ * case RESOURCE_FIELD: final JaxrsResource fieldParent =
+ * findResource((IType) element.getJavaElement().getParent()); if
+ * (fieldParent != null) { fieldParent.addField((JaxrsParamField)
+ * element); } break; case RESOURCE_METHOD: final JaxrsResource
+ * methodParent = findResource((IType)
+ * element.getJavaElement().getParent()); if (methodParent != null) {
+ * methodParent.addMethod((IJaxrsResourceMethod) element); } break;
*/
}
indexElement(element);
@@ -196,9 +210,12 @@
protected void indexElement(final IJaxrsElement<?> element) {
final IJavaElement javaElement = element.getJavaElement();
indexElement(element, javaElement);
- indexElement(element, JdtUtils.getCompilationUnit(javaElement));
- indexElement(element, JdtUtils.getPackageFragmentRoot(javaElement));
- indexElement(element, javaElement.getJavaProject());
+ // index element that are bound to a java type, not a field or a method
+ if (element.getJavaElement().getElementType() == IJavaElement.TYPE) {
+ indexElement(element, JdtUtils.getCompilationUnit(javaElement));
+ indexElement(element, JdtUtils.getPackageFragmentRoot(javaElement));
+ indexElement(element, javaElement.getJavaProject());
+ }
for (Annotation annotation : element.getAnnotations()) {
indexElement(element, annotation);
}
@@ -210,8 +227,10 @@
}
}
- /** @param jaxrsElement
- * @param javaElement */
+ /**
+ * @param jaxrsElement
+ * @param javaElement
+ */
@SuppressWarnings("unchecked")
private void indexElement(final IJaxrsElement<?> jaxrsElement, final IJavaElement javaElement) {
if (javaElement == null) {
@@ -260,21 +279,17 @@
return Collections.unmodifiableList(providers);
}
- /** @param field
+ /**
+ * @param field
* @param iJavaElement
- * @return
- * private JaxrsResource findResource(final IType javaElement) {
+ * @return private JaxrsResource findResource(final IType javaElement) {
* final String targetIdentifier =
- * javaElement.getHandleIdentifier();
- * for (IJaxrsResource resource : resources) {
- * final String resourceIdentifier =
- * resource.getJavaElement().getHandleIdentifier();
- * if (resourceIdentifier.equals(targetIdentifier)) {
- * return (JaxrsResource) resource;
- * }
- * }
- * return null;
- * } */
+ * javaElement.getHandleIdentifier(); for (IJaxrsResource resource :
+ * resources) { final String resourceIdentifier =
+ * resource.getJavaElement().getHandleIdentifier(); if
+ * (resourceIdentifier.equals(targetIdentifier)) { return
+ * (JaxrsResource) resource; } } return null; }
+ */
@Override
public final List<IJaxrsHttpMethod> getAllHttpMethods() {
@@ -290,10 +305,12 @@
return serviceUri;
}
- /** Sets the Base URI for the URI mapping templates.
+ /**
+ * Sets the Base URI for the URI mapping templates.
*
* @param uri
- * the serviceUri to set */
+ * the serviceUri to set
+ */
public final void setServiceUri(final String uri) {
// remove trailing "*" character, if present.
if (uri.endsWith("*")) {
@@ -303,13 +320,15 @@
}
}
- /** Returns the JAX-RS ElementKind associated with the given java element.
+ /**
+ * Returns the JAX-RS ElementKind associated with the given java element.
*
* @param element
* the underlying java element (can be IType or IMethod)
* @return the associated JAX-RS element, or null if none found
* @throws JavaModelException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public final IJaxrsElement<?> find(final IJavaElement element) throws JavaModelException {
switch (element.getElementType()) {
case IJavaElement.TYPE:
@@ -322,7 +341,8 @@
return null;
}
- /** Report errors from the given markers into the JAX-RS element(s)
+ /**
+ * Report errors from the given markers into the JAX-RS element(s)
* associated with the given compiltation unit.
*
* @param compilationUnit
@@ -331,7 +351,8 @@
* the markers
* @return true if errors were found and reported, false otherwise
* @throws JavaModelException
- * in case of underlying exception */
+ * in case of underlying exception
+ */
public final boolean reportErrors(final ICompilationUnit compilationUnit, final IMarker[] markers)
throws JavaModelException {
boolean hasErrors = false;
@@ -350,11 +371,13 @@
return hasErrors;
}
- /** Resets this metamodel for further re-use (ie, before a new 'full/clean'
+ /**
+ * Resets this metamodel for further re-use (ie, before a new 'full/clean'
* build). Keeping the same instance of Metamodel in the project's session
* properties is a convenient thing, especially on the UI side, where some
* caching system is use to maintain the state of nodes in the Common
- * Navigator (framework). */
+ * Navigator (framework).
+ */
public void reset() {
Logger.debug("Reseting the JAX-RS Metamodel fpr project {}", this.javaProject.getElementName());
this.applications.clear();
@@ -364,11 +387,13 @@
this.elementsIndex.clear();
}
- /** @param annotation
+ /**
+ * @param annotation
* @param metamodel
* @param annotationName
* @return
- * @throws CoreException */
+ * @throws CoreException
+ */
public IJaxrsHttpMethod getHttpMethod(final String annotationName) throws CoreException {
IType annotationType = JdtUtils.resolveType(annotationName, javaProject, new NullProgressMonitor());
if (annotationType != null) {
@@ -382,6 +407,9 @@
@Override
public IJaxrsElement<?> getElement(IJavaElement element) {
+ if (element == null) {
+ return null;
+ }
final String handleIdentifier = element.getHandleIdentifier();
final Set<IJaxrsElement<?>> elements = elementsIndex.get(handleIdentifier);
if (elements == null || elements.isEmpty()) {
@@ -423,10 +451,12 @@
return elements;
}
- /** Remove the given JAX-RS Resource from the metamodel.
+ /**
+ * Remove the given JAX-RS Resource from the metamodel.
*
* @param resource
- * @return true if the resource was actually removed, false otherwise. */
+ * @return true if the resource was actually removed, false otherwise.
+ */
public void remove(IJaxrsElement<?> element) {
if (element == null) {
return;
@@ -476,4 +506,9 @@
return true;
}
+ public IJaxrsElement<?> getElement(IResource resource) {
+
+ return null;
+ }
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamBeanProperty.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -3,9 +3,11 @@
*/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -27,10 +29,12 @@
}
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
+
@Override
public EnumKind getKind() {
return null;
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsParamField.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -3,6 +3,7 @@
*/
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.DefaultValue;
@@ -10,9 +11,8 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IField;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -58,10 +58,12 @@
}
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
+
@Override
public EnumKind getKind() {
if (getPathParamAnnotation() != null) {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsProvider.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -11,14 +11,17 @@
package org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsProvider;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** JAX-RS Provider class Providers *must* implement MessageBodyReader,
* MessageBodyWriter or ExceptionMapper Providers *may* be annotated with
@@ -50,7 +53,7 @@
* @return
* @throws InvalidModelElementException
* @throws CoreException */
- public JaxrsProvider build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+ public JaxrsProvider build(IProgressMonitor progressMonitor) throws CoreException {
JaxrsProvider provider = new JaxrsProvider(this);
// provider.merge(javaType, progressMonitor);
return provider;
@@ -119,12 +122,13 @@
* entry.getKey()); addProviderKind(entry.getKey(),
* entry.getValue(), mediaTypes); } } return changes; } */
- /** {@inheritDoc} */
@Override
- public void validate(IProgressMonitor progressMonitor) {
-
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ return messages;
}
+
@Override
public EnumKind getKind() {
// TODO Auto-generated method stub
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResource.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -23,13 +23,10 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuilder;
-import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumElementKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
@@ -143,30 +140,7 @@
return EnumKind.UNDEFINED;
}
- /** {@inheritDoc}
- *
- * @throws CoreException */
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
- Logger.debug("Validating " + super.getJavaElement().getFullyQualifiedName());
- super.getJavaElement()
- .getResource()
- .deleteMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM, true,
- org.eclipse.core.resources.IResource.DEPTH_INFINITE);
- for (Entry<String, IJaxrsResourceMethod> entry : resourceMethods.entrySet()) {
- ((JaxrsResourceMethod) entry.getValue()).validate(progressMonitor);
- }
- Logger.debug("Validation done.");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.jboss.tools.ws.jaxrs.core.internal.metamodel.IResource#hasErrors(
- * boolean)
- */
- @Override
public final void hasErrors(final boolean hasErrors) {
super.hasErrors(hasErrors);
if (!hasErrors) {
@@ -349,4 +323,15 @@
return new ArrayList<IJaxrsResourceMethod>(resourceMethods.values());
}
+ @Override
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ // delegating the validation to the undelying resource methods
+ for(Entry<String, IJaxrsResourceMethod> entry : resourceMethods.entrySet()) {
+ final IJaxrsResourceMethod resourceMethod = entry.getValue();
+ messages.addAll(resourceMethod.validate());
+ }
+ return messages;
+ }
+
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/domain/JaxrsResourceMethod.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -20,13 +20,17 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodParameter;
import org.jboss.tools.ws.jaxrs.core.jdt.JavaMethodSignature;
@@ -34,15 +38,12 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.EnumKind;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
-import org.jboss.tools.ws.jaxrs.core.metamodel.InvalidModelElementException;
/** @author xcoulon */
public class JaxrsResourceMethod extends JaxrsElement<IMethod> implements IJaxrsResourceMethod {
private final JaxrsResource parentResource;
- private final EnumKind kind = null;
-
/** return type of the java javaMethod. Null if this is not a subresource
* locator. */
private IType returnedJavaType = null;
@@ -178,11 +179,26 @@
return EnumElementKind.RESOURCE_METHOD;
}
- /** {@inheritDoc}
- *
- * @throws CoreException */
@Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
+ public List<ValidatorMessage> validate() {
+ List<ValidatorMessage> messages = new ArrayList<ValidatorMessage>();
+ final List<String> pathParamValueProposals = getPathParamValueProposals();
+ for (JavaMethodParameter parameter : this.javaMethodParameters) {
+ final Annotation annotation = parameter.getAnnotation(PathParam.class.getName());
+ if(annotation != null) {
+ final String value = annotation.getValue("value");
+ if(!pathParamValueProposals.contains(value)) {
+ final ValidatorMessage message = ValidatorMessage.create("Invalid @PathParam value: expected " + pathParamValueProposals, this.getResource());
+ message.setAttribute(IMarker.MARKER, JaxrsMetamodelBuilder.JAXRS_PROBLEM);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ message.setAttribute(IMarker.CHAR_START, annotation.getRegion().getOffset());
+ message.setAttribute(IMarker.CHAR_END, annotation.getRegion().getOffset() + annotation.getRegion().getLength());
+ messages.add(message);
+ Logger.debug("Validation message for {}: {}", this.getJavaElement().getElementName(), message);
+ }
+ }
+ }
+ return messages;
}
/*
@@ -367,4 +383,5 @@
return params;
}
+
}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -0,0 +1,69 @@
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodel;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.ConstantUtils;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
+
+public class JaxrsMetamodelValidator extends AbstractValidator {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.wst.validation.AbstractValidator#validate(org.eclipse.core
+ * .resources.IResource, int, org.eclipse.wst.validation.ValidationState,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ final ValidationResult validationResult = new ValidationResult();
+ final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
+ try {
+ subMonitor.beginTask("Validating the JAX-RS Metamodel", 1);
+ if (resource.getType() == IResource.FILE && "java".equals(resource.getFileExtension())) {
+ clearMarkers((IFile) resource);
+ final JaxrsMetamodel jaxrsMetamodel = JaxrsMetamodel.get(resource.getProject());
+ if (jaxrsMetamodel == null) {
+ return validationResult;
+ }
+ IJaxrsElement<?> element = jaxrsMetamodel.getElement(JdtUtils.getCompilationUnit(resource));
+ if (element != null) {
+ Logger.debug("Validating the JAX-RS Metamodel after {} was {}", resource.getName(), ConstantUtils.getStaticFieldName(IResourceDelta.class, kind));
+ List<ValidatorMessage> validationMessages = element.validate();
+ for (ValidatorMessage validationMessage : validationMessages) {
+ validationResult.add(validationMessage);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ Logger.error("Failed to validate the resource change", e);
+ } finally {
+ subMonitor.done();
+ }
+ return validationResult;
+ }
+
+ private void clearMarkers(IFile file) {
+ try {
+ file.deleteMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
+ org.eclipse.core.resources.IResource.DEPTH_INFINITE);
+ } catch (CoreException e) {
+ }
+ }
+
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/Annotation.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -17,13 +17,15 @@
private final Map<String, List<String>> javaAnnotationElements;
- private final TypedRegion region;
+ private TypedRegion region;
- /** Full constructor
+ /**
+ * Full constructor
*
* @param annotation
* @param name
- * @param annotationElements */
+ * @param annotationElements
+ */
public Annotation(IAnnotation annotation, String name, Map<String, List<String>> annotationElements,
final TypedRegion region) {
this.javaAnnotation = annotation;
@@ -40,6 +42,9 @@
}
this.javaAnnotationElements.clear();
this.javaAnnotationElements.putAll(annotation.getJavaAnnotationElements());
+ if (annotation.getRegion() != null) {
+ this.region = annotation.getRegion();
+ }
return true;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -6,6 +6,7 @@
import java.util.Map;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -21,6 +22,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TypedRegion;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
public class JavaMethodSignaturesVisitor extends ASTVisitor {
@@ -60,7 +62,11 @@
@Override
public boolean visit(MethodDeclaration declaration) {
try {
- IMethod method = (IMethod) compilationUnit.getElementAt(declaration.getStartPosition());
+ final IJavaElement element = compilationUnit.getElementAt(declaration.getStartPosition());
+ if(element.getElementType() != IJavaElement.METHOD) {
+ return true;
+ }
+ IMethod method = (IMethod) element;
if (this.method != null && !this.method.getHandleIdentifier().equals(method.getHandleIdentifier())) {
return true;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/IJaxrsElement.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -3,6 +3,7 @@
import java.util.List;
import org.eclipse.jdt.core.IMember;
+import org.eclipse.wst.validation.ValidatorMessage;
import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
public interface IJaxrsElement<T extends IMember> {
@@ -25,4 +26,6 @@
EnumKind getKind();
+ List<ValidatorMessage> validate();
+
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/AllTests.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -6,9 +6,10 @@
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementChangedEventFilterTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JavaElementChangedProcessorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsElementChangedProcessorTestCase;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuildJobTestCase;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuildJobTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsElementFactoryTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsMetamodelTestCase;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation.JaxrsMetamodelValidatorTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionUtilsTestCase;
import org.jboss.tools.ws.jaxrs.core.internal.utils.PathParamValidationTestCase;
import org.jboss.tools.ws.jaxrs.core.jdt.CompilationUnitsRepositoryTestCase;
@@ -22,9 +23,9 @@
@SuiteClasses({ ProjectBuilderUtilsTestCase.class, ProjectNatureUtilsTestCase.class, JdtUtilsTestCase.class,
CompilationUnitsRepositoryTestCase.class, ElementChangedEventScannerTestCase.class,
JavaElementChangedEventFilterTestCase.class, JavaElementChangedProcessorTestCase.class,
- JaxrsElementChangedProcessorTestCase.class, JaxrsMetamodelFullBuildJobTestCase.class,
+ JaxrsElementChangedProcessorTestCase.class, JaxrsMetamodelBuildJobTestCase.class,
JaxrsElementFactoryTestCase.class, JaxrsMetamodelTestCase.class, CollectionUtilsTestCase.class,
- PathParamValidationTestCase.class, PubSubServiceTestCase.class })
+ PathParamValidationTestCase.class, PubSubServiceTestCase.class, JaxrsMetamodelValidatorTestCase.class })
public class AllTests {
}
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 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/WorkbenchUtils.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -828,6 +828,7 @@
throws JavaModelException {
Annotation annotation = JdtUtils.resolveAnnotation(member, JdtUtils.parse(member, null),
annotationClass);
+
Map<String, List<String>> elements = new HashMap<String, List<String>>();
elements.put("value", Arrays.asList(values));
annotation.update(new Annotation(annotation.getJavaAnnotation(), annotation.getName(), elements, null));
Copied: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java (from rev 36531, trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java)
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
+
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
+import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
+import org.junit.Assert;
+import org.junit.Test;
+
+/** @author xcoulon */
+public class JaxrsMetamodelBuildJobTestCase extends AbstractMetamodelBuilderTestCase {
+
+ @Test
+ public void shouldAssertHTTPMethods() throws CoreException {
+ // 6 HttpMethods in the jax-rs API (@GET, etc.) + 1 in the project
+ // (@FOO)
+ Assert.assertEquals(1 * 7, metamodel.getAllHttpMethods().size());
+ Set<IJaxrsHttpMethod> jaxrsHttpMethods = new HashSet<IJaxrsHttpMethod>();
+ for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
+ // toString() called for code coverage
+ Assert.assertNotNull(httpMethod.toString());
+ Assert.assertTrue(jaxrsHttpMethods.add(httpMethod));
+ }
+ }
+
+ @Test
+ public void shouldAssertResourcesAndMethods() throws CoreException {
+ // for now, the result excludes the (binary) AsynchronousDispatcher, and
+ // hence, its (sub)resources
+ Assert.assertEquals(5, metamodel.getAllResources().size());
+ for (IJaxrsResource jaxrsResource : metamodel.getAllResources()) {
+ assertThat(jaxrsResource.getJavaElement(), notNullValue());
+ assertThat(jaxrsResource.getKind(), notNullValue());
+ assertThat(jaxrsResource.getAllMethods().size(), greaterThan(0));
+ }
+ }
+
+ @Test
+ public void shouldAssertResolvedEndpoints() throws CoreException {
+ List<IJaxrsEndpoint> endpoints = metamodel.getAllEndpoints();
+ Assert.assertEquals("Wrong result", 11, endpoints.size());
+ for (IJaxrsEndpoint endpoint : endpoints) {
+ Assert.assertFalse("Empty list of resourceMethods", endpoint.getResourceMethods().isEmpty());
+ Assert.assertNotNull("No URI Path template", endpoint.getUriPathTemplate());
+ Assert.assertFalse("No URI Path template:" + endpoint.getUriPathTemplate(), endpoint.getUriPathTemplate()
+ .contains("null"));
+ Assert.assertFalse("Found some '//' in the uri path template in " + endpoint.getUriPathTemplate(), endpoint
+ .getUriPathTemplate().contains("//"));
+ Assert.assertNotNull("No Http Method", endpoint.getHttpMethod());
+ Assert.assertFalse("No consumed media types", endpoint.getConsumedMediaTypes().isEmpty());
+ Assert.assertFalse("No produced media types", endpoint.getProducedMediaTypes().isEmpty());
+ }
+ }
+
+ @Test
+ public void shouldRetrieveCustomerResource() throws CoreException {
+ IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
+ final IJaxrsResource customerResource = (IJaxrsResource) metamodel.getElement(customerType);
+ Assert.assertNotNull("CustomerResource not found", customerType);
+ Assert.assertEquals("Wrong number of resource resourceMethods", 6, customerResource.getResourceMethods().size());
+ }
+
+ @Test
+ public void shouldRetrieveCustomerResourceMethodProposals() throws CoreException {
+ IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getCustomers");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveCustomerSubresourceMethodProposals() throws CoreException {
+ IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getCustomer");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals(), containsInAnyOrder("id"));
+ }
+
+ @Test
+ public void shouldRetrieveBookResourceMethodProposals() throws CoreException {
+ IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getAllProducts");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldRetrieveBooksubresourceMethodProposals() throws CoreException {
+ IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
+ IMethod customerMethod = getMethod(customerType, "getProduct");
+ final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
+ Assert.assertThat(customerResourceMethod, notNullValue());
+ Assert.assertThat(customerResourceMethod.getPathParamValueProposals(), containsInAnyOrder("id"));
+ }
+
+}
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelBuildJobTestCase.java
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Deleted: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/builder/JaxrsMetamodelFullBuildJobTestCase.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -1,129 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder;
-
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.emptyIterable;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getMethod;
-import static org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.getType;
-import static org.junit.Assert.assertThat;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsHttpMethod;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
-import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResourceMethod;
-import org.junit.Assert;
-import org.junit.Test;
-
-/** @author xcoulon */
-public class JaxrsMetamodelFullBuildJobTestCase extends AbstractMetamodelBuilderTestCase {
-
- @Test
- public void shouldAssertHTTPMethods() throws CoreException {
- // 6 HttpMethods in the jax-rs API (@GET, etc.) + 1 in the project
- // (@FOO)
- Assert.assertEquals(1 * 7, metamodel.getAllHttpMethods().size());
- Set<IJaxrsHttpMethod> jaxrsHttpMethods = new HashSet<IJaxrsHttpMethod>();
- for (IJaxrsHttpMethod httpMethod : metamodel.getAllHttpMethods()) {
- // toString() called for code coverage
- Assert.assertNotNull(httpMethod.toString());
- Assert.assertTrue(jaxrsHttpMethods.add(httpMethod));
- }
- }
-
- @Test
- public void shouldAssertResourcesAndMethods() throws CoreException {
- // for now, the result excludes the (binary) AsynchronousDispatcher, and
- // hence, its (sub)resources
- Assert.assertEquals(5, metamodel.getAllResources().size());
- for (IJaxrsResource jaxrsResource : metamodel.getAllResources()) {
- assertThat(jaxrsResource.getJavaElement(), notNullValue());
- assertThat(jaxrsResource.getKind(), notNullValue());
- assertThat(jaxrsResource.getAllMethods().size(), greaterThan(0));
- }
- }
-
- @Test
- public void shouldAssertResolvedEndpoints() throws CoreException {
- List<IJaxrsEndpoint> endpoints = metamodel.getAllEndpoints();
- Assert.assertEquals("Wrong result", 11, endpoints.size());
- for (IJaxrsEndpoint endpoint : endpoints) {
- Assert.assertFalse("Empty list of resourceMethods", endpoint.getResourceMethods().isEmpty());
- Assert.assertNotNull("No URI Path template", endpoint.getUriPathTemplate());
- Assert.assertFalse("No URI Path template:" + endpoint.getUriPathTemplate(), endpoint.getUriPathTemplate()
- .contains("null"));
- Assert.assertFalse("Found some '//' in the uri path template in " + endpoint.getUriPathTemplate(), endpoint
- .getUriPathTemplate().contains("//"));
- Assert.assertNotNull("No Http Method", endpoint.getHttpMethod());
- Assert.assertFalse("No consumed media types", endpoint.getConsumedMediaTypes().isEmpty());
- Assert.assertFalse("No produced media types", endpoint.getProducedMediaTypes().isEmpty());
- }
- }
-
- @Test
- public void shouldRetrieveCustomerResource() throws CoreException {
- IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
- final IJaxrsResource customerResource = (IJaxrsResource) metamodel.getElement(customerType);
- Assert.assertNotNull("CustomerResource not found", customerType);
- Assert.assertEquals("Wrong number of resource resourceMethods", 6, customerResource.getResourceMethods().size());
- }
-
- @Test
- public void shouldRetrieveCustomerResourceMethodProposals() throws CoreException {
- IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
- IMethod customerMethod = getMethod(customerType, "getCustomers");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(), equalTo(0));
- }
-
- @Test
- public void shouldRetrieveCustomerSubresourceMethodProposals() throws CoreException {
- IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
- IMethod customerMethod = getMethod(customerType, "getCustomer");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals(), containsInAnyOrder("id"));
- }
-
- @Test
- public void shouldRetrieveBookResourceMethodProposals() throws CoreException {
- IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- IMethod customerMethod = getMethod(customerType, "getAllProducts");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals().size(), equalTo(0));
- }
-
- @Test
- public void shouldRetrieveBooksubresourceMethodProposals() throws CoreException {
- IType customerType = getType("org.jboss.tools.ws.jaxrs.sample.services.BookResource", javaProject);
- IMethod customerMethod = getMethod(customerType, "getProduct");
- final IJaxrsResourceMethod customerResourceMethod = (IJaxrsResourceMethod) metamodel.getElement(customerMethod);
- Assert.assertThat(customerResourceMethod, notNullValue());
- Assert.assertThat(customerResourceMethod.getPathParamValueProposals(), containsInAnyOrder("id"));
- }
-
-}
Added: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -0,0 +1,80 @@
+/**
+ *
+ */
+package org.jboss.tools.ws.jaxrs.core.internal.metamodel.validation;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.Path;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
+import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
+import org.jboss.tools.ws.jaxrs.core.jdt.Annotation;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsElement;
+import org.junit.Test;
+
+/**
+ * @author Xi
+ *
+ */
+public class JaxrsMetamodelValidatorTestCase extends AbstractMetamodelBuilderTestCase {
+
+ @Test
+ public void shouldValidateHttpMethod() throws CoreException {
+ // preconditions
+ IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final IJaxrsElement<?> httpMethod = metamodel.getElement(fooType);
+ // operation
+ final List<ValidatorMessage> validationMessages = httpMethod.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldNotValidateHttpMethod() throws CoreException {
+ // preconditions
+ IType fooType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.FOO", javaProject);
+ final IJaxrsElement<?> httpMethod = metamodel.getElement(fooType);
+ Annotation httpAnnotation = WorkbenchUtils.getAnnotation(fooType, HttpMethod.class, new String[0]);
+ httpMethod.addOrUpdateAnnotation(httpAnnotation);
+ // operation
+ final List<ValidatorMessage> validationMessages = httpMethod.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(1));
+ }
+
+ @Test
+ public void shouldValidateResourceMethod() throws CoreException {
+ // preconditions
+ IType customerJavaType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
+ final IJaxrsElement<?> customerResource = metamodel.getElement(customerJavaType);
+ // operation
+ final List<ValidatorMessage> validationMessages = customerResource.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(0));
+ }
+
+ @Test
+ public void shouldNotValidateResourceMethod() throws CoreException {
+ // preconditions
+ IType customerJavaType = WorkbenchUtils.getType("org.jboss.tools.ws.jaxrs.sample.services.CustomerResource", javaProject);
+ final IJaxrsElement<?> customerResource = metamodel.getElement(customerJavaType);
+ IMethod customerJavaMethod = WorkbenchUtils.getMethod(customerJavaType, "getCustomer");
+ final IJaxrsElement<?> customerResourceMethod = metamodel.getElement(customerJavaMethod);
+ Annotation pathAnnotation = WorkbenchUtils.getAnnotation(customerJavaMethod, Path.class, "/{foo}");
+ customerResourceMethod.addOrUpdateAnnotation(pathAnnotation);
+ // operation
+ final List<ValidatorMessage> validationMessages = customerResource.validate();
+ // validation
+ assertThat(validationMessages.size(), equalTo(1));
+ }
+
+}
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/metamodel/validation/JaxrsMetamodelValidatorTestCase.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/internal/utils/PathParamValidationTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java 2011-11-22 19:53:40 UTC (rev 36541)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/internal/utils/PathParamValidationTestCase.java 2011-11-22 21:07:06 UTC (rev 36542)
@@ -20,7 +20,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.WorkbenchUtils;
import org.jboss.tools.ws.jaxrs.core.builder.AbstractMetamodelBuilderTestCase;
-import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelFullBuilder;
+import org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.JaxrsMetamodelBuilder;
import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsResource;
import org.junit.Assert;
import org.junit.Ignore;
@@ -34,14 +34,14 @@
// pre-conditions : add a standard class : no new root resource (yet)
ICompilationUnit fooCompilationUnit = WorkbenchUtils.createCompilationUnit(javaProject, "FooResource.txt",
"org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java", bundle);
- IMarker[] markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM, true,
+ IMarker[] markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("No marker expected", 0, markers.length);
// operation : replace @PathParam("id") with @PathParam("ide")
WorkbenchUtils.replaceAllOccurrencesOfCode(fooCompilationUnit, "@PathParam(\"id\")", "@PathParam(\"ide\")",
true);
// post-conditions: expect a validation error
- markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM, true,
+ markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("Wrong number of markers", 1, markers.length);
@@ -54,7 +54,7 @@
"org.jboss.tools.ws.jaxrs.sample.services", "FooResource.java", bundle);
List<IJaxrsResource> resources = metamodel.getAllResources();
Assert.assertEquals(6, resources.size());
- IMarker[] markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM, true,
+ IMarker[] markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("No marker expected", 0, markers.length);
// operation : change both @Path and @PathParam values
@@ -63,7 +63,7 @@
WorkbenchUtils.replaceAllOccurrencesOfCode(fooCompilationUnit, "@PathParam(\"id\")", "@PathParam(\"ide\")",
true);
// post-conditions: expect no validation error
- markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelFullBuilder.JAXRS_PROBLEM, true,
+ markers = fooCompilationUnit.getResource().findMarkers(JaxrsMetamodelBuilder.JAXRS_PROBLEM, true,
IResource.DEPTH_INFINITE);
Assert.assertEquals("No marker expected", 0, markers.length);
13 years, 1 month
JBoss Tools SVN: r36541 - in trunk/forge/plugins/org.jboss.tools.forge.ui: src/org/jboss/tools/forge/ui/console and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: koen.aers(a)jboss.com
Date: 2011-11-22 14:53:40 -0500 (Tue, 22 Nov 2011)
New Revision: 36541
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/OpenPostProcessor.java
Log:
JBIDE-10203:
- open <file> shows file in editor whether in workspace or not
- open <folder> selects folder in project and/or pacakage explorer if folder is in workspace
Modified: trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF 2011-11-22 17:42:29 UTC (rev 36540)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/META-INF/MANIFEST.MF 2011-11-22 19:53:40 UTC (rev 36541)
@@ -16,7 +16,8 @@
org.eclipse.jdt.core,
org.eclipse.ui.views,
org.jboss.tools.forge.core;bundle-version="1.0.0",
- org.eclipse.core.filesystem;bundle-version="1.3.100"
+ org.eclipse.core.filesystem;bundle-version="1.3.100",
+ org.eclipse.ui.navigator;bundle-version="3.5.100"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.jboss.tools.forge.ui.ForgeUIPlugin
Modified: trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/OpenPostProcessor.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/OpenPostProcessor.java 2011-11-22 17:42:29 UTC (rev 36540)
+++ trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/OpenPostProcessor.java 2011-11-22 19:53:40 UTC (rev 36541)
@@ -4,29 +4,33 @@
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.part.ISetSelectionTarget;
import org.jboss.tools.forge.ui.ForgeUIPlugin;
public class OpenPostProcessor {
public void postProcess(String line, String currentResourcePath) {
- try {
- String resourceToOpen = currentResourcePath + File.separator + line.substring(5).trim();
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(resourceToOpen));
- if (fileStore.fetchInfo().isDirectory()) {
- expandDirectoryInExplorer(resourceToOpen);
- } else {
- openFileInEditor(fileStore);
- }
- IWorkbenchPage workbenchPage = ForgeCommandPostProcessorHelper.getActiveWorkbenchPage();
- if (workbenchPage != null) {
- IDE.openEditorOnFileStore(workbenchPage, fileStore);
- }
- } catch (PartInitException e) {
- ForgeUIPlugin.log(e);
+ String resourceToOpen = currentResourcePath + File.separator + line.substring(5).trim();
+ IPath path = new Path(resourceToOpen);
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(resourceToOpen));
+ if (fileStore.fetchInfo().isDirectory()) {
+ expandDirectoryInExplorer(path);
+ } else {
+ openFileInEditor(fileStore);
}
}
@@ -41,8 +45,42 @@
}
}
- private void expandDirectoryInExplorer(String resourceToOpen) {
-
+ private void expandDirectoryInExplorer(IPath path) {
+ IWorkbenchPage workbenchPage = ForgeCommandPostProcessorHelper.getActiveWorkbenchPage();
+ IContainer objectToSelect = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
+ if (objectToSelect != null && workbenchPage != null) {
+ IViewPart projectExplorer = workbenchPage.findView("org.eclipse.ui.navigator.ProjectExplorer");
+ if (projectExplorer != null && projectExplorer instanceof CommonNavigator) {
+ expandInProjectExplorer((CommonNavigator)projectExplorer, objectToSelect);
+ }
+ IViewPart packageExplorer = workbenchPage.findView("org.eclipse.jdt.ui.PackageExplorer");
+ if (packageExplorer == null && projectExplorer == null) {
+ try {
+ packageExplorer = workbenchPage.showView("org.eclipse.jdt.ui.PackageExplorer");
+ } catch (PartInitException e) {
+ ForgeUIPlugin.log(e);
+ }
+ }
+ if (packageExplorer != null) {
+ expandInPackageExplorer(packageExplorer, objectToSelect);
+ }
+ }
}
-
+
+ private void expandInProjectExplorer(CommonNavigator projectExplorer, IContainer container) {
+ projectExplorer.selectReveal(new StructuredSelection(container));
+ TreeViewer treeViewer = projectExplorer.getCommonViewer();
+ treeViewer.expandToLevel(container, 1);
+ }
+
+ private void expandInPackageExplorer(IViewPart packageExplorer, IContainer container) {
+ if (packageExplorer instanceof ISetSelectionTarget) {
+ ((ISetSelectionTarget)packageExplorer).selectReveal(new StructuredSelection(container));
+ }
+ Object treeViewer = packageExplorer.getAdapter(ISelectionProvider.class);
+ if (treeViewer != null && treeViewer instanceof TreeViewer) {
+ ((TreeViewer)treeViewer).expandToLevel(JavaCore.create(container), 1);
+ }
+ }
+
}
13 years, 1 month